Blame Makefile

Packit Service 0ee8e1
# SPDX-License-Identifier: GPL-2.0-or-later
Packit 2ad57b
#
Packit 2ad57b
# Device Tree Compiler
Packit 2ad57b
#
Packit 2ad57b
Packit 2ad57b
#
Packit 2ad57b
# Version information will be constructed in this order:
Packit 2ad57b
# EXTRAVERSION might be "-rc", for example.
Packit 2ad57b
# LOCAL_VERSION is likely from command line.
Packit 2ad57b
# CONFIG_LOCALVERSION from some future config system.
Packit 2ad57b
#
Packit 2ad57b
VERSION = 1
Packit Service 0ee8e1
PATCHLEVEL = 6
Packit Service 0ee8e1
SUBLEVEL = 0
Packit 2ad57b
EXTRAVERSION =
Packit 2ad57b
LOCAL_VERSION =
Packit 2ad57b
CONFIG_LOCALVERSION =
Packit 2ad57b
Packit Service 0ee8e1
# Control the assumptions made (e.g. risking security issues) in the code.
Packit Service 0ee8e1
# See libfdt_internal.h for details
Packit Service 0ee8e1
ASSUME_MASK ?= 0
Packit Service 0ee8e1
Packit Service 0ee8e1
CPPFLAGS = -I libfdt -I . -DFDT_ASSUME_MASK=$(ASSUME_MASK)
Packit 2ad57b
WARNINGS = -Wall -Wpointer-arith -Wcast-qual -Wnested-externs \
Packit 2ad57b
	-Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wshadow
Packit Service 0ee8e1
CFLAGS = -g -Os $(SHAREDLIB_CFLAGS) -Werror $(WARNINGS) $(EXTRA_CFLAGS)
Packit 2ad57b
Packit 2ad57b
BISON = bison
Packit 2ad57b
LEX = flex
Packit 2ad57b
SWIG = swig
Packit 2ad57b
PKG_CONFIG ?= pkg-config
Packit Service 0ee8e1
PYTHON ?= python3
Packit 2ad57b
Packit 2ad57b
INSTALL = /usr/bin/install
Packit Service 0ee8e1
INSTALL_PROGRAM = $(INSTALL)
Packit Service 0ee8e1
INSTALL_LIB = $(INSTALL)
Packit Service 0ee8e1
INSTALL_DATA = $(INSTALL) -m 644
Packit Service 0ee8e1
INSTALL_SCRIPT = $(INSTALL)
Packit 2ad57b
DESTDIR =
Packit 2ad57b
PREFIX = $(HOME)
Packit 2ad57b
BINDIR = $(PREFIX)/bin
Packit 2ad57b
LIBDIR = $(PREFIX)/lib
Packit 2ad57b
INCLUDEDIR = $(PREFIX)/include
Packit 2ad57b
Packit 2ad57b
HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
Packit 2ad57b
	    sed -e 's/\(cygwin\|msys\).*/\1/')
Packit 2ad57b
Packit Service 0ee8e1
NO_PYTHON ?= 0
Packit Service 0ee8e1
Packit Service 0ee8e1
NO_VALGRIND := $(shell $(PKG_CONFIG) --exists valgrind; echo $$?)
Packit Service 0ee8e1
ifeq ($(NO_VALGRIND),1)
Packit Service 0ee8e1
	CPPFLAGS += -DNO_VALGRIND
Packit Service 0ee8e1
else
Packit Service 0ee8e1
	CFLAGS += $(shell $(PKG_CONFIG) --cflags valgrind)
Packit Service 0ee8e1
endif
Packit Service 0ee8e1
Packit Service 0ee8e1
NO_YAML := $(shell $(PKG_CONFIG) --exists yaml-0.1; echo $$?)
Packit Service 0ee8e1
ifeq ($(NO_YAML),1)
Packit Service 0ee8e1
	CFLAGS += -DNO_YAML
Packit Service 0ee8e1
else
Packit Service 0ee8e1
	LDLIBS_dtc += $(shell $(PKG_CONFIG) --libs yaml-0.1)
