]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
pylibfdt: move pylibfdt to scripts/dtc/pylibfdt and refactor makefile
authorMasahiro Yamada <yamada.masahiro@socionext.com>
Tue, 17 Oct 2017 04:42:43 +0000 (13:42 +0900)
committerTom Rini <trini@konsulko.com>
Fri, 17 Nov 2017 12:43:32 +0000 (07:43 -0500)
The pylibfdt is used by dtoc (and, indirectly by binman), but there
is no reason why it must be generated in the tools/ directory.

Recently, U-Boot switched over to the bundled DTC, and the directory
structure under scripts/dtc/ now mirrors the upstream DTC project.
So, scripts/dtc/pylibfdt is the best location.

I also rewrote the Makefile in a cleaner Kbuild style.

The scripts from the upstream have been moved as follows:

  lib/libfdt/pylibfdt/setup.py -> scripts/dtc/pylibfdt/setup.py
  lib/libfdt/pylibfdt/libfdt.i -> scripts/dtc/pylibfdt/libfdt.i_shipped

The .i_shipped is coped to .i during building because the .i must be
located in the objtree when we build it out of tree.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Makefile
scripts/Makefile.spl
scripts/dtc/Makefile
scripts/dtc/pylibfdt/.gitignore [new file with mode: 0644]
scripts/dtc/pylibfdt/Makefile [new file with mode: 0644]
scripts/dtc/pylibfdt/libfdt.i_shipped [moved from lib/libfdt/pylibfdt/libfdt.i with 100% similarity]
scripts/dtc/pylibfdt/setup.py [moved from lib/libfdt/pylibfdt/setup.py with 100% similarity]
tools/.gitignore
tools/Makefile
tools/binman/binman.py

index 67f01ad7e4e88f5c2ae26a19839629633420a517..f94813d86b797b45c5a42073caa22e1c3ef2bebd 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1380,7 +1380,7 @@ $(timestamp_h): $(srctree)/Makefile FORCE
        $(call filechk,timestamp.h)
 
 checkbinman: tools
-       @if ! ( echo 'import libfdt' | ( PYTHONPATH=tools $(PYTHON) )); then \
+       @if ! ( echo 'import libfdt' | ( PYTHONPATH=scripts/dtc/pylibfdt $(PYTHON) )); then \
                echo >&2; \
                echo >&2 '*** binman needs the Python libfdt library.'; \
                echo >&2 '*** Either install it on your system, or try:'; \
index 49b27ac9267be60e55bd03fc41819fa15ec9694a..065bb259d529b0b23e27de449887f3c034de17ee 100644 (file)
@@ -257,7 +257,7 @@ quiet_cmd_fdtgrep = FDTGREP $@
 $(obj)/$(SPL_BIN).dtb: dts/dt.dtb $(objtree)/tools/fdtgrep FORCE
        $(call if_changed,fdtgrep)
 
-pythonpath = PYTHONPATH=tools
+pythonpath = PYTHONPATH=scripts/dtc/pylibfdt
 
 quiet_cmd_dtocc = DTOC C  $@
 cmd_dtocc = $(pythonpath) $(srctree)/tools/dtoc/dtoc -d $(obj)/$(SPL_BIN).dtb -o $@ platdata
@@ -381,7 +381,7 @@ ifneq ($(cmd_files),)
 endif
 
 checkdtoc: tools
-       @if ! ( echo 'import libfdt' | ( PYTHONPATH=tools $(PYTHON) )); then \
+       @if ! ( echo 'import libfdt' | ( PYTHONPATH=scripts/dtc/pylibfdt $(PYTHON) )); then \
                echo '*** dtoc needs the Python libfdt library. Either '; \
                echo '*** install it on your system, or try:'; \
                echo '***'; \
index 2a48022c41e7d184660c59de87fa7dce0b345d4b..f4a16ed2a5f37db52cd01d60fa7056163fce0233 100644 (file)
@@ -29,3 +29,6 @@ $(obj)/dtc-lexer.lex.o: $(obj)/dtc-parser.tab.h
 
 # generated files need to be cleaned explicitly
 clean-files    := dtc-lexer.lex.c dtc-parser.tab.c dtc-parser.tab.h
+
+# Added for U-Boot
+subdir-y += pylibfdt
diff --git a/scripts/dtc/pylibfdt/.gitignore b/scripts/dtc/pylibfdt/.gitignore
new file mode 100644 (file)
index 0000000..033f23d
--- /dev/null
@@ -0,0 +1,4 @@
+/_libfdt.so
+/libfdt.py
+/libfdt.pyc
+/libfdt_wrap.c
diff --git a/scripts/dtc/pylibfdt/Makefile b/scripts/dtc/pylibfdt/Makefile
new file mode 100644 (file)
index 0000000..01d5e0f
--- /dev/null
@@ -0,0 +1,30 @@
+# Unfortunately setup.py below cannot handle srctree being ".." which it often
+# is. It fails with an error like:
+# Fatal error: can't create build/temp.linux-x86_64-2.7/../lib/libfdt/fdt.o:
+#    No such file or directory
+# To fix this, use an absolute path.
+LIBFDT_srcdir = $(abspath $(srctree)/$(src)/../libfdt)
+
+include $(LIBFDT_srcdir)/Makefile.libfdt
+
+# Unfortunately setup.py (or actually the Python distutil implementation) puts
+# files into the same directory as the .i file. We cannot touch the source
+# directory, so we "ship" .i file into the objtree.
+PYLIBFDT_srcs = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_SRCS)) \
+               $(obj)/libfdt.i
+
+quiet_cmd_pymod = PYMOD   $@
+      cmd_pymod = unset CC; unset CROSS_COMPILE; unset CFLAGS;\
+               LDFLAGS="$(HOSTLDFLAGS)" \
+               VERSION="u-boot-$(UBOOTVERSION)" \
+               CPPFLAGS="$(HOSTCFLAGS) -I$(LIBFDT_srcdir)" OBJDIR=$(obj) \
+               SOURCES="$(PYLIBFDT_srcs)" \
+               SWIG_OPTS="-I$(LIBFDT_srcdir) -I$(LIBFDT_srcdir)/.." \
+               $(PYTHON) $< --quiet build_ext --inplace
+
+$(obj)/_libfdt.so: $(src)/setup.py $(PYLIBFDT_srcs) FORCE
+       $(call if_changed,pymod)
+
+always += _libfdt.so
+
+clean-files += libfdt.i _libfdt.so libfdt.py libfdt_wrap.c
index 5293d44697ca3784b93d8d25973d5cbafc962d19..6a487d22027aa6838eb1fbc2335473a731863b62 100644 (file)
@@ -1,4 +1,3 @@
-/_libfdt.so
 /atmel_pmecc_params
 /bin2header
 /bmp_logo
@@ -17,9 +16,6 @@
 /img2srec
 /kwboot
 /lib/
-/libfdt.py
-/libfdt.pyc
-/libfdt_wrap.c
 /mips-relocs
 /mkenvimage
 /mkexynosspl
index 5db2a542252a8a695fb75077fdb7a76270f8ec8c..2b87e184f3c4dcbfd27a2f55727a44d15857f8f5 100644 (file)
@@ -63,15 +63,6 @@ LIBFDT_CSRCS := fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c  \
                        fdt_empty_tree.c fdt_addresses.c fdt_overlay.c \
                        fdt_region.c
 
-# Unfortunately setup.py below cannot handle srctree being ".." which it often
-# is. It fails with an error like:
-# Fatal error: can't create build/temp.linux-x86_64-2.7/../lib/libfdt/fdt.o:
-#    No such file or directory
-# To fix this, use an absolute path.
-libfdt_tree := $(shell readlink -f $(srctree)/lib/libfdt)
-
-LIBFDT_SRCS := $(addprefix $(libfdt_tree)/, $(LIBFDT_CSRCS))
-LIBFDT_SWIG := $(addprefix $(libfdt_tree)/, pylibfdt/libfdt.i)
 LIBFDT_OBJS := $(addprefix lib/libfdt/, $(patsubst %.c, %.o, $(LIBFDT_CSRCS)))
 
 RSA_OBJS-$(CONFIG_FIT_SIGNATURE) := $(addprefix lib/rsa/, \
@@ -123,23 +114,6 @@ mkimage-objs   := $(dumpimage-mkimage-objs) mkimage.o
 fit_info-objs   := $(dumpimage-mkimage-objs) fit_info.o
 fit_check_sign-objs   := $(dumpimage-mkimage-objs) fit_check_sign.o
 
-# Unfortunately setup.py (or actually the Python distutil implementation)
-# puts files into the same directory as the .i file. We cannot touch the source
-# directory, so we copy the .i file into the tools/ build subdirectory before
-# calling setup. This directory is safe to write to. This ensures that we get
-# all three files in $(obj)/tools: _libfdt.so, libfdt.py and libfdt_wrap.c
-# The latter is a temporary file which we could actually remove.
-tools/_libfdt.so: $(LIBFDT_SRCS) $(LIBFDT_SWIG)
-       $(Q)cp $(LIBFDT_SWIG) tools/.
-       $(Q)unset CC; \
-       unset CROSS_COMPILE; \
-       LDFLAGS="$(HOSTLDFLAGS)" CFLAGS= VERSION="u-boot-$(UBOOTVERSION)" \
-               CPPFLAGS="$(_hostc_flags)" OBJDIR=tools \
-               SOURCES="$(LIBFDT_SRCS) tools/libfdt.i" \
-               SWIG_OPTS="-I$(srctree)/lib/libfdt -I$(srctree)/lib" \
-               $(PYTHON) $(libfdt_tree)/pylibfdt/setup.py --quiet build_ext \
-                       --build-lib tools
-
 ifneq ($(CONFIG_MX23)$(CONFIG_MX28),)
 # Add CONFIG_MXS into host CFLAGS, so we can check whether or not register
 # the mxsimage support within tools/mxsimage.c .
@@ -231,10 +205,6 @@ clean-dirs := lib common
 
 always := $(hostprogs-y)
 
-# Build a libfdt Python module if swig is available
-# Use 'sudo apt-get install swig libpython-dev' to enable this
-always += $(if $(shell which swig 2> /dev/null),_libfdt.so)
-
 # Generated LCD/video logo
 LOGO_H = $(objtree)/include/bmp_logo.h
 LOGO_DATA_H = $(objtree)/include/bmp_logo_data.h
index 09dc36a3f7913b356c1d5eaf0a68ad76eeaf61da..e75a59d9517d23304a6b7fd7f9c680ad659a7d5e 100755 (executable)
@@ -21,7 +21,7 @@ for dirname in ['../patman', '../dtoc', '..']:
     sys.path.insert(0, os.path.join(our_path, dirname))
 
 # Bring in the libfdt module
-sys.path.insert(0, 'tools')
+sys.path.insert(0, 'scripts/dtc/pylibfdt')
 
 # Also allow entry-type modules to be brought in from the etype directory.
 sys.path.insert(0, os.path.join(our_path, 'etype'))