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 # 11 VERSION = 1 12 PATCHLEVEL = 4 13 SUBLEVEL = 2 14 EXTRAVERSION = 15 LOCAL_VERSION = 16 CONFIG_LOCALVERSION = 17 18 CPPFLAGS = -I libfdt -I . 19 WARNINGS = -Wall -Wpointer-arith -Wcast-qual -Wnested-externs \ 20 -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wshadow 21 CFLAGS = -g -Os -fPIC -Werror $(WARNINGS) 22 23 BISON = bison 24 LEX = flex 25 26 INSTALL = /usr/bin/install 27 DESTDIR = 28 PREFIX = $(HOME) 29 BINDIR = $(PREFIX)/bin 30 LIBDIR = $(PREFIX)/lib 31 INCLUDEDIR = $(PREFIX)/include 32 33 HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \ 34 sed -e 's/\(cygwin\).*/cygwin/') 35 36 ifeq ($(HOSTOS),darwin) 37 SHAREDLIB_EXT=dylib 38 SHAREDLIB_LINK_OPTIONS=-dynamiclib -Wl,-install_name -Wl, 39 else 40 SHAREDLIB_EXT=so 41 SHAREDLIB_LINK_OPTIONS=-shared -Wl,--version-script=$(LIBFDT_version) -Wl,-soname, 42 endif 43 44 # 45 # Overall rules 46 # 47 ifdef V 48 VECHO = : 49 else 50 VECHO = echo " " 51 ARFLAGS = rc 52 .SILENT: 53 endif 54 55 NODEPTARGETS = clean 56 ifeq ($(MAKECMDGOALS),) 57 DEPTARGETS = all 58 else 59 DEPTARGETS = $(filter-out $(NODEPTARGETS),$(MAKECMDGOALS)) 60 endif 61 62 # 63 # Rules for versioning 64 # 65 66 DTC_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) 67 VERSION_FILE = version_gen.h 68 69 CONFIG_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 73 nullstring := 74 space := $(nullstring) # end of line 75 76 localver_config = $(subst $(space),, $(string) \ 77 $(patsubst "%",%,$(CONFIG_LOCALVERSION))) 78 79 localver_cmd = $(subst $(space),, $(string) \ 80 $(patsubst "%",%,$(LOCALVERSION))) 81 82 localver_scm = $(shell $(CONFIG_SHELL) ./scripts/setlocalversion) 83 localver_full = $(localver_config)$(localver_cmd)$(localver_scm) 84 85 dtc_version = $(DTC_VERSION)$(localver_full) 86 87 # Contents of the generated version file. 88 define filechk_version 89 (echo "#define DTC_VERSION \"DTC $(dtc_version)\""; ) 90 endef 91 92 define 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; 103 endef 104 105 106 include Makefile.convert-dtsv0 107 include Makefile.dtc 108 include Makefile.utils 109 110 BIN += convert-dtsv0 111 BIN += dtc 112 BIN += fdtdump 113 BIN += fdtget 114 BIN += fdtput 115 116 SCRIPTS = dtdiff 117 118 all: $(BIN) libfdt 119 120 121 ifneq ($(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) 127 endif 128 129 130 131 # 132 # Rules for libfdt 133 # 134 LIBFDT_objdir = libfdt 135 LIBFDT_srcdir = libfdt 136 LIBFDT_archive = $(LIBFDT_objdir)/libfdt.a 137 LIBFDT_lib = $(LIBFDT_objdir)/libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT) 138 LIBFDT_include = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_INCLUDES)) 139 LIBFDT_version = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_VERSION)) 140 141 include $(LIBFDT_srcdir)/Makefile.libfdt 142 143 .PHONY: libfdt 144 libfdt: $(LIBFDT_archive) $(LIBFDT_lib) 145 146 $(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS)) 147 $(LIBFDT_lib): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS)) 148 149 libfdt_clean: 150 @$(VECHO) CLEAN "(libfdt)" 151 rm -f $(addprefix $(LIBFDT_objdir)/,$(STD_CLEANFILES)) 152 rm -f $(LIBFDT_objdir)/*.so 153 154 ifneq ($(DEPTARGETS),) 155 -include $(LIBFDT_OBJS:%.o=$(LIBFDT_objdir)/%.d) 156 endif 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 163 install-bin: all $(SCRIPTS) 164 @$(VECHO) INSTALL-BIN 165 $(INSTALL) -d $(DESTDIR)$(BINDIR) 166 $(INSTALL) $(BIN) $(SCRIPTS) $(DESTDIR)$(BINDIR) 167 168 install-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 176 install-includes: 177 @$(VECHO) INSTALL-INC 178 $(INSTALL) -d $(DESTDIR)$(INCLUDEDIR) 179 $(INSTALL) -m 644 $(LIBFDT_include) $(DESTDIR)$(INCLUDEDIR) 180 181 install: install-bin install-lib install-includes 182 183 $(VERSION_FILE): Makefile FORCE 184 $(call filechk,version) 185 186 187 dtc: $(DTC_OBJS) 188 189 convert-dtsv0: $(CONVERT_OBJS) 190 @$(VECHO) LD $@ 191 $(LINK.c) -o $@ $^ 192 193 fdtdump: $(FDTDUMP_OBJS) 194 195 fdtget: $(FDTGET_OBJS) $(LIBFDT_archive) 196 197 fdtput: $(FDTPUT_OBJS) $(LIBFDT_archive) 198 199 dist: 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 # 209 ifeq ($(MAINTAINER),y) 210 GPG = gpg2 211 KUP = kup 212 KUPDIR = /pub/software/utils/dtc 213 214 kup: 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 219 endif 220 221 tags: 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 # 230 TESTS_PREFIX=tests/ 231 232 TESTS_BIN += dtc 233 TESTS_BIN += convert-dtsv0 234 TESTS_BIN += fdtput 235 TESTS_BIN += fdtget 236 TESTS_BIN += fdtdump 237 238 include tests/Makefile.tests 239 240 # 241 # Clean rules 242 # 243 STD_CLEANFILES = *~ *.o *.$(SHAREDLIB_EXT) *.d *.a *.i *.s core a.out vgcore.* \ 244 *.tab.[ch] *.lex.c *.output 245 246 clean: 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 300 FORCE: 301