Packit Service 0ee8e1
endif
Packit Service 0ee8e1
Packit 2ad57b
ifeq ($(HOSTOS),darwin)
Packit 2ad57b
SHAREDLIB_EXT     = dylib
Packit 2ad57b
SHAREDLIB_CFLAGS  = -fPIC
Packit 2ad57b
SHAREDLIB_LDFLAGS = -fPIC -dynamiclib -Wl,-install_name -Wl,
Packit 2ad57b
else ifeq ($(HOSTOS),$(filter $(HOSTOS),msys cygwin))
Packit 2ad57b
SHAREDLIB_EXT     = so
Packit 2ad57b
SHAREDLIB_CFLAGS  =
Packit 2ad57b
SHAREDLIB_LDFLAGS = -shared -Wl,--version-script=$(LIBFDT_version) -Wl,-soname,
Packit 2ad57b
else
Packit 2ad57b
SHAREDLIB_EXT     = so
Packit 2ad57b
SHAREDLIB_CFLAGS  = -fPIC
Packit 2ad57b
SHAREDLIB_LDFLAGS = -fPIC -shared -Wl,--version-script=$(LIBFDT_version) -Wl,-soname,
Packit 2ad57b
endif
Packit 2ad57b
Packit 2ad57b
#
Packit 2ad57b
# Overall rules
Packit 2ad57b
#
Packit 2ad57b
ifdef V
Packit 2ad57b
VECHO = :
Packit 2ad57b
else
Packit 2ad57b
VECHO = echo "	"
Packit 2ad57b
ARFLAGS = rc
Packit 2ad57b
.SILENT:
Packit 2ad57b
endif
Packit 2ad57b
Packit 2ad57b
NODEPTARGETS = clean
Packit 2ad57b
ifeq ($(MAKECMDGOALS),)
Packit 2ad57b
DEPTARGETS = all
Packit 2ad57b
else
Packit 2ad57b
DEPTARGETS = $(filter-out $(NODEPTARGETS),$(MAKECMDGOALS))
Packit 2ad57b
endif
Packit 2ad57b
Packit 2ad57b
#
Packit 2ad57b
# Rules for versioning
Packit 2ad57b
#
Packit 2ad57b
Packit 2ad57b
DTC_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
Packit 2ad57b
VERSION_FILE = version_gen.h
Packit 2ad57b
Packit 2ad57b
CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
Packit 2ad57b
	  else if [ -x /bin/bash ]; then echo /bin/bash; \
Packit 2ad57b
	  else echo sh; fi ; fi)
Packit 2ad57b
Packit 2ad57b
nullstring :=
Packit 2ad57b
space	:= $(nullstring) # end of line
Packit 2ad57b
Packit 2ad57b
localver_config = $(subst $(space),, $(string) \
Packit 2ad57b
			      $(patsubst "%",%,$(CONFIG_LOCALVERSION)))
Packit 2ad57b
Packit 2ad57b
localver_cmd = $(subst $(space),, $(string) \
Packit 2ad57b
			      $(patsubst "%",%,$(LOCALVERSION)))
Packit 2ad57b
Packit 2ad57b
localver_scm = $(shell $(CONFIG_SHELL) ./scripts/setlocalversion)
Packit 2ad57b
localver_full  = $(localver_config)$(localver_cmd)$(localver_scm)
Packit 2ad57b
Packit 2ad57b
dtc_version = $(DTC_VERSION)$(localver_full)
Packit 2ad57b
Packit 2ad57b
# Contents of the generated version file.
Packit 2ad57b
define filechk_version
Packit 2ad57b
	(echo "#define DTC_VERSION \"DTC $(dtc_version)\""; )
Packit 2ad57b
endef
Packit 2ad57b
Packit 2ad57b
define filechk
Packit 2ad57b
	set -e;					\
Packit 2ad57b
	echo '	CHK $@';			\
Packit 2ad57b
	mkdir -p $(dir $@);			\
