You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile.housekeeping 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598
  1. # -*- makefile -*- : Force emacs to use Makefile mode
  2. # This file contains various boring housekeeping functions that would
  3. # otherwise seriously clutter up the main Makefile.
  4. # Objects to be removed by "make clean"
  5. #
  6. CLEANUP := $(BIN)/*.* # *.* to avoid catching the "CVS" directory
  7. # Version number calculations
  8. #
  9. VERSION_MAJOR = 0
  10. VERSION_MINOR = 5
  11. VERSION_PATCH = 1
  12. EXTRAVERSION =
  13. MM_VERSION = $(VERSION_MAJOR).$(VERSION_MINOR)
  14. VERSION = $(MM_VERSION).$(VERSION_PATCH)$(EXTRAVERSION)
  15. CFLAGS += -DVERSION_MAJOR=$(VERSION_MAJOR) \
  16. -DVERSION_MINOR=$(VERSION_MINOR) \
  17. -DVERSION=\"$(VERSION)\"
  18. IDENT = '$(@F) $(VERSION) (GPL) etherboot.org'
  19. version :
  20. @$(ECHO) $(VERSION)
  21. # Check for tools that can cause failed builds
  22. #
  23. .toolcheck : Makefile Config
  24. @if $(CC) -v 2>&1 | grep -is 'gcc version 2\.96' > /dev/null; then \
  25. $(ECHO) 'gcc 2.96 is unsuitable for compiling Etherboot'; \
  26. $(ECHO) 'Use gcc 2.95 or gcc 3.x instead'; \
  27. exit 1; \
  28. fi
  29. @if [ `perl -e 'use bytes; print chr(255)' | wc -c` = 2 ]; then \
  30. $(ECHO) 'Your Perl version has a Unicode handling bug'; \
  31. $(ECHO) 'Execute this command before compiling Etherboot:'; \
  32. $(ECHO) 'export LANG=$${LANG%.UTF-8}'; \
  33. exit 1; \
  34. fi
  35. @$(TOUCH) $@
  36. VERYCLEANUP += .toolcheck
  37. # Find a usable "echo -e" substitute.
  38. #
  39. TAB := $(shell $(PRINTF) '\t')
  40. ECHO_E_ECHO := $(ECHO)
  41. ECHO_E_ECHO_E := $(ECHO) -e
  42. ECHO_E_BIN_ECHO := /bin/echo
  43. ECHO_E_BIN_ECHO_E := /bin/echo -e
  44. ECHO_E_ECHO_TAB := $(shell $(ECHO_E_ECHO) '\t' | cat)
  45. ECHO_E_ECHO_E_TAB := $(shell $(ECHO_E_ECHO_E) '\t' | cat)
  46. ECHO_E_BIN_ECHO_TAB := $(shell $(ECHO_E_BIN_ECHO) '\t')
  47. ECHO_E_BIN_ECHO_E_TAB := $(shell $(ECHO_E_BIN_ECHO_E) '\t')
  48. ifeq ($(ECHO_E_ECHO_TAB),$(TAB))
  49. ECHO_E ?= $(ECHO_E_ECHO)
  50. endif
  51. ifeq ($(ECHO_E_ECHO_E_TAB),$(TAB))
  52. ECHO_E ?= $(ECHO_E_ECHO_E)
  53. endif
  54. ifeq ($(ECHO_E_BIN_ECHO_TAB),$(TAB))
  55. ECHO_E ?= $(ECHO_E_BIN_ECHO)
  56. endif
  57. ifeq ($(ECHO_E_BIN_ECHO_E_TAB),$(TAB))
  58. ECHO_E ?= $(ECHO_E_BIN_ECHO_E)
  59. endif
  60. .echocheck :
  61. ifdef ECHO_E
  62. @$(TOUCH) $@
  63. else
  64. @$(PRINTF) '%24s : x%sx\n' 'tab' '$(TAB)'
  65. @$(PRINTF) '%24s : x%sx\n' '"$(ECHO_E_ECHO) \t"' \
  66. '$(ECHO_E_ECHO_TAB)'
  67. @$(PRINTF) '%24s : x%sx\n' '"$(ECHO_E_ECHO_E) \t"' \
  68. '$(ECHO_E_ECHO_E_TAB)'
  69. @$(PRINTF) '%24s : x%sx\n' '"$(ECHO_E_BIN_ECHO) \t"' \
  70. '$(ECHO_E_BIN_ECHO_TAB)'
  71. @$(PRINTF) '%24s : x%sx\n' '"$(ECHO_E_BIN_ECHO_E) \t"' \
  72. '$(ECHO_E_BIN_ECHO_E_TAB)'
  73. @$(ECHO) "No usable \"echo -e\" substitute found"
  74. @exit 1
  75. endif
  76. VERYCLEANUP += .echocheck
  77. echo :
  78. @$(ECHO) "Using \"$(ECHO_E)\" for \"echo -e\""
  79. # Build verbosity
  80. #
  81. ifeq ($(V),1)
  82. Q =
  83. QM = @\#
  84. else
  85. Q = @
  86. QM = @
  87. endif
  88. # Check for an old version of gas (binutils 2.9.1)
  89. #
  90. OLDGAS := $(shell $(AS) --version | grep -q '2\.9\.1' && $(ECHO) -DGAS291)
  91. CFLAGS += $(OLDGAS)
  92. oldgas :
  93. @$(ECHO) $(oldgas)
  94. # Some widespread patched versions of gcc include -fstack-protector by
  95. # default, even when -ffreestanding is specified. We therefore need
  96. # to disable -fstack-protector if the compiler supports it.
  97. #
  98. SP_TEST = $(CC) -fno-stack-protector -x c -E - < /dev/null >/dev/null 2>&1
  99. SP_FLAGS := $(shell $(SP_TEST) && $(ECHO) '-fno-stack-protector')
  100. CFLAGS += $(SP_FLAGS)
  101. # compiler.h is needed for our linking and debugging system
  102. #
  103. CFLAGS += -include compiler.h
  104. # config/%.h files are generated from config.h using mkconfig.pl
  105. config/%.h : config.h
  106. $(MKCONFIG) $<
  107. CLEANUP += config/*.h
  108. # SRCDIRS lists all directories containing source files.
  109. srcdirs :
  110. @$(ECHO) $(SRCDIRS)
  111. # SRCS lists all .c or .S files found in any SRCDIR
  112. #
  113. SRCS += $(wildcard $(patsubst %,%/*.c,$(SRCDIRS)))
  114. SRCS += $(wildcard $(patsubst %,%/*.S,$(SRCDIRS)))
  115. srcs :
  116. @$(ECHO) $(SRCS)
  117. # AUTO_SRCS lists all files in SRCS that are not mentioned in
  118. # NON_AUTO_SRCS. Files should be added to NON_AUTO_SRCS if they
  119. # cannot be built using the standard build template.
  120. #
  121. AUTO_SRCS = $(filter-out $(NON_AUTO_SRCS),$(SRCS))
  122. autosrcs :
  123. @$(ECHO) $(AUTO_SRCS)
  124. # We automatically generate rules for any file mentioned in AUTO_SRCS
  125. # using the following set of templates. It would be cleaner to use
  126. # $(eval ...), but this function exists only in GNU make >= 3.80.
  127. # src_template : generate Makefile rules for a given source file
  128. #
  129. # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
  130. # $(2) is the full path to the .d file (e.g. "bin/deps/drivers/net/rtl8139.d")
  131. # $(3) is the source type (e.g. "c")
  132. # $(4) is the source base name (e.g. "rtl8139")
  133. #
  134. define src_template
  135. @$(ECHO) "Generating Makefile rules for $(1)"
  136. @$(MKDIR) -p $(dir $(2))
  137. @$(RM) $(2)
  138. @$(TOUCH) $(2)
  139. $(foreach OBJ,$(if $(OBJS_$(4)),$(OBJS_$(4)),$(4)), \
  140. $(call obj_template,$(1),$(2),$(3),$(OBJ)))
  141. @$(PARSEROM) $(1) >> $(2)
  142. endef
  143. # obj_template : generate Makefile rules for a given resultant object
  144. # of a particular source file. (We can have multiple objects per
  145. # source file via the OBJS_xxx list.)
  146. #
  147. # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
  148. # $(2) is the full path to the .d file (e.g. "bin/deps/drivers/net/rtl8139.d")
  149. # $(3) is the source type (e.g. "c")
  150. # $(4) is the object name (e.g. "rtl8139")
  151. #
  152. define obj_template
  153. @$(CPP) $(CFLAGS) $(CFLAGS_$(3)) $(CFLAGS_$(4)) -DOBJECT=$(4) \
  154. -Wno-error -M $(1) -MT "$(4)_DEPS" -MG -MP | \
  155. sed 's/_DEPS\s*:/_DEPS =/' >> $(2)
  156. @$(ECHO_E) '\n$$(BIN)/$(4).o : $(1) $$(MAKEDEPS) $$($(4)_DEPS)' \
  157. '\n\t$$(QM)$(ECHO) " [BUILD] $$@"\n' \
  158. '\n\t$$(RULE_$(3))\n' \
  159. '\nBOBJS += $$(BIN)/$(4).o\n' \
  160. $(foreach TGT,$(DEBUG_TARGETS), \
  161. $(if $(RULE_$(3)_to_$(TGT)), \
  162. '\n$$(BIN)/$(4).$(TGT) : $(1) $$(MAKEDEPS) $$($(4)_DEPS)' \
  163. '\n\t$$(QM)$(ECHO) " [BUILD] $$@"\n' \
  164. '\n\t$$(RULE_$(3)_to_$(TGT))\n' \
  165. '\n$(TGT)_OBJS += $$(BIN)/$(4).$(TGT)\n' ) ) \
  166. '\n$(2) : $$($(4)_DEPS)\n' \
  167. '\nTAGS : $$($(4)_DEPS)\n' \
  168. >> $(2)
  169. endef
  170. # Rule to generate the Makefile rules files to be included
  171. #
  172. $(BIN)/deps/%.d : % $(MAKEDEPS) $(PARSEROM)
  173. $(if $(filter $(AUTO_SRCS),$<),$(call src_template,$<,$@,$(subst .,,$(suffix $<)),$(basename $(notdir $<))),@$(ECHO) 'ERROR: $< is not an AUTO_SRC' ; exit 1)
  174. # Calculate and include the list of Makefile rules files
  175. #
  176. AUTO_DEPS = $(patsubst %,$(BIN)/deps/%.d,$(AUTO_SRCS))
  177. include $(AUTO_DEPS)
  178. autodeps :
  179. @$(ECHO) $(AUTO_DEPS)
  180. VERYCLEANUP += $(BIN)/deps
  181. # The following variables are created by the Makefile rules files
  182. #
  183. bobjs :
  184. @$(ECHO) $(BOBJS)
  185. drivers :
  186. @$(ECHO) $(DRIVERS)
  187. .PHONY : drivers
  188. roms :
  189. @$(ECHO) $(ROMS)
  190. # Embedded binary
  191. $(BIN)/embedimg.bin: $(EMBEDDED_IMAGE)
  192. $(QM)$(ECHO) " [COPY] $@"
  193. $(Q)$(CP) -f $(EMBEDDED_IMAGE) $@
  194. $(BIN)/embed.o: $(BIN)/embedimg.bin
  195. CFLAGS_embed = -DEMBEDIMG=\"$(BIN)/embedimg.bin\"
  196. # Generate the NIC file from the parsed source files. The NIC file is
  197. # only for rom-o-matic.
  198. #
  199. $(BIN)/NIC : $(AUTO_DEPS)
  200. @$(ECHO) '# This is an automatically generated file, do not edit' > $@
  201. @$(ECHO) '# It does not affect anything in the build, ' \
  202. 'it is only for rom-o-matic' >> $@
  203. @$(ECHO) >> $@
  204. @perl -ne 'chomp; print "$$1\n" if /\# NIC\t(.*)$$/' $^ >> $@
  205. CLEANUP += $(BIN)/NIC
  206. # Analyse a target name (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and
  207. # derive the variables:
  208. #
  209. # TGT_ELEMENTS : the elements of the target (e.g. "dfe538 prism2_pci")
  210. # TGT_PREFIX : the prefix type (e.g. "zrom")
  211. # TGT_DRIVERS : the driver for each element (e.g. "rtl8139 prism2_pci")
  212. # TGT_ROM_NAME : the ROM name (e.g. "dfe538")
  213. # TGT_MEDIA : the media type (e.g. "rom")
  214. #
  215. DRIVERS_gpxe = $(DRIVERS)
  216. CARD_DRIVER = $(firstword $(DRIVER_$(1)) $(1))
  217. TGT_ELEMENTS = $(subst --, ,$(firstword $(subst ., ,$(notdir $@))))
  218. TGT_PREFIX = $(word 2,$(subst ., ,$(notdir $@)))
  219. TGT_ROM_NAME = $(firstword $(TGT_ELEMENTS))
  220. TGT_DRIVERS = $(strip $(if $(DRIVERS_$(TGT_ROM_NAME)), \
  221. $(DRIVERS_$(TGT_ROM_NAME)), \
  222. $(foreach TGT_ELEMENT,$(TGT_ELEMENTS), \
  223. $(call CARD_DRIVER,$(TGT_ELEMENT))) ))
  224. TGT_MEDIA = $(subst z,,$(TGT_PREFIX))
  225. # Look up ROM IDs for the current target
  226. # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
  227. #
  228. # TGT_PCI_VENDOR : the PCI vendor ID (e.g. "0x1186")
  229. # TGT_PCI_DEVICE : the PCI device ID (e.g. "0x1300")
  230. #
  231. TGT_PCI_VENDOR = $(PCI_VENDOR_$(TGT_ROM_NAME))
  232. TGT_PCI_DEVICE = $(PCI_DEVICE_$(TGT_ROM_NAME))
  233. # Calculate link-time options for the current target
  234. # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
  235. #
  236. # TGT_LD_DRIVERS : symbols to require in order to drag in the relevant drivers
  237. # (e.g. "obj_rtl8139 obj_prism2_pci")
  238. # TGT_LD_IDS : symbols to define in order to fill in ID structures in the
  239. # ROM header (e.g."pci_vendor_id=0x1186 pci_device_id=0x1300")
  240. #
  241. TGT_LD_DRIVERS = $(subst -,_,$(patsubst %,obj_%,$(TGT_DRIVERS)))
  242. TGT_LD_PREFIX = obj_$(TGT_PREFIX)prefix
  243. TGT_LD_IDS = $(if $(TGT_PCI_VENDOR),pci_vendor_id=$(TGT_PCI_VENDOR)) \
  244. $(if $(TGT_PCI_DEVICE),pci_device_id=$(TGT_PCI_DEVICE))
  245. # Calculate linker flags based on link-time options for the current
  246. # target type (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the
  247. # variables:
  248. #
  249. # TGT_LD_FLAGS : target-specific flags to pass to linker (e.g.
  250. # "-u obj_zpciprefix -u obj_rtl8139 -u obj_prism2_pci
  251. # --defsym pci_vendor=0x1186 --defsym pci_device=0x1300")
  252. #
  253. TGT_LD_FLAGS = $(foreach SYM,$(TGT_LD_PREFIX) $(TGT_LD_DRIVERS) obj_config,\
  254. -u $(SYM) --defsym check_$(SYM)=$(SYM) ) \
  255. $(patsubst %,--defsym %,$(TGT_LD_IDS))
  256. # Calculate makerom flags for the specific target
  257. # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
  258. #
  259. # TGT_MAKEROM_FLAGS : target-specific flags for makerom (e.g.
  260. # "-p 0x1186,0x1300")
  261. #
  262. TGT_MAKEROM_FLAGS = $(strip $(MAKEROM_FLAGS_$(TGT_ROM_NAME)) \
  263. $(if $(TGT_PCI_VENDOR),$(strip -p $(TGT_PCI_VENDOR),$(TGT_PCI_DEVICE))))
  264. # Calculate list of debugging versions of objects to be included in
  265. # the target.
  266. #
  267. COMMA := ,
  268. DEBUG_LIST = $(subst $(COMMA), ,$(DEBUG))
  269. DEBUG_OBJ_LEVEL = $(firstword $(word 2,$(subst :, ,$(1))) 1)
  270. DEBUG_OBJ_BASE = $(word 1,$(subst :, ,$(1))).dbg$(call DEBUG_OBJ_LEVEL,$(1))
  271. DEBUG_OBJ = $(BIN)/$(call DEBUG_OBJ_BASE,$(1)).o
  272. DEBUG_ORIG_OBJ = $(BIN)/$(word 1,$(subst :, ,$(1))).o
  273. DEBUG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_OBJ,$(D)))
  274. DEBUG_ORIG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_ORIG_OBJ,$(D)))
  275. BLIB_OBJS = $(DEBUG_OBJS) $(filter-out $(DEBUG_ORIG_OBJS),$(BOBJS))
  276. # Print out all derived information for a given target.
  277. #
  278. $(BIN)/%.info :
  279. @$(ECHO) 'Elements : $(TGT_ELEMENTS)'
  280. @$(ECHO) 'Prefix : $(TGT_PREFIX)'
  281. @$(ECHO) 'Drivers : $(TGT_DRIVERS)'
  282. @$(ECHO) 'ROM name : $(TGT_ROM_NAME)'
  283. @$(ECHO) 'Media : $(TGT_MEDIA)'
  284. @$(ECHO)
  285. @$(ECHO) 'PCI vendor : $(TGT_PCI_VENDOR)'
  286. @$(ECHO) 'PCI device : $(TGT_PCI_DEVICE)'
  287. @$(ECHO)
  288. @$(ECHO) 'LD driver symbols : $(TGT_LD_DRIVERS)'
  289. @$(ECHO) 'LD prefix symbols : $(TGT_LD_PREFIX)'
  290. @$(ECHO) 'LD ID symbols : $(TGT_LD_IDS)'
  291. @$(ECHO)
  292. @$(ECHO) 'LD target flags : $(TGT_LD_FLAGS)'
  293. @$(ECHO)
  294. @$(ECHO) 'makerom target flags : $(TGT_MAKEROM_FLAGS)'
  295. @$(ECHO)
  296. @$(ECHO) 'Debugging objects : $(DEBUG_OBJS)'
  297. @$(ECHO) 'Replaced objects : $(DEBUG_ORIG_OBJS)'
  298. # List of objects included in the last build of blib. This is needed
  299. # in order to correctly rebuild blib whenever the list of objects
  300. # changes.
  301. #
  302. BLIB_LIST = $(BIN)/.blib.list
  303. ifneq ($(shell cat $(BLIB_LIST)),$(BLIB_OBJS))
  304. $(shell $(ECHO) "$(BLIB_OBJS)" > $(BLIB_LIST))
  305. endif
  306. $(BLIB_LIST) :
  307. VERYCLEANUP += $(BLIB_LIST)
  308. # Library of all objects
  309. #
  310. BLIB = $(BIN)/blib.a
  311. $(BLIB) : $(BLIB_OBJS) $(BLIB_LIST) $(MAKEDEPS)
  312. $(Q)$(RM) $(BLIB)
  313. $(QM)$(ECHO) " [AR] $@"
  314. $(Q)$(AR) r $@ $(BLIB_OBJS)
  315. $(Q)$(RANLIB) $@
  316. blib : $(BLIB)
  317. # Build an intermediate object file from the objects required for the
  318. # specified target.
  319. #
  320. $(BIN)/%.tmp : $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
  321. $(QM)$(ECHO) " [LD] $@"
  322. $(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $(BLIB) -o $@ \
  323. -Map $(BIN)/$*.tmp.map
  324. $(Q)$(OBJDUMP) -ht $@ | $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
  325. # Keep intermediate object file (useful for debugging)
  326. .SECONDARY : $(BIN)/%.tmp
  327. # Show a linker map for the specified target
  328. #
  329. $(BIN)/%.map : $(BIN)/%.tmp
  330. @less $(BIN)/$*.tmp.map
  331. # Extract compression information from intermediate object file
  332. #
  333. $(BIN)/%.zinfo : $(BIN)/%.tmp
  334. $(QM)$(ECHO) " [ZINFO] $@"
  335. $(Q)$(OBJCOPY) -O binary -j .zinfo $< $@
  336. # Build raw binary file from intermediate object file
  337. #
  338. $(BIN)/%.bin : $(BIN)/%.tmp
  339. $(QM)$(ECHO) " [BIN] $@"
  340. $(Q)$(OBJCOPY) -O binary -R .zinfo $< $@
  341. # Compress raw binary file
  342. #
  343. $(BIN)/%.zbin : $(BIN)/%.bin $(BIN)/%.zinfo $(ZBIN)
  344. $(QM)$(ECHO) " [ZBIN] $@"
  345. $(Q)$(ZBIN) $(BIN)/$*.bin $(BIN)/$*.zinfo > $@
  346. # Build bochs symbol table
  347. $(BIN)/%.bxs : $(BIN)/%.tmp
  348. $(NM) $< | cut -d" " -f1,3 > $@
  349. # Rules for each media format. These are generated and placed in an
  350. # external Makefile fragment. We could do this via $(eval ...), but
  351. # that would require make >= 3.80.
  352. #
  353. # Note that there's an alternative way to generate most .rom images:
  354. # they can be copied from their 'master' ROM image using cp and
  355. # reprocessed with makerom to add the PCI IDs and ident string. The
  356. # relevant rule would look something like:
  357. #
  358. # $(BIN)/dfe538%rom : $(BIN)/rtl8139%rom
  359. # cat $< $@
  360. # $(FINALISE_rom)
  361. #
  362. # You can derive the ROM/driver relationships using the variables
  363. # DRIVER_<rom> and/or ROMS_<driver>.
  364. #
  365. # We don't currently do this, because (a) it would require generating
  366. # yet more Makefile fragments (since you need a rule for each ROM in
  367. # ROMS), and (b) the linker is so fast that it probably wouldn't make
  368. # much difference to the overall build time.
  369. media :
  370. @$(ECHO) $(MEDIA)
  371. AUTO_MEDIA = $(filter-out $(NON_AUTO_MEDIA),$(MEDIA))
  372. automedia :
  373. @$(ECHO) $(AUTO_MEDIA)
  374. # media_template : create Makefile rules for specified media
  375. #
  376. # $(1) is the media name (e.g. "rom")
  377. # $(2) is the full path to the .d file (e.g. "bin/deps/rom.media.d")
  378. #
  379. define media_template
  380. @$(ECHO) "Generating Makefile rules for $(1) media"
  381. @$(MKDIR) -p $(dir $(2))
  382. @$(RM) $(2)
  383. @$(TOUCH) $(2)
  384. @$(ECHO_E) '$$(BIN)/%.$(1) : $$(BIN)/%.$(1).zbin' \
  385. '\n\t$$(QM)$(ECHO) " [FINISH] $$@"' \
  386. '\n\t$$(Q)$$(CP) $$< $$@' \
  387. '\n\t$$(Q)$$(FINALISE_$(1))' \
  388. > $(2)
  389. endef
  390. # Rule to generate the Makefile rules to be included
  391. #
  392. $(BIN)/deps/%.media.d : $(MAKEDEPS)
  393. $(if $(filter $(AUTO_MEDIA),$*), \
  394. $(call media_template,$*,$@), \
  395. @$(ECHO) 'ERROR: $* is not an AUTO_MEDIA' ; exit 1)
  396. # Calculate and include the list of Makefile rules files
  397. #
  398. MEDIA_DEPS = $(patsubst %,$(BIN)/deps/%.media.d,$(AUTO_MEDIA))
  399. mediadeps :
  400. @$(ECHO) $(MEDIA_DEPS)
  401. include $(MEDIA_DEPS)
  402. # The "allXXXs" targets for each suffix
  403. #
  404. allall: allroms allzroms allpxes allisos alldsks
  405. allroms allzroms : all%s : $(foreach ROM,$(ROMS),$(BIN)/$(ROM).%)
  406. allpxes allisos alldsks : all%s : $(foreach DRIVER,$(DRIVERS),$(BIN)/$(DRIVER).%)
  407. # Alias for gpxe.%
  408. #
  409. $(BIN)/etherboot.% : $(BIN)/gpxe.%
  410. ln -sf $(notdir $<) $@
  411. # Wrap up binary blobs
  412. #
  413. $(BIN)/%.o : payload/%.img
  414. $(QM)echo " [WRAP] $@"
  415. $(Q)$(LD) -b binary -r -o $@ $< --undefined obj_payload \
  416. --defsym obj_$*=0
  417. BOBJS += $(patsubst payload/%.img,$(BIN)/%.o,$(wildcard payload/*.img))
  418. # The compression utilities
  419. #
  420. $(NRV2B) : util/nrv2b.c $(MAKEDEPS)
  421. $(QM)$(ECHO) " [HOSTCC] $@"
  422. $(Q)$(HOST_CC) -O2 -DENCODE -DDECODE -DMAIN -DVERBOSE -DNDEBUG \
  423. -DBITSIZE=32 -DENDIAN=0 -o $@ $<
  424. CLEANUP += $(NRV2B)
  425. $(ZBIN) : util/zbin.c util/nrv2b.c $(MAKEDEPS)
  426. $(QM)$(ECHO) " [HOSTCC] $@"
  427. $(Q)$(HOST_CC) -O2 -o $@ $<
  428. CLEANUP += $(ZBIN)
  429. # Auto-incrementing build serial number. Append "bs" to your list of
  430. # build targets to get a serial number printed at the end of the
  431. # build. Enable -DBUILD_SERIAL in order to see it when the code runs.
  432. #
  433. BUILDSERIAL_H = config/.buildserial.h
  434. BUILDSERIAL_NOW = config/.buildserial.now
  435. BUILDSERIAL_NEXT = config/.buildserial.next
  436. $(BUILDSERIAL_NOW) $(BUILDSERIAL_NEXT) :
  437. $(ECHO) 1 > $@
  438. $(BUILDSERIAL_H) : $(BUILDSERIAL_NOW) $(BUILDSERIAL_NEXT)
  439. $(ECHO) '#define BUILD_SERIAL_NUM $(shell cat $<)' > $@
  440. ifeq ($(filter bs,$(MAKECMDGOALS)),bs)
  441. $(shell diff -q $(BUILDSERIAL_NOW) $(BUILDSERIAL_NEXT) > /dev/null || \
  442. cp -f $(BUILDSERIAL_NEXT) $(BUILDSERIAL_NOW))
  443. endif
  444. bs : $(BUILDSERIAL_NOW)
  445. @$(ECHO) $$(( $(shell cat $<) + 1 )) > $(BUILDSERIAL_NEXT)
  446. @$(ECHO) "Build serial number is $(shell cat $<)"
  447. # List of available architectures
  448. #
  449. ARCHS = $(filter-out CVS,$(patsubst arch/%,%,$(wildcard arch/*)))
  450. archs :
  451. @$(ECHO) $(ARCHS)
  452. OTHER_ARCHS = $(filter-out $(ARCH),$(ARCHS))
  453. otherarchs :
  454. @$(ECHO) $(OTHER_ARCHS)
  455. # Build the TAGS file for emacs
  456. #
  457. TAGS : TAGS.$(ARCH)
  458. TAGS.$(ARCH) :
  459. ctags -e -R -f $@ --exclude=bin \
  460. $(foreach ARCH,$(OTHER_ARCHS),--exclude=arch/$(ARCH))
  461. CLEANUP += TAGS*
  462. # Symbol table checks
  463. #
  464. SYMTAB = $(BIN)/symtab
  465. $(SYMTAB) : $(BLIB)
  466. $(OBJDUMP) -w -t $< > $@
  467. CLEANUP += $(BIN)/symtab
  468. symcheck : $(SYMTAB)
  469. $(SYMCHECK) $<
  470. # Force rebuild for any given target
  471. #
  472. $(BIN)/%.rebuild :
  473. rm -f $(BIN)/$*
  474. $(MAKE) $(MAKEFLAGS) $(BIN)/$*
  475. # Documentation
  476. #
  477. $(BIN)/doxygen.cfg : doxygen.cfg $(MAKEDEPS)
  478. $(PERL) -pe 's{\@SRCDIRS\@}{$(SRCDIRS)}; ' \
  479. -e 's{\@BIN\@}{$(BIN)}; ' \
  480. -e 's{\@ARCH\@}{$(ARCH)}; ' \
  481. $< > $@
  482. $(BIN)/doc : $(BIN)/doxygen.cfg
  483. $(DOXYGEN) $<
  484. .PHONY : $(BIN)/doc
  485. VERYCLEANUP += $(BIN)/doc
  486. doc : $(BIN)/doc
  487. docview :
  488. @[ -f $(BIN)/doc/html/index.html ] || $(MAKE) $(BIN)/doc
  489. @if [ -n "$$BROWSER" ] ; then \
  490. ( $$BROWSER $(BIN)/doc/html/index.html & ) ; \
  491. else \
  492. $(ECHO) "Documentation index in $(BIN)/doc/html/index.html" ; \
  493. fi
  494. # Clean-up
  495. #
  496. clean :
  497. $(RM) $(CLEANUP)
  498. veryclean : clean
  499. $(RM) -r $(VERYCLEANUP)
  500. # Make clean tarballs for release
  501. gpxe-tarball : ../VERSION
  502. ($(ECHO) -n $(VERSION) ''; date -u +'%Y-%m-%d') > ../VERSION
  503. $(RM) -r /tmp/gpxe/gpxe-$(VERSION)
  504. mkdir -p /tmp/gpxe/gpxe-$(VERSION)
  505. cp -rP .. /tmp/gpxe/gpxe-$(VERSION)
  506. $(RM) -r /tmp/gpxe/CVS
  507. ( cd /tmp/gpxe/gpxe-$(VERSION)/src ; $(RM) -r bin/deps ; $(MAKE) clean ; $(MAKE) veryclean )
  508. ( cd /tmp/gpxe; tar cf /tmp/gpxe/gpxe-$(VERSION).tar --exclude CVS --exclude "#*" \
  509. --exclude "*~" gpxe-$(VERSION) )
  510. bzip2 -9 < /tmp/gpxe/gpxe-$(VERSION).tar > /tmp/gpxe/gpxe-$(VERSION).tar.bz2
  511. gzip -9 < /tmp/gpxe/gpxe-$(VERSION).tar > /tmp/gpxe/gpxe-$(VERSION).tar.gz
  512. $(RM) -r /tmp/gpxe/gpxe-$(VERSION)
  513. $(RM) /tmp/gpxe/gpxe-$(VERSION).tar
  514. ( cd /tmp/gpxe ; tar -zxf /tmp/gpxe/gpxe-$(VERSION).tar.gz )