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

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