Browse Source

[build] Use $(eval) if available

When the $(eval) function is available (in GNU make >= 3.80), we can
evaluate many of the dynamically-generated Makefile rules directly.
This avoids generating a few hundred Makefile fragments in the
filesystem, and so speeds up the build process.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
05d11b7337
2 changed files with 113 additions and 48 deletions
  1. 108
    43
      src/Makefile.housekeeping
  2. 5
    5
      src/arch/i386/Makefile.pcbios

+ 108
- 43
src/Makefile.housekeeping View File

@@ -113,6 +113,18 @@ $(warning Use GNU ld instead)
113 113
 $(error Unsuitable build environment found)
114 114
 endif
115 115
 
116
+###############################################################################
117
+#
118
+# Check if $(eval ...) is available to use
119
+#
120
+
121
+HAVE_EVAL :=
122
+ifndef NO_EVAL
123
+$(eval HAVE_EVAL := yes)
124
+endif
125
+eval :
126
+	@$(ECHO) $(HAVE_EVAL)
127
+
116 128
 ###############################################################################
117 129
 #
118 130
 # Check for various tool workarounds
@@ -128,6 +140,11 @@ WORKAROUND_LDFLAGS :=
128 140
 COMMA	:= ,
129 141
 EMPTY	:=
130 142
 SPACE	:= $(EMPTY) $(EMPTY)
143
+HASH	:= \#
144
+define NEWLINE
145
+
146
+
147
+endef
131 148
 
132 149
 # Check for an old version of gas (binutils 2.9.1)
133 150
 #
@@ -675,83 +692,118 @@ $(BIN)/version.o : ../.git/index
675 692
 endif
676 693
 
677 694
 # We automatically generate rules for any file mentioned in AUTO_SRCS
678
-# using the following set of templates.  It would be cleaner to use
679
-# $(eval ...), but this function exists only in GNU make >= 3.80.
695
+# using the following set of templates.  We use $(eval ...) if
696
+# available, otherwise we generate separate Makefile fragments and
697
+# include them.
680 698
 
681 699
 # deps_template : generate dependency list for a given source file
682 700
 #
683 701
 # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
702
+#
703
+define deps_template_file
704
+$(call deps_template_parts,$(1),$(subst .,,$(suffix $(1))),$(basename $(notdir $(1))))
705
+endef
706
+#
707
+# $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
684 708
 # $(2) is the source type (e.g. "c")
685 709
 # $(3) is the source base name (e.g. "rtl8139")
686 710
 #
687
-define deps_template
711
+define deps_template_parts
688 712
 	@$(ECHO) "  [DEPS] $(1)"
689 713
 	@$(MKDIR) -p $(BIN)/deps/$(dir $(1))
690 714
 	$(Q)$(CPP) $(CFLAGS) $(CFLAGS_$(2)) $(CFLAGS_$(3)) -DOBJECT=$(3) \
691 715
 		-Wno-error -M $(1) -MG -MP | \
692 716
 		sed 's/\.o\s*:/_DEPS +=/' > $(BIN)/deps/$(1).d
717
+	$(Q)$(if $(findstring drivers/,$(1)),\
718
+	   $(PERL) $(PARSEROM) $(1) >> $(BIN)/deps/$(1).d)
693 719
 endef
694 720
 
695 721
 # rules_template : generate rules for a given source file
696 722
 #
697 723
 # $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
724
+#
725
+define rules_template
726
+$(call rules_template_parts,$(1),$(subst .,,$(suffix $(1))),$(basename $(notdir $(1))))
727
+endef
728
+#
729
+# $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
698 730
 # $(2) is the source type (e.g. "c")
699 731
 # $(3) is the source base name (e.g. "rtl8139")
700 732
 #
701
-define rules_template
733
+define rules_template_parts
734
+$$(BIN)/$(3).o : $(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(3)_DEPS)
735
+	$$(QM)$(ECHO) "  [BUILD] $$@"
736
+	$$(RULE_$(2))
737
+BOBJS += $$(BIN)/$(3).o
738
+$(foreach TGT,$(DEBUG_TARGETS),$(if $(RULE_$(2)_to_$(TGT)),$(NEWLINE)$(call rules_template_target,$(1),$(2),$(3),$(TGT))))
739
+$$(BIN)/deps/$(1).d : $$($(3)_DEPS)
740
+TAGS : $$($(3)_DEPS)
741
+endef
742
+#
743
+# $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
744
+# $(2) is the source type (e.g. "c")
745
+# $(3) is the source base name (e.g. "rtl8139")
746
+# $(4) is the destination type (e.g. "dbg%.o")
747
+#
748
+define rules_template_target
749
+$$(BIN)/$(3).$(4) : $(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(3)_DEPS)
750
+	$$(QM)$(ECHO) "  [BUILD] $$@"
751
+	$$(RULE_$(2)_to_$(4))
752
+$(TGT)_OBJS += $$(BIN)/$(3).$(4)
753
+endef
754
+#
755
+# $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
756
+#
757
+define rules_template_file
702 758
 	@$(ECHO) "  [RULES] $(1)"
703 759
 	@$(MKDIR) -p $(BIN)/rules/$(dir $(1))
704
-	@$(ECHO_E) '\n$$(BIN)/$(3).o :' \
705
-		 '$(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(3)_DEPS)' \
706
-		 '\n\t$$(QM)$(ECHO) "  [BUILD] $$@"' \
707
-		 '\n\t$$(RULE_$(2))\n' \
708
-		 '\nBOBJS += $$(BIN)/$(3).o\n' \
709
-		 $(foreach TGT,$(DEBUG_TARGETS), \
710
-		    $(if $(RULE_$(2)_to_$(TGT)), \
711
-		    '\n$$(BIN)/$(3).$(TGT) :' \
712
-		    '$(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(3)_DEPS)' \
713
-		    '\n\t$$(QM)$(ECHO) "  [BUILD] $$@"' \
714
-		    '\n\t$$(RULE_$(2)_to_$(TGT))\n' \
715
-		    '\n$(TGT)_OBJS += $$(BIN)/$(3).$(TGT)\n' ) ) \
716
-		 '\n$(BIN)/deps/$(1).d : $$($(3)_DEPS)\n' \
717
-		 '\nTAGS : $$($(3)_DEPS)\n' > $(BIN)/rules/$(1).r
718
-	@$(if $(findstring drivers/,$(1)),\
719
-	   $(PERL) $(PARSEROM) $(1) >> $(BIN)/rules/$(1).r)
760
+	@$(ECHO_E) '$(subst $(NEWLINE),\n,$(call rules_template,$(1)))' \
761
+		 > $(BIN)/rules/$(1).r
720 762
 endef
721 763
 
722
-# Rule to generate the dependency list file
764
+# Generate the dependency files
723 765
 #
724
-$(BIN)/deps/%.d : % $(MAKEDEPS)
725
-	$(call deps_template,$<,$(subst .,,$(suffix $<)),$(basename $(notdir $<)))
766
+$(BIN)/deps/%.d : % $(MAKEDEPS) $(PARSEROM)
767
+	$(call deps_template_file,$<)
726 768
 
727
-# Calculate and include the list of dependency list files
769
+# Calculate list of dependency files
728 770
 #
729 771
 AUTO_DEPS	= $(patsubst %,$(BIN)/deps/%.d,$(AUTO_SRCS))
772
+autodeps :
773
+	@$(ECHO) $(AUTO_DEPS)
774
+VERYCLEANUP	+= $(BIN)/deps
775
+
776
+# Include dependency files
777
+#
730 778
 ifdef NEED_DEPS
731 779
 ifneq ($(AUTO_DEPS),)
732 780
 -include $(AUTO_DEPS)
733 781
 endif
734 782
 endif
735
-autodeps :
736
-	@$(ECHO) $(AUTO_DEPS)
737
-VERYCLEANUP	+= $(BIN)/deps
738 783
 
739
-# Rule to generate the rules file
784
+# Generate the rules files
740 785
 #
741
-$(BIN)/rules/%.r : % $(MAKEDEPS) $(PARSEROM)
742
-	$(call rules_template,$<,$(subst .,,$(suffix $<)),$(basename $(notdir $<)))
786
+$(BIN)/rules/%.r : % $(MAKEDEPS)
787
+	$(call rules_template_file,$<)
743 788
 
744
-# Calculate and include the list of rules files
789
+# Calculate list of rules files
745 790
 #
746 791
 AUTO_RULES	= $(patsubst %,$(BIN)/rules/%.r,$(AUTO_SRCS))
792
+autorules :
793
+	@$(ECHO) $(AUTO_RULES)
794
+VERYCLEANUP	+= $(BIN)/rules
795
+
796
+# Evaluate rules (or include rules files)
797
+#
747 798
 ifdef NEED_DEPS
748 799
 ifneq ($(AUTO_RULES),)
800
+ifneq ($(HAVE_EVAL),)
801
+$(foreach SRC,$(AUTO_SRCS),$(eval $(call rules_template,$(SRC))))
802
+else
749 803
 -include $(AUTO_RULES)
750 804
 endif
751 805
 endif
752
-autorules :
753
-	@$(ECHO) $(AUTO_RULES)
754
-VERYCLEANUP	+= $(BIN)/rules
806
+endif
755 807
 
756 808
 # The following variables are created by the rules files
757 809
 #
@@ -1028,36 +1080,49 @@ AUTO_MEDIA	= $(filter-out $(NON_AUTO_MEDIA),$(MEDIA))
1028 1080
 automedia :
1029 1081
 	@$(ECHO) $(AUTO_MEDIA)
1030 1082
 
1031
-# media_template : create Makefile rules for specified media
1083
+# media_template : create media rules
1032 1084
 #
1033 1085
 # $(1) is the media name (e.g. "rom")
1034 1086
 #
1035 1087
 define media_template
1088
+$$(BIN)/%.$(1) : $$(BIN)/%.$(1).zbin
1089
+	$$(QM)echo "  [FINISH] $$@"
1090
+	$$(Q)$$(CP) $$< $$@
1091
+	$$(Q)$$(if $$(PAD_$(1)),$$(PAD_$(1)) $$@)
1092
+	$$(Q)$$(if $$(FINALISE_$(1)),$$(FINALISE_$(1)) $$@)
1093
+endef
1094
+#
1095
+# $(1) is the media name (e.g. "rom")
1096
+#
1097
+define media_template_file
1036 1098
 	@$(ECHO) "  [MEDIARULES] $(1)"
1037 1099
 	@$(MKDIR) -p $(BIN)/rules/$(dir $(1))
1038
-	@$(ECHO_E) '$$(BIN)/%.$(1) : $$(BIN)/%.$(1).zbin' \
1039
-		  '\n\t$$(QM)$(ECHO) "  [FINISH] $$@"' \
1040
-		  '\n\t$$(Q)$$(CP) $$< $$@' \
1041
-		  '\n\t$$(Q)$$(PAD_$(1))' \
1042
-		  '\n\t$$(Q)$$(FINALISE_$(1))' \
1100
+	@$(ECHO_E) '$(subst $(NEWLINE),\n,$(call media_template,$(1)))' \
1043 1101
 		> $(BIN)/rules/$(1).media.r
1044 1102
 endef
1045 1103
 
1046
-# Rule to generate the Makefile rules to be included
1104
+# Generate media rules files
1047 1105
 #
1048 1106
 $(BIN)/rules/%.media.r : $(MAKEDEPS)
1049
-	$(call media_template,$*)
1107
+	$(call media_template_file,$*)
1050 1108
 
1051
-# Calculate and include the list of Makefile rules files
1109
+# Calculate list of media rules files
1052 1110
 #
1053 1111
 MEDIA_RULES		= $(patsubst %,$(BIN)/rules/%.media.r,$(AUTO_MEDIA))
1054 1112
 mediarules :
1055 1113
 	@$(ECHO) $(MEDIA_RULES)
1114
+
1115
+# Evaluate media rules (or include media rules files)
1116
+#
1056 1117
 ifdef NEED_DEPS
1057 1118
 ifneq ($(MEDIA_RULES),)
1119
+ifneq ($(HAVE_EVAL),)
1120
+$(foreach MEDIUM,$(AUTO_MEDIA),$(eval $(call media_template,$(MEDIUM))))
1121
+else
1058 1122
 -include $(MEDIA_RULES)
1059 1123
 endif
1060 1124
 endif
1125
+endif
1061 1126
 
1062 1127
 # Wrap up binary blobs (for embedded images)
1063 1128
 #

+ 5
- 5
src/arch/i386/Makefile.pcbios View File

@@ -29,15 +29,15 @@ MEDIA		+= exe
29 29
 
30 30
 # Padding rules
31 31
 #
32
-PAD_rom		= $(PERL) $(PADIMG) --blksize=512 --byte=0xff $@
32
+PAD_rom		= $(PERL) $(PADIMG) --blksize=512 --byte=0xff
33 33
 PAD_mrom	= $(PAD_rom)
34
-PAD_dsk		= $(PERL) $(PADIMG) --blksize=512 $@
35
-PAD_hd		= $(PERL) $(PADIMG) --blksize=32768 $@
36
-PAD_exe		= $(PERL) $(PADIMG) --blksize=512 $@
34
+PAD_dsk		= $(PERL) $(PADIMG) --blksize=512
35
+PAD_hd		= $(PERL) $(PADIMG) --blksize=32768
36
+PAD_exe		= $(PERL) $(PADIMG) --blksize=512
37 37
 
38 38
 # Finalisation rules
39 39
 #
40
-FINALISE_rom	= $(PERL) $(FIXROM) $@
40
+FINALISE_rom	= $(PERL) $(FIXROM)
41 41
 FINALISE_mrom	= $(FINALISE_rom)
42 42
 
43 43
 # rule to make a non-emulation ISO boot image

Loading…
Cancel
Save