Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Makefile.housekeeping 40KB

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