blob: a8e54a361512ad6ae844d3991ea4a5eac4617328 [file] [log] [blame]
Luca Weissb1111222019-09-07 17:25:31 +02001#!/usr/bin/env python3
Rob Herringa5ac29b2019-06-20 15:19:40 -06002# SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause)
Simon Glass50f25072017-03-17 16:14:30 -06003
Luca Weissb1111222019-09-07 17:25:31 +02004# While Python 3 is the default, it's also possible to invoke
5# this setup.py script with Python 2.
6
Simon Glass50f25072017-03-17 16:14:30 -06007"""
8setup.py file for SWIG libfdt
Simon Glass90db6d92017-04-07 15:51:32 -06009Copyright (C) 2017 Google, Inc.
10Written by Simon Glass <sjg@chromium.org>
Simon Glass50f25072017-03-17 16:14:30 -060011"""
12
Rob Herringc6917762021-11-10 19:11:32 -060013from setuptools import setup, Extension
Rob Herringc001fc02022-02-03 12:04:07 -060014from setuptools.command.build_py import build_py as _build_py
15
Simon Glass50f25072017-03-17 16:14:30 -060016import os
Simon Glass90db6d92017-04-07 15:51:32 -060017import re
Simon Glass50f25072017-03-17 16:14:30 -060018import sys
19
Rob Herring23b56cb2021-11-10 19:11:35 -060020srcdir = os.path.dirname(__file__)
21
Marc-André Lureau4048aed2022-01-03 11:38:55 +040022with open(os.path.join(srcdir, "README"), "r") as fh:
Rob Herring1cc41b12021-11-11 22:16:29 -060023 long_description = fh.read()
24
Marc-André Lureau05874d02020-10-12 11:34:03 +040025def get_top_builddir():
26 if '--top-builddir' in sys.argv:
27 index = sys.argv.index('--top-builddir')
28 sys.argv.pop(index)
29 return sys.argv.pop(index)
30 else:
Rob Herring23b56cb2021-11-10 19:11:35 -060031 return srcdir
Marc-André Lureau05874d02020-10-12 11:34:03 +040032
Marc-André Lureau05874d02020-10-12 11:34:03 +040033top_builddir = get_top_builddir()
34
Simon Glass50f25072017-03-17 16:14:30 -060035libfdt_module = Extension(
36 '_libfdt',
Rob Herring23b56cb2021-11-10 19:11:35 -060037 sources=[os.path.join(srcdir, 'pylibfdt/libfdt.i')],
Ross Burton383e1482021-11-11 16:05:36 +000038 define_macros=[('PY_SSIZE_T_CLEAN', None)],
Rob Herring23b56cb2021-11-10 19:11:35 -060039 include_dirs=[os.path.join(srcdir, 'libfdt')],
David Gibson607b8582018-11-23 22:11:33 +110040 libraries=['fdt'],
Marc-André Lureau05874d02020-10-12 11:34:03 +040041 library_dirs=[os.path.join(top_builddir, 'libfdt')],
Rob Herring23b56cb2021-11-10 19:11:35 -060042 swig_opts=['-I' + os.path.join(srcdir, 'libfdt')],
Simon Glass50f25072017-03-17 16:14:30 -060043)
44
Rob Herringc001fc02022-02-03 12:04:07 -060045class build_py(_build_py):
46 def run(self):
47 self.run_command("build_ext")
48 return super().run()
49
Simon Glassb04a2cf2017-04-05 10:01:39 -060050setup(
51 name='libfdt',
Rob Herring0b106a72021-11-10 19:11:33 -060052 use_scm_version={
Rob Herring23b56cb2021-11-10 19:11:35 -060053 "root": srcdir,
Rob Herring0b106a72021-11-10 19:11:33 -060054 },
Rob Herringc001fc02022-02-03 12:04:07 -060055 cmdclass = {'build_py' : build_py},
Rob Herring0b106a72021-11-10 19:11:33 -060056 setup_requires = ['setuptools_scm'],
Rob Herring69a76072021-11-10 19:11:34 -060057 author='Simon Glass',
58 author_email='sjg@chromium.org',
Simon Glassb04a2cf2017-04-05 10:01:39 -060059 description='Python binding for libfdt',
60 ext_modules=[libfdt_module],
Rob Herring23b56cb2021-11-10 19:11:35 -060061 package_dir={'': os.path.join(srcdir, 'pylibfdt')},
David Gibson1e4a0922018-08-10 17:33:24 +100062 py_modules=['libfdt'],
Rob Herring1cc41b12021-11-11 22:16:29 -060063
64 long_description=long_description,
65 long_description_content_type="text/plain",
66 url="https://git.kernel.org/pub/scm/utils/dtc/dtc.git",
67 license="BSD",
68 license_files=["GPL", "BSD-2-Clause"],
69
70 classifiers=[
71 "Programming Language :: Python :: 3",
72 "License :: OSI Approved :: BSD License",
73 "License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)",
74 "Operating System :: OS Independent",
75 ],
76
Simon Glassb04a2cf2017-04-05 10:01:39 -060077)