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 # Check for tools that can cause failed builds
60 @if $(CC) -v 2>&1 | grep -is 'gcc version 2\.96' > /dev/null; then \
61 $(ECHO) 'gcc 2.96 is unsuitable for compiling Etherboot'; \
62 $(ECHO) 'Use gcc 2.95 or gcc 3.x instead'; \
65 @if [ `perl -e 'use bytes; print chr(255)' | wc -c` = 2 ]; then \
66 $(ECHO) 'Your Perl version has a Unicode handling bug'; \
67 $(ECHO) 'Execute this command before compiling Etherboot:'; \
68 $(ECHO) 'export LANG=$${LANG%.UTF-8}'; \
72 MAKEDEPS += .toolcheck
73 VERYCLEANUP += .toolcheck
75 ###############################################################################
77 # Check for various tool workarounds
80 # Check for an old version of gas (binutils 2.9.1)
82 OLDGAS := $(shell $(AS) --version | grep -q '2\.9\.1' && $(ECHO) -DGAS291)
87 # Some widespread patched versions of gcc include -fstack-protector by
88 # default, even when -ffreestanding is specified. We therefore need
89 # to disable -fstack-protector if the compiler supports it.
91 SP_TEST = $(CC) -fno-stack-protector -x c -c /dev/null \
92 -o /dev/null >/dev/null 2>&1
93 SP_FLAGS := $(shell $(SP_TEST) && $(ECHO) '-fno-stack-protector')
96 ###############################################################################
108 ###############################################################################
110 # Set BIN according to whatever was specified on the command line as
114 # Determine how many different BIN directories are mentioned in the
117 BIN_GOALS := $(filter bin/% bin-%,$(MAKECMDGOALS))
118 BIN_GOAL_BINS := $(foreach BG,$(BIN_GOALS),$(firstword $(subst /, ,$(BG))))
119 NUM_BINS := $(words $(sort $(BIN_GOAL_BINS)))
123 # No BIN directory was specified. Set BIN to "bin" as a sensible
132 # If exactly one BIN directory was specified, set BIN to match this
135 BIN := $(firstword $(BIN_GOAL_BINS))
139 # More than one BIN directory was specified. We cannot handle the
140 # latter case within a single make invocation, so set up recursive
141 # targets for each BIN directory.
143 # Leave $(BIN) undefined. This has implications for any target that
144 # depends on $(BIN); such targets should be made conditional upon the
145 # existence of $(BIN).
147 $(BIN_GOALS) : % : BIN_RECURSE
148 $(Q)$(MAKE) --no-print-directory BIN=$(firstword $(subst /, ,$@)) $@
151 endif # NUM_BINS == 1
152 endif # NUM_BINS == 0
156 # Create $(BIN) directory if it doesn't exist yet
158 ifeq ($(wildcard $(BIN)),)
159 $(shell $(MKDIR) -p $(BIN))
162 # Target to allow e.g. "make bin-efi arch"
165 @# Do nothing, silently
168 # Remove everything in $(BIN) for a "make clean"
170 CLEANUP += $(BIN)/*.* # Avoid picking up directories
174 # Determine whether or not we need to include the dependency files
176 NO_DEP_TARGETS := $(BIN) clean veryclean
177 ifeq ($(MAKECMDGOALS),)
180 ifneq ($(strip $(filter-out $(NO_DEP_TARGETS),$(MAKECMDGOALS))),)
184 ###############################################################################
186 # Select build architecture and platform based on $(BIN)
188 # BIN has the form bin[-[arch-]platform]
190 ARCHS := $(patsubst arch/%,%,$(wildcard arch/*))
191 PLATFORMS := $(patsubst config/defaults/%.h,%,\
192 $(wildcard config/defaults/*.h))
197 @$(ECHO) $(PLATFORMS)
201 # Determine architecture portion of $(BIN), if present
202 BIN_ARCH := $(strip $(foreach A,$(ARCHS),\
203 $(patsubst bin-$(A)-%,$(A),\
204 $(filter bin-$(A)-%,$(BIN)))))
206 # Determine platform portion of $(BIN), if present
208 BIN_PLATFORM := $(patsubst bin-%,%,$(filter bin-%,$(BIN)))
210 BIN_PLATFORM := $(patsubst bin-$(BIN_ARCH)-%,%,$(BIN))
213 # Determine build architecture
215 ARCH := $(firstword $(BIN_ARCH) $(DEFAULT_ARCH))
216 CFLAGS += -DARCH=$(ARCH)
221 # Determine build platform
222 DEFAULT_PLATFORM := pcbios
223 PLATFORM := $(firstword $(BIN_PLATFORM) $(DEFAULT_PLATFORM))
224 CFLAGS += -DPLATFORM=$(PLATFORM)
230 # Include architecture-specific Makefile
232 MAKEDEPS += arch/$(ARCH)/Makefile
233 include arch/$(ARCH)/Makefile
236 ###############################################################################
238 # Source file handling
240 # SRCDIRS lists all directories containing source files.
244 # SRCS lists all .c or .S files found in any SRCDIR
246 SRCS += $(wildcard $(patsubst %,%/*.c,$(SRCDIRS)))
247 SRCS += $(wildcard $(patsubst %,%/*.S,$(SRCDIRS)))
251 # AUTO_SRCS lists all files in SRCS that are not mentioned in
252 # NON_AUTO_SRCS. Files should be added to NON_AUTO_SRCS if they
253 # cannot be built using the standard build template.
255 AUTO_SRCS = $(filter-out $(NON_AUTO_SRCS),$(SRCS))
257 @$(ECHO) $(AUTO_SRCS)
259 # Just about everything else in this section depends upon having
266 CFLAGS += -I include -I arch/$(ARCH)/include -I .
267 CFLAGS += -Os -ffreestanding
268 CFLAGS += -Wall -W -Wformat-nonliteral
270 CFLAGS += $(EXTRA_CFLAGS)
271 ASFLAGS += $(EXTRA_ASFLAGS)
272 LDFLAGS += $(EXTRA_LDFLAGS)
274 # Embedded image, if present
276 EMBEDDED_IMAGE = /dev/null
278 # Inhibit -Werror if NO_WERROR is specified on make command line
280 ifneq ($(NO_WERROR),1)
284 # compiler.h is needed for our linking and debugging system
286 CFLAGS += -include compiler.h
288 # CFLAGS for specific object types
291 CFLAGS_S += -DASSEMBLY
293 # Base object name of the current target
295 OBJECT = $(firstword $(subst ., ,$(@F)))
297 # CFLAGS for specific object files. You can define
298 # e.g. CFLAGS_rtl8139, and have those flags automatically used when
299 # compiling bin/rtl8139.o.
301 OBJ_CFLAGS = $(CFLAGS_$(OBJECT)) -DOBJECT=$(subst -,_,$(OBJECT))
303 @$(ECHO) $(OBJ_CFLAGS)
305 # Rules for specific object types.
307 COMPILE_c = $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
308 RULE_c = $(Q)$(COMPILE_c) -c $< -o $@
309 RULE_c_to_dbg%.o = $(Q)$(COMPILE_c) -Ddebug_$(OBJECT)=$* -c $< -o $@
310 RULE_c_to_c = $(Q)$(COMPILE_c) -E -c $< > $@
311 RULE_c_to_s = $(Q)$(COMPILE_c) -S -g0 -c $< -o $@
313 PREPROCESS_S = $(CPP) $(CFLAGS) $(CFLAGS_S) $(OBJ_CFLAGS)
314 ASSEMBLE_S = $(AS) $(ASFLAGS)
315 RULE_S = $(Q)$(PREPROCESS_S) $< | $(ASSEMBLE_S) -o $@
316 RULE_S_to_s = $(Q)$(PREPROCESS_S) $< > $@
318 DEBUG_TARGETS += dbg%.o c s
320 # We automatically generate rules for any file mentioned in AUTO_SRCS
321 # using the following set of templates. It would be cleaner to use
322 # $(eval ...), but this function exists only in GNU make >= 3.80.
324 # src_template : generate Makefile rules for a given source file
326 # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
327 # $(2) is the full path to the .d file (e.g. "bin/deps/drivers/net/rtl8139.d")
328 # $(3) is the source type (e.g. "c")
329 # $(4) is the source base name (e.g. "rtl8139")
333 @$(ECHO) " [DEPS] $(1)"
334 @$(MKDIR) -p $(dir $(2))
337 $(foreach OBJ,$(if $(OBJS_$(4)),$(OBJS_$(4)),$(4)), \
338 $(call obj_template,$(1),$(2),$(3),$(OBJ)))
339 @$(PARSEROM) $(1) >> $(2)
343 # obj_template : generate Makefile rules for a given resultant object
344 # of a particular source file. (We can have multiple objects per
345 # source file via the OBJS_xxx list.)
347 # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
348 # $(2) is the full path to the .d file (e.g. "bin/deps/drivers/net/rtl8139.d")
349 # $(3) is the source type (e.g. "c")
350 # $(4) is the object name (e.g. "rtl8139")
354 @$(CPP) $(CFLAGS) $(CFLAGS_$(3)) $(CFLAGS_$(4)) -DOBJECT=$(4) \
355 -Wno-error -MM $(1) -MT "$(4)_DEPS" -MG -MP | \
356 sed 's/_DEPS\s*:/_DEPS =/' >> $(2)
357 @$(ECHO_E) '\n$$(BIN)/$(4).o : $(1) $$(MAKEDEPS) $$($(4)_DEPS)' \
358 '\n\t$$(QM)$(ECHO) " [BUILD] $$@"' \
359 '\n\t$$(RULE_$(3))\n' \
360 '\nBOBJS += $$(BIN)/$(4).o\n' \
361 $(foreach TGT,$(DEBUG_TARGETS), \
362 $(if $(RULE_$(3)_to_$(TGT)), \
363 '\n$$(BIN)/$(4).$(TGT) : $(1) $$(MAKEDEPS) $$($(4)_DEPS)' \
364 '\n\t$$(QM)$(ECHO) " [BUILD] $$@"' \
365 '\n\t$$(RULE_$(3)_to_$(TGT))\n' \
366 '\n$(TGT)_OBJS += $$(BIN)/$(4).$(TGT)\n' ) ) \
367 '\n$(2) : $$($(4)_DEPS)\n' \
368 '\nTAGS : $$($(4)_DEPS)\n' \
373 # Rule to generate the Makefile rules files to be included
375 $(BIN)/deps/%.d : % $(MAKEDEPS) $(PARSEROM)
376 $(if $(filter $(AUTO_SRCS),$<),$(call src_template,$<,$@,$(subst .,,$(suffix $<)),$(basename $(notdir $<))),@$(ECHO) 'ERROR: $< is not an AUTO_SRC' ; exit 1)
378 # Calculate and include the list of Makefile rules files
380 AUTO_DEPS = $(patsubst %,$(BIN)/deps/%.d,$(AUTO_SRCS))
382 ifneq ($(AUTO_DEPS),)
383 -include $(AUTO_DEPS)
387 @$(ECHO) $(AUTO_DEPS)
388 VERYCLEANUP += $(BIN)/deps
390 # The following variables are created by the Makefile rules files
401 $(BIN)/embedimg.bin: $(EMBEDDED_IMAGE)
402 $(QM)$(ECHO) " [COPY] $@"
403 $(Q)$(CP) -f $(EMBEDDED_IMAGE) $@
405 $(BIN)/embed.o: $(BIN)/embedimg.bin
406 CFLAGS_embed = -DEMBEDIMG=\"$(BIN)/embedimg.bin\"
408 # Generate the NIC file from the parsed source files. The NIC file is
409 # only for rom-o-matic.
411 $(BIN)/NIC : $(AUTO_DEPS)
412 @$(ECHO) '# This is an automatically generated file, do not edit' > $@
413 @$(ECHO) '# It does not affect anything in the build, ' \
414 'it is only for rom-o-matic' >> $@
416 @perl -ne 'chomp; print "$$1\n" if /\# NIC\t(.*)$$/' $^ >> $@
417 CLEANUP += $(BIN)/NIC # Doesn't match the $(BIN)/*.* pattern
419 # Analyse a target name (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and
420 # derive the variables:
422 # TGT_ELEMENTS : the elements of the target (e.g. "dfe538 prism2_pci")
423 # TGT_PREFIX : the prefix type (e.g. "zrom")
424 # TGT_DRIVERS : the driver for each element (e.g. "rtl8139 prism2_pci")
425 # TGT_ROM_NAME : the ROM name (e.g. "dfe538")
426 # TGT_MEDIA : the media type (e.g. "rom")
428 DRIVERS_gpxe = $(DRIVERS)
429 CARD_DRIVER = $(firstword $(DRIVER_$(1)) $(1))
430 TGT_ELEMENTS = $(subst --, ,$(firstword $(subst ., ,$(notdir $@))))
431 TGT_PREFIX = $(word 2,$(subst ., ,$(notdir $@)))
432 TGT_ROM_NAME = $(firstword $(TGT_ELEMENTS))
433 TGT_DRIVERS = $(strip $(if $(DRIVERS_$(TGT_ROM_NAME)), \
434 $(DRIVERS_$(TGT_ROM_NAME)), \
435 $(foreach TGT_ELEMENT,$(TGT_ELEMENTS), \
436 $(call CARD_DRIVER,$(TGT_ELEMENT))) ))
437 TGT_MEDIA = $(subst z,,$(TGT_PREFIX))
439 # Look up ROM IDs for the current target
440 # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
442 # TGT_PCI_VENDOR : the PCI vendor ID (e.g. "0x1186")
443 # TGT_PCI_DEVICE : the PCI device ID (e.g. "0x1300")
445 TGT_PCI_VENDOR = $(PCI_VENDOR_$(TGT_ROM_NAME))
446 TGT_PCI_DEVICE = $(PCI_DEVICE_$(TGT_ROM_NAME))
448 # Calculate link-time options for the current target
449 # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
451 # TGT_LD_DRIVERS : symbols to require in order to drag in the relevant drivers
452 # (e.g. "obj_rtl8139 obj_prism2_pci")
453 # TGT_LD_IDS : symbols to define in order to fill in ID structures in the
454 # ROM header (e.g."pci_vendor_id=0x1186 pci_device_id=0x1300")
456 TGT_LD_DRIVERS = $(subst -,_,$(patsubst %,obj_%,$(TGT_DRIVERS)))
457 TGT_LD_PREFIX = obj_$(TGT_PREFIX)prefix
458 TGT_LD_IDS = pci_vendor_id=$(firstword $(TGT_PCI_VENDOR) 0) \
459 pci_device_id=$(firstword $(TGT_PCI_DEVICE) 0)
461 # Calculate linker flags based on link-time options for the current
462 # target type (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the
465 # TGT_LD_FLAGS : target-specific flags to pass to linker (e.g.
466 # "-u obj_zpciprefix -u obj_rtl8139 -u obj_prism2_pci
467 # --defsym pci_vendor=0x1186 --defsym pci_device=0x1300")
469 TGT_LD_FLAGS = $(foreach SYM,$(TGT_LD_PREFIX) $(TGT_LD_DRIVERS) obj_config,\
470 -u $(SYM) --defsym check_$(SYM)=$(SYM) ) \
471 $(patsubst %,--defsym %,$(TGT_LD_IDS))
473 # Calculate makerom flags for the specific target
474 # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
476 # TGT_MAKEROM_FLAGS : target-specific flags for makerom (e.g.
477 # "-p 0x1186,0x1300")
479 TGT_MAKEROM_FLAGS = $(strip $(MAKEROM_FLAGS_$(TGT_ROM_NAME)) \
480 $(if $(TGT_PCI_VENDOR),$(strip -p $(TGT_PCI_VENDOR),$(TGT_PCI_DEVICE))))
482 # Calculate list of debugging versions of objects to be included in
486 DEBUG_LIST = $(subst $(COMMA), ,$(DEBUG))
487 DEBUG_OBJ_LEVEL = $(firstword $(word 2,$(subst :, ,$(1))) 1)
488 DEBUG_OBJ_BASE = $(word 1,$(subst :, ,$(1))).dbg$(call DEBUG_OBJ_LEVEL,$(1))
489 DEBUG_OBJ = $(BIN)/$(call DEBUG_OBJ_BASE,$(1)).o
490 DEBUG_ORIG_OBJ = $(BIN)/$(word 1,$(subst :, ,$(1))).o
491 DEBUG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_OBJ,$(D)))
492 DEBUG_ORIG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_ORIG_OBJ,$(D)))
493 BLIB_OBJS = $(DEBUG_OBJS) $(filter-out $(DEBUG_ORIG_OBJS),$(BOBJS))
495 # Print out all derived information for a given target.
498 @$(ECHO) 'Elements : $(TGT_ELEMENTS)'
499 @$(ECHO) 'Prefix : $(TGT_PREFIX)'
500 @$(ECHO) 'Drivers : $(TGT_DRIVERS)'
501 @$(ECHO) 'ROM name : $(TGT_ROM_NAME)'
502 @$(ECHO) 'Media : $(TGT_MEDIA)'
504 @$(ECHO) 'PCI vendor : $(TGT_PCI_VENDOR)'
505 @$(ECHO) 'PCI device : $(TGT_PCI_DEVICE)'
507 @$(ECHO) 'LD driver symbols : $(TGT_LD_DRIVERS)'
508 @$(ECHO) 'LD prefix symbols : $(TGT_LD_PREFIX)'
509 @$(ECHO) 'LD ID symbols : $(TGT_LD_IDS)'
511 @$(ECHO) 'LD target flags : $(TGT_LD_FLAGS)'
513 @$(ECHO) 'makerom target flags : $(TGT_MAKEROM_FLAGS)'
515 @$(ECHO) 'Debugging objects : $(DEBUG_OBJS)'
516 @$(ECHO) 'Replaced objects : $(DEBUG_ORIG_OBJS)'
518 # List of objects included in the last build of blib. This is needed
519 # in order to correctly rebuild blib whenever the list of objects
522 BLIB_LIST := $(BIN)/.blib.list
523 ifeq ($(wildcard $(BLIB_LIST)),)
526 BLIB_LIST_OBJS := $(shell cat $(BLIB_LIST))
528 ifneq ($(BLIB_LIST_OBJS),$(BLIB_OBJS))
529 $(shell $(ECHO) "$(BLIB_OBJS)" > $(BLIB_LIST))
534 VERYCLEANUP += $(BLIB_LIST)
536 # Library of all objects
539 $(BLIB) : $(BLIB_OBJS) $(BLIB_LIST) $(MAKEDEPS)
541 $(QM)$(ECHO) " [AR] $@"
542 $(Q)$(AR) r $@ $(BLIB_OBJS)
546 # Build an intermediate object file from the objects required for the
549 $(BIN)/%.tmp : $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
550 $(QM)$(ECHO) " [LD] $@"
551 $(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $(BLIB) -o $@ \
552 -Map $(BIN)/$*.tmp.map
553 $(Q)$(OBJDUMP) -ht $@ | $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
555 # Keep intermediate object file (useful for debugging)
556 .PRECIOUS : $(BIN)/%.tmp
558 # Show a linker map for the specified target
560 $(BIN)/%.map : $(BIN)/%.tmp
561 @less $(BIN)/$*.tmp.map
563 # Extract compression information from intermediate object file
565 $(BIN)/%.zinfo : $(BIN)/%.tmp
566 $(QM)$(ECHO) " [ZINFO] $@"
567 $(Q)$(OBJCOPY) -O binary -j .zinfo $< $@
569 # Build raw binary file from intermediate object file
571 $(BIN)/%.bin : $(BIN)/%.tmp
572 $(QM)$(ECHO) " [BIN] $@"
573 $(Q)$(OBJCOPY) -O binary -R .zinfo $< $@
575 # Compress raw binary file
577 $(BIN)/%.zbin : $(BIN)/%.bin $(BIN)/%.zinfo $(ZBIN)
578 $(QM)$(ECHO) " [ZBIN] $@"
579 $(Q)$(ZBIN) $(BIN)/$*.bin $(BIN)/$*.zinfo > $@
581 # Rules for each media format. These are generated and placed in an
582 # external Makefile fragment. We could do this via $(eval ...), but
583 # that would require make >= 3.80.
585 # Note that there's an alternative way to generate most .rom images:
586 # they can be copied from their 'master' ROM image using cp and
587 # reprocessed with makerom to add the PCI IDs and ident string. The
588 # relevant rule would look something like:
590 # $(BIN)/dfe538%rom : $(BIN)/rtl8139%rom
594 # You can derive the ROM/driver relationships using the variables
595 # DRIVER_<rom> and/or ROMS_<driver>.
597 # We don't currently do this, because (a) it would require generating
598 # yet more Makefile fragments (since you need a rule for each ROM in
599 # ROMS), and (b) the linker is so fast that it probably wouldn't make
600 # much difference to the overall build time.
605 AUTO_MEDIA = $(filter-out $(NON_AUTO_MEDIA),$(MEDIA))
607 @$(ECHO) $(AUTO_MEDIA)
609 # media_template : create Makefile rules for specified media
611 # $(1) is the media name (e.g. "rom")
612 # $(2) is the full path to the .d file (e.g. "bin/deps/rom.media.d")
614 define media_template
616 @$(ECHO) " [MEDIADEPS] $(1)"
617 @$(MKDIR) -p $(dir $(2))
620 @$(ECHO_E) '$$(BIN)/%.$(1) : $$(BIN)/%.$(1).zbin' \
621 '\n\t$$(QM)$(ECHO) " [FINISH] $$@"' \
622 '\n\t$$(Q)$$(CP) $$< $$@' \
623 '\n\t$$(Q)$$(FINALISE_$(1))' \
628 # Rule to generate the Makefile rules to be included
630 $(BIN)/deps/%.media.d : $(MAKEDEPS)
631 $(if $(filter $(AUTO_MEDIA),$*), \
632 $(call media_template,$*,$@), \
633 @$(ECHO) 'ERROR: $* is not an AUTO_MEDIA' ; exit 1)
635 # Calculate and include the list of Makefile rules files
637 MEDIA_DEPS = $(patsubst %,$(BIN)/deps/%.media.d,$(AUTO_MEDIA))
639 @$(ECHO) $(MEDIA_DEPS)
641 ifneq ($(MEDIA_DEPS),)
642 -include $(MEDIA_DEPS)
646 # Wrap up binary blobs (for embedded images)
648 $(BIN)/%.o : payload/%.img
649 $(QM)echo " [WRAP] $@"
650 $(Q)$(LD) -b binary -r -o $@ $< --undefined obj_payload \
653 BOBJS += $(patsubst payload/%.img,$(BIN)/%.o,$(wildcard payload/*.img))
655 # The "allXXXs" targets for each suffix
657 allall: allroms allzroms allpxes allisos alldsks
658 allroms allzroms : all%s : $(foreach ROM,$(ROMS),$(BIN)/$(ROM).%)
659 allpxes allisos alldsks : all%s : $(foreach DRIVER,$(DRIVERS),$(BIN)/$(DRIVER).%)
663 $(BIN)/etherboot.% : $(BIN)/gpxe.%
664 ln -sf $(notdir $<) $@
668 ###############################################################################
670 # Rules for finalising files. TGT_MAKEROM_FLAGS is defined as part of
671 # the automatic build system and varies by target; it includes the
672 # "-p 0x1234,0x5678" string to set the PCI IDs.
674 FINALISE_rom = $(MAKEROM) $(MAKEROM_FLAGS) $(TGT_MAKEROM_FLAGS) \
677 # Some ROMs require specific flags to be passed to makerom.pl
679 MAKEROM_FLAGS_3c503 = -3
681 ###############################################################################
683 # The compression utilities
685 $(NRV2B) : util/nrv2b.c $(MAKEDEPS)
686 $(QM)$(ECHO) " [HOSTCC] $@"
687 $(Q)$(HOST_CC) -O2 -DENCODE -DDECODE -DMAIN -DVERBOSE -DNDEBUG \
688 -DBITSIZE=32 -DENDIAN=0 -o $@ $<
691 $(ZBIN) : util/zbin.c util/nrv2b.c $(MAKEDEPS)
692 $(QM)$(ECHO) " [HOSTCC] $@"
693 $(Q)$(HOST_CC) -O2 -o $@ $<
696 ###############################################################################
698 # The EFI custom linker
700 $(EFILINK) : util/efilink.c $(MAKEDEPS)
701 $(QM)$(ECHO) " [HOSTCC] $@"
702 $(Q)$(HOST_CC) -O2 -o $@ $< -lbfd
703 CLEANUP += $(EFILINK)
705 ###############################################################################
707 # Auto-incrementing build serial number. Append "bs" to your list of
708 # build targets to get a serial number printed at the end of the
709 # build. Enable -DBUILD_SERIAL in order to see it when the code runs.
711 BUILDSERIAL_H = config/.buildserial.h
712 BUILDSERIAL_NOW = config/.buildserial.now
713 BUILDSERIAL_NEXT = config/.buildserial.next
715 $(BUILDSERIAL_NOW) $(BUILDSERIAL_NEXT) :
718 $(BUILDSERIAL_H) : $(BUILDSERIAL_NOW) $(BUILDSERIAL_NEXT)
719 $(ECHO) '#define BUILD_SERIAL_NUM $(shell cat $<)' > $@
721 ifeq ($(filter bs,$(MAKECMDGOALS)),bs)
722 $(shell diff -q $(BUILDSERIAL_NOW) $(BUILDSERIAL_NEXT) > /dev/null || \
723 cp -f $(BUILDSERIAL_NEXT) $(BUILDSERIAL_NOW))
726 bs : $(BUILDSERIAL_NOW)
727 @$(ECHO) $$(( $(shell cat $<) + 1 )) > $(BUILDSERIAL_NEXT)
728 @$(ECHO) "Build serial number is $(shell cat $<)"
730 ###############################################################################
732 # Build the TAGS file(s) for emacs
735 ctags -e -R -f $@ --exclude=bin
739 ###############################################################################
741 # Force rebuild for any given target
747 ###############################################################################
749 # Symbol table checks
754 SYMTAB = $(BIN)/symtab
756 $(OBJDUMP) -w -t $< > $@
758 CLEANUP += $(BIN)/symtab
765 ###############################################################################
767 # Build bochs symbol table
772 $(BIN)/%.bxs : $(BIN)/%.tmp
773 $(NM) $< | cut -d" " -f1,3 > $@
777 ###############################################################################
784 $(BIN)/doxygen.cfg : doxygen.cfg $(MAKEDEPS)
785 $(PERL) -pe 's{\@SRCDIRS\@}{$(SRCDIRS)}; ' \
786 -e 's{\@BIN\@}{$(BIN)}; ' \
787 -e 's{\@ARCH\@}{$(ARCH)}; ' \
790 $(BIN)/doc : $(BIN)/doxygen.cfg
795 VERYCLEANUP += $(BIN)/doc
800 @[ -f $(BIN)/doc/html/index.html ] || $(MAKE) $(BIN)/doc
801 @if [ -n "$$BROWSER" ] ; then \
802 ( $$BROWSER $(BIN)/doc/html/index.html & ) ; \
804 $(ECHO) "Documentation index in $(BIN)/doc/html/index.html" ; \
809 ###############################################################################
817 $(RM) -r $(VERYCLEANUP)