Blame Makefile

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 2ad57b
PATCHLEVEL = 4
Packit 2ad57b
SUBLEVEL = 6
Packit 2ad57b
EXTRAVERSION =
Packit 2ad57b
LOCAL_VERSION =
Packit 2ad57b
CONFIG_LOCALVERSION =
Packit 2ad57b
Packit 2ad57b
CPPFLAGS = -I libfdt -I .
Packit 2ad57b
WARNINGS = -Wall -Wpointer-arith -Wcast-qual -Wnested-externs \
Packit 2ad57b
	-Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wshadow
Packit 2ad57b
CFLAGS = -g -Os $(SHAREDLIB_CFLAGS) -Werror $(WARNINGS)
Packit 2ad57b
Packit 2ad57b
BISON = bison
Packit 2ad57b
LEX = flex
Packit 2ad57b
SWIG = swig
Packit 2ad57b
PKG_CONFIG ?= pkg-config
Packit 2ad57b
Packit 2ad57b
INSTALL = /usr/bin/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 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 2ad57b
# We need both Python and swig to build pylibfdt.
Packit 2ad57b
.PHONY: maybe_pylibfdt
Packit 2ad57b
maybe_pylibfdt: FORCE
Packit 2ad57b
	if $(PKG_CONFIG) --cflags python2 >/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 2ad57b
	if [ "$$can_build" = "yes" ]; then \
Packit 2ad57b
		$(MAKE) pylibfdt; \
Packit 2ad57b
	else \
Packit 2ad57b
		echo "## Skipping pylibfdt (install python dev and swig to build)"; \
Packit 2ad57b
	fi
Packit 2ad57b
Packit 2ad57b
ifeq ($(NO_PYTHON),)
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 2ad57b
LIBFDT_objdir = libfdt
Packit 2ad57b
LIBFDT_srcdir = libfdt
Packit 2ad57b
LIBFDT_archive = $(LIBFDT_objdir)/libfdt.a
Packit 2ad57b
LIBFDT_lib = $(LIBFDT_objdir)/libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT)
Packit 2ad57b
LIBFDT_include = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_INCLUDES))
Packit 2ad57b
LIBFDT_version = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_VERSION))
Packit 2ad57b
Packit 2ad57b
include $(LIBFDT_srcdir)/Makefile.libfdt
Packit 2ad57b
Packit 2ad57b
.PHONY: libfdt
Packit 2ad57b
libfdt: $(LIBFDT_archive) $(LIBFDT_lib)
Packit 2ad57b
Packit 2ad57b
$(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS))
Packit 2ad57b
$(LIBFDT_lib): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS))
Packit 2ad57b
Packit 2ad57b
libfdt_clean:
Packit 2ad57b
	@$(VECHO) CLEAN "(libfdt)"
Packit 2ad57b
	rm -f $(addprefix $(LIBFDT_objdir)/,$(STD_CLEANFILES))
Packit 2ad57b
	rm -f $(LIBFDT_objdir)/*.so
Packit 2ad57b
Packit 2ad57b
ifneq ($(DEPTARGETS),)
Packit 2ad57b
-include $(LIBFDT_OBJS:%.o=$(LIBFDT_objdir)/%.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 2ad57b
	$(INSTALL) $(BIN) $(SCRIPTS) $(DESTDIR)$(BINDIR)
Packit 2ad57b
Packit 2ad57b
install-lib: all
Packit 2ad57b
	@$(VECHO) INSTALL-LIB
Packit 2ad57b
	$(INSTALL) -d $(DESTDIR)$(LIBDIR)
Packit 2ad57b
	$(INSTALL) $(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 2ad57b
	$(INSTALL) -m 644 $(LIBFDT_archive) $(DESTDIR)$(LIBDIR)
Packit 2ad57b
Packit 2ad57b
install-includes:
Packit 2ad57b
	@$(VECHO) INSTALL-INC
Packit 2ad57b
	$(INSTALL) -d $(DESTDIR)$(INCLUDEDIR)
Packit 2ad57b
	$(INSTALL) -m 644 $(LIBFDT_include) $(DESTDIR)$(INCLUDEDIR)
Packit 2ad57b
Packit 2ad57b
install: install-bin install-lib install-includes
Packit 2ad57b
Packit 2ad57b
ifeq ($(NO_PYTHON),)
Packit 2ad57b
install: 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 2ad57b
fdtget:	$(FDTGET_OBJS) $(LIBFDT_archive)
Packit 2ad57b
Packit 2ad57b
fdtput:	$(FDTPUT_OBJS) $(LIBFDT_archive)
Packit 2ad57b
Packit 2ad57b
fdtoverlay: $(FDTOVERLAY_OBJS) $(LIBFDT_archive)
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 2ad57b
PYLIBFDT_srcdir = pylibfdt
Packit 2ad57b
PYLIBFDT_objdir = pylibfdt
Packit 2ad57b
Packit 2ad57b
include $(PYLIBFDT_srcdir)/Makefile.pylibfdt
Packit 2ad57b
Packit 2ad57b
.PHONY: pylibfdt
Packit 2ad57b
pylibfdt: $(PYLIBFDT_objdir)/_libfdt.so
Packit 2ad57b
Packit 2ad57b
pylibfdt_clean:
Packit 2ad57b
	@$(VECHO) CLEAN "(pylibfdt)"
Packit 2ad57b
	rm -f $(addprefix $(PYLIBFDT_objdir)/,$(PYLIBFDT_cleanfiles))
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 2ad57b
ifeq ($(NO_PYTHON),)
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 2ad57b
	$(LINK.c) -o $@ $^
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 2ad57b
	$(CC) $(CPPFLAGS) -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
$(LIBFDT_lib):
Packit 2ad57b
	@$(VECHO) LD $@
Packit 2ad57b
	$(CC) $(LDFLAGS) $(SHAREDLIB_LDFLAGS)$(LIBFDT_soname) -o $(LIBFDT_lib) $^
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 2ad57b
	$(BISON) -d $<
Packit 2ad57b
Packit 2ad57b
FORCE: