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

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