This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Replace makefile fragments by use of $(eval ...)
- From: Andreas Schwab <schwab at linux-m68k dot org>
- To: libc-alpha at sourceware dot org
- Date: Thu, 12 Jul 2012 17:31:08 +0200
- Subject: [PATCH] Replace makefile fragments by use of $(eval ...)
This patch replaces repated uses of include with $(eval) to avoid
reading the same makefile fragment many times, instead evaluating the
result of the expansion directly. This gives a speedup of 1.5% to 2.5%
for an empty run (everything up-to-date). The $(eval) function was
added in 3.80, so I had to bump the minimum make version a bit.
Andreas.
* configure.in: Check for GNU make 3.80 or later.
* configure: Regenerated.
* manual/install.texi (Tools for Compilation): Bump minimum
version for GNU make to 3.80.
* INSTALL: Regenerated.
* Makeconfig (o-iterator, cppflags-iterator): Define.
* Makerules (o-iterator): Remove.
Use `$(call o-iterator,...)' instead of `include
$(o-iterator)' and `$(call cppflags-iterator,...)' instead of
including cppflags-iterator.mk. Replace use of extra-modules.mk
by use of $(eval ...).
* elf/Makefile: Likewise.
* elf/rtld-Rules: Likewise.
* extra-lib.mk: Likewise.
* locale/Makefile: Likewise.
* math/Makefile: Likewise.
* nscd/Makefile: Likewise.
* sunrpc/Makefile: Likewise.
* cppflags-iterator.mk: Removed.
* extra-modules.mk: Removed.
* o-iterator.mk: Removed.
---
INSTALL | 4 ++--
Makeconfig | 12 +++++++++++
Makerules | 58 +++++++++++++++-------------------------------------
configure | 2 +-
configure.in | 2 +-
cppflags-iterator.mk | 7 -------
elf/Makefile | 3 +--
elf/rtld-Rules | 3 +--
extra-lib.mk | 10 ++-------
extra-modules.mk | 9 --------
locale/Makefile | 7 +++----
manual/install.texi | 4 ++--
math/Makefile | 3 +--
nscd/Makefile | 4 +---
o-iterator.mk | 9 --------
sunrpc/Makefile | 7 ++-----
16 files changed, 45 insertions(+), 99 deletions(-)
delete mode 100644 cppflags-iterator.mk
delete mode 100644 extra-modules.mk
delete mode 100644 o-iterator.mk
diff --git a/INSTALL b/INSTALL
index d4fabe9..91f94ec 100644
--- a/INSTALL
+++ b/INSTALL
@@ -272,12 +272,12 @@ Recommended Tools for Compilation
We recommend installing the following GNU tools before attempting to
build the GNU C Library:
- * GNU `make' 3.79 or newer
+ * GNU `make' 3.80 or newer
You need the latest version of GNU `make'. Modifying the GNU C
Library to work with other `make' programs would be so difficult
that we recommend you port GNU `make' instead. *Really.* We
- recommend GNU `make' version 3.79. All earlier versions have
+ recommend GNU `make' version 3.80. All earlier versions have
severe bugs or lack features.
* GCC 4.3 or newer, GCC 4.6 recommended
diff --git a/Makeconfig b/Makeconfig
index 859b588..21553a4 100644
--- a/Makeconfig
+++ b/Makeconfig
@@ -1010,6 +1010,18 @@ endif
sysd-rules-targets := $(sort $(foreach p,$(sysd-rules-patterns),\
$(firstword $(subst :, ,$p))))
+# This variable can be called with one argument as in
+# ``$(call o-iterator,$(list))'' after defining $(o-iterator-doit) to produce
+# some desired rule using $o; $(o-iterator-doit) is evaluated for each word
+# in $(list).
+o-iterator = $(foreach o,$(1),$(eval $(o-iterator-doit)))
+
+# This variable can be called with two arguments as in
+# ``$(call cppflags-iterator,$(list),$(lib))''; it causes the appropriate
+# CPPFLAGS and CFLAGS for $(lib) be used of each element in $(list).
+cppflags-iterator = $(foreach cpp-src,$(1),$(eval \
+libof-$(notdir $(cpp-src)) := $(2)))
+
endif # Makeconfig not yet included
# Local Variables:
diff --git a/Makerules b/Makerules
index 685b1b8..c3e5ed4 100644
--- a/Makerules
+++ b/Makerules
@@ -54,12 +54,6 @@ endif
ifndef +included-Makeconfig
include $(..)Makeconfig
endif
-
-# This variable is used in ``include $(o-iterator)'' after defining
-# $(o-iterator-doit) to produce some desired rule using $o for the object
-# suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
-# is produced for each object suffix in use.
-o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
# Include any system-specific makefiles.
@@ -271,20 +265,17 @@ endif
define o-iterator-doit
$(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
endef
-object-suffixes-left := $(all-object-suffixes)
-include $(o-iterator)
+$(call o-iterator,$(all-object-suffixes))
define o-iterator-doit
$(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
endef
-object-suffixes-left := $(all-object-suffixes)
-include $(o-iterator)
+$(call o-iterator,$(all-object-suffixes))
define o-iterator-doit
$(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
endef
-object-suffixes-left := $(all-object-suffixes)
-include $(o-iterator)
+$(call o-iterator,$(all-object-suffixes))
# Omit the objpfx rules when building in the source tree, because
# objpfx is empty and so these rules just override the ones above.
@@ -294,14 +285,12 @@ ifdef objpfx
define o-iterator-doit
$(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
endef
-object-suffixes-left := $(all-object-suffixes)
-include $(o-iterator)
+$(call o-iterator,$(all-object-suffixes))
define o-iterator-doit
$(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
endef
-object-suffixes-left := $(all-object-suffixes)
-include $(o-iterator)
+$(call o-iterator,$(all-object-suffixes))
endif
# Generate version maps, but wait until sysdep-subdirs is known
@@ -622,11 +611,8 @@ endif
# The makefile may define $(modules-names) to build additional modules.
# These are built with $(build-module), except any in $(modules-names-nobuild).
ifdef modules-names
-# extra-lib.mk is included once for each extra lib to define rules
-# to build it, and to add its objects to the various variables.
-# During its evaluation, $(lib) is set to the name of the library.
-extra-modules-left := $(modules-names)
-include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
+$(foreach module,$(modules-names),$(eval \
+CPPFLAGS-$(module).c += -DNOT_IN_libc))
extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
$(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
@@ -734,8 +720,7 @@ $(make-target-directory)
echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
mv -f $@T $@
endef
-object-suffixes-left := $(object-suffixes-for-libc)
-include $(o-iterator)
+$(call o-iterator,$(object-suffixes-for-libc))
endif
@@ -754,8 +739,7 @@ subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
ifndef subdir
$(subdirs-stamps): subdir_lib;
endif
-object-suffixes-left = $(object-suffixes-for-libc)
-include $(o-iterator)
+$(call o-iterator,$(object-suffixes-for-libc))
# This makes all the object files.
@@ -955,18 +939,14 @@ ifneq (,$(versioned))
define o-iterator-doit
$(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
endef
-object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
-ifneq (,$(object-suffixes-left))
-include $(o-iterator)
-endif
+$(call o-iterator,$(filter-out $(install-lib-ldscripts),$(versioned)))
# Make symlinks in the build directory, because the versioned names might
# be referenced by a DT_NEEDED in another library.
define o-iterator-doit
$(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
endef
-object-suffixes-left := $(versioned)
-include $(o-iterator)
+$(call o-iterator,$(versioned))
generated += $(foreach o,$(versioned),$o$($o-version))
@@ -976,30 +956,26 @@ $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
$(+force);
$$(make-shlib-link)
endef
-object-suffixes-left := $(versioned)
-include $(o-iterator)
+$(call o-iterator,$(versioned))
define o-iterator-doit
$(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
$$(do-install-program)
endef
-object-suffixes-left := $(versioned)
-include $(o-iterator)
+$(call o-iterator,$(versioned))
else
define o-iterator-doit
$(inst_slibdir)/$o$($o-version): \
$(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
$$(make-shlib-link)
endef
-object-suffixes-left := $(versioned)
-include $(o-iterator)
+$(call o-iterator,$(versioned))
define o-iterator-doit
$(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
$$(do-install-program)
endef
-object-suffixes-left := $(versioned)
-include $(o-iterator)
+$(call o-iterator,$(versioned))
endif
endif
@@ -1131,9 +1107,7 @@ xcheck: xtests
all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
ifneq (,$(all-nonlib))
-cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
-lib := nonlib
-include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
+$(call cppflags-iterator,$(all-nonlib:=.c) $(all-nonlib:=.cc),nonlib)
endif
# The include magic above causes those files to use this variable for flags.
diff --git a/configure b/configure
index 1268168..53c1950 100755
--- a/configure
+++ b/configure
@@ -4810,7 +4810,7 @@ $as_echo_n "checking version of $MAKE... " >&6; }
ac_prog_version=`$MAKE --version 2>&1 | sed -n 's/^.*GNU Make[^0-9]*\([0-9][0-9.]*\).*$/\1/p'`
case $ac_prog_version in
'') ac_prog_version="v. ?.??, bad"; ac_verc_fail=yes;;
- 3.79* | 3.[89]*)
+ 3.[89]* | [4-9].*)
ac_prog_version="$ac_prog_version, ok"; ac_verc_fail=no;;
*) ac_prog_version="$ac_prog_version, bad"; ac_verc_fail=yes;;
diff --git a/configure.in b/configure.in
index 6b6dde5..347fd79 100644
--- a/configure.in
+++ b/configure.in
@@ -919,7 +919,7 @@ AC_CHECK_PROG_VER(CC, ${ac_tool_prefix}gcc ${ac_tool_prefix}cc, -v,
critic_missing="$critic_missing gcc")
AC_CHECK_PROG_VER(MAKE, gnumake gmake make, --version,
[GNU Make[^0-9]*\([0-9][0-9.]*\)],
- [3.79* | 3.[89]*], critic_missing="$critic_missing make")
+ [3.[89]* | [4-9].*], critic_missing="$critic_missing make")
AC_CHECK_PROG_VER(MSGFMT, gnumsgfmt gmsgfmt msgfmt, --version,
[GNU gettext.* \([0-9]*\.[0-9.]*\)],
diff --git a/cppflags-iterator.mk b/cppflags-iterator.mk
deleted file mode 100644
index 89a472b..0000000
--- a/cppflags-iterator.mk
+++ /dev/null
@@ -1,7 +0,0 @@
-# This file is included several times in a row, once
-# for each element of $(lib)-routines and $(lib)-sysdeps_routines.
-
-cpp-src := $(firstword $(cpp-srcs-left))
-cpp-srcs-left := $(filter-out $(cpp-src),$(cpp-srcs-left))
-
-libof-$(notdir $(cpp-src)) := $(lib)
diff --git a/elf/Makefile b/elf/Makefile
index 9054199..1b843dd 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -1140,8 +1140,7 @@ define o-iterator-doit
$(objpfx)tst-initorder2$o.os: tst-initorder2.c; \
$$(compile-command.c) -DNAME=\"$o\"
endef
-object-suffixes-left := a b c d
-include $(o-iterator)
+$(call o-iterator,a b c d)
$(objpfx)tst-initorder2.out: $(objpfx)tst-initorder2
$(elf-objpfx)${rtld-installed-name} \
diff --git a/elf/rtld-Rules b/elf/rtld-Rules
index 1e03332..b797a6f 100644
--- a/elf/rtld-Rules
+++ b/elf/rtld-Rules
@@ -61,12 +61,11 @@ endif # not -s
# For each subdirectory, define a pattern rule that makes all of that
# subdirectory's modules at once with one recursive make command.
-object-suffixes-left := $(rtld-subdirs)
define o-iterator-doit
$(foreach obj,$(rtld-$o),$(common-objpfx)%/rtld-$(obj)): FORCE ; \
+$$(rtld-subdir-make)
endef
-include $(patsubst %,../o-iterator.mk,$(object-suffixes-left))
+$(call o-iterator,$(rtld-subdirs))
# This is how we descend into each subdirectory. See below.
define rtld-subdir-make
diff --git a/extra-lib.mk b/extra-lib.mk
index a2293c5..e9d2aa9 100644
--- a/extra-lib.mk
+++ b/extra-lib.mk
@@ -57,7 +57,6 @@ endif
# Use o-iterator.mk to generate a rule for each flavor of library.
-ifneq (,$(filter-out .os .oS,$(object-suffixes-$(lib))))
define o-iterator-doit
$(objpfx)$(patsubst %,$(libtype$o),$(lib:lib%=%)): \
$(patsubst %,$(objpfx)%$o,\
@@ -65,9 +64,7 @@ $(objpfx)$(patsubst %,$(libtype$o),$(lib:lib%=%)): \
$(all-$(lib)-routines))); \
$$(build-extra-lib)
endef
-object-suffixes-left = $(filter-out .os .oS,$(object-suffixes-$(lib)))
-include $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
-endif
+$(call o-iterator,$(filter-out .os .oS,$(object-suffixes-$(lib))))
ifneq (,$(filter .os,$(object-suffixes-$(lib))))
$(objpfx)$(patsubst %,$(libtype.os),$(lib:lib%=%)): \
@@ -96,9 +93,6 @@ endif
endif
# This will define `libof-ROUTINE := LIB' for each of the routines.
-cpp-srcs-left := $($(lib)-routines) $($(lib)-sysdep_routines)
-ifneq (,$(cpp-srcs-left))
-include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
-endif
+$(call cppflags-iterator,$($(lib)-routines) $($(lib)-sysdep_routines),$(lib))
CPPFLAGS-$(lib) := -DNOT_IN_libc=1 -DIS_IN_$(lib)=1 -DIN_LIB=$(lib)
diff --git a/extra-modules.mk b/extra-modules.mk
deleted file mode 100644
index c7ed850..0000000
--- a/extra-modules.mk
+++ /dev/null
@@ -1,9 +0,0 @@
-# This file is included several times in a row, once
-# for each element of $(modules-names). $(extra-modules-left)
-# is initialized first to $(modules-names) so that with each
-# inclusion, we advance $(module) to the next name.
-
-module := $(firstword $(extra-modules-left))
-extra-modules-left := $(filter-out $(module),$(extra-modules-left))
-
-CPPFLAGS-$(module).c += -DNOT_IN_libc
diff --git a/locale/Makefile b/locale/Makefile
index 42c6772..1ecc51c 100644
--- a/locale/Makefile
+++ b/locale/Makefile
@@ -93,10 +93,9 @@ CFLAGS-locfile.c = -Wno-write-strings -Wno-char-subscripts
CFLAGS-charmap-dir.c = -Wno-write-strings
# This makes sure -DNOT_IN_libc et al are passed for all these modules.
-cpp-srcs-left := $(addsuffix .c,$(localedef-modules) $(localedef-aux) \
- $(locale-modules) $(lib-modules))
-lib := locale-programs
-include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
+locale-srcs = $(addsuffix .c,$(localedef-modules) $(localedef-aux) \
+ $(locale-modules) $(lib-modules))
+$(call cppflags-iterator,$(locale-srcs),locale-programs)
# Depend on libc.so so a DT_NEEDED is generated in the shared objects.
# This ensures they will load libc.so for needed symbols if loaded by
diff --git a/manual/install.texi b/manual/install.texi
index 5aca058..08f6fb7 100644
--- a/manual/install.texi
+++ b/manual/install.texi
@@ -307,12 +307,12 @@ build @theglibc{}:
@itemize @bullet
@item
-GNU @code{make} 3.79 or newer
+GNU @code{make} 3.80 or newer
You need the latest version of GNU @code{make}. Modifying @theglibc{}
to work with other @code{make} programs would be so difficult that
we recommend you port GNU @code{make} instead. @strong{Really.} We
-recommend GNU @code{make} version 3.79. All earlier versions have severe
+recommend GNU @code{make} version 3.80. All earlier versions have severe
bugs or lack features.
@item
diff --git a/math/Makefile b/math/Makefile
index 60e3899..7ab0b7b 100644
--- a/math/Makefile
+++ b/math/Makefile
@@ -153,8 +153,7 @@ include ../Rules
define o-iterator-doit
$(objpfx)m_%$o: s_%.c $(before-compile); $$(compile-command.c)
endef
-object-suffixes-left := $(all-object-suffixes)
-include $(o-iterator)
+$(call o-iterator,$(all-object-suffixes))
# This file defines the default _LIB_VERSION variable that controls
diff --git a/nscd/Makefile b/nscd/Makefile
index ba052eb..26e1a61 100644
--- a/nscd/Makefile
+++ b/nscd/Makefile
@@ -119,9 +119,7 @@ LDFLAGS-nscd = -Wl,-z,now
endif
# This makes sure -DNOT_IN_libc is passed for all these modules.
-cpp-srcs-left := $(nscd-modules:=.c)
-lib := nonlib
-include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
+$(call cppflags-iterator,$(nscd-modules:=.c),nonlib)
$(objpfx)nscd: $(nscd-modules:%=$(objpfx)%.o)
diff --git a/o-iterator.mk b/o-iterator.mk
deleted file mode 100644
index 18a6e48..0000000
--- a/o-iterator.mk
+++ /dev/null
@@ -1,9 +0,0 @@
-# This file is included several times in a row, once
-# for each element of $(object-suffixes). $(object-suffixes-left)
-# is initialized first to $(object-suffixes) so that with each
-# inclusion, we advance $o to the next suffix.
-
-o := $(firstword $(object-suffixes-left))
-object-suffixes-left := $(filter-out $o,$(object-suffixes-left))
-
-$(o-iterator-doit)
diff --git a/sunrpc/Makefile b/sunrpc/Makefile
index 48a458a..75745da 100644
--- a/sunrpc/Makefile
+++ b/sunrpc/Makefile
@@ -169,9 +169,7 @@ $(objpfx)cross-rpcgen: $(cross-rpcgen-objs)
$(BUILD_CC) $^ $(BUILD_LDFLAGS) -o $@
# This makes sure -DNOT_IN_libc is passed for all these modules.
-cpp-srcs-left := $(rpcgen-objs:.o=.c)
-lib := nonlib
-include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
+$(call cppflags-iterator,$(rpcgen-objs:.o=.c), nonlib)
# How we run rpcgen to generate sources and headers in the rules below.
# Setting CPP tells it how to run the C preprocessor correctly. Note
@@ -210,8 +208,7 @@ $(objpfx)x%.stmp: rpcsvc/%.x $(objpfx)cross-rpcgen
define o-iterator-doit
$(rpcsvc:%.x=$(objpfx)x%$o): $(objpfx)x%$o: $(objpfx)x%.c $(objpfx)rpcsvc/%.h
endef
-object-suffixes-left = $(filter-out $(librpcsvc-inhibit-o),$(object-suffixes))
-include $(o-iterator)
+$(call o-iterator,$(filter-out $(librpcsvc-inhibit-o),$(object-suffixes)))
rpcsvc-dt-files := $(foreach o,$(filter-out $(librpcsvc-inhibit-o),\
$(object-suffixes)),\
--
1.7.11.2
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."