Packit 2ad57b
	$(filechk_$(1)) < $< > $@.tmp;		\
Packit 2ad57b
	if [ -r $@ ] && cmp -s $@ $@.tmp; then	\
Packit 2ad57b
		rm -f $@.tmp;			\
Packit 2ad57b
	else					\
Packit 2ad57b
		echo '	UPD $@';		\
Packit 2ad57b
		mv -f $@.tmp $@;		\
Packit 2ad57b
	fi;
Packit 2ad57b
endef
Packit 2ad57b
Packit 2ad57b
Packit 2ad57b
include Makefile.convert-dtsv0
Packit 2ad57b
include Makefile.dtc
Packit 2ad57b
include Makefile.utils
Packit 2ad57b
Packit 2ad57b
BIN += convert-dtsv0
Packit 2ad57b
BIN += dtc
Packit 2ad57b
BIN += fdtdump
Packit 2ad57b
BIN += fdtget
Packit 2ad57b
BIN += fdtput
Packit 2ad57b
BIN += fdtoverlay
Packit 2ad57b
Packit 2ad57b
SCRIPTS = dtdiff
Packit 2ad57b
Packit 2ad57b
all: $(BIN) libfdt
Packit 2ad57b
Packit Service 0ee8e1
# We need both Python and swig to build/install pylibfdt.
Packit Service 0ee8e1
# This builds the given make ${target} if those deps are found.
Packit Service 0ee8e1
check_python_deps = \
Packit Service 0ee8e1
	if $(PKG_CONFIG) --cflags $(PYTHON) >/dev/null 2>&1; then \
Packit 2ad57b
		if which swig >/dev/null 2>&1; then \
Packit 2ad57b
			can_build=yes; \
Packit 2ad57b
		fi; \
Packit 2ad57b
	fi; \
Packit Service 0ee8e1
	if [ "$${can_build}" = "yes" ]; then \
Packit Service 0ee8e1
		$(MAKE) $${target}; \
Packit 2ad57b
	else \
Packit Service 0ee8e1
		echo "\#\# Skipping pylibfdt (install python dev and swig to build)"; \
Packit Service 0ee8e1
	fi ;
Packit 2ad57b
Packit Service 0ee8e1
.PHONY: maybe_pylibfdt
Packit Service 0ee8e1
maybe_pylibfdt: FORCE
Packit Service 0ee8e1
	target=pylibfdt; $(check_python_deps)
Packit Service 0ee8e1
Packit Service 0ee8e1
ifeq ($(NO_PYTHON),0)
Packit 2ad57b
all: maybe_pylibfdt
Packit 2ad57b
endif
Packit 2ad57b
Packit 2ad57b
Packit 2ad57b
ifneq ($(DEPTARGETS),)
Packit 2ad57b
-include $(DTC_OBJS:%.o=%.d)
Packit 2ad57b
-include $(CONVERT_OBJS:%.o=%.d)
Packit 2ad57b
-include $(FDTDUMP_OBJS:%.o=%.d)
Packit 2ad57b
-include $(FDTGET_OBJS:%.o=%.d)
Packit 2ad57b
-include $(FDTPUT_OBJS:%.o=%.d)
Packit 2ad57b
-include $(FDTOVERLAY_OBJS:%.o=%.d)
Packit 2ad57b
endif
Packit 2ad57b
Packit 2ad57b
Packit 2ad57b
Packit 2ad57b
#
Packit 2ad57b
# Rules for libfdt
Packit 2ad57b
#
Packit Service 0ee8e1
LIBFDT_dir = libfdt
Packit Service 0ee8e1
LIBFDT_archive = $(LIBFDT_dir)/libfdt.a
Packit Service 0ee8e1
LIBFDT_lib = $(LIBFDT_dir)/$(LIBFDT_LIB)
Packit Service 0ee8e1
LIBFDT_include = $(addprefix $(LIBFDT_dir)/,$(LIBFDT_INCLUDES))
Packit Service 0ee8e1
LIBFDT_version = $(addprefix $(LIBFDT_dir)/,$(LIBFDT_VERSION))
Packit 2ad57b
Packit Service 0ee8e1
include $(LIBFDT_dir)/Makefile.libfdt
Packit 2ad57b
Packit 2ad57b
.PHONY: libfdt
Packit 2ad57b
libfdt: $(LIBFDT_archive) $(LIBFDT_lib)
Packit 2ad57b
Packit Service 0ee8e1
$(LIBFDT_archive): $(addprefix $(LIBFDT_dir)/,$(LIBFDT_OBJS))
Packit 2ad57b
Packit Service 0ee8e1
$(LIBFDT_lib): $(addprefix $(LIBFDT_dir)/,$(LIBFDT_OBJS)) $(LIBFDT_version)
Packit Service 0ee8e1
	@$(VECHO) LD $@
