Browse Source

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>
main
Marc-André Lureau 4 years ago committed by David Gibson
parent
commit
05874d0821
  1. 4
      pylibfdt/Makefile.pylibfdt
  2. 27
      pylibfdt/setup.py

4
pylibfdt/Makefile.pylibfdt

@ -10,7 +10,7 @@ PYLIBFDT_CLEANDIRS_L = build __pycache__ @@ -10,7 +10,7 @@ PYLIBFDT_CLEANDIRS_L = build __pycache__
PYLIBFDT_CLEANDIRS = $(PYLIBFDT_CLEANDIRS_L:%=$(PYLIBFDT_dir)/%)

SETUP = $(PYLIBFDT_dir)/setup.py
SETUPFLAGS =
SETUPFLAGS = --top-builddir .

ifndef V
SETUPFLAGS += --quiet
@ -18,7 +18,7 @@ endif @@ -18,7 +18,7 @@ endif

$(PYMODULE): $(PYLIBFDT_srcs) $(LIBFDT_archive) $(SETUP) $(VERSION_FILE)
@$(VECHO) PYMOD $@
$(PYTHON) $(SETUP) $(SETUPFLAGS) build_ext --build-lib=../$(PYLIBFDT_dir)
$(PYTHON) $(SETUP) $(SETUPFLAGS) build_ext --build-lib=$(PYLIBFDT_dir)

install_pylibfdt: $(PYMODULE)
@$(VECHO) INSTALL-PYLIB

27
pylibfdt/setup.py

@ -19,23 +19,33 @@ import sys @@ -19,23 +19,33 @@ import sys
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():
version_file = "../version_gen.h"
version_file = os.path.join(top_builddir, 'version_gen.h')
f = open(version_file, 'rt')
m = re.match(VERSION_PATTERN, f.readline())
return m.group(1)


setupdir = os.path.dirname(os.path.abspath(sys.argv[0]))
os.chdir(setupdir)

libfdt_module = Extension(
'_libfdt',
sources=['libfdt.i'],
include_dirs=['../libfdt'],
sources=[os.path.join(srcdir, 'libfdt.i')],
include_dirs=[os.path.join(srcdir, '../libfdt')],
libraries=['fdt'],
library_dirs=['../libfdt'],
swig_opts=['-I../libfdt'],
library_dirs=[os.path.join(top_builddir, 'libfdt')],
swig_opts=['-I' + os.path.join(srcdir, '../libfdt')],
)

setup(
@ -44,5 +54,6 @@ setup( @@ -44,5 +54,6 @@ setup(
author='Simon Glass <sjg@chromium.org>',
description='Python binding for libfdt',
ext_modules=[libfdt_module],
package_dir={'': srcdir},
py_modules=['libfdt'],
)

Loading…
Cancel
Save