• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Device Tree Compiler
3#
4
5#
6# Version information will be constructed in this order:
7# EXTRAVERSION might be "-rc", for example.
8# LOCAL_VERSION is likely from command line.
9# CONFIG_LOCALVERSION from some future config system.
10#
11VERSION = 1
12PATCHLEVEL = 4
13SUBLEVEL = 4
14EXTRAVERSION =
15LOCAL_VERSION =
16CONFIG_LOCALVERSION =
17
18CPPFLAGS = -I libfdt -I .
19WARNINGS = -Wall -Wpointer-arith -Wcast-qual -Wnested-externs \
20	-Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wshadow
21CFLAGS = -g -Os $(SHAREDLIB_CFLAGS) -Werror $(WARNINGS)
22
23BISON = bison
24LEX = flex
25SWIG = swig
26PKG_CONFIG ?= pkg-config
27
28INSTALL = /usr/bin/install
29DESTDIR =
30PREFIX = $(HOME)
31BINDIR = $(PREFIX)/bin
32LIBDIR = $(PREFIX)/lib
33INCLUDEDIR = $(PREFIX)/include
34
35HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
36	    sed -e 's/\(cygwin\|msys\).*/\1/')
37
38ifeq ($(HOSTOS),darwin)
39SHAREDLIB_EXT     = dylib
40SHAREDLIB_CFLAGS  = -fPIC
41SHAREDLIB_LDFLAGS = -fPIC -dynamiclib -Wl,-install_name -Wl,
42else ifeq ($(HOSTOS),$(filter $(HOSTOS),msys cygwin))
43SHAREDLIB_EXT     = so
44SHAREDLIB_CFLAGS  =
45SHAREDLIB_LDFLAGS = -shared -Wl,--version-script=$(LIBFDT_version) -Wl,-soname,
46else
47SHAREDLIB_EXT     = so
48SHAREDLIB_CFLAGS  = -fPIC
49SHAREDLIB_LDFLAGS = -fPIC -shared -Wl,--version-script=$(LIBFDT_version) -Wl,-soname,
50endif
51
52#
53# Overall rules
54#
55ifdef V
56VECHO = :
57else
58VECHO = echo "	"
59ARFLAGS = rc
60.SILENT:
61endif
62
63NODEPTARGETS = clean
64ifeq ($(MAKECMDGOALS),)
65DEPTARGETS = all
66else
67DEPTARGETS = $(filter-out $(NODEPTARGETS),$(MAKECMDGOALS))
68endif
69
70#
71# Rules for versioning
72#
73
74DTC_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
75VERSION_FILE = version_gen.h
76
77CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
78	  else if [ -x /bin/bash ]; then echo /bin/bash; \
79	  else echo sh; fi ; fi)
80
81nullstring :=
82space	:= $(nullstring) # end of line
83
84localver_config = $(subst $(space),, $(string) \
85			      $(patsubst "%",%,$(CONFIG_LOCALVERSION)))
86
87localver_cmd = $(subst $(space),, $(string) \
88			      $(patsubst "%",%,$(LOCALVERSION)))
89
90localver_scm = $(shell $(CONFIG_SHELL) ./scripts/setlocalversion)
91localver_full  = $(localver_config)$(localver_cmd)$(localver_scm)
92
93dtc_version = $(DTC_VERSION)$(localver_full)
94
95# Contents of the generated version file.
96define filechk_version
97	(echo "#define DTC_VERSION \"DTC $(dtc_version)\""; )
98endef
99
100define filechk
101	set -e;					\
102	echo '	CHK $@';			\
103	mkdir -p $(dir $@);			\
104	$(filechk_$(1)) < $< > $@.tmp;		\
105	if [ -r $@ ] && cmp -s $@ $@.tmp; then	\
106		rm -f $@.tmp;			\
107	else					\
108		echo '	UPD $@';		\
109		mv -f $@.tmp $@;		\
110	fi;
111endef
112
113
114include Makefile.convert-dtsv0
115include Makefile.dtc
116include Makefile.utils
117
118BIN += convert-dtsv0
119BIN += dtc
120BIN += fdtdump
121BIN += fdtget
122BIN += fdtput
123BIN += fdtoverlay
124
125SCRIPTS = dtdiff
126
127all: $(BIN) libfdt
128
129# We need both Python and swig to build pylibfdt.
130.PHONY: maybe_pylibfdt
131maybe_pylibfdt: FORCE
132	if $(PKG_CONFIG) --cflags python >/dev/null 2>&1; then \
133		if which swig >/dev/null 2>&1; then \
134			can_build=yes; \
135		fi; \
136	fi; \
137	if [ "$$can_build" = "yes" ]; then \
138		$(MAKE) pylibfdt; \
139	else \
140		echo "## Skipping pylibfdt (install python dev and swig to build)"; \
141	fi
142
143ifeq ($(NO_PYTHON),)
144all: maybe_pylibfdt
145endif
146
147
148ifneq ($(DEPTARGETS),)
149-include $(DTC_OBJS:%.o=%.d)
150-include $(CONVERT_OBJS:%.o=%.d)
151-include $(FDTDUMP_OBJS:%.o=%.d)
152-include $(FDTGET_OBJS:%.o=%.d)
153-include $(FDTPUT_OBJS:%.o=%.d)
154-include $(FDTOVERLAY_OBJS:%.o=%.d)
155endif
156
157
158
159#
160# Rules for libfdt
161#
162LIBFDT_objdir = libfdt
163LIBFDT_srcdir = libfdt
164LIBFDT_archive = $(LIBFDT_objdir)/libfdt.a
165LIBFDT_lib = $(LIBFDT_objdir)/libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT)
166LIBFDT_include = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_INCLUDES))
167LIBFDT_version = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_VERSION))
168
169include $(LIBFDT_srcdir)/Makefile.libfdt
170
171.PHONY: libfdt
172libfdt: $(LIBFDT_archive) $(LIBFDT_lib)
173
174$(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS))
175$(LIBFDT_lib): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS))
176
177libfdt_clean:
178	@$(VECHO) CLEAN "(libfdt)"
179	rm -f $(addprefix $(LIBFDT_objdir)/,$(STD_CLEANFILES))
180	rm -f $(LIBFDT_objdir)/*.so
181
182ifneq ($(DEPTARGETS),)
183-include $(LIBFDT_OBJS:%.o=$(LIBFDT_objdir)/%.d)
184endif
185
186# This stops make from generating the lex and bison output during
187# auto-dependency computation, but throwing them away as an
188# intermediate target and building them again "for real"
189.SECONDARY: $(DTC_GEN_SRCS) $(CONVERT_GEN_SRCS)
190
191install-bin: all $(SCRIPTS)
192	@$(VECHO) INSTALL-BIN
193	$(INSTALL) -d $(DESTDIR)$(BINDIR)
194	$(INSTALL) $(BIN) $(SCRIPTS) $(DESTDIR)$(BINDIR)
195
196install-lib: all
197	@$(VECHO) INSTALL-LIB
198	$(INSTALL) -d $(DESTDIR)$(LIBDIR)
199	$(INSTALL) $(LIBFDT_lib) $(DESTDIR)$(LIBDIR)
200	ln -sf $(notdir $(LIBFDT_lib)) $(DESTDIR)$(LIBDIR)/$(LIBFDT_soname)
201	ln -sf $(LIBFDT_soname) $(DESTDIR)$(LIBDIR)/libfdt.$(SHAREDLIB_EXT)
202	$(INSTALL) -m 644 $(LIBFDT_archive) $(DESTDIR)$(LIBDIR)
203
204install-includes:
205	@$(VECHO) INSTALL-INC
206	$(INSTALL) -d $(DESTDIR)$(INCLUDEDIR)
207	$(INSTALL) -m 644 $(LIBFDT_include) $(DESTDIR)$(INCLUDEDIR)
208
209install: install-bin install-lib install-includes
210
211ifeq ($(NO_PYTHON),)
212install: install_pylibfdt
213endif
214
215$(VERSION_FILE): Makefile FORCE
216	$(call filechk,version)
217
218
219dtc: $(DTC_OBJS)
220
221convert-dtsv0: $(CONVERT_OBJS)
222	@$(VECHO) LD $@
223	$(LINK.c) -o $@ $^
224
225fdtdump:	$(FDTDUMP_OBJS)
226
227fdtget:	$(FDTGET_OBJS) $(LIBFDT_archive)
228
229fdtput:	$(FDTPUT_OBJS) $(LIBFDT_archive)
230
231fdtoverlay: $(FDTOVERLAY_OBJS) $(LIBFDT_archive)
232
233dist:
234	git archive --format=tar --prefix=dtc-$(dtc_version)/ HEAD \
235		> ../dtc-$(dtc_version).tar
236	cat ../dtc-$(dtc_version).tar | \
237		gzip -9 > ../dtc-$(dtc_version).tar.gz
238
239
240#
241# Rules for pylibfdt
242#
243PYLIBFDT_srcdir = pylibfdt
244PYLIBFDT_objdir = pylibfdt
245
246include $(PYLIBFDT_srcdir)/Makefile.pylibfdt
247
248.PHONY: pylibfdt
249pylibfdt: $(PYLIBFDT_objdir)/_libfdt.so
250
251pylibfdt_clean:
252	@$(VECHO) CLEAN "(pylibfdt)"
253	rm -f $(addprefix $(PYLIBFDT_objdir)/,$(PYLIBFDT_cleanfiles))
254
255#
256# Release signing and uploading
257# This is for maintainer convenience, don't try this at home.
258#
259ifeq ($(MAINTAINER),y)
260GPG = gpg2
261KUP = kup
262KUPDIR = /pub/software/utils/dtc
263
264kup: dist
265	$(GPG) --detach-sign --armor -o ../dtc-$(dtc_version).tar.sign \
266		../dtc-$(dtc_version).tar
267	$(KUP) put ../dtc-$(dtc_version).tar.gz ../dtc-$(dtc_version).tar.sign \
268		$(KUPDIR)/dtc-$(dtc_version).tar.gz
269endif
270
271tags: FORCE
272	rm -f tags
273	find . \( -name tests -type d -prune \) -o \
274	       \( ! -name '*.tab.[ch]' ! -name '*.lex.c' \
275	       -name '*.[chly]' -type f -print \) | xargs ctags -a
276
277#
278# Testsuite rules
279#
280TESTS_PREFIX=tests/
281
282TESTS_BIN += dtc
283TESTS_BIN += convert-dtsv0
284TESTS_BIN += fdtput
285TESTS_BIN += fdtget
286TESTS_BIN += fdtdump
287TESTS_BIN += fdtoverlay
288ifeq ($(NO_PYTHON),)
289TESTS_PYLIBFDT += maybe_pylibfdt
290endif
291
292include tests/Makefile.tests
293
294#
295# Clean rules
296#
297STD_CLEANFILES = *~ *.o *.$(SHAREDLIB_EXT) *.d *.a *.i *.s core a.out vgcore.* \
298	*.tab.[ch] *.lex.c *.output
299
300clean: libfdt_clean pylibfdt_clean tests_clean
301	@$(VECHO) CLEAN
302	rm -f $(STD_CLEANFILES)
303	rm -f $(VERSION_FILE)
304	rm -f $(BIN)
305	rm -f dtc-*.tar dtc-*.tar.sign dtc-*.tar.asc
306
307#
308# Generic compile rules
309#
310%: %.o
311	@$(VECHO) LD $@
312	$(LINK.c) -o $@ $^
313
314%.o: %.c
315	@$(VECHO) CC $@
316	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
317
318%.o: %.S
319	@$(VECHO) AS $@
320	$(CC) $(CPPFLAGS) $(AFLAGS) -D__ASSEMBLY__ -o $@ -c $<
321
322%.d: %.c
323	@$(VECHO) DEP $<
324	$(CC) $(CPPFLAGS) -MM -MG -MT "$*.o $@" $< > $@
325
326%.d: %.S
327	@$(VECHO) DEP $<
328	$(CC) $(CPPFLAGS) -MM -MG -MT "$*.o $@" $< > $@
329
330%.i:	%.c
331	@$(VECHO) CPP $@
332	$(CC) $(CPPFLAGS) -E $< > $@
333
334%.s:	%.c
335	@$(VECHO) CC -S $@
336	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -S $<
337
338%.a:
339	@$(VECHO) AR $@
340	$(AR) $(ARFLAGS) $@ $^
341
342$(LIBFDT_lib):
343	@$(VECHO) LD $@
344	$(CC) $(LDFLAGS) $(SHAREDLIB_LDFLAGS)$(LIBFDT_soname) -o $(LIBFDT_lib) $^
345
346%.lex.c: %.l
347	@$(VECHO) LEX $@
348	$(LEX) -o$@ $<
349
350%.tab.c %.tab.h %.output: %.y
351	@$(VECHO) BISON $@
352	$(BISON) -d $<
353
354FORCE:
355