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 ###############################################################################
59 HOST_OS := $(shell uname -s)
63 ###############################################################################
65 # Check for tools that can cause failed builds
68 @if $(CC) -v 2>&1 | grep -is 'gcc version 2\.96' > /dev/null; then \
69 $(ECHO) 'gcc 2.96 is unsuitable for compiling Etherboot'; \
70 $(ECHO) 'Use gcc 2.95 or gcc 3.x instead'; \
73 @if [ `perl -e 'use bytes; print chr(255)' | wc -c` = 2 ]; then \
74 $(ECHO) 'Your Perl version has a Unicode handling bug'; \
75 $(ECHO) 'Execute this command before compiling Etherboot:'; \
76 $(ECHO) 'export LANG=$${LANG%.UTF-8}'; \
80 MAKEDEPS += .toolcheck
81 VERYCLEANUP += .toolcheck
83 ###############################################################################
85 # Check for various tool workarounds
88 # Make syntax does not allow use of comma or space in certain places.
89 # This ugly workaround is suggested in the manual.
93 SPACE := $(EMPTY) $(EMPTY)
95 # Check for an old version of gas (binutils 2.9.1)
97 OLDGAS := $(shell $(AS) --version | grep -q '2\.9\.1' && $(ECHO) -DGAS291)
102 # Some widespread patched versions of gcc include -fstack-protector by
103 # default, even when -ffreestanding is specified. We therefore need
104 # to disable -fstack-protector if the compiler supports it.
106 SP_TEST = $(CC) -fno-stack-protector -x c -c /dev/null \
107 -o /dev/null >/dev/null 2>&1
108 SP_FLAGS := $(shell $(SP_TEST) && $(ECHO) '-fno-stack-protector')
109 CFLAGS += $(SP_FLAGS)
111 ###############################################################################
123 ###############################################################################
125 # Set BIN according to whatever was specified on the command line as
129 # Determine how many different BIN directories are mentioned in the
132 BIN_GOALS := $(filter bin/% bin-%,$(MAKECMDGOALS))
133 BIN_GOAL_BINS := $(foreach BG,$(BIN_GOALS),$(firstword $(subst /, ,$(BG))))
134 NUM_BINS := $(words $(sort $(BIN_GOAL_BINS)))
138 # No BIN directory was specified. Set BIN to "bin" as a sensible
147 # If exactly one BIN directory was specified, set BIN to match this
150 BIN := $(firstword $(BIN_GOAL_BINS))
154 # More than one BIN directory was specified. We cannot handle the
155 # latter case within a single make invocation, so set up recursive
156 # targets for each BIN directory.
158 # Leave $(BIN) undefined. This has implications for any target that
159 # depends on $(BIN); such targets should be made conditional upon the
160 # existence of $(BIN).
162 $(BIN_GOALS) : % : BIN_RECURSE
163 $(Q)$(MAKE) --no-print-directory BIN=$(firstword $(subst /, ,$@)) $@
166 endif # NUM_BINS == 1
167 endif # NUM_BINS == 0
171 # Create $(BIN) directory if it doesn't exist yet
173 ifeq ($(wildcard $(BIN)),)
174 $(shell $(MKDIR) -p $(BIN))
177 # Target to allow e.g. "make bin-efi arch"
180 @# Do nothing, silently
183 # Remove everything in $(BIN) for a "make clean"
185 CLEANUP += $(BIN)/*.* # Avoid picking up directories
189 # Determine whether or not we need to include the dependency files
191 NO_DEP_TARGETS := $(BIN) clean veryclean
192 ifeq ($(MAKECMDGOALS),)
195 ifneq ($(strip $(filter-out $(NO_DEP_TARGETS),$(MAKECMDGOALS))),)
199 ###############################################################################
201 # Select build architecture and platform based on $(BIN)
203 # BIN has the form bin[-[arch-]platform]
205 ARCHS := $(patsubst arch/%,%,$(wildcard arch/*))
206 PLATFORMS := $(patsubst config/defaults/%.h,%,\
207 $(wildcard config/defaults/*.h))
212 @$(ECHO) $(PLATFORMS)
216 # Determine architecture portion of $(BIN), if present
217 BIN_ARCH := $(strip $(foreach A,$(ARCHS),\
218 $(patsubst bin-$(A)-%,$(A),\
219 $(filter bin-$(A)-%,$(BIN)))))
221 # Determine platform portion of $(BIN), if present
223 BIN_PLATFORM := $(patsubst bin-%,%,$(filter bin-%,$(BIN)))
225 BIN_PLATFORM := $(patsubst bin-$(BIN_ARCH)-%,%,$(BIN))
228 # Determine build architecture
230 ARCH := $(firstword $(BIN_ARCH) $(DEFAULT_ARCH))
231 CFLAGS += -DARCH=$(ARCH)
236 # Determine build platform
237 DEFAULT_PLATFORM := pcbios
238 PLATFORM := $(firstword $(BIN_PLATFORM) $(DEFAULT_PLATFORM))
239 CFLAGS += -DPLATFORM=$(PLATFORM)
245 # Include architecture-specific Makefile
247 MAKEDEPS += arch/$(ARCH)/Makefile
248 include arch/$(ARCH)/Makefile
251 ###############################################################################
253 # Source file handling
255 # SRCDIRS lists all directories containing source files.
259 # SRCS lists all .c or .S files found in any SRCDIR
261 SRCS += $(wildcard $(patsubst %,%/*.c,$(SRCDIRS)))
262 SRCS += $(wildcard $(patsubst %,%/*.S,$(SRCDIRS)))
266 # AUTO_SRCS lists all files in SRCS that are not mentioned in
267 # NON_AUTO_SRCS. Files should be added to NON_AUTO_SRCS if they
268 # cannot be built using the standard build template.
270 AUTO_SRCS = $(filter-out $(NON_AUTO_SRCS),$(SRCS))
272 @$(ECHO) $(AUTO_SRCS)
274 # Just about everything else in this section depends upon having
281 CFLAGS += -I include -I arch/$(ARCH)/include -I .
282 CFLAGS += -Os -ffreestanding
283 CFLAGS += -Wall -W -Wformat-nonliteral
285 CFLAGS += $(EXTRA_CFLAGS)
286 ASFLAGS += $(EXTRA_ASFLAGS)
287 LDFLAGS += $(EXTRA_LDFLAGS)
289 # Inhibit -Werror if NO_WERROR is specified on make command line
291 ifneq ($(NO_WERROR),1)
293 ASFLAGS += --fatal-warnings
296 # compiler.h is needed for our linking and debugging system
298 CFLAGS += -include compiler.h
300 # CFLAGS for specific object types
303 CFLAGS_S += -DASSEMBLY
305 # Base object name of the current target
307 OBJECT = $(firstword $(subst ., ,$(@F)))
309 # CFLAGS for specific object files. You can define
310 # e.g. CFLAGS_rtl8139, and have those flags automatically used when
311 # compiling bin/rtl8139.o.
313 OBJ_CFLAGS = $(CFLAGS_$(OBJECT)) -DOBJECT=$(subst -,_,$(OBJECT))
315 @$(ECHO) $(OBJ_CFLAGS)
317 # Rules for specific object types.
319 COMPILE_c = $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
320 RULE_c = $(Q)$(COMPILE_c) -c $< -o $@
321 RULE_c_to_dbg%.o = $(Q)$(COMPILE_c) -Ddebug_$(OBJECT)=$* -c $< -o $@
322 RULE_c_to_c = $(Q)$(COMPILE_c) -E -c $< > $@
323 RULE_c_to_s = $(Q)$(COMPILE_c) -S -g0 -c $< -o $@
325 PREPROCESS_S = $(CPP) $(CFLAGS) $(CFLAGS_S) $(OBJ_CFLAGS)
326 ASSEMBLE_S = $(AS) $(ASFLAGS)
327 RULE_S = $(Q)$(PREPROCESS_S) $< | $(ASSEMBLE_S) -o $@
328 RULE_S_to_s = $(Q)$(PREPROCESS_S) $< > $@
330 DEBUG_TARGETS += dbg%.o c s
332 # We automatically generate rules for any file mentioned in AUTO_SRCS
333 # using the following set of templates. It would be cleaner to use
334 # $(eval ...), but this function exists only in GNU make >= 3.80.
336 # src_template : generate Makefile rules for a given source file
338 # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
339 # $(2) is the full path to the .d file (e.g. "bin/deps/drivers/net/rtl8139.d")
340 # $(3) is the source type (e.g. "c")
341 # $(4) is the source base name (e.g. "rtl8139")
345 @$(ECHO) " [DEPS] $(1)"
346 @$(MKDIR) -p $(dir $(2))
349 $(foreach OBJ,$(if $(OBJS_$(4)),$(OBJS_$(4)),$(4)), \
350 $(call obj_template,$(1),$(2),$(3),$(OBJ)))
351 @$(PARSEROM) $(1) >> $(2)
355 # obj_template : generate Makefile rules for a given resultant object
356 # of a particular source file. (We can have multiple objects per
357 # source file via the OBJS_xxx list.)
359 # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
360 # $(2) is the full path to the .d file (e.g. "bin/deps/drivers/net/rtl8139.d")
361 # $(3) is the source type (e.g. "c")
362 # $(4) is the object name (e.g. "rtl8139")
366 @$(CPP) $(CFLAGS) $(CFLAGS_$(3)) $(CFLAGS_$(4)) -DOBJECT=$(4) \
367 -Wno-error -MM $(1) -MT "$(4)_DEPS" -MG -MP | \
368 sed 's/_DEPS\s*:/_DEPS =/' >> $(2)
369 @$(ECHO_E) '\n$$(BIN)/$(4).o : $(1) $$(MAKEDEPS) $$($(4)_DEPS)' \
370 '\n\t$$(QM)$(ECHO) " [BUILD] $$@"' \
371 '\n\t$$(RULE_$(3))\n' \
372 '\nBOBJS += $$(BIN)/$(4).o\n' \
373 $(foreach TGT,$(DEBUG_TARGETS), \
374 $(if $(RULE_$(3)_to_$(TGT)), \
375 '\n$$(BIN)/$(4).$(TGT) : $(1) $$(MAKEDEPS) $$($(4)_DEPS)' \
376 '\n\t$$(QM)$(ECHO) " [BUILD] $$@"' \
377 '\n\t$$(RULE_$(3)_to_$(TGT))\n' \
378 '\n$(TGT)_OBJS += $$(BIN)/$(4).$(TGT)\n' ) ) \
379 '\n$(2) : $$($(4)_DEPS)\n' \
380 '\nTAGS : $$($(4)_DEPS)\n' \
385 # Rule to generate the Makefile rules files to be included
387 $(BIN)/deps/%.d : % $(MAKEDEPS) $(PARSEROM)
388 $(if $(filter $(AUTO_SRCS),$<),$(call src_template,$<,$@,$(subst .,,$(suffix $<)),$(basename $(notdir $<))),@$(ECHO) 'ERROR: $< is not an AUTO_SRC' ; exit 1)
390 # Calculate and include the list of Makefile rules files
392 AUTO_DEPS = $(patsubst %,$(BIN)/deps/%.d,$(AUTO_SRCS))
394 ifneq ($(AUTO_DEPS),)
395 -include $(AUTO_DEPS)
399 @$(ECHO) $(AUTO_DEPS)
400 VERYCLEANUP += $(BIN)/deps
402 # The following variables are created by the Makefile rules files
412 # List of embedded images included in the last build of embedded.o.
413 # This is needed in order to correctly rebuild embedded.o whenever the
414 # list of objects changes.
416 EMBEDDED_LIST := $(BIN)/.embedded.list
417 ifeq ($(wildcard $(EMBEDDED_LIST)),)
418 EMBEDDED_LIST_IMAGE :=
420 EMBEDDED_LIST_IMAGE := $(shell cat $(EMBEDDED_LIST))
422 ifneq ($(EMBEDDED_LIST_IMAGE),$(EMBEDDED_IMAGE))
423 $(shell $(ECHO) "$(EMBEDDED_IMAGE)" > $(EMBEDDED_LIST))
428 VERYCLEANUP += $(EMBEDDED_LIST)
430 EMBEDDED_FILES := $(subst $(COMMA), ,$(EMBEDDED_IMAGE))
431 EMBED_ALL := $(foreach i,$(shell seq 1 $(words $(EMBEDDED_FILES))),\
432 EMBED ( $(i), \"$(word $(i), $(EMBEDDED_FILES))\",\
433 \"$(notdir $(word $(i),$(EMBEDDED_FILES)))\" ))
435 $(BIN)/embedded.o : $(EMBEDDED_FILES) $(EMBEDDED_LIST)
436 CFLAGS_embedded = -DEMBED_ALL="$(EMBED_ALL)"
438 # Generate the NIC file from the parsed source files. The NIC file is
439 # only for rom-o-matic.
441 $(BIN)/NIC : $(AUTO_DEPS)
442 @$(ECHO) '# This is an automatically generated file, do not edit' > $@
443 @$(ECHO) '# It does not affect anything in the build, ' \
444 'it is only for rom-o-matic' >> $@
446 @perl -ne 'chomp; print "$$1\n" if /\# NIC\t(.*)$$/' $^ >> $@
447 CLEANUP += $(BIN)/NIC # Doesn't match the $(BIN)/*.* pattern
449 # Analyse a target name (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and
450 # derive the variables:
452 # TGT_ELEMENTS : the elements of the target (e.g. "dfe538 prism2_pci")
453 # TGT_PREFIX : the prefix type (e.g. "zrom")
454 # TGT_DRIVERS : the driver for each element (e.g. "rtl8139 prism2_pci")
455 # TGT_ROM_NAME : the ROM name (e.g. "dfe538")
456 # TGT_MEDIA : the media type (e.g. "rom")
458 DRIVERS_gpxe = $(DRIVERS)
459 CARD_DRIVER = $(firstword $(DRIVER_$(1)) $(1))
460 TGT_ELEMENTS = $(subst --, ,$(firstword $(subst ., ,$(notdir $@))))
461 TGT_PREFIX = $(word 2,$(subst ., ,$(notdir $@)))
462 TGT_ROM_NAME = $(firstword $(TGT_ELEMENTS))
463 TGT_DRIVERS = $(strip $(if $(DRIVERS_$(TGT_ROM_NAME)), \
464 $(DRIVERS_$(TGT_ROM_NAME)), \
465 $(foreach TGT_ELEMENT,$(TGT_ELEMENTS), \
466 $(call CARD_DRIVER,$(TGT_ELEMENT))) ))
467 TGT_MEDIA = $(subst z,,$(TGT_PREFIX))
469 # Look up ROM IDs for the current target
470 # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
472 # TGT_PCI_VENDOR : the PCI vendor ID (e.g. "0x1186")
473 # TGT_PCI_DEVICE : the PCI device ID (e.g. "0x1300")
475 TGT_PCI_VENDOR = $(PCI_VENDOR_$(TGT_ROM_NAME))
476 TGT_PCI_DEVICE = $(PCI_DEVICE_$(TGT_ROM_NAME))
478 # Calculate link-time options for the current target
479 # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
481 # TGT_LD_DRIVERS : symbols to require in order to drag in the relevant drivers
482 # (e.g. "obj_rtl8139 obj_prism2_pci")
483 # TGT_LD_IDS : symbols to define in order to fill in ID structures in the
484 # ROM header (e.g."pci_vendor_id=0x1186 pci_device_id=0x1300")
486 TGT_LD_DRIVERS = $(subst -,_,$(patsubst %,obj_%,$(TGT_DRIVERS)))
487 TGT_LD_PREFIX = obj_$(TGT_PREFIX)prefix
488 TGT_LD_IDS = pci_vendor_id=$(firstword $(TGT_PCI_VENDOR) 0) \
489 pci_device_id=$(firstword $(TGT_PCI_DEVICE) 0)
491 # Calculate linker flags based on link-time options for the current
492 # target type (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the
495 # TGT_LD_FLAGS : target-specific flags to pass to linker (e.g.
496 # "-u obj_zpciprefix -u obj_rtl8139 -u obj_prism2_pci
497 # --defsym pci_vendor=0x1186 --defsym pci_device=0x1300")
499 TGT_LD_FLAGS = $(foreach SYM,$(TGT_LD_PREFIX) $(TGT_LD_DRIVERS) obj_config,\
500 -u $(SYM) --defsym check_$(SYM)=$(SYM) ) \
501 $(patsubst %,--defsym %,$(TGT_LD_IDS))
503 # Calculate makerom flags for the specific target
504 # (e.g. "bin/dfe538--prism2_pci.zrom.tmp") and derive the variables:
506 # TGT_MAKEROM_FLAGS : target-specific flags for makerom (e.g.
507 # "-p 0x1186,0x1300")
509 TGT_MAKEROM_FLAGS = $(strip $(MAKEROM_FLAGS_$(TGT_ROM_NAME)) \
510 $(if $(TGT_PCI_VENDOR),$(strip -p $(TGT_PCI_VENDOR),$(TGT_PCI_DEVICE))))
512 # Calculate list of debugging versions of objects to be included in
515 DEBUG_LIST = $(subst $(COMMA), ,$(DEBUG))
516 DEBUG_OBJ_LEVEL = $(firstword $(word 2,$(subst :, ,$(1))) 1)
517 DEBUG_OBJ_BASE = $(word 1,$(subst :, ,$(1))).dbg$(call DEBUG_OBJ_LEVEL,$(1))
518 DEBUG_OBJ = $(BIN)/$(call DEBUG_OBJ_BASE,$(1)).o
519 DEBUG_ORIG_OBJ = $(BIN)/$(word 1,$(subst :, ,$(1))).o
520 DEBUG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_OBJ,$(D)))
521 DEBUG_ORIG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_ORIG_OBJ,$(D)))
522 BLIB_OBJS = $(DEBUG_OBJS) $(filter-out $(DEBUG_ORIG_OBJS),$(BOBJS))
524 # Print out all derived information for a given target.
527 @$(ECHO) 'Elements : $(TGT_ELEMENTS)'
528 @$(ECHO) 'Prefix : $(TGT_PREFIX)'
529 @$(ECHO) 'Drivers : $(TGT_DRIVERS)'
530 @$(ECHO) 'ROM name : $(TGT_ROM_NAME)'
531 @$(ECHO) 'Media : $(TGT_MEDIA)'
533 @$(ECHO) 'PCI vendor : $(TGT_PCI_VENDOR)'
534 @$(ECHO) 'PCI device : $(TGT_PCI_DEVICE)'
536 @$(ECHO) 'LD driver symbols : $(TGT_LD_DRIVERS)'
537 @$(ECHO) 'LD prefix symbols : $(TGT_LD_PREFIX)'
538 @$(ECHO) 'LD ID symbols : $(TGT_LD_IDS)'
540 @$(ECHO) 'LD target flags : $(TGT_LD_FLAGS)'
542 @$(ECHO) 'makerom target flags : $(TGT_MAKEROM_FLAGS)'
544 @$(ECHO) 'Debugging objects : $(DEBUG_OBJS)'
545 @$(ECHO) 'Replaced objects : $(DEBUG_ORIG_OBJS)'
547 # List of objects included in the last build of blib. This is needed
548 # in order to correctly rebuild blib whenever the list of objects
551 BLIB_LIST := $(BIN)/.blib.list
552 ifeq ($(wildcard $(BLIB_LIST)),)
555 BLIB_LIST_OBJS := $(shell cat $(BLIB_LIST))
557 ifneq ($(BLIB_LIST_OBJS),$(BLIB_OBJS))
558 $(shell $(ECHO) "$(BLIB_OBJS)" > $(BLIB_LIST))
563 VERYCLEANUP += $(BLIB_LIST)
565 # Library of all objects
568 $(BLIB) : $(BLIB_OBJS) $(BLIB_LIST) $(MAKEDEPS)
570 $(QM)$(ECHO) " [AR] $@"
571 $(Q)$(AR) r $@ $(BLIB_OBJS)
575 # Build an intermediate object file from the objects required for the
578 $(BIN)/%.tmp : $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
579 $(QM)$(ECHO) " [LD] $@"
580 $(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $(BLIB) -o $@ \
581 -Map $(BIN)/$*.tmp.map
582 $(Q)$(OBJDUMP) -ht $@ | $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
584 # Keep intermediate object file (useful for debugging)
585 .PRECIOUS : $(BIN)/%.tmp
587 # Show a linker map for the specified target
589 $(BIN)/%.map : $(BIN)/%.tmp
590 @less $(BIN)/$*.tmp.map
592 # Extract compression information from intermediate object file
594 $(BIN)/%.zinfo : $(BIN)/%.tmp
595 $(QM)$(ECHO) " [ZINFO] $@"
596 $(Q)$(OBJCOPY) -O binary -j .zinfo $< $@
598 # Build raw binary file from intermediate object file
600 $(BIN)/%.bin : $(BIN)/%.tmp
601 $(QM)$(ECHO) " [BIN] $@"
602 $(Q)$(OBJCOPY) -O binary -R .zinfo $< $@
604 # Compress raw binary file
606 $(BIN)/%.zbin : $(BIN)/%.bin $(BIN)/%.zinfo $(ZBIN)
607 $(QM)$(ECHO) " [ZBIN] $@"
608 $(Q)$(ZBIN) $(BIN)/$*.bin $(BIN)/$*.zinfo > $@
610 # Rules for each media format. These are generated and placed in an
611 # external Makefile fragment. We could do this via $(eval ...), but
612 # that would require make >= 3.80.
614 # Note that there's an alternative way to generate most .rom images:
615 # they can be copied from their 'master' ROM image using cp and
616 # reprocessed with makerom to add the PCI IDs and ident string. The
617 # relevant rule would look something like:
619 # $(BIN)/dfe538%rom : $(BIN)/rtl8139%rom
623 # You can derive the ROM/driver relationships using the variables
624 # DRIVER_<rom> and/or ROMS_<driver>.
626 # We don't currently do this, because (a) it would require generating
627 # yet more Makefile fragments (since you need a rule for each ROM in
628 # ROMS), and (b) the linker is so fast that it probably wouldn't make
629 # much difference to the overall build time.
634 AUTO_MEDIA = $(filter-out $(NON_AUTO_MEDIA),$(MEDIA))
636 @$(ECHO) $(AUTO_MEDIA)
638 # media_template : create Makefile rules for specified media
640 # $(1) is the media name (e.g. "rom")
641 # $(2) is the full path to the .d file (e.g. "bin/deps/rom.media.d")
643 define media_template
645 @$(ECHO) " [MEDIADEPS] $(1)"
646 @$(MKDIR) -p $(dir $(2))
649 @$(ECHO_E) '$$(BIN)/%.$(1) : $$(BIN)/%.$(1).zbin' \
650 '\n\t$$(QM)$(ECHO) " [FINISH] $$@"' \
651 '\n\t$$(Q)$$(CP) $$< $$@' \
652 '\n\t$$(Q)$$(FINALISE_$(1))' \
657 # Rule to generate the Makefile rules to be included
659 $(BIN)/deps/%.media.d : $(MAKEDEPS)
660 $(if $(filter $(AUTO_MEDIA),$*), \
661 $(call media_template,$*,$@), \
662 @$(ECHO) 'ERROR: $* is not an AUTO_MEDIA' ; exit 1)
664 # Calculate and include the list of Makefile rules files
666 MEDIA_DEPS = $(patsubst %,$(BIN)/deps/%.media.d,$(AUTO_MEDIA))
668 @$(ECHO) $(MEDIA_DEPS)
670 ifneq ($(MEDIA_DEPS),)
671 -include $(MEDIA_DEPS)
675 # Wrap up binary blobs (for embedded images)
677 $(BIN)/%.o : payload/%.img
678 $(QM)echo " [WRAP] $@"
679 $(Q)$(LD) -b binary -r -o $@ $< --undefined obj_payload \
682 BOBJS += $(patsubst payload/%.img,$(BIN)/%.o,$(wildcard payload/*.img))
684 # The "allXXXs" targets for each suffix
686 allall: allroms allzroms allpxes allisos alldsks
687 allroms allzroms : all%s : $(foreach ROM,$(ROMS),$(BIN)/$(ROM).%)
688 allpxes allisos alldsks : all%s : $(foreach DRIVER,$(DRIVERS),$(BIN)/$(DRIVER).%)
692 $(BIN)/etherboot.% : $(BIN)/gpxe.%
693 ln -sf $(notdir $<) $@
697 ###############################################################################
699 # Rules for finalising files. TGT_MAKEROM_FLAGS is defined as part of
700 # the automatic build system and varies by target; it includes the
701 # "-p 0x1234,0x5678" string to set the PCI IDs.
703 FINALISE_rom = $(MAKEROM) $(MAKEROM_FLAGS) $(TGT_MAKEROM_FLAGS) \
706 # Some ROMs require specific flags to be passed to makerom.pl
708 MAKEROM_FLAGS_3c503 = -3
710 ###############################################################################
712 # The compression utilities
714 $(NRV2B) : util/nrv2b.c $(MAKEDEPS)
715 $(QM)$(ECHO) " [HOSTCC] $@"
716 $(Q)$(HOST_CC) -O2 -DENCODE -DDECODE -DMAIN -DVERBOSE -DNDEBUG \
717 -DBITSIZE=32 -DENDIAN=0 -o $@ $<
720 $(ZBIN) : util/zbin.c util/nrv2b.c $(MAKEDEPS)
721 $(QM)$(ECHO) " [HOSTCC] $@"
722 $(Q)$(HOST_CC) -O2 -o $@ $<
725 ###############################################################################
727 # The EFI image converter
729 $(ELF2EFI32) : util/elf2efi.c $(MAKEDEPS)
730 $(QM)$(ECHO) " [HOSTCC] $@"
731 $(Q)$(HOST_CC) -DMDE_CPU_IA32 -idirafter include -O2 \
732 -o $@ $< -lbfd -liberty
733 CLEANUP += $(ELF2EFI32)
735 $(ELF2EFI64) : util/elf2efi.c $(MAKEDEPS)
736 $(QM)$(ECHO) " [HOSTCC] $@"
737 $(Q)$(HOST_CC) -DMDE_CPU_X64 -idirafter include -O2 \
738 -o $@ $< -lbfd -liberty
739 CLEANUP += $(ELF2EFI64)
741 $(EFIROM) : util/efirom.c $(MAKEDEPS)
742 $(QM)$(ECHO) " [HOSTCC] $@"
743 $(Q)$(HOST_CC) -idirafter include -O2 -o $@ $<
746 ###############################################################################
748 # Auto-incrementing build serial number. Append "bs" to your list of
749 # build targets to get a serial number printed at the end of the
750 # build. Enable -DBUILD_SERIAL in order to see it when the code runs.
752 BUILDSERIAL_H = config/.buildserial.h
753 BUILDSERIAL_NOW = config/.buildserial.now
754 BUILDSERIAL_NEXT = config/.buildserial.next
756 $(BUILDSERIAL_NOW) $(BUILDSERIAL_NEXT) :
759 $(BUILDSERIAL_H) : $(BUILDSERIAL_NOW) $(BUILDSERIAL_NEXT)
760 $(ECHO) '#define BUILD_SERIAL_NUM $(shell cat $<)' > $@
762 ifeq ($(filter bs,$(MAKECMDGOALS)),bs)
763 $(shell diff -q $(BUILDSERIAL_NOW) $(BUILDSERIAL_NEXT) > /dev/null || \
764 cp -f $(BUILDSERIAL_NEXT) $(BUILDSERIAL_NOW))
767 bs : $(BUILDSERIAL_NOW)
768 @$(ECHO) $$(( $(shell cat $<) + 1 )) > $(BUILDSERIAL_NEXT)
769 @$(ECHO) "Build serial number is $(shell cat $<)"
771 ###############################################################################
773 # Build the TAGS file(s) for emacs
776 ctags -e -R -f $@ --exclude=bin
780 ###############################################################################
782 # Force rebuild for any given target
788 ###############################################################################
790 # Symbol table checks
795 SYMTAB = $(BIN)/symtab
797 $(OBJDUMP) -w -t $< > $@
799 CLEANUP += $(BIN)/symtab
806 ###############################################################################
808 # Build bochs symbol table
813 $(BIN)/%.bxs : $(BIN)/%.tmp
814 $(NM) $< | cut -d" " -f1,3 > $@
818 ###############################################################################
825 $(BIN)/doxygen.cfg : doxygen.cfg $(MAKEDEPS)
826 $(PERL) -pe 's{\@SRCDIRS\@}{$(SRCDIRS)}; ' \
827 -e 's{\@BIN\@}{$(BIN)}; ' \
828 -e 's{\@ARCH\@}{$(ARCH)}; ' \
831 $(BIN)/doc : $(BIN)/doxygen.cfg
836 VERYCLEANUP += $(BIN)/doc
841 @[ -f $(BIN)/doc/html/index.html ] || $(MAKE) $(BIN)/doc
842 @if [ -n "$$BROWSER" ] ; then \
843 ( $$BROWSER $(BIN)/doc/html/index.html & ) ; \
845 $(ECHO) "Documentation index in $(BIN)/doc/html/index.html" ; \
850 ###############################################################################
858 $(RM) -r $(VERYCLEANUP)