1#!/usr/bin/env python3 2# SPDX-License-Identifier: (GPL-2.0-or-later OR BSD-2-Clause) 3 4# While Python 3 is the default, it's also possible to invoke 5# this setup.py script with Python 2. 6 7""" 8setup.py file for SWIG libfdt 9Copyright (C) 2017 Google, Inc. 10Written by Simon Glass <[email protected]> 11""" 12 13from setuptools import setup, Extension 14from setuptools.command.build_py import build_py as _build_py 15 16import os 17import re 18import sys 19 20srcdir = os.path.dirname(__file__) 21 22with open(os.path.join(srcdir, "README.md"), "r") as fh: 23 long_description = fh.read() 24 25def 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: 31 return srcdir 32 33top_builddir = get_top_builddir() 34 35libfdt_module = Extension( 36 '_libfdt', 37 sources=[os.path.join(srcdir, 'pylibfdt/libfdt.i')], 38 define_macros=[('PY_SSIZE_T_CLEAN', None)], 39 include_dirs=[os.path.join(srcdir, 'libfdt')], 40 libraries=['fdt'], 41 library_dirs=[os.path.join(top_builddir, 'libfdt')], 42 swig_opts=['-I' + os.path.join(srcdir, 'libfdt')], 43) 44 45class build_py(_build_py): 46 def run(self): 47 self.run_command("build_ext") 48 return super().run() 49 50setup( 51 name='libfdt', 52 use_scm_version={ 53 "root": srcdir, 54 }, 55 cmdclass = {'build_py' : build_py}, 56 setup_requires = ['setuptools_scm'], 57 author='Simon Glass', 58 author_email='[email protected]', 59 description='Python binding for libfdt', 60 ext_modules=[libfdt_module], 61 package_dir={'': os.path.join(srcdir, 'pylibfdt')}, 62 py_modules=['libfdt'], 63 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 77) 78