您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Makefile.housekeeping 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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 = 5
  10. VERSION_MINOR = 3
  11. VERSION_PATCH = 14
  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. # Check for an old version of gas (binutils 2.9.1)
  38. #
  39. OLDGAS := $(shell $(AS) --version | grep -q '2\.9\.1' && echo -DGAS291)
  40. CFLAGS += $(OLDGAS)
  41. oldgas :
  42. @echo $(oldgas)
  43. # SRCDIRS lists all directories containing source files.
  44. srcdirs :
  45. @echo $(SRCDIRS)
  46. # SRCS lists all .c or .S files found in any SRCDIR
  47. #
  48. SRCS += $(wildcard $(patsubst %,%/*.c,$(SRCDIRS)))
  49. SRCS += $(wildcard $(patsubst %,%/*.S,$(SRCDIRS)))
  50. srcs :
  51. @echo $(SRCS)
  52. # AUTO_SRCS lists all files in SRCS that are not mentioned in
  53. # NON_AUTO_SRCS. Files should be added to NON_AUTO_SRCS if they
  54. # cannot be built using the standard build template.
  55. #
  56. AUTO_SRCS = $(filter-out $(NON_AUTO_SRCS),$(SRCS))
  57. autosrcs :
  58. @echo $(AUTO_SRCS)
  59. # We automatically generate rules for any file mentioned in AUTO_SRCS
  60. # using the following set of templates. It would be cleaner to use
  61. # $(eval ...), but this function exists only in GNU make >= 3.80.
  62. # src_template : generate Makefile rules for a given source file
  63. #
  64. # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
  65. # $(2) is the full path to the .d file (e.g. "bin/deps/drivers/net/rtl8139.d")
  66. # $(3) is the source type (e.g. "c")
  67. # $(4) is the source base name (e.g. "rtl8139")
  68. #
  69. define src_template
  70. @echo "Generating Makefile rules for $(1)"
  71. @$(MKDIR) -p $(dir $(2))
  72. @$(RM) $(2)
  73. @$(TOUCH) $(2)
  74. $(foreach OBJ,$(if $(OBJS_$(4)),$(OBJS_$(4)),$(4)), \
  75. $(call obj_template,$(1),$(2),$(3),$(OBJ)))
  76. @$(PARSEROM) $(1) >> $(2)
  77. endef
  78. # obj_template : generate Makefile rules for a given resultant object
  79. # of a particular source file. (We can have multiple objects per
  80. # source file via the OBJS_xxx list.)
  81. #
  82. # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
  83. # $(2) is the full path to the .d file (e.g. "bin/deps/drivers/net/rtl8139.d")
  84. # $(3) is the source type (e.g. "c")
  85. # $(4) is the object name (e.g. "rtl8139")
  86. #
  87. define obj_template
  88. @$(CPP) $(CFLAGS) $(CFLAGS_$(3)) $(CFLAGS_$(4)) \
  89. -M $(1) -MT "$(4)_DEPS" | tr : = >> $(2)
  90. @echo -e '\n$$(BIN)/$(4).o : $(1) $$(MAKEDEPS) $$($(4)_DEPS)' \
  91. '\n\t$$(RULE_$(3))\n' \
  92. '\nBOBJS += $$(BIN)/$(4).o\n' \
  93. $(foreach TGT,$(DEBUG_TARGETS), \
  94. $(if $(RULE_$(3)_to_$(TGT)), \
  95. '\n$$(BIN)/$(4).$(TGT) : $(1) $$(MAKEDEPS) $$($(4)_DEPS)' \
  96. '\n\t$$(RULE_$(3)_to_$(TGT))\n' ) ) \
  97. '\n$(2) : $$($(4)_DEPS)\n' \
  98. '\nTAGS : $$($(4)_DEPS)\n' \
  99. >> $(2)
  100. endef
  101. # Rule to generate the Makefile rules files to be included
  102. #
  103. $(BIN)/deps/%.d : % $(MAKEDEPS) $(PARSEROM)
  104. $(if $(filter $(AUTO_SRCS),$<),$(call src_template,$<,$@,$(subst .,,$(suffix $<)),$(basename $(notdir $<))),@echo 'ERROR: $< is not an AUTO_SRC' ; exit 1)
  105. # Calculate and include the list of Makefile rules files
  106. #
  107. AUTO_DEPS = $(patsubst %,$(BIN)/deps/%.d,$(AUTO_SRCS))
  108. include $(AUTO_DEPS)
  109. autodeps :
  110. @echo $(AUTO_DEPS)
  111. VERYCLEANUP += $(BIN)/deps
  112. # The following variables are created by the Makefile rules files
  113. #
  114. bobjs :
  115. @echo $(BOBJS)
  116. drivers :
  117. @echo $(DRIVERS)
  118. .PHONY : drivers
  119. roms :
  120. @echo $(ROMS)
  121. # Generate the NIC file from the parsed source files. The NIC file is
  122. # only for rom-o-matic.
  123. #
  124. $(BIN)/NIC : $(AUTO_DEPS)
  125. @echo '# This is an automatically generated file, do not edit' > $@
  126. @echo '# It does not affect anything in the build, ' \
  127. 'it is only for rom-o-matic' >> $@
  128. @echo >> $@
  129. @perl -ne 'chomp; print "$$1\n" if /\# NIC\t(.*)$$/' $^ >> $@
  130. CLEANUP += $(BIN)/NIC
  131. # Library of all objects
  132. #
  133. $(BLIB) : $(BOBJS)
  134. $(AR) r $@ $(BOBJS)
  135. $(RANLIB) $@
  136. blib : $(BLIB)
  137. # Analyse a target name (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and
  138. # derive the variables:
  139. #
  140. # TGT_ELEMENTS : the elements of the target (e.g. "dfe538 prism2_pci")
  141. # TGT_PREFIX : the prefix type (e.g. "zrom")
  142. # TGT_DRIVERS : the driver for each element (e.g. "rtl8139 prism2_pci")
  143. # TGT_ROM_NAME : the ROM name (e.g. "dfe538")
  144. # TGT_MEDIA : the media type (e.g. "rom")
  145. #
  146. TGT_ELEMENTS = $(subst --, ,$(firstword $(subst ., ,$(notdir $@))))
  147. TGT_PREFIX = $(word 2,$(subst ., ,$(notdir $@)))
  148. TGT_DRIVERS = $(strip $(foreach TGT_ELEMENT,$(TGT_ELEMENTS), \
  149. $(firstword $(DRIVER_$(TGT_ELEMENT)) $(TGT_ELEMENT))))
  150. TGT_ROM_NAME = $(firstword $(TGT_ELEMENTS))
  151. TGT_MEDIA = $(subst z,,$(TGT_PREFIX))
  152. # Look up ROM type and IDs for the current target
  153. # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
  154. #
  155. # TGT_ROM_TYPE : PCI/ISA indicator (e.g. "pci")
  156. # TGT_PCI_VENDOR : the PCI vendor ID (e.g. "0x1186")
  157. # TGT_PCI_DEVICE : the PCI device ID (e.g. "0x1300")
  158. #
  159. TGT_ROM_TYPE = $(ROM_TYPE_$(TGT_ROM_NAME))
  160. TGT_PCI_VENDOR = $(PCI_VENDOR_$(TGT_ROM_NAME))
  161. TGT_PCI_DEVICE = $(PCI_DEVICE_$(TGT_ROM_NAME))
  162. # Calculate link-time options for the current target
  163. # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
  164. #
  165. # TGT_LD_DRIVERS : symbols to require in order to drag in the relevant drivers
  166. # (e.g. "obj_rtl8139 obj_prism2_pci")
  167. # TGT_LD_PREFIX : symbols to require in order to drag in the relevant prefix
  168. # (e.g. "obj_zpciprefix")
  169. # TGT_LD_IDS : symbols to define in order to fill in ID structures in the
  170. # ROM header (e.g. "pci_vendor=0x1186 pci_device=0x1300")
  171. #
  172. TGT_LD_DRIVERS = $(subst -,_,$(patsubst %,obj_%,$(TGT_DRIVERS)))
  173. TGT_LD_PREFIX = obj_$(subst rom,$(TGT_ROM_TYPE),$(TGT_PREFIX))prefix
  174. TGT_LD_IDS = $(if $(TGT_PCI_VENDOR),pci_vendor=$(TGT_PCI_VENDOR)) \
  175. $(if $(TGT_PCI_DEVICE),pci_device=$(TGT_PCI_DEVICE))
  176. # Calculate linker flags based on link-time options for the current
  177. # target type (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the
  178. # variables:
  179. #
  180. # TGT_LD_FLAGS : target-specific flags to pass to linker (e.g.
  181. # "-u obj_zpciprefix -u obj_rtl8139 -u obj_prism2_pci
  182. # --defsym pci_vendor=0x1186 --defsym pci_device=0x1300")
  183. #
  184. TGT_LD_FLAGS = $(foreach SYM,$(TGT_LD_PREFIX) $(TGT_LD_DRIVERS) obj_config,\
  185. -u $(SYM) --defsym check_$(SYM)=$(SYM) ) \
  186. $(patsubst %,--defsym %,$(TGT_LD_IDS))
  187. # Calculate makerom flags for the specific target
  188. # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
  189. #
  190. # TGT_MAKEROM_FLAGS : target-specific flags for makerom (e.g.
  191. # "-p 0x1186,0x1300")
  192. #
  193. TGT_MAKEROM_FLAGS = $(strip $(MAKEROM_FLAGS_$(TGT_ROM_NAME)) \
  194. $(if $(TGT_PCI_VENDOR),$(strip -p $(TGT_PCI_VENDOR),$(TGT_PCI_DEVICE))))
  195. # Print out all derived information for a given target.
  196. #
  197. $(BIN)/%.info :
  198. @echo 'Elements : $(TGT_ELEMENTS)'
  199. @echo 'Prefix : $(TGT_PREFIX)'
  200. @echo 'Drivers : $(TGT_DRIVERS)'
  201. @echo 'ROM name : $(TGT_ROM_NAME)'
  202. @echo 'Media : $(TGT_MEDIA)'
  203. @echo
  204. @echo 'ROM type : $(TGT_ROM_TYPE)'
  205. @echo 'PCI vendor : $(TGT_PCI_VENDOR)'
  206. @echo 'PCI device : $(TGT_PCI_DEVICE)'
  207. @echo
  208. @echo 'LD driver symbols : $(TGT_LD_DRIVERS)'
  209. @echo 'LD prefix symbols : $(TGT_LD_PREFIX)'
  210. @echo 'LD ID symbols : $(TGT_LD_IDS)'
  211. @echo
  212. @echo 'LD target flags : $(TGT_LD_FLAGS)'
  213. @echo
  214. @echo 'makerom target flags : $(TGT_MAKEROM_FLAGS)'
  215. # Build an intermediate object file from the objects required for the
  216. # specified target.
  217. #
  218. $(BIN)/%.tmp : $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
  219. $(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $< -o $@ \
  220. -Map $(BIN)/$*.tmp.map
  221. # Show a linker map for the specified target
  222. #
  223. $(BIN)/%.map : $(BIN)/%.tmp
  224. @less $(BIN)/$*.tmp.map
  225. # Rules for each media format. These are generated and placed in an
  226. # external Makefile fragment. We could do this via $(eval ...), but
  227. # that would require make >= 3.80.
  228. #
  229. # Note that there's an alternative way to generate most .rom images:
  230. # they can be copied from their 'master' ROM image using cp and
  231. # reprocessed with makerom to add the PCI IDs and ident string. The
  232. # relevant rule would look something like:
  233. #
  234. # $(BIN)/dfe538%rom : $(BIN)/rtl8139%rom
  235. # cat $< $@
  236. # $(FINALISE_rom)
  237. #
  238. # You can derive the ROM/driver relationships using the variables
  239. # DRIVER_<rom> and/or ROMS_<driver>.
  240. #
  241. # We don't currently do this, because (a) it would require generating
  242. # yet more Makefile fragments (since you need a rule for each ROM in
  243. # ROMS), and (b) the linker is so fast that it probably wouldn't make
  244. # much difference to the overall build time.
  245. media :
  246. @echo $(MEDIA)
  247. AUTO_MEDIA = $(filter-out $(NON_AUTO_MEDIA),$(MEDIA))
  248. automedia :
  249. @echo $(AUTO_MEDIA)
  250. # media_template : create Makefile rules for specified media
  251. #
  252. # $(1) is the media name (e.g. "rom")
  253. # $(2) is the full path to the .d file (e.g. "bin/deps/rom.media.d")
  254. #
  255. define media_template
  256. @echo "Generating Makefile rules for $(1) media"
  257. @$(MKDIR) -p $(dir $(2))
  258. @$(RM) $(2)
  259. @$(TOUCH) $(2)
  260. @echo -e '$$(BIN)/%$(1) : $$(BIN)/%$(1).tmp' \
  261. '\n\t$$(OBJCOPY) -O binary $$< $$@' \
  262. '\n\t$$(FINALISE_$(1))' \
  263. > $(2)
  264. endef
  265. # Rule to generate the Makefile rules to be included
  266. #
  267. $(BIN)/deps/%.media.d : $(MAKEDEPS)
  268. $(if $(filter $(AUTO_MEDIA),$*), \
  269. $(call media_template,$*,$@), \
  270. @echo 'ERROR: $* is not an AUTO_MEDIA' ; exit 1)
  271. # Calculate and include the list of Makefile rules files
  272. #
  273. MEDIA_DEPS = $(patsubst %,$(BIN)/deps/%.media.d,$(AUTO_MEDIA))
  274. mediadeps :
  275. @echo $(MEDIA_DEPS)
  276. include $(MEDIA_DEPS)
  277. # The "allXXXs" targets for each suffix
  278. #
  279. allroms allzroms : all%s : $(foreach ROM,$(ROMS),$(BIN)/$(ROM).%)
  280. all%s : $(foreach DRIVER,$(DRIVERS),$(BIN)/$(DRIVER).%)
  281. # The compressor utility
  282. #
  283. $(NRV2B) : util/nrv2b.c $(MAKEDEPS)
  284. $(HOST_CC) -O2 -DENCODE -DDECODE -DMAIN -DVERBOSE -DNDEBUG \
  285. -DBITSIZE=32 -DENDIAN=0 -o $@ $<
  286. CLEANUP += $(NRV2B)
  287. # Auto-incrementing build serial number. Append "bs" to your list of
  288. # build targets to get a serial number printed at the end of the
  289. # build. Enable -DBUILD_SERIAL in order to see it when the code runs.
  290. #
  291. BUILDSERIAL_H = include/.buildserial.h
  292. $(BUILDSERIAL_H) :
  293. @if [ ! -s $@ ]; then echo '#define BUILD_SERIAL_NUM 0' > $@; fi
  294. @perl -pi -e 's/(BUILD_SERIAL_NUM)\s+(\d+)/"$${1} ".($${2}+1)/e' $@
  295. bs : $(BUILDSERIAL_H)
  296. @perl -n -e '/BUILD_SERIAL_NUM\s+(\d+)/ && ' \
  297. -e 'print "Build serial number is $$1\n";' $<
  298. ifeq ($(filter bs,$(MAKECMDGOALS)),bs)
  299. .PHONY : $(BUILDSERIAL_H)
  300. endif
  301. # Ensure that include/.buildserial.h always exists, to solve the
  302. # problem of bootstrapping a BUILD_SERIAL-enabled build.
  303. #
  304. ifeq ($(wildcard $(BUILDSERIAL_H)),)
  305. $(shell $(TOUCH) $(BUILDSERIAL_H))
  306. endif
  307. # List of available architectures
  308. #
  309. ARCHS = $(filter-out CVS,$(patsubst arch/%,%,$(wildcard arch/*)))
  310. archs :
  311. @echo $(ARCHS)
  312. OTHER_ARCHS = $(filter-out $(ARCH),$(ARCHS))
  313. otherarchs :
  314. @echo $(OTHER_ARCHS)
  315. # Build the TAGS file for emacs
  316. #
  317. TAGS : TAGS.$(ARCH)
  318. TAGS.$(ARCH) :
  319. ctags -e -R -f $@ $(foreach ARCH,$(OTHER_ARCHS),--exclude=arch/$(ARCH))
  320. CLEANUP += TAGS*
  321. # Clean-up
  322. #
  323. clean :
  324. $(RM) $(CLEANUP)
  325. veryclean : clean
  326. $(RM) -r $(VERYCLEANUP)