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
92 @if $(CC) -v 2>&1 | grep -is 'gcc version 2\.96' > /dev/null; then \
93 $(ECHO) 'gcc 2.96 is unsuitable for compiling Etherboot'; \
94 $(ECHO) 'Use gcc 2.95 or gcc 3.x instead'; \
97 @if [ `perl -e 'use bytes; print chr(255)' | wc -c` = 2 ]; then \
98 $(ECHO) 'Your Perl version has a Unicode handling bug'; \
99 $(ECHO) 'Execute this command before compiling Etherboot:'; \
100 $(ECHO) 'export LANG=$${LANG%.UTF-8}'; \
104 MAKEDEPS += .toolcheck
105 VERYCLEANUP += .toolcheck
107 ###############################################################################
109 # Check for various tool workarounds
112 # Make syntax does not allow use of comma or space in certain places.
113 # This ugly workaround is suggested in the manual.
117 SPACE := $(EMPTY) $(EMPTY)
119 # Check for an old version of gas (binutils 2.9.1)
121 OLDGAS := $(shell $(AS) --version | grep -q '2\.9\.1' && $(ECHO) -DGAS291)
126 # Some widespread patched versions of gcc include -fstack-protector by
127 # default, even when -ffreestanding is specified. We therefore need
128 # to disable -fstack-protector if the compiler supports it.
131 SP_TEST = $(CC) -fno-stack-protector -x c -c /dev/null \
132 -o /dev/null >/dev/null 2>&1
133 SP_FLAGS := $(shell $(SP_TEST) && $(ECHO) '-fno-stack-protector')
134 CFLAGS += $(SP_FLAGS)
137 # Some versions of gas choke on division operators, treating them as
138 # comment markers. Specifying --divide will work around this problem,
139 # but isn't available on older gas versions.
141 DIVIDE_TEST = $(AS) --divide /dev/null -o /dev/null 2>/dev/null
142 DIVIDE_FLAGS := $(shell $(DIVIDE_TEST) && $(ECHO) '--divide')
143 ASFLAGS += $(DIVIDE_FLAGS)
145 ###############################################################################
157 ###############################################################################
159 # Set BIN according to whatever was specified on the command line as
163 # Determine how many different BIN directories are mentioned in the
166 BIN_GOALS := $(filter bin/% bin-%,$(MAKECMDGOALS))
167 BIN_GOAL_BINS := $(foreach BG,$(BIN_GOALS),$(firstword $(subst /, ,$(BG))))
168 NUM_BINS := $(words $(sort $(BIN_GOAL_BINS)))
172 # No BIN directory was specified. Set BIN to "bin" as a sensible
181 # If exactly one BIN directory was specified, set BIN to match this
184 BIN := $(firstword $(BIN_GOAL_BINS))
188 # More than one BIN directory was specified. We cannot handle the
189 # latter case within a single make invocation, so set up recursive
190 # targets for each BIN directory.
192 # Leave $(BIN) undefined. This has implications for any target that
193 # depends on $(BIN); such targets should be made conditional upon the
194 # existence of $(BIN).
196 $(BIN_GOALS) : % : BIN_RECURSE
197 $(Q)$(MAKE) --no-print-directory BIN=$(firstword $(subst /, ,$@)) $@
200 endif # NUM_BINS == 1
201 endif # NUM_BINS == 0
205 # Create $(BIN) directory if it doesn't exist yet
207 ifeq ($(wildcard $(BIN)),)
208 $(shell $(MKDIR) -p $(BIN))
211 # Target to allow e.g. "make bin-efi arch"
214 @# Do nothing, silently
217 # Remove everything in $(BIN) for a "make clean"
219 CLEANUP += $(BIN)/*.* # Avoid picking up directories
223 # Determine whether or not we need to include the dependency files
225 NO_DEP_TARGETS := $(BIN) clean veryclean
226 ifeq ($(MAKECMDGOALS),)
229 ifneq ($(strip $(filter-out $(NO_DEP_TARGETS),$(MAKECMDGOALS))),)
233 ###############################################################################
235 # Select build architecture and platform based on $(BIN)
237 # BIN has the form bin[-[arch-]platform]
239 ARCHS := $(patsubst arch/%,%,$(wildcard arch/*))
240 PLATFORMS := $(patsubst config/defaults/%.h,%,\
241 $(wildcard config/defaults/*.h))
246 @$(ECHO) $(PLATFORMS)
250 # Determine architecture portion of $(BIN), if present
251 BIN_ARCH := $(strip $(foreach A,$(ARCHS),\
252 $(patsubst bin-$(A)-%,$(A),\
253 $(filter bin-$(A)-%,$(BIN)))))
255 # Determine platform portion of $(BIN), if present
257 BIN_PLATFORM := $(patsubst bin-%,%,$(filter bin-%,$(BIN)))
259 BIN_PLATFORM := $(patsubst bin-$(BIN_ARCH)-%,%,$(BIN))
262 # Determine build architecture
264 ARCH := $(firstword $(BIN_ARCH) $(DEFAULT_ARCH))
265 CFLAGS += -DARCH=$(ARCH)
270 # Determine build platform
271 DEFAULT_PLATFORM := pcbios
272 PLATFORM := $(firstword $(BIN_PLATFORM) $(DEFAULT_PLATFORM))
273 CFLAGS += -DPLATFORM=$(PLATFORM)
279 # Include architecture-specific Makefile
281 MAKEDEPS += arch/$(ARCH)/Makefile
282 include arch/$(ARCH)/Makefile
285 ###############################################################################
287 # Source file handling
289 # SRCDIRS lists all directories containing source files.
293 # SRCS lists all .c or .S files found in any SRCDIR
295 SRCS += $(wildcard $(patsubst %,%/*.c,$(SRCDIRS)))
296 SRCS += $(wildcard $(patsubst %,%/*.S,$(SRCDIRS)))
300 # AUTO_SRCS lists all files in SRCS that are not mentioned in
301 # NON_AUTO_SRCS. Files should be added to NON_AUTO_SRCS if they
302 # cannot be built using the standard build template.
304 AUTO_SRCS = $(filter-out $(NON_AUTO_SRCS),$(SRCS))
306 @$(ECHO) $(AUTO_SRCS)
308 # Just about everything else in this section depends upon having
315 CFLAGS += -I include -I arch/$(ARCH)/include -I .
319 CFLAGS += -ffreestanding
320 CFLAGS += -Wall -W -Wformat-nonliteral
323 CFLAGS += -fno-builtin
326 CFLAGS += -diag-disable 111 # Unreachable code
327 CFLAGS += -diag-disable 128 # Unreachable loop
328 CFLAGS += -diag-disable 170 # Array boundary checks
329 CFLAGS += -diag-disable 177 # Unused functions
330 CFLAGS += -diag-disable 181 # printf() format checks
331 CFLAGS += -diag-disable 188 # enum strictness
332 CFLAGS += -diag-disable 193 # Undefined preprocessor identifiers
333 CFLAGS += -diag-disable 280 # switch ( constant )
334 CFLAGS += -diag-disable 310 # K&R parameter lists
335 CFLAGS += -diag-disable 424 # Extra semicolon
336 CFLAGS += -diag-disable 589 # Declarations mid-code
337 CFLAGS += -diag-disable 593 # Unused variables
338 CFLAGS += -diag-disable 810 # Casting ints to smaller ints
339 CFLAGS += -diag-disable 981 # Sequence point violations
340 CFLAGS += -diag-disable 1292 # Ignored attributes
341 CFLAGS += -diag-disable 1338 # void pointer arithmetic
342 CFLAGS += -diag-disable 1361 # Variable-length arrays
343 CFLAGS += -diag-disable 1418 # Missing prototypes
344 CFLAGS += -diag-disable 1419 # Missing prototypes
345 CFLAGS += -diag-disable 1599 # Hidden variables
346 CFLAGS += -Wall -Wmissing-declarations
348 CFLAGS += $(EXTRA_CFLAGS)
349 ASFLAGS += $(EXTRA_ASFLAGS)
350 LDFLAGS += $(EXTRA_LDFLAGS)
352 # Inhibit -Werror if NO_WERROR is specified on make command line
354 ifneq ($(NO_WERROR),1)
356 ASFLAGS += --fatal-warnings
359 # compiler.h is needed for our linking and debugging system
361 CFLAGS += -include compiler.h
363 # CFLAGS for specific object types
366 CFLAGS_S += -DASSEMBLY
368 # Base object name of the current target
370 OBJECT = $(firstword $(subst ., ,$(@F)))
372 # CFLAGS for specific object files. You can define
373 # e.g. CFLAGS_rtl8139, and have those flags automatically used when
374 # compiling bin/rtl8139.o.
376 OBJ_CFLAGS = $(CFLAGS_$(OBJECT)) -DOBJECT=$(subst -,_,$(OBJECT))
378 @$(ECHO) $(OBJ_CFLAGS)
380 # ICC requires postprocessing objects to fix up table alignments
383 POST_O = && $(ICCFIX) $@
384 POST_O_DEPS := $(ICCFIX)
390 # Rules for specific object types.
392 COMPILE_c = $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
393 RULE_c = $(Q)$(COMPILE_c) -c $< -o $@ $(POST_O)
394 RULE_c_to_dbg%.o = $(Q)$(COMPILE_c) -Ddebug_$(OBJECT)=$* -c $< -o $@ $(POST_O)
395 RULE_c_to_c = $(Q)$(COMPILE_c) -E -c $< > $@
396 RULE_c_to_s = $(Q)$(COMPILE_c) -S -g0 -c $< -o $@
398 PREPROCESS_S = $(CPP) $(CFLAGS) $(CFLAGS_S) $(OBJ_CFLAGS)
399 ASSEMBLE_S = $(AS) $(ASFLAGS)
400 RULE_S = $(Q)$(PREPROCESS_S) $< | $(ASSEMBLE_S) -o $@
401 RULE_S_to_s = $(Q)$(PREPROCESS_S) $< > $@
403 DEBUG_TARGETS += dbg%.o c s
405 # We automatically generate rules for any file mentioned in AUTO_SRCS
406 # using the following set of templates. It would be cleaner to use
407 # $(eval ...), but this function exists only in GNU make >= 3.80.
409 # src_template : generate Makefile rules for a given source file
411 # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
412 # $(2) is the full path to the .d file (e.g. "bin/deps/drivers/net/rtl8139.d")
413 # $(3) is the source type (e.g. "c")
414 # $(4) is the source base name (e.g. "rtl8139")
418 @$(ECHO) " [DEPS] $(1)"
419 @$(MKDIR) -p $(dir $(2))
422 $(foreach OBJ,$(if $(OBJS_$(4)),$(OBJS_$(4)),$(4)), \
423 $(call obj_template,$(1),$(2),$(3),$(OBJ)))
424 @$(PARSEROM) $(1) >> $(2)
428 # obj_template : generate Makefile rules for a given resultant object
429 # of a particular source file. (We can have multiple objects per
430 # source file via the OBJS_xxx list.)
432 # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
433 # $(2) is the full path to the .d file (e.g. "bin/deps/drivers/net/rtl8139.d")
434 # $(3) is the source type (e.g. "c")
435 # $(4) is the object name (e.g. "rtl8139")
439 @$(CPP) $(CFLAGS) $(CFLAGS_$(3)) $(CFLAGS_$(4)) -DOBJECT=$(4) \
440 -Wno-error -MM $(1) -MG -MP | \
441 sed 's/\.o\s*:/_DEPS =/' >> $(2)
442 @$(ECHO_E) '\n$$(BIN)/$(4).o :' \
443 '$(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(4)_DEPS)' \
444 '\n\t$$(QM)$(ECHO) " [BUILD] $$@"' \
445 '\n\t$$(RULE_$(3))\n' \
446 '\nBOBJS += $$(BIN)/$(4).o\n' \
447 $(foreach TGT,$(DEBUG_TARGETS), \
448 $(if $(RULE_$(3)_to_$(TGT)), \
449 '\n$$(BIN)/$(4).$(TGT) :' \
450 '$(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(4)_DEPS)' \
451 '\n\t$$(QM)$(ECHO) " [BUILD] $$@"' \
452 '\n\t$$(RULE_$(3)_to_$(TGT))\n' \
453 '\n$(TGT)_OBJS += $$(BIN)/$(4).$(TGT)\n' ) ) \
454 '\n$(2) : $$($(4)_DEPS)\n' \
455 '\nTAGS : $$($(4)_DEPS)\n' \
460 # Rule to generate the Makefile rules files to be included
462 $(BIN)/deps/%.d : % $(MAKEDEPS) $(PARSEROM)
463 $(if $(filter $(AUTO_SRCS),$<),$(call src_template,$<,$@,$(subst .,,$(suffix $<)),$(basename $(notdir $<))),@$(ECHO) 'ERROR: $< is not an AUTO_SRC' ; exit 1)
465 # Calculate and include the list of Makefile rules files
467 AUTO_DEPS = $(patsubst %,$(BIN)/deps/%.d,$(AUTO_SRCS))
469 ifneq ($(AUTO_DEPS),)
470 -include $(AUTO_DEPS)
474 @$(ECHO) $(AUTO_DEPS)
475 VERYCLEANUP += $(BIN)/deps
477 # The following variables are created by the Makefile rules files
487 # List of embedded images included in the last build of embedded.o.
488 # This is needed in order to correctly rebuild embedded.o whenever the
489 # list of objects changes.
491 EMBEDDED_LIST := $(BIN)/.embedded.list
492 ifeq ($(wildcard $(EMBEDDED_LIST)),)
493 EMBEDDED_LIST_IMAGE := <invalid>
495 EMBEDDED_LIST_IMAGE := $(shell cat $(EMBEDDED_LIST))
497 ifneq ($(EMBEDDED_LIST_IMAGE),$(EMBEDDED_IMAGE))
498 $(shell $(ECHO) "$(EMBEDDED_IMAGE)" > $(EMBEDDED_LIST))
503 VERYCLEANUP += $(EMBEDDED_LIST)
505 EMBEDDED_FILES := $(subst $(COMMA), ,$(EMBEDDED_IMAGE))
506 EMBED_ALL := $(foreach i,$(call seq,1,$(words $(EMBEDDED_FILES))),\
507 EMBED ( $(i), \"$(word $(i), $(EMBEDDED_FILES))\",\
508 \"$(notdir $(word $(i),$(EMBEDDED_FILES)))\" ))
510 $(BIN)/embedded.o : $(EMBEDDED_FILES) $(EMBEDDED_LIST)
511 CFLAGS_embedded = -DEMBED_ALL="$(EMBED_ALL)"
513 # Generate the NIC file from the parsed source files. The NIC file is
514 # only for rom-o-matic.
516 $(BIN)/NIC : $(AUTO_DEPS)
517 @$(ECHO) '# This is an automatically generated file, do not edit' > $@
518 @$(ECHO) '# It does not affect anything in the build, ' \
519 'it is only for rom-o-matic' >> $@
521 @perl -ne 'chomp; print "$$1\n" if /\# NIC\t(.*)$$/' $^ >> $@
522 CLEANUP += $(BIN)/NIC # Doesn't match the $(BIN)/*.* pattern
524 # Analyse a target name (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and
525 # derive the variables:
527 # TGT_ELEMENTS : the elements of the target (e.g. "dfe538 prism2_pci")
528 # TGT_PREFIX : the prefix type (e.g. "zrom")
529 # TGT_DRIVERS : the driver for each element (e.g. "rtl8139 prism2_pci")
530 # TGT_ROM_NAME : the ROM name (e.g. "dfe538")
531 # TGT_MEDIA : the media type (e.g. "rom")
533 DRIVERS_gpxe = $(DRIVERS)
534 CARD_DRIVER = $(firstword $(DRIVER_$(1)) $(1))
535 TGT_ELEMENTS = $(subst --, ,$(firstword $(subst ., ,$(notdir $@))))
536 TGT_PREFIX = $(word 2,$(subst ., ,$(notdir $@)))
537 TGT_ROM_NAME = $(firstword $(TGT_ELEMENTS))
538 TGT_DRIVERS = $(strip $(if $(DRIVERS_$(TGT_ROM_NAME)), \
539 $(DRIVERS_$(TGT_ROM_NAME)), \
540 $(foreach TGT_ELEMENT,$(TGT_ELEMENTS), \
541 $(call CARD_DRIVER,$(TGT_ELEMENT))) ))
542 TGT_MEDIA = $(subst z,,$(TGT_PREFIX))
544 # Look up ROM IDs for the current target
545 # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
547 # TGT_PCI_VENDOR : the PCI vendor ID (e.g. "0x1186")
548 # TGT_PCI_DEVICE : the PCI device ID (e.g. "0x1300")
550 TGT_PCI_VENDOR = $(PCI_VENDOR_$(TGT_ROM_NAME))
551 TGT_PCI_DEVICE = $(PCI_DEVICE_$(TGT_ROM_NAME))
553 # Calculate link-time options for the current target
554 # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
556 # TGT_LD_DRIVERS : symbols to require in order to drag in the relevant drivers
557 # (e.g. "obj_rtl8139 obj_prism2_pci")
558 # TGT_LD_IDS : symbols to define in order to fill in ID structures in the
559 # ROM header (e.g."pci_vendor_id=0x1186 pci_device_id=0x1300")
561 TGT_LD_DRIVERS = $(subst -,_,$(patsubst %,obj_%,$(TGT_DRIVERS)))
562 TGT_LD_PREFIX = obj_$(TGT_PREFIX)prefix
563 TGT_LD_IDS = pci_vendor_id=$(firstword $(TGT_PCI_VENDOR) 0) \
564 pci_device_id=$(firstword $(TGT_PCI_DEVICE) 0)
566 # Calculate linker flags based on link-time options for the current
567 # target type (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the
570 # TGT_LD_FLAGS : target-specific flags to pass to linker (e.g.
571 # "-u obj_zpciprefix -u obj_rtl8139 -u obj_prism2_pci
572 # --defsym pci_vendor=0x1186 --defsym pci_device=0x1300")
574 TGT_LD_FLAGS = $(foreach SYM,$(TGT_LD_PREFIX) $(TGT_LD_DRIVERS) obj_config,\
575 -u $(SYM) --defsym check_$(SYM)=$(SYM) ) \
576 $(patsubst %,--defsym %,$(TGT_LD_IDS))
578 # Calculate makerom flags for the specific target
579 # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
581 # TGT_MAKEROM_FLAGS : target-specific flags for makerom (e.g.
582 # "-p 0x1186,0x1300")
584 TGT_MAKEROM_FLAGS = $(strip $(MAKEROM_FLAGS_$(TGT_ROM_NAME)) \
585 $(if $(TGT_PCI_VENDOR),$(strip -p $(TGT_PCI_VENDOR),$(TGT_PCI_DEVICE))))
587 # Calculate list of debugging versions of objects to be included in
590 DEBUG_LIST = $(subst $(COMMA), ,$(DEBUG))
591 DEBUG_OBJ_LEVEL = $(firstword $(word 2,$(subst :, ,$(1))) 1)
592 DEBUG_OBJ_BASE = $(word 1,$(subst :, ,$(1))).dbg$(call DEBUG_OBJ_LEVEL,$(1))
593 DEBUG_OBJ = $(BIN)/$(call DEBUG_OBJ_BASE,$(1)).o
594 DEBUG_ORIG_OBJ = $(BIN)/$(word 1,$(subst :, ,$(1))).o
595 DEBUG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_OBJ,$(D)))
596 DEBUG_ORIG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_ORIG_OBJ,$(D)))
597 BLIB_OBJS = $(DEBUG_OBJS) $(filter-out $(DEBUG_ORIG_OBJS),$(BOBJS))
599 # Print out all derived information for a given target.
602 @$(ECHO) 'Elements : $(TGT_ELEMENTS)'
603 @$(ECHO) 'Prefix : $(TGT_PREFIX)'
604 @$(ECHO) 'Drivers : $(TGT_DRIVERS)'
605 @$(ECHO) 'ROM name : $(TGT_ROM_NAME)'
606 @$(ECHO) 'Media : $(TGT_MEDIA)'
608 @$(ECHO) 'PCI vendor : $(TGT_PCI_VENDOR)'
609 @$(ECHO) 'PCI device : $(TGT_PCI_DEVICE)'
611 @$(ECHO) 'LD driver symbols : $(TGT_LD_DRIVERS)'
612 @$(ECHO) 'LD prefix symbols : $(TGT_LD_PREFIX)'
613 @$(ECHO) 'LD ID symbols : $(TGT_LD_IDS)'
615 @$(ECHO) 'LD target flags : $(TGT_LD_FLAGS)'
617 @$(ECHO) 'makerom target flags : $(TGT_MAKEROM_FLAGS)'
619 @$(ECHO) 'Debugging objects : $(DEBUG_OBJS)'
620 @$(ECHO) 'Replaced objects : $(DEBUG_ORIG_OBJS)'
622 # List of objects included in the last build of blib. This is needed
623 # in order to correctly rebuild blib whenever the list of objects
626 BLIB_LIST := $(BIN)/.blib.list
627 ifeq ($(wildcard $(BLIB_LIST)),)
628 BLIB_LIST_OBJS := <invalid>
630 BLIB_LIST_OBJS := $(shell cat $(BLIB_LIST))
632 ifneq ($(BLIB_LIST_OBJS),$(BLIB_OBJS))
633 $(shell $(ECHO) "$(BLIB_OBJS)" > $(BLIB_LIST))
638 VERYCLEANUP += $(BLIB_LIST)
640 # Library of all objects
643 $(BLIB) : $(BLIB_OBJS) $(BLIB_LIST) $(MAKEDEPS)
645 $(QM)$(ECHO) " [AR] $@"
646 $(Q)$(AR) r $@ $(BLIB_OBJS)
650 # Build an intermediate object file from the objects required for the
653 $(BIN)/%.tmp : $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
654 $(QM)$(ECHO) " [LD] $@"
655 $(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $(BLIB) -o $@ \
656 -Map $(BIN)/$*.tmp.map
657 $(Q)$(OBJDUMP) -ht $@ | $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
659 # Keep intermediate object file (useful for debugging)
660 .PRECIOUS : $(BIN)/%.tmp
662 # Show a linker map for the specified target
664 $(BIN)/%.map : $(BIN)/%.tmp
665 @less $(BIN)/$*.tmp.map
667 # Get objects list for the specified target
670 $(sort $(foreach OBJ_SYMBOL,\
671 $(filter obj_%,$(shell $(NM) $(1) | cut -d" " -f3)),\
672 $(patsubst obj_%,%,$(OBJ_SYMBOL))))
674 $(BIN)/%.objs : $(BIN)/%.tmp
675 $(Q)$(ECHO) $(call objs_list,$<)
677 # Get dependency list for the specified target
680 $(sort $(foreach OBJ,$(call objs_list,$(1)),$($(OBJ)_DEPS)))
682 $(BIN)/%.deps : $(BIN)/%.tmp
683 $(Q)$(ECHO) $(call deps_list,$<)
685 # Get unneeded source files for the specified target
688 $(sort $(filter-out $(call deps_list,$<),\
689 $(foreach BOBJ,$(BOBJS),\
690 $($(basename $(notdir $(BOBJ)))_DEPS))))
692 $(BIN)/%.nodeps : $(BIN)/%.tmp
693 $(Q)$(ECHO) $(call nodeps_list,$<)
695 # Extract compression information from intermediate object file
697 $(BIN)/%.zinfo : $(BIN)/%.tmp
698 $(QM)$(ECHO) " [ZINFO] $@"
699 $(Q)$(OBJCOPY) -O binary -j .zinfo $< $@
701 # Build raw binary file from intermediate object file
703 $(BIN)/%.bin : $(BIN)/%.tmp
704 $(QM)$(ECHO) " [BIN] $@"
705 $(Q)$(OBJCOPY) -O binary -R .zinfo $< $@
707 # Compress raw binary file
709 $(BIN)/%.zbin : $(BIN)/%.bin $(BIN)/%.zinfo $(ZBIN)
710 $(QM)$(ECHO) " [ZBIN] $@"
711 $(Q)$(ZBIN) $(BIN)/$*.bin $(BIN)/$*.zinfo > $@
713 # Rules for each media format. These are generated and placed in an
714 # external Makefile fragment. We could do this via $(eval ...), but
715 # that would require make >= 3.80.
717 # Note that there's an alternative way to generate most .rom images:
718 # they can be copied from their 'master' ROM image using cp and
719 # reprocessed with makerom to add the PCI IDs and ident string. The
720 # relevant rule would look something like:
722 # $(BIN)/dfe538%rom : $(BIN)/rtl8139%rom
726 # You can derive the ROM/driver relationships using the variables
727 # DRIVER_<rom> and/or ROMS_<driver>.
729 # We don't currently do this, because (a) it would require generating
730 # yet more Makefile fragments (since you need a rule for each ROM in
731 # ROMS), and (b) the linker is so fast that it probably wouldn't make
732 # much difference to the overall build time.
737 AUTO_MEDIA = $(filter-out $(NON_AUTO_MEDIA),$(MEDIA))
739 @$(ECHO) $(AUTO_MEDIA)
741 # media_template : create Makefile rules for specified media
743 # $(1) is the media name (e.g. "rom")
744 # $(2) is the full path to the .d file (e.g. "bin/deps/rom.media.d")
746 define media_template
748 @$(ECHO) " [MEDIADEPS] $(1)"
749 @$(MKDIR) -p $(dir $(2))
752 @$(ECHO_E) '$$(BIN)/%.$(1) : $$(BIN)/%.$(1).zbin' \
753 '\n\t$$(QM)$(ECHO) " [FINISH] $$@"' \
754 '\n\t$$(Q)$$(CP) $$< $$@' \
755 '\n\t$$(Q)$$(PAD_$(1))' \
756 '\n\t$$(Q)$$(FINALISE_$(1))' \
761 # Rule to generate the Makefile rules to be included
763 $(BIN)/deps/%.media.d : $(MAKEDEPS)
764 $(if $(filter $(AUTO_MEDIA),$*), \
765 $(call media_template,$*,$@), \
766 @$(ECHO) 'ERROR: $* is not an AUTO_MEDIA' ; exit 1)
768 # Calculate and include the list of Makefile rules files
770 MEDIA_DEPS = $(patsubst %,$(BIN)/deps/%.media.d,$(AUTO_MEDIA))
772 @$(ECHO) $(MEDIA_DEPS)
774 ifneq ($(MEDIA_DEPS),)
775 -include $(MEDIA_DEPS)
779 # Wrap up binary blobs (for embedded images)
781 $(BIN)/%.o : payload/%.img
782 $(QM)echo " [WRAP] $@"
783 $(Q)$(LD) -b binary -r -o $@ $< --undefined obj_payload \
786 BOBJS += $(patsubst payload/%.img,$(BIN)/%.o,$(wildcard payload/*.img))
788 # The "allXXXs" targets for each suffix
790 allall: allroms allzroms allpxes allisos alldsks
791 allroms allzroms : all%s : $(foreach ROM,$(ROMS),$(BIN)/$(ROM).%)
792 allpxes allisos alldsks : all%s : $(foreach DRIVER,$(DRIVERS),$(BIN)/$(DRIVER).%)
796 $(BIN)/etherboot.% : $(BIN)/gpxe.%
797 ln -sf $(notdir $<) $@
801 ###############################################################################
803 # Rules for finalising files. TGT_MAKEROM_FLAGS is defined as part of
804 # the automatic build system and varies by target; it includes the
805 # "-p 0x1234,0x5678" string to set the PCI IDs.
807 FINALISE_rom = $(MAKEROM) $(MAKEROM_FLAGS) $(TGT_MAKEROM_FLAGS) \
810 # Some ROMs require specific flags to be passed to makerom.pl
812 MAKEROM_FLAGS_3c503 = -3
814 ###############################################################################
816 # The compression utilities
818 $(NRV2B) : util/nrv2b.c $(MAKEDEPS)
819 $(QM)$(ECHO) " [HOSTCC] $@"
820 $(Q)$(HOST_CC) -O2 -DENCODE -DDECODE -DMAIN -DVERBOSE -DNDEBUG \
821 -DBITSIZE=32 -DENDIAN=0 -o $@ $<
824 $(ZBIN) : util/zbin.c util/nrv2b.c $(MAKEDEPS)
825 $(QM)$(ECHO) " [HOSTCC] $@"
826 $(Q)$(HOST_CC) -O2 -o $@ $<
829 ###############################################################################
831 # The EFI image converter
833 ELF2EFI_CFLAGS := -I$(BINUTILS_DIR)/include -I$(BFD_DIR)/include \
834 -idirafter include -L$(BINUTILS_DIR)/lib -L$(BFD_DIR)/lib \
837 $(ELF2EFI32) : util/elf2efi.c $(MAKEDEPS)
838 $(QM)$(ECHO) " [HOSTCC] $@"
839 $(Q)$(HOST_CC) $(ELF2EFI_CFLAGS) -DMDE_CPU_IA32 -O2 -o $@ $<
840 CLEANUP += $(ELF2EFI32)
842 $(ELF2EFI64) : util/elf2efi.c $(MAKEDEPS)
843 $(QM)$(ECHO) " [HOSTCC] $@"
844 $(Q)$(HOST_CC) $(ELF2EFI_CFLAGS) -DMDE_CPU_X64 -O2 -o $@ $<
845 CLEANUP += $(ELF2EFI64)
847 $(EFIROM) : util/efirom.c $(MAKEDEPS)
848 $(QM)$(ECHO) " [HOSTCC] $@"
849 $(Q)$(HOST_CC) -idirafter include -O2 -o $@ $<
852 ###############################################################################
854 # The ICC fixup utility
856 $(ICCFIX) : util/iccfix.c $(MAKEDEPS)
857 $(QM)$(ECHO) " [HOSTCC] $@"
858 $(Q)$(HOST_CC) -idirafter include -O2 -o $@ $<
861 ###############################################################################
863 # Auto-incrementing build serial number. Append "bs" to your list of
864 # build targets to get a serial number printed at the end of the
865 # build. Enable -DBUILD_SERIAL in order to see it when the code runs.
867 BUILDSERIAL_H = config/.buildserial.h
868 BUILDSERIAL_NOW = config/.buildserial.now
869 BUILDSERIAL_NEXT = config/.buildserial.next
871 $(BUILDSERIAL_NOW) $(BUILDSERIAL_NEXT) :
874 $(BUILDSERIAL_H) : $(BUILDSERIAL_NOW) $(BUILDSERIAL_NEXT)
875 $(ECHO) '#define BUILD_SERIAL_NUM $(shell cat $<)' > $@
877 ifeq ($(filter bs,$(MAKECMDGOALS)),bs)
878 $(shell diff -q $(BUILDSERIAL_NOW) $(BUILDSERIAL_NEXT) > /dev/null || \
879 cp -f $(BUILDSERIAL_NEXT) $(BUILDSERIAL_NOW))
882 bs : $(BUILDSERIAL_NOW)
883 @$(ECHO) $$(( $(shell cat $<) + 1 )) > $(BUILDSERIAL_NEXT)
884 @$(ECHO) "Build serial number is $(shell cat $<)"
886 ###############################################################################
888 # Build the TAGS file(s) for emacs
891 ctags -e -R -f $@ --exclude=bin
895 ###############################################################################
897 # Force rebuild for any given target
903 ###############################################################################
905 # Symbol table checks
910 SYMTAB = $(BIN)/symtab
912 $(OBJDUMP) -w -t $< > $@
914 CLEANUP += $(BIN)/symtab
921 ###############################################################################
923 # Build bochs symbol table
928 $(BIN)/%.bxs : $(BIN)/%.tmp
929 $(NM) $< | cut -d" " -f1,3 > $@
933 ###############################################################################
940 $(BIN)/doxygen.cfg : doxygen.cfg $(MAKEDEPS)
941 $(PERL) -pe 's{\@SRCDIRS\@}{$(SRCDIRS)}; ' \
942 -e 's{\@BIN\@}{$(BIN)}; ' \
943 -e 's{\@ARCH\@}{$(ARCH)}; ' \
946 $(BIN)/doc : $(BIN)/doxygen.cfg
951 VERYCLEANUP += $(BIN)/doc
956 @[ -f $(BIN)/doc/html/index.html ] || $(MAKE) $(BIN)/doc
957 @if [ -n "$$BROWSER" ] ; then \
958 ( $$BROWSER $(BIN)/doc/html/index.html & ) ; \
960 $(ECHO) "Documentation index in $(BIN)/doc/html/index.html" ; \
965 ###############################################################################
973 $(RM) -r $(VERYCLEANUP)