On Wed, Oct 11, 2023 at 2:13 PM Phil Howard <phil@xxxxxxxxxxxxx> wrote: > > Build gpiod into Python module. > > Optional environment var USE_SYSTEM_GPIO=1 to Let's call it USE_SYSTEM_GPIOD or USE_SYSTEM_LIBGPIOD or even LINK_SYSTEM_LIBGPIOD? > generate a module that depends upon system gpiod. > > Signed-off-by: Phil Howard <phil@xxxxxxxxxxxxx> > --- > bindings/python/MANIFEST.in | 4 +++ > bindings/python/include | 1 + > bindings/python/lib | 1 + > bindings/python/setup.py | 57 ++++++++++++++++++++++++++++--------- > 4 files changed, 50 insertions(+), 13 deletions(-) > create mode 120000 bindings/python/include > create mode 120000 bindings/python/lib > > diff --git a/bindings/python/MANIFEST.in b/bindings/python/MANIFEST.in > index c7124d4..eff8977 100644 > --- a/bindings/python/MANIFEST.in > +++ b/bindings/python/MANIFEST.in > @@ -11,3 +11,7 @@ recursive-include gpiod/ext *.h > > recursive-include tests/gpiosim *.c > recursive-include tests/procname *.c > + > +recursive-include lib *.c > +recursive-include lib *.h > +recursive-include include *.h > diff --git a/bindings/python/include b/bindings/python/include > new file mode 120000 > index 0000000..fcffffb > --- /dev/null > +++ b/bindings/python/include > @@ -0,0 +1 @@ > +../../include > \ No newline at end of file Addressing Andy's remark: I think this is just how git generates diffs for links, nothing we can do about it. I would prefer not to have links in the repo anyway, it would be great if we could create them at build-time. Bart > diff --git a/bindings/python/lib b/bindings/python/lib > new file mode 120000 > index 0000000..58677dd > --- /dev/null > +++ b/bindings/python/lib > @@ -0,0 +1 @@ > +../../lib > \ No newline at end of file > diff --git a/bindings/python/setup.py b/bindings/python/setup.py > index 66b7908..2e25981 100644 > --- a/bindings/python/setup.py > +++ b/bindings/python/setup.py > @@ -19,19 +19,53 @@ class build_ext(orig_build_ext): > rmtree(path.join(self.build_lib, "tests"), ignore_errors=True) > > > +with open("gpiod/version.py", "r") as fd: > + exec(fd.read()) > + > + > +sources = [ > + # gpiod Python bindings > + "gpiod/ext/chip.c", > + "gpiod/ext/common.c", > + "gpiod/ext/line-config.c", > + "gpiod/ext/line-settings.c", > + "gpiod/ext/module.c", > + "gpiod/ext/request.c", > +] > + > +if "USE_SYSTEM_GPIOD" in environ and environ["USE_SYSTEM_GPIOD"] == "1": > + libraries = ["gpiod"] > + include_dirs = ["gpiod"] > +else: > + sources += [ > + # gpiod library > + "lib/chip.c", > + "lib/chip-info.c", > + "lib/edge-event.c", > + "lib/info-event.c", > + "lib/internal.c", > + "lib/line-config.c", > + "lib/line-info.c", > + "lib/line-request.c", > + "lib/line-settings.c", > + "lib/misc.c", > + "lib/request-config.c", > + ] > + libraries = [] > + include_dirs = ["include", "lib", "gpiod/ext"] > + > + > gpiod_ext = Extension( > "gpiod._ext", > - sources=[ > - "gpiod/ext/chip.c", > - "gpiod/ext/common.c", > - "gpiod/ext/line-config.c", > - "gpiod/ext/line-settings.c", > - "gpiod/ext/module.c", > - "gpiod/ext/request.c", > - ], > + libraries=libraries, > + sources=sources, > define_macros=[("_GNU_SOURCE", "1")], > - libraries=["gpiod"], > - extra_compile_args=["-Wall", "-Wextra"], > + include_dirs=include_dirs, > + extra_compile_args=[ > + "-Wall", > + "-Wextra", > + '-DGPIOD_VERSION_STR="{}"'.format(__version__), > + ], > ) > > gpiosim_ext = Extension( > @@ -54,9 +88,6 @@ if "GPIOD_WITH_TESTS" in environ and environ["GPIOD_WITH_TESTS"] == "1": > extensions.append(gpiosim_ext) > extensions.append(procname_ext) > > -with open("gpiod/version.py", "r") as fd: > - exec(fd.read()) > - > setup( > name="libgpiod", > packages=find_packages(exclude=["tests", "tests.*"]), > -- > 2.34.1 >