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
# The section type character (e.g. "@" in "@progbits") varies by
497
CFLAGS += -DASM_TCHAR='$(ASM_TCHAR)' -DASM_TCHAR_OPS='$(ASM_TCHAR_OPS)'
499
# CFLAGS for specific object types
502
CFLAGS_S += -DASSEMBLY
504
# Base object name of the current target
506
OBJECT = $(firstword $(subst ., ,$(@F)))
508
# CFLAGS for specific object files. You can define
509
# e.g. CFLAGS_rtl8139, and have those flags automatically used when
510
# compiling bin/rtl8139.o.
512
OBJ_CFLAGS = $(CFLAGS_$(OBJECT)) -DOBJECT=$(subst -,_,$(OBJECT))
514
@$(ECHO) $(OBJ_CFLAGS)
516
# ICC requires postprocessing objects to fix up table alignments
519
POST_O = && $(ICCFIX) $@
520
POST_O_DEPS := $(ICCFIX)
526
# Debug level calculations
528
DBGLVL_MAX = -DDBGLVL_MAX=$(firstword $(subst ., ,$(1)))
529
DBGLVL_DFLT = -DDBGLVL_DFLT=$(lastword $(subst ., ,$(1)))
530
DBGLVL = $(call DBGLVL_MAX,$(1)) $(call DBGLVL_DFLT,$(1))
532
# Rules for specific object types.
534
COMPILE_c = $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
535
RULE_c = $(Q)$(COMPILE_c) -c $< -o $@ $(POST_O)
536
RULE_c_to_ids.o = $(Q)$(ECHO_E) '$(OBJ_IDS_ASM_NL)' | $(ASSEMBLE_S) -o $@
537
RULE_c_to_dbg%.o= $(Q)$(COMPILE_c) $(call DBGLVL,$*) -c $< -o $@ $(POST_O)
538
RULE_c_to_c = $(Q)$(COMPILE_c) -E -c $< > $@
539
RULE_c_to_s = $(Q)$(COMPILE_c) -S -g0 -c $< -o $@
541
PREPROCESS_S = $(CPP) $(CFLAGS) $(CFLAGS_S) $(OBJ_CFLAGS)
542
ASSEMBLE_S = $(AS) $(ASFLAGS)
543
RULE_S = $(Q)$(PREPROCESS_S) $< | $(ASSEMBLE_S) -o $@
544
RULE_S_to_dbg%.o= $(Q)$(PREPROCESS_S) $(call DBGLVL,$*) $< | $(ASSEMBLE_S) -o $@
545
RULE_S_to_s = $(Q)$(PREPROCESS_S) $< > $@
547
GENERIC_TARGETS += ids.o dbg%.o c s
549
# List of embedded images included in the last build of embedded.o.
550
# This is needed in order to correctly rebuild embedded.o whenever the
551
# list of objects changes.
553
EMBED := $(EMBEDDED_IMAGE) # Maintain backwards compatibility
554
EMBEDDED_LIST := $(BIN)/.embedded.list
555
ifeq ($(wildcard $(EMBEDDED_LIST)),)
556
EMBED_OLD := <invalid>
558
EMBED_OLD := $(shell cat $(EMBEDDED_LIST))
560
ifneq ($(EMBED_OLD),$(EMBED))
561
$(shell $(ECHO) "$(EMBED)" > $(EMBEDDED_LIST))
564
$(EMBEDDED_LIST) : $(MAKEDEPS)
566
VERYCLEANUP += $(EMBEDDED_LIST)
568
EMBEDDED_FILES := $(subst $(COMMA), ,$(EMBED))
569
EMBED_ALL := $(foreach i,$(call seq,1,$(words $(EMBEDDED_FILES))),\
570
EMBED ( $(i), \"$(word $(i), $(EMBEDDED_FILES))\",\
571
\"$(notdir $(word $(i),$(EMBEDDED_FILES)))\" ))
573
embedded_DEPS += $(EMBEDDED_FILES) $(EMBEDDED_LIST)
575
CFLAGS_embedded = -DEMBED_ALL="$(EMBED_ALL)"
577
# List of trusted root certificates
579
TRUSTED_LIST := $(BIN)/.trusted.list
580
ifeq ($(wildcard $(TRUSTED_LIST)),)
581
TRUST_OLD := <invalid>
583
TRUST_OLD := $(shell cat $(TRUSTED_LIST))
585
ifneq ($(TRUST_OLD),$(TRUST))
586
$(shell $(ECHO) "$(TRUST)" > $(TRUSTED_LIST))
589
$(TRUSTED_LIST) : $(MAKEDEPS)
591
VERYCLEANUP += $(TRUSTED_LIST)
593
# Trusted root certificate fingerprints
595
TRUSTED_CERTS := $(subst $(COMMA), ,$(TRUST))
596
TRUSTED_FPS := $(foreach CERT,$(TRUSTED_CERTS),\
597
0x$(subst :,$(COMMA) 0x,$(lastword $(subst =, ,\
598
$(shell $(OPENSSL) x509 -in $(CERT) -noout -sha256 \
599
-fingerprint))))$(COMMA))
601
rootcert_DEPS += $(TRUSTED_FILES) $(TRUSTED_LIST)
603
CFLAGS_rootcert = $(if $(TRUSTED_FPS),-DTRUSTED="$(TRUSTED_FPS)")
605
# List of embedded certificates
607
CERT_LIST := $(BIN)/.certificate.list
608
ifeq ($(wildcard $(CERT_LIST)),)
609
CERT_OLD := <invalid>
611
CERT_OLD := $(shell cat $(CERT_LIST))
613
ifneq ($(CERT_OLD),$(CERT))
614
$(shell $(ECHO) "$(CERT)" > $(CERT_LIST))
617
$(CERT_LIST) : $(MAKEDEPS)
619
VERYCLEANUP += $(CERT_LIST)
621
# Embedded certificates concatenated and then split into one file per
622
# certificate (even if original files contained certificate chains)
624
CERT_FILES := $(subst $(COMMA), ,$(CERT))
625
CERT_CONCAT := $(BIN)/.certificates.pem
629
CERT_COUNT := $(shell grep "BEGIN CERTIFICATE" $(CERT_FILES) | wc -l)
631
$(CERT_CONCAT) : $(CERT_FILES) $(CERT_LIST)
632
$(Q)cat $(CERT_FILES) > $@
634
# We must use an (otherwise unnecessary) pattern rule here to encode
635
# the fact that one "csplit" command generates multiple targets
636
CERT_PEMS := $(foreach i,$(call seq,1,$(CERT_COUNT)),\
637
$(BIN)/.certificate.pem.$(i))
638
$(subst .pem.,.%.,$(CERT_PEMS)) : $(BIN)/.certificates.%
639
$(Q)$(CSPLIT) -q -n 1 -f $(BIN)/.certificate.pem. $< \
640
'/BEGIN CERTIFICATE/' '{*}'
642
CERT_DERS := $(subst .certificate.pem.,.certificate.der.,$(CERT_PEMS))
643
$(BIN)/.certificate.der.% : $(BIN)/.certificate.pem.%
644
$(Q)$(OPENSSL) x509 -in $< -outform DER -out $@
646
CERT_ALL := $(foreach i,$(call seq,1,$(CERT_COUNT)),\
647
CERT ( $(i), \"$(word $(i),$(CERT_DERS))\" ))
651
certstore_DEPS += $(CERT_LIST) $(CERT_FILES) $(CERT_PEMS) $(CERT_DERS)
653
CFLAGS_certstore += -DCERT_ALL="$(CERT_ALL)"
655
CLEANUP += $(BIN)/.certificate.* $(BIN)/.certificates.*
657
# (Single-element) list of private keys
660
PRIVKEY := $(KEY) # Maintain backwards compatibility
662
PRIVKEY_LIST := $(BIN)/.private_key.list
663
ifeq ($(wildcard $(PRIVKEY_LIST)),)
664
PRIVKEY_OLD := <invalid>
666
PRIVKEY_OLD := $(shell cat $(PRIVKEY_LIST))
668
ifneq ($(PRIVKEY_OLD),$(PRIVKEY))
669
$(shell $(ECHO) "$(PRIVKEY)" > $(PRIVKEY_LIST))
672
$(PRIVKEY_LIST) : $(MAKEDEPS)
674
VERYCLEANUP += $(PRIVKEY_LIST)
676
# Embedded private key
678
PRIVKEY_INC := $(BIN)/.private_key.der
681
$(PRIVKEY_INC) : $(PRIVKEY) $(PRIVKEY_LIST)
682
$(Q)$(OPENSSL) rsa -in $< -outform DER -out $@
684
privkey_DEPS += $(PRIVKEY_INC)
687
CLEANUP += $(BIN)/.private_key.*
689
privkey_DEPS += $(PRIVKEY_LIST)
691
CFLAGS_privkey += $(if $(PRIVKEY),-DPRIVATE_KEY="\"$(PRIVKEY_INC)\"")
693
# (Single-element) list of named configurations
695
CONFIG_LIST := $(BIN)/.config.list
696
ifeq ($(wildcard $(CONFIG_LIST)),)
697
CONFIG_OLD := <invalid>
699
CONFIG_OLD := $(shell cat $(CONFIG_LIST))
701
ifneq ($(CONFIG_OLD),$(CONFIG))
702
$(shell $(ECHO) "$(CONFIG)" > $(CONFIG_LIST))
705
$(CONFIG_LIST) : $(MAKEDEPS)
707
VERYCLEANUP += $(CONFIG_LIST)
709
# Named configurations
712
ifneq ($(wildcard config/$(CONFIG)),)
713
CFLAGS += -DCONFIG=$(CONFIG)
715
CFLAGS += -DLOCAL_CONFIG=$(CONFIG)
718
config/named.h : $(CONFIG_LIST)
721
.PRECIOUS : config/named.h
723
# (Single-element) list of assertion configuration
725
ASSERT_LIST := $(BIN)/.assert.list
726
ifeq ($(wildcard $(ASSERT_LIST)),)
727
ASSERT_OLD := <invalid>
729
ASSERT_OLD := $(shell cat $(ASSERT_LIST))
731
ifneq ($(ASSERT_OLD),$(ASSERT))
732
$(shell $(ECHO) "$(ASSERT)" > $(ASSERT_LIST))
735
$(ASSERT_LIST) : $(MAKEDEPS)
737
VERYCLEANUP += $(ASSERT_LIST)
739
# Assertion configuration
742
CFLAGS += -DASSERTING=$(ASSERT)
745
include/assert.h : $(ASSERT_LIST)
748
.PRECIOUS : include/assert.h
750
# (Single-element) list of profiling configuration
752
PROFILE_LIST := $(BIN)/.profile.list
753
ifeq ($(wildcard $(PROFILE_LIST)),)
754
PROFILE_OLD := <invalid>
756
PROFILE_OLD := $(shell cat $(PROFILE_LIST))
758
ifneq ($(PROFILE_OLD),$(PROFILE))
759
$(shell $(ECHO) "$(PROFILE)" > $(PROFILE_LIST))
762
$(PROFILE_LIST) : $(MAKEDEPS)
764
VERYCLEANUP += $(PROFILE_LIST)
766
# Profiling configuration
769
CFLAGS += -DPROFILING=$(PROFILE)
772
include/ipxe/profile.h : $(PROFILE_LIST)
775
.PRECIOUS : include/ipxe/profile.h
777
# These files use .incbin inline assembly to include a binary file.
778
# Unfortunately ccache does not detect this dependency and caches
779
# builds even when the binary file has changed.
781
$(BIN)/embedded.% : override CC := env CCACHE_DISABLE=1 $(CC)
782
$(BIN)/certstore.% : override CC := env CCACHE_DISABLE=1 $(CC)
783
$(BIN)/privkey.% : override CC := env CCACHE_DISABLE=1 $(CC)
785
# Debug message autocolourisation range
787
DBGCOL_LIST := $(BIN)/.dbgcol.list
788
ifeq ($(wildcard $(DBGCOL_LIST)),)
789
DBGCOL_OLD := <invalid>
791
DBGCOL_OLD := $(shell cat $(DBGCOL_LIST))
793
ifneq ($(DBGCOL_OLD),$(DBGCOL))
794
$(shell $(ECHO) "$(DBGCOL)" > $(DBGCOL_LIST))
797
$(DBGCOL_LIST) : $(MAKEDEPS)
799
VERYCLEANUP += $(DBGCOL_LIST)
801
DBGCOL_COLOURS := $(subst -, ,$(DBGCOL))
802
DBGCOL_MIN := $(firstword $(DBGCOL_COLOURS))
803
DBGCOL_MAX := $(lastword $(DBGCOL_COLOURS))
805
debug_DEPS += $(DBGCOL_LIST)
807
CFLAGS_debug += $(if $(DBGCOL_MIN),-DDBGCOL_MIN=$(DBGCOL_MIN))
808
CFLAGS_debug += $(if $(DBGCOL_MAX),-DDBGCOL_MAX=$(DBGCOL_MAX))
810
# We automatically generate rules for any file mentioned in AUTO_SRCS
811
# using the following set of templates. We use $(eval ...) if
812
# available, otherwise we generate separate Makefile fragments and
815
# deps_template : generate dependency list for a given source file
817
# $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
819
define deps_template_file
820
$(call deps_template_parts,$(1),$(subst .,,$(suffix $(1))),$(basename $(notdir $(1))))
823
# $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
824
# $(2) is the source type (e.g. "c")
825
# $(3) is the source base name (e.g. "rtl8139")
827
define deps_template_parts
828
@$(ECHO) " [DEPS] $(1)"
829
@$(MKDIR) -p $(BIN)/deps/$(dir $(1))
830
$(Q)$(CPP) $(CFLAGS) $(CFLAGS_$(2)) $(CFLAGS_$(3)) -DOBJECT=$(3) \
831
-Wno-error -M $(1) -MG -MP | \
832
sed 's/\.o\s*:/_DEPS +=/' > $(BIN)/deps/$(1).d
835
# rules_template : generate rules for a given source file
837
# $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
839
define rules_template
840
$(call rules_template_parts,$(1),$(subst .,,$(suffix $(1))),$(basename $(notdir $(1))))
843
# $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
844
# $(2) is the source type (e.g. "c")
845
# $(3) is the source base name (e.g. "rtl8139")
847
define rules_template_parts
848
$$(BIN)/$(3).o : $(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(3)_DEPS)
849
$$(QM)$(ECHO) " [BUILD] $$@"
851
BOBJS += $$(BIN)/$(3).o
852
$(foreach TGT,$(GENERIC_TARGETS),$(if $(RULE_$(2)_to_$(TGT)),$(NEWLINE)$(call rules_template_target,$(1),$(2),$(3),$(TGT))))
853
$$(BIN)/deps/$(1).d : $$($(3)_DEPS)
857
# $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
858
# $(2) is the source type (e.g. "c")
859
# $(3) is the source base name (e.g. "rtl8139")
860
# $(4) is the destination type (e.g. "dbg%.o")
862
define rules_template_target
863
$$(BIN)/$(3).$(4) : $(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(3)_DEPS)
864
$$(QM)$(ECHO) " [BUILD] $$@"
865
$$(RULE_$(2)_to_$(4))
866
$(TGT)_OBJS += $$(BIN)/$(3).$(4)
869
# $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
871
define rules_template_file
872
@$(ECHO) " [RULES] $(1)"
873
@$(MKDIR) -p $(BIN)/rules/$(dir $(1))
874
@$(ECHO_E) '$(subst $(NEWLINE),\n,$(call rules_template,$(1)))' \
875
> $(BIN)/rules/$(1).r
878
# Generate the dependency files
880
$(BIN)/deps/%.d : % $(MAKEDEPS)
881
$(call deps_template_file,$<)
883
# Calculate list of dependency files
885
AUTO_DEPS = $(patsubst %,$(BIN)/deps/%.d,$(AUTO_SRCS))
887
@$(ECHO) $(AUTO_DEPS)
888
VERYCLEANUP += $(BIN)/deps
890
# Include dependency files
893
ifneq ($(AUTO_DEPS),)
894
-include $(AUTO_DEPS)
898
# Generate the rules files
900
$(BIN)/rules/%.r : % $(MAKEDEPS)
901
$(call rules_template_file,$<)
903
# Calculate list of rules files
905
AUTO_RULES = $(patsubst %,$(BIN)/rules/%.r,$(AUTO_SRCS))
907
@$(ECHO) $(AUTO_RULES)
908
VERYCLEANUP += $(BIN)/rules
910
# Evaluate rules (or include rules files)
913
ifneq ($(AUTO_RULES),)
914
ifneq ($(HAVE_EVAL),)
915
$(foreach SRC,$(AUTO_SRCS),$(eval $(call rules_template,$(SRC))))
917
-include $(AUTO_RULES)
922
# Files to be parsed using parserom.pl
924
ROM_SRCS = $(foreach SRC,$(AUTO_SRCS),\
925
$(if $(findstring drivers/,$(SRC)),$(SRC)))
929
# List of files to be parsed using parserom.pl
931
ROM_SRCS_LIST := $(BIN)/.rom.list
932
ifeq ($(wildcard $(ROM_SRCS_LIST)),)
933
ROM_SRCS_OLD := <invalid>
935
ROM_SRCS_OLD := $(shell cat $(ROM_SRCS_LIST))
937
ifneq ($(ROM_SRCS_OLD),$(ROM_SRCS))
938
$(shell $(ECHO) "$(ROM_SRCS)" > $(ROM_SRCS_LIST))
941
$(ROM_SRCS_LIST) : $(MAKEDEPS)
943
VERYCLEANUP += $(ROM_SRCS_LIST)
945
# ROM definition file
947
ROMDEFS = $(BIN)/.rom.defs
948
$(ROMDEFS) : $(ROM_SRCS) $(ROM_SRCS_LIST) $(PARSEROM) $(MAKEDEPS)
949
$(QM)$(ECHO) " [PARSEROM]"
950
$(Q)$(PERL) $(PARSEROM) $(ROM_SRCS) > $@
952
VERYCLEANUP += $(ROMDEFS)
954
# Evaluate ROM definition file
961
# Device ID tables (using IDs from ROM definition file)
963
define obj_pci_id_asm
964
.section ".pci_devlist.$(1)", "a", $(ASM_TCHAR)progbits
965
.globl pci_devlist_$(1)
967
.short ( 0x$(1) & 0xffff )
970
define obj_isa_id_asm
972
OBJ_IDS_ASM = $(foreach ROM,$(ROMS_$(OBJECT)),$(call obj_$(ROM_TYPE_$(ROM))_id_asm,$(ROM)))
973
OBJ_IDS_ASM_NL = $(subst $(NEWLINE),\n,$(OBJ_IDS_ASM))
975
@$(ECHO_E) '$(OBJ_IDS_ASM_NL)'
977
BOBJS += $(patsubst %,$(BIN)/%.ids.o,$(DRIVERS))
979
# The following variables are created by the autogenerated rules
984
@$(ECHO) $(DRIVERS_$*)
991
# Generate error usage information
993
$(BIN)/%.einfo : $(BIN)/%.o
994
$(QM)$(ECHO) " [EINFO] $@"
995
$(Q)$(OBJCOPY) -O binary -j .einfo --set-section-flags .einfo=alloc \
998
EINFOS := $(patsubst $(BIN)/%.o,$(BIN)/%.einfo,$(BOBJS))
999
$(BIN)/errors : $(EINFOS) $(EINFO)
1000
$(QM)$(ECHO) " [EINFO] $@"
1001
$(Q)$(EINFO) $(EINFOS) | sort > $@
1002
CLEANUP += $(BIN)/errors # Doesn't match the $(BIN)/*.* pattern
1004
# Generate the NIC file from the parsed source files. The NIC file is
1005
# only for rom-o-matic.
1007
$(BIN)/NIC : $(AUTO_DEPS)
1008
@$(ECHO) '# This is an automatically generated file, do not edit' > $@
1009
@$(ECHO) '# It does not affect anything in the build, ' \
1010
'it is only for rom-o-matic' >> $@
1012
@perl -ne 'chomp; print "$$1\n" if /\# NIC\t(.*)$$/' $^ >> $@
1013
CLEANUP += $(BIN)/NIC # Doesn't match the $(BIN)/*.* pattern
1015
# Select drivers to be included in the all-drivers build
1017
DRIVERS_ipxe = $(DRIVERS_net) $(DRIVERS_infiniband) \
1018
$(DRIVERS_xen) $(DRIVERS_hyperv)
1020
# Analyse a target name (e.g. "bin/dfe538--prism2_pci.rom.tmp") and
1021
# derive the variables:
1023
# TGT_ELEMENTS : the elements of the target (e.g. "dfe538 prism2_pci")
1024
# TGT_PREFIX : the prefix type (e.g. "pcirom")
1025
# TGT_DRIVERS : the driver for each element (e.g. "rtl8139 prism2_pci")
1026
# TGT_ROM_NAME : the ROM name (e.g. "dfe538")
1028
TGT_ELEMENTS = $(subst --, ,$(firstword $(subst ., ,$(notdir $@))))
1029
TGT_ROM_NAME = $(firstword $(TGT_ELEMENTS))
1030
TGT_DRIVERS = $(strip $(foreach TGT_ELEMENT,$(TGT_ELEMENTS), \
1031
$(if $(DRIVERS_$(TGT_ELEMENT)), \
1032
$(DRIVERS_$(TGT_ELEMENT)), \
1033
$(firstword $(DRIVER_$(TGT_ELEMENT)) \
1035
TGT_PREFIX_NAME = $(word 2,$(subst ., ,$(notdir $@)))
1036
TGT_PREFIX = $(strip $(if $(filter rom,$(TGT_PREFIX_NAME)), \
1037
$(ROM_TYPE_$(TGT_ROM_NAME))rom, \
1038
$(TGT_PREFIX_NAME)))
1040
# Look up ROM IDs for the current target
1041
# (e.g. "bin/dfe538--prism2_pci.rom.tmp") and derive the variables:
1043
# TGT_PCI_VENDOR : the PCI vendor ID (e.g. "0x1186")
1044
# TGT_PCI_DEVICE : the PCI device ID (e.g. "0x1300")
1046
TGT_PCI_VENDOR = $(PCI_VENDOR_$(TGT_ROM_NAME))
1047
TGT_PCI_DEVICE = $(PCI_DEVICE_$(TGT_ROM_NAME))
1049
# Calculate link-time options for the current target
1050
# (e.g. "bin/dfe538--prism2_pci.rom.tmp") and derive the variables:
1052
# TGT_LD_DRIVERS : symbols to require in order to drag in the relevant drivers
1053
# (e.g. "obj_rtl8139 obj_prism2_pci")
1054
# TGT_LD_IDS : symbols to define in order to fill in ID structures in the
1055
# ROM header (e.g."pci_vendor_id=0x1186 pci_device_id=0x1300")
1057
TGT_LD_DRIVERS = $(subst -,_,$(patsubst %,obj_%,$(TGT_DRIVERS)))
1058
TGT_LD_IDS = pci_vendor_id=$(firstword $(TGT_PCI_VENDOR) 0) \
1059
pci_device_id=$(firstword $(TGT_PCI_DEVICE) 0)
1060
TGT_LD_DEVLIST = $(foreach ELEM,$(TGT_ELEMENTS),$(if $(PCI_VENDOR_$(ELEM)),\
1061
pci_devlist_$(patsubst 0x%,%,$(PCI_VENDOR_$(ELEM)))$(patsubst 0x%,%,$(PCI_DEVICE_$(ELEM)))))
1062
TGT_LD_ENTRY = _$(TGT_PREFIX)_start
1064
# Calculate linker flags based on link-time options for the current
1065
# target type (e.g. "bin/dfe538--prism2_pci.rom.tmp") and derive the
1068
# TGT_LD_FLAGS : target-specific flags to pass to linker (e.g.
1069
# "-u obj_zpciprefix -u obj_rtl8139 -u obj_prism2_pci
1070
# --defsym pci_vendor=0x1186 --defsym pci_device=0x1300")
1072
TGT_LD_FLAGS = $(foreach SYM,$(TGT_LD_ENTRY) $(TGT_LD_DRIVERS) \
1073
$(TGT_LD_DEVLIST) obj_config obj_config_$(PLATFORM),\
1074
-u $(SYM) --defsym check_$(SYM)=$(SYM) ) \
1075
$(patsubst %,--defsym %,$(TGT_LD_IDS)) \
1078
# Calculate list of debugging versions of objects to be included in
1081
DEBUG_LIST = $(subst $(COMMA), ,$(DEBUG))
1082
DEBUG_MAX = $(firstword $(word 2,$(subst :, ,$(1))) 1)
1083
DEBUG_DFLT = $(if $(word 3,$(subst :, ,$(1))),.$(word 3,$(subst :, ,$(1))))
1084
DEBUG_LEVEL = $(call DEBUG_MAX,$(1))$(call DEBUG_DFLT,$(1))
1085
DEBUG_BASE = $(firstword $(subst :, ,$(1))).dbg$(call DEBUG_LEVEL,$(1))
1086
DEBUG_OBJ = $(BIN)/$(call DEBUG_BASE,$(1)).o
1087
DEBUG_ORIG_OBJ = $(BIN)/$(firstword $(subst :, ,$(1))).o
1088
DEBUG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_OBJ,$(D)))
1089
DEBUG_ORIG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_ORIG_OBJ,$(D)))
1090
BLIB_OBJS = $(DEBUG_OBJS) $(filter-out $(DEBUG_ORIG_OBJS),$(BOBJS))
1092
# Print out all derived information for a given target.
1095
@$(ECHO) 'Elements : $(TGT_ELEMENTS)'
1096
@$(ECHO) 'Prefix : $(TGT_PREFIX)'
1097
@$(ECHO) 'Drivers : $(TGT_DRIVERS)'
1098
@$(ECHO) 'ROM name : $(TGT_ROM_NAME)'
1100
@$(ECHO) 'PCI vendor : $(TGT_PCI_VENDOR)'
1101
@$(ECHO) 'PCI device : $(TGT_PCI_DEVICE)'
1103
@$(ECHO) 'LD driver symbols : $(TGT_LD_DRIVERS)'
1104
@$(ECHO) 'LD ID symbols : $(TGT_LD_IDS)'
1105
@$(ECHO) 'LD devlist symbols : $(TGT_LD_DEVLIST)'
1106
@$(ECHO) 'LD entry point : $(TGT_LD_ENTRY)'
1108
@$(ECHO) 'LD target flags : $(TGT_LD_FLAGS)'
1110
@$(ECHO) 'Debugging objects : $(DEBUG_OBJS)'
1111
@$(ECHO) 'Replaced objects : $(DEBUG_ORIG_OBJS)'
1113
# List of objects included in the last build of blib. This is needed
1114
# in order to correctly rebuild blib whenever the list of objects
1117
BLIB_LIST := $(BIN)/.blib.list
1118
ifeq ($(wildcard $(BLIB_LIST)),)
1119
BLIB_OBJS_OLD := <invalid>
1121
BLIB_OBJS_OLD := $(shell cat $(BLIB_LIST))
1123
ifneq ($(BLIB_OBJS_OLD),$(BLIB_OBJS))
1124
$(shell $(ECHO) "$(BLIB_OBJS)" > $(BLIB_LIST))
1127
$(BLIB_LIST) : $(MAKEDEPS)
1129
VERYCLEANUP += $(BLIB_LIST)
1131
# Library of all objects
1133
BLIB = $(BIN)/blib.a
1134
$(BLIB) : $(BLIB_OBJS) $(BLIB_LIST) $(MAKEDEPS)
1136
$(QM)$(ECHO) " [AR] $@"
1137
$(Q)$(AR) r $@ $(sort $(BLIB_OBJS))
1141
# Command to generate build ID. Must be unique for each $(BIN)/%.tmp,
1142
# even within the same build run.
1144
BUILD_ID_CMD := perl -e 'printf "0x%08x", int ( rand ( 0xffffffff ) );'
1148
BUILD_TIMESTAMP := $(shell date +%s)
1152
GIT_INDEX := $(if $(GITVERSION),$(if $(wildcard ../.git/index),../.git/index))
1153
$(BIN)/version.%.o : core/version.c $(MAKEDEPS) $(GIT_INDEX)
1154
$(QM)$(ECHO) " [VERSION] $@"
1155
$(Q)$(COMPILE_c) -DBUILD_NAME="\"$*\"" \
1156
-DVERSION_MAJOR=$(VERSION_MAJOR) \
1157
-DVERSION_MINOR=$(VERSION_MINOR) \
1158
-DVERSION_PATCH=$(VERSION_PATCH) \
1159
-DVERSION="\"$(VERSION)\"" \
1162
# Build an intermediate object file from the objects required for the
1165
$(BIN)/%.tmp : $(BIN)/version.%.o $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
1166
$(QM)$(ECHO) " [LD] $@"
1167
$(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $< $(BLIB) -o $@ \
1168
--defsym _build_id=`$(BUILD_ID_CMD)` \
1169
--defsym _build_timestamp=$(BUILD_TIMESTAMP) \
1170
-Map $(BIN)/$*.tmp.map
1171
$(Q)$(OBJDUMP) -ht $@ | $(PERL) $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
1173
# Keep intermediate object file (useful for debugging)
1174
.PRECIOUS : $(BIN)/%.tmp
1176
# Show a linker map for the specified target
1178
$(BIN)/%.map : $(BIN)/%.tmp
1179
@less $(BIN)/$*.tmp.map
1181
# Get objects list for the specified target
1184
$(sort $(foreach OBJ_SYMBOL,\
1185
$(filter obj_%,$(shell $(NM) $(1) | cut -d" " -f3)),\
1186
$(patsubst obj_%,%,$(OBJ_SYMBOL))))
1188
$(BIN)/%.objs : $(BIN)/%.tmp
1189
$(Q)$(ECHO) $(call objs_list,$<)
1190
$(BIN)/%.sizes : $(BIN)/%.tmp
1191
$(Q)$(SIZE) -t $(foreach OBJ,$(call objs_list,$<),$(wildcard $(BIN)/$(subst _,?,$(OBJ)).o)) | \
1194
# Get dependency list for the specified target
1197
$(sort $(foreach OBJ,$(call objs_list,$(1)),$($(OBJ)_DEPS)))
1199
$(BIN)/%.deps : $(BIN)/%.tmp
1200
$(Q)$(ECHO) $(call deps_list,$<)
1202
# Get unneeded source files for the specified target
1205
$(sort $(filter-out $(call deps_list,$(1)),\
1206
$(foreach BOBJ,$(BOBJS),\
1207
$($(basename $(notdir $(BOBJ)))_DEPS))))
1209
$(BIN)/%.nodeps : $(BIN)/%.tmp
1210
$(Q)$(ECHO) $(call nodeps_list,$<)
1212
# Get licensing verdict for the specified target
1214
define licensable_deps_list
1215
$(filter-out config/local/%.h,\
1216
$(filter-out $(BIN)/.%.list,\
1217
$(call deps_list,$(1))))
1219
define unlicensed_deps_list
1220
$(shell grep -L FILE_LICENCE $(call licensable_deps_list,$(1)))
1223
$(sort $(foreach LICENCE,\
1224
$(filter __licence__%,$(shell $(NM) $(1) | cut -d" " -f3)),\
1225
$(word 2,$(subst __, ,$(LICENCE)))))
1227
$(BIN)/%.licence_list : $(BIN)/%.tmp
1228
$(Q)$(ECHO) $(call licence_list,$<)
1229
$(BIN)/%.licence : $(BIN)/%.tmp
1230
$(QM)$(ECHO) " [LICENCE] $@"
1231
$(Q)$(if $(strip $(call unlicensed_deps_list,$<)),\
1232
echo -n "Unable to determine licence because the following " ;\
1233
echo "files are missing a licence declaration:" ;\
1234
echo $(call unlicensed_deps_list,$<);\
1236
$(PERL) $(LICENCE) $(call licence_list,$<))
1238
# Extract compression information from intermediate object file
1240
$(BIN)/%.zinfo : $(BIN)/%.tmp
1241
$(QM)$(ECHO) " [ZINFO] $@"
1242
$(Q)$(OBJCOPY) -O binary -j .zinfo $< $@
1244
# Build raw binary file from intermediate object file
1246
$(BIN)/%.bin : $(BIN)/%.tmp
1247
$(QM)$(ECHO) " [BIN] $@"
1248
$(Q)$(OBJCOPY) -O binary -R .zinfo $< $@
1250
# Compress raw binary file
1252
$(BIN)/%.zbin : $(BIN)/%.bin $(BIN)/%.zinfo $(ZBIN)
1253
$(QM)$(ECHO) " [ZBIN] $@"
1254
$(Q)$(ZBIN) $(BIN)/$*.bin $(BIN)/$*.zinfo > $@
1256
# Rules for each media format. These are generated and placed in an
1257
# external Makefile fragment. We could do this via $(eval ...), but
1258
# that would require make >= 3.80.
1260
# Note that there's an alternative way to generate most .rom images:
1261
# they can be copied from their 'master' ROM image using cp and
1262
# reprocessed with makerom to add the PCI IDs and ident string. The
1263
# relevant rule would look something like:
1265
# $(BIN)/dfe538%rom : $(BIN)/rtl8139%rom
1269
# You can derive the ROM/driver relationships using the variables
1270
# DRIVER_<rom> and/or ROMS_<driver>.
1272
# We don't currently do this, because (a) it would require generating
1273
# yet more Makefile fragments (since you need a rule for each ROM in
1274
# ROMS), and (b) the linker is so fast that it probably wouldn't make
1275
# much difference to the overall build time.
1277
# Add NON_AUTO_MEDIA to the media list, so that they show up in the
1280
MEDIA += $(NON_AUTO_MEDIA)
1285
AUTO_MEDIA = $(filter-out $(NON_AUTO_MEDIA),$(MEDIA))
1287
@$(ECHO) $(AUTO_MEDIA)
1289
# media_template : create media rules
1291
# $(1) is the media name (e.g. "rom")
1293
define media_template
1294
$(if $(filter $(1),$(AUTO_MEDIA)),$(call auto_media_template,$(1)))
1295
LIST_$(1) := $$(if $$(LIST_NAME_$(1)),$$($$(LIST_NAME_$(1))),$$(DRIVERS))
1296
ALL_$(1) = $$(foreach ITEM,$$(LIST_$(1)),$$(BIN)/$$(ITEM).$(1))
1297
$$(BIN)/all$(1)s : $$(ALL_$(1))
1298
$$(BIN)/allall : $$(BIN)/all$(1)s
1299
all$(1)s : $$(BIN)/all$(1)s
1300
allall : $$(BIN)/allall
1303
# $(1) is the media name (e.g. "rom")
1305
define auto_media_template
1306
$$(BIN)/%.$(1) : $$(BIN)/%.$(1).zbin
1307
$$(QM)echo " [FINISH] $$@"
1309
$$(Q)$$(if $$(PAD_$(1)),$$(PAD_$(1)) $$@)
1310
$$(Q)$$(if $$(FINALISE_$(1)),$$(FINALISE_$(1)) $$@)
1313
# $(1) is the media name (e.g. "rom")
1315
define media_template_file
1316
@$(ECHO) " [MEDIARULES] $(1)"
1317
@$(MKDIR) -p $(BIN)/rules/$(dir $(1))
1318
@$(ECHO_E) '$(subst $(NEWLINE),\n,$(call media_template,$(1)))' \
1319
> $(BIN)/rules/$(1).media.r
1322
# Generate media rules files
1324
$(BIN)/rules/%.media.r : $(MAKEDEPS)
1325
$(call media_template_file,$*)
1327
# Calculate list of media rules files
1329
MEDIA_RULES = $(patsubst %,$(BIN)/rules/%.media.r,$(MEDIA))
1331
@$(ECHO) $(MEDIA_RULES)
1333
# Evaluate media rules (or include media rules files)
1336
ifneq ($(MEDIA_RULES),)
1337
ifneq ($(HAVE_EVAL),)
1338
$(foreach MEDIUM,$(MEDIA),$(eval $(call media_template,$(MEDIUM))))
1340
-include $(MEDIA_RULES)
1347
$(BIN)/etherboot.% : $(BIN)/ipxe.%
1348
ln -sf $(notdir $<) $@
1350
endif # defined(BIN)
1352
###############################################################################
1354
# The compression utilities
1357
ZBIN_LDFLAGS := -llzma
1359
$(ZBIN) : util/zbin.c $(MAKEDEPS)
1360
$(QM)$(ECHO) " [HOSTCC] $@"
1361
$(Q)$(HOST_CC) $(HOST_CFLAGS) $< $(ZBIN_LDFLAGS) -o $@
1364
###############################################################################
1366
# The EFI image converter
1369
$(ELF2EFI32) : util/elf2efi.c $(MAKEDEPS)
1370
$(QM)$(ECHO) " [HOSTCC] $@"
1371
$(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -DEFI_TARGET32 $< -o $@
1372
CLEANUP += $(ELF2EFI32)
1374
$(ELF2EFI64) : util/elf2efi.c $(MAKEDEPS)
1375
$(QM)$(ECHO) " [HOSTCC] $@"
1376
$(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -DEFI_TARGET64 $< -o $@
1377
CLEANUP += $(ELF2EFI64)
1379
$(EFIROM) : util/efirom.c $(MAKEDEPS)
1380
$(QM)$(ECHO) " [HOSTCC] $@"
1381
$(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
1382
CLEANUP += $(EFIROM)
1384
$(EFIFATBIN) : util/efifatbin.c $(MAKEDEPS)
1385
$(QM)$(ECHO) " [HOSTCC] $@"
1386
$(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
1387
CLEANUP += $(EFIFATBIN)
1389
###############################################################################
1391
# The ICC fixup utility
1393
$(ICCFIX) : util/iccfix.c $(MAKEDEPS)
1394
$(QM)$(ECHO) " [HOSTCC] $@"
1395
$(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
1396
CLEANUP += $(ICCFIX)
1398
###############################################################################
1400
# The error usage information utility
1402
$(EINFO) : util/einfo.c $(MAKEDEPS)
1403
$(QM)$(ECHO) " [HOSTCC] $@"
1404
$(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
1407
###############################################################################
1411
CONFIG_HEADERS := $(patsubst config/%,%,$(wildcard config/*.h))
1412
CONFIG_LOCAL_HEADERS := $(foreach HEADER,$(CONFIG_HEADERS),\
1413
config/local/$(HEADER))
1415
$(CONFIG_LOCAL_HEADERS) :
1418
.PRECIOUS : $(CONFIG_LOCAL_HEADERS)
1422
CONFIG_LOCAL_NAMED_HEADERS := $(foreach HEADER,$(CONFIG_HEADERS),\
1423
config/local/$(CONFIG)/$(HEADER))
1425
$(CONFIG_LOCAL_NAMED_HEADERS) :
1426
$(Q)$(MKDIR) -p $(dir $@)
1429
.PRECIOUS : $(CONFIG_LOCAL_NAMED_HEADERS)
1433
###############################################################################
1435
# Build the TAGS file(s) for emacs
1438
ctags -e -R -f $@ --exclude=bin
1442
###############################################################################
1444
# Force rebuild for any given target
1450
###############################################################################
1452
# Symbol table checks
1457
SYMTAB = $(BIN)/symtab
1459
$(OBJDUMP) -w -t $< > $@
1461
CLEANUP += $(BIN)/symtab
1463
symcheck : $(SYMTAB)
1464
$(PERL) $(SYMCHECK) $<
1466
endif # defined(BIN)
1468
###############################################################################
1470
# Build bochs symbol table
1475
$(BIN)/%.bxs : $(BIN)/%.tmp
1476
$(NM) $< | cut -d" " -f1,3 > $@
1478
endif # defined(BIN)
1480
###############################################################################
1487
$(BIN)/doxygen.cfg : doxygen.cfg $(MAKEDEPS)
1488
$(Q)$(PERL) -pe 's{\@SRCDIRS\@}{$(SRCDIRS)}; ' \
1489
-e 's{\@INCDIRS\@}{$(filter-out .,$(INCDIRS))}; ' \
1490
-e 's{\@BIN\@}{$(BIN)}; ' \
1491
-e 's{\@ARCH\@}{$(ARCH)}; ' \
1494
$(BIN)/doc : $(BIN)/doxygen.cfg
1502
$(Q)$(RM) -r $(BIN)/doc
1504
VERYCLEANUP += $(BIN)/doc
1507
@[ -f $(BIN)/doc/html/index.html ] || $(MAKE) $(BIN)/doc
1508
@if [ -n "$$BROWSER" ] ; then \
1509
( $$BROWSER $(BIN)/doc/html/index.html & ) ; \
1511
$(ECHO) "Documentation index in $(BIN)/doc/html/index.html" ; \
1514
endif # defined(BIN)
1516
###############################################################################
1521
hci/keymap/keymap_%.c :
1522
$(Q)$(PERL) $(GENKEYMAP) $* > $@
1524
###############################################################################
1526
# Force deletion of incomplete targets
1531
###############################################################################
1536
ifeq ($(NUM_BINS),0)
1538
CLEANUP := $(patsubst $(BIN)/%,$(ALLBINS)/%,$(CLEANUP))
1539
VERYCLEANUP := $(patsubst $(BIN)/%,$(ALLBINS)/%,$(VERYCLEANUP))
1546
$(RM) -r $(VERYCLEANUP)