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)) \
PYMODULE = $(PYLIBFDT_objdir)/_libfdt.so PYMODULE = $(PYLIBFDT_objdir)/_libfdt.so


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


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


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

11
pylibfdt/setup.py

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


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


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




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


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


libfdt_module = Extension( libfdt_module = Extension(
'_libfdt', '_libfdt',
@ -112,6 +108,5 @@ 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={'': objdir},
py_modules=['pylibfdt/libfdt'], py_modules=['pylibfdt/libfdt'],
) )

Loading…
Cancel
Save