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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490
  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. ifeq ($(CCTYPE),gcc)
  82. GCC_2_96_BANNER := $(shell $(CC) -v 2>&1 | grep -is 'gcc version 2\.96')
  83. ifneq ($(GCC_2_96_BANNER),)
  84. $(warning gcc 2.96 is unsuitable for compiling iPXE)
  85. $(warning Use gcc 2.95 or a newer version instead)
  86. $(error Unsuitable build environment found)
  87. endif
  88. endif
  89. PERL_UNICODE_CHECK := $(shell $(PERL) -e 'use bytes; print chr(255)' | wc -c)
  90. ifeq ($(PERL_UNICODE_CHECK),2)
  91. $(warning Your Perl version has a Unicode handling bug)
  92. $(warning Execute this command before building iPXE:)
  93. $(warning export LANG=$${LANG%.UTF-8})
  94. $(error Unsuitable build environment found)
  95. endif
  96. LD_GOLD_BANNER := $(shell $(LD) -v 2>&1 | grep 'GNU gold')
  97. ifneq ($(LD_GOLD_BANNER),)
  98. $(warning GNU gold is unsuitable for building iPXE)
  99. $(warning Use GNU ld instead)
  100. $(error Unsuitable build environment found)
  101. endif
  102. ###############################################################################
  103. #
  104. # Check if $(eval ...) is available to use
  105. #
  106. HAVE_EVAL :=
  107. ifndef NO_EVAL
  108. $(eval HAVE_EVAL := yes)
  109. endif
  110. eval :
  111. @$(ECHO) $(HAVE_EVAL)
  112. ###############################################################################
  113. #
  114. # Check for various tool workarounds
  115. #
  116. WORKAROUND_CFLAGS :=
  117. WORKAROUND_ASFLAGS :=
  118. WORKAROUND_LDFLAGS :=
  119. # Make syntax does not allow use of comma or space in certain places.
  120. # This ugly workaround is suggested in the manual.
  121. #
  122. COMMA := ,
  123. EMPTY :=
  124. SPACE := $(EMPTY) $(EMPTY)
  125. HASH := \#
  126. define NEWLINE
  127. endef
  128. # Some widespread patched versions of gcc include -fstack-protector by
  129. # default, even when -ffreestanding is specified. We therefore need
  130. # to disable -fstack-protector if the compiler supports it.
  131. #
  132. ifeq ($(CCTYPE),gcc)
  133. SP_TEST = $(CC) -fno-stack-protector -x c -c /dev/null \
  134. -o /dev/null >/dev/null 2>&1
  135. SP_FLAGS := $(shell $(SP_TEST) && $(ECHO) '-fno-stack-protector')
  136. WORKAROUND_CFLAGS += $(SP_FLAGS)
  137. endif
  138. # gcc 4.4 generates .eh_frame sections by default, which distort the
  139. # output of "size". Inhibit this.
  140. #
  141. ifeq ($(CCTYPE),gcc)
  142. CFI_TEST = $(CC) -fno-dwarf2-cfi-asm -fno-exceptions -fno-unwind-tables \
  143. -fno-asynchronous-unwind-tables -x c -c /dev/null \
  144. -o /dev/null >/dev/null 2>&1
  145. CFI_FLAGS := $(shell $(CFI_TEST) && \
  146. $(ECHO) '-fno-dwarf2-cfi-asm -fno-exceptions ' \
  147. '-fno-unwind-tables -fno-asynchronous-unwind-tables')
  148. WORKAROUND_CFLAGS += $(CFI_FLAGS)
  149. endif
  150. # gcc 4.6 generates spurious warnings if -Waddress is in force.
  151. # Inhibit this.
  152. #
  153. ifeq ($(CCTYPE),gcc)
  154. WNA_TEST = $(CC) -Wno-address -x c -c /dev/null -o /dev/null >/dev/null 2>&1
  155. WNA_FLAGS := $(shell $(WNA_TEST) && $(ECHO) '-Wno-address')
  156. WORKAROUND_CFLAGS += $(WNA_FLAGS)
  157. endif
  158. # Some versions of gas choke on division operators, treating them as
  159. # comment markers. Specifying --divide will work around this problem,
  160. # but isn't available on older gas versions.
  161. #
  162. DIVIDE_TEST = $(AS) --divide /dev/null -o /dev/null 2>/dev/null
  163. DIVIDE_FLAGS := $(shell $(DIVIDE_TEST) && $(ECHO) '--divide')
  164. WORKAROUND_ASFLAGS += $(DIVIDE_FLAGS)
  165. ###############################################################################
  166. #
  167. # Build verbosity
  168. #
  169. ifeq ($(V),1)
  170. Q :=
  171. QM := @\#
  172. else
  173. Q := @
  174. QM := @
  175. endif
  176. ###############################################################################
  177. #
  178. # Checker
  179. #
  180. ifeq ($(C),1)
  181. export REAL_CC := $(CC)
  182. CC := cgcc
  183. CFLAGS += -Wno-decl
  184. endif
  185. ###############################################################################
  186. #
  187. # Set BIN according to whatever was specified on the command line as
  188. # the build target.
  189. #
  190. # Determine how many different BIN directories are mentioned in the
  191. # make goals.
  192. #
  193. BIN_GOALS := $(filter bin bin/% bin-%,$(MAKECMDGOALS))
  194. BIN_GOALS_BINS := $(sort $(foreach BG,$(BIN_GOALS),\
  195. $(firstword $(subst /, ,$(BG)))))
  196. NUM_BINS := $(words $(BIN_GOALS_BINS))
  197. ifeq ($(NUM_BINS),0)
  198. # No BIN directory was specified. Set BIN to "bin" as a sensible
  199. # default.
  200. BIN := bin
  201. else # NUM_BINS == 0
  202. ifeq ($(NUM_BINS),1)
  203. # If exactly one BIN directory was specified, set BIN to match this
  204. # directory.
  205. #
  206. BIN := $(firstword $(BIN_GOALS_BINS))
  207. else # NUM_BINS == 1
  208. # More than one BIN directory was specified. We cannot handle the
  209. # latter case within a single make invocation, so set up recursive
  210. # targets for each BIN directory. Use exactly one target for each BIN
  211. # directory since running multiple make invocations within the same
  212. # BIN directory is likely to cause problems.
  213. #
  214. # Leave $(BIN) undefined. This has implications for any target that
  215. # depends on $(BIN); such targets should be made conditional upon the
  216. # existence of $(BIN).
  217. #
  218. BIN_GOALS_FIRST := $(foreach BGB,$(BIN_GOALS_BINS),\
  219. $(firstword $(filter $(BGB)/%,$(BIN_GOALS))))
  220. BIN_GOALS_OTHER := $(filter-out $(BIN_GOALS_FIRST),$(BIN_GOALS))
  221. $(BIN_GOALS_FIRST) : % : BIN_RECURSE
  222. $(Q)$(MAKE) --no-print-directory BIN=$(firstword $(subst /, ,$@)) \
  223. $(filter $(firstword $(subst /, ,$@))/%, $(BIN_GOALS))
  224. $(BIN_GOALS_OTHER) : % : BIN_RECURSE
  225. $(Q)$(TRUE)
  226. .PHONY : BIN_RECURSE
  227. endif # NUM_BINS == 1
  228. endif # NUM_BINS == 0
  229. ifdef BIN
  230. # Create $(BIN) directory if it doesn't exist yet
  231. #
  232. ifeq ($(wildcard $(BIN)),)
  233. $(shell $(MKDIR) -p $(BIN))
  234. endif
  235. # Target to allow e.g. "make bin-efi arch"
  236. #
  237. $(BIN) :
  238. @# Do nothing, silently
  239. .PHONY : $(BIN)
  240. # Remove everything in $(BIN) for a "make clean"
  241. #
  242. CLEANUP += $(BIN)/*.* # Avoid picking up directories
  243. endif # defined(BIN)
  244. # Determine whether or not we need to include the dependency files
  245. #
  246. NO_DEP_TARGETS := $(BIN) clean veryclean
  247. ifeq ($(MAKECMDGOALS),)
  248. NEED_DEPS := 1
  249. endif
  250. ifneq ($(strip $(filter-out $(NO_DEP_TARGETS),$(MAKECMDGOALS))),)
  251. NEED_DEPS := 1
  252. endif
  253. ###############################################################################
  254. #
  255. # Select build architecture and platform based on $(BIN)
  256. #
  257. # BIN has the form bin[-[arch-]platform]
  258. ARCHS := $(patsubst arch/%,%,$(wildcard arch/*))
  259. PLATFORMS := $(patsubst config/defaults/%.h,%,\
  260. $(wildcard config/defaults/*.h))
  261. archs :
  262. @$(ECHO) $(ARCHS)
  263. platforms :
  264. @$(ECHO) $(PLATFORMS)
  265. ifdef BIN
  266. # Determine architecture portion of $(BIN), if present
  267. BIN_ARCH := $(strip $(foreach A,$(ARCHS),\
  268. $(patsubst bin-$(A)-%,$(A),\
  269. $(filter bin-$(A)-%,$(BIN)))))
  270. # Determine platform portion of $(BIN), if present
  271. ifeq ($(BIN_ARCH),)
  272. BIN_PLATFORM := $(patsubst bin-%,%,$(filter bin-%,$(BIN)))
  273. else
  274. BIN_PLATFORM := $(patsubst bin-$(BIN_ARCH)-%,%,$(BIN))
  275. endif
  276. # Determine build architecture
  277. DEFAULT_ARCH := i386
  278. ARCH := $(firstword $(BIN_ARCH) $(DEFAULT_ARCH))
  279. CFLAGS += -DARCH=$(ARCH)
  280. arch :
  281. @$(ECHO) $(ARCH)
  282. .PHONY : arch
  283. # Determine build platform
  284. DEFAULT_PLATFORM := pcbios
  285. PLATFORM := $(firstword $(BIN_PLATFORM) $(DEFAULT_PLATFORM))
  286. CFLAGS += -DPLATFORM=$(PLATFORM)
  287. platform :
  288. @$(ECHO) $(PLATFORM)
  289. endif # defined(BIN)
  290. # Include architecture-specific Makefile
  291. ifdef ARCH
  292. MAKEDEPS += arch/$(ARCH)/Makefile
  293. include arch/$(ARCH)/Makefile
  294. endif
  295. # Include architecture-specific include path
  296. ifdef ARCH
  297. INCDIRS += arch/$(ARCH)/include
  298. INCDIRS += arch/$(ARCH)/include/$(PLATFORM)
  299. endif
  300. ###############################################################################
  301. #
  302. # Source file handling
  303. # SRCDIRS lists all directories containing source files.
  304. srcdirs :
  305. @$(ECHO) $(SRCDIRS)
  306. # SRCS lists all .c or .S files found in any SRCDIR
  307. #
  308. SRCS += $(wildcard $(patsubst %,%/*.c,$(SRCDIRS)))
  309. SRCS += $(wildcard $(patsubst %,%/*.S,$(SRCDIRS)))
  310. srcs :
  311. @$(ECHO) $(SRCS)
  312. # AUTO_SRCS lists all files in SRCS that are not mentioned in
  313. # NON_AUTO_SRCS. Files should be added to NON_AUTO_SRCS if they
  314. # cannot be built using the standard build template.
  315. #
  316. AUTO_SRCS = $(filter-out $(NON_AUTO_SRCS),$(SRCS))
  317. autosrcs :
  318. @$(ECHO) $(AUTO_SRCS)
  319. # Just about everything else in this section depends upon having
  320. # $(BIN) set
  321. ifdef BIN
  322. # INCDIRS lists the include path
  323. incdirs :
  324. @$(ECHO) $(INCDIRS)
  325. # Common flags
  326. #
  327. CFLAGS += $(foreach INC,$(INCDIRS),-I$(INC))
  328. CFLAGS += -Os
  329. CFLAGS += -g
  330. ifeq ($(CCTYPE),gcc)
  331. CFLAGS += -ffreestanding
  332. CFLAGS += -Wall -W -Wformat-nonliteral
  333. HOST_CFLAGS += -Wall -W -Wformat-nonliteral
  334. endif
  335. ifeq ($(CCTYPE),icc)
  336. CFLAGS += -fno-builtin
  337. CFLAGS += -no-ip
  338. CFLAGS += -no-gcc
  339. CFLAGS += -diag-disable 111 # Unreachable code
  340. CFLAGS += -diag-disable 128 # Unreachable loop
  341. CFLAGS += -diag-disable 170 # Array boundary checks
  342. CFLAGS += -diag-disable 177 # Unused functions
  343. CFLAGS += -diag-disable 181 # printf() format checks
  344. CFLAGS += -diag-disable 188 # enum strictness
  345. CFLAGS += -diag-disable 193 # Undefined preprocessor identifiers
  346. CFLAGS += -diag-disable 280 # switch ( constant )
  347. CFLAGS += -diag-disable 310 # K&R parameter lists
  348. CFLAGS += -diag-disable 424 # Extra semicolon
  349. CFLAGS += -diag-disable 589 # Declarations mid-code
  350. CFLAGS += -diag-disable 593 # Unused variables
  351. CFLAGS += -diag-disable 810 # Casting ints to smaller ints
  352. CFLAGS += -diag-disable 981 # Sequence point violations
  353. CFLAGS += -diag-disable 1292 # Ignored attributes
  354. CFLAGS += -diag-disable 1338 # void pointer arithmetic
  355. CFLAGS += -diag-disable 1361 # Variable-length arrays
  356. CFLAGS += -diag-disable 1418 # Missing prototypes
  357. CFLAGS += -diag-disable 1419 # Missing prototypes
  358. CFLAGS += -diag-disable 1599 # Hidden variables
  359. CFLAGS += -Wall -Wmissing-declarations
  360. endif
  361. CFLAGS += $(WORKAROUND_CFLAGS) $(EXTRA_CFLAGS)
  362. ASFLAGS += $(WORKAROUND_ASFLAGS) $(EXTRA_ASFLAGS)
  363. LDFLAGS += $(WORKAROUND_LDFLAGS) $(EXTRA_LDFLAGS)
  364. HOST_CFLAGS += -O2 -g
  365. # Inhibit -Werror if NO_WERROR is specified on make command line
  366. #
  367. ifneq ($(NO_WERROR),1)
  368. CFLAGS += -Werror
  369. ASFLAGS += --fatal-warnings
  370. HOST_CFLAGS += -Werror
  371. endif
  372. # Function trace recorder state in the last build. This is needed
  373. # in order to correctly rebuild whenever the function recorder is
  374. # enabled/disabled.
  375. #
  376. FNREC_STATE := $(BIN)/.fnrec.state
  377. ifeq ($(wildcard $(FNREC_STATE)),)
  378. FNREC_OLD := <invalid>
  379. else
  380. FNREC_OLD := $(shell cat $(FNREC_STATE))
  381. endif
  382. ifeq ($(FNREC_OLD),$(FNREC))
  383. $(FNREC_STATE) :
  384. else
  385. $(FNREC_STATE) : clean
  386. $(shell $(ECHO) "$(FNREC)" > $(FNREC_STATE))
  387. endif
  388. VERYCLEANUP += $(FNREC_STATE)
  389. MAKEDEPS += $(FNREC_STATE)
  390. ifeq ($(FNREC),1)
  391. # Enabling -finstrument-functions affects gcc's analysis and leads to spurious
  392. # warnings about use of uninitialised variables.
  393. #
  394. CFLAGS += -Wno-uninitialized
  395. CFLAGS += -finstrument-functions
  396. CFLAGS += -finstrument-functions-exclude-file-list=core/fnrec.c
  397. endif
  398. # Enable per-item sections and section garbage collection. Note that
  399. # some older versions of gcc support -fdata-sections but treat it as
  400. # implying -fno-common, which would break our build. Some other older
  401. # versions issue a spurious and uninhibitable warning if
  402. # -ffunction-sections is used with -g, which would also break our
  403. # build since we use -Werror.
  404. #
  405. ifeq ($(CCTYPE),gcc)
  406. DS_TEST = $(ECHO) 'char x;' | \
  407. $(CC) -fdata-sections -S -x c - -o - 2>/dev/null | \
  408. grep -E '\.comm' > /dev/null
  409. DS_FLAGS := $(shell $(DS_TEST) && $(ECHO) '-fdata-sections')
  410. FS_TEST = $(CC) -ffunction-sections -g -c -x c /dev/null \
  411. -o /dev/null 2>/dev/null
  412. FS_FLAGS := $(shell $(FS_TEST) && $(ECHO) '-ffunction-sections')
  413. CFLAGS += $(FS_FLAGS) $(DS_FLAGS)
  414. endif
  415. LDFLAGS += --gc-sections
  416. # Force creation of static binaries (required for OpenBSD, does no
  417. # harm on other platforms).
  418. #
  419. LDFLAGS += -static
  420. # compiler.h is needed for our linking and debugging system
  421. #
  422. CFLAGS += -include include/compiler.h
  423. # The section type character (e.g. "@" in "@progbits") varies by
  424. # architecture.
  425. #
  426. CFLAGS += -DASM_TCHAR='$(ASM_TCHAR)' -DASM_TCHAR_OPS='$(ASM_TCHAR_OPS)'
  427. # CFLAGS for specific object types
  428. #
  429. CFLAGS_c +=
  430. CFLAGS_S += -DASSEMBLY
  431. # Base object name of the current target
  432. #
  433. OBJECT = $(firstword $(subst ., ,$(@F)))
  434. # CFLAGS for specific object files. You can define
  435. # e.g. CFLAGS_rtl8139, and have those flags automatically used when
  436. # compiling bin/rtl8139.o.
  437. #
  438. OBJ_CFLAGS = $(CFLAGS_$(OBJECT)) -DOBJECT=$(subst -,_,$(OBJECT))
  439. $(BIN)/%.flags :
  440. @$(ECHO) $(OBJ_CFLAGS)
  441. # ICC requires postprocessing objects to fix up table alignments
  442. #
  443. ifeq ($(CCTYPE),icc)
  444. POST_O = && $(ICCFIX) $@
  445. POST_O_DEPS := $(ICCFIX)
  446. else
  447. POST_O :=
  448. POST_O_DEPS :=
  449. endif
  450. # Rules for specific object types.
  451. #
  452. COMPILE_c = $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
  453. RULE_c = $(Q)$(COMPILE_c) -c $< -o $@ $(POST_O)
  454. RULE_c_to_ids.o = $(Q)$(ECHO_E) '$(OBJ_IDS_ASM_NL)' | $(ASSEMBLE_S) -o $@
  455. RULE_c_to_dbg%.o = $(Q)$(COMPILE_c) -DDBGLVL_MAX=$* -c $< -o $@ $(POST_O)
  456. RULE_c_to_c = $(Q)$(COMPILE_c) -E -c $< > $@
  457. RULE_c_to_s = $(Q)$(COMPILE_c) -S -g0 -c $< -o $@
  458. PREPROCESS_S = $(CPP) $(CFLAGS) $(CFLAGS_S) $(OBJ_CFLAGS)
  459. ASSEMBLE_S = $(AS) $(ASFLAGS)
  460. RULE_S = $(Q)$(PREPROCESS_S) $< | $(ASSEMBLE_S) -o $@
  461. RULE_S_to_dbg%.o = $(Q)$(PREPROCESS_S) -DDBGLVL_MAX=$* $< | $(ASSEMBLE_S) -o $@
  462. RULE_S_to_s = $(Q)$(PREPROCESS_S) $< > $@
  463. GENERIC_TARGETS += ids.o dbg%.o c s
  464. # List of embedded images included in the last build of embedded.o.
  465. # This is needed in order to correctly rebuild embedded.o whenever the
  466. # list of objects changes.
  467. #
  468. EMBED := $(EMBEDDED_IMAGE) # Maintain backwards compatibility
  469. EMBEDDED_LIST := $(BIN)/.embedded.list
  470. ifeq ($(wildcard $(EMBEDDED_LIST)),)
  471. EMBED_OLD := <invalid>
  472. else
  473. EMBED_OLD := $(shell cat $(EMBEDDED_LIST))
  474. endif
  475. ifneq ($(EMBED_OLD),$(EMBED))
  476. $(shell $(ECHO) "$(EMBED)" > $(EMBEDDED_LIST))
  477. endif
  478. $(EMBEDDED_LIST) : $(MAKEDEPS)
  479. VERYCLEANUP += $(EMBEDDED_LIST)
  480. EMBEDDED_FILES := $(subst $(COMMA), ,$(EMBED))
  481. EMBED_ALL := $(foreach i,$(call seq,1,$(words $(EMBEDDED_FILES))),\
  482. EMBED ( $(i), \"$(word $(i), $(EMBEDDED_FILES))\",\
  483. \"$(notdir $(word $(i),$(EMBEDDED_FILES)))\" ))
  484. embedded_DEPS += $(EMBEDDED_FILES) $(EMBEDDED_LIST)
  485. CFLAGS_embedded = -DEMBED_ALL="$(EMBED_ALL)"
  486. # List of trusted root certificates
  487. #
  488. TRUSTED_LIST := $(BIN)/.trusted.list
  489. ifeq ($(wildcard $(TRUSTED_LIST)),)
  490. TRUST_OLD := <invalid>
  491. else
  492. TRUST_OLD := $(shell cat $(TRUSTED_LIST))
  493. endif
  494. ifneq ($(TRUST_OLD),$(TRUST))
  495. $(shell $(ECHO) "$(TRUST)" > $(TRUSTED_LIST))
  496. endif
  497. $(TRUSTED_LIST) : $(MAKEDEPS)
  498. VERYCLEANUP += $(TRUSTED_LIST)
  499. # Trusted root certificate fingerprints
  500. #
  501. TRUSTED_CERTS := $(subst $(COMMA), ,$(TRUST))
  502. TRUSTED_FPS := $(foreach CERT,$(TRUSTED_CERTS),\
  503. 0x$(subst :,$(COMMA) 0x,$(lastword $(subst =, ,\
  504. $(shell $(OPENSSL) x509 -in $(CERT) -noout -sha256 \
  505. -fingerprint))))$(COMMA))
  506. rootcert_DEPS += $(TRUSTED_FILES) $(TRUSTED_LIST)
  507. CFLAGS_rootcert = $(if $(TRUSTED_FPS),-DTRUSTED="$(TRUSTED_FPS)")
  508. # List of embedded certificates
  509. #
  510. CERT_LIST := $(BIN)/.certificate.list
  511. ifeq ($(wildcard $(CERT_LIST)),)
  512. CERT_OLD := <invalid>
  513. else
  514. CERT_OLD := $(shell cat $(CERT_LIST))
  515. endif
  516. ifneq ($(CERT_OLD),$(CERT))
  517. $(shell $(ECHO) "$(CERT)" > $(CERT_LIST))
  518. endif
  519. $(CERT_LIST) : $(MAKEDEPS)
  520. VERYCLEANUP += $(CERT_LIST)
  521. # Embedded certificates concatenated and then split into one file per
  522. # certificate (even if original files contained certificate chains)
  523. #
  524. CERT_FILES := $(subst $(COMMA), ,$(CERT))
  525. CERT_CONCAT := $(BIN)/.certificates.pem
  526. ifneq ($(CERT),)
  527. CERT_COUNT := $(shell grep "BEGIN CERTIFICATE" $(CERT_FILES) | wc -l)
  528. $(CERT_CONCAT) : $(CERT_FILES) $(CERT_LIST)
  529. $(Q)cat $(CERT_FILES) > $@
  530. # We must use an (otherwise unnecessary) pattern rule here to encode
  531. # the fact that one "csplit" command generates multiple targets
  532. CERT_PEMS := $(foreach i,$(call seq,1,$(CERT_COUNT)),\
  533. $(BIN)/.certificate.pem.$(i))
  534. $(subst .pem.,.%.,$(CERT_PEMS)) : $(BIN)/.certificates.%
  535. $(Q)$(CSPLIT) -q -n 1 -f $(BIN)/.certificate.pem. $< \
  536. '/BEGIN CERTIFICATE/' '{*}'
  537. CERT_DERS := $(subst .certificate.pem.,.certificate.der.,$(CERT_PEMS))
  538. $(BIN)/.certificate.der.% : $(BIN)/.certificate.pem.%
  539. $(Q)$(OPENSSL) x509 -in $< -outform DER -out $@
  540. CERT_ALL := $(foreach i,$(call seq,1,$(CERT_COUNT)),\
  541. CERT ( $(i), \"$(word $(i),$(CERT_DERS))\" ))
  542. endif
  543. certstore_DEPS += $(CERT_LIST) $(CERT_FILES) $(CERT_PEMS) $(CERT_DERS)
  544. CFLAGS_certstore += -DCERT_ALL="$(CERT_ALL)"
  545. CLEANUP += $(BIN)/.certificate.* $(BIN)/.certificates.*
  546. # (Single-element) list of private keys
  547. #
  548. ifdef KEY
  549. PRIVKEY := $(KEY) # Maintain backwards compatibility
  550. endif
  551. PRIVKEY_LIST := $(BIN)/.private_key.list
  552. ifeq ($(wildcard $(PRIVKEY_LIST)),)
  553. PRIVKEY_OLD := <invalid>
  554. else
  555. PRIVKEY_OLD := $(shell cat $(PRIVKEY_LIST))
  556. endif
  557. ifneq ($(PRIVKEY_OLD),$(PRIVKEY))
  558. $(shell $(ECHO) "$(PRIVKEY)" > $(PRIVKEY_LIST))
  559. endif
  560. $(PRIVKEY_LIST) : $(MAKEDEPS)
  561. VERYCLEANUP += $(PRIVKEY_LIST)
  562. # Embedded private key
  563. #
  564. PRIVKEY_INC := $(BIN)/.private_key.der
  565. ifdef PRIVKEY
  566. $(PRIVKEY_INC) : $(PRIVKEY) $(PRIVKEY_LIST)
  567. $(Q)$(OPENSSL) rsa -in $< -outform DER -out $@
  568. privkey_DEPS += $(PRIVKEY_INC)
  569. endif
  570. CLEANUP += $(BIN)/.private_key.*
  571. privkey_DEPS += $(PRIVKEY_LIST)
  572. CFLAGS_privkey += $(if $(PRIVKEY),-DPRIVATE_KEY="\"$(PRIVKEY_INC)\"")
  573. # (Single-element) list of named configurations
  574. #
  575. CONFIG_LIST := $(BIN)/.config.list
  576. ifeq ($(wildcard $(CONFIG_LIST)),)
  577. CONFIG_OLD := <invalid>
  578. else
  579. CONFIG_OLD := $(shell cat $(CONFIG_LIST))
  580. endif
  581. ifneq ($(CONFIG_OLD),$(CONFIG))
  582. $(shell $(ECHO) "$(CONFIG)" > $(CONFIG_LIST))
  583. endif
  584. $(CONFIG_LIST) : $(MAKEDEPS)
  585. VERYCLEANUP += $(CONFIG_LIST)
  586. # Named configurations
  587. #
  588. ifneq ($(CONFIG),)
  589. ifneq ($(wildcard config/$(CONFIG)),)
  590. CFLAGS += -DCONFIG=$(CONFIG)
  591. endif
  592. CFLAGS += -DLOCAL_CONFIG=$(CONFIG)
  593. endif
  594. config/named.h : $(CONFIG_LIST)
  595. $(Q)$(TOUCH) $@
  596. .PRECIOUS : config/named.h
  597. # These files use .incbin inline assembly to include a binary file.
  598. # Unfortunately ccache does not detect this dependency and caches
  599. # builds even when the binary file has changed.
  600. #
  601. $(BIN)/embedded.% : override CC := env CCACHE_DISABLE=1 $(CC)
  602. $(BIN)/certstore.% : override CC := env CCACHE_DISABLE=1 $(CC)
  603. $(BIN)/privkey.% : override CC := env CCACHE_DISABLE=1 $(CC)
  604. # Debug message autocolourisation range
  605. #
  606. DBGCOL_LIST := $(BIN)/.dbgcol.list
  607. ifeq ($(wildcard $(DBGCOL_LIST)),)
  608. DBGCOL_OLD := <invalid>
  609. else
  610. DBGCOL_OLD := $(shell cat $(DBGCOL_LIST))
  611. endif
  612. ifneq ($(DBGCOL_OLD),$(DBGCOL))
  613. $(shell $(ECHO) "$(DBGCOL)" > $(DBGCOL_LIST))
  614. endif
  615. $(DBGCOL_LIST) : $(MAKEDEPS)
  616. VERYCLEANUP += $(DBGCOL_LIST)
  617. DBGCOL_COLOURS := $(subst -, ,$(DBGCOL))
  618. DBGCOL_MIN := $(firstword $(DBGCOL_COLOURS))
  619. DBGCOL_MAX := $(lastword $(DBGCOL_COLOURS))
  620. debug_DEPS += $(DBGCOL_LIST)
  621. CFLAGS_debug += $(if $(DBGCOL_MIN),-DDBGCOL_MIN=$(DBGCOL_MIN))
  622. CFLAGS_debug += $(if $(DBGCOL_MAX),-DDBGCOL_MAX=$(DBGCOL_MAX))
  623. # We automatically generate rules for any file mentioned in AUTO_SRCS
  624. # using the following set of templates. We use $(eval ...) if
  625. # available, otherwise we generate separate Makefile fragments and
  626. # include them.
  627. # deps_template : generate dependency list for a given source file
  628. #
  629. # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
  630. #
  631. define deps_template_file
  632. $(call deps_template_parts,$(1),$(subst .,,$(suffix $(1))),$(basename $(notdir $(1))))
  633. endef
  634. #
  635. # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
  636. # $(2) is the source type (e.g. "c")
  637. # $(3) is the source base name (e.g. "rtl8139")
  638. #
  639. define deps_template_parts
  640. @$(ECHO) " [DEPS] $(1)"
  641. @$(MKDIR) -p $(BIN)/deps/$(dir $(1))
  642. $(Q)$(CPP) $(CFLAGS) $(CFLAGS_$(2)) $(CFLAGS_$(3)) -DOBJECT=$(3) \
  643. -Wno-error -M $(1) -MG -MP | \
  644. sed 's/\.o\s*:/_DEPS +=/' > $(BIN)/deps/$(1).d
  645. endef
  646. # rules_template : generate rules for a given source file
  647. #
  648. # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
  649. #
  650. define rules_template
  651. $(call rules_template_parts,$(1),$(subst .,,$(suffix $(1))),$(basename $(notdir $(1))))
  652. endef
  653. #
  654. # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
  655. # $(2) is the source type (e.g. "c")
  656. # $(3) is the source base name (e.g. "rtl8139")
  657. #
  658. define rules_template_parts
  659. $$(BIN)/$(3).o : $(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(3)_DEPS)
  660. $$(QM)$(ECHO) " [BUILD] $$@"
  661. $$(RULE_$(2))
  662. BOBJS += $$(BIN)/$(3).o
  663. $(foreach TGT,$(GENERIC_TARGETS),$(if $(RULE_$(2)_to_$(TGT)),$(NEWLINE)$(call rules_template_target,$(1),$(2),$(3),$(TGT))))
  664. $$(BIN)/deps/$(1).d : $$($(3)_DEPS)
  665. TAGS : $$($(3)_DEPS)
  666. endef
  667. #
  668. # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
  669. # $(2) is the source type (e.g. "c")
  670. # $(3) is the source base name (e.g. "rtl8139")
  671. # $(4) is the destination type (e.g. "dbg%.o")
  672. #
  673. define rules_template_target
  674. $$(BIN)/$(3).$(4) : $(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(3)_DEPS)
  675. $$(QM)$(ECHO) " [BUILD] $$@"
  676. $$(RULE_$(2)_to_$(4))
  677. $(TGT)_OBJS += $$(BIN)/$(3).$(4)
  678. endef
  679. #
  680. # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
  681. #
  682. define rules_template_file
  683. @$(ECHO) " [RULES] $(1)"
  684. @$(MKDIR) -p $(BIN)/rules/$(dir $(1))
  685. @$(ECHO_E) '$(subst $(NEWLINE),\n,$(call rules_template,$(1)))' \
  686. > $(BIN)/rules/$(1).r
  687. endef
  688. # Generate the dependency files
  689. #
  690. $(BIN)/deps/%.d : % $(MAKEDEPS)
  691. $(call deps_template_file,$<)
  692. # Calculate list of dependency files
  693. #
  694. AUTO_DEPS = $(patsubst %,$(BIN)/deps/%.d,$(AUTO_SRCS))
  695. autodeps :
  696. @$(ECHO) $(AUTO_DEPS)
  697. VERYCLEANUP += $(BIN)/deps
  698. # Include dependency files
  699. #
  700. ifdef NEED_DEPS
  701. ifneq ($(AUTO_DEPS),)
  702. -include $(AUTO_DEPS)
  703. endif
  704. endif
  705. # Generate the rules files
  706. #
  707. $(BIN)/rules/%.r : % $(MAKEDEPS)
  708. $(call rules_template_file,$<)
  709. # Calculate list of rules files
  710. #
  711. AUTO_RULES = $(patsubst %,$(BIN)/rules/%.r,$(AUTO_SRCS))
  712. autorules :
  713. @$(ECHO) $(AUTO_RULES)
  714. VERYCLEANUP += $(BIN)/rules
  715. # Evaluate rules (or include rules files)
  716. #
  717. ifdef NEED_DEPS
  718. ifneq ($(AUTO_RULES),)
  719. ifneq ($(HAVE_EVAL),)
  720. $(foreach SRC,$(AUTO_SRCS),$(eval $(call rules_template,$(SRC))))
  721. else
  722. -include $(AUTO_RULES)
  723. endif
  724. endif
  725. endif
  726. # Files to be parsed using parserom.pl
  727. #
  728. ROM_SRCS = $(foreach SRC,$(AUTO_SRCS),\
  729. $(if $(findstring drivers/,$(SRC)),$(SRC)))
  730. romsrcs :
  731. @$(ECHO) $(ROM_SRCS)
  732. # List of files to be parsed using parserom.pl
  733. #
  734. ROM_SRCS_LIST := $(BIN)/.rom.list
  735. ifeq ($(wildcard $(ROM_SRCS_LIST)),)
  736. ROM_SRCS_OLD := <invalid>
  737. else
  738. ROM_SRCS_OLD := $(shell cat $(ROM_SRCS_LIST))
  739. endif
  740. ifneq ($(ROM_SRCS_OLD),$(ROM_SRCS))
  741. $(shell $(ECHO) "$(ROM_SRCS)" > $(ROM_SRCS_LIST))
  742. endif
  743. $(ROM_SRCS_LIST) : $(MAKEDEPS)
  744. VERYCLEANUP += $(ROM_SRCS_LIST)
  745. # ROM definition file
  746. #
  747. ROMDEFS = $(BIN)/.rom.defs
  748. $(ROMDEFS) : $(ROM_SRCS) $(ROM_SRCS_LIST) $(PARSEROM) $(MAKEDEPS)
  749. $(QM)$(ECHO) " [PARSEROM]"
  750. $(Q)$(PERL) $(PARSEROM) $(ROM_SRCS) > $@
  751. VERYCLEANUP += $(ROMDEFS)
  752. # Evaluate ROM definition file
  753. ifdef NEED_DEPS
  754. ifneq ($(ROM_SRCS),)
  755. -include $(ROMDEFS)
  756. endif
  757. endif
  758. # Device ID tables (using IDs from ROM definition file)
  759. #
  760. define obj_pci_id_asm
  761. .section ".pci_devlist.$(1)", "a", $(ASM_TCHAR)progbits
  762. .globl pci_devlist_$(1)
  763. pci_devlist_$(1):
  764. .short ( 0x$(1) & 0xffff )
  765. endef
  766. define obj_isa_id_asm
  767. endef
  768. OBJ_IDS_ASM = $(foreach ROM,$(ROMS_$(OBJECT)),$(call obj_$(ROM_TYPE_$(ROM))_id_asm,$(ROM)))
  769. OBJ_IDS_ASM_NL = $(subst $(NEWLINE),\n,$(OBJ_IDS_ASM))
  770. $(BIN)/%.ids :
  771. @$(ECHO_E) '$(OBJ_IDS_ASM_NL)'
  772. BOBJS += $(patsubst %,$(BIN)/%.ids.o,$(DRIVERS))
  773. # The following variables are created by the autogenerated rules
  774. #
  775. bobjs :
  776. @$(ECHO) $(BOBJS)
  777. drivers_% :
  778. @$(ECHO) $(DRIVERS_$*)
  779. drivers :
  780. @$(ECHO) $(DRIVERS)
  781. .PHONY : drivers
  782. roms :
  783. @$(ECHO) $(ROMS)
  784. # Generate error usage information
  785. #
  786. $(BIN)/%.einfo : $(BIN)/%.o
  787. $(QM)$(ECHO) " [EINFO] $@"
  788. $(Q)$(OBJCOPY) -O binary -j .einfo --set-section-flags .einfo=alloc \
  789. $< $@
  790. EINFOS := $(patsubst $(BIN)/%.o,$(BIN)/%.einfo,$(BOBJS))
  791. $(BIN)/errors : $(EINFOS) $(EINFO)
  792. $(QM)$(ECHO) " [EINFO] $@"
  793. $(Q)$(EINFO) $(EINFOS) | sort > $@
  794. CLEANUP += $(BIN)/errors # Doesn't match the $(BIN)/*.* pattern
  795. # Generate the NIC file from the parsed source files. The NIC file is
  796. # only for rom-o-matic.
  797. #
  798. $(BIN)/NIC : $(AUTO_DEPS)
  799. @$(ECHO) '# This is an automatically generated file, do not edit' > $@
  800. @$(ECHO) '# It does not affect anything in the build, ' \
  801. 'it is only for rom-o-matic' >> $@
  802. @$(ECHO) >> $@
  803. @perl -ne 'chomp; print "$$1\n" if /\# NIC\t(.*)$$/' $^ >> $@
  804. CLEANUP += $(BIN)/NIC # Doesn't match the $(BIN)/*.* pattern
  805. # Select drivers to be included in the all-drivers build
  806. #
  807. DRIVERS_ipxe = $(DRIVERS_net) $(DRIVERS_infiniband) \
  808. $(DRIVERS_xen) $(DRIVERS_hyperv)
  809. # Analyse a target name (e.g. "bin/dfe538--prism2_pci.rom.tmp") and
  810. # derive the variables:
  811. #
  812. # TGT_ELEMENTS : the elements of the target (e.g. "dfe538 prism2_pci")
  813. # TGT_PREFIX : the prefix type (e.g. "pcirom")
  814. # TGT_DRIVERS : the driver for each element (e.g. "rtl8139 prism2_pci")
  815. # TGT_ROM_NAME : the ROM name (e.g. "dfe538")
  816. #
  817. TGT_ELEMENTS = $(subst --, ,$(firstword $(subst ., ,$(notdir $@))))
  818. TGT_ROM_NAME = $(firstword $(TGT_ELEMENTS))
  819. TGT_DRIVERS = $(strip $(foreach TGT_ELEMENT,$(TGT_ELEMENTS), \
  820. $(if $(DRIVERS_$(TGT_ELEMENT)), \
  821. $(DRIVERS_$(TGT_ELEMENT)), \
  822. $(firstword $(DRIVER_$(TGT_ELEMENT)) \
  823. $(TGT_ELEMENT)))))
  824. TGT_PREFIX_NAME = $(word 2,$(subst ., ,$(notdir $@)))
  825. TGT_PREFIX = $(strip $(if $(filter rom,$(TGT_PREFIX_NAME)), \
  826. $(ROM_TYPE_$(TGT_ROM_NAME))rom, \
  827. $(TGT_PREFIX_NAME)))
  828. # Look up ROM IDs for the current target
  829. # (e.g. "bin/dfe538--prism2_pci.rom.tmp") and derive the variables:
  830. #
  831. # TGT_PCI_VENDOR : the PCI vendor ID (e.g. "0x1186")
  832. # TGT_PCI_DEVICE : the PCI device ID (e.g. "0x1300")
  833. #
  834. TGT_PCI_VENDOR = $(PCI_VENDOR_$(TGT_ROM_NAME))
  835. TGT_PCI_DEVICE = $(PCI_DEVICE_$(TGT_ROM_NAME))
  836. # Calculate link-time options for the current target
  837. # (e.g. "bin/dfe538--prism2_pci.rom.tmp") and derive the variables:
  838. #
  839. # TGT_LD_DRIVERS : symbols to require in order to drag in the relevant drivers
  840. # (e.g. "obj_rtl8139 obj_prism2_pci")
  841. # TGT_LD_IDS : symbols to define in order to fill in ID structures in the
  842. # ROM header (e.g."pci_vendor_id=0x1186 pci_device_id=0x1300")
  843. #
  844. TGT_LD_DRIVERS = $(subst -,_,$(patsubst %,obj_%,$(TGT_DRIVERS)))
  845. TGT_LD_IDS = pci_vendor_id=$(firstword $(TGT_PCI_VENDOR) 0) \
  846. pci_device_id=$(firstword $(TGT_PCI_DEVICE) 0)
  847. TGT_LD_DEVLIST = $(foreach ELEM,$(TGT_ELEMENTS),$(if $(PCI_VENDOR_$(ELEM)),\
  848. pci_devlist_$(patsubst 0x%,%,$(PCI_VENDOR_$(ELEM)))$(patsubst 0x%,%,$(PCI_DEVICE_$(ELEM)))))
  849. TGT_LD_ENTRY = _$(TGT_PREFIX)_start
  850. # Calculate linker flags based on link-time options for the current
  851. # target type (e.g. "bin/dfe538--prism2_pci.rom.tmp") and derive the
  852. # variables:
  853. #
  854. # TGT_LD_FLAGS : target-specific flags to pass to linker (e.g.
  855. # "-u obj_zpciprefix -u obj_rtl8139 -u obj_prism2_pci
  856. # --defsym pci_vendor=0x1186 --defsym pci_device=0x1300")
  857. #
  858. TGT_LD_FLAGS = $(foreach SYM,$(TGT_LD_ENTRY) $(TGT_LD_DRIVERS) \
  859. $(TGT_LD_DEVLIST) obj_config obj_config_$(PLATFORM),\
  860. -u $(SYM) --defsym check_$(SYM)=$(SYM) ) \
  861. $(patsubst %,--defsym %,$(TGT_LD_IDS)) \
  862. -e $(TGT_LD_ENTRY)
  863. # Calculate list of debugging versions of objects to be included in
  864. # the target.
  865. #
  866. DEBUG_LIST = $(subst $(COMMA), ,$(DEBUG))
  867. DEBUG_OBJ_LEVEL = $(firstword $(word 2,$(subst :, ,$(1))) 1)
  868. DEBUG_OBJ_BASE = $(word 1,$(subst :, ,$(1))).dbg$(call DEBUG_OBJ_LEVEL,$(1))
  869. DEBUG_OBJ = $(BIN)/$(call DEBUG_OBJ_BASE,$(1)).o
  870. DEBUG_ORIG_OBJ = $(BIN)/$(word 1,$(subst :, ,$(1))).o
  871. DEBUG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_OBJ,$(D)))
  872. DEBUG_ORIG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_ORIG_OBJ,$(D)))
  873. BLIB_OBJS = $(DEBUG_OBJS) $(filter-out $(DEBUG_ORIG_OBJS),$(BOBJS))
  874. # Print out all derived information for a given target.
  875. #
  876. $(BIN)/%.info :
  877. @$(ECHO) 'Elements : $(TGT_ELEMENTS)'
  878. @$(ECHO) 'Prefix : $(TGT_PREFIX)'
  879. @$(ECHO) 'Drivers : $(TGT_DRIVERS)'
  880. @$(ECHO) 'ROM name : $(TGT_ROM_NAME)'
  881. @$(ECHO)
  882. @$(ECHO) 'PCI vendor : $(TGT_PCI_VENDOR)'
  883. @$(ECHO) 'PCI device : $(TGT_PCI_DEVICE)'
  884. @$(ECHO)
  885. @$(ECHO) 'LD driver symbols : $(TGT_LD_DRIVERS)'
  886. @$(ECHO) 'LD ID symbols : $(TGT_LD_IDS)'
  887. @$(ECHO) 'LD devlist symbols : $(TGT_LD_DEVLIST)'
  888. @$(ECHO) 'LD entry point : $(TGT_LD_ENTRY)'
  889. @$(ECHO)
  890. @$(ECHO) 'LD target flags : $(TGT_LD_FLAGS)'
  891. @$(ECHO)
  892. @$(ECHO) 'Debugging objects : $(DEBUG_OBJS)'
  893. @$(ECHO) 'Replaced objects : $(DEBUG_ORIG_OBJS)'
  894. # List of objects included in the last build of blib. This is needed
  895. # in order to correctly rebuild blib whenever the list of objects
  896. # changes.
  897. #
  898. BLIB_LIST := $(BIN)/.blib.list
  899. ifeq ($(wildcard $(BLIB_LIST)),)
  900. BLIB_OBJS_OLD := <invalid>
  901. else
  902. BLIB_OBJS_OLD := $(shell cat $(BLIB_LIST))
  903. endif
  904. ifneq ($(BLIB_OBJS_OLD),$(BLIB_OBJS))
  905. $(shell $(ECHO) "$(BLIB_OBJS)" > $(BLIB_LIST))
  906. endif
  907. $(BLIB_LIST) : $(MAKEDEPS)
  908. VERYCLEANUP += $(BLIB_LIST)
  909. # Library of all objects
  910. #
  911. BLIB = $(BIN)/blib.a
  912. $(BLIB) : $(BLIB_OBJS) $(BLIB_LIST) $(MAKEDEPS)
  913. $(Q)$(RM) $(BLIB)
  914. $(QM)$(ECHO) " [AR] $@"
  915. $(Q)$(AR) r $@ $(sort $(BLIB_OBJS))
  916. $(Q)$(RANLIB) $@
  917. blib : $(BLIB)
  918. # Command to generate build ID. Must be unique for each $(BIN)/%.tmp,
  919. # even within the same build run.
  920. #
  921. BUILD_ID_CMD := perl -e 'printf "0x%08x", int ( rand ( 0xffffffff ) );'
  922. # Build timestamp
  923. #
  924. BUILD_TIMESTAMP := $(shell date +%s)
  925. # Build version
  926. #
  927. GIT_INDEX := $(if $(GITVERSION),$(if $(wildcard ../.git/index),../.git/index))
  928. $(BIN)/version.%.o : core/version.c $(MAKEDEPS) $(GIT_INDEX)
  929. $(QM)$(ECHO) " [VERSION] $@"
  930. $(Q)$(COMPILE_c) -DBUILD_NAME="\"$*\"" \
  931. -DVERSION_MAJOR=$(VERSION_MAJOR) \
  932. -DVERSION_MINOR=$(VERSION_MINOR) \
  933. -DVERSION_PATCH=$(VERSION_PATCH) \
  934. -DVERSION="\"$(VERSION)\"" \
  935. -c $< -o $@
  936. # Build an intermediate object file from the objects required for the
  937. # specified target.
  938. #
  939. $(BIN)/%.tmp : $(BIN)/version.%.o $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
  940. $(QM)$(ECHO) " [LD] $@"
  941. $(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $< $(BLIB) -o $@ \
  942. --defsym _build_id=`$(BUILD_ID_CMD)` \
  943. --defsym _build_timestamp=$(BUILD_TIMESTAMP) \
  944. -Map $(BIN)/$*.tmp.map
  945. $(Q)$(OBJDUMP) -ht $@ | $(PERL) $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
  946. # Keep intermediate object file (useful for debugging)
  947. .PRECIOUS : $(BIN)/%.tmp
  948. # Show a linker map for the specified target
  949. #
  950. $(BIN)/%.map : $(BIN)/%.tmp
  951. @less $(BIN)/$*.tmp.map
  952. # Get objects list for the specified target
  953. #
  954. define objs_list
  955. $(sort $(foreach OBJ_SYMBOL,\
  956. $(filter obj_%,$(shell $(NM) $(1) | cut -d" " -f3)),\
  957. $(patsubst obj_%,%,$(OBJ_SYMBOL))))
  958. endef
  959. $(BIN)/%.objs : $(BIN)/%.tmp
  960. $(Q)$(ECHO) $(call objs_list,$<)
  961. $(BIN)/%.sizes : $(BIN)/%.tmp
  962. $(Q)$(SIZE) -t $(foreach OBJ,$(call objs_list,$<),$(wildcard $(BIN)/$(subst _,?,$(OBJ)).o)) | \
  963. sort -g
  964. # Get dependency list for the specified target
  965. #
  966. define deps_list
  967. $(sort $(foreach OBJ,$(call objs_list,$(1)),$($(OBJ)_DEPS)))
  968. endef
  969. $(BIN)/%.deps : $(BIN)/%.tmp
  970. $(Q)$(ECHO) $(call deps_list,$<)
  971. # Get unneeded source files for the specified target
  972. #
  973. define nodeps_list
  974. $(sort $(filter-out $(call deps_list,$(1)),\
  975. $(foreach BOBJ,$(BOBJS),\
  976. $($(basename $(notdir $(BOBJ)))_DEPS))))
  977. endef
  978. $(BIN)/%.nodeps : $(BIN)/%.tmp
  979. $(Q)$(ECHO) $(call nodeps_list,$<)
  980. # Get licensing verdict for the specified target
  981. #
  982. define licensable_deps_list
  983. $(filter-out config/local/%.h,\
  984. $(filter-out $(BIN)/.%.list,\
  985. $(call deps_list,$(1))))
  986. endef
  987. define unlicensed_deps_list
  988. $(shell grep -L FILE_LICENCE $(call licensable_deps_list,$(1)))
  989. endef
  990. define licence_list
  991. $(sort $(foreach LICENCE,\
  992. $(filter __licence__%,$(shell $(NM) $(1) | cut -d" " -f3)),\
  993. $(word 2,$(subst __, ,$(LICENCE)))))
  994. endef
  995. $(BIN)/%.licence_list : $(BIN)/%.tmp
  996. $(Q)$(ECHO) $(call licence_list,$<)
  997. $(BIN)/%.licence : $(BIN)/%.tmp
  998. $(QM)$(ECHO) " [LICENCE] $@"
  999. $(Q)$(if $(strip $(call unlicensed_deps_list,$<)),\
  1000. echo -n "Unable to determine licence because the following " ;\
  1001. echo "files are missing a licence declaration:" ;\
  1002. echo $(call unlicensed_deps_list,$<);\
  1003. exit 1,\
  1004. $(PERL) $(LICENCE) $(call licence_list,$<))
  1005. # Extract compression information from intermediate object file
  1006. #
  1007. $(BIN)/%.zinfo : $(BIN)/%.tmp
  1008. $(QM)$(ECHO) " [ZINFO] $@"
  1009. $(Q)$(OBJCOPY) -O binary -j .zinfo $< $@
  1010. # Build raw binary file from intermediate object file
  1011. #
  1012. $(BIN)/%.bin : $(BIN)/%.tmp
  1013. $(QM)$(ECHO) " [BIN] $@"
  1014. $(Q)$(OBJCOPY) -O binary -R .zinfo $< $@
  1015. # Compress raw binary file
  1016. #
  1017. $(BIN)/%.zbin : $(BIN)/%.bin $(BIN)/%.zinfo $(ZBIN)
  1018. $(QM)$(ECHO) " [ZBIN] $@"
  1019. $(Q)$(ZBIN) $(BIN)/$*.bin $(BIN)/$*.zinfo > $@
  1020. # Rules for each media format. These are generated and placed in an
  1021. # external Makefile fragment. We could do this via $(eval ...), but
  1022. # that would require make >= 3.80.
  1023. #
  1024. # Note that there's an alternative way to generate most .rom images:
  1025. # they can be copied from their 'master' ROM image using cp and
  1026. # reprocessed with makerom to add the PCI IDs and ident string. The
  1027. # relevant rule would look something like:
  1028. #
  1029. # $(BIN)/dfe538%rom : $(BIN)/rtl8139%rom
  1030. # cat $< $@
  1031. # $(FINALISE_rom)
  1032. #
  1033. # You can derive the ROM/driver relationships using the variables
  1034. # DRIVER_<rom> and/or ROMS_<driver>.
  1035. #
  1036. # We don't currently do this, because (a) it would require generating
  1037. # yet more Makefile fragments (since you need a rule for each ROM in
  1038. # ROMS), and (b) the linker is so fast that it probably wouldn't make
  1039. # much difference to the overall build time.
  1040. # Add NON_AUTO_MEDIA to the media list, so that they show up in the
  1041. # output of "make"
  1042. #
  1043. MEDIA += $(NON_AUTO_MEDIA)
  1044. media :
  1045. @$(ECHO) $(MEDIA)
  1046. AUTO_MEDIA = $(filter-out $(NON_AUTO_MEDIA),$(MEDIA))
  1047. automedia :
  1048. @$(ECHO) $(AUTO_MEDIA)
  1049. # media_template : create media rules
  1050. #
  1051. # $(1) is the media name (e.g. "rom")
  1052. #
  1053. define media_template
  1054. $(if $(filter $(1),$(AUTO_MEDIA)),$(call auto_media_template,$(1)))
  1055. LIST_$(1) := $$(if $$(LIST_NAME_$(1)),$$($$(LIST_NAME_$(1))),$$(DRIVERS))
  1056. ALL_$(1) = $$(foreach ITEM,$$(LIST_$(1)),$$(BIN)/$$(ITEM).$(1))
  1057. $$(BIN)/all$(1)s : $$(ALL_$(1))
  1058. $$(BIN)/allall : $$(BIN)/all$(1)s
  1059. all$(1)s : $$(BIN)/all$(1)s
  1060. allall : $$(BIN)/allall
  1061. endef
  1062. #
  1063. # $(1) is the media name (e.g. "rom")
  1064. #
  1065. define auto_media_template
  1066. $$(BIN)/%.$(1) : $$(BIN)/%.$(1).zbin
  1067. $$(QM)echo " [FINISH] $$@"
  1068. $$(Q)$$(CP) $$< $$@
  1069. $$(Q)$$(if $$(PAD_$(1)),$$(PAD_$(1)) $$@)
  1070. $$(Q)$$(if $$(FINALISE_$(1)),$$(FINALISE_$(1)) $$@)
  1071. endef
  1072. #
  1073. # $(1) is the media name (e.g. "rom")
  1074. #
  1075. define media_template_file
  1076. @$(ECHO) " [MEDIARULES] $(1)"
  1077. @$(MKDIR) -p $(BIN)/rules/$(dir $(1))
  1078. @$(ECHO_E) '$(subst $(NEWLINE),\n,$(call media_template,$(1)))' \
  1079. > $(BIN)/rules/$(1).media.r
  1080. endef
  1081. # Generate media rules files
  1082. #
  1083. $(BIN)/rules/%.media.r : $(MAKEDEPS)
  1084. $(call media_template_file,$*)
  1085. # Calculate list of media rules files
  1086. #
  1087. MEDIA_RULES = $(patsubst %,$(BIN)/rules/%.media.r,$(MEDIA))
  1088. mediarules :
  1089. @$(ECHO) $(MEDIA_RULES)
  1090. # Evaluate media rules (or include media rules files)
  1091. #
  1092. ifdef NEED_DEPS
  1093. ifneq ($(MEDIA_RULES),)
  1094. ifneq ($(HAVE_EVAL),)
  1095. $(foreach MEDIUM,$(MEDIA),$(eval $(call media_template,$(MEDIUM))))
  1096. else
  1097. -include $(MEDIA_RULES)
  1098. endif
  1099. endif
  1100. endif
  1101. # Alias for ipxe.%
  1102. #
  1103. $(BIN)/etherboot.% : $(BIN)/ipxe.%
  1104. ln -sf $(notdir $<) $@
  1105. endif # defined(BIN)
  1106. ###############################################################################
  1107. #
  1108. # The compression utilities
  1109. #
  1110. ZBIN_LDFLAGS := -llzma
  1111. $(ZBIN) : util/zbin.c $(MAKEDEPS)
  1112. $(QM)$(ECHO) " [HOSTCC] $@"
  1113. $(Q)$(HOST_CC) $(HOST_CFLAGS) $< $(ZBIN_LDFLAGS) -o $@
  1114. CLEANUP += $(ZBIN)
  1115. ###############################################################################
  1116. #
  1117. # The EFI image converter
  1118. #
  1119. ELF2EFI_CFLAGS := -I$(BINUTILS_DIR)/include -I$(BFD_DIR)/include \
  1120. -I$(ZLIB_DIR)/include -idirafter include
  1121. ELF2EFI_LDFLAGS := -L$(BINUTILS_DIR)/lib -L$(BFD_DIR)/lib -L$(ZLIB_DIR)/lib \
  1122. -lbfd -ldl -lz -Wl,--no-warn-search-mismatch
  1123. $(ELF2EFI32) : util/elf2efi.c $(MAKEDEPS)
  1124. $(QM)$(ECHO) " [HOSTCC] $@"
  1125. $(Q)$(HOST_CC) $(HOST_CFLAGS) $(ELF2EFI_CFLAGS) -DEFI_TARGET_IA32 $< \
  1126. $(ELF2EFI_LDFLAGS) -o $@
  1127. CLEANUP += $(ELF2EFI32)
  1128. $(ELF2EFI64) : util/elf2efi.c $(MAKEDEPS)
  1129. $(QM)$(ECHO) " [HOSTCC] $@"
  1130. $(Q)$(HOST_CC) $(HOST_CFLAGS) $(ELF2EFI_CFLAGS) -DEFI_TARGET_X64 $< \
  1131. $(ELF2EFI_LDFLAGS) -o $@
  1132. CLEANUP += $(ELF2EFI64)
  1133. $(EFIROM) : util/efirom.c $(MAKEDEPS)
  1134. $(QM)$(ECHO) " [HOSTCC] $@"
  1135. $(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
  1136. CLEANUP += $(EFIROM)
  1137. $(EFIFATBIN) : util/efifatbin.c $(MAKEDEPS)
  1138. $(QM)$(ECHO) " [HOSTCC] $@"
  1139. $(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
  1140. CLEANUP += $(EFIFATBIN)
  1141. ###############################################################################
  1142. #
  1143. # The ICC fixup utility
  1144. #
  1145. $(ICCFIX) : util/iccfix.c $(MAKEDEPS)
  1146. $(QM)$(ECHO) " [HOSTCC] $@"
  1147. $(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
  1148. CLEANUP += $(ICCFIX)
  1149. ###############################################################################
  1150. #
  1151. # The error usage information utility
  1152. #
  1153. $(EINFO) : util/einfo.c $(MAKEDEPS)
  1154. $(QM)$(ECHO) " [HOSTCC] $@"
  1155. $(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
  1156. CLEANUP += $(EINFO)
  1157. ###############################################################################
  1158. #
  1159. # Local configs
  1160. #
  1161. CONFIG_HEADERS := $(patsubst config/%,%,$(wildcard config/*.h))
  1162. CONFIG_LOCAL_HEADERS := $(foreach HEADER,$(CONFIG_HEADERS),\
  1163. config/local/$(HEADER))
  1164. $(CONFIG_LOCAL_HEADERS) :
  1165. $(Q)$(TOUCH) $@
  1166. .PRECIOUS : $(CONFIG_LOCAL_HEADERS)
  1167. ifneq ($(CONFIG),)
  1168. CONFIG_LOCAL_NAMED_HEADERS := $(foreach HEADER,$(CONFIG_HEADERS),\
  1169. config/local/$(CONFIG)/$(HEADER))
  1170. $(CONFIG_LOCAL_NAMED_HEADERS) :
  1171. $(Q)$(MKDIR) -p $(dir $@)
  1172. $(Q)$(TOUCH) $@
  1173. .PRECIOUS : $(CONFIG_LOCAL_NAMED_HEADERS)
  1174. endif
  1175. ###############################################################################
  1176. #
  1177. # Build the TAGS file(s) for emacs
  1178. #
  1179. TAGS :
  1180. ctags -e -R -f $@ --exclude=bin
  1181. CLEANUP += TAGS
  1182. ###############################################################################
  1183. #
  1184. # Force rebuild for any given target
  1185. #
  1186. %.rebuild :
  1187. rm -f $*
  1188. $(Q)$(MAKE) $*
  1189. ###############################################################################
  1190. #
  1191. # Symbol table checks
  1192. #
  1193. ifdef BIN
  1194. SYMTAB = $(BIN)/symtab
  1195. $(SYMTAB) : $(BLIB)
  1196. $(OBJDUMP) -w -t $< > $@
  1197. CLEANUP += $(BIN)/symtab
  1198. symcheck : $(SYMTAB)
  1199. $(PERL) $(SYMCHECK) $<
  1200. endif # defined(BIN)
  1201. ###############################################################################
  1202. #
  1203. # Build bochs symbol table
  1204. #
  1205. ifdef BIN
  1206. $(BIN)/%.bxs : $(BIN)/%.tmp
  1207. $(NM) $< | cut -d" " -f1,3 > $@
  1208. endif # defined(BIN)
  1209. ###############################################################################
  1210. #
  1211. # Documentation
  1212. #
  1213. ifdef BIN
  1214. $(BIN)/doxygen.cfg : doxygen.cfg $(MAKEDEPS)
  1215. $(Q)$(PERL) -pe 's{\@SRCDIRS\@}{$(SRCDIRS)}; ' \
  1216. -e 's{\@INCDIRS\@}{$(filter-out .,$(INCDIRS))}; ' \
  1217. -e 's{\@BIN\@}{$(BIN)}; ' \
  1218. -e 's{\@ARCH\@}{$(ARCH)}; ' \
  1219. $< > $@
  1220. $(BIN)/doc : $(BIN)/doxygen.cfg
  1221. $(Q)$(DOXYGEN) $<
  1222. .PHONY : $(BIN)/doc
  1223. doc : $(BIN)/doc
  1224. doc-clean :
  1225. $(Q)$(RM) -r $(BIN)/doc
  1226. VERYCLEANUP += $(BIN)/doc
  1227. docview :
  1228. @[ -f $(BIN)/doc/html/index.html ] || $(MAKE) $(BIN)/doc
  1229. @if [ -n "$$BROWSER" ] ; then \
  1230. ( $$BROWSER $(BIN)/doc/html/index.html & ) ; \
  1231. else \
  1232. $(ECHO) "Documentation index in $(BIN)/doc/html/index.html" ; \
  1233. fi
  1234. endif # defined(BIN)
  1235. ###############################################################################
  1236. #
  1237. # Keyboard maps
  1238. #
  1239. hci/keymap/keymap_%.c :
  1240. $(Q)$(PERL) $(GENKEYMAP) $* > $@
  1241. ###############################################################################
  1242. #
  1243. # Force deletion of incomplete targets
  1244. #
  1245. .DELETE_ON_ERROR :
  1246. ###############################################################################
  1247. #
  1248. # Clean-up
  1249. #
  1250. ifeq ($(NUM_BINS),0)
  1251. ALLBINS := bin{,-*}
  1252. CLEANUP := $(patsubst $(BIN)/%,$(ALLBINS)/%,$(CLEANUP))
  1253. VERYCLEANUP := $(patsubst $(BIN)/%,$(ALLBINS)/%,$(VERYCLEANUP))
  1254. endif
  1255. clean :
  1256. $(RM) $(CLEANUP)
  1257. veryclean : clean
  1258. $(RM) -r $(VERYCLEANUP)