pylibfdt: allow build out of tree
With meson, we have to support out-of-tree build. Introduce a --top-builddir option, which will default to the current directory to lookup generated filed such as version_gen.h and output directories. Other source paths are derived from the location of the setup.py script in the source tree. --build-lib is changed to be relative to the current directory, instead of relative to setup.py. This has less surprising results! Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <20201012073405.1682782-2-marcandre.lureau@redhat.com> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
3bc3a6b9fe
commit
05874d0821
2 changed files with 21 additions and 10 deletions
|
@ -10,7 +10,7 @@ PYLIBFDT_CLEANDIRS_L = build __pycache__
|
||||||
PYLIBFDT_CLEANDIRS = $(PYLIBFDT_CLEANDIRS_L:%=$(PYLIBFDT_dir)/%)
|
PYLIBFDT_CLEANDIRS = $(PYLIBFDT_CLEANDIRS_L:%=$(PYLIBFDT_dir)/%)
|
||||||
|
|
||||||
SETUP = $(PYLIBFDT_dir)/setup.py
|
SETUP = $(PYLIBFDT_dir)/setup.py
|
||||||
SETUPFLAGS =
|
SETUPFLAGS = --top-builddir .
|
||||||
|
|
||||||
ifndef V
|
ifndef V
|
||||||
SETUPFLAGS += --quiet
|
SETUPFLAGS += --quiet
|
||||||
|
@ -18,7 +18,7 @@ endif
|
||||||
|
|
||||||
$(PYMODULE): $(PYLIBFDT_srcs) $(LIBFDT_archive) $(SETUP) $(VERSION_FILE)
|
$(PYMODULE): $(PYLIBFDT_srcs) $(LIBFDT_archive) $(SETUP) $(VERSION_FILE)
|
||||||
@$(VECHO) PYMOD $@
|
@$(VECHO) PYMOD $@
|
||||||
$(PYTHON) $(SETUP) $(SETUPFLAGS) build_ext --build-lib=../$(PYLIBFDT_dir)
|
$(PYTHON) $(SETUP) $(SETUPFLAGS) build_ext --build-lib=$(PYLIBFDT_dir)
|
||||||
|
|
||||||
install_pylibfdt: $(PYMODULE)
|
install_pylibfdt: $(PYMODULE)
|
||||||
@$(VECHO) INSTALL-PYLIB
|
@$(VECHO) INSTALL-PYLIB
|
||||||
|
|
|
@ -19,23 +19,33 @@ import sys
|
||||||
VERSION_PATTERN = '^#define DTC_VERSION "DTC ([^"]*)"$'
|
VERSION_PATTERN = '^#define DTC_VERSION "DTC ([^"]*)"$'
|
||||||
|
|
||||||
|
|
||||||
|
def get_top_builddir():
|
||||||
|
if '--top-builddir' in sys.argv:
|
||||||
|
index = sys.argv.index('--top-builddir')
|
||||||
|
sys.argv.pop(index)
|
||||||
|
return sys.argv.pop(index)
|
||||||
|
else:
|
||||||
|
return os.getcwd()
|
||||||
|
|
||||||
|
|
||||||
|
srcdir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
||||||
|
top_builddir = get_top_builddir()
|
||||||
|
|
||||||
|
|
||||||
def get_version():
|
def get_version():
|
||||||
version_file = "../version_gen.h"
|
version_file = os.path.join(top_builddir, 'version_gen.h')
|
||||||
f = open(version_file, 'rt')
|
f = open(version_file, 'rt')
|
||||||
m = re.match(VERSION_PATTERN, f.readline())
|
m = re.match(VERSION_PATTERN, f.readline())
|
||||||
return m.group(1)
|
return m.group(1)
|
||||||
|
|
||||||
|
|
||||||
setupdir = os.path.dirname(os.path.abspath(sys.argv[0]))
|
|
||||||
os.chdir(setupdir)
|
|
||||||
|
|
||||||
libfdt_module = Extension(
|
libfdt_module = Extension(
|
||||||
'_libfdt',
|
'_libfdt',
|
||||||
sources=['libfdt.i'],
|
sources=[os.path.join(srcdir, 'libfdt.i')],
|
||||||
include_dirs=['../libfdt'],
|
include_dirs=[os.path.join(srcdir, '../libfdt')],
|
||||||
libraries=['fdt'],
|
libraries=['fdt'],
|
||||||
library_dirs=['../libfdt'],
|
library_dirs=[os.path.join(top_builddir, 'libfdt')],
|
||||||
swig_opts=['-I../libfdt'],
|
swig_opts=['-I' + os.path.join(srcdir, '../libfdt')],
|
||||||
)
|
)
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
|
@ -44,5 +54,6 @@ setup(
|
||||||
author='Simon Glass <sjg@chromium.org>',
|
author='Simon Glass <sjg@chromium.org>',
|
||||||
description='Python binding for libfdt',
|
description='Python binding for libfdt',
|
||||||
ext_modules=[libfdt_module],
|
ext_modules=[libfdt_module],
|
||||||
|
package_dir={'': srcdir},
|
||||||
py_modules=['libfdt'],
|
py_modules=['libfdt'],
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in a new issue