Browse Source

pylibfdt: Correctly set build output directory

Our Makefile currently passes PYLIBFDT_objdir into setup.py in an attempt
to set the correct place to put the Python extension module output.  But
that gets passed in the 'package_dir' map in distutils.

But that's basically not what package_dir controls.  What actually makes us
find the module in the right place is the --inplace passed to setup.py
(causing the module to go into the current directory), and the following
'mv' in the Makefile to move it into the right final location.

We can simplify setup.py by dropping the useless objdir stuff, and get the
module put in the right place straight way by instead using the --build-lib
setup.py option.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Simon Glass <sjg@chromium.org>
main
David Gibson 6 years ago
parent
commit
dd695d6afb
  1. 6
      pylibfdt/Makefile.pylibfdt
  2. 11
      pylibfdt/setup.py

6
pylibfdt/Makefile.pylibfdt

@ -6,15 +6,13 @@ PYLIBFDT_srcs = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_SRCS)) \ @@ -6,15 +6,13 @@ PYLIBFDT_srcs = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_SRCS)) \
PYMODULE = $(PYLIBFDT_objdir)/_libfdt.so

define run_setup
SOURCES="$(1)" CPPFLAGS="$(CPPFLAGS)" OBJDIR="$(PYLIBFDT_objdir)"
VERSION="$(dtc_version)"
SOURCES="$(1)" CPPFLAGS="$(CPPFLAGS)" VERSION="$(dtc_version)"
$(PYLIBFDT_objdir)/setup.py --quiet $(2)
endef

$(PYMODULE): $(PYLIBFDT_srcs)
@$(VECHO) PYMOD $@
$(call run_setup, $^, build_ext --inplace)
mv _libfdt.so $@
$(call run_setup, $^, build_ext --build-lib=$(PYLIBFDT_objdir))

install_pylibfdt: $(PYMODULE)
$(VECHO) INSTALL-PYLIB; \

11
pylibfdt/setup.py

@ -7,7 +7,6 @@ Written by Simon Glass <sjg@chromium.org> @@ -7,7 +7,6 @@ Written by Simon Glass <sjg@chromium.org>

Files to be built into the extension are provided in SOURCES
C flags to use are provided in CPPFLAGS
Object file directory is provided in OBJDIR
Version is provided in VERSION

If these variables are not given they are parsed from the Makefiles. This
@ -73,7 +72,6 @@ def GetEnvFromMakefiles(): @@ -73,7 +72,6 @@ def GetEnvFromMakefiles():
Version string
List of files to build
List of extra C preprocessor flags needed
Object directory to use (always '')
"""
basedir = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0])))
makevars = ParseMakefile(os.path.join(basedir, 'Makefile'))
@ -84,21 +82,19 @@ def GetEnvFromMakefiles(): @@ -84,21 +82,19 @@ def GetEnvFromMakefiles():
files = [os.path.join(basedir, 'libfdt', fname) for fname in files]
files.append('pylibfdt/libfdt.i')
cflags = ['-I%s/libfdt' % basedir]
objdir = ''
return version, files, cflags, objdir
return version, files, cflags


progname = sys.argv[0]
files = os.environ.get('SOURCES', '').split()
cflags = os.environ.get('CPPFLAGS', '').split()
objdir = os.environ.get('OBJDIR')
version = os.environ.get('VERSION')

# If we were called directly rather than through our Makefile (which is often
# the case with Python module installation), read the settings from the
# Makefile.
if not all((version, files, cflags, objdir)):
version, files, cflags, objdir = GetEnvFromMakefiles()
if not all((version, files, cflags)):
version, files, cflags= GetEnvFromMakefiles()

libfdt_module = Extension(
'_libfdt',
@ -112,6 +108,5 @@ setup( @@ -112,6 +108,5 @@ setup(
author='Simon Glass <sjg@chromium.org>',
description='Python binding for libfdt',
ext_modules=[libfdt_module],
package_dir={'': objdir},
py_modules=['pylibfdt/libfdt'],
)

Loading…
Cancel
Save