You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile.housekeeping 42KB

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