Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Makefile.housekeeping 36KB

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