Packit Service 0ee8e1
	$(CC) $(LDFLAGS) $(SHAREDLIB_LDFLAGS)$(LIBFDT_soname) -o $(LIBFDT_lib) \
Packit Service 0ee8e1
		$(addprefix $(LIBFDT_dir)/,$(LIBFDT_OBJS))
Packit Service 0ee8e1
	ln -sf $(LIBFDT_LIB) $(LIBFDT_dir)/$(LIBFDT_soname)
Packit 2ad57b
Packit 2ad57b
ifneq ($(DEPTARGETS),)
Packit Service 0ee8e1
-include $(LIBFDT_OBJS:%.o=$(LIBFDT_dir)/%.d)
Packit 2ad57b
endif
Packit 2ad57b
Packit 2ad57b
# This stops make from generating the lex and bison output during
Packit 2ad57b
# auto-dependency computation, but throwing them away as an
Packit 2ad57b
# intermediate target and building them again "for real"
Packit 2ad57b
.SECONDARY: $(DTC_GEN_SRCS) $(CONVERT_GEN_SRCS)
Packit 2ad57b
Packit 2ad57b
install-bin: all $(SCRIPTS)
Packit 2ad57b
	@$(VECHO) INSTALL-BIN
Packit 2ad57b
	$(INSTALL) -d $(DESTDIR)$(BINDIR)
Packit Service 0ee8e1
	$(INSTALL_PROGRAM) $(BIN) $(DESTDIR)$(BINDIR)
Packit Service 0ee8e1
	$(INSTALL_SCRIPT) $(SCRIPTS) $(DESTDIR)$(BINDIR)
Packit 2ad57b
Packit 2ad57b
install-lib: all
Packit 2ad57b
	@$(VECHO) INSTALL-LIB
Packit 2ad57b
	$(INSTALL) -d $(DESTDIR)$(LIBDIR)
Packit Service 0ee8e1
	$(INSTALL_LIB) $(LIBFDT_lib) $(DESTDIR)$(LIBDIR)
Packit 2ad57b
	ln -sf $(notdir $(LIBFDT_lib)) $(DESTDIR)$(LIBDIR)/$(LIBFDT_soname)
Packit 2ad57b
	ln -sf $(LIBFDT_soname) $(DESTDIR)$(LIBDIR)/libfdt.$(SHAREDLIB_EXT)
Packit Service 0ee8e1
	$(INSTALL_DATA) $(LIBFDT_archive) $(DESTDIR)$(LIBDIR)
Packit 2ad57b
Packit 2ad57b
install-includes:
Packit 2ad57b
	@$(VECHO) INSTALL-INC
Packit 2ad57b
	$(INSTALL) -d $(DESTDIR)$(INCLUDEDIR)
Packit Service 0ee8e1
	$(INSTALL_DATA) $(LIBFDT_include) $(DESTDIR)$(INCLUDEDIR)
Packit 2ad57b
Packit 2ad57b
install: install-bin install-lib install-includes
Packit 2ad57b
Packit Service 0ee8e1
.PHONY: maybe_install_pylibfdt
Packit Service 0ee8e1
maybe_install_pylibfdt: FORCE
Packit Service 0ee8e1
	target=install_pylibfdt; $(check_python_deps)
Packit Service 0ee8e1
Packit Service 0ee8e1
ifeq ($(NO_PYTHON),0)
Packit Service 0ee8e1
install: maybe_install_pylibfdt
Packit 2ad57b
endif
Packit 2ad57b
Packit 2ad57b
$(VERSION_FILE): Makefile FORCE
Packit 2ad57b
	$(call filechk,version)
Packit 2ad57b
Packit 2ad57b
Packit 2ad57b
dtc: $(DTC_OBJS)
Packit 2ad57b
Packit 2ad57b
convert-dtsv0: $(CONVERT_OBJS)
Packit 2ad57b
	@$(VECHO) LD $@
Packit 2ad57b
	$(LINK.c) -o $@ $^
Packit 2ad57b
Packit 2ad57b
fdtdump:	$(FDTDUMP_OBJS)
Packit 2ad57b
Packit Service 0ee8e1
fdtget:	$(FDTGET_OBJS) $(LIBFDT_lib)
Packit 2ad57b
Packit Service 0ee8e1
fdtput:	$(FDTPUT_OBJS) $(LIBFDT_lib)
Packit 2ad57b
Packit Service 0ee8e1
fdtoverlay: $(FDTOVERLAY_OBJS) $(LIBFDT_lib)
Packit 2ad57b
Packit 2ad57b
dist:
Packit 2ad57b
	git archive --format=tar --prefix=dtc-$(dtc_version)/ HEAD \
Packit 2ad57b
		> ../dtc-$(dtc_version).tar
Packit 2ad57b
	cat ../dtc-$(dtc_version).tar | \
Packit 2ad57b
		gzip -9 > ../dtc-$(dtc_version).tar.gz
Packit 2ad57b
Packit 2ad57b
Packit 2ad57b
#
Packit 2ad57b
# Rules for pylibfdt
Packit 2ad57b
#
Packit Service 0ee8e1
PYLIBFDT_dir = pylibfdt
Packit 2ad57b
Packit Service 0ee8e1
include $(PYLIBFDT_dir)/Makefile.pylibfdt
Packit 2ad57b
Packit 2ad57b
.PHONY: pylibfdt
Packit Service 0ee8e1
pylibfdt: $(PYLIBFDT_dir)/_libfdt.so
Packit 2ad57b
Packit 2ad57b
#
Packit 2ad57b
# Release signing and uploading
Packit 2ad57b
# This is for maintainer convenience, don't try this at home.
Packit 2ad57b
#
Packit 2ad57b
ifeq ($(MAINTAINER),y)
Packit 2ad57b
GPG = gpg2
Packit 2ad57b
KUP = kup
Packit 2ad57b
KUPDIR = /pub/software/utils/dtc
Packit 2ad57b
Packit 2ad57b
kup: dist
Packit 2ad57b
	$(GPG) --detach-sign --armor -o ../dtc-$(dtc_version).tar.sign \
Packit 2ad57b
		../dtc-$(dtc_version).tar
Packit 2ad57b
	$(KUP) put ../dtc-$(dtc_version).tar.gz ../dtc-$(dtc_version).tar.sign \
Packit 2ad57b
		$(KUPDIR)/dtc-$(dtc_version).tar.gz
Packit 2ad57b
endif
Packit 2ad57b
Packit 2ad57b
tags: FORCE
Packit 2ad57b
	rm -f tags
Packit 2ad57b
	find . \( -name tests -type d -prune \) -o \
Packit 2ad57b
	       \( ! -name '*.tab.[ch]' ! -name '*.lex.c' \
Packit 2ad57b
	       -name '*.[chly]' -type f -print \) | xargs ctags -a
Packit 2ad57b
Packit 2ad57b
#
Packit 2ad57b
# Testsuite rules
Packit 2ad57b
#
Packit 2ad57b
TESTS_PREFIX=tests/
Packit 2ad57b
Packit 2ad57b
TESTS_BIN += dtc
Packit 2ad57b
TESTS_BIN += convert-dtsv0
Packit 2ad57b
TESTS_BIN += fdtput
Packit 2ad57b
TESTS_BIN += fdtget
Packit 2ad57b
TESTS_BIN += fdtdump
Packit 2ad57b
TESTS_BIN += fdtoverlay
Packit Service 0ee8e1
ifeq ($(NO_PYTHON),0)
Packit 2ad57b
TESTS_PYLIBFDT += maybe_pylibfdt
Packit 2ad57b
endif
Packit 2ad57b
Packit 2ad57b
include tests/Makefile.tests
Packit 2ad57b
Packit 2ad57b
#
Packit 2ad57b
# Clean rules
Packit 2ad57b
#
Packit 2ad57b
STD_CLEANFILES = *~ *.o *.$(SHAREDLIB_EXT) *.d *.a *.i *.s core a.out vgcore.* \
Packit 2ad57b
	*.tab.[ch] *.lex.c *.output
Packit 2ad57b
Packit 2ad57b
clean: libfdt_clean pylibfdt_clean tests_clean
Packit 2ad57b
	@$(VECHO) CLEAN
Packit 2ad57b
	rm -f $(STD_CLEANFILES)
Packit 2ad57b
	rm -f $(VERSION_FILE)
Packit 2ad57b
	rm -f $(BIN)
Packit 2ad57b
	rm -f dtc-*.tar dtc-*.tar.sign dtc-*.tar.asc
Packit 2ad57b
Packit 2ad57b
#
Packit 2ad57b
# Generic compile rules
Packit 2ad57b
#
Packit 2ad57b
%: %.o
Packit 2ad57b
	@$(VECHO) LD $@
Packit Service 0ee8e1
	$(LINK.c) -o $@ $^ $(LDLIBS_$*)
Packit 2ad57b
Packit 2ad57b
%.o: %.c
Packit 2ad57b
	@$(VECHO) CC $@
Packit 2ad57b
	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
Packit 2ad57b
Packit 2ad57b
%.o: %.S
Packit 2ad57b
	@$(VECHO) AS $@
Packit 2ad57b
	$(CC) $(CPPFLAGS) $(AFLAGS) -D__ASSEMBLY__ -o $@ -c $<
Packit 2ad57b
Packit 2ad57b
%.d: %.c
Packit 2ad57b
	@$(VECHO) DEP $<
Packit Service 0ee8e1
	$(CC) $(CPPFLAGS) $(CFLAGS) -MM -MG -MT "$*.o $@" $< > $@
Packit 2ad57b
Packit 2ad57b
%.d: %.S
Packit 2ad57b
	@$(VECHO) DEP $<
Packit 2ad57b
	$(CC) $(CPPFLAGS) -MM -MG -MT "$*.o $@" $< > $@
Packit 2ad57b
Packit 2ad57b
%.i:	%.c
Packit 2ad57b
	@$(VECHO) CPP $@
Packit 2ad57b
	$(CC) $(CPPFLAGS) -E $< > $@
Packit 2ad57b
Packit 2ad57b
%.s:	%.c
Packit 2ad57b
	@$(VECHO) CC -S $@
Packit 2ad57b
	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -S $<
Packit 2ad57b
Packit 2ad57b
%.a:
Packit 2ad57b
	@$(VECHO) AR $@
Packit 2ad57b
	$(AR) $(ARFLAGS) $@ $^
Packit 2ad57b
Packit 2ad57b
%.lex.c: %.l
Packit 2ad57b
	@$(VECHO) LEX $@
Packit 2ad57b
	$(LEX) -o$@ $<
Packit 2ad57b
Packit 2ad57b
%.tab.c %.tab.h %.output: %.y
Packit 2ad57b
	@$(VECHO) BISON $@
Packit Service 0ee8e1
	$(BISON) -b $(basename $(basename $@)) -d $<
Packit 2ad57b
Packit 2ad57b
FORCE: