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