blob: e117d6302db8b9c914c8947ada3554e33cc0ccd2 [file] [log] [blame]
Philip Howard567ee002013-03-27 22:22:00 +00001#!/usr/bin/env python
2
Mark Liffiton37ca9702017-08-13 12:52:10 -05003import os
4import sys
5
Mark Liffiton36449072017-08-12 16:47:21 -05006from setuptools import setup, Extension
Mark Liffitonf43bfce2017-08-12 23:34:01 -05007from setuptools.command.build_py import build_py
Mark Liffiton37ca9702017-08-13 12:52:10 -05008from setuptools.command.sdist import sdist
9from distutils.spawn import find_executable
Phil Howard60cc6422015-03-11 12:20:54 +000010from glob import glob
Philip Howard567ee002013-03-27 22:22:00 +000011
Phil Howard3f99ba12016-02-29 12:12:28 +000012sources = glob('WiringPi/devLib/*.c')
13sources += glob('WiringPi/wiringPi/*.c')
Joshua Yang8d7c2232018-02-22 13:52:33 +090014
Joshua Yang8d7c2232018-02-22 13:52:33 +090015# Exclude template file.
16sources = list(set(sources) - set(glob('WiringPi/wiringPi/odroid_template.c')))
17
Mark Liffiton37ca9702017-08-13 12:52:10 -050018# If we have swig, use it. Otherwise, use the pre-generated
19# wrapper from the source distribution.
20if find_executable('swig'):
21 sources += ['wiringpi.i']
22elif os.path.exists('wiringpi_wrap.c'):
23 sources += ['wiringpi_wrap.c']
24else:
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 Howard3f99ba12016-02-29 12:12:28 +000029
Deokgyu Yanga5de1bc2020-04-28 11:40:44 +090030try:
31 sources.remove('WiringPi/devLib/piFaceOld.c')
32except ValueError:
33 # the file is already excluded in the source distribution
34 pass
35
36
Mark Liffitonf43bfce2017-08-12 23:34:01 -050037# 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 Liffiton37ca9702017-08-13 12:52:10 -050044class build_py_ext_first(build_py):
Mark Liffitonf43bfce2017-08-12 23:34:01 -050045 def run(self):
46 self.run_command("build_ext")
47 return build_py.run(self)
48
49
Mark Liffiton37ca9702017-08-13 12:52:10 -050050# Make sure wiringpi_wrap.c is available for the source dist, also.
51class sdist_ext_first(sdist):
52 def run(self):
53 self.run_command("build_ext")
54 return sdist.run(self)
55
56
Yang Deokgyudd194672019-09-04 11:29:11 +090057_odroid_wiringpi = Extension(
58 '_odroid_wiringpi',
Phil Howard22041762014-07-18 11:48:01 +000059 include_dirs=['WiringPi/wiringPi','WiringPi/devLib'],
neuralassembly91b71d72017-03-29 17:25:14 +090060 sources=sources,
Mark Liffiton8600c392018-04-29 09:12:55 -050061 swig_opts=['-threads'],
steve.jeong734a6052022-11-15 17:55:45 +090062 extra_link_args=['-lcrypt', '-lrt'],
Philip Howard567ee002013-03-27 22:22:00 +000063)
64
65setup(
Yang Deokgyudd194672019-09-04 11:29:11 +090066 name = 'odroid_wiringpi',
steve.jeong5f932ee2022-12-20 09:42:24 +090067 version = '3.14.4',
Yang Deokgyudd194672019-09-04 11:29:11 +090068 ext_modules = [ _odroid_wiringpi ],
69 py_modules = ["odroid_wiringpi"],
Philip Howard567ee002013-03-27 22:22:00 +000070 install_requires=[],
Mark Liffiton37ca9702017-08-13 12:52:10 -050071 cmdclass = {'build_py' : build_py_ext_first, 'sdist' : sdist_ext_first},
Philip Howard567ee002013-03-27 22:22:00 +000072)