blob: e442d5c24201b3dbc4147e0f270568a618aec3cf [file] [log] [blame]
Masahiro Yamada47ae5392017-10-17 13:42:43 +09001# Unfortunately setup.py below cannot handle srctree being ".." which it often
2# is. It fails with an error like:
3# Fatal error: can't create build/temp.linux-x86_64-2.7/../lib/libfdt/fdt.o:
4# No such file or directory
5# To fix this, use an absolute path.
6LIBFDT_srcdir = $(abspath $(srctree)/$(src)/../libfdt)
7
8include $(LIBFDT_srcdir)/Makefile.libfdt
9
10# Unfortunately setup.py (or actually the Python distutil implementation) puts
11# files into the same directory as the .i file. We cannot touch the source
12# directory, so we "ship" .i file into the objtree.
13PYLIBFDT_srcs = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_SRCS)) \
14 $(obj)/libfdt.i
15
Simon Glass85feff32022-07-30 20:57:11 -060016# create a version string compliant with PEP 440
17PEP_VERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(subst -,,$(EXTRAVERSION))
18
Masahiro Yamada47ae5392017-10-17 13:42:43 +090019quiet_cmd_pymod = PYMOD $@
Marek Vasut7f93db72018-05-18 09:56:53 +020020 cmd_pymod = unset CROSS_COMPILE; unset CFLAGS; \
21 CC="$(HOSTCC)" LDSHARED="$(HOSTCC) -shared " \
Masahiro Yamada47ae5392017-10-17 13:42:43 +090022 LDFLAGS="$(HOSTLDFLAGS)" \
Simon Glass85feff32022-07-30 20:57:11 -060023 VERSION="$(PEP_VERSION)" \
Masahiro Yamada47ae5392017-10-17 13:42:43 +090024 CPPFLAGS="$(HOSTCFLAGS) -I$(LIBFDT_srcdir)" OBJDIR=$(obj) \
25 SOURCES="$(PYLIBFDT_srcs)" \
26 SWIG_OPTS="-I$(LIBFDT_srcdir) -I$(LIBFDT_srcdir)/.." \
Simon Glass7ccca832019-10-31 07:42:59 -060027 $(PYTHON3) $< --quiet build_ext --inplace
Masahiro Yamada47ae5392017-10-17 13:42:43 +090028
Simon Glass237b3cc2021-03-25 06:40:48 +130029rebuild: $(src)/setup.py $(PYLIBFDT_srcs)
Simon Glass63592732020-07-09 18:39:33 -060030 @# Remove the library since otherwise Python doesn't seem to regenerate
31 @# the libfdt.py file if it is missing.
Simon Glass237b3cc2021-03-25 06:40:48 +130032 @rm -f $(obj)/_libfdt*.so
Masahiro Yamada47ae5392017-10-17 13:42:43 +090033 $(call if_changed,pymod)
Simon Glass237b3cc2021-03-25 06:40:48 +130034 @# Rename the file to _libfdt.so so this Makefile doesn't run every time
35 @if [ ! -e $(obj)/_libfdt.so ]; then \
36 mv $(obj)/_libfdt*.so $(obj)/_libfdt.so; \
37 fi
38
39$(obj)/_libfdt.so $(obj)/libfdt.py &: rebuild
Simon Glassf9736772021-03-28 11:27:18 +130040 @:
Masahiro Yamada47ae5392017-10-17 13:42:43 +090041
Simon Glass237b3cc2021-03-25 06:40:48 +130042always += _libfdt.so libfdt.py
Masahiro Yamada47ae5392017-10-17 13:42:43 +090043
44clean-files += libfdt.i _libfdt.so libfdt.py libfdt_wrap.c