From addf968c7321132a8c659e06cc06c76534ec31f5 Mon Sep 17 00:00:00 2001 From: Joerg Faschingbauer Date: Wed, 18 Jan 2023 10:11:45 +0100 Subject: [PATCH] bindings: python: fix out-of-tree build Makefile.am delegates the build of the python extension to its setup.py file, which references the extension .c files relative to the source dir. This makes it impossible to build in a directory that is different from the source directory (for example, for PC and ARM but from the same source). * Invoke setup.py from $(srcdir) * Modify setup.py to pick up .c files relative from setup.py's own directory. Signed-off-by: Joerg Faschingbauer Signed-off-by: Bartosz Golaszewski --- bindings/python/Makefile.am | 4 ++-- bindings/python/setup.py | 23 +++++++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/bindings/python/Makefile.am b/bindings/python/Makefile.am index 3212a8f..9fb2e95 100644 --- a/bindings/python/Makefile.am +++ b/bindings/python/Makefile.am @@ -12,13 +12,13 @@ endif all-local: GPIOD_VERSION_STRING=$(VERSION_STR) \ GPIOD_WITH_TESTS=$(BUILD_TESTS) \ - $(PYTHON) setup.py build_ext --inplace \ + $(PYTHON) $(srcdir)/setup.py build_ext --inplace \ --include-dirs=$(top_srcdir)/include/:$(top_srcdir)/tests/gpiosim/ \ --library-dirs=$(top_builddir)/lib/.libs/:$(top_srcdir)/tests/gpiosim/.libs/ install-exec-local: GPIOD_WITH_TESTS= \ - $(PYTHON) setup.py install --prefix=$(prefix) + $(PYTHON) $(srcdir)/setup.py install --prefix=$(prefix) SUBDIRS = gpiod diff --git a/bindings/python/setup.py b/bindings/python/setup.py index a951069..e748295 100644 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -1,18 +1,21 @@ # SPDX-License-Identifier: GPL-2.0-or-later # SPDX-FileCopyrightText: 2022 Bartosz Golaszewski -from os import environ +from os import environ, path from setuptools import setup, Extension, find_packages +def src(filename): + return path.join(path.dirname(__file__), filename) + 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", + src("gpiod/ext/chip.c"), + src("gpiod/ext/common.c"), + src("gpiod/ext/line-config.c"), + src("gpiod/ext/line-settings.c"), + src("gpiod/ext/module.c"), + src("gpiod/ext/request.c"), ], define_macros=[("_GNU_SOURCE", "1")], libraries=["gpiod"], @@ -21,7 +24,7 @@ gpiod_ext = Extension( gpiosim_ext = Extension( "tests.gpiosim._ext", - sources=["tests/gpiosim/ext.c"], + sources=[src("tests/gpiosim/ext.c")], define_macros=[("_GNU_SOURCE", "1")], libraries=["gpiosim"], extra_compile_args=["-Wall", "-Wextra"], @@ -29,7 +32,7 @@ gpiosim_ext = Extension( procname_ext = Extension( "tests.procname._ext", - sources=["tests/procname/ext.c"], + sources=[src("tests/procname/ext.c")], define_macros=[("_GNU_SOURCE", "1")], extra_compile_args=["-Wall", "-Wextra"], ) @@ -39,7 +42,7 @@ 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: +with open(src("gpiod/version.py"), "r") as fd: exec(fd.read()) setup( -- 2.30.2