Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Makefile.housekeeping 36KB

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