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

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