Philip Howard | 567ee00 | 2013-03-27 22:22:00 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
Mark Liffiton | 37ca970 | 2017-08-13 12:52:10 -0500 | [diff] [blame] | 3 | import os |
| 4 | import sys |
| 5 | |
Mark Liffiton | 3644907 | 2017-08-12 16:47:21 -0500 | [diff] [blame] | 6 | from setuptools import setup, Extension |
Mark Liffiton | f43bfce | 2017-08-12 23:34:01 -0500 | [diff] [blame] | 7 | from setuptools.command.build_py import build_py |
Mark Liffiton | 37ca970 | 2017-08-13 12:52:10 -0500 | [diff] [blame] | 8 | from setuptools.command.sdist import sdist |
| 9 | from distutils.spawn import find_executable |
Phil Howard | 60cc642 | 2015-03-11 12:20:54 +0000 | [diff] [blame] | 10 | from glob import glob |
Philip Howard | 567ee00 | 2013-03-27 22:22:00 +0000 | [diff] [blame] | 11 | |
Phil Howard | 3f99ba1 | 2016-02-29 12:12:28 +0000 | [diff] [blame] | 12 | sources = glob('WiringPi/devLib/*.c') |
| 13 | sources += glob('WiringPi/wiringPi/*.c') |
Joshua Yang | 8d7c223 | 2018-02-22 13:52:33 +0900 | [diff] [blame] | 14 | |
Joshua Yang | 8d7c223 | 2018-02-22 13:52:33 +0900 | [diff] [blame] | 15 | # Exclude template file. |
| 16 | sources = list(set(sources) - set(glob('WiringPi/wiringPi/odroid_template.c'))) |
| 17 | |
Mark Liffiton | 37ca970 | 2017-08-13 12:52:10 -0500 | [diff] [blame] | 18 | # If we have swig, use it. Otherwise, use the pre-generated |
| 19 | # wrapper from the source distribution. |
| 20 | if find_executable('swig'): |
| 21 | sources += ['wiringpi.i'] |
| 22 | elif os.path.exists('wiringpi_wrap.c'): |
| 23 | sources += ['wiringpi_wrap.c'] |
| 24 | else: |
| 25 | print("Error: Building this module requires either that swig is installed\n" |
| 26 | " (e.g., 'sudo apt install swig') or that wiringpi_wrap.c from the\n" |
| 27 | " source distribution (on pypi) is available.") |
| 28 | sys.exit(1) |
Phil Howard | 3f99ba1 | 2016-02-29 12:12:28 +0000 | [diff] [blame] | 29 | |
Deokgyu Yang | a5de1bc | 2020-04-28 11:40:44 +0900 | [diff] [blame] | 30 | try: |
| 31 | sources.remove('WiringPi/devLib/piFaceOld.c') |
| 32 | except ValueError: |
| 33 | # the file is already excluded in the source distribution |
| 34 | pass |
| 35 | |
| 36 | |
Mark Liffiton | f43bfce | 2017-08-12 23:34:01 -0500 | [diff] [blame] | 37 | # Fix so that build_ext runs before build_py |
| 38 | # Without this, wiringpi.py is generated too late and doesn't |
| 39 | # end up in the distribution when running setup.py bdist or bdist_wheel. |
| 40 | # Based on: |
| 41 | # https://stackoverflow.com/a/29551581/7938656 |
| 42 | # and |
| 43 | # https://blog.niteoweb.com/setuptools-run-custom-code-in-setup-py/ |
Mark Liffiton | 37ca970 | 2017-08-13 12:52:10 -0500 | [diff] [blame] | 44 | class build_py_ext_first(build_py): |
Mark Liffiton | f43bfce | 2017-08-12 23:34:01 -0500 | [diff] [blame] | 45 | def run(self): |
| 46 | self.run_command("build_ext") |
| 47 | return build_py.run(self) |
| 48 | |
| 49 | |
Mark Liffiton | 37ca970 | 2017-08-13 12:52:10 -0500 | [diff] [blame] | 50 | # Make sure wiringpi_wrap.c is available for the source dist, also. |
| 51 | class sdist_ext_first(sdist): |
| 52 | def run(self): |
| 53 | self.run_command("build_ext") |
| 54 | return sdist.run(self) |
| 55 | |
| 56 | |
Yang Deokgyu | dd19467 | 2019-09-04 11:29:11 +0900 | [diff] [blame] | 57 | _odroid_wiringpi = Extension( |
| 58 | '_odroid_wiringpi', |
Phil Howard | 2204176 | 2014-07-18 11:48:01 +0000 | [diff] [blame] | 59 | include_dirs=['WiringPi/wiringPi','WiringPi/devLib'], |
neuralassembly | 91b71d7 | 2017-03-29 17:25:14 +0900 | [diff] [blame] | 60 | sources=sources, |
Mark Liffiton | 8600c39 | 2018-04-29 09:12:55 -0500 | [diff] [blame] | 61 | swig_opts=['-threads'], |
steve.jeong | 734a605 | 2022-11-15 17:55:45 +0900 | [diff] [blame^] | 62 | extra_link_args=['-lcrypt', '-lrt'], |
Philip Howard | 567ee00 | 2013-03-27 22:22:00 +0000 | [diff] [blame] | 63 | ) |
| 64 | |
| 65 | setup( |
Yang Deokgyu | dd19467 | 2019-09-04 11:29:11 +0900 | [diff] [blame] | 66 | name = 'odroid_wiringpi', |
steve.jeong | e308c80 | 2022-11-15 17:50:38 +0900 | [diff] [blame] | 67 | version = '3.14.0', |
Yang Deokgyu | dd19467 | 2019-09-04 11:29:11 +0900 | [diff] [blame] | 68 | ext_modules = [ _odroid_wiringpi ], |
| 69 | py_modules = ["odroid_wiringpi"], |
Philip Howard | 567ee00 | 2013-03-27 22:22:00 +0000 | [diff] [blame] | 70 | install_requires=[], |
Mark Liffiton | 37ca970 | 2017-08-13 12:52:10 -0500 | [diff] [blame] | 71 | cmdclass = {'build_py' : build_py_ext_first, 'sdist' : sdist_ext_first}, |
Philip Howard | 567ee00 | 2013-03-27 22:22:00 +0000 | [diff] [blame] | 72 | ) |