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 = 4 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 $(SHAREDLIB_CFLAGS) -Werror $(WARNINGS) 22 23 BISON = bison 24 LEX = flex 25 SWIG = swig 26 PKG_CONFIG ?= pkg-config 27 28 INSTALL = /usr/bin/install 29 DESTDIR = 30 PREFIX = $(HOME) 31 BINDIR = $(PREFIX)/bin 32 LIBDIR = $(PREFIX)/lib 33 INCLUDEDIR = $(PREFIX)/include 34 35 HOSTOS := $(shell uname -s | tr '[:upper:]' '[:lower:]' | \ 36 sed -e 's/\(cygwin\|msys\).*/\1/') 37 38 ifeq ($(HOSTOS),darwin) 39 SHAREDLIB_EXT = dylib 40 SHAREDLIB_CFLAGS = -fPIC 41 SHAREDLIB_LDFLAGS = -fPIC -dynamiclib -Wl,-install_name -Wl, 42 else ifeq ($(HOSTOS),$(filter $(HOSTOS),msys cygwin)) 43 SHAREDLIB_EXT = so 44 SHAREDLIB_CFLAGS = 45 SHAREDLIB_LDFLAGS = -shared -Wl,--version-script=$(LIBFDT_version) -Wl,-soname, 46 else 47 SHAREDLIB_EXT = so 48 SHAREDLIB_CFLAGS = -fPIC 49 SHAREDLIB_LDFLAGS = -fPIC -shared -Wl,--version-script=$(LIBFDT_version) -Wl,-soname, 50 endif 51 52 # 53 # Overall rules 54 # 55 ifdef V 56 VECHO = : 57 else 58 VECHO = echo " " 59 ARFLAGS = rc 60 .SILENT: 61 endif 62 63 NODEPTARGETS = clean 64 ifeq ($(MAKECMDGOALS),) 65 DEPTARGETS = all 66 else 67 DEPTARGETS = $(filter-out $(NODEPTARGETS),$(MAKECMDGOALS)) 68 endif 69 70 # 71 # Rules for versioning 72 # 73 74 DTC_VERSION = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) 75 VERSION_FILE = version_gen.h 76 77 CONFIG_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 81 nullstring := 82 space := $(nullstring) # end of line 83 84 localver_config = $(subst $(space),, $(string) \ 85 $(patsubst "%",%,$(CONFIG_LOCALVERSION))) 86 87 localver_cmd = $(subst $(space),, $(string) \ 88 $(patsubst "%",%,$(LOCALVERSION))) 89 90 localver_scm = $(shell $(CONFIG_SHELL) ./scripts/setlocalversion) 91 localver_full = $(localver_config)$(localver_cmd)$(localver_scm) 92 93 dtc_version = $(DTC_VERSION)$(localver_full) 94 95 # Contents of the generated version file. 96 define filechk_version 97 (echo "#define DTC_VERSION \"DTC $(dtc_version)\""; ) 98 endef 99 100 define 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; 111 endef 112 113 114 include Makefile.convert-dtsv0 115 include Makefile.dtc 116 include Makefile.utils 117 118 BIN += convert-dtsv0 119 BIN += dtc 120 BIN += fdtdump 121 BIN += fdtget 122 BIN += fdtput 123 BIN += fdtoverlay 124 125 SCRIPTS = dtdiff 126 127 all: $(BIN) libfdt 128 129 # We need both Python and swig to build pylibfdt. 130 .PHONY: maybe_pylibfdt 131 maybe_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 143 ifeq ($(NO_PYTHON),) 144 all: maybe_pylibfdt 145 endif 146 147 148 ifneq ($(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) 155 endif 156 157 158 159 # 160 # Rules for libfdt 161 # 162 LIBFDT_objdir = libfdt 163 LIBFDT_srcdir = libfdt 164 LIBFDT_archive = $(LIBFDT_objdir)/libfdt.a 165 LIBFDT_lib = $(LIBFDT_objdir)/libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT) 166 LIBFDT_include = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_INCLUDES)) 167 LIBFDT_version = $(addprefix $(LIBFDT_srcdir)/,$(LIBFDT_VERSION)) 168 169 include $(LIBFDT_srcdir)/Makefile.libfdt 170 171 .PHONY: libfdt 172 libfdt: $(LIBFDT_archive) $(LIBFDT_lib) 173 174 $(LIBFDT_archive): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS)) 175 $(LIBFDT_lib): $(addprefix $(LIBFDT_objdir)/,$(LIBFDT_OBJS)) 176 177 libfdt_clean: 178 @$(VECHO) CLEAN "(libfdt)" 179 rm -f $(addprefix $(LIBFDT_objdir)/,$(STD_CLEANFILES)) 180 rm -f $(LIBFDT_objdir)/*.so 181 182 ifneq ($(DEPTARGETS),) 183 -include $(LIBFDT_OBJS:%.o=$(LIBFDT_objdir)/%.d) 184 endif 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 191 install-bin: all $(SCRIPTS) 192 @$(VECHO) INSTALL-BIN 193 $(INSTALL) -d $(DESTDIR)$(BINDIR) 194 $(INSTALL) $(BIN) $(SCRIPTS) $(DESTDIR)$(BINDIR) 195 196 install-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 204 install-includes: 205 @$(VECHO) INSTALL-INC 206 $(INSTALL) -d $(DESTDIR)$(INCLUDEDIR) 207 $(INSTALL) -m 644 $(LIBFDT_include) $(DESTDIR)$(INCLUDEDIR) 208 209 install: install-bin install-lib install-includes 210 211 ifeq ($(NO_PYTHON),) 212 install: install_pylibfdt 213 endif 214 215 $(VERSION_FILE): Makefile FORCE 216 $(call filechk,version) 217 218 219 dtc: $(DTC_OBJS) 220 221 convert-dtsv0: $(CONVERT_OBJS) 222 @$(VECHO) LD $@ 223 $(LINK.c) -o $@ $^ 224 225 fdtdump: $(FDTDUMP_OBJS) 226 227 fdtget: $(FDTGET_OBJS) $(LIBFDT_archive) 228 229 fdtput: $(FDTPUT_OBJS) $(LIBFDT_archive) 230 231 fdtoverlay: $(FDTOVERLAY_OBJS) $(LIBFDT_archive) 232 233 dist: 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 # 243 PYLIBFDT_srcdir = pylibfdt 244 PYLIBFDT_objdir = pylibfdt 245 246 include $(PYLIBFDT_srcdir)/Makefile.pylibfdt 247 248 .PHONY: pylibfdt 249 pylibfdt: $(PYLIBFDT_objdir)/_libfdt.so 250 251 pylibfdt_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 # 259 ifeq ($(MAINTAINER),y) 260 GPG = gpg2 261 KUP = kup 262 KUPDIR = /pub/software/utils/dtc 263 264 kup: 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 269 endif 270 271 tags: 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 # 280 TESTS_PREFIX=tests/ 281 282 TESTS_BIN += dtc 283 TESTS_BIN += convert-dtsv0 284 TESTS_BIN += fdtput 285 TESTS_BIN += fdtget 286 TESTS_BIN += fdtdump 287 TESTS_BIN += fdtoverlay 288 ifeq ($(NO_PYTHON),) 289 TESTS_PYLIBFDT += maybe_pylibfdt 290 endif 291 292 include tests/Makefile.tests 293 294 # 295 # Clean rules 296 # 297 STD_CLEANFILES = *~ *.o *.$(SHAREDLIB_EXT) *.d *.a *.i *.s core a.out vgcore.* \ 298 *.tab.[ch] *.lex.c *.output 299 300 clean: 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 354 FORCE: 355