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

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