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 32KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136
  1. # -*- makefile -*- : Force emacs to use Makefile mode
  2. #
  3. # This file contains various boring housekeeping functions that would
  4. # otherwise seriously clutter up the main Makefile.
  5. ###############################################################################
  6. #
  7. # Find a usable "echo -e" substitute.
  8. #
  9. TAB := $(shell $(PRINTF) '\t')
  10. ECHO_E_ECHO := $(ECHO)
  11. ECHO_E_ECHO_E := $(ECHO) -e
  12. ECHO_E_BIN_ECHO := /bin/echo
  13. ECHO_E_BIN_ECHO_E := /bin/echo -e
  14. ECHO_E_ECHO_TAB := $(shell $(ECHO_E_ECHO) '\t' | cat)
  15. ECHO_E_ECHO_E_TAB := $(shell $(ECHO_E_ECHO_E) '\t' | cat)
  16. ECHO_E_BIN_ECHO_TAB := $(shell $(ECHO_E_BIN_ECHO) '\t')
  17. ECHO_E_BIN_ECHO_E_TAB := $(shell $(ECHO_E_BIN_ECHO_E) '\t')
  18. ifeq ($(ECHO_E_ECHO_TAB),$(TAB))
  19. ECHO_E := $(ECHO_E_ECHO)
  20. endif
  21. ifeq ($(ECHO_E_ECHO_E_TAB),$(TAB))
  22. ECHO_E := $(ECHO_E_ECHO_E)
  23. endif
  24. ifeq ($(ECHO_E_BIN_ECHO_TAB),$(TAB))
  25. ECHO_E := $(ECHO_E_BIN_ECHO)
  26. endif
  27. ifeq ($(ECHO_E_BIN_ECHO_E_TAB),$(TAB))
  28. ECHO_E := $(ECHO_E_BIN_ECHO_E)
  29. endif
  30. .echocheck :
  31. ifdef ECHO_E
  32. @$(TOUCH) $@
  33. else
  34. @$(PRINTF) '%24s : x%sx\n' 'tab' '$(TAB)'
  35. @$(PRINTF) '%24s : x%sx\n' '"$(ECHO_E_ECHO) \t"' \
  36. '$(ECHO_E_ECHO_TAB)'
  37. @$(PRINTF) '%24s : x%sx\n' '"$(ECHO_E_ECHO_E) \t"' \
  38. '$(ECHO_E_ECHO_E_TAB)'
  39. @$(PRINTF) '%24s : x%sx\n' '"$(ECHO_E_BIN_ECHO) \t"' \
  40. '$(ECHO_E_BIN_ECHO_TAB)'
  41. @$(PRINTF) '%24s : x%sx\n' '"$(ECHO_E_BIN_ECHO_E) \t"' \
  42. '$(ECHO_E_BIN_ECHO_E_TAB)'
  43. @$(ECHO) "No usable \"echo -e\" substitute found"
  44. @exit 1
  45. endif
  46. MAKEDEPS += .echocheck
  47. VERYCLEANUP += .echocheck
  48. echo :
  49. @$(ECHO) "Using \"$(ECHO_E)\" for \"echo -e\""
  50. ###############################################################################
  51. #
  52. # Generate a usable "seq" substitute
  53. #
  54. define seq
  55. $(shell awk 'BEGIN { for ( i = $(1) ; i <= $(2) ; i++ ) print i }')
  56. endef
  57. ###############################################################################
  58. #
  59. # Determine host OS
  60. #
  61. HOST_OS := $(shell uname -s)
  62. hostos :
  63. @$(ECHO) $(HOST_OS)
  64. ###############################################################################
  65. #
  66. # Determine compiler
  67. CCDEFS := $(shell $(CC) -E -x c -c /dev/null -dM | cut -d" " -f2)
  68. ccdefs:
  69. @$(ECHO) $(CCDEFS)
  70. ifeq ($(filter __ICC,$(CCDEFS)),__ICC)
  71. CCTYPE := icc
  72. else
  73. CCTYPE := gcc
  74. endif
  75. cctype:
  76. @$(ECHO) $(CCTYPE)
  77. ###############################################################################
  78. #
  79. # Check for tools that can cause failed builds
  80. #
  81. .toolcheck :
  82. @if $(CC) -v 2>&1 | grep -is 'gcc version 2\.96' > /dev/null; then \
  83. $(ECHO) 'gcc 2.96 is unsuitable for compiling Etherboot'; \
  84. $(ECHO) 'Use gcc 2.95 or gcc 3.x instead'; \
  85. exit 1; \
  86. fi
  87. @if [ `perl -e 'use bytes; print chr(255)' | wc -c` = 2 ]; then \
  88. $(ECHO) 'Your Perl version has a Unicode handling bug'; \
  89. $(ECHO) 'Execute this command before compiling Etherboot:'; \
  90. $(ECHO) 'export LANG=$${LANG%.UTF-8}'; \
  91. exit 1; \
  92. fi
  93. @$(TOUCH) $@
  94. MAKEDEPS += .toolcheck
  95. VERYCLEANUP += .toolcheck
  96. ###############################################################################
  97. #
  98. # Check for various tool workarounds
  99. #
  100. WORKAROUND_CFLAGS :=
  101. WORKAROUND_ASFLAGS :=
  102. WORKAROUND_LDFLAGS :=
  103. # Make syntax does not allow use of comma or space in certain places.
  104. # This ugly workaround is suggested in the manual.
  105. #
  106. COMMA := ,
  107. EMPTY :=
  108. SPACE := $(EMPTY) $(EMPTY)
  109. # Check for an old version of gas (binutils 2.9.1)
  110. #
  111. OLDGAS := $(shell $(AS) --version | grep -q '2\.9\.1' && $(ECHO) -DGAS291)
  112. WORKAROUND_CFLAGS += $(OLDGAS)
  113. oldgas :
  114. @$(ECHO) $(oldgas)
  115. # Some widespread patched versions of gcc include -fstack-protector by
  116. # default, even when -ffreestanding is specified. We therefore need
  117. # to disable -fstack-protector if the compiler supports it.
  118. #
  119. ifeq ($(CCTYPE),gcc)
  120. SP_TEST = $(CC) -fno-stack-protector -x c -c /dev/null \
  121. -o /dev/null >/dev/null 2>&1
  122. SP_FLAGS := $(shell $(SP_TEST) && $(ECHO) '-fno-stack-protector')
  123. WORKAROUND_CFLAGS += $(SP_FLAGS)
  124. endif
  125. # Some widespread patched versions of gcc include -fPIE -Wl,-pie by
  126. # default. Note that gcc will exit *successfully* if it fails to
  127. # recognise an option that starts with "no", so we have to test for
  128. # output on stderr instead of checking the exit status.
  129. #
  130. ifeq ($(CCTYPE),gcc)
  131. PIE_TEST = [ -z "`$(CC) -fno-PIE -nopie -x c -c /dev/null -o /dev/null 2>&1`" ]
  132. PIE_FLAGS := $(shell $(PIE_TEST) && $(ECHO) '-fno-PIE -nopie')
  133. WORKAROUND_CFLAGS += $(PIE_FLAGS)
  134. endif
  135. # gcc 4.4 generates .eh_frame sections by default, which distort the
  136. # output of "size". Inhibit this.
  137. #
  138. ifeq ($(CCTYPE),gcc)
  139. CFI_TEST = $(CC) -fno-dwarf2-cfi-asm -x c -c /dev/null \
  140. -o /dev/null >/dev/null 2>&1
  141. CFI_FLAGS := $(shell $(CFI_TEST) && $(ECHO) '-fno-dwarf2-cfi-asm')
  142. WORKAROUND_CFLAGS += $(CFI_FLAGS)
  143. endif
  144. # gcc 4.6 generates spurious warnings if -Waddress is in force.
  145. # Inhibit this.
  146. #
  147. ifeq ($(CCTYPE),gcc)
  148. WNA_TEST = $(CC) -Wno-address -x c -c /dev/null -o /dev/null >/dev/null 2>&1
  149. WNA_FLAGS := $(shell $(WNA_TEST) && $(ECHO) '-Wno-address')
  150. WORKAROUND_CFLAGS += $(WNA_FLAGS)
  151. endif
  152. # Some versions of gas choke on division operators, treating them as
  153. # comment markers. Specifying --divide will work around this problem,
  154. # but isn't available on older gas versions.
  155. #
  156. DIVIDE_TEST = $(AS) --divide /dev/null -o /dev/null 2>/dev/null
  157. DIVIDE_FLAGS := $(shell $(DIVIDE_TEST) && $(ECHO) '--divide')
  158. WORKAROUND_ASFLAGS += $(DIVIDE_FLAGS)
  159. ###############################################################################
  160. #
  161. # Build verbosity
  162. #
  163. ifeq ($(V),1)
  164. Q :=
  165. QM := @\#
  166. else
  167. Q := @
  168. QM := @
  169. endif
  170. ###############################################################################
  171. #
  172. # Set BIN according to whatever was specified on the command line as
  173. # the build target.
  174. #
  175. # Determine how many different BIN directories are mentioned in the
  176. # make goals.
  177. #
  178. BIN_GOALS := $(filter bin/% bin-%,$(MAKECMDGOALS))
  179. BIN_GOALS_BINS := $(sort $(foreach BG,$(BIN_GOALS),\
  180. $(firstword $(subst /, ,$(BG)))))
  181. NUM_BINS := $(words $(BIN_GOALS_BINS))
  182. ifeq ($(NUM_BINS),0)
  183. # No BIN directory was specified. Set BIN to "bin" as a sensible
  184. # default.
  185. BIN := bin
  186. else # NUM_BINS == 0
  187. ifeq ($(NUM_BINS),1)
  188. # If exactly one BIN directory was specified, set BIN to match this
  189. # directory.
  190. #
  191. BIN := $(firstword $(BIN_GOALS_BINS))
  192. else # NUM_BINS == 1
  193. # More than one BIN directory was specified. We cannot handle the
  194. # latter case within a single make invocation, so set up recursive
  195. # targets for each BIN directory. Use exactly one target for each BIN
  196. # directory since running multiple make invocations within the same
  197. # BIN directory is likely to cause problems.
  198. #
  199. # Leave $(BIN) undefined. This has implications for any target that
  200. # depends on $(BIN); such targets should be made conditional upon the
  201. # existence of $(BIN).
  202. #
  203. BIN_GOALS_FIRST := $(foreach BGB,$(BIN_GOALS_BINS),\
  204. $(firstword $(filter $(BGB)/%,$(BIN_GOALS))))
  205. BIN_GOALS_OTHER := $(filter-out $(BIN_GOALS_FIRST),$(BIN_GOALS))
  206. $(BIN_GOALS_FIRST) : % : BIN_RECURSE
  207. $(Q)$(MAKE) --no-print-directory BIN=$(firstword $(subst /, ,$@)) \
  208. $(filter $(firstword $(subst /, ,$@))/%, $(BIN_GOALS))
  209. $(BIN_GOALS_OTHER) : % : BIN_RECURSE
  210. $(Q)$(TRUE)
  211. .PHONY : BIN_RECURSE
  212. endif # NUM_BINS == 1
  213. endif # NUM_BINS == 0
  214. ifdef BIN
  215. # Create $(BIN) directory if it doesn't exist yet
  216. #
  217. ifeq ($(wildcard $(BIN)),)
  218. $(shell $(MKDIR) -p $(BIN))
  219. endif
  220. # Target to allow e.g. "make bin-efi arch"
  221. #
  222. $(BIN) :
  223. @# Do nothing, silently
  224. .PHONY : $(BIN)
  225. # Remove everything in $(BIN) for a "make clean"
  226. #
  227. CLEANUP += $(BIN)/*.* # Avoid picking up directories
  228. endif # defined(BIN)
  229. # Determine whether or not we need to include the dependency files
  230. #
  231. NO_DEP_TARGETS := $(BIN) clean veryclean
  232. ifeq ($(MAKECMDGOALS),)
  233. NEED_DEPS := 1
  234. endif
  235. ifneq ($(strip $(filter-out $(NO_DEP_TARGETS),$(MAKECMDGOALS))),)
  236. NEED_DEPS := 1
  237. endif
  238. ###############################################################################
  239. #
  240. # Select build architecture and platform based on $(BIN)
  241. #
  242. # BIN has the form bin[-[arch-]platform]
  243. ARCHS := $(patsubst arch/%,%,$(wildcard arch/*))
  244. PLATFORMS := $(patsubst config/defaults/%.h,%,\
  245. $(wildcard config/defaults/*.h))
  246. archs :
  247. @$(ECHO) $(ARCHS)
  248. platforms :
  249. @$(ECHO) $(PLATFORMS)
  250. ifdef BIN
  251. # Determine architecture portion of $(BIN), if present
  252. BIN_ARCH := $(strip $(foreach A,$(ARCHS),\
  253. $(patsubst bin-$(A)-%,$(A),\
  254. $(filter bin-$(A)-%,$(BIN)))))
  255. # Determine platform portion of $(BIN), if present
  256. ifeq ($(BIN_ARCH),)
  257. BIN_PLATFORM := $(patsubst bin-%,%,$(filter bin-%,$(BIN)))
  258. else
  259. BIN_PLATFORM := $(patsubst bin-$(BIN_ARCH)-%,%,$(BIN))
  260. endif
  261. # Determine build architecture
  262. DEFAULT_ARCH := i386
  263. ARCH := $(firstword $(BIN_ARCH) $(DEFAULT_ARCH))
  264. CFLAGS += -DARCH=$(ARCH)
  265. arch :
  266. @$(ECHO) $(ARCH)
  267. .PHONY : arch
  268. # Determine build platform
  269. DEFAULT_PLATFORM := pcbios
  270. PLATFORM := $(firstword $(BIN_PLATFORM) $(DEFAULT_PLATFORM))
  271. CFLAGS += -DPLATFORM=$(PLATFORM)
  272. platform :
  273. @$(ECHO) $(PLATFORM)
  274. endif # defined(BIN)
  275. # Include architecture-specific Makefile
  276. ifdef ARCH
  277. MAKEDEPS += arch/$(ARCH)/Makefile
  278. include arch/$(ARCH)/Makefile
  279. endif
  280. # Include architecture-specific include path
  281. ifdef ARCH
  282. INCDIRS += arch/$(ARCH)/include
  283. INCDIRS += arch/$(ARCH)/include/$(PLATFORM)
  284. endif
  285. ###############################################################################
  286. #
  287. # Source file handling
  288. # SRCDIRS lists all directories containing source files.
  289. srcdirs :
  290. @$(ECHO) $(SRCDIRS)
  291. # SRCS lists all .c or .S files found in any SRCDIR
  292. #
  293. SRCS += $(wildcard $(patsubst %,%/*.c,$(SRCDIRS)))
  294. SRCS += $(wildcard $(patsubst %,%/*.S,$(SRCDIRS)))
  295. srcs :
  296. @$(ECHO) $(SRCS)
  297. # AUTO_SRCS lists all files in SRCS that are not mentioned in
  298. # NON_AUTO_SRCS. Files should be added to NON_AUTO_SRCS if they
  299. # cannot be built using the standard build template.
  300. #
  301. AUTO_SRCS = $(filter-out $(NON_AUTO_SRCS),$(SRCS))
  302. autosrcs :
  303. @$(ECHO) $(AUTO_SRCS)
  304. # Just about everything else in this section depends upon having
  305. # $(BIN) set
  306. ifdef BIN
  307. # INCDIRS lists the include path
  308. incdirs :
  309. @$(ECHO) $(INCDIRS)
  310. # Common flags
  311. #
  312. CFLAGS += $(foreach INC,$(INCDIRS),-I$(INC))
  313. CFLAGS += -Os
  314. CFLAGS += -g
  315. ifeq ($(CCTYPE),gcc)
  316. CFLAGS += -ffreestanding
  317. CFLAGS += -Wall -W -Wformat-nonliteral
  318. endif
  319. ifeq ($(CCTYPE),icc)
  320. CFLAGS += -fno-builtin
  321. CFLAGS += -no-ip
  322. CFLAGS += -no-gcc
  323. CFLAGS += -diag-disable 111 # Unreachable code
  324. CFLAGS += -diag-disable 128 # Unreachable loop
  325. CFLAGS += -diag-disable 170 # Array boundary checks
  326. CFLAGS += -diag-disable 177 # Unused functions
  327. CFLAGS += -diag-disable 181 # printf() format checks
  328. CFLAGS += -diag-disable 188 # enum strictness
  329. CFLAGS += -diag-disable 193 # Undefined preprocessor identifiers
  330. CFLAGS += -diag-disable 280 # switch ( constant )
  331. CFLAGS += -diag-disable 310 # K&R parameter lists
  332. CFLAGS += -diag-disable 424 # Extra semicolon
  333. CFLAGS += -diag-disable 589 # Declarations mid-code
  334. CFLAGS += -diag-disable 593 # Unused variables
  335. CFLAGS += -diag-disable 810 # Casting ints to smaller ints
  336. CFLAGS += -diag-disable 981 # Sequence point violations
  337. CFLAGS += -diag-disable 1292 # Ignored attributes
  338. CFLAGS += -diag-disable 1338 # void pointer arithmetic
  339. CFLAGS += -diag-disable 1361 # Variable-length arrays
  340. CFLAGS += -diag-disable 1418 # Missing prototypes
  341. CFLAGS += -diag-disable 1419 # Missing prototypes
  342. CFLAGS += -diag-disable 1599 # Hidden variables
  343. CFLAGS += -Wall -Wmissing-declarations
  344. endif
  345. CFLAGS += $(WORKAROUND_CFLAGS) $(EXTRA_CFLAGS)
  346. ASFLAGS += $(WORKAROUND_ASFLAGS) $(EXTRA_ASFLAGS)
  347. LDFLAGS += $(WORKAROUND_LDFLAGS) $(EXTRA_LDFLAGS)
  348. # Inhibit -Werror if NO_WERROR is specified on make command line
  349. #
  350. ifneq ($(NO_WERROR),1)
  351. CFLAGS += -Werror
  352. ASFLAGS += --fatal-warnings
  353. endif
  354. # Function trace recorder state in the last build. This is needed
  355. # in order to correctly rebuild whenever the function recorder is
  356. # enabled/disabled.
  357. #
  358. FNREC_STATE := $(BIN)/.fnrec.state
  359. ifeq ($(wildcard $(FNREC_STATE)),)
  360. FNREC_OLD := <invalid>
  361. else
  362. FNREC_OLD := $(shell cat $(FNREC_STATE))
  363. endif
  364. ifeq ($(FNREC_OLD),$(FNREC))
  365. $(FNREC_STATE) :
  366. else
  367. $(FNREC_STATE) : clean
  368. $(shell $(ECHO) "$(FNREC)" > $(FNREC_STATE))
  369. endif
  370. VERYCLEANUP += $(FNREC_STATE)
  371. MAKEDEPS += $(FNREC_STATE)
  372. ifeq ($(FNREC),1)
  373. # Enabling -finstrument-functions affects gcc's analysis and leads to spurious
  374. # warnings about use of uninitialised variables.
  375. #
  376. CFLAGS += -Wno-uninitialized
  377. CFLAGS += -finstrument-functions
  378. CFLAGS += -finstrument-functions-exclude-file-list=core/fnrec.c
  379. endif
  380. # Enable per-item sections and section garbage collection. Note that
  381. # some older versions of gcc support -fdata-sections but treat it as
  382. # implying -fno-common, which would break our build.
  383. #
  384. ifeq ($(CCTYPE),gcc)
  385. DS_TEST = $(ECHO) 'char x;' | \
  386. $(CC) -fdata-sections -S -x c - -o - 2>/dev/null | \
  387. grep -E '\.comm' > /dev/null
  388. DS_FLAGS := $(shell $(DS_TEST) && $(ECHO) '-fdata-sections')
  389. CFLAGS += -ffunction-sections $(DS_FLAGS)
  390. endif
  391. LDFLAGS += --gc-sections
  392. # compiler.h is needed for our linking and debugging system
  393. #
  394. CFLAGS += -include compiler.h
  395. # CFLAGS for specific object types
  396. #
  397. CFLAGS_c +=
  398. CFLAGS_S += -DASSEMBLY
  399. # Base object name of the current target
  400. #
  401. OBJECT = $(firstword $(subst ., ,$(@F)))
  402. # CFLAGS for specific object files. You can define
  403. # e.g. CFLAGS_rtl8139, and have those flags automatically used when
  404. # compiling bin/rtl8139.o.
  405. #
  406. OBJ_CFLAGS = $(CFLAGS_$(OBJECT)) -DOBJECT=$(subst -,_,$(OBJECT))
  407. $(BIN)/%.flags :
  408. @$(ECHO) $(OBJ_CFLAGS)
  409. # ICC requires postprocessing objects to fix up table alignments
  410. #
  411. ifeq ($(CCTYPE),icc)
  412. POST_O = && $(ICCFIX) $@
  413. POST_O_DEPS := $(ICCFIX)
  414. else
  415. POST_O :=
  416. POST_O_DEPS :=
  417. endif
  418. # Rules for specific object types.
  419. #
  420. COMPILE_c = $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
  421. RULE_c = $(Q)$(COMPILE_c) -c $< -o $@ $(POST_O)
  422. RULE_c_to_dbg%.o = $(Q)$(COMPILE_c) -Ddebug_$(subst -,_,$(OBJECT))=$* -c $< -o $@ $(POST_O)
  423. RULE_c_to_c = $(Q)$(COMPILE_c) -E -c $< > $@
  424. RULE_c_to_s = $(Q)$(COMPILE_c) -S -g0 -c $< -o $@
  425. PREPROCESS_S = $(CPP) $(CFLAGS) $(CFLAGS_S) $(OBJ_CFLAGS)
  426. ASSEMBLE_S = $(AS) $(ASFLAGS)
  427. RULE_S = $(Q)$(PREPROCESS_S) $< | $(ASSEMBLE_S) -o $@
  428. RULE_S_to_dbg%.o = $(Q)$(PREPROCESS_S) -Ddebug_$(subst -,_,$(OBJECT))=$* $< | $(ASSEMBLE_S) -o $@
  429. RULE_S_to_s = $(Q)$(PREPROCESS_S) $< > $@
  430. DEBUG_TARGETS += dbg%.o c s
  431. # We automatically generate rules for any file mentioned in AUTO_SRCS
  432. # using the following set of templates. It would be cleaner to use
  433. # $(eval ...), but this function exists only in GNU make >= 3.80.
  434. # deps_template : generate dependency list for a given source file
  435. #
  436. # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
  437. # $(2) is the source type (e.g. "c")
  438. # $(3) is the source base name (e.g. "rtl8139")
  439. #
  440. define deps_template
  441. @$(ECHO) " [DEPS] $(1)"
  442. @$(MKDIR) -p $(BIN)/deps/$(dir $(1))
  443. @$(CPP) $(CFLAGS) $(CFLAGS_$(2)) $(CFLAGS_$(3)) -DOBJECT=$(3) \
  444. -Wno-error -M $(1) -MG -MP | \
  445. sed 's/\.o\s*:/_DEPS =/' > $(BIN)/deps/$(1).d
  446. endef
  447. # rules_template : generate rules for a given source file
  448. #
  449. # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
  450. # $(2) is the source type (e.g. "c")
  451. # $(3) is the source base name (e.g. "rtl8139")
  452. #
  453. define rules_template
  454. @$(ECHO) " [RULES] $(1)"
  455. @$(MKDIR) -p $(BIN)/rules/$(dir $(1))
  456. @$(ECHO_E) '\n$$(BIN)/$(3).o :' \
  457. '$(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(3)_DEPS)' \
  458. '\n\t$$(QM)$(ECHO) " [BUILD] $$@"' \
  459. '\n\t$$(RULE_$(2))\n' \
  460. '\nBOBJS += $$(BIN)/$(3).o\n' \
  461. $(foreach TGT,$(DEBUG_TARGETS), \
  462. $(if $(RULE_$(2)_to_$(TGT)), \
  463. '\n$$(BIN)/$(3).$(TGT) :' \
  464. '$(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(3)_DEPS)' \
  465. '\n\t$$(QM)$(ECHO) " [BUILD] $$@"' \
  466. '\n\t$$(RULE_$(2)_to_$(TGT))\n' \
  467. '\n$(TGT)_OBJS += $$(BIN)/$(3).$(TGT)\n' ) ) \
  468. '\n$(BIN)/deps/$(1).d : $$($(3)_DEPS)\n' \
  469. '\nTAGS : $$($(3)_DEPS)\n' > $(BIN)/rules/$(1).r
  470. @$(PERL) $(PARSEROM) $(1) >> $(BIN)/rules/$(1).r
  471. endef
  472. # Rule to generate the dependency list file
  473. #
  474. $(BIN)/deps/%.d : % $(MAKEDEPS)
  475. $(call deps_template,$<,$(subst .,,$(suffix $<)),$(basename $(notdir $<)))
  476. # Calculate and include the list of dependency list files
  477. #
  478. AUTO_DEPS = $(patsubst %,$(BIN)/deps/%.d,$(AUTO_SRCS))
  479. ifdef NEED_DEPS
  480. ifneq ($(AUTO_DEPS),)
  481. -include $(AUTO_DEPS)
  482. endif
  483. endif
  484. autodeps :
  485. @$(ECHO) $(AUTO_DEPS)
  486. VERYCLEANUP += $(BIN)/deps
  487. # Rule to generate the rules file
  488. #
  489. $(BIN)/rules/%.r : % $(MAKEDEPS) $(PARSEROM)
  490. $(call rules_template,$<,$(subst .,,$(suffix $<)),$(basename $(notdir $<)))
  491. # Calculate and include the list of rules files
  492. #
  493. AUTO_RULES = $(patsubst %,$(BIN)/rules/%.r,$(AUTO_SRCS))
  494. ifdef NEED_DEPS
  495. ifneq ($(AUTO_RULES),)
  496. -include $(AUTO_RULES)
  497. endif
  498. endif
  499. autorules :
  500. @$(ECHO) $(AUTO_RULES)
  501. VERYCLEANUP += $(BIN)/rules
  502. # The following variables are created by the rules files
  503. #
  504. bobjs :
  505. @$(ECHO) $(BOBJS)
  506. drivers :
  507. @$(ECHO) $(DRIVERS)
  508. .PHONY : drivers
  509. roms :
  510. @$(ECHO) $(ROMS)
  511. # List of embedded images included in the last build of embedded.o.
  512. # This is needed in order to correctly rebuild embedded.o whenever the
  513. # list of objects changes.
  514. #
  515. EMBEDDED_LIST := $(BIN)/.embedded.list
  516. ifeq ($(wildcard $(EMBEDDED_LIST)),)
  517. EMBEDDED_IMAGE_OLD := <invalid>
  518. else
  519. EMBEDDED_IMAGE_OLD := $(shell cat $(EMBEDDED_LIST))
  520. endif
  521. ifneq ($(EMBEDDED_IMAGE_OLD),$(EMBEDDED_IMAGE))
  522. $(shell $(ECHO) "$(EMBEDDED_IMAGE)" > $(EMBEDDED_LIST))
  523. endif
  524. $(EMBEDDED_LIST) :
  525. VERYCLEANUP += $(EMBEDDED_LIST)
  526. EMBEDDED_FILES := $(subst $(COMMA), ,$(EMBEDDED_IMAGE))
  527. EMBED_ALL := $(foreach i,$(call seq,1,$(words $(EMBEDDED_FILES))),\
  528. EMBED ( $(i), \"$(word $(i), $(EMBEDDED_FILES))\",\
  529. \"$(notdir $(word $(i),$(EMBEDDED_FILES)))\" ))
  530. $(BIN)/embedded.o : $(EMBEDDED_FILES) $(EMBEDDED_LIST)
  531. # This file uses .incbin inline assembly to include a binary file.
  532. # Unfortunately ccache does not detect this dependency and caches builds even
  533. # when the binary file has changed.
  534. #
  535. $(BIN)/embedded.o : override CC := env CCACHE_DISABLE=1 $(CC)
  536. CFLAGS_embedded = -DEMBED_ALL="$(EMBED_ALL)"
  537. # Generate error usage information
  538. #
  539. $(BIN)/%.einfo : $(BIN)/%.o
  540. $(QM)$(ECHO) " [EINFO] $@"
  541. $(Q)$(OBJCOPY) -O binary -j .einfo --set-section-flags .einfo=alloc \
  542. $< $@
  543. EINFOS := $(patsubst $(BIN)/%.o,$(BIN)/%.einfo,$(BOBJS))
  544. $(BIN)/errors : $(EINFOS) $(EINFO)
  545. $(QM)$(ECHO) " [EINFO] $@"
  546. $(Q)$(EINFO) $(EINFOS) | sort > $@
  547. CLEANUP += $(BIN)/errors # Doesn't match the $(BIN)/*.* pattern
  548. # Generate the NIC file from the parsed source files. The NIC file is
  549. # only for rom-o-matic.
  550. #
  551. $(BIN)/NIC : $(AUTO_DEPS)
  552. @$(ECHO) '# This is an automatically generated file, do not edit' > $@
  553. @$(ECHO) '# It does not affect anything in the build, ' \
  554. 'it is only for rom-o-matic' >> $@
  555. @$(ECHO) >> $@
  556. @perl -ne 'chomp; print "$$1\n" if /\# NIC\t(.*)$$/' $^ >> $@
  557. CLEANUP += $(BIN)/NIC # Doesn't match the $(BIN)/*.* pattern
  558. # Analyse a target name (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and
  559. # derive the variables:
  560. #
  561. # TGT_ELEMENTS : the elements of the target (e.g. "dfe538 prism2_pci")
  562. # TGT_PREFIX : the prefix type (e.g. "zrom")
  563. # TGT_DRIVERS : the driver for each element (e.g. "rtl8139 prism2_pci")
  564. # TGT_ROM_NAME : the ROM name (e.g. "dfe538")
  565. # TGT_MEDIA : the media type (e.g. "rom")
  566. #
  567. DRIVERS_ipxe = $(DRIVERS)
  568. CARD_DRIVER = $(firstword $(DRIVER_$(1)) $(1))
  569. TGT_ELEMENTS = $(subst --, ,$(firstword $(subst ., ,$(notdir $@))))
  570. TGT_PREFIX = $(word 2,$(subst ., ,$(notdir $@)))
  571. TGT_ROM_NAME = $(firstword $(TGT_ELEMENTS))
  572. TGT_DRIVERS = $(strip $(if $(DRIVERS_$(TGT_ROM_NAME)), \
  573. $(DRIVERS_$(TGT_ROM_NAME)), \
  574. $(foreach TGT_ELEMENT,$(TGT_ELEMENTS), \
  575. $(call CARD_DRIVER,$(TGT_ELEMENT))) ))
  576. TGT_MEDIA = $(subst z,,$(TGT_PREFIX))
  577. # Look up ROM IDs for the current target
  578. # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
  579. #
  580. # TGT_PCI_VENDOR : the PCI vendor ID (e.g. "0x1186")
  581. # TGT_PCI_DEVICE : the PCI device ID (e.g. "0x1300")
  582. #
  583. TGT_PCI_VENDOR = $(PCI_VENDOR_$(TGT_ROM_NAME))
  584. TGT_PCI_DEVICE = $(PCI_DEVICE_$(TGT_ROM_NAME))
  585. # Calculate link-time options for the current target
  586. # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
  587. #
  588. # TGT_LD_DRIVERS : symbols to require in order to drag in the relevant drivers
  589. # (e.g. "obj_rtl8139 obj_prism2_pci")
  590. # TGT_LD_IDS : symbols to define in order to fill in ID structures in the
  591. # ROM header (e.g."pci_vendor_id=0x1186 pci_device_id=0x1300")
  592. #
  593. TGT_LD_DRIVERS = $(subst -,_,$(patsubst %,obj_%,$(TGT_DRIVERS)))
  594. TGT_LD_IDS = pci_vendor_id=$(firstword $(TGT_PCI_VENDOR) 0) \
  595. pci_device_id=$(firstword $(TGT_PCI_DEVICE) 0)
  596. TGT_LD_ENTRY = _$(TGT_PREFIX)_start
  597. # Calculate linker flags based on link-time options for the current
  598. # target type (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the
  599. # variables:
  600. #
  601. # TGT_LD_FLAGS : target-specific flags to pass to linker (e.g.
  602. # "-u obj_zpciprefix -u obj_rtl8139 -u obj_prism2_pci
  603. # --defsym pci_vendor=0x1186 --defsym pci_device=0x1300")
  604. #
  605. TGT_LD_FLAGS = $(foreach SYM,$(TGT_LD_ENTRY) $(TGT_LD_DRIVERS) obj_config,\
  606. -u $(SYM) --defsym check_$(SYM)=$(SYM) ) \
  607. $(patsubst %,--defsym %,$(TGT_LD_IDS)) \
  608. -e $(TGT_LD_ENTRY)
  609. # Calculate list of debugging versions of objects to be included in
  610. # the target.
  611. #
  612. DEBUG_LIST = $(subst $(COMMA), ,$(DEBUG))
  613. DEBUG_OBJ_LEVEL = $(firstword $(word 2,$(subst :, ,$(1))) 1)
  614. DEBUG_OBJ_BASE = $(word 1,$(subst :, ,$(1))).dbg$(call DEBUG_OBJ_LEVEL,$(1))
  615. DEBUG_OBJ = $(BIN)/$(call DEBUG_OBJ_BASE,$(1)).o
  616. DEBUG_ORIG_OBJ = $(BIN)/$(word 1,$(subst :, ,$(1))).o
  617. DEBUG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_OBJ,$(D)))
  618. DEBUG_ORIG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_ORIG_OBJ,$(D)))
  619. BLIB_OBJS = $(DEBUG_OBJS) $(filter-out $(DEBUG_ORIG_OBJS),$(BOBJS))
  620. # Print out all derived information for a given target.
  621. #
  622. $(BIN)/%.info :
  623. @$(ECHO) 'Elements : $(TGT_ELEMENTS)'
  624. @$(ECHO) 'Prefix : $(TGT_PREFIX)'
  625. @$(ECHO) 'Drivers : $(TGT_DRIVERS)'
  626. @$(ECHO) 'ROM name : $(TGT_ROM_NAME)'
  627. @$(ECHO) 'Media : $(TGT_MEDIA)'
  628. @$(ECHO)
  629. @$(ECHO) 'PCI vendor : $(TGT_PCI_VENDOR)'
  630. @$(ECHO) 'PCI device : $(TGT_PCI_DEVICE)'
  631. @$(ECHO)
  632. @$(ECHO) 'LD driver symbols : $(TGT_LD_DRIVERS)'
  633. @$(ECHO) 'LD ID symbols : $(TGT_LD_IDS)'
  634. @$(ECHO) 'LD entry point : $(TGT_LD_ENTRY)'
  635. @$(ECHO)
  636. @$(ECHO) 'LD target flags : $(TGT_LD_FLAGS)'
  637. @$(ECHO)
  638. @$(ECHO) 'Debugging objects : $(DEBUG_OBJS)'
  639. @$(ECHO) 'Replaced objects : $(DEBUG_ORIG_OBJS)'
  640. # List of objects included in the last build of blib. This is needed
  641. # in order to correctly rebuild blib whenever the list of objects
  642. # changes.
  643. #
  644. BLIB_LIST := $(BIN)/.blib.list
  645. ifeq ($(wildcard $(BLIB_LIST)),)
  646. BLIB_OBJS_OLD := <invalid>
  647. else
  648. BLIB_OBJS_OLD := $(shell cat $(BLIB_LIST))
  649. endif
  650. ifneq ($(BLIB_OBJS_OLD),$(BLIB_OBJS))
  651. $(shell $(ECHO) "$(BLIB_OBJS)" > $(BLIB_LIST))
  652. endif
  653. $(BLIB_LIST) :
  654. VERYCLEANUP += $(BLIB_LIST)
  655. # Library of all objects
  656. #
  657. BLIB = $(BIN)/blib.a
  658. $(BLIB) : $(BLIB_OBJS) $(BLIB_LIST) $(MAKEDEPS)
  659. $(Q)$(RM) $(BLIB)
  660. $(QM)$(ECHO) " [AR] $@"
  661. $(Q)$(AR) r $@ $(BLIB_OBJS)
  662. $(Q)$(RANLIB) $@
  663. blib : $(BLIB)
  664. # Command to generate build ID. Must be unique for each $(BIN)/%.tmp,
  665. # even within the same build run.
  666. #
  667. BUILD_ID_CMD := perl -e 'printf "0x%08x", int ( rand ( 0xffffffff ) );'
  668. # Build an intermediate object file from the objects required for the
  669. # specified target.
  670. #
  671. $(BIN)/%.tmp : $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
  672. $(QM)$(ECHO) " [LD] $@"
  673. $(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $(BLIB) -o $@ \
  674. --defsym _build_id=`$(BUILD_ID_CMD)` -Map $(BIN)/$*.tmp.map
  675. $(Q)$(OBJDUMP) -ht $@ | $(PERL) $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
  676. # Keep intermediate object file (useful for debugging)
  677. .PRECIOUS : $(BIN)/%.tmp
  678. # Show a linker map for the specified target
  679. #
  680. $(BIN)/%.map : $(BIN)/%.tmp
  681. @less $(BIN)/$*.tmp.map
  682. # Get objects list for the specified target
  683. #
  684. define objs_list
  685. $(sort $(foreach OBJ_SYMBOL,\
  686. $(filter obj_%,$(shell $(NM) $(1) | cut -d" " -f3)),\
  687. $(patsubst obj_%,%,$(OBJ_SYMBOL))))
  688. endef
  689. $(BIN)/%.objs : $(BIN)/%.tmp
  690. $(Q)$(ECHO) $(call objs_list,$<)
  691. $(BIN)/%.sizes : $(BIN)/%.tmp
  692. $(Q)$(SIZE) -t $(foreach OBJ,$(call objs_list,$<),$(wildcard $(BIN)/$(subst _,?,$(OBJ)).o)) | \
  693. sort -g
  694. # Get dependency list for the specified target
  695. #
  696. define deps_list
  697. $(sort $(foreach OBJ,$(call objs_list,$(1)),$($(OBJ)_DEPS)))
  698. endef
  699. $(BIN)/%.deps : $(BIN)/%.tmp
  700. $(Q)$(ECHO) $(call deps_list,$<)
  701. # Get unneeded source files for the specified target
  702. #
  703. define nodeps_list
  704. $(sort $(filter-out $(call deps_list,$(1)),\
  705. $(foreach BOBJ,$(BOBJS),\
  706. $($(basename $(notdir $(BOBJ)))_DEPS))))
  707. endef
  708. $(BIN)/%.nodeps : $(BIN)/%.tmp
  709. $(Q)$(ECHO) $(call nodeps_list,$<)
  710. # Get licensing verdict for the specified target
  711. #
  712. define licensable_deps_list
  713. $(filter-out config/local/%.h,$(call deps_list,$(1)))
  714. endef
  715. define unlicensed_deps_list
  716. $(shell grep -L FILE_LICENCE $(call licensable_deps_list,$(1)))
  717. endef
  718. define licence_list
  719. $(patsubst __licence_%,%,\
  720. $(filter __licence_%,$(shell $(NM) $(1) | cut -d" " -f3)))
  721. endef
  722. $(BIN)/%.licence : $(BIN)/%.tmp
  723. $(QM)$(ECHO) " [LICENCE] $@"
  724. $(Q)$(if $(strip $(call unlicensed_deps_list,$<)),\
  725. echo -n "Unable to determine licence because the following " ;\
  726. echo "files are missing a licence declaration:" ;\
  727. echo $(call unlicensed_deps_list,$<);\
  728. exit 1,\
  729. $(PERL) $(LICENCE) $(call licence_list,$<))
  730. # Extract compression information from intermediate object file
  731. #
  732. $(BIN)/%.zinfo : $(BIN)/%.tmp
  733. $(QM)$(ECHO) " [ZINFO] $@"
  734. $(Q)$(OBJCOPY) -O binary -j .zinfo $< $@
  735. # Build raw binary file from intermediate object file
  736. #
  737. $(BIN)/%.bin : $(BIN)/%.tmp
  738. $(QM)$(ECHO) " [BIN] $@"
  739. $(Q)$(OBJCOPY) -O binary -R .zinfo $< $@
  740. # Compress raw binary file
  741. #
  742. $(BIN)/%.zbin : $(BIN)/%.bin $(BIN)/%.zinfo $(ZBIN)
  743. $(QM)$(ECHO) " [ZBIN] $@"
  744. $(Q)$(ZBIN) $(BIN)/$*.bin $(BIN)/$*.zinfo > $@
  745. # Rules for each media format. These are generated and placed in an
  746. # external Makefile fragment. We could do this via $(eval ...), but
  747. # that would require make >= 3.80.
  748. #
  749. # Note that there's an alternative way to generate most .rom images:
  750. # they can be copied from their 'master' ROM image using cp and
  751. # reprocessed with makerom to add the PCI IDs and ident string. The
  752. # relevant rule would look something like:
  753. #
  754. # $(BIN)/dfe538%rom : $(BIN)/rtl8139%rom
  755. # cat $< $@
  756. # $(FINALISE_rom)
  757. #
  758. # You can derive the ROM/driver relationships using the variables
  759. # DRIVER_<rom> and/or ROMS_<driver>.
  760. #
  761. # We don't currently do this, because (a) it would require generating
  762. # yet more Makefile fragments (since you need a rule for each ROM in
  763. # ROMS), and (b) the linker is so fast that it probably wouldn't make
  764. # much difference to the overall build time.
  765. # Add NON_AUTO_MEDIA to the media list, so that they show up in the
  766. # output of "make"
  767. #
  768. MEDIA += $(NON_AUTO_MEDIA)
  769. media :
  770. @$(ECHO) $(MEDIA)
  771. AUTO_MEDIA = $(filter-out $(NON_AUTO_MEDIA),$(MEDIA))
  772. automedia :
  773. @$(ECHO) $(AUTO_MEDIA)
  774. # media_template : create Makefile rules for specified media
  775. #
  776. # $(1) is the media name (e.g. "rom")
  777. #
  778. define media_template
  779. @$(ECHO) " [MEDIARULES] $(1)"
  780. @$(MKDIR) -p $(BIN)/rules/$(dir $(1))
  781. @$(ECHO_E) '$$(BIN)/%.$(1) : $$(BIN)/%.$(1).zbin' \
  782. '\n\t$$(QM)$(ECHO) " [FINISH] $$@"' \
  783. '\n\t$$(Q)$$(CP) $$< $$@' \
  784. '\n\t$$(Q)$$(PAD_$(1))' \
  785. '\n\t$$(Q)$$(FINALISE_$(1))' \
  786. > $(BIN)/rules/$(1).media.r
  787. endef
  788. # Rule to generate the Makefile rules to be included
  789. #
  790. $(BIN)/rules/%.media.r : $(MAKEDEPS)
  791. $(call media_template,$*)
  792. # Calculate and include the list of Makefile rules files
  793. #
  794. MEDIA_RULES = $(patsubst %,$(BIN)/rules/%.media.r,$(AUTO_MEDIA))
  795. mediarules :
  796. @$(ECHO) $(MEDIA_RULES)
  797. ifdef NEED_DEPS
  798. ifneq ($(MEDIA_RULES),)
  799. -include $(MEDIA_RULES)
  800. endif
  801. endif
  802. # Wrap up binary blobs (for embedded images)
  803. #
  804. $(BIN)/%.o : payload/%.img
  805. $(QM)echo " [WRAP] $@"
  806. $(Q)$(LD) -b binary -r -o $@ $< --undefined obj_payload \
  807. --defsym obj_$*=0
  808. BOBJS += $(patsubst payload/%.img,$(BIN)/%.o,$(wildcard payload/*.img))
  809. # The "allXXXs" targets for each suffix
  810. #
  811. allall: allroms allpxes allisos alldsks
  812. allroms : all%s : $(foreach ROM,$(ROMS),$(BIN)/$(ROM).%)
  813. allpxes allisos alldsks : all%s : $(foreach DRIVER,$(DRIVERS),$(BIN)/$(DRIVER).%)
  814. # Alias for ipxe.%
  815. #
  816. $(BIN)/etherboot.% : $(BIN)/ipxe.%
  817. ln -sf $(notdir $<) $@
  818. endif # defined(BIN)
  819. ###############################################################################
  820. #
  821. # The compression utilities
  822. #
  823. $(NRV2B) : util/nrv2b.c $(MAKEDEPS)
  824. $(QM)$(ECHO) " [HOSTCC] $@"
  825. $(Q)$(HOST_CC) -O2 -DENCODE -DDECODE -DMAIN -DVERBOSE -DNDEBUG \
  826. -DBITSIZE=32 -DENDIAN=0 -o $@ $<
  827. CLEANUP += $(NRV2B)
  828. $(ZBIN) : util/zbin.c util/nrv2b.c $(MAKEDEPS)
  829. $(QM)$(ECHO) " [HOSTCC] $@"
  830. $(Q)$(HOST_CC) -O2 -o $@ $<
  831. CLEANUP += $(ZBIN)
  832. ###############################################################################
  833. #
  834. # The EFI image converter
  835. #
  836. ELF2EFI_CFLAGS := -I$(BINUTILS_DIR)/include -I$(BFD_DIR)/include \
  837. -I$(ZLIB_DIR)/include -idirafter include \
  838. -L$(BINUTILS_DIR)/lib -L$(BFD_DIR)/lib -L$(ZLIB_DIR)/lib \
  839. -lbfd -ldl -liberty -lz -Wl,--no-warn-search-mismatch
  840. $(ELF2EFI32) : util/elf2efi.c $(MAKEDEPS)
  841. $(QM)$(ECHO) " [HOSTCC] $@"
  842. $(Q)$(HOST_CC) $< $(ELF2EFI_CFLAGS) -DEFI_TARGET_IA32 -O2 -o $@
  843. CLEANUP += $(ELF2EFI32)
  844. $(ELF2EFI64) : util/elf2efi.c $(MAKEDEPS)
  845. $(QM)$(ECHO) " [HOSTCC] $@"
  846. $(Q)$(HOST_CC) $< $(ELF2EFI_CFLAGS) -DEFI_TARGET_X64 -O2 -o $@
  847. CLEANUP += $(ELF2EFI64)
  848. $(EFIROM) : util/efirom.c $(MAKEDEPS)
  849. $(QM)$(ECHO) " [HOSTCC] $@"
  850. $(Q)$(HOST_CC) -idirafter include -O2 -o $@ $<
  851. CLEANUP += $(EFIROM)
  852. ###############################################################################
  853. #
  854. # The ICC fixup utility
  855. #
  856. $(ICCFIX) : util/iccfix.c $(MAKEDEPS)
  857. $(QM)$(ECHO) " [HOSTCC] $@"
  858. $(Q)$(HOST_CC) -idirafter include -O2 -o $@ $<
  859. CLEANUP += $(ICCFIX)
  860. ###############################################################################
  861. #
  862. # The error usage information utility
  863. #
  864. $(EINFO) : util/einfo.c $(MAKEDEPS)
  865. $(QM)$(ECHO) " [HOSTCC] $@"
  866. $(Q)$(HOST_CC) -idirafter include -O2 -o $@ $<
  867. CLEANUP += $(EINFO)
  868. ###############################################################################
  869. #
  870. # Local configs
  871. #
  872. config/local/%.h :
  873. $(Q)touch $@
  874. ###############################################################################
  875. #
  876. # Auto-incrementing build serial number. Append "bs" to your list of
  877. # build targets to get a serial number printed at the end of the
  878. # build. Enable -DBUILD_SERIAL in order to see it when the code runs.
  879. #
  880. BUILDSERIAL_H = config/.buildserial.h
  881. BUILDSERIAL_NOW = config/.buildserial.now
  882. BUILDSERIAL_NEXT = config/.buildserial.next
  883. $(BUILDSERIAL_NOW) $(BUILDSERIAL_NEXT) :
  884. $(ECHO) 1 > $@
  885. $(BUILDSERIAL_H) : $(BUILDSERIAL_NOW) $(BUILDSERIAL_NEXT)
  886. $(ECHO) '#define BUILD_SERIAL_NUM $(shell cat $<)' > $@
  887. ifeq ($(filter bs,$(MAKECMDGOALS)),bs)
  888. $(shell diff -q $(BUILDSERIAL_NOW) $(BUILDSERIAL_NEXT) > /dev/null || \
  889. cp -f $(BUILDSERIAL_NEXT) $(BUILDSERIAL_NOW))
  890. endif
  891. bs : $(BUILDSERIAL_NOW)
  892. @$(ECHO) $$(( $(shell cat $<) + 1 )) > $(BUILDSERIAL_NEXT)
  893. @$(ECHO) "Build serial number is $(shell cat $<)"
  894. ###############################################################################
  895. #
  896. # Build the TAGS file(s) for emacs
  897. #
  898. TAGS :
  899. ctags -e -R -f $@ --exclude=bin
  900. CLEANUP += TAGS
  901. ###############################################################################
  902. #
  903. # Force rebuild for any given target
  904. #
  905. %.rebuild :
  906. rm -f $*
  907. $(Q)$(MAKE) $*
  908. ###############################################################################
  909. #
  910. # Symbol table checks
  911. #
  912. ifdef BIN
  913. SYMTAB = $(BIN)/symtab
  914. $(SYMTAB) : $(BLIB)
  915. $(OBJDUMP) -w -t $< > $@
  916. CLEANUP += $(BIN)/symtab
  917. symcheck : $(SYMTAB)
  918. $(PERL) $(SYMCHECK) $<
  919. endif # defined(BIN)
  920. ###############################################################################
  921. #
  922. # Build bochs symbol table
  923. #
  924. ifdef BIN
  925. $(BIN)/%.bxs : $(BIN)/%.tmp
  926. $(NM) $< | cut -d" " -f1,3 > $@
  927. endif # defined(BIN)
  928. ###############################################################################
  929. #
  930. # Documentation
  931. #
  932. ifdef BIN
  933. $(BIN)/doxygen.cfg : doxygen.cfg $(MAKEDEPS)
  934. $(Q)$(PERL) -pe 's{\@SRCDIRS\@}{$(SRCDIRS)}; ' \
  935. -e 's{\@INCDIRS\@}{$(filter-out .,$(INCDIRS))}; ' \
  936. -e 's{\@BIN\@}{$(BIN)}; ' \
  937. -e 's{\@ARCH\@}{$(ARCH)}; ' \
  938. $< > $@
  939. $(BIN)/doc : $(BIN)/doxygen.cfg
  940. $(Q)$(DOXYGEN) $<
  941. .PHONY : $(BIN)/doc
  942. doc : $(BIN)/doc
  943. doc-clean :
  944. $(Q)$(RM) -r $(BIN)/doc
  945. VERYCLEANUP += $(BIN)/doc
  946. docview :
  947. @[ -f $(BIN)/doc/html/index.html ] || $(MAKE) $(BIN)/doc
  948. @if [ -n "$$BROWSER" ] ; then \
  949. ( $$BROWSER $(BIN)/doc/html/index.html & ) ; \
  950. else \
  951. $(ECHO) "Documentation index in $(BIN)/doc/html/index.html" ; \
  952. fi
  953. endif # defined(BIN)
  954. ###############################################################################
  955. #
  956. # Keyboard maps
  957. #
  958. hci/keymap/keymap_%.c :
  959. $(Q)$(PERL) $(GENKEYMAP) $* > $@
  960. ###############################################################################
  961. #
  962. # Force deletion of incomplete targets
  963. #
  964. .DELETE_ON_ERROR :
  965. ###############################################################################
  966. #
  967. # Clean-up
  968. #
  969. clean :
  970. $(RM) $(CLEANUP)
  971. veryclean : clean
  972. $(RM) -r $(VERYCLEANUP)