1 # -*- makefile -*- : Force emacs to use Makefile mode
3 # This file contains various boring housekeeping functions that would
4 # otherwise seriously clutter up the main Makefile.
6 ###############################################################################
8 # Find a usable "echo -e" substitute.
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')
20 ifeq ($(ECHO_E_ECHO_TAB),$(TAB))
21 ECHO_E := $(ECHO_E_ECHO)
23 ifeq ($(ECHO_E_ECHO_E_TAB),$(TAB))
24 ECHO_E := $(ECHO_E_ECHO_E)
26 ifeq ($(ECHO_E_BIN_ECHO_TAB),$(TAB))
27 ECHO_E := $(ECHO_E_BIN_ECHO)
29 ifeq ($(ECHO_E_BIN_ECHO_E_TAB),$(TAB))
30 ECHO_E := $(ECHO_E_BIN_ECHO_E)
37 @$(PRINTF) '%24s : x%sx\n' 'tab' '$(TAB)'
38 @$(PRINTF) '%24s : x%sx\n' '"$(ECHO_E_ECHO) \t"' \
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"
49 MAKEDEPS += .echocheck
50 VERYCLEANUP += .echocheck
53 @$(ECHO) "Using \"$(ECHO_E)\" for \"echo -e\""
55 ###############################################################################
57 # Generate a usable "seq" substitute
60 $(shell awk 'BEGIN { for ( i = $(1) ; i <= $(2) ; i++ ) print i }')
63 ###############################################################################
67 HOST_OS := $(shell uname -s)
71 ###############################################################################
75 CCDEFS := $(shell $(CC) -E -x c -c /dev/null -dM | cut -d" " -f2)
79 ifeq ($(filter __ICC,$(CCDEFS)),__ICC)
87 ###############################################################################
89 # Check for tools that can cause failed builds
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)
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)
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)
116 ###############################################################################
118 # Check if $(eval ...) is available to use
123 $(eval HAVE_EVAL := yes)
126 @$(ECHO) $(HAVE_EVAL)
128 ###############################################################################
130 # Check for various tool workarounds
134 WORKAROUND_ASFLAGS :=
135 WORKAROUND_LDFLAGS :=
137 # Make syntax does not allow use of comma or space in certain places.
138 # This ugly workaround is suggested in the manual.
142 SPACE := $(EMPTY) $(EMPTY)
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.
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)
160 # gcc 4.4 generates .eh_frame sections by default, which distort the
161 # output of "size". Inhibit this.
164 CFI_TEST = $(CC) -fno-dwarf2-cfi-asm -fno-exceptions -fno-unwind-tables \
165 -fno-asynchronous-unwind-tables -x c -c /dev/null \
166 -o /dev/null >/dev/null 2>&1
167 CFI_FLAGS := $(shell $(CFI_TEST) && \
168 $(ECHO) '-fno-dwarf2-cfi-asm -fno-exceptions ' \
169 '-fno-unwind-tables -fno-asynchronous-unwind-tables')
170 WORKAROUND_CFLAGS += $(CFI_FLAGS)
173 # gcc 4.6 generates spurious warnings if -Waddress is in force.
177 WNA_TEST = $(CC) -Wno-address -x c -c /dev/null -o /dev/null >/dev/null 2>&1
178 WNA_FLAGS := $(shell $(WNA_TEST) && $(ECHO) '-Wno-address')
179 WORKAROUND_CFLAGS += $(WNA_FLAGS)
182 # Some versions of gas choke on division operators, treating them as
183 # comment markers. Specifying --divide will work around this problem,
184 # but isn't available on older gas versions.
186 DIVIDE_TEST = $(AS) --divide /dev/null -o /dev/null 2>/dev/null
187 DIVIDE_FLAGS := $(shell $(DIVIDE_TEST) && $(ECHO) '--divide')
188 WORKAROUND_ASFLAGS += $(DIVIDE_FLAGS)
190 ###############################################################################
202 ###############################################################################
207 export REAL_CC := $(CC)
212 ###############################################################################
214 # Set BIN according to whatever was specified on the command line as
218 # Determine how many different BIN directories are mentioned in the
221 BIN_GOALS := $(filter bin bin/% bin-%,$(MAKECMDGOALS))
222 BIN_GOALS_BINS := $(sort $(foreach BG,$(BIN_GOALS),\
223 $(firstword $(subst /, ,$(BG)))))
224 NUM_BINS := $(words $(BIN_GOALS_BINS))
228 # No BIN directory was specified. Set BIN to "bin" as a sensible
237 # If exactly one BIN directory was specified, set BIN to match this
240 BIN := $(firstword $(BIN_GOALS_BINS))
244 # More than one BIN directory was specified. We cannot handle the
245 # latter case within a single make invocation, so set up recursive
246 # targets for each BIN directory. Use exactly one target for each BIN
247 # directory since running multiple make invocations within the same
248 # BIN directory is likely to cause problems.
250 # Leave $(BIN) undefined. This has implications for any target that
251 # depends on $(BIN); such targets should be made conditional upon the
252 # existence of $(BIN).
254 BIN_GOALS_FIRST := $(foreach BGB,$(BIN_GOALS_BINS),\
255 $(firstword $(filter $(BGB)/%,$(BIN_GOALS))))
256 BIN_GOALS_OTHER := $(filter-out $(BIN_GOALS_FIRST),$(BIN_GOALS))
258 $(BIN_GOALS_FIRST) : % : BIN_RECURSE
259 $(Q)$(MAKE) --no-print-directory BIN=$(firstword $(subst /, ,$@)) \
260 $(filter $(firstword $(subst /, ,$@))/%, $(BIN_GOALS))
261 $(BIN_GOALS_OTHER) : % : BIN_RECURSE
265 endif # NUM_BINS == 1
266 endif # NUM_BINS == 0
270 # Create $(BIN) directory if it doesn't exist yet
272 ifeq ($(wildcard $(BIN)),)
273 $(shell $(MKDIR) -p $(BIN))
276 # Target to allow e.g. "make bin-efi arch"
279 @# Do nothing, silently
282 # Remove everything in $(BIN) for a "make clean"
284 CLEANUP += $(BIN)/*.* # Avoid picking up directories
288 # Determine whether or not we need to include the dependency files
290 NO_DEP_TARGETS := $(BIN) clean veryclean
291 ifeq ($(MAKECMDGOALS),)
294 ifneq ($(strip $(filter-out $(NO_DEP_TARGETS),$(MAKECMDGOALS))),)
298 ###############################################################################
300 # Select build architecture and platform based on $(BIN)
302 # BIN has the form bin[-[arch-]platform]
304 ARCHS := $(patsubst arch/%,%,$(wildcard arch/*))
305 PLATFORMS := $(patsubst config/defaults/%.h,%,\
306 $(wildcard config/defaults/*.h))
311 @$(ECHO) $(PLATFORMS)
315 # Determine architecture portion of $(BIN), if present
316 BIN_ARCH := $(strip $(foreach A,$(ARCHS),\
317 $(patsubst bin-$(A)-%,$(A),\
318 $(filter bin-$(A)-%,$(BIN)))))
320 # Determine platform portion of $(BIN), if present
322 BIN_PLATFORM := $(patsubst bin-%,%,$(filter bin-%,$(BIN)))
324 BIN_PLATFORM := $(patsubst bin-$(BIN_ARCH)-%,%,$(BIN))
327 # Determine build architecture
329 ARCH := $(firstword $(BIN_ARCH) $(DEFAULT_ARCH))
330 CFLAGS += -DARCH=$(ARCH)
335 # Determine build platform
336 DEFAULT_PLATFORM := pcbios
337 PLATFORM := $(firstword $(BIN_PLATFORM) $(DEFAULT_PLATFORM))
338 CFLAGS += -DPLATFORM=$(PLATFORM)
344 # Include architecture-specific Makefile
346 MAKEDEPS += arch/$(ARCH)/Makefile
347 include arch/$(ARCH)/Makefile
350 # Include architecture-specific include path
352 INCDIRS += arch/$(ARCH)/include
353 INCDIRS += arch/$(ARCH)/include/$(PLATFORM)
356 ###############################################################################
358 # Source file handling
360 # SRCDIRS lists all directories containing source files.
364 # SRCS lists all .c or .S files found in any SRCDIR
366 SRCS += $(wildcard $(patsubst %,%/*.c,$(SRCDIRS)))
367 SRCS += $(wildcard $(patsubst %,%/*.S,$(SRCDIRS)))
371 # AUTO_SRCS lists all files in SRCS that are not mentioned in
372 # NON_AUTO_SRCS. Files should be added to NON_AUTO_SRCS if they
373 # cannot be built using the standard build template.
375 AUTO_SRCS = $(filter-out $(NON_AUTO_SRCS),$(SRCS))
377 @$(ECHO) $(AUTO_SRCS)
379 # Just about everything else in this section depends upon having
384 # INCDIRS lists the include path
390 CFLAGS += $(foreach INC,$(INCDIRS),-I$(INC))
394 CFLAGS += -ffreestanding
395 CFLAGS += -Wall -W -Wformat-nonliteral
396 HOST_CFLAGS += -Wall -W -Wformat-nonliteral
399 CFLAGS += -fno-builtin
402 CFLAGS += -diag-disable 111 # Unreachable code
403 CFLAGS += -diag-disable 128 # Unreachable loop
404 CFLAGS += -diag-disable 170 # Array boundary checks
405 CFLAGS += -diag-disable 177 # Unused functions
406 CFLAGS += -diag-disable 181 # printf() format checks
407 CFLAGS += -diag-disable 188 # enum strictness
408 CFLAGS += -diag-disable 193 # Undefined preprocessor identifiers
409 CFLAGS += -diag-disable 280 # switch ( constant )
410 CFLAGS += -diag-disable 310 # K&R parameter lists
411 CFLAGS += -diag-disable 424 # Extra semicolon
412 CFLAGS += -diag-disable 589 # Declarations mid-code
413 CFLAGS += -diag-disable 593 # Unused variables
414 CFLAGS += -diag-disable 810 # Casting ints to smaller ints
415 CFLAGS += -diag-disable 981 # Sequence point violations
416 CFLAGS += -diag-disable 1292 # Ignored attributes
417 CFLAGS += -diag-disable 1338 # void pointer arithmetic
418 CFLAGS += -diag-disable 1361 # Variable-length arrays
419 CFLAGS += -diag-disable 1418 # Missing prototypes
420 CFLAGS += -diag-disable 1419 # Missing prototypes
421 CFLAGS += -diag-disable 1599 # Hidden variables
422 CFLAGS += -Wall -Wmissing-declarations
424 CFLAGS += $(WORKAROUND_CFLAGS) $(EXTRA_CFLAGS)
425 ASFLAGS += $(WORKAROUND_ASFLAGS) $(EXTRA_ASFLAGS)
426 LDFLAGS += $(WORKAROUND_LDFLAGS) $(EXTRA_LDFLAGS)
427 HOST_CFLAGS += -O2 -g
429 # Inhibit -Werror if NO_WERROR is specified on make command line
431 ifneq ($(NO_WERROR),1)
433 ASFLAGS += --fatal-warnings
434 HOST_CFLAGS += -Werror
437 # Function trace recorder state in the last build. This is needed
438 # in order to correctly rebuild whenever the function recorder is
441 FNREC_STATE := $(BIN)/.fnrec.state
442 ifeq ($(wildcard $(FNREC_STATE)),)
443 FNREC_OLD := <invalid>
445 FNREC_OLD := $(shell cat $(FNREC_STATE))
447 ifeq ($(FNREC_OLD),$(FNREC))
450 $(FNREC_STATE) : clean
451 $(shell $(ECHO) "$(FNREC)" > $(FNREC_STATE))
454 VERYCLEANUP += $(FNREC_STATE)
455 MAKEDEPS += $(FNREC_STATE)
458 # Enabling -finstrument-functions affects gcc's analysis and leads to spurious
459 # warnings about use of uninitialised variables.
461 CFLAGS += -Wno-uninitialized
462 CFLAGS += -finstrument-functions
463 CFLAGS += -finstrument-functions-exclude-file-list=core/fnrec.c
466 # Enable per-item sections and section garbage collection. Note that
467 # some older versions of gcc support -fdata-sections but treat it as
468 # implying -fno-common, which would break our build. Some other older
469 # versions issue a spurious and uninhibitable warning if
470 # -ffunction-sections is used with -g, which would also break our
471 # build since we use -Werror.
474 DS_TEST = $(ECHO) 'char x;' | \
475 $(CC) -fdata-sections -S -x c - -o - 2>/dev/null | \
476 grep -E '\.comm' > /dev/null
477 DS_FLAGS := $(shell $(DS_TEST) && $(ECHO) '-fdata-sections')
478 FS_TEST = $(CC) -ffunction-sections -g -c -x c /dev/null \
479 -o /dev/null 2>/dev/null
480 FS_FLAGS := $(shell $(FS_TEST) && $(ECHO) '-ffunction-sections')
481 CFLAGS += $(FS_FLAGS) $(DS_FLAGS)
483 LDFLAGS += --gc-sections
485 # Force creation of static binaries (required for OpenBSD, does no
486 # harm on other platforms).
490 # compiler.h is needed for our linking and debugging system
492 CFLAGS += -include include/compiler.h
494 # CFLAGS for specific object types
497 CFLAGS_S += -DASSEMBLY
499 # Base object name of the current target
501 OBJECT = $(firstword $(subst ., ,$(@F)))
503 # CFLAGS for specific object files. You can define
504 # e.g. CFLAGS_rtl8139, and have those flags automatically used when
505 # compiling bin/rtl8139.o.
507 OBJ_CFLAGS = $(CFLAGS_$(OBJECT)) -DOBJECT=$(subst -,_,$(OBJECT))
509 @$(ECHO) $(OBJ_CFLAGS)
511 # ICC requires postprocessing objects to fix up table alignments
514 POST_O = && $(ICCFIX) $@
515 POST_O_DEPS := $(ICCFIX)
521 # Rules for specific object types.
523 COMPILE_c = $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
524 RULE_c = $(Q)$(COMPILE_c) -c $< -o $@ $(POST_O)
525 RULE_c_to_ids.o = $(Q)$(ECHO_E) '$(OBJ_IDS_ASM_NL)' | $(ASSEMBLE_S) -o $@
526 RULE_c_to_dbg%.o = $(Q)$(COMPILE_c) -DDBGLVL_MAX=$* -c $< -o $@ $(POST_O)
527 RULE_c_to_c = $(Q)$(COMPILE_c) -E -c $< > $@
528 RULE_c_to_s = $(Q)$(COMPILE_c) -S -g0 -c $< -o $@
530 PREPROCESS_S = $(CPP) $(CFLAGS) $(CFLAGS_S) $(OBJ_CFLAGS)
531 ASSEMBLE_S = $(AS) $(ASFLAGS)
532 RULE_S = $(Q)$(PREPROCESS_S) $< | $(ASSEMBLE_S) -o $@
533 RULE_S_to_dbg%.o = $(Q)$(PREPROCESS_S) -DDBGLVL_MAX=$* $< | $(ASSEMBLE_S) -o $@
534 RULE_S_to_s = $(Q)$(PREPROCESS_S) $< > $@
536 GENERIC_TARGETS += ids.o dbg%.o c s
538 # List of embedded images included in the last build of embedded.o.
539 # This is needed in order to correctly rebuild embedded.o whenever the
540 # list of objects changes.
542 EMBED := $(EMBEDDED_IMAGE) # Maintain backwards compatibility
543 EMBEDDED_LIST := $(BIN)/.embedded.list
544 ifeq ($(wildcard $(EMBEDDED_LIST)),)
545 EMBED_OLD := <invalid>
547 EMBED_OLD := $(shell cat $(EMBEDDED_LIST))
549 ifneq ($(EMBED_OLD),$(EMBED))
550 $(shell $(ECHO) "$(EMBED)" > $(EMBEDDED_LIST))
553 $(EMBEDDED_LIST) : $(MAKEDEPS)
555 VERYCLEANUP += $(EMBEDDED_LIST)
557 EMBEDDED_FILES := $(subst $(COMMA), ,$(EMBED))
558 EMBED_ALL := $(foreach i,$(call seq,1,$(words $(EMBEDDED_FILES))),\
559 EMBED ( $(i), \"$(word $(i), $(EMBEDDED_FILES))\",\
560 \"$(notdir $(word $(i),$(EMBEDDED_FILES)))\" ))
562 embedded_DEPS += $(EMBEDDED_FILES) $(EMBEDDED_LIST)
564 CFLAGS_embedded = -DEMBED_ALL="$(EMBED_ALL)"
566 # List of trusted root certificates
568 TRUSTED_LIST := $(BIN)/.trusted.list
569 ifeq ($(wildcard $(TRUSTED_LIST)),)
570 TRUST_OLD := <invalid>
572 TRUST_OLD := $(shell cat $(TRUSTED_LIST))
574 ifneq ($(TRUST_OLD),$(TRUST))
575 $(shell $(ECHO) "$(TRUST)" > $(TRUSTED_LIST))
578 $(TRUSTED_LIST) : $(MAKEDEPS)
580 VERYCLEANUP += $(TRUSTED_LIST)
582 # Trusted root certificate fingerprints
584 TRUSTED_CERTS := $(subst $(COMMA), ,$(TRUST))
585 TRUSTED_FPS := $(foreach CERT,$(TRUSTED_CERTS),\
586 0x$(subst :,$(COMMA) 0x,$(lastword $(subst =, ,\
587 $(shell $(OPENSSL) x509 -in $(CERT) -noout -sha256 \
588 -fingerprint))))$(COMMA))
590 rootcert_DEPS += $(TRUSTED_FILES) $(TRUSTED_LIST)
592 CFLAGS_rootcert = $(if $(TRUSTED_FPS),-DTRUSTED="$(TRUSTED_FPS)")
594 # List of embedded certificates
596 CERT_LIST := $(BIN)/.certificate.list
597 ifeq ($(wildcard $(CERT_LIST)),)
598 CERT_OLD := <invalid>
600 CERT_OLD := $(shell cat $(CERT_LIST))
602 ifneq ($(CERT_OLD),$(CERT))
603 $(shell $(ECHO) "$(CERT)" > $(CERT_LIST))
606 $(CERT_LIST) : $(MAKEDEPS)
608 VERYCLEANUP += $(CERT_LIST)
610 # Embedded certificates concatenated and then split into one file per
611 # certificate (even if original files contained certificate chains)
613 CERT_FILES := $(subst $(COMMA), ,$(CERT))
614 CERT_CONCAT := $(BIN)/.certificates.pem
618 CERT_COUNT := $(shell grep "BEGIN CERTIFICATE" $(CERT_FILES) | wc -l)
620 $(CERT_CONCAT) : $(CERT_FILES) $(CERT_LIST)
621 $(Q)cat $(CERT_FILES) > $@
623 # We must use an (otherwise unnecessary) pattern rule here to encode
624 # the fact that one "csplit" command generates multiple targets
625 CERT_PEMS := $(foreach i,$(call seq,1,$(CERT_COUNT)),\
626 $(BIN)/.certificate.pem.$(i))
627 $(subst .pem.,.%.,$(CERT_PEMS)) : $(BIN)/.certificates.%
628 $(Q)$(CSPLIT) -q -n 1 -f $(BIN)/.certificate.pem. $< \
629 '/BEGIN CERTIFICATE/' '{*}'
631 CERT_DERS := $(subst .certificate.pem.,.certificate.der.,$(CERT_PEMS))
632 $(BIN)/.certificate.der.% : $(BIN)/.certificate.pem.%
633 $(Q)$(OPENSSL) x509 -in $< -outform DER -out $@
635 CERT_ALL := $(foreach i,$(call seq,1,$(CERT_COUNT)),\
636 CERT ( $(i), \"$(word $(i),$(CERT_DERS))\" ))
640 certstore_DEPS += $(CERT_LIST) $(CERT_FILES) $(CERT_PEMS) $(CERT_DERS)
642 CFLAGS_certstore += -DCERT_ALL="$(CERT_ALL)"
644 CLEANUP += $(BIN)/.certificate.* $(BIN)/.certificates.*
646 # (Single-element) list of private keys
649 PRIVKEY := $(KEY) # Maintain backwards compatibility
651 PRIVKEY_LIST := $(BIN)/.private_key.list
652 ifeq ($(wildcard $(PRIVKEY_LIST)),)
653 PRIVKEY_OLD := <invalid>
655 PRIVKEY_OLD := $(shell cat $(PRIVKEY_LIST))
657 ifneq ($(PRIVKEY_OLD),$(PRIVKEY))
658 $(shell $(ECHO) "$(PRIVKEY)" > $(PRIVKEY_LIST))
661 $(PRIVKEY_LIST) : $(MAKEDEPS)
663 VERYCLEANUP += $(PRIVKEY_LIST)
665 # Embedded private key
667 PRIVKEY_INC := $(BIN)/.private_key.der
670 $(PRIVKEY_INC) : $(PRIVKEY) $(PRIVKEY_LIST)
671 $(Q)$(OPENSSL) rsa -in $< -outform DER -out $@
673 privkey_DEPS += $(PRIVKEY_INC)
676 CLEANUP += $(BIN)/.private_key.*
678 privkey_DEPS += $(PRIVKEY_LIST)
680 CFLAGS_privkey += $(if $(PRIVKEY),-DPRIVATE_KEY="\"$(PRIVKEY_INC)\"")
682 # (Single-element) list of named configurations
684 CONFIG_LIST := $(BIN)/.config.list
685 ifeq ($(wildcard $(CONFIG_LIST)),)
686 CONFIG_OLD := <invalid>
688 CONFIG_OLD := $(shell cat $(CONFIG_LIST))
690 ifneq ($(CONFIG_OLD),$(CONFIG))
691 $(shell $(ECHO) "$(CONFIG)" > $(CONFIG_LIST))
694 $(CONFIG_LIST) : $(MAKEDEPS)
696 VERYCLEANUP += $(CONFIG_LIST)
698 # Named configurations
701 ifneq ($(wildcard config/$(CONFIG)),)
702 CFLAGS += -DCONFIG=$(CONFIG)
704 CFLAGS += -DLOCAL_CONFIG=$(CONFIG)
707 config/named.h : $(CONFIG_LIST)
710 .PRECIOUS : config/named.h
712 # These files use .incbin inline assembly to include a binary file.
713 # Unfortunately ccache does not detect this dependency and caches
714 # builds even when the binary file has changed.
716 $(BIN)/embedded.% : override CC := env CCACHE_DISABLE=1 $(CC)
717 $(BIN)/certstore.% : override CC := env CCACHE_DISABLE=1 $(CC)
718 $(BIN)/privkey.% : override CC := env CCACHE_DISABLE=1 $(CC)
720 # Debug message autocolourisation range
722 DBGCOL_LIST := $(BIN)/.dbgcol.list
723 ifeq ($(wildcard $(DBGCOL_LIST)),)
724 DBGCOL_OLD := <invalid>
726 DBGCOL_OLD := $(shell cat $(DBGCOL_LIST))
728 ifneq ($(DBGCOL_OLD),$(DBGCOL))
729 $(shell $(ECHO) "$(DBGCOL)" > $(DBGCOL_LIST))
732 $(DBGCOL_LIST) : $(MAKEDEPS)
734 VERYCLEANUP += $(DBGCOL_LIST)
736 DBGCOL_COLOURS := $(subst -, ,$(DBGCOL))
737 DBGCOL_MIN := $(word 1,$(DBGCOL_COLOURS))
738 DBGCOL_MAX := $(word 2,$(DBGCOL_COLOURS))
740 debug_DEPS += $(DBGCOL_LIST)
742 CFLAGS_debug += $(if $(DBGCOL_MIN),-DDBGCOL_MIN=$(DBGCOL_MIN))
743 CFLAGS_debug += $(if $(DBGCOL_MAX),-DDBGCOL_MAX=$(DBGCOL_MAX))
745 # We automatically generate rules for any file mentioned in AUTO_SRCS
746 # using the following set of templates. We use $(eval ...) if
747 # available, otherwise we generate separate Makefile fragments and
750 # deps_template : generate dependency list for a given source file
752 # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
754 define deps_template_file
755 $(call deps_template_parts,$(1),$(subst .,,$(suffix $(1))),$(basename $(notdir $(1))))
758 # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
759 # $(2) is the source type (e.g. "c")
760 # $(3) is the source base name (e.g. "rtl8139")
762 define deps_template_parts
763 @$(ECHO) " [DEPS] $(1)"
764 @$(MKDIR) -p $(BIN)/deps/$(dir $(1))
765 $(Q)$(CPP) $(CFLAGS) $(CFLAGS_$(2)) $(CFLAGS_$(3)) -DOBJECT=$(3) \
766 -Wno-error -M $(1) -MG -MP | \
767 sed 's/\.o\s*:/_DEPS +=/' > $(BIN)/deps/$(1).d
770 # rules_template : generate rules for a given source file
772 # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
774 define rules_template
775 $(call rules_template_parts,$(1),$(subst .,,$(suffix $(1))),$(basename $(notdir $(1))))
778 # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
779 # $(2) is the source type (e.g. "c")
780 # $(3) is the source base name (e.g. "rtl8139")
782 define rules_template_parts
783 $$(BIN)/$(3).o : $(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(3)_DEPS)
784 $$(QM)$(ECHO) " [BUILD] $$@"
786 BOBJS += $$(BIN)/$(3).o
787 $(foreach TGT,$(GENERIC_TARGETS),$(if $(RULE_$(2)_to_$(TGT)),$(NEWLINE)$(call rules_template_target,$(1),$(2),$(3),$(TGT))))
788 $$(BIN)/deps/$(1).d : $$($(3)_DEPS)
792 # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
793 # $(2) is the source type (e.g. "c")
794 # $(3) is the source base name (e.g. "rtl8139")
795 # $(4) is the destination type (e.g. "dbg%.o")
797 define rules_template_target
798 $$(BIN)/$(3).$(4) : $(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(3)_DEPS)
799 $$(QM)$(ECHO) " [BUILD] $$@"
800 $$(RULE_$(2)_to_$(4))
801 $(TGT)_OBJS += $$(BIN)/$(3).$(4)
804 # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
806 define rules_template_file
807 @$(ECHO) " [RULES] $(1)"
808 @$(MKDIR) -p $(BIN)/rules/$(dir $(1))
809 @$(ECHO_E) '$(subst $(NEWLINE),\n,$(call rules_template,$(1)))' \
810 > $(BIN)/rules/$(1).r
813 # Generate the dependency files
815 $(BIN)/deps/%.d : % $(MAKEDEPS)
816 $(call deps_template_file,$<)
818 # Calculate list of dependency files
820 AUTO_DEPS = $(patsubst %,$(BIN)/deps/%.d,$(AUTO_SRCS))
822 @$(ECHO) $(AUTO_DEPS)
823 VERYCLEANUP += $(BIN)/deps
825 # Include dependency files
828 ifneq ($(AUTO_DEPS),)
829 -include $(AUTO_DEPS)
833 # Generate the rules files
835 $(BIN)/rules/%.r : % $(MAKEDEPS)
836 $(call rules_template_file,$<)
838 # Calculate list of rules files
840 AUTO_RULES = $(patsubst %,$(BIN)/rules/%.r,$(AUTO_SRCS))
842 @$(ECHO) $(AUTO_RULES)
843 VERYCLEANUP += $(BIN)/rules
845 # Evaluate rules (or include rules files)
848 ifneq ($(AUTO_RULES),)
849 ifneq ($(HAVE_EVAL),)
850 $(foreach SRC,$(AUTO_SRCS),$(eval $(call rules_template,$(SRC))))
852 -include $(AUTO_RULES)
857 # Files to be parsed using parserom.pl
859 ROM_SRCS = $(foreach SRC,$(AUTO_SRCS),\
860 $(if $(findstring drivers/,$(SRC)),$(SRC)))
864 # List of files to be parsed using parserom.pl
866 ROM_SRCS_LIST := $(BIN)/.rom.list
867 ifeq ($(wildcard $(ROM_SRCS_LIST)),)
868 ROM_SRCS_OLD := <invalid>
870 ROM_SRCS_OLD := $(shell cat $(ROM_SRCS_LIST))
872 ifneq ($(ROM_SRCS_OLD),$(ROM_SRCS))
873 $(shell $(ECHO) "$(ROM_SRCS)" > $(ROM_SRCS_LIST))
876 $(ROM_SRCS_LIST) : $(MAKEDEPS)
878 VERYCLEANUP += $(ROM_SRCS_LIST)
880 # ROM definition file
882 ROMDEFS = $(BIN)/.rom.defs
883 $(ROMDEFS) : $(ROM_SRCS) $(ROM_SRCS_LIST) $(PARSEROM) $(MAKEDEPS)
884 $(QM)$(ECHO) " [PARSEROM]"
885 $(Q)$(PERL) $(PARSEROM) $(ROM_SRCS) > $@
887 VERYCLEANUP += $(ROMDEFS)
889 # Evaluate ROM definition file
896 # Device ID tables (using IDs from ROM definition file)
898 define obj_pci_id_asm
899 .section ".pci_devlist.$(1)", "a", @progbits
900 .globl pci_devlist_$(1)
902 .short ( 0x$(1) & 0xffff )
905 define obj_isa_id_asm
907 OBJ_IDS_ASM = $(foreach ROM,$(ROMS_$(OBJECT)),$(call obj_$(ROM_TYPE_$(ROM))_id_asm,$(ROM)))
908 OBJ_IDS_ASM_NL = $(subst $(NEWLINE),\n,$(OBJ_IDS_ASM))
910 @$(ECHO_E) '$(OBJ_IDS_ASM_NL)'
912 BOBJS += $(patsubst %,$(BIN)/%.ids.o,$(DRIVERS))
914 # The following variables are created by the autogenerated rules
919 @$(ECHO) $(DRIVERS_$*)
926 # Generate error usage information
928 $(BIN)/%.einfo : $(BIN)/%.o
929 $(QM)$(ECHO) " [EINFO] $@"
930 $(Q)$(OBJCOPY) -O binary -j .einfo --set-section-flags .einfo=alloc \
933 EINFOS := $(patsubst $(BIN)/%.o,$(BIN)/%.einfo,$(BOBJS))
934 $(BIN)/errors : $(EINFOS) $(EINFO)
935 $(QM)$(ECHO) " [EINFO] $@"
936 $(Q)$(EINFO) $(EINFOS) | sort > $@
937 CLEANUP += $(BIN)/errors # Doesn't match the $(BIN)/*.* pattern
939 # Generate the NIC file from the parsed source files. The NIC file is
940 # only for rom-o-matic.
942 $(BIN)/NIC : $(AUTO_DEPS)
943 @$(ECHO) '# This is an automatically generated file, do not edit' > $@
944 @$(ECHO) '# It does not affect anything in the build, ' \
945 'it is only for rom-o-matic' >> $@
947 @perl -ne 'chomp; print "$$1\n" if /\# NIC\t(.*)$$/' $^ >> $@
948 CLEANUP += $(BIN)/NIC # Doesn't match the $(BIN)/*.* pattern
950 # Select drivers to be included in the all-drivers build
952 DRIVERS_ipxe = $(DRIVERS_net) $(DRIVERS_infiniband) \
953 $(DRIVERS_xen) $(DRIVERS_hyperv)
955 # Analyse a target name (e.g. "bin/dfe538--prism2_pci.rom.tmp") and
956 # derive the variables:
958 # TGT_ELEMENTS : the elements of the target (e.g. "dfe538 prism2_pci")
959 # TGT_PREFIX : the prefix type (e.g. "pcirom")
960 # TGT_DRIVERS : the driver for each element (e.g. "rtl8139 prism2_pci")
961 # TGT_ROM_NAME : the ROM name (e.g. "dfe538")
963 CARD_DRIVER = $(firstword $(DRIVER_$(1)) $(1))
964 TGT_ELEMENTS = $(subst --, ,$(firstword $(subst ., ,$(notdir $@))))
965 TGT_ROM_NAME = $(firstword $(TGT_ELEMENTS))
966 TGT_DRIVERS = $(strip $(if $(DRIVERS_$(TGT_ROM_NAME)), \
967 $(DRIVERS_$(TGT_ROM_NAME)), \
968 $(foreach TGT_ELEMENT,$(TGT_ELEMENTS), \
969 $(call CARD_DRIVER,$(TGT_ELEMENT))) ))
970 TGT_PREFIX_NAME = $(word 2,$(subst ., ,$(notdir $@)))
971 TGT_PREFIX = $(strip $(if $(filter rom,$(TGT_PREFIX_NAME)), \
972 $(ROM_TYPE_$(TGT_ROM_NAME))rom, \
975 # Look up ROM IDs for the current target
976 # (e.g. "bin/dfe538--prism2_pci.rom.tmp") and derive the variables:
978 # TGT_PCI_VENDOR : the PCI vendor ID (e.g. "0x1186")
979 # TGT_PCI_DEVICE : the PCI device ID (e.g. "0x1300")
981 TGT_PCI_VENDOR = $(PCI_VENDOR_$(TGT_ROM_NAME))
982 TGT_PCI_DEVICE = $(PCI_DEVICE_$(TGT_ROM_NAME))
984 # Calculate link-time options for the current target
985 # (e.g. "bin/dfe538--prism2_pci.rom.tmp") and derive the variables:
987 # TGT_LD_DRIVERS : symbols to require in order to drag in the relevant drivers
988 # (e.g. "obj_rtl8139 obj_prism2_pci")
989 # TGT_LD_IDS : symbols to define in order to fill in ID structures in the
990 # ROM header (e.g."pci_vendor_id=0x1186 pci_device_id=0x1300")
992 TGT_LD_DRIVERS = $(subst -,_,$(patsubst %,obj_%,$(TGT_DRIVERS)))
993 TGT_LD_IDS = pci_vendor_id=$(firstword $(TGT_PCI_VENDOR) 0) \
994 pci_device_id=$(firstword $(TGT_PCI_DEVICE) 0)
995 TGT_LD_DEVLIST = $(foreach ELEM,$(TGT_ELEMENTS),$(if $(PCI_VENDOR_$(ELEM)),\
996 pci_devlist_$(patsubst 0x%,%,$(PCI_VENDOR_$(ELEM)))$(patsubst 0x%,%,$(PCI_DEVICE_$(ELEM)))))
997 TGT_LD_ENTRY = _$(TGT_PREFIX)_start
999 # Calculate linker flags based on link-time options for the current
1000 # target type (e.g. "bin/dfe538--prism2_pci.rom.tmp") and derive the
1003 # TGT_LD_FLAGS : target-specific flags to pass to linker (e.g.
1004 # "-u obj_zpciprefix -u obj_rtl8139 -u obj_prism2_pci
1005 # --defsym pci_vendor=0x1186 --defsym pci_device=0x1300")
1007 TGT_LD_FLAGS = $(foreach SYM,$(TGT_LD_ENTRY) $(TGT_LD_DRIVERS) \
1008 $(TGT_LD_DEVLIST) obj_config,\
1009 -u $(SYM) --defsym check_$(SYM)=$(SYM) ) \
1010 $(patsubst %,--defsym %,$(TGT_LD_IDS)) \
1013 # Calculate list of debugging versions of objects to be included in
1016 DEBUG_LIST = $(subst $(COMMA), ,$(DEBUG))
1017 DEBUG_OBJ_LEVEL = $(firstword $(word 2,$(subst :, ,$(1))) 1)
1018 DEBUG_OBJ_BASE = $(word 1,$(subst :, ,$(1))).dbg$(call DEBUG_OBJ_LEVEL,$(1))
1019 DEBUG_OBJ = $(BIN)/$(call DEBUG_OBJ_BASE,$(1)).o
1020 DEBUG_ORIG_OBJ = $(BIN)/$(word 1,$(subst :, ,$(1))).o
1021 DEBUG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_OBJ,$(D)))
1022 DEBUG_ORIG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_ORIG_OBJ,$(D)))
1023 BLIB_OBJS = $(DEBUG_OBJS) $(filter-out $(DEBUG_ORIG_OBJS),$(BOBJS))
1025 # Print out all derived information for a given target.
1028 @$(ECHO) 'Elements : $(TGT_ELEMENTS)'
1029 @$(ECHO) 'Prefix : $(TGT_PREFIX)'
1030 @$(ECHO) 'Drivers : $(TGT_DRIVERS)'
1031 @$(ECHO) 'ROM name : $(TGT_ROM_NAME)'
1033 @$(ECHO) 'PCI vendor : $(TGT_PCI_VENDOR)'
1034 @$(ECHO) 'PCI device : $(TGT_PCI_DEVICE)'
1036 @$(ECHO) 'LD driver symbols : $(TGT_LD_DRIVERS)'
1037 @$(ECHO) 'LD ID symbols : $(TGT_LD_IDS)'
1038 @$(ECHO) 'LD devlist symbols : $(TGT_LD_DEVLIST)'
1039 @$(ECHO) 'LD entry point : $(TGT_LD_ENTRY)'
1041 @$(ECHO) 'LD target flags : $(TGT_LD_FLAGS)'
1043 @$(ECHO) 'Debugging objects : $(DEBUG_OBJS)'
1044 @$(ECHO) 'Replaced objects : $(DEBUG_ORIG_OBJS)'
1046 # List of objects included in the last build of blib. This is needed
1047 # in order to correctly rebuild blib whenever the list of objects
1050 BLIB_LIST := $(BIN)/.blib.list
1051 ifeq ($(wildcard $(BLIB_LIST)),)
1052 BLIB_OBJS_OLD := <invalid>
1054 BLIB_OBJS_OLD := $(shell cat $(BLIB_LIST))
1056 ifneq ($(BLIB_OBJS_OLD),$(BLIB_OBJS))
1057 $(shell $(ECHO) "$(BLIB_OBJS)" > $(BLIB_LIST))
1060 $(BLIB_LIST) : $(MAKEDEPS)
1062 VERYCLEANUP += $(BLIB_LIST)
1064 # Library of all objects
1066 BLIB = $(BIN)/blib.a
1067 $(BLIB) : $(BLIB_OBJS) $(BLIB_LIST) $(MAKEDEPS)
1069 $(QM)$(ECHO) " [AR] $@"
1070 $(Q)$(AR) r $@ $(sort $(BLIB_OBJS))
1074 # Command to generate build ID. Must be unique for each $(BIN)/%.tmp,
1075 # even within the same build run.
1077 BUILD_ID_CMD := perl -e 'printf "0x%08x", int ( rand ( 0xffffffff ) );'
1081 BUILD_TIMESTAMP := $(shell date +%s)
1085 GIT_INDEX := $(if $(GITVERSION),$(if $(wildcard ../.git/index),../.git/index))
1086 $(BIN)/version.%.o : core/version.c $(MAKEDEPS) $(GIT_INDEX)
1087 $(QM)$(ECHO) " [VERSION] $@"
1088 $(Q)$(COMPILE_c) -DBUILD_NAME="\"$*\"" \
1089 -DVERSION_MAJOR=$(VERSION_MAJOR) \
1090 -DVERSION_MINOR=$(VERSION_MINOR) \
1091 -DVERSION_PATCH=$(VERSION_PATCH) \
1092 -DVERSION="\"$(VERSION)\"" \
1095 # Build an intermediate object file from the objects required for the
1098 $(BIN)/%.tmp : $(BIN)/version.%.o $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
1099 $(QM)$(ECHO) " [LD] $@"
1100 $(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $< $(BLIB) -o $@ \
1101 --defsym _build_id=`$(BUILD_ID_CMD)` \
1102 --defsym _build_timestamp=$(BUILD_TIMESTAMP) \
1103 -Map $(BIN)/$*.tmp.map
1104 $(Q)$(OBJDUMP) -ht $@ | $(PERL) $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
1106 # Keep intermediate object file (useful for debugging)
1107 .PRECIOUS : $(BIN)/%.tmp
1109 # Show a linker map for the specified target
1111 $(BIN)/%.map : $(BIN)/%.tmp
1112 @less $(BIN)/$*.tmp.map
1114 # Get objects list for the specified target
1117 $(sort $(foreach OBJ_SYMBOL,\
1118 $(filter obj_%,$(shell $(NM) $(1) | cut -d" " -f3)),\
1119 $(patsubst obj_%,%,$(OBJ_SYMBOL))))
1121 $(BIN)/%.objs : $(BIN)/%.tmp
1122 $(Q)$(ECHO) $(call objs_list,$<)
1123 $(BIN)/%.sizes : $(BIN)/%.tmp
1124 $(Q)$(SIZE) -t $(foreach OBJ,$(call objs_list,$<),$(wildcard $(BIN)/$(subst _,?,$(OBJ)).o)) | \
1127 # Get dependency list for the specified target
1130 $(sort $(foreach OBJ,$(call objs_list,$(1)),$($(OBJ)_DEPS)))
1132 $(BIN)/%.deps : $(BIN)/%.tmp
1133 $(Q)$(ECHO) $(call deps_list,$<)
1135 # Get unneeded source files for the specified target
1138 $(sort $(filter-out $(call deps_list,$(1)),\
1139 $(foreach BOBJ,$(BOBJS),\
1140 $($(basename $(notdir $(BOBJ)))_DEPS))))
1142 $(BIN)/%.nodeps : $(BIN)/%.tmp
1143 $(Q)$(ECHO) $(call nodeps_list,$<)
1145 # Get licensing verdict for the specified target
1147 define licensable_deps_list
1148 $(filter-out config/local/%.h,\
1149 $(filter-out $(BIN)/.%.list,\
1150 $(call deps_list,$(1))))
1152 define unlicensed_deps_list
1153 $(shell grep -L FILE_LICENCE $(call licensable_deps_list,$(1)))
1156 $(sort $(foreach LICENCE,\
1157 $(filter __licence__%,$(shell $(NM) $(1) | cut -d" " -f3)),\
1158 $(word 2,$(subst __, ,$(LICENCE)))))
1160 $(BIN)/%.licence_list : $(BIN)/%.tmp
1161 $(Q)$(ECHO) $(call licence_list,$<)
1162 $(BIN)/%.licence : $(BIN)/%.tmp
1163 $(QM)$(ECHO) " [LICENCE] $@"
1164 $(Q)$(if $(strip $(call unlicensed_deps_list,$<)),\
1165 echo -n "Unable to determine licence because the following " ;\
1166 echo "files are missing a licence declaration:" ;\
1167 echo $(call unlicensed_deps_list,$<);\
1169 $(PERL) $(LICENCE) $(call licence_list,$<))
1171 # Extract compression information from intermediate object file
1173 $(BIN)/%.zinfo : $(BIN)/%.tmp
1174 $(QM)$(ECHO) " [ZINFO] $@"
1175 $(Q)$(OBJCOPY) -O binary -j .zinfo $< $@
1177 # Build raw binary file from intermediate object file
1179 $(BIN)/%.bin : $(BIN)/%.tmp
1180 $(QM)$(ECHO) " [BIN] $@"
1181 $(Q)$(OBJCOPY) -O binary -R .zinfo $< $@
1183 # Compress raw binary file
1185 $(BIN)/%.zbin : $(BIN)/%.bin $(BIN)/%.zinfo $(ZBIN)
1186 $(QM)$(ECHO) " [ZBIN] $@"
1187 $(Q)$(ZBIN) $(BIN)/$*.bin $(BIN)/$*.zinfo > $@
1189 # Rules for each media format. These are generated and placed in an
1190 # external Makefile fragment. We could do this via $(eval ...), but
1191 # that would require make >= 3.80.
1193 # Note that there's an alternative way to generate most .rom images:
1194 # they can be copied from their 'master' ROM image using cp and
1195 # reprocessed with makerom to add the PCI IDs and ident string. The
1196 # relevant rule would look something like:
1198 # $(BIN)/dfe538%rom : $(BIN)/rtl8139%rom
1202 # You can derive the ROM/driver relationships using the variables
1203 # DRIVER_<rom> and/or ROMS_<driver>.
1205 # We don't currently do this, because (a) it would require generating
1206 # yet more Makefile fragments (since you need a rule for each ROM in
1207 # ROMS), and (b) the linker is so fast that it probably wouldn't make
1208 # much difference to the overall build time.
1210 # Add NON_AUTO_MEDIA to the media list, so that they show up in the
1213 MEDIA += $(NON_AUTO_MEDIA)
1218 AUTO_MEDIA = $(filter-out $(NON_AUTO_MEDIA),$(MEDIA))
1220 @$(ECHO) $(AUTO_MEDIA)
1222 # media_template : create media rules
1224 # $(1) is the media name (e.g. "rom")
1226 define media_template
1227 $(if $(filter $(1),$(AUTO_MEDIA)),$(call auto_media_template,$(1)))
1228 LIST_$(1) := $$(if $$(LIST_NAME_$(1)),$$($$(LIST_NAME_$(1))),$$(DRIVERS))
1229 ALL_$(1) = $$(foreach ITEM,$$(LIST_$(1)),$$(BIN)/$$(ITEM).$(1))
1230 $$(BIN)/all$(1)s : $$(ALL_$(1))
1231 $$(BIN)/allall : $$(BIN)/all$(1)s
1232 all$(1)s : $$(BIN)/all$(1)s
1233 allall : $$(BIN)/allall
1236 # $(1) is the media name (e.g. "rom")
1238 define auto_media_template
1239 $$(BIN)/%.$(1) : $$(BIN)/%.$(1).zbin
1240 $$(QM)echo " [FINISH] $$@"
1242 $$(Q)$$(if $$(PAD_$(1)),$$(PAD_$(1)) $$@)
1243 $$(Q)$$(if $$(FINALISE_$(1)),$$(FINALISE_$(1)) $$@)
1246 # $(1) is the media name (e.g. "rom")
1248 define media_template_file
1249 @$(ECHO) " [MEDIARULES] $(1)"
1250 @$(MKDIR) -p $(BIN)/rules/$(dir $(1))
1251 @$(ECHO_E) '$(subst $(NEWLINE),\n,$(call media_template,$(1)))' \
1252 > $(BIN)/rules/$(1).media.r
1255 # Generate media rules files
1257 $(BIN)/rules/%.media.r : $(MAKEDEPS)
1258 $(call media_template_file,$*)
1260 # Calculate list of media rules files
1262 MEDIA_RULES = $(patsubst %,$(BIN)/rules/%.media.r,$(MEDIA))
1264 @$(ECHO) $(MEDIA_RULES)
1266 # Evaluate media rules (or include media rules files)
1269 ifneq ($(MEDIA_RULES),)
1270 ifneq ($(HAVE_EVAL),)
1271 $(foreach MEDIUM,$(MEDIA),$(eval $(call media_template,$(MEDIUM))))
1273 -include $(MEDIA_RULES)
1280 $(BIN)/etherboot.% : $(BIN)/ipxe.%
1281 ln -sf $(notdir $<) $@
1283 endif # defined(BIN)
1285 ###############################################################################
1287 # The compression utilities
1290 ZBIN_LDFLAGS := -llzma
1292 $(ZBIN) : util/zbin.c $(MAKEDEPS)
1293 $(QM)$(ECHO) " [HOSTCC] $@"
1294 $(Q)$(HOST_CC) $(HOST_CFLAGS) $< $(ZBIN_LDFLAGS) -o $@
1297 ###############################################################################
1299 # The EFI image converter
1301 ELF2EFI_CFLAGS := -I$(BINUTILS_DIR)/include -I$(BFD_DIR)/include \
1302 -I$(ZLIB_DIR)/include -idirafter include
1303 ELF2EFI_LDFLAGS := -L$(BINUTILS_DIR)/lib -L$(BFD_DIR)/lib -L$(ZLIB_DIR)/lib \
1304 -lbfd -ldl -liberty -lz -Wl,--no-warn-search-mismatch
1306 $(ELF2EFI32) : util/elf2efi.c $(MAKEDEPS)
1307 $(QM)$(ECHO) " [HOSTCC] $@"
1308 $(Q)$(HOST_CC) $(HOST_CFLAGS) $(ELF2EFI_CFLAGS) -DEFI_TARGET_IA32 $< \
1309 $(ELF2EFI_LDFLAGS) -o $@
1310 CLEANUP += $(ELF2EFI32)
1312 $(ELF2EFI64) : util/elf2efi.c $(MAKEDEPS)
1313 $(QM)$(ECHO) " [HOSTCC] $@"
1314 $(Q)$(HOST_CC) $(HOST_CFLAGS) $(ELF2EFI_CFLAGS) -DEFI_TARGET_X64 $< \
1315 $(ELF2EFI_LDFLAGS) -o $@
1316 CLEANUP += $(ELF2EFI64)
1318 $(EFIROM) : util/efirom.c $(MAKEDEPS)
1319 $(QM)$(ECHO) " [HOSTCC] $@"
1320 $(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
1321 CLEANUP += $(EFIROM)
1323 $(EFIFATBIN) : util/efifatbin.c $(MAKEDEPS)
1324 $(QM)$(ECHO) " [HOSTCC] $@"
1325 $(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
1326 CLEANUP += $(EFIFATBIN)
1328 ###############################################################################
1330 # The ICC fixup utility
1332 $(ICCFIX) : util/iccfix.c $(MAKEDEPS)
1333 $(QM)$(ECHO) " [HOSTCC] $@"
1334 $(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
1335 CLEANUP += $(ICCFIX)
1337 ###############################################################################
1339 # The error usage information utility
1341 $(EINFO) : util/einfo.c $(MAKEDEPS)
1342 $(QM)$(ECHO) " [HOSTCC] $@"
1343 $(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
1346 ###############################################################################
1350 CONFIG_HEADERS := $(patsubst config/%,%,$(wildcard config/*.h))
1351 CONFIG_LOCAL_HEADERS := $(foreach HEADER,$(CONFIG_HEADERS),\
1352 config/local/$(HEADER))
1354 $(CONFIG_LOCAL_HEADERS) :
1357 .PRECIOUS : $(CONFIG_LOCAL_HEADERS)
1361 CONFIG_LOCAL_NAMED_HEADERS := $(foreach HEADER,$(CONFIG_HEADERS),\
1362 config/local/$(CONFIG)/$(HEADER))
1364 $(CONFIG_LOCAL_NAMED_HEADERS) :
1365 $(Q)$(MKDIR) -p $(dir $@)
1368 .PRECIOUS : $(CONFIG_LOCAL_NAMED_HEADERS)
1372 ###############################################################################
1374 # Build the TAGS file(s) for emacs
1377 ctags -e -R -f $@ --exclude=bin
1381 ###############################################################################
1383 # Force rebuild for any given target
1389 ###############################################################################
1391 # Symbol table checks
1396 SYMTAB = $(BIN)/symtab
1398 $(OBJDUMP) -w -t $< > $@
1400 CLEANUP += $(BIN)/symtab
1402 symcheck : $(SYMTAB)
1403 $(PERL) $(SYMCHECK) $<
1405 endif # defined(BIN)
1407 ###############################################################################
1409 # Build bochs symbol table
1414 $(BIN)/%.bxs : $(BIN)/%.tmp
1415 $(NM) $< | cut -d" " -f1,3 > $@
1417 endif # defined(BIN)
1419 ###############################################################################
1426 $(BIN)/doxygen.cfg : doxygen.cfg $(MAKEDEPS)
1427 $(Q)$(PERL) -pe 's{\@SRCDIRS\@}{$(SRCDIRS)}; ' \
1428 -e 's{\@INCDIRS\@}{$(filter-out .,$(INCDIRS))}; ' \
1429 -e 's{\@BIN\@}{$(BIN)}; ' \
1430 -e 's{\@ARCH\@}{$(ARCH)}; ' \
1433 $(BIN)/doc : $(BIN)/doxygen.cfg
1441 $(Q)$(RM) -r $(BIN)/doc
1443 VERYCLEANUP += $(BIN)/doc
1446 @[ -f $(BIN)/doc/html/index.html ] || $(MAKE) $(BIN)/doc
1447 @if [ -n "$$BROWSER" ] ; then \
1448 ( $$BROWSER $(BIN)/doc/html/index.html & ) ; \
1450 $(ECHO) "Documentation index in $(BIN)/doc/html/index.html" ; \
1453 endif # defined(BIN)
1455 ###############################################################################
1460 hci/keymap/keymap_%.c :
1461 $(Q)$(PERL) $(GENKEYMAP) $* > $@
1463 ###############################################################################
1465 # Force deletion of incomplete targets
1470 ###############################################################################
1475 ifeq ($(NUM_BINS),0)
1477 CLEANUP := $(patsubst $(BIN)/%,$(ALLBINS)/%,$(CLEANUP))
1478 VERYCLEANUP := $(patsubst $(BIN)/%,$(ALLBINS)/%,$(VERYCLEANUP))
1485 $(RM) -r $(VERYCLEANUP)