• 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 -fPIC -Werror $(WARNINGS)
22
23BISON = bison
24LEX = flex
25
26INSTALL = /usr/bin/install
27DESTDIR =
28PREFIX = $(HOME)
29BINDIR = $(PREFIX)/bin
30LIBDIR = $(PREFIX)/lib
31INCLUDEDIR = $(PREFIX)/include
32
33HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \
34	    sed -e 's/\(cygwin\).*/cygwin/')
35
36ifeq ($(HOSTOS),darwin)
37SHAREDLIB_EXT=dylib
38SHAREDLIB_LINK_OPTIONS=-dynamiclib -Wl,-install_name -Wl,
39else
40SHAREDLIB_EXT=so
41SHAREDLIB_LINK_OPTIONS=-shared -Wl,--version-script=$(LIBFDT_version) -Wl,-soname,
42endif
43
44#
45# Overall rules
46#
47ifdef V
48VECHO = :
49else
50VECHO = echo "	"
51ARFLAGS = rc
52.SILENT:
53endif
54
55NODEPTARGETS = clean
56ifeq ($(MAKECMDGOALS),)
57DEPTARGETS = all
58else
59DEPTARGETS = $(filter-out $(NODEPTARGETS),$(MAKECMDGOALS))
60endif
61
62#
63# Rules for versioning
64#
65
66DTC_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
67VERSION_FILE = version_gen.h
68
69CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
70	  else if [ -x /bin/bash ]; then echo /bin/bash; \
71	  else echo sh; fi ; fi)
72
73nullstring :=
74space	:= $(nullstring) # end of line
75
76localver_config = $(subst $(space),, $(string) \
77			      $(patsubst "%",%,$(CONFIG_LOCALVERSION)))
78
79localver_cmd = $(subst $(space),, $(string) \
80			      $(patsubst "%",%,$(LOCALVERSION)))
81
82localver_scm = $(shell $(CONFIG_SHELL) ./scripts/setlocalversion)
83localver_full  = $(localver_config)$(localver_cmd)$(localver_scm)
84
85dtc_version = $(DTC_VERSION)$(localver_full)
86
87# Contents of the generated version file.
88define filechk_version
89	(echo "#define DTC_VERSION \"DTC $(dtc_version)\""; )
90endef
91
92define filechk
93	set -e;					\
94	echo '	CHK $@';			\
95	mkdir -p $(dir $@);			\
96	$(filechk_$(1)) < $< > $@.tmp;		\
97	if [ -r $@ ] && cmp -s $@ $@.tmp; then	\
98		rm -f $@.tmp;			\
99	else					\
100		echo '	UPD $@';		\
101		mv -f $@.tmp $@;		\
102	fi;
103endef
104
105
106include Makefile.convert-dtsv0
107include Makefile.dtc
108include Makefile.utils
109
110BIN += convert-dtsv0
111BIN += dtc
112BIN += fdtdump
113BIN += fdtget
114BIN += fdtput
115
116SCRIPTS = dtdiff
117
118all: $(BIN) libfdt
119
120
121ifneq ($(DEPTARGETS),)
122-include $(DTC_OBJS:%.o=%.d)
123-include $(CONVERT_OBJS:%.o=%.d)
124-include $(FDTDUMP_OBJS:%.o=%.d)
125-include $(FDTGET_OBJS:%.o=%.d)
126-include $(FDTPUT_OBJS:%.o=%.d)
127endif
128
129
130
131#
132# Rules for libfdt
133#
134LIBFDT_objdir = libfdt
135LIBFDT_srcdir = libfdt
136LIBFDT_archive = $(LIBFDT_objdir)/libfdt.a
137LIBFDT_lib = $(LIBFDT_objdir)/libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT)
138LIBFDT_include = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_INCLUDES))
139LIBFDT_version = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_VERSION))
140
141include $(LIBFDT_srcdir)/Makefile.libfdt
142
143.PHONY: libfdt
144libfdt: $(LIBFDT_archive) $(LIBFDT_lib)
145
146$(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS))
147$(LIBFDT_lib): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS))
148
149libfdt_clean:
150	@$(VECHO) CLEAN "(libfdt)"
151	rm -f $(addprefix $(LIBFDT_objdir)/,$(STD_CLEANFILES))
152	rm -f $(LIBFDT_objdir)/*.so
153
154ifneq ($(DEPTARGETS),)
155-include $(LIBFDT_OBJS:%.o=$(LIBFDT_objdir)/%.d)
156endif
157
158# This stops make from generating the lex and bison output during
159# auto-dependency computation, but throwing them away as an
160# intermediate target and building them again "for real"
161.SECONDARY: $(DTC_GEN_SRCS) $(CONVERT_GEN_SRCS)
162
163install-bin: all $(SCRIPTS)
164	@$(VECHO) INSTALL-BIN
165	$(INSTALL) -d $(DESTDIR)$(BINDIR)
166	$(INSTALL) $(BIN) $(SCRIPTS) $(DESTDIR)$(BINDIR)
167
168install-lib: all
169	@$(VECHO) INSTALL-LIB
170	$(INSTALL) -d $(DESTDIR)$(LIBDIR)
171	$(INSTALL) $(LIBFDT_lib) $(DESTDIR)$(LIBDIR)
172	ln -sf $(notdir $(LIBFDT_lib)) $(DESTDIR)$(LIBDIR)/$(LIBFDT_soname)
173	ln -sf $(LIBFDT_soname) $(DESTDIR)$(LIBDIR)/libfdt.$(SHAREDLIB_EXT)
174	$(INSTALL) -m 644 $(LIBFDT_archive) $(DESTDIR)$(LIBDIR)
175
176install-includes:
177	@$(VECHO) INSTALL-INC
178	$(INSTALL) -d $(DESTDIR)$(INCLUDEDIR)
179	$(INSTALL) -m 644 $(LIBFDT_include) $(DESTDIR)$(INCLUDEDIR)
180
181install: install-bin install-lib install-includes
182
183$(VERSION_FILE): Makefile FORCE
184	$(call filechk,version)
185
186
187dtc: $(DTC_OBJS)
188
189convert-dtsv0: $(CONVERT_OBJS)
190	@$(VECHO) LD $@
191	$(LINK.c) -o $@ $^
192
193fdtdump:	$(FDTDUMP_OBJS)
194
195fdtget:	$(FDTGET_OBJS) $(LIBFDT_archive)
196
197fdtput:	$(FDTPUT_OBJS) $(LIBFDT_archive)
198
199dist:
200	git archive --format=tar --prefix=dtc-$(dtc_version)/ HEAD \
201		> ../dtc-$(dtc_version).tar
202	cat ../dtc-$(dtc_version).tar | \
203		gzip -9 > ../dtc-$(dtc_version).tar.gz
204
205#
206# Release signing and uploading
207# This is for maintainer convenience, don't try this at home.
208#
209ifeq ($(MAINTAINER),y)
210GPG = gpg2
211KUP = kup
212KUPDIR = /pub/software/utils/dtc
213
214kup: dist
215	$(GPG) --detach-sign --armor -o ../dtc-$(dtc_version).tar.sign \
216		../dtc-$(dtc_version).tar
217	$(KUP) put ../dtc-$(dtc_version).tar.gz ../dtc-$(dtc_version).tar.sign \
218		$(KUPDIR)/dtc-$(dtc_version).tar.gz
219endif
220
221tags: FORCE
222	rm -f tags
223	find . \( -name tests -type d -prune \) -o \
224	       \( ! -name '*.tab.[ch]' ! -name '*.lex.c' \
225	       -name '*.[chly]' -type f -print \) | xargs ctags -a
226
227#
228# Testsuite rules
229#
230TESTS_PREFIX=tests/
231
232TESTS_BIN += dtc
233TESTS_BIN += convert-dtsv0
234TESTS_BIN += fdtput
235TESTS_BIN += fdtget
236TESTS_BIN += fdtdump
237
238include tests/Makefile.tests
239
240#
241# Clean rules
242#
243STD_CLEANFILES = *~ *.o *.$(SHAREDLIB_EXT) *.d *.a *.i *.s core a.out vgcore.* \
244	*.tab.[ch] *.lex.c *.output
245
246clean: libfdt_clean tests_clean
247	@$(VECHO) CLEAN
248	rm -f $(STD_CLEANFILES)
249	rm -f $(VERSION_FILE)
250	rm -f $(BIN)
251	rm -f dtc-*.tar dtc-*.tar.sign dtc-*.tar.asc
252
253#
254# Generic compile rules
255#
256%: %.o
257	@$(VECHO) LD $@
258	$(LINK.c) -o $@ $^
259
260%.o: %.c
261	@$(VECHO) CC $@
262	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -c $<
263
264%.o: %.S
265	@$(VECHO) AS $@
266	$(CC) $(CPPFLAGS) $(AFLAGS) -D__ASSEMBLY__ -o $@ -c $<
267
268%.d: %.c
269	@$(VECHO) DEP $<
270	$(CC) $(CPPFLAGS) -MM -MG -MT "$*.o $@" $< > $@
271
272%.d: %.S
273	@$(VECHO) DEP $<
274	$(CC) $(CPPFLAGS) -MM -MG -MT "$*.o $@" $< > $@
275
276%.i:	%.c
277	@$(VECHO) CPP $@
278	$(CC) $(CPPFLAGS) -E $< > $@
279
280%.s:	%.c
281	@$(VECHO) CC -S $@
282	$(CC) $(CPPFLAGS) $(CFLAGS) -o $@ -S $<
283
284%.a:
285	@$(VECHO) AR $@
286	$(AR) $(ARFLAGS) $@ $^
287
288$(LIBFDT_lib):
289	@$(VECHO) LD $@
290	$(CC) $(LDFLAGS) -fPIC $(SHAREDLIB_LINK_OPTIONS)$(LIBFDT_soname) -o $(LIBFDT_lib) $^
291
292%.lex.c: %.l
293	@$(VECHO) LEX $@
294	$(LEX) -o$@ $<
295
296%.tab.c %.tab.h %.output: %.y
297	@$(VECHO) BISON $@
298	$(BISON) -d $<
299
300FORCE:
301