]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - Makerules
* Makeconfig (sysd-rules-patterns): New variable.
[thirdparty/glibc.git] / Makerules
index 28a7028d10e3c348ef07678ee6c0ffc94c96aa99..3661ad4e9d2c1b04512f595dfe773e4ac817e80d 100644 (file)
--- a/Makerules
+++ b/Makerules
@@ -1,4 +1,4 @@
-# Copyright (C) 1991-2002, 2003 Free Software Foundation, Inc.
+# Copyright (C) 1991-2006, 2007, 2008 Free Software Foundation, Inc.
 # This file is part of the GNU C Library.
 
 # The GNU C Library is free software; you can redistribute it and/or
@@ -56,22 +56,6 @@ ifndef +included-Makeconfig
 include $(..)Makeconfig
 endif
 
-# `configure' writes a definition of `config-sysdirs' in `config.make'.
-sysdirs = $(strip $(full_config_sysdirs))
-
-+sysdir_pfx = $(common-objpfx)
-
-export sysdirs := $(sysdirs)
-
-+sysdep_dirs := $(full_config_sysdirs)
-ifdef objdir
-+sysdep_dirs := $(objdir) $(+sysdep_dirs)
-endif
-
-# Add -I switches to get the right sysdep directories.
-# `+includes' in Makeconfig references $(+sysdep-includes).
-+sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
-
 # 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
@@ -94,7 +78,7 @@ vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
 # being included individually by a subdir makefile (hurd/Makefile needs this).
 in-Makerules := yes
 
-sysdep-makefiles := $(wildcard $(full_config_sysdirs:=/Makefile))
+sysdep-makefiles := $(wildcard $(sysdirs:=/Makefile))
 ifneq (,$(sysdep-makefiles))
 include $(sysdep-makefiles)
 endif
@@ -125,29 +109,9 @@ $(common-objpfx)%.latest: $(common-objpfx)abi-versions.h
 endif # avoid-generated
 endif # $(versioning) = yes
 
-
-# Generating headers for assembly constants.
-# We need this defined early to get into before-compile before
-# it's used in sysd-rules, below.
-$(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
-                                          %.sym $(before-compile)
-       $(AWK) -f $< $(filter %.sym,$^) \
-       | $(CC) -S -o - $(CFLAGS) $(CPPFLAGS) -x c - \
-               -MD -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)' \
-       | sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' > $(@:.h.d=.h)T
-       sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
-           $(@:.h=.h.d)T > $(@:.h=.h.d)T2
-       rm -f $(@:.h=.h.d)T
-       mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
-       mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
-vpath %.sym $(sysdirs)
-before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
-
-
-# When we have no deps pass doing it, then make sure the subdirectory
-# for object files gets created.
-ifdef no_deps
+# Make sure the subdirectory for object files gets created.
 ifdef objpfx
+ifeq (,$(wildcard $(objpfx).))
 before-compile += $(objpfx).
 $(objpfx).:
        $(make-target-directory)
@@ -166,25 +130,71 @@ ifdef before-compile
 $(before-compile):
 endif
 
+# We don't want $(common-objpfx) files to depend on miscellaneous stuff
+# in subdirs.
+ifdef subdir
+common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
+else
+common-before-compile = $(before-compile)
+endif
+
+ifndef subdir
 # If a makefile needs to do something conditional on something that
 # can only be figured out from headers, write a FOO.make.c input
 # file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
 # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
-$(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(before-compile)
+#
+# We only generate these in the top-level makefile, to avoid any weirdness
+# from subdir-specific makefile tweaks creeping in on an update.
+$(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
        rm -f $@T $@.dT
        (echo '# Generated from $*.make.c by Makerules.'; \
-        SUNPRO_DEPENDENCIES='$@.dT $$(common-objpfx)$*.make' \
-        $(CC) $(CFLAGS) $(CPPFLAGS) -E $< \
+        $(CC) $(CFLAGS) $(CPPFLAGS) -E -DASSEMBLER $< \
+              -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
         | sed -n '/@@@/{s/@@@[  ]*\(.*\)@@@/\1/;s/[     ]*$$//p;}'; \
         echo 'common-generated += $(@F)'; \
         sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
         rm -f $@.dT) > $@T
        mv -f $@T $@
+endif
 
 ifdef subdir
-sed-remove-dotdot := -e 's@  *\.\.\/\([^       \]*\)@ $$(..)\1@g'
+sed-remove-dotdot := -e 's@  *\.\.\/\([^       \]*\)@ $$(..)\1@g' \
+                    -e 's@^\.\.\/\([^  \]*\)@$$(..)\1@g'
 else
-sed-remove-dotdot := -e 's@  *\([^     \/$$][^         \]*\)@ $$(..)\1@g'
+sed-remove-dotdot := -e 's@  *\([^     \/$$][^         \]*\)@ $$(..)\1@g' \
+                    -e 's@^\([^        \/$$][^         \]*\)@$$(..)\1@g'
+endif
+
+
+ifdef gen-as-const-headers
+# Generating headers for assembly constants.
+# We need this defined early to get into before-compile before
+# it's used in sysd-rules, below.
+$(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
+                                          %.sym $(common-before-compile)
+       $(AWK) -f $< $(filter %.sym,$^) \
+       | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
+               -MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
+       sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
+               $(@:.h.d=.h)T3 > $(@:.h.d=.h)T
+       rm -f $(@:.h.d=.h)T3
+       sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
+           $(@:.h=.h.d)T > $(@:.h=.h.d)T2
+       rm -f $(@:.h=.h.d)T
+       mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
+       mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
+vpath %.sym $(sysdirs)
+before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
+
+tests += $(gen-as-const-headers:%.sym=test-as-const-%)
+generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
+$(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
+                           %.sym $(common-objpfx)%.h
+       ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
+        $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
+        echo '#include "$(..)test-skeleton.c"') > $@T
+       mv -f $@T $@
 endif
 \f
 # Generate an ordered list of implicit rules which find the source files in
@@ -193,40 +203,79 @@ endif
 # later directory would be chosen over a .c file in an earlier directory,
 # which does not preserve the desired sysdeps ordering behavior.
 
-# When making the list of .d files to include, we can't know which ones
-# have source in .s files, and thus do not in fact need a .d file.
-# So we must define rules to make .d files for .s files.
-define make-dummy-dep
-$(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
+# System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
+# patterns matching sysdep directories whose assembly source files should
+# be suppressed.
+ifdef inhibit-sysdep-asm
+define check-inhibit-asm
+case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) asm= ;; esac;
 endef
-$(common-objpfx)dummy.d:
-       echo '# .s files cannot contain includes, so they need no deps.' > $@
-
-# It matters that this set of rules, for compiling from sources in
-# the current directory (the $srcdir/$subdir) come before the
-# generated sysdep rules in included from sysd-rules below.  When
-# compiling in the source tree, generated sources go into the current
-# directory, and those should be chosen before any sources in sysdeps.
+endif
+
+-include $(common-objpfx)sysd-rules
+ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
+# The value of $(+sysdep_dirs) the sysd-rules was computed for
+# differs from the one we are using now.  So force a rebuild of sysd-rules.
+sysd-rules-force = FORCE
+FORCE:
+endif
+$(common-objpfx)sysd-rules: $(common-objpfx)config.make $(..)Makerules \
+                           $(sysdep-makefiles) $(sysd-rules-force)
+       -@rm -f $@T
+       (echo 'sysd-rules-sysdirs := $(config-sysdirs)';                      \
+        for dir in $(config-sysdirs); do                                     \
+          case "$$dir" in                                                    \
+          /*) ;;                                                             \
+          *) dir="\$$(..)$$dir" ;;                                           \
+          esac;                                                              \
+          asm='.S .s';                                                       \
+          $(check-inhibit-asm)                                               \
+          for o in $(all-object-suffixes); do                                \
+            set $(subst :, ,$(sysd-rules-patterns));                         \
+            while [ $$# -ge 2 ]; do                                          \
+              t=$$1; shift;                                                  \
+              d=$$1; shift;                                                  \
+              v=$${t%%%}; [ x"$$v" = x ] || v="\$$($${v}CPPFLAGS)";          \
+              for s in $$asm .c; do                                          \
+                echo "\$$(objpfx)$$t$$o: $$dir/$$d$$s \$$(before-compile)";  \
+                echo " \$$(compile-command$$s) $$v";                         \
+              done;                                                          \
+            done;                                                            \
+          done;                                                              \
+          echo "\$$(inst_includedir)/%.h: $$dir/%.h \$$(+force)";            \
+          echo "       \$$(do-install)";                                     \
+        done;                                                                \
+        echo 'sysd-rules-done = t') > $@T
+       mv -f $@T $@
+
+ifndef sysd-rules-done
+# Don't do deps until this exists, because it provides rules to make the deps.
+no_deps=t
+endif
+
 define o-iterator-doit
 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
 endef
 object-suffixes-left := $(all-object-suffixes)
 include $(o-iterator)
-$(objpfx)%.d: %.S $(before-compile); $(+make-deps)
 
 define o-iterator-doit
 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
 endef
 object-suffixes-left := $(all-object-suffixes)
 include $(o-iterator)
-$(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
 
 define o-iterator-doit
 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
 endef
 object-suffixes-left := $(all-object-suffixes)
 include $(o-iterator)
-$(objpfx)%.d: %.c $(before-compile); $(+make-deps)
+
+define o-iterator-doit
+$(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
+endef
+object-suffixes-left := $(all-object-suffixes)
+include $(o-iterator)
 
 # Omit the objpfx rules when building in the source tree, because
 # objpfx is empty and so these rules just override the ones above.
@@ -238,106 +287,20 @@ $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
 endef
 object-suffixes-left := $(all-object-suffixes)
 include $(o-iterator)
-$(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
 
 define o-iterator-doit
 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
 endef
 object-suffixes-left := $(all-object-suffixes)
 include $(o-iterator)
-$(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
 
 define o-iterator-doit
 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
 endef
 object-suffixes-left := $(all-object-suffixes)
 include $(o-iterator)
-$(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
-endif
-
-# System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
-# patterns matching sysdep directories whose assembly source files should
-# be suppressed.
-ifdef inhibit-sysdep-asm
-define open-check-inhibit-asm
-case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
-endef
-close-check-inhibit-asm = ;; esac ;
-endif
-
--include $(+sysdir_pfx)sysd-rules
-ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
-# The value of $(+sysdep_dirs) the sysd-rules was computed for
-# differs from the one we are using now.  So force a rebuild of sysd-rules.
-sysd-rules-force = FORCE
-FORCE:
-endif
-$(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
-                         $(wildcard $(foreach dir,$(sysdirs),\
-                                              $(dir)/Makefile))\
-                         $(sysd-rules-force)
-       -@rm -f $@T
-       (echo 'sysd-rules-sysdirs := $(config-sysdirs)';                      \
-        for dir in $(config-sysdirs:%='$$(..)%'); do                         \
-          for o in $(all-object-suffixes); do \
-            $(open-check-inhibit-asm) \
-            echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
-                 \$$(compile-command.S)";                                    \
-            echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
-                 \$$(compile-command.s)";                                    \
-            echo "\$$(objpfx)rtld-%$$o: $$dir/%.S \$$(before-compile); \
-                 \$$(compile-command.S)";                                    \
-            echo "\$$(objpfx)rtld-%$$o: $$dir/%.s \$$(before-compile); \
-                 \$$(compile-command.s)";                                    \
-            echo "\$$(objpfx)ptw-%$$o: $$dir/%.S \$$(before-compile); \
-                 \$$(compile-command.S)";                                    \
-            echo "\$$(objpfx)ptw-%$$o: $$dir/%.s \$$(before-compile); \
-                 \$$(compile-command.s)";                                    \
-            $(close-check-inhibit-asm) \
-            echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
-                 \$$(compile-command.c)";                                    \
-            echo "\$$(objpfx)rtld-%$$o: $$dir/%.c \$$(before-compile); \
-                 \$$(compile-command.c)";                                    \
-            echo "\$$(objpfx)ptw-%$$o: $$dir/%.c \$$(before-compile); \
-                 \$$(compile-command.c)";                                    \
-          done; \
-          $(open-check-inhibit-asm) \
-          echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
-               \$$(make-dummy-dep)";                          \
-          echo "\$$(objpfx)rtld-%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
-               \$$(make-dummy-dep)";                          \
-          echo "\$$(objpfx)ptw-%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
-               \$$(make-dummy-dep)";                          \
-          echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
-               \$$(+make-deps)";                                             \
-          echo "\$$(objpfx)rtld-%.d: $$dir/%.S \$$(before-compile); \
-               \$$(+make-deps)";                                             \
-          echo "\$$(objpfx)ptw-%.d: $$dir/%.S \$$(before-compile); \
-               \$$(+make-deps)";                                             \
-          $(close-check-inhibit-asm)   \
-          echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
-               \$$(+make-deps)";                                             \
-          echo "\$$(objpfx)rtld-%.d: $$dir/%.c \$$(before-compile); \
-               \$$(+make-deps)";                                             \
-          echo "\$$(objpfx)ptw-%.d: $$dir/%.c \$$(before-compile); \
-               \$$(+make-deps)";                                             \
-          echo "\$$(objpfx)m_%.S: $$dir/s_%.S; \$$(+make-include-of-dep)";   \
-          echo "\$$(objpfx)m_%.c: $$dir/s_%.c; \$$(+make-include-of-dep)";   \
-        done;                                                                \
-        echo 'sysd-rules-done = t') > $@T
-       mv -f $@T $@
-
-ifndef sysd-rules-done
-# Don't do deps until this exists, because it provides rules to make the deps.
-no_deps=t
 endif
 
-# This is used by the m_%.[Sc] pattern rules in sysd-rules.
-define +make-include-of-dep
-echo '#include <$<>' > $@T
-mv -f $@T $@
-endef
-
 # Generate version maps, but wait until sysdep-subdirs is known
 ifeq ($(sysd-sorted-done),t)
 ifeq ($(versioning),yes)
@@ -348,7 +311,7 @@ postclean-generated += sysd-versions Versions.all abi-versions.h \
                       Versions.def.v.i Versions.def.v Versions.v.i Versions.v
 
 ifndef avoid-generated
-ifneq ($(sysd-versions-subdirs),$(all-subdirs) $(config-sysdirs))
+ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
 sysd-versions-force = FORCE
 FORCE:
 endif
@@ -358,21 +321,22 @@ $(common-objpfx)Versions.def.v.i: $(..)Versions.def \
 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
                              $(common-objpfx)soversions.i \
                              $(common-objpfx)Versions.def.v
-       { while read lib version setname; do \
+       { while read which lib version setname; do \
+           test x"$$which" = xDEFAULT || continue; \
            test -z "$$setname" || echo "$$lib : $$setname"; \
          done < $(word 2,$^); \
          cat $(word 3,$^); \
        } | LC_ALL=C $(AWK) -f $< > $@T
        mv -f $@T $@
 # See %.v/%.v.i implicit rules in Makeconfig.
-$(common-objpfx)Versions.v.i: $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
+$(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
                              $(wildcard $(sysdirs:%=%/Versions)) \
                              $(common-objpfx)abi-versions.h \
                              $(sysd-versions-force)
 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
                               $(common-objpfx)Versions.v \
                               $(..)scripts/versions.awk
-       ( echo 'sysd-versions-subdirs = $(all-subdirs) $(config-sysdirs)' ; \
+       ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
          cat $(word 2,$^) \
          | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
                            -v move_if_change='$(move-if-change)' \
@@ -383,34 +347,22 @@ endif # avoid-generated
 endif # $(versioning) = yes
 endif # sysd-sorted-done
 
-
-ifndef compile-command.S
-compile-command.S = $(compile.S) $(OUTPUT_OPTION)
-endif
-ifndef compile-command.s
-compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
-endif
-ifndef compile-command.c
-compile-command.c = $(compile.c) $(OUTPUT_OPTION)
-endif
+# Generate .dT files as we compile.
+compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
+compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
+compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION) $(compile-mkdep-flags)
+compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
+compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
 
 # GCC can grok options after the file name, and it looks nicer that way.
 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
+compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
 compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
                  $(ASFLAGS) $(ASFLAGS-$(suffix $@))
 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
                  $(ASFLAGS) $(ASFLAGS-$(suffix $@))
 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
 
-# If we want to generate MD5 checksums for the sources do this now.
-ifeq ($(md5),yes)
-generate-md5 = ; rm -f $(@:.d=.md5); \
-$(CC) -E $< $(CFLAGS) $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | \
-sed '/^\#/d;/^[[:space:]]*$$/d' | md5sum > $(@:.d=.md5)
-else
-generate-md5 =
-endif
-
 # We need this for the output to go in the right place.  It will default to
 # empty if make was configured to work with a cc that can't grok -c and -o
 # together.  You can't compile the C library with such a compiler.
@@ -420,14 +372,16 @@ OUTPUT_OPTION = -o $@
 # the dependency run for C sources.  But having it for assembly sources can
 # get the wrong predefines.
 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
+
 define +make-deps
 $(make-target-directory)
 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
-            $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed \
--e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
-$(sed-remove-objpfx) > $(@:.d=.T)
+            $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed -e\
+'s,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
+$(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
 mv -f $(@:.d=.T) $@ $(generate-md5)
 endef
+
 ifneq (,$(objpfx))
 # Continuation lines here are dangerous because they introduce spaces!
 define sed-remove-objpfx
@@ -511,17 +465,35 @@ endif
 ifeq (yes,$(elf))
 # binutils only position loadable notes into the first page for binaries,
 # not for shared objects
-$(common-objpfx)shlib.lds: $(common-objpfx)config.make
+$(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
        $(LINK.o) -shared -Wl,-O1 \
+                 -nostdlib -nostartfiles \
                  $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
                  -Wl,--verbose 2>&1 | \
          sed > $@T \
              -e '/^=========/,/^=========/!d;/^=========/d' \
-             -e 's/^.*\.hash[  ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
+             $(if $(filter yes,$(have-hash-style)), \
+                  -e 's/^.*\.gnu\.hash[        ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
+                  -e '/^[      ]*\.hash[       ]*:.*$$/{h;d;}' \
+                  -e '/DATA_SEGMENT_ALIGN/{H;g}' \
+               , \
+                  -e 's/^.*\.hash[     ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
+              ) \
              -e 's/^.*\*(\.dynbss).*$$/& \
                 PROVIDE(__start___libc_freeres_ptrs = .); \
                 *(__libc_freeres_ptrs) \
-                PROVIDE(__stop___libc_freeres_ptrs = .);/'
+                PROVIDE(__stop___libc_freeres_ptrs = .);/'\
+             -e 's@^.*\*(\.jcr).*$$@& \
+                PROVIDE(__start___libc_subfreeres = .);\
+                __libc_subfreeres : { *(__libc_subfreeres) }\
+                PROVIDE(__stop___libc_subfreeres = .);\
+                PROVIDE(__start___libc_atexit = .);\
+                __libc_atexit : { *(__libc_atexit) }\
+                PROVIDE(__stop___libc_atexit = .);\
+                PROVIDE(__start___libc_thread_subfreeres = .);\
+                __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
+                PROVIDE(__stop___libc_thread_subfreeres = .);\
+                /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
        mv -f $@T $@
 common-generated += shlib.lds
 
@@ -555,6 +527,7 @@ endef
 else
 define build-module-helper
 $(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
+         $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
          -B$(csu-objpfx) $(load-map-file) \
          $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
          -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
@@ -570,6 +543,11 @@ define build-module
 $(build-module-helper) -o $@ -T $(common-objpfx)shlib.lds \
          $(csu-objpfx)abi-note.o $(build-module-objlist)
 endef
+define build-module-asneeded
+$(build-module-helper) -o $@ -T $(common-objpfx)shlib.lds \
+         $(csu-objpfx)abi-note.o \
+         -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed
+endef
 else
 ifneq (,$(findstring aix,$(config-os)))
 define build-module
@@ -601,12 +579,14 @@ build-shlib-objlist = $(build-module-helper-objlist) \
 # Also omits crti.o and crtn.o, which we do not want
 # since we define our own `.init' section specially.
 LDFLAGS-c.so = -nostdlib -nostartfiles
-# But we still want to link libc.so against $(gnulib).
-LDLIBS-c.so += $(gnulib)
+# But we still want to link libc.so against $(libc.so-gnulib).
+LDLIBS-c.so += $(libc.so-gnulib)
 # Give libc.so an entry point and make it directly runnable itself.
 LDFLAGS-c.so += -e __libc_main
-# Force the backward compatibility EH functions to be linked.
-LDFLAGS-c.so += -u __register_frame
+# If lazy relocation is disabled add the -z now flag.
+ifeq ($(bind-now),yes)
+LDFLAGS-c.so += -Wl,-z,now
+endif
 # Pre-link the objects of libc_pic.a so that we can locally resolve
 # COMMON symbols before we link against ld.so.  This is because ld.so
 # contains some of libc_pic.a already, which will prevent the COMMONs
@@ -679,9 +659,27 @@ ifdef extra-libs
 extra-libs-left := $(extra-libs)
 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
 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))
+
+extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
+$(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
+               $(objpfx)%.os $(common-objpfx)shlib.lds \
+               $(common-objpfx)libc.so $(common-objpfx)libc_nonshared.a
+       $(build-module)
+endif
 \f
 +depfiles := $(sources:.c=.d) \
             $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
+            $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
             $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
 ifeq ($(build-programs),yes)
 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
@@ -689,6 +687,15 @@ endif
 +depfiles := $(addprefix $(objpfx),\
                         $(filter-out $(addsuffix .d,$(omit-deps)),\
                                      $(+depfiles)))
+all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
++depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
+            $(wildcard $(all-dt-files:.dt=.d))
+
+# This is a funny rule in that it removes its input file.
+%.d: %.dt
+       @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
+        mv -f $(@:.d=.T) $@ && \
+        rm -f $<
 
 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
 # They will be generated when they're needed, and trying too early won't work.
@@ -710,7 +717,9 @@ MAKEFLAGS := $(MAKEFLAGS)r
 # Generic rule for making directories.
 %/:
 # mkdir isn't smart enough to strip a trailing /.
-       mkdir $(@:%/=%)
+# We always require a mkdir which supports the -p option to avoid error
+# messages in case of races.
+       mkdir -p $(@:%/=%)
 \f
 # Make sure that object files are not removed
 # when they are intermediates between sources and library members.
@@ -762,6 +771,7 @@ define o-iterator-doit
 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
 endef
 define do-stamp
+$(make-target-directory)
 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
 mv -f $@T $@
 endef
@@ -811,12 +821,13 @@ force-install:
 
 # $(install-lib) are installed from the object directory into $(libdir);
 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
-# unless they also appear in $(non-lib.a).  $(install-data) are installed
-# as they are into $(datadir).  $(headers) are installed as they are in
+# unless they also appear in $(non-lib.a).  $(install-data) are installed as
+# they are into $(datadir).  $(headers) are installed as they are in
 # $(includedir).  $(install-bin), $(install-bin-script) and $(install-sbin)
 # are installed from the object directory into $(bindir), $(bindir) and
-# $(sbindir), respectively.  $(install-others) are absolute path names of
-# files to install; rules to install them are defined elsewhere.
+# $(sbindir), respectively.  $(install-others) and $(install-others-programs)
+# are absolute path names of files to install; rules to install them are
+# defined elsewhere.
 
 # The simple library name to install libc.a under.
 # This could be defined by a sysdep Makefile.
@@ -967,7 +978,7 @@ $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
         cat $<; \
         echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
              '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
-             ')' \
+             ' AS_NEEDED (' $(slibdir)/$(rtld-installed-name) ') )' \
        ) > $@.new
        mv -f $@.new $@
 
@@ -1090,8 +1101,21 @@ $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
 endif
 headers := $(strip $(headers))
 ifdef headers
-$(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
+# This implicit rule installs headers from the source directory.
+# It may be ignored in preference to rules from sysd-rules to find
+# headers in the sysdeps tree.
+$(inst_includedir)/%.h: $(objpfx)%.h $(+force)
+       $(do-install)
+$(inst_includedir)/%.h: %.h $(+force)
        $(do-install)
+$(inst_includedir)/%.h: $(..)include/%.h $(+force)
+       $(do-install)
+headers-nonh := $(filter-out %.h,$(headers))
+ifdef headers-nonh
+$(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
+                                                % $(+force)
+       $(do-install)
+endif  # headers-nonh
 endif  # headers
 
 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
@@ -1108,6 +1132,7 @@ install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
 install-others-nosubdir: $(install-others)
+install-others-programs-nosubdir: $(install-others-programs)
 
 # We need all the `-nosubdir' targets so that `install' in the parent
 # doesn't depend on several things which each iterate over the subdirs.
@@ -1116,14 +1141,12 @@ install-others-nosubdir: $(install-others)
 install-%:: install-%-nosubdir ;
 
 .PHONY: install install-no-libc.a-nosubdir
-ifeq ($(build-programs),yes)
-install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
-                           install-bin-nosubdir install-bin-script-nosubdir \
-                           install-lib-nosubdir install-others-nosubdir \
-                           install-rootsbin-nosubdir install-sbin-nosubdir
-else
-install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
+install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
                            install-lib-nosubdir install-others-nosubdir
+ifeq ($(build-programs),yes)
+install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
+                           install-rootsbin-nosubdir install-sbin-nosubdir \
+                           install-others-programs-nosubdir
 endif
 install: install-no-libc.a-nosubdir
 \f
@@ -1157,9 +1180,9 @@ xcheck: xtests
 
 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
 ifneq (,$(all-nonlib))
-cpp-srcs-left = $(all-nonlib:=.c)
+cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
 lib := nonlib
-include $(patsubst %,$(..)cppflags-iterator.mk,$(all-nonlib))
+include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
 endif
 
 # The include magic above causes those files to use this variable for flags.
@@ -1187,8 +1210,9 @@ check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
 define check-abi
        LC_ALL=C \
        $(AWK) -f $< -v 'config=$(check-abi-config)' \
+              $(patsubst %,-v 'lastversion=%',$($*-abi-frozen)) \
               $(filter %.abilist,$^) \
-       | { diff -pu0 - $(filter %.symlist,$^) $(check-abi-warn) ; }
+       | { diff -p -U 0 - $(filter %.symlist,$^) $(check-abi-warn) ; }
 endef
 ifeq ($(enable-check-abi),warn)
 check-abi-warn = || echo '*** WARNING: $*.so failed ABI check'
@@ -1196,10 +1220,7 @@ endif
 
 ifeq ($(firstword $(sysd-sorted-done) f)$(firstword $(generating) f),tf)
 -include $(common-objpfx)tls.make
-config-tls := notls
-ifeq ($(use-tls),yes)
 config-tls := tls
-endif
 ifeq ($(use-thread),yes)
 config-tls := thread
 endif
@@ -1257,43 +1278,32 @@ endif
 
 endif
 
-# There's no good place to put this - here will do.
-# The dependencies are wrong if it's run from the top level.
-ifeq ($(filter %posix, $(sysdirs)),)
-L_tmpnam  = 1
-TMP_MAX   = 0
-L_ctermid = 1
-L_cuserid = 1
-else
-L_tmpnam  = 20
-TMP_MAX   = 238328
-L_ctermid = 9
-L_cuserid = 9
-endif
+# These will have been set by sysdeps/posix/Makefile.
+L_tmpnam  ?= 1
+TMP_MAX   ?= 0
+L_ctermid ?= 1
+L_cuserid ?= 1
+
 stdio_lim = $(common-objpfx)bits/stdio_lim.h
 
 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
                   $(common-objpfx)config.make
        $(make-target-directory)
-       echo '#include "$(..)posix/bits/posix1_lim.h"' |                \
-       SUNPRO_DEPENDENCIES='$(@:st=dT) $@'                             \
-       $(CC) $(+includes) -E -dM -xc - -o $(@:st=hT)
-       echo '#include "$(..)misc/sys/uio.h"' |                         \
-       SUNPRO_DEPENDENCIES='$(@:st=dT) $@'                             \
-       $(CC) -D_LIBC=1 $(+includes) -E -dM -xc - | cat - >> $(@:st=hT)
-ifdef sed-remove-objpfx
-       sed $(sed-remove-objpfx) $(@:st=dT) > $(@:st=dt)
-       cat $(@:st=dt) >> $(@:st=d)
-else
-       cat $(@:st=dT) >> $(@:st=d)
-endif
+       { echo '#include "$(..)posix/bits/posix1_lim.h"';               \
+         echo '#define _LIBC 1';                                       \
+         echo '#include "$(..)misc/sys/uio.h"'; } |                    \
+       $(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)'   \
+             $(+includes) -xc - -o $(@:st=hT)
+       sed $(sed-remove-objpfx) $(sed-remove-dotdot)                   \
+           $(@:st=dT) > $(@:st=dt)
+       mv -f $(@:st=dt) $(@:st=d)
        fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`;       \
        filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`;    \
        iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`;        \
        fopen_max=$${fopen_max:-16};                                    \
        filename_max=$${filename_max:-1024};                            \
-       if [ -z $$iov_max ]; then                                       \
+       if [ -z "$$iov_max" ]; then                                     \
          define_iov_max="# undef IOV_MAX";                             \
        else                                                            \
          define_iov_max="# define IOV_MAX $$iov_max";                  \
@@ -1316,19 +1326,14 @@ ifndef no_deps
 endif
 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
 \f
-.PHONY: TAGS
-TAGS: $(objpfx)distinfo $(..)MakeTAGS
-       $(MAKE) $(addprefix -f ,$^) $@
-
-$(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
-       $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
 FORCE:
 
-
 .PHONY: echo-headers
 echo-headers:
        @echo $(headers)
 
+%.bz2: %; bzip2 -9vk $<
+%.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
 \f
 # Common cleaning targets.
 
@@ -1355,8 +1360,8 @@ common-mostlyclean:
                                                      $(test-srcs)) \
                                     $(addsuffix -bp.out,$(tests) $(xtests) \
                                                         $(test-srcs)))
-       -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
-                                    $(install-lib.so) \
+       -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
+                                    $(install-lib) $(install-lib.so) \
                                     $(install-lib.so:%.so=%_pic.a))
        -rm -f core
        -rm -f $(objpfx)rtld-*.os
@@ -1368,11 +1373,10 @@ endef
 
 # Also remove the dependencies and generated source files.
 common-clean: common-mostlyclean
-       -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
-       -rm -f $(objpfx)rtld-*.d
+       -rm -f $(addprefix $(objpfx),$(generated))
+       -rm -f $(objpfx)*.d $(objpfx)*.dt
        -rm -fr $(addprefix $(objpfx),$(generated-dirs))
        -rm -f $(addprefix $(common-objpfx),$(common-generated))
-       -rm -f $(objpfx)distinfo
 \f
 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
 # for each function which is a stub.  We grovel over all the .d files
@@ -1383,53 +1387,19 @@ ifdef objpfx
 .PHONY: stubs # The parent Makefile calls this target.
 stubs: $(objpfx)stubs
 endif
-$(objpfx)stubs: $(+depfiles)
-# Use /dev/null since `...` might expand to empty.
-       (s=`cd $(sysdep_dir) && $(PWD_P)`; \
-        $(patsubst %/,cd % &&,$(objpfx)) \
-        sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
-         `sed -n -e 's@$(sysdep_dir)/@'"$$s"'/@g' \
-                 -e 's@\$$(common-objpfx)@$(..)@g' -e 's@\$$(objpfx)@@g' \
-                 -e '/:  *[^ ]/{s@^.*: *\([^ ]*\) .*$$@\1@; h; }' \
-                 -e '/:$$/d' \
-                 -e '/stub-tag\.h/{; g; p; }' \
-                 $(patsubst $(objpfx)%,%,$^) /dev/null` \
-            /dev/null) > $@T
+objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
+                 $(addprefix $(objpfx),$(extra-objs))
+$(objpfx)stubs: $(objs-for-stubs)
+ifneq (,$(strip $(objs-for-stubs)))
+       (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
+       $(AWK) '/\.gnu\.glibc-stub\./ { \
+                 sub(/\.gnu\.glibc-stub\./, "", $$2); \
+                 stubs[$$2] = 1; } \
+               END { for (s in stubs) print "#define __stub_" s }' > $@T
        mv -f $@T $@
-\f
-# Make the distribution tar file.
-
-.PHONY: dist
-dist: $(objpfx)distinfo $(..)Make-dist
-       $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
-
-# Avoid depending on source files found in sysdeps dirs,
-# because the references affect implicit rule selection.
-dist: $(filter-out %.c %.S %.s,$(distribute))
-
-# We used to simply export all these variables, but that frequently made the
-# environment get too large.  Instead, we write all the information into
-# a generated makefile fragment `distinfo', and then include it with -f in
-# the sub-make that makes the distribution (above).
-$(objpfx)distinfo: Makefile $(..)Makerules \
-                  $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
-       $(make-target-directory)
-       $(distinfo-vars)
-       mv -f $@.new $@
-.PHONY: subdir_distinfo
-subdir_distinfo: $(objpfx)distinfo
-
-define distinfo-vars
-rm -f $@.new
-echo > $@.new 'subdir := $(subdir)'
-$(foreach var,subdir-dirs sources elided-routines sysdep_routines \
-             headers sysdep_headers distribute dont_distribute generated \
-             others tests xtests test-srcs extra-libs versioned \
-             $(extra-libs:%=%-routines) \
-             $(addprefix install-,lib lib.so data bin bin-script sbin others),
-echo >> $@.new '$(subdir)-$(var) := $($(var))'
-echo >> $@.new '$(var) = $$($(subdir)-$(var))')
-endef
+else
+       > $@
+endif
 \f
 ifneq (,$(strip $(gpl2lgpl)))
 ifneq (,$(wildcard $(..)gpl2lgpl.sed))