Blame Makerules

Packit 6c4009
# Copyright (C) 1991-2018 Free Software Foundation, Inc.
Packit 6c4009
# This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
# The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
# modify it under the terms of the GNU Lesser General Public
Packit 6c4009
# License as published by the Free Software Foundation; either
Packit 6c4009
# version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
# The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
# Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
# You should have received a copy of the GNU Lesser General Public
Packit 6c4009
# License along with the GNU C Library; if not, see
Packit 6c4009
# <http://www.gnu.org/licenses/>.
Packit 6c4009
Packit 6c4009
#
Packit 6c4009
#	Common rules for making the GNU C library.  This file is included
Packit 6c4009
#	by the top-level Makefile and by all subdirectory makefiles
Packit 6c4009
#	(through Rules).
Packit 6c4009
#
Packit 6c4009
ifneq (,)
Packit 6c4009
This makefile requires GNU Make.
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
REQUIRED_MAKE_VERSION = 3.74
Packit 6c4009
REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
Packit 6c4009
Packit 6c4009
ifneq ($(REQUIRED_MAKE_VERSION), \
Packit 6c4009
       $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
Packit 6c4009
Wrong GNU Make version.  See above for the version needed.
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
ifdef	subdir
Packit 6c4009
..	:= ../
Packit 6c4009
endif	# subdir
Packit 6c4009
Packit 6c4009
# If `sources' was defined by the parent makefile, undefine it so
Packit 6c4009
# we will later get it from wildcard search in this directory.
Packit 6c4009
ifneq	"$(findstring env,$(origin sources))" ""
Packit 6c4009
sources :=
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
oPATH := $(PATH)
Packit 6c4009
PATH := this definition should take precedence over $(oPATH)
Packit 6c4009
ifeq ($(PATH),$(oPATH))
Packit 6c4009
You must not use the -e flag when building the GNU C library.
Packit 6c4009
else
Packit 6c4009
PATH := $(oPATH)
Packit 6c4009
endif
Packit 6c4009

Packit 6c4009
ifndef +included-Makeconfig
Packit 6c4009
include $(..)Makeconfig
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
# This variable is used in ``include $(o-iterator)'' after defining
Packit 6c4009
# $(o-iterator-doit) to produce some desired rule using $o for the object
Packit 6c4009
# suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
Packit 6c4009
# is produced for each object suffix in use.
Packit 6c4009
o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
Packit 6c4009

Packit 6c4009
# Include any system-specific makefiles.
Packit 6c4009
Packit 6c4009
# This is here so things in sysdep Makefiles can easily depend on foo.h as
Packit 6c4009
# appropriate and not worry about where foo.h comes from, which may be
Packit 6c4009
# system dependent and not known by that Makefile.
Packit 6c4009
vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
Packit 6c4009
				      $(+sysdep_dirs) $(..)))
Packit 6c4009
Packit 6c4009
# The same is true for RPC source files.
Packit 6c4009
vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
Packit 6c4009
				      $(+sysdep_dirs) $(..)))
Packit 6c4009
Packit 6c4009
# Some sysdep makefiles use this to distinguish being included here from
Packit 6c4009
# being included individually by a subdir makefile (hurd/Makefile needs this).
Packit 6c4009
in-Makerules := yes
Packit 6c4009
Packit 6c4009
sysdep-makefiles := $(wildcard $(sysdirs:=/Makefile))
Packit 6c4009
ifneq (,$(sysdep-makefiles))
Packit 6c4009
include $(sysdep-makefiles)
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
# Reorder before-compile so that mach things come first, and hurd things
Packit 6c4009
# second, before all else.  The mach and hurd subdirectories have many
Packit 6c4009
# generated header files which the much of rest of the library depends on,
Packit 6c4009
# so it is best to build them first (and mach before hurd, at that).
Packit 6c4009
before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
Packit 6c4009
			   $(before-compile)) \
Packit 6c4009
		  $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
Packit 6c4009
			       $(before-compile))
Packit 6c4009
Packit 6c4009
# Even before that, we need abi-versions.h which is generated right here.
Packit 6c4009
ifeq ($(build-shared),yes)
Packit 6c4009
ifndef avoid-generated
Packit 6c4009
before-compile := $(common-objpfx)abi-versions.h $(before-compile)
Packit 6c4009
$(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
Packit 6c4009
				$(common-objpfx)Versions.all
Packit 6c4009
	LC_ALL=C $(AWK) -f $^ > $@T
Packit 6c4009
	mv -f $@T $@
Packit 6c4009
Packit 6c4009
$(common-objpfx)%.latest: $(common-objpfx)abi-versions.h
Packit 6c4009
	sed -n '/ VERSION_$*_/{s/^.*_\([A-Z0-9_]*\).*$$/\1/;h;};$${g;p;}' \
Packit 6c4009
	    $(common-objpfx)abi-versions.h > $@T
Packit 6c4009
	mv -f $@T $@
Packit 6c4009
Packit 6c4009
# first-versions.h and ldbl-compat-choose.h provide macros used in
Packit 6c4009
# various symbol versioning macro calls.
Packit 6c4009
before-compile := $(common-objpfx)first-versions.h \
Packit 6c4009
		  $(common-objpfx)ldbl-compat-choose.h $(before-compile)
Packit 6c4009
$(common-objpfx)first-versions.h: $(common-objpfx)versions.stmp
Packit 6c4009
$(common-objpfx)ldbl-compat-choose.h: $(common-objpfx)versions.stmp
Packit 6c4009
endif # avoid-generated
Packit 6c4009
endif # $(build-shared) = yes
Packit 6c4009
Packit 6c4009
ifndef avoid-generated
Packit 6c4009
ifneq (,$(CXX))
Packit 6c4009
# If C++ headers <cstdlib> or <cmath> are used, GCC 6 will include
Packit 6c4009
# /usr/include/stdlib.h or /usr/include/math.h from "#include_next"
Packit 6c4009
# (instead of stdlib/stdlib.h or math/math.h in the glibc source
Packit 6c4009
# directory), and this turns up as a make dependency.  An implicit
Packit 6c4009
# rule will kick in and make will try to install stdlib/stdlib.h or
Packit 6c4009
# math/math.h as /usr/include/stdlib.h or /usr/include/math.h because
Packit 6c4009
# the target is out of date.  We make a copy of <cstdlib> and <cmath>
Packit 6c4009
# in the glibc build directory so that stdlib/stdlib.h and math/math.h
Packit 6c4009
# will be used instead of /usr/include/stdlib.h and /usr/include/math.h.
Packit 6c4009
before-compile := $(common-objpfx)cstdlib $(common-objpfx)cmath \
Packit 6c4009
	          $(before-compile)
Packit 6c4009
$(common-objpfx)cstdlib: $(c++-cstdlib-header)
Packit 6c4009
	$(INSTALL_DATA) $< $@T
Packit 6c4009
	$(move-if-change) $@T $@
Packit 6c4009
$(common-objpfx)cmath: $(c++-cmath-header)
Packit 6c4009
	$(INSTALL_DATA) $< $@T
Packit 6c4009
	$(move-if-change) $@T $@
Packit 6c4009
ifneq (,$(c++-bits-std_abs-h))
Packit 6c4009
# Also make a copy of <bits/std_abs.h> from GCC 7 to prevent it from
Packit 6c4009
# including /usr/include/stdlib.h.
Packit 6c4009
before-compile := $(common-objpfx)bits/std_abs.h $(before-compile)
Packit 6c4009
$(common-objpfx)bits/std_abs.h: $(c++-bits-std_abs-h)
Packit 6c4009
	$(INSTALL_DATA) $< $@T
Packit 6c4009
	$(move-if-change) $@T $@
Packit 6c4009
endif
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
before-compile := $(common-objpfx)libc-abis.h $(before-compile)
Packit 6c4009
$(common-objpfx)libc-abis.h: $(common-objpfx)libc-abis.stamp; @:
Packit 6c4009
$(common-objpfx)libc-abis.stamp: $(..)scripts/gen-libc-abis \
Packit 6c4009
			     $(firstword $(wildcard $(sysdirs:=/libc-abis)) \
Packit 6c4009
					 $(..)libc-abis) \
Packit 6c4009
			     $(..)Makerules
Packit 6c4009
	$(SHELL) $< \
Packit 6c4009
		 $(base-machine)-$(config-vendor)-$(config-os) \
Packit 6c4009
		 < $(word 2,$^) > $(@:.stamp=.h)T
Packit 6c4009
	$(move-if-change) $(@:.stamp=.h)T $(@:.stamp=.h)
Packit 6c4009
	touch $@
Packit 6c4009
common-generated += $(common-objpfx)libc-abis.h
Packit 6c4009
endif # avoid-generated
Packit 6c4009
Packit 6c4009
ifeq (yes,$(build-shared))
Packit 6c4009
$(common-objpfx)runtime-linker.h: $(common-objpfx)runtime-linker.stamp; @:
Packit 6c4009
$(common-objpfx)runtime-linker.stamp: $(common-objpfx)config.make
Packit 6c4009
	$(make-target-directory)
Packit 6c4009
	echo '#define RUNTIME_LINKER "$(rtlddir)/$(rtld-installed-name)"' \
Packit 6c4009
		> ${@:stamp=T}
Packit 6c4009
	$(move-if-change) ${@:stamp=T} ${@:stamp=h}
Packit 6c4009
	touch $@
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
# Make sure the subdirectory for object files gets created.
Packit 6c4009
ifdef objpfx
Packit 6c4009
ifeq (,$(wildcard $(objpfx).))
Packit 6c4009
before-compile += $(objpfx).
Packit 6c4009
$(objpfx).:
Packit 6c4009
	$(make-target-directory)
Packit 6c4009
endif
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
# Remove existing files from `before-compile'.  Things are added there when
Packit 6c4009
# they must exist for dependency generation to work right, but once they
Packit 6c4009
# exist there is no further need for every single file to depend on them,
Packit 6c4009
# and those gratuitous dependencies result in many gratuitous
Packit 6c4009
# recompilations.
Packit 6c4009
before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
Packit 6c4009
Packit 6c4009
# Don't let any before-compile file be an intermediate and get removed.
Packit 6c4009
ifdef before-compile
Packit 6c4009
$(before-compile):
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
# We don't want $(common-objpfx) files to depend on miscellaneous stuff
Packit 6c4009
# in subdirs.
Packit 6c4009
ifdef subdir
Packit 6c4009
common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
Packit 6c4009
else
Packit 6c4009
common-before-compile = $(before-compile)
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
ifndef subdir
Packit 6c4009
# If a makefile needs to do something conditional on something that
Packit 6c4009
# can only be figured out from headers, write a FOO.make.c input
Packit 6c4009
# file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
Packit 6c4009
# to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
Packit 6c4009
#
Packit 6c4009
# We only generate these in the top-level makefile, to avoid any weirdness
Packit 6c4009
# from subdir-specific makefile tweaks creeping in on an update.
Packit 6c4009
$(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
Packit 6c4009
	rm -f $@T $@.dT
Packit 6c4009
	(echo '# Generated from $*.make.c by Makerules.'; \
Packit 6c4009
	 $(CC) $(CFLAGS) $(CPPFLAGS) -E -DASSEMBLER $< \
Packit 6c4009
	       -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
Packit 6c4009
	 | sed -n '/@@@/{s/@@@[	 ]*\(.*\)@@@/\1/;s/[	 ]*$$//p;}'; \
Packit 6c4009
	 echo 'common-generated += $(@F)'; \
Packit 6c4009
	 sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
Packit 6c4009
	 rm -f $@.dT) > $@T
Packit 6c4009
	mv -f $@T $@
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
ifdef subdir
Packit 6c4009
sed-remove-dotdot := -e 's@  *\.\.\/\([^ 	\]*\)@ $$(..)\1@g' \
Packit 6c4009
		     -e 's@^\.\.\/\([^ 	\]*\)@$$(..)\1@g'
Packit 6c4009
else
Packit 6c4009
sed-remove-dotdot := -e 's@  *\([^ 	\/$$][^ 	\]*\)@ $$(..)\1@g' \
Packit 6c4009
		     -e 's@^\([^ 	\/$$][^ 	\]*\)@$$(..)\1@g'
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
ifdef gen-py-const-headers
Packit 6c4009
# We'll use a static pattern rule to match .pysym files with their
Packit 6c4009
# corresponding generated .py files.
Packit 6c4009
# The generated .py files go in the submodule's dir in the glibc build dir.
Packit 6c4009
py-const-files := $(patsubst %.pysym,%.py,$(gen-py-const-headers))
Packit 6c4009
py-const-dir := $(objpfx)
Packit 6c4009
py-const := $(addprefix $(py-const-dir),$(py-const-files))
Packit 6c4009
py-const-script := $(..)scripts/gen-py-const.awk
Packit 6c4009
Packit 6c4009
# This is a hack we use to generate .py files with constants for Python
Packit 6c4009
# pretty printers.  It works the same way as gen-as-const.
Packit 6c4009
# See scripts/gen-py-const.awk for details on how the awk | gcc mechanism
Packit 6c4009
# works.
Packit 6c4009
#
Packit 6c4009
# $@.tmp and $@.tmp2 are temporary files we use to store the partial contents
Packit 6c4009
# of the target file.  We do this instead of just writing on $@ because, if the
Packit 6c4009
# build process terminates prematurely, re-running Make wouldn't run this rule
Packit 6c4009
# since Make would see that the target file already exists (despite it being
Packit 6c4009
# incomplete).
Packit 6c4009
#
Packit 6c4009
# The sed line replaces "@name@SOME_NAME@value@SOME_VALUE@" strings from the
Packit 6c4009
# output of 'gcc -S' with "SOME_NAME = SOME_VALUE" strings.
Packit 6c4009
# The '-n' option, combined with the '/p' command, makes sed output only the
Packit 6c4009
# modified lines instead of the whole input file.  The output is redirected
Packit 6c4009
# to a .py file; we'll import it in the pretty printers file to read
Packit 6c4009
# the constants generated by gen-py-const.awk.
Packit 6c4009
# The regex has two capturing groups, for SOME_NAME and SOME_VALUE
Packit 6c4009
# respectively.  Notice SOME_VALUE may be prepended by a special character,
Packit 6c4009
# depending on the assembly syntax (e.g. immediates are prefixed by a '$'
Packit 6c4009
# in AT&T x86, and by a '#' in ARM).  We discard it using a complemented set
Packit 6c4009
# before the second capturing group.
Packit 6c4009
$(py-const): $(py-const-dir)%.py: %.pysym $(py-const-script) \
Packit 6c4009
	     $(common-before-compile)
Packit 6c4009
	$(make-target-directory)
Packit 6c4009
	$(AWK) -f $(py-const-script) $< \
Packit 6c4009
	       | $(CC) -S -o $@.tmp $(CFLAGS) $(CPPFLAGS) -x c -
Packit 6c4009
	echo '# GENERATED FILE\n' > $@.tmp2
Packit 6c4009
	echo '# Constant definitions for pretty printers.' >> $@.tmp2
Packit 6c4009
	echo '# See gen-py-const.awk for details.\n' >> $@.tmp2
Packit 6c4009
	sed -n -r 's/^.*@name@([^@]+)@value@[^[:xdigit:]Xx-]*([[:xdigit:]Xx-]+)@.*/\1 = \2/p' \
Packit 6c4009
	    $@.tmp >> $@.tmp2
Packit 6c4009
	mv -f $@.tmp2 $@
Packit 6c4009
	rm -f $@.tmp
Packit 6c4009
Packit 6c4009
generated += $(py-const)
Packit 6c4009
endif  # gen-py-const-headers
Packit 6c4009
Packit 6c4009
ifdef gen-as-const-headers
Packit 6c4009
# Generating headers for assembly constants.
Packit 6c4009
# We need this defined early to get into before-compile before
Packit 6c4009
# it's used in sysd-rules, below.
Packit 6c4009
# Define GEN_AS_CONST_HEADERS to avoid circular dependency [BZ #22792].
Packit 6c4009
# NB: <tcb-offsets.h> is generated from tcb-offsets.sym to define
Packit 6c4009
# offsets and sizes of types in <tls.h> and maybe <pthread.h> which
Packit 6c4009
# may include <tcb-offsets.h>.  Target header files can check if
Packit 6c4009
# GEN_AS_CONST_HEADERS is defined to avoid circular dependency which
Packit 6c4009
# may lead to build hang on a many-core machine.
Packit 6c4009
$(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
Packit 6c4009
					   %.sym $(common-before-compile)
Packit 6c4009
	$(AWK) -f $< $(filter %.sym,$^) \
Packit 6c4009
	| $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) \
Packit 6c4009
		-DGEN_AS_CONST_HEADERS -x c - \
Packit 6c4009
		-MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
Packit 6c4009
	sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
Packit 6c4009
		$(@:.h.d=.h)T3 > $(@:.h.d=.h)T
Packit 6c4009
	rm -f $(@:.h.d=.h)T3
Packit 6c4009
	sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
Packit 6c4009
	    $(@:.h=.h.d)T > $(@:.h=.h.d)T2
Packit 6c4009
	rm -f $(@:.h=.h.d)T
Packit 6c4009
	mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
Packit 6c4009
	mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
Packit 6c4009
vpath %.sym $(sysdirs)
Packit 6c4009
before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
Packit 6c4009
Packit 6c4009
tests-internal += $(gen-as-const-headers:%.sym=test-as-const-%)
Packit 6c4009
generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
Packit 6c4009
$(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
Packit 6c4009
			    %.sym $(common-objpfx)%.h
Packit 6c4009
	($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
Packit 6c4009
	 $(AWK) -v test=1 -f $< $(filter %.sym,$^); \
Packit 6c4009
	 echo '#include "$(..)test-skeleton.c"') > $@T
Packit 6c4009
	mv -f $@T $@
Packit 6c4009
endif
Packit 6c4009

Packit 6c4009
ifeq (yes,$(build-shared))
Packit 6c4009
# Generate the header containing the names of all shared libraries.
Packit 6c4009
# We use a stamp file to avoid unnecessary recompilations.
Packit 6c4009
before-compile += $(common-objpfx)gnu/lib-names.h
Packit 6c4009
ifeq ($(soversions.mk-done),t)
Packit 6c4009
ifndef abi-variants
Packit 6c4009
lib-names-h-abi = gnu/lib-names.h
Packit 6c4009
lib-names-stmp-abi = gnu/lib-names.stmp
Packit 6c4009
else
Packit 6c4009
lib-names-h-abi = gnu/lib-names-$(default-abi).h
Packit 6c4009
lib-names-stmp-abi = gnu/lib-names-$(default-abi).stmp
Packit 6c4009
before-compile += $(common-objpfx)$(lib-names-h-abi)
Packit 6c4009
common-generated += gnu/lib-names.h
Packit 6c4009
install-others-nosubdir: $(inst_includedir)/$(lib-names-h-abi)
Packit 6c4009
$(common-objpfx)gnu/lib-names.h:
Packit 6c4009
	$(make-target-directory)
Packit 6c4009
	{ \
Packit 6c4009
	 echo '/* This file is automatically generated.';\
Packit 6c4009
	 echo '   It defines macros to allow user program to find the shared'; \
Packit 6c4009
	 echo '   library files which come as part of GNU libc.  */'; \
Packit 6c4009
	 echo '#ifndef __GNU_LIB_NAMES_H'; \
Packit 6c4009
	 echo '#define __GNU_LIB_NAMES_H	1'; \
Packit 6c4009
	 echo ''; \
Packit 6c4009
	 $(if $(abi-includes), \
Packit 6c4009
	  $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
Packit 6c4009
	  echo '';) \
Packit 6c4009
	 $(foreach v,$(abi-variants),\
Packit 6c4009
	 $(if $(abi-$(v)-condition),\
Packit 6c4009
	 echo '#if $(abi-$(v)-condition)'; \
Packit 6c4009
	 echo '# include <gnu/lib-names-$(v).h>'); \
Packit 6c4009
	 $(if $(abi-$(v)-condition),echo '#endif';)) \
Packit 6c4009
	 echo ''; \
Packit 6c4009
	 echo '#endif	/* gnu/lib-names.h */'; \
Packit 6c4009
	} >  $@
Packit 6c4009
endif
Packit 6c4009
$(common-objpfx)$(lib-names-h-abi): $(common-objpfx)$(lib-names-stmp-abi); @:
Packit 6c4009
$(common-objpfx)$(lib-names-stmp-abi): $(..)scripts/lib-names.awk \
Packit 6c4009
				       $(common-objpfx)soversions.i
Packit 6c4009
	$(make-target-directory)
Packit 6c4009
	{ \
Packit 6c4009
	 $(if $(abi-variants), \
Packit 6c4009
	 echo '/* This file is automatically generated.  */';\
Packit 6c4009
	 echo '#ifndef __GNU_LIB_NAMES_H'; \
Packit 6c4009
	 echo '# error "Never use <$(lib-names-h-abi)> directly; include <gnu/lib-names.h> instead."'; \
Packit 6c4009
	 echo '#endif';, \
Packit 6c4009
	 echo '/* This file is automatically generated.';\
Packit 6c4009
	 echo '   It defines macros to allow user program to find the shared'; \
Packit 6c4009
	 echo '   library files which come as part of GNU libc.  */'; \
Packit 6c4009
	 echo '#ifndef __GNU_LIB_NAMES_H'; \
Packit 6c4009
	 echo '#define __GNU_LIB_NAMES_H	1';) \
Packit 6c4009
	 echo ''; \
Packit 6c4009
	 ($(foreach s,$(all-sonames), echo $(s);)) \
Packit 6c4009
	 | LC_ALL=C $(AWK) -f $(firstword $^) | LC_ALL=C sort; \
Packit 6c4009
	 $(if $(abi-variants),, \
Packit 6c4009
	 echo ''; \
Packit 6c4009
	 echo '#endif	/* gnu/lib-names.h */';) \
Packit 6c4009
	} >  ${@:stmp=T}
Packit 6c4009
	$(move-if-change) ${@:stmp=T} ${@:stmp=h}
Packit 6c4009
	touch $@
Packit 6c4009
endif
Packit 6c4009
common-generated += $(lib-names-h-abi) $(lib-names-stmp-abi)
Packit 6c4009
endif
Packit 6c4009

Packit 6c4009
###############################################################################
Packit 6c4009
# NOTE!  Everything adding to before-compile needs to come before this point! #
Packit 6c4009
###############################################################################
Packit 6c4009
Packit 6c4009
# Generate an ordered list of implicit rules which find the source files in
Packit 6c4009
# each sysdep directory.  The old method was to use vpath to search all the
Packit 6c4009
# sysdep directories.  However, that had the problem that a .S file in a
Packit 6c4009
# later directory would be chosen over a .c file in an earlier directory,
Packit 6c4009
# which does not preserve the desired sysdeps ordering behavior.
Packit 6c4009
Packit 6c4009
# System-dependent makefiles can put in `inhibit-sysdep-asm' regexps
Packit 6c4009
# matching sysdep directories whose assembly source files should be
Packit 6c4009
# suppressed.
Packit 6c4009
Packit 6c4009
-include $(common-objpfx)sysd-rules
Packit 6c4009
ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
Packit 6c4009
# The value of $(+sysdep_dirs) the sysd-rules was computed for
Packit 6c4009
# differs from the one we are using now.  So force a rebuild of sysd-rules.
Packit 6c4009
sysd-rules-force = FORCE
Packit 6c4009
FORCE:
Packit 6c4009
endif
Packit 6c4009
$(common-objpfx)sysd-rules: $(..)scripts/sysd-rules.awk \
Packit 6c4009
			    $(common-objpfx)config.make $(..)Makerules \
Packit 6c4009
			    $(sysdep-makefiles) $(sysdep-makeconfigs) \
Packit 6c4009
			    $(sysd-rules-force)
Packit 6c4009
	-@rm -f $@T
Packit 6c4009
	LC_ALL=C $(AWK) -f $< > $@T \
Packit 6c4009
			-v all_object_suffixes='$(all-object-suffixes)' \
Packit 6c4009
			-v inhibit_sysdep_asm='$(inhibit-sysdep-asm)' \
Packit 6c4009
			-v sysd_rules_patterns='$(sysd-rules-patterns)' \
Packit 6c4009
			-v config_sysdirs='$(config-sysdirs)'
Packit 6c4009
	mv -f $@T $@
Packit 6c4009
Packit 6c4009
ifndef sysd-rules-done
Packit 6c4009
# Don't do deps until this exists, because it provides rules to make the deps.
Packit 6c4009
no_deps=t
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
define o-iterator-doit
Packit 6c4009
$(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
Packit 6c4009
endef
Packit 6c4009
object-suffixes-left := $(all-object-suffixes)
Packit 6c4009
include $(o-iterator)
Packit 6c4009
Packit 6c4009
define o-iterator-doit
Packit 6c4009
$(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
Packit 6c4009
endef
Packit 6c4009
object-suffixes-left := $(all-object-suffixes)
Packit 6c4009
include $(o-iterator)
Packit 6c4009
Packit 6c4009
define o-iterator-doit
Packit 6c4009
$(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
Packit 6c4009
endef
Packit 6c4009
object-suffixes-left := $(all-object-suffixes)
Packit 6c4009
include $(o-iterator)
Packit 6c4009
Packit 6c4009
# Omit the objpfx rules when building in the source tree, because
Packit 6c4009
# objpfx is empty and so these rules just override the ones above.
Packit 6c4009
ifdef objpfx
Packit 6c4009
# Define first rules to find the source files in $(objpfx).
Packit 6c4009
# Generated source files will end up there.
Packit 6c4009
define o-iterator-doit
Packit 6c4009
$(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
Packit 6c4009
endef
Packit 6c4009
object-suffixes-left := $(all-object-suffixes)
Packit 6c4009
include $(o-iterator)
Packit 6c4009
Packit 6c4009
define o-iterator-doit
Packit 6c4009
$(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
Packit 6c4009
endef
Packit 6c4009
object-suffixes-left := $(all-object-suffixes)
Packit 6c4009
include $(o-iterator)
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
# Generate version maps, but wait until sysdep-subdirs is known
Packit 6c4009
ifeq ($(sysd-sorted-done),t)
Packit 6c4009
ifeq ($(build-shared),yes)
Packit 6c4009
-include $(common-objpfx)sysd-versions
Packit 6c4009
$(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
Packit 6c4009
common-generated += $(version-maps)
Packit 6c4009
postclean-generated += sysd-versions Versions.all abi-versions.h \
Packit 6c4009
		       Versions.def Versions.v.i Versions.v
Packit 6c4009
Packit 6c4009
ifndef avoid-generated
Packit 6c4009
ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
Packit 6c4009
sysd-versions-force = FORCE
Packit 6c4009
FORCE:
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
$(common-objpfx)Versions.def: $(..)scripts/versionlist.awk \
Packit 6c4009
			      $(common-objpfx)Versions.v
Packit 6c4009
	LC_ALL=C $(AWK) -f $^ > $@T
Packit 6c4009
	mv -f $@T $@
Packit 6c4009
Packit 6c4009
$(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
Packit 6c4009
			      $(common-objpfx)soversions.i \
Packit 6c4009
			      $(common-objpfx)Versions.def
Packit 6c4009
	{ while read which lib version setname; do \
Packit 6c4009
	    test x"$$which" = xDEFAULT || continue; \
Packit 6c4009
	    test -z "$$setname" || echo "$$lib : $$setname"; \
Packit 6c4009
	  done < $(word 2,$^); \
Packit 6c4009
	  cat $(word 3,$^); \
Packit 6c4009
	} | LC_ALL=C $(AWK) -f $< > $@T
Packit 6c4009
	mv -f $@T $@
Packit 6c4009
# See %.v/%.v.i implicit rules in Makeconfig.
Packit 6c4009
$(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
Packit 6c4009
			      $(wildcard $(sysdirs:%=%/Versions)) \
Packit 6c4009
			      $(sysd-versions-force)
Packit 6c4009
$(common-objpfx)sysd-versions: $(common-objpfx)versions.stmp
Packit 6c4009
$(common-objpfx)versions.stmp: $(common-objpfx)Versions.all \
Packit 6c4009
			       $(common-objpfx)Versions.v \
Packit 6c4009
			       $(..)scripts/versions.awk
Packit 6c4009
	( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
Packit 6c4009
	  cat $(word 2,$^) \
Packit 6c4009
	  | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
Packit 6c4009
			    -v move_if_change='$(move-if-change)' \
Packit 6c4009
			    -f $(word 3,$^); \
Packit 6c4009
	) > $(common-objpfx)sysd-versionsT
Packit 6c4009
	mv -f $(common-objpfx)sysd-versionsT $(common-objpfx)sysd-versions
Packit 6c4009
	touch $@
Packit 6c4009
endif # avoid-generated
Packit 6c4009
endif # $(build-shared) = yes
Packit 6c4009
endif # sysd-sorted-done
Packit 6c4009
Packit 6c4009
# Generate .dT files as we compile.
Packit 6c4009
compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
Packit 6c4009
compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
Packit 6c4009
compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
Packit 6c4009
compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
Packit 6c4009
Packit 6c4009
# Like compile-mkdep-flags, but for use with $(BUILD_CC).  We don't want to
Packit 6c4009
# track system includes here, they may spuriously trigger an install rule,
Packit 6c4009
# and would cause the check-local-headers test to fail.
Packit 6c4009
native-compile-mkdep-flags = -MMD -MP -MF $@.dt -MT $@
Packit 6c4009
Packit 6c4009
# GCC can grok options after the file name, and it looks nicer that way.
Packit 6c4009
compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
Packit 6c4009
compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
Packit 6c4009
compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
Packit 6c4009
		  $(ASFLAGS) $(ASFLAGS-$(suffix $@))
Packit 6c4009
COMPILE.c = $(CC) -c $(CFLAGS) $(CPPFLAGS)
Packit 6c4009
COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
Packit 6c4009
		  $(ASFLAGS) $(ASFLAGS-$(suffix $@))
Packit 6c4009
Packit 6c4009
# We need this for the output to go in the right place.  It will default to
Packit 6c4009
# empty if make was configured to work with a cc that can't grok -c and -o
Packit 6c4009
# together.  You can't compile the C library with such a compiler.
Packit 6c4009
OUTPUT_OPTION = -o $@
Packit 6c4009
Packit 6c4009
# This is the end of the pipeline for compiling generated C code.
Packit 6c4009
compile-stdin.c = $(COMPILE.c) -o $@ -x c - $(compile-mkdep-flags)
Packit 6c4009
Packit 6c4009
# We need the $(CFLAGS) to be in there to have the right predefines during
Packit 6c4009
# the dependency run for C sources.  But having it for assembly sources can
Packit 6c4009
# get the wrong predefines.
Packit 6c4009
S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
Packit 6c4009
Packit 6c4009
define +make-deps
Packit 6c4009
$(make-target-directory)
Packit 6c4009
$(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
Packit 6c4009
	     $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(
Packit 6c4009
's,$(subst .,\.,$(@F:.d=.o)),$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
Packit 6c4009
$(sed-remove-objpfx) $(sed-remove-dotdot) > $(@:.d=.T)
Packit 6c4009
mv -f $(@:.d=.T) $@ $(generate-md5)
Packit 6c4009
endef
Packit 6c4009
Packit 6c4009
ifneq (,$(objpfx))
Packit 6c4009
# Continuation lines here are dangerous because they introduce spaces!
Packit 6c4009
define sed-remove-objpfx
Packit 6c4009
-e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
Packit 6c4009
-e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
Packit 6c4009
endef
Packit 6c4009
endif
Packit 6c4009

Packit 6c4009
# Modify the list of routines we build for different targets
Packit 6c4009
Packit 6c4009
ifeq (yes,$(build-shared))
Packit 6c4009
ifndef libc.so-version
Packit 6c4009
# Undefine this because it can't work when we libc.so is unversioned.
Packit 6c4009
static-only-routines =
Packit 6c4009
endif
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
elide-routines.oS += $(filter-out $(static-only-routines),\
Packit 6c4009
				  $(routines) $(aux) $(sysdep_routines))
Packit 6c4009
elide-routines.os += $(static-only-routines)
Packit 6c4009
Packit 6c4009
# If we have versioned code we don't need the old versions in any of the
Packit 6c4009
# static libraries.
Packit 6c4009
elide-routines.o  += $(shared-only-routines)
Packit 6c4009
elide-routines.op += $(shared-only-routines)
Packit 6c4009

Packit 6c4009
# Shared library building.
Packit 6c4009
Packit 6c4009
ifeq (yes,$(build-shared))
Packit 6c4009
Packit 6c4009
# Reference map file only when shared libraries are built and a map file name
Packit 6c4009
# is given.
Packit 6c4009
ifeq ($(build-shared),yes)
Packit 6c4009
map-file = $(firstword $($(@F:.so=-map)) \
Packit 6c4009
		       $(addprefix $(common-objpfx), \
Packit 6c4009
				   $(filter $(@F:.so=.map),$(version-maps))))
Packit 6c4009
load-map-file = $(map-file:%=-Wl,--version-script=%)
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
# Compiler arguments to use to link a shared object with libc and
Packit 6c4009
# ld.so.  This is intended to be as similar as possible to a default
Packit 6c4009
# link with an installed libc.
Packit 6c4009
link-libc-args = -Wl,--start-group \
Packit 6c4009
		 $(libc-for-link) \
Packit 6c4009
		 $(common-objpfx)libc_nonshared.a \
Packit 6c4009
		 $(as-needed) $(elf-objpfx)ld.so $(no-as-needed) \
Packit 6c4009
		 -Wl,--end-group
Packit 6c4009
Packit 6c4009
# The corresponding shared libc to use.  This may be modified for a
Packit 6c4009
# particular target.
Packit 6c4009
libc-for-link = $(common-objpfx)libc.so
Packit 6c4009
Packit 6c4009
# The corresponding dependencies.  As these are used in dependencies,
Packit 6c4009
# not just commands, they cannot use target-specific variables so need
Packit 6c4009
# to name both possible libc.so objects.
Packit 6c4009
link-libc-deps = $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so \
Packit 6c4009
		 $(common-objpfx)libc_nonshared.a $(elf-objpfx)ld.so
Packit 6c4009
Packit 6c4009
# Pattern rule to build a shared object from an archive of PIC objects.
Packit 6c4009
# This must come after the installation rules so Make doesn't try to
Packit 6c4009
# build shared libraries in place from the installed *_pic.a files.
Packit 6c4009
# $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
Packit 6c4009
# on other shared objects.  The linking with libc and ld.so is intended
Packit 6c4009
# to be as similar as possible to a default link with an installed libc.
Packit 6c4009
lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(link-libc-deps)
Packit 6c4009
	$(build-shlib) $(link-libc-args)
Packit 6c4009
	$(call after-link,$@)
Packit 6c4009
Packit 6c4009
define build-shlib-helper
Packit 6c4009
$(LINK.o) -shared -static-libgcc -Wl,-O1 $(sysdep-LDFLAGS) \
Packit 6c4009
	  $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(rtld-LDFLAGS) \
Packit 6c4009
	  $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
Packit 6c4009
	  $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
Packit 6c4009
	  -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
Packit 6c4009
	  $(LDFLAGS.so) $(LDFLAGS-lib.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
Packit 6c4009
	  -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
Packit 6c4009
endef
Packit 6c4009
Packit 6c4009
ifeq (yes,$(use-default-link))
Packit 6c4009
# If the linker is good enough, we can let it use its default linker script.
Packit 6c4009
shlib-lds =
Packit 6c4009
shlib-lds-flags =
Packit 6c4009
else
Packit 6c4009
# binutils only position loadable notes into the first page for binaries,
Packit 6c4009
# not for shared objects
Packit 6c4009
$(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
Packit 6c4009
	$(LINK.o) -shared -Wl,-O1 \
Packit 6c4009
		  -nostdlib -nostartfiles \
Packit 6c4009
		  $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
Packit 6c4009
		  -Wl,--verbose 2>&1 | \
Packit 6c4009
	  sed > $@T \
Packit 6c4009
	      -e '/^=========/,/^=========/!d;/^=========/d' \
Packit 6c4009
	      $(if $(filter yes,$(have-hash-style)), \
Packit 6c4009
		   -e 's/^.*\.gnu\.hash[ 	]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
Packit 6c4009
		   -e '/^[ 	]*\.hash[ 	]*:.*$$/{h;d;}' \
Packit 6c4009
		   -e '/DATA_SEGMENT_ALIGN/{H;g}' \
Packit 6c4009
		, \
Packit 6c4009
		   -e 's/^.*\.hash[ 	]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
Packit 6c4009
	       ) \
Packit 6c4009
	      -e 's/^.*\*(\.dynbss).*$$/& \
Packit 6c4009
		 PROVIDE(__start___libc_freeres_ptrs = .); \
Packit 6c4009
		 *(__libc_freeres_ptrs) \
Packit 6c4009
		 PROVIDE(__stop___libc_freeres_ptrs = .);/'\
Packit 6c4009
	      -e 's@^.*\*(\.jcr).*$$@& \
Packit 6c4009
		 PROVIDE(__start___libc_subfreeres = .);\
Packit 6c4009
		 __libc_subfreeres : { *(__libc_subfreeres) }\
Packit 6c4009
		 PROVIDE(__stop___libc_subfreeres = .);\
Packit 6c4009
		 PROVIDE(__start___libc_atexit = .);\
Packit 6c4009
		 __libc_atexit : { *(__libc_atexit) }\
Packit 6c4009
		 PROVIDE(__stop___libc_atexit = .);\
Packit 6c4009
		 PROVIDE(__start___libc_IO_vtables = .);\
Packit 6c4009
		 __libc_IO_vtables : { *(__libc_IO_vtables) }\
Packit 6c4009
		 PROVIDE(__stop___libc_IO_vtables = .);\
Packit 6c4009
		 /DISCARD/ : { *(.gnu.glibc-stub.*) }@'
Packit 6c4009
	test -s $@T
Packit 6c4009
	mv -f $@T $@
Packit 6c4009
common-generated += shlib.lds
Packit 6c4009
Packit 6c4009
shlib-lds = $(common-objpfx)shlib.lds
Packit 6c4009
shlib-lds-flags = -T $(shlib-lds)
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
define build-shlib
Packit 6c4009
$(build-shlib-helper) -o $@ $(shlib-lds-flags) \
Packit 6c4009
	  $(csu-objpfx)abi-note.o $(build-shlib-objlist)
Packit 6c4009
endef
Packit 6c4009
Packit 6c4009
define build-module-helper
Packit 6c4009
$(LINK.o) -shared -static-libgcc $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
Packit 6c4009
	  $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
Packit 6c4009
	  -B$(csu-objpfx) $(load-map-file) \
Packit 6c4009
	  $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
Packit 6c4009
	  -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
Packit 6c4009
endef
Packit 6c4009
Packit 6c4009
# This macro is similar to build-shlib but it does not define a soname
Packit 6c4009
# and it does not depend on the destination name to start with `lib'.
Packit 6c4009
# binutils only position loadable notes into the first page for binaries,
Packit 6c4009
# not for shared objects
Packit 6c4009
define build-module
Packit 6c4009
$(build-module-helper) -o $@ $(shlib-lds-flags) \
Packit 6c4009
	  $(csu-objpfx)abi-note.o $(build-module-objlist) $(link-libc-args)
Packit 6c4009
$(call after-link,$@)
Packit 6c4009
endef
Packit 6c4009
define build-module-asneeded
Packit 6c4009
$(build-module-helper) -o $@ $(shlib-lds-flags) \
Packit 6c4009
	  $(csu-objpfx)abi-note.o \
Packit 6c4009
	  -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed \
Packit 6c4009
	  $(link-libc-args)
Packit 6c4009
$(call after-link,$@)
Packit 6c4009
endef
Packit 6c4009
Packit 6c4009
# sofini.os must be placed last since it terminates .eh_frame section.
Packit 6c4009
build-module-helper-objlist = \
Packit 6c4009
	$(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
Packit 6c4009
		   $(filter-out %.lds $(map-file) $(+preinit) $(+postinit) \
Packit 6c4009
				$(elf-objpfx)sofini.os \
Packit 6c4009
				$(link-libc-deps),$^))
Packit 6c4009
Packit 6c4009
build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
Packit 6c4009
build-shlib-objlist = $(build-module-helper-objlist) \
Packit 6c4009
		      $(LDLIBS-$(@F:lib%.so=%).so) \
Packit 6c4009
		      $(filter $(elf-objpfx)sofini.os,$^)
Packit 6c4009
Packit 6c4009
# Don't try to use -lc when making libc.so itself.
Packit 6c4009
# Also omits crti.o and crtn.o, which we do not want
Packit 6c4009
# since we define our own `.init' section specially.
Packit 6c4009
LDFLAGS-c.so = -nostdlib -nostartfiles
Packit 6c4009
# But we still want to link libc.so against $(libc.so-gnulib).
Packit 6c4009
LDLIBS-c.so += $(libc.so-gnulib)
Packit 6c4009
# Give libc.so an entry point and make it directly runnable itself.
Packit 6c4009
LDFLAGS-c.so += -e __libc_main
Packit 6c4009
# Pre-link the objects of libc_pic.a so that we can locally resolve
Packit 6c4009
# COMMON symbols before we link against ld.so.  This is because ld.so
Packit 6c4009
# contains some of libc_pic.a already, which will prevent the COMMONs
Packit 6c4009
# from being allocated in libc.so, which introduces evil dependencies
Packit 6c4009
# between libc.so and ld.so, which can make it impossible to upgrade.
Packit 6c4009
$(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
Packit 6c4009
	$(LINK.o) -nostdlib -nostartfiles -r -o $@ \
Packit 6c4009
	$(LDFLAGS-c_pic.os) -Wl,-d $(whole-archive) $^ -o $@
Packit 6c4009
Packit 6c4009
ifeq (,$(strip $(shlib-lds-flags)))
Packit 6c4009
# Generate a list of -R options to excise .gnu.glibc-stub.* sections.
Packit 6c4009
$(common-objpfx)libc_pic.opts: $(common-objpfx)libc_pic.os
Packit 6c4009
	$(OBJDUMP) -h $< | \
Packit 6c4009
	$(AWK) '$$2 ~ /\.gnu\.glibc-stub\./ { print "-R", $$2 }' \
Packit 6c4009
		> $@T
Packit 6c4009
	mv -f $@T $@
Packit 6c4009
# Apply those -R options.
Packit 6c4009
$(common-objpfx)libc_pic.os.clean: $(common-objpfx)libc_pic.opts \
Packit 6c4009
				   $(common-objpfx)libc_pic.os
Packit 6c4009
	$(OBJCOPY) @$^ $@
Packit 6c4009
generated += libc_pic.opts libc_pic.os.clean
Packit 6c4009
Packit 6c4009
libc_pic_clean := .clean
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
# Build a possibly-modified version of libc_pic.a for use in building
Packit 6c4009
# linkobj/libc.so.
Packit 6c4009
ifeq (,$(filter sunrpc,$(subdirs)))
Packit 6c4009
$(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a
Packit 6c4009
	$(make-target-directory)
Packit 6c4009
	ln -f $< $@
Packit 6c4009
else
Packit 6c4009
$(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a \
Packit 6c4009
				    $(common-objpfx)sunrpc/librpc_compat_pic.a
Packit 6c4009
	$(make-target-directory)
Packit 6c4009
	(cd $(common-objpfx)linkobj; \
Packit 6c4009
	 $(AR) x ../libc_pic.a; \
Packit 6c4009
	 rm $$($(AR) t ../sunrpc/librpc_compat_pic.a | sed 's/^compat-//'); \
Packit 6c4009
	 $(AR) x ../sunrpc/librpc_compat_pic.a; \
Packit 6c4009
	 $(AR) cr libc_pic.a *.os; \
Packit 6c4009
	 rm *.os)
Packit 6c4009
endif # $(subdirs) contains sunrpc
Packit 6c4009
Packit 6c4009
# Clear link-libc-deps for the libc.so libraries so build-shlibs does not
Packit 6c4009
# filter ld.so out of the list of linked objects.
Packit 6c4009
$(common-objpfx)libc.so: link-libc-deps = # empty
Packit 6c4009
$(common-objpfx)linkobj/libc.so: link-libc-deps = # empty
Packit 6c4009
Packit 6c4009
# Use our own special initializer and finalizer files for the libc.so
Packit 6c4009
# libraries.
Packit 6c4009
$(common-objpfx)libc.so: $(elf-objpfx)soinit.os \
Packit 6c4009
			 $(common-objpfx)libc_pic.os$(libc_pic_clean) \
Packit 6c4009
			 $(elf-objpfx)sofini.os \
Packit 6c4009
			 $(elf-objpfx)interp.os \
Packit 6c4009
			 $(elf-objpfx)ld.so \
Packit 6c4009
			 $(shlib-lds)
Packit 6c4009
	$(build-shlib)
Packit 6c4009
	$(call after-link,$@)
Packit 6c4009
Packit 6c4009
$(common-objpfx)linkobj/libc.so: $(elf-objpfx)soinit.os \
Packit 6c4009
			 $(common-objpfx)linkobj/libc_pic.a \
Packit 6c4009
			 $(elf-objpfx)sofini.os \
Packit 6c4009
			 $(elf-objpfx)interp.os \
Packit 6c4009
			 $(elf-objpfx)ld.so \
Packit 6c4009
			 $(shlib-lds)
Packit 6c4009
	$(build-shlib)
Packit 6c4009
	$(call after-link,$@)
Packit 6c4009
Packit 6c4009
ifeq ($(build-shared),yes)
Packit 6c4009
$(common-objpfx)libc.so: $(common-objpfx)libc.map
Packit 6c4009
endif
Packit 6c4009
common-generated += libc.so libc_pic.os
Packit 6c4009
ifdef libc.so-version
Packit 6c4009
$(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
Packit 6c4009
	$(make-link)
Packit 6c4009
common-generated += libc.so$(libc.so-version)
Packit 6c4009
endif
Packit 6c4009
endif
Packit 6c4009

Packit 6c4009
# Figure out the source filenames in this directory.
Packit 6c4009
Packit 6c4009
override sources := $(addsuffix .c,\
Packit 6c4009
			$(filter-out $(elided-routines),\
Packit 6c4009
			    $(routines) $(aux) \
Packit 6c4009
			    $(sysdep_routines)))
Packit 6c4009
sysdep_routines := $(sysdep_routines)
Packit 6c4009
Packit 6c4009
headers := $(headers) $(sysdep_headers)
Packit 6c4009
Packit 6c4009
# This is the list of all object files, gotten by
Packit 6c4009
# replacing every ".c" in `sources' with a ".o".
Packit 6c4009
override objects := $(addprefix $(objpfx),$(sources:.c=.o))
Packit 6c4009
Packit 6c4009
Packit 6c4009
# The makefile may define $(extra-libs) with `libfoo libbar'
Packit 6c4009
# to build libfoo.a et al from the modules listed in $(libfoo-routines).
Packit 6c4009
ifdef extra-libs
Packit 6c4009
# extra-lib.mk is included once for each extra lib to define rules
Packit 6c4009
# to build it, and to add its objects to the various variables.
Packit 6c4009
# During its evaluation, $(lib) is set to the name of the library.
Packit 6c4009
extra-libs-left := $(extra-libs)
Packit 6c4009
include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
# The makefile may define $(modules-names) to build additional modules.
Packit 6c4009
# These are built with $(build-module), except any in $(modules-names-nobuild).
Packit 6c4009
# MODULE_NAME=extramodules, except any in $(modules-names-tests).
Packit 6c4009
ifdef modules-names
Packit 6c4009
cpp-srcs-left := $(filter-out $(modules-names-tests),$(modules-names))
Packit 6c4009
ifneq (,$(cpp-srcs-left))
Packit 6c4009
lib := extramodules
Packit 6c4009
include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
ifdef modules-names-tests
Packit 6c4009
cpp-srcs-left := $(filter $(modules-names-tests),$(modules-names))
Packit 6c4009
ifneq (,$(cpp-srcs-left))
Packit 6c4009
lib := testsuite
Packit 6c4009
include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
Packit 6c4009
endif
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
Packit 6c4009
$(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
Packit 6c4009
		$(objpfx)%.os $(shlib-lds) $(link-libs-deps)
Packit 6c4009
	$(build-module)
Packit 6c4009
endif
Packit 6c4009

Packit 6c4009
+depfiles := $(sources:.c=.d) \
Packit 6c4009
	     $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
Packit 6c4009
	     $(patsubst %.oS,%.d,$(filter %.oS,$(extra-objs))) \
Packit 6c4009
	     $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
Packit 6c4009
	     $(addsuffix .d,$(tests) $(tests-internal) $(xtests) $(test-srcs))
Packit 6c4009
ifeq ($(build-programs),yes)
Packit 6c4009
+depfiles += $(addsuffix .d,$(others) $(sysdep-others))
Packit 6c4009
endif
Packit 6c4009
+depfiles := $(addprefix $(objpfx),\
Packit 6c4009
			 $(filter-out $(addsuffix .d,$(omit-deps)),\
Packit 6c4009
				      $(+depfiles)))
Packit 6c4009
all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
Packit 6c4009
+depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
Packit 6c4009
	     $(wildcard $(all-dt-files:.dt=.d))
Packit 6c4009
Packit 6c4009
# This is a funny rule in that it removes its input file.
Packit 6c4009
%.d: %.dt
Packit 6c4009
	@sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
Packit 6c4009
	 mv -f $(@:.d=.T) $@ && \
Packit 6c4009
	 rm -f $<
Packit 6c4009
Packit 6c4009
# Avoid the .h.d files for any .sym files whose .h files don't exist yet.
Packit 6c4009
# They will be generated when they're needed, and trying too early won't work.
Packit 6c4009
+gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
Packit 6c4009
+depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
Packit 6c4009
						$(+gen-as-const)))
Packit 6c4009
Packit 6c4009
ifdef +depfiles
Packit 6c4009
ifneq ($(no_deps),t)
Packit 6c4009
-include $(+depfiles)
Packit 6c4009
endif
Packit 6c4009
endif
Packit 6c4009

Packit 6c4009
# Maximize efficiency by minimizing the number of rules.
Packit 6c4009
.SUFFIXES:	# Clear the suffix list.  We don't use suffix rules.
Packit 6c4009
# Don't define any builtin rules.
Packit 6c4009
MAKEFLAGS := $(MAKEFLAGS)r
Packit 6c4009
Packit 6c4009
# Generic rule for making directories.
Packit 6c4009
%/:
Packit 6c4009
# mkdir isn't smart enough to strip a trailing /.
Packit 6c4009
# We always require a mkdir which supports the -p option to avoid error
Packit 6c4009
# messages in case of races.
Packit 6c4009
	mkdir -p $(@:%/=%)
Packit 6c4009

Packit 6c4009
# Make sure that object files are not removed
Packit 6c4009
# when they are intermediates between sources and library members.
Packit 6c4009
.PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
Packit 6c4009
Packit 6c4009
# Make sure that the parent library archive is never removed.
Packit 6c4009
.PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
Packit 6c4009

Packit 6c4009
# Use the verbose option of ar and tar when not running silently.
Packit 6c4009
ifeq	"$(findstring s,$(MAKEFLAGS))" ""	# if not -s
Packit 6c4009
verbose := v
Packit 6c4009
else	   					# -s
Packit 6c4009
verbose	:=
Packit 6c4009
endif						# not -s
Packit 6c4009
Packit 6c4009
ARFLAGS := r$(verbose)
Packit 6c4009
CREATE_ARFLAGS := cru$(verbose)
Packit 6c4009

Packit 6c4009
# This makes all the object files in the parent library archive.
Packit 6c4009
Packit 6c4009
.PHONY: lib lib-noranlib
Packit 6c4009
lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
Packit 6c4009
lib-noranlib: libobjs
Packit 6c4009
Packit 6c4009
# For object-suffix $o, the list of objects with that suffix.
Packit 6c4009
# Makefiles can define `elide-routines.so = foo' to leave foo.so out.
Packit 6c4009
o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
Packit 6c4009
						       $(elide-routines$o)),\
Packit 6c4009
					    $(objects))) \
Packit 6c4009
	    $(addprefix $(objpfx),$(o-objects$o))
Packit 6c4009
Packit 6c4009
others: $(addprefix $(objpfx),$(install-lib))
Packit 6c4009
Packit 6c4009
ifndef objects
Packit 6c4009
Packit 6c4009
# Create the stamp$o files to keep the parent makefile happy.
Packit 6c4009
subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
Packit 6c4009
$(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
Packit 6c4009
	$(make-target-directory)
Packit 6c4009
	rm -f $@; > $@
Packit 6c4009
else
Packit 6c4009
Packit 6c4009
# Define explicit rules to update each $(objpfx)stamp.SUFFIX
Packit 6c4009
# timestamp file; these rules (one explicit rule is generated for each
Packit 6c4009
# object suffix) write a list of objects to update in the stamp file.
Packit 6c4009
# The parent will then actually add them all to the archive in the
Packit 6c4009
# archive rule, below.
Packit 6c4009
define o-iterator-doit
Packit 6c4009
$(objpfx)stamp$o: $(o-objects); $$(do-stamp)
Packit 6c4009
endef
Packit 6c4009
define do-stamp
Packit 6c4009
$(make-target-directory)
Packit 6c4009
echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
Packit 6c4009
mv -f $@T $@
Packit 6c4009
endef
Packit 6c4009
object-suffixes-left := $(object-suffixes-for-libc)
Packit 6c4009
include $(o-iterator)
Packit 6c4009
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
# Now define explicit rules to build the library archives; these depend
Packit 6c4009
# on the stamp files built above.
Packit 6c4009
define o-iterator-doit
Packit 6c4009
$(common-objpfx)$(patsubst %,$(libtype$o),c): \
Packit 6c4009
		$(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
Packit 6c4009
endef
Packit 6c4009
define do-makelib
Packit 6c4009
cd $(common-objdir) && \
Packit 6c4009
$(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
Packit 6c4009
endef
Packit 6c4009
subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
Packit 6c4009
subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
Packit 6c4009
ifndef subdir
Packit 6c4009
$(subdirs-stamps): subdir_lib;
Packit 6c4009
endif
Packit 6c4009
object-suffixes-left = $(object-suffixes-for-libc)
Packit 6c4009
include $(o-iterator)
Packit 6c4009
Packit 6c4009
Packit 6c4009
# This makes all the object files.
Packit 6c4009
.PHONY: objects objs libobjs extra-objs
Packit 6c4009
objects objs: libobjs extra-objs
Packit 6c4009
libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
Packit 6c4009
extra-objs: $(addprefix $(objpfx),$(extra-objs))
Packit 6c4009
Packit 6c4009
# Canned sequence for building an extra library archive.
Packit 6c4009
define build-extra-lib
Packit 6c4009
$(patsubst %/,cd % &&,$(objpfx)) \
Packit 6c4009
$(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
Packit 6c4009
      $(patsubst $(objpfx)%,%,$^)
Packit 6c4009
endef
Packit 6c4009

Packit 6c4009
# Installation.
Packit 6c4009
Packit 6c4009
.PHONY: force-install
Packit 6c4009
force-install:
Packit 6c4009
Packit 6c4009
# $(install-lib) are installed from the object directory into $(libdir);
Packit 6c4009
# files in $(install-lib) matching `lib%.a' are ranlib'd after installation
Packit 6c4009
# unless they also appear in $(non-lib.a).  $(install-data) are installed as
Packit 6c4009
# they are into $(datadir).  $(headers) are installed as they are in
Packit 6c4009
# $(includedir).  $(install-bin), $(install-bin-script) and $(install-sbin)
Packit 6c4009
# are installed from the object directory into $(bindir), $(bindir) and
Packit 6c4009
# $(sbindir), respectively.  $(install-others) and $(install-others-programs)
Packit 6c4009
# are absolute path names of files to install; rules to install them are
Packit 6c4009
# defined elsewhere.
Packit 6c4009
Packit 6c4009
# The simple library name to install libc.a under.
Packit 6c4009
# This could be defined by a sysdep Makefile.
Packit 6c4009
ifndef libc-name
Packit 6c4009
libc-name := c
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
define do-install
Packit 6c4009
$(make-target-directory)
Packit 6c4009
$(INSTALL_DATA) $< $@
Packit 6c4009
endef
Packit 6c4009
Packit 6c4009
# Make the target directory if it doesn't exist, using the `mkinstalldirs'
Packit 6c4009
# script that does `mkdir -p' even if `mkdir' doesn't support that flag.
Packit 6c4009
define make-target-directory
Packit 6c4009
$(addprefix $(..)./scripts/mkinstalldirs ,\
Packit 6c4009
	    $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
Packit 6c4009
endef
Packit 6c4009
Packit 6c4009
# Any directory (parent or subdir) should install libc.a; this way
Packit 6c4009
# "make install" in a subdir is guaranteed to install everything it changes.
Packit 6c4009
installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
Packit 6c4009
			     $(inst_libdir)/$(patsubst %,$(libtype$o),\
Packit 6c4009
						     $(libprefix)$(libc-name)))
Packit 6c4009
Packit 6c4009
.PHONY: check-install-supported
Packit 6c4009
check-install-supported:
Packit 6c4009
Packit 6c4009
# Check to see if the prefix or exec_prefix GNU standard variable
Packit 6c4009
# has been overridden on the command line and, if so, fail with
Packit 6c4009
# an error message since doing so is not supported (set DESTDIR
Packit 6c4009
# instead).
Packit 6c4009
ifeq ($(origin prefix),command line)
Packit 6c4009
check-install-supported:
Packit 6c4009
	$(error Overriding prefix is not supported. Set DESTDIR instead.)
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
ifeq ($(origin exec_prefix),command line)
Packit 6c4009
check-install-supported:
Packit 6c4009
	$(error Overriding exec_prefix is not supported. Set DESTDIR instead.)
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
install: check-install-supported
Packit 6c4009
Packit 6c4009
install: $(installed-libcs)
Packit 6c4009
$(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
Packit 6c4009
	$(make-target-directory)
Packit 6c4009
	$(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
Packit 6c4009
Packit 6c4009
define do-install-program
Packit 6c4009
$(make-target-directory)
Packit 6c4009
$(INSTALL_PROGRAM) $< $@.new
Packit 6c4009
mv -f $@.new $@
Packit 6c4009
endef
Packit 6c4009
Packit 6c4009
define do-install-script
Packit 6c4009
$(make-target-directory)
Packit 6c4009
$(INSTALL_SCRIPT) $< $@.new
Packit 6c4009
mv -f $@.new $@
Packit 6c4009
endef
Packit 6c4009
Packit 6c4009
install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
Packit 6c4009
install-lib := $(filter-out %.so %_pic.a,$(install-lib))
Packit 6c4009
Packit 6c4009
ifeq (yes,$(build-shared))
Packit 6c4009
# Find which .so's have versions.
Packit 6c4009
versioned := $(strip $(foreach so,$(install-lib.so),\
Packit 6c4009
			       $(patsubst %,$(so),$($(so)-version))))
Packit 6c4009
Packit 6c4009
install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
Packit 6c4009
install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
Packit 6c4009
Packit 6c4009
# For versioned libraries, we install three files:
Packit 6c4009
#	$(inst_libdir)/libfoo.so	-- for linking, symlink or ld script
Packit 6c4009
#	$(inst_slibdir)/libfoo.so.NN	-- for loading by SONAME, symlink
Packit 6c4009
#	$(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
Packit 6c4009
lib-version := $(firstword $($(subdir)-version) $(version))
Packit 6c4009
install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
Packit 6c4009
		      $(foreach L,$(install-lib.so-versioned),\
Packit 6c4009
				$(inst_libdir)/$L \
Packit 6c4009
				$(inst_slibdir)/$(L:.so=)-$(lib-version).so \
Packit 6c4009
				$(inst_slibdir)/$L$($L-version))
Packit 6c4009
Packit 6c4009
# Install all the unversioned shared libraries.
Packit 6c4009
$(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
Packit 6c4009
    $(objpfx)%.so $(+force)
Packit 6c4009
	$(do-install-program)
Packit 6c4009
Packit 6c4009
ifneq ($(findstring -s,$(LN_S)),)
Packit 6c4009
define make-link
Packit 6c4009
rm -f $@.new
Packit 6c4009
$(SHELL) $(..)scripts/rellns-sh $< $@.new
Packit 6c4009
mv -f $@.new $@
Packit 6c4009
endef
Packit 6c4009
define make-link-multidir
Packit 6c4009
$(patsubst %/,cd %,$(objpfx)); \
Packit 6c4009
  $(addprefix $(abspath $(..)scripts/mkinstalldirs) ,$(dir $(multidir))); \
Packit 6c4009
  $(LN_S) . $(multidir) 2> /dev/null; \
Packit 6c4009
  test -L $(multidir)
Packit 6c4009
endef
Packit 6c4009
else
Packit 6c4009
# If we have no symbolic links don't bother with rellns-sh.
Packit 6c4009
define make-link
Packit 6c4009
rm -f $@.new
Packit 6c4009
$(LN_S) $< $@.new
Packit 6c4009
mv -f $@.new $@
Packit 6c4009
endef
Packit 6c4009
define make-link-multidir
Packit 6c4009
$(make-target-directory)
Packit 6c4009
ln -f $(objpfx)/$(@F) $@
Packit 6c4009
endef
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
ifeq (yes,$(build-shared))
Packit 6c4009
ifeq (no,$(cross-compiling))
Packit 6c4009
symbolic-link-prog := $(elf-objpfx)sln
Packit 6c4009
symbolic-link-list := $(elf-objpfx)symlink.list
Packit 6c4009
define make-shlib-link
Packit 6c4009
echo `$(..)scripts/rellns-sh -p $< $@` $@ >> $(symbolic-link-list)
Packit 6c4009
endef
Packit 6c4009
else # cross-compiling
Packit 6c4009
# We need a definition that can be used by elf/Makefile's install rules.
Packit 6c4009
symbolic-link-prog = $(LN_S)
Packit 6c4009
endif
Packit 6c4009
endif
Packit 6c4009
ifndef make-shlib-link
Packit 6c4009
define make-shlib-link
Packit 6c4009
rm -f $@
Packit 6c4009
$(LN_S) `$(..)scripts/rellns-sh -p $< $@` $@
Packit 6c4009
endef
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
ifdef libc.so-version
Packit 6c4009
# For a library specified to be version N, install three files:
Packit 6c4009
# libc.so	->	libc.so.N	(e.g. libc.so.6)
Packit 6c4009
# libc.so.6	->	libc-VERSION.so	(e.g. libc-1.10.so)
Packit 6c4009
Packit 6c4009
$(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
Packit 6c4009
					   $(+force)
Packit 6c4009
	$(make-shlib-link)
Packit 6c4009
$(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
Packit 6c4009
	$(do-install-program)
Packit 6c4009
install: $(inst_slibdir)/libc.so$(libc.so-version)
Packit 6c4009
Packit 6c4009
# This fragment of linker script gives the OUTPUT_FORMAT statement
Packit 6c4009
# for the configuration we are building.  We put this statement into
Packit 6c4009
# the linker scripts we install for -lc et al so that they will not be
Packit 6c4009
# used by a link for a different format on a multi-architecture system.
Packit 6c4009
$(common-objpfx)format.lds: $(..)scripts/output-format.sed \
Packit 6c4009
			    $(common-objpfx)config.make \
Packit 6c4009
			    $(common-objpfx)config.h $(..)Makerules
Packit 6c4009
ifneq (unknown,$(output-format))
Packit 6c4009
	echo > $@.new 'OUTPUT_FORMAT($(output-format))'
Packit 6c4009
else
Packit 6c4009
	$(LINK.o) -shared $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
Packit 6c4009
		  $(LDFLAGS.so) $(LDFLAGS-lib.so) \
Packit 6c4009
		  -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
Packit 6c4009
	| sed -n -f $< > $@.new
Packit 6c4009
	test -s $@.new
Packit 6c4009
	rm -f $@.so
Packit 6c4009
endif
Packit 6c4009
	mv -f $@.new $@
Packit 6c4009
common-generated += format.lds
Packit 6c4009
Packit 6c4009
ifndef subdir
Packit 6c4009
# What we install as libc.so for programs to link against is in fact a
Packit 6c4009
# link script.  It contains references for the various libraries we need.
Packit 6c4009
# The libc.so object is not complete since some functions are only defined
Packit 6c4009
# in libc_nonshared.a.
Packit 6c4009
# We need to use absolute paths since otherwise local copies (if they exist)
Packit 6c4009
# of the files are taken by the linker.
Packit 6c4009
install: $(inst_libdir)/libc.so
Packit 6c4009
$(inst_libdir)/libc.so: $(common-objpfx)format.lds \
Packit 6c4009
			$(common-objpfx)libc.so$(libc.so-version) \
Packit 6c4009
			$(inst_libdir)/$(patsubst %,$(libtype.oS),\
Packit 6c4009
						  $(libprefix)$(libc-name)) \
Packit 6c4009
			$(+force)
Packit 6c4009
	(echo '/* GNU ld script';\
Packit 6c4009
	 echo '   Use the shared library, but some functions are only in';\
Packit 6c4009
	 echo '   the static library, so try that secondarily.  */';\
Packit 6c4009
	 cat $<; \
Packit 6c4009
	 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
Packit 6c4009
	      '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
Packit 6c4009
	      ' AS_NEEDED (' $(rtlddir)/$(rtld-installed-name) ') )' \
Packit 6c4009
	) > $@.new
Packit 6c4009
	mv -f $@.new $@
Packit 6c4009
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
else
Packit 6c4009
install: $(inst_slibdir)/libc.so
Packit 6c4009
$(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
Packit 6c4009
	$(do-install-program)
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
ifneq (,$(versioned))
Packit 6c4009
# Produce three sets of rules as above for all the smaller versioned libraries.
Packit 6c4009
Packit 6c4009
define o-iterator-doit
Packit 6c4009
$(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
Packit 6c4009
endef
Packit 6c4009
object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
Packit 6c4009
ifneq (,$(object-suffixes-left))
Packit 6c4009
include $(o-iterator)
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
# Make symlinks in the build directory, because the versioned names might
Packit 6c4009
# be referenced by a DT_NEEDED in another library.
Packit 6c4009
define o-iterator-doit
Packit 6c4009
$(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
Packit 6c4009
endef
Packit 6c4009
object-suffixes-left := $(versioned)
Packit 6c4009
include $(o-iterator)
Packit 6c4009
Packit 6c4009
generated += $(foreach o,$(versioned),$o$($o-version))
Packit 6c4009
Packit 6c4009
ifeq (,$($(subdir)-version))
Packit 6c4009
define o-iterator-doit
Packit 6c4009
$(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
Packit 6c4009
				 $(+force);
Packit 6c4009
	$$(make-shlib-link)
Packit 6c4009
endef
Packit 6c4009
object-suffixes-left := $(versioned)
Packit 6c4009
include $(o-iterator)
Packit 6c4009
Packit 6c4009
define o-iterator-doit
Packit 6c4009
$(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
Packit 6c4009
	$$(do-install-program)
Packit 6c4009
endef
Packit 6c4009
object-suffixes-left := $(versioned)
Packit 6c4009
include $(o-iterator)
Packit 6c4009
else
Packit 6c4009
define o-iterator-doit
Packit 6c4009
$(inst_slibdir)/$o$($o-version): \
Packit 6c4009
  $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
Packit 6c4009
	$$(make-shlib-link)
Packit 6c4009
endef
Packit 6c4009
object-suffixes-left := $(versioned)
Packit 6c4009
include $(o-iterator)
Packit 6c4009
Packit 6c4009
define o-iterator-doit
Packit 6c4009
$(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
Packit 6c4009
	$$(do-install-program)
Packit 6c4009
endef
Packit 6c4009
object-suffixes-left := $(versioned)
Packit 6c4009
include $(o-iterator)
Packit 6c4009
endif
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
define do-install-so
Packit 6c4009
$(do-install-program)
Packit 6c4009
$(patsubst %,$(LN_S) -f $(@F) \
Packit 6c4009
			$(@D)/$(patsubst %$*.so,%,$(
Packit 6c4009
	   $(filter-out %.so,$@))
Packit 6c4009
endef
Packit 6c4009
Packit 6c4009
so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
Packit 6c4009
$(foreach v,$(so-versions),\
Packit 6c4009
	  $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
Packit 6c4009
					       $(+force)
Packit 6c4009
	$(do-install-so)
Packit 6c4009
$(foreach v,$(so-versions),\
Packit 6c4009
	  $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
Packit 6c4009
	$(do-install-so)
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
ifdef install-bin
Packit 6c4009
$(addprefix $(inst_bindir)/,$(install-bin)): \
Packit 6c4009
    $(inst_bindir)/%: $(objpfx)% $(+force)
Packit 6c4009
	$(do-install-program)
Packit 6c4009
endif
Packit 6c4009
ifdef install-bin-script
Packit 6c4009
$(addprefix $(inst_bindir)/,$(install-bin-script)): \
Packit 6c4009
    $(inst_bindir)/%: $(objpfx)% $(+force)
Packit 6c4009
	$(do-install-script)
Packit 6c4009
endif
Packit 6c4009
ifdef install-rootsbin
Packit 6c4009
$(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
Packit 6c4009
   $(inst_rootsbindir)/%: $(objpfx)% $(+force)
Packit 6c4009
	$(do-install-program)
Packit 6c4009
endif
Packit 6c4009
ifdef install-sbin
Packit 6c4009
$(addprefix $(inst_sbindir)/,$(install-sbin)): \
Packit 6c4009
    $(inst_sbindir)/%: $(objpfx)% $(+force)
Packit 6c4009
	$(do-install-program)
Packit 6c4009
endif
Packit 6c4009
ifdef install-lib
Packit 6c4009
install-lib.a := $(filter lib%.a,$(install-lib))
Packit 6c4009
install-lib.a := $(filter-out $(install-lib-ldscripts),$(install-lib.a))
Packit 6c4009
install-lib-non.a := $(filter-out lib%.a,$(install-lib))
Packit 6c4009
ifdef install-lib-non.a
Packit 6c4009
$(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
Packit 6c4009
  $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
Packit 6c4009
	$(do-install)
Packit 6c4009
endif
Packit 6c4009
ifdef install-lib.a
Packit 6c4009
$(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
Packit 6c4009
  $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
Packit 6c4009
	$(do-install)
Packit 6c4009
endif
Packit 6c4009
endif
Packit 6c4009
ifdef install-data
Packit 6c4009
$(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
Packit 6c4009
	$(do-install)
Packit 6c4009
endif
Packit 6c4009
headers := $(strip $(headers))
Packit 6c4009
ifdef headers
Packit 6c4009
# This implicit rule installs headers from the source directory.
Packit 6c4009
# It may be ignored in preference to rules from sysd-rules to find
Packit 6c4009
# headers in the sysdeps tree.
Packit 6c4009
$(inst_includedir)/%.h: $(objpfx)%.h $(+force)
Packit 6c4009
	$(do-install)
Packit 6c4009
$(inst_includedir)/%.h: $(common-objpfx)%.h $(+force)
Packit 6c4009
	$(do-install)
Packit 6c4009
$(inst_includedir)/%.h: %.h $(+force)
Packit 6c4009
	$(do-install)
Packit 6c4009
$(inst_includedir)/%.h: $(..)include/%.h $(+force)
Packit 6c4009
	$(do-install)
Packit 6c4009
headers-nonh := $(filter-out %.h,$(headers))
Packit 6c4009
ifdef headers-nonh
Packit 6c4009
$(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
Packit 6c4009
						 % $(+force)
Packit 6c4009
	$(do-install)
Packit 6c4009
endif	# headers-nonh
Packit 6c4009
endif	# headers
Packit 6c4009
Packit 6c4009
.PHONY: install-bin-nosubdir install-bin-script-nosubdir \
Packit 6c4009
	install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
Packit 6c4009
	install-data-nosubdir install-headers-nosubdir
Packit 6c4009
install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
Packit 6c4009
install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
Packit 6c4009
install-rootsbin-nosubdir: \
Packit 6c4009
	$(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
Packit 6c4009
install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
Packit 6c4009
install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
Packit 6c4009
		       $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
Packit 6c4009
		       $(addprefix $(libprefix),$(install-lib-non.a)))
Packit 6c4009
install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
Packit 6c4009
install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
Packit 6c4009
install-others-nosubdir: $(install-others)
Packit 6c4009
install-others-programs-nosubdir: $(install-others-programs)
Packit 6c4009
Packit 6c4009
# We need all the `-nosubdir' targets so that `install' in the parent
Packit 6c4009
# doesn't depend on several things which each iterate over the subdirs.
Packit 6c4009
# This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
Packit 6c4009
# subroutine.  Then in the parent `install-FOO' also causes subdir makes.
Packit 6c4009
install-%:: install-%-nosubdir ;
Packit 6c4009
Packit 6c4009
.PHONY: install install-no-libc.a-nosubdir
Packit 6c4009
install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
Packit 6c4009
			    install-lib-nosubdir install-others-nosubdir
Packit 6c4009
ifeq ($(build-programs),yes)
Packit 6c4009
install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
Packit 6c4009
			    install-rootsbin-nosubdir install-sbin-nosubdir \
Packit 6c4009
			    install-others-programs-nosubdir
Packit 6c4009
endif
Packit 6c4009
install: install-no-libc.a-nosubdir
Packit 6c4009

Packit 6c4009
# Command to compile $< using the native libraries.
Packit 6c4009
define native-compile
Packit 6c4009
$(make-target-directory)
Packit 6c4009
$(BUILD_CC) $($(basename $(
Packit 6c4009
	    $< $(OUTPUT_OPTION) $(BUILD_LDFLAGS)
Packit 6c4009
endef
Packit 6c4009
Packit 6c4009
# We always want to use configuration definitions.
Packit 6c4009
ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -D_GNU_SOURCE \
Packit 6c4009
		   -DIS_IN_build -include $(common-objpfx)config.h
Packit 6c4009
Packit 6c4009
# Support the GNU standard name for this target.
Packit 6c4009
.PHONY: check
Packit 6c4009
check: tests
Packit 6c4009
# Special target to run tests which cannot be run unconditionally.
Packit 6c4009
# Maintainers should use this target.
Packit 6c4009
.PHONY: xcheck
Packit 6c4009
xcheck: xtests
Packit 6c4009
Packit 6c4009
# The only difference between MODULE_NAME=testsuite and MODULE_NAME=nonlib is
Packit 6c4009
# that almost all internal declarations from config.h, libc-symbols.h, and
Packit 6c4009
# include/*.h are not available to 'testsuite' code, but are to 'nonlib' code.
Packit Service b68343
all-testsuite := $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) \
Packit Service b68343
		 $(tests-container))
Packit 6c4009
ifneq (,$(all-testsuite))
Packit 6c4009
cpp-srcs-left = $(all-testsuite)
Packit 6c4009
lib := testsuite
Packit 6c4009
include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
all-nonlib := $(strip $(tests-internal) $(test-internal-extras) \
Packit 6c4009
		      $(others) $(others-extras))
Packit 6c4009
ifneq (,$(all-nonlib))
Packit 6c4009
cpp-srcs-left = $(all-nonlib)
Packit 6c4009
lib := nonlib
Packit 6c4009
include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
ifeq ($(build-shared),yes)
Packit 6c4009
# Generate normalized lists of symbols, versions, and data sizes.
Packit 6c4009
# This is handy for checking against existing library binaries.
Packit 6c4009
Packit 6c4009
%.symlist: $(..)scripts/abilist.awk %.dynsym
Packit 6c4009
	LC_ALL=C $(AWK) -f $^ > $@T
Packit 6c4009
	mv -f $@T $@
Packit 6c4009
Packit 6c4009
%.dynsym: %.so
Packit 6c4009
	LC_ALL=C $(OBJDUMP) --dynamic-syms $< > $@T
Packit 6c4009
	mv -f $@T $@
Packit 6c4009
Packit 6c4009
# A sysdeps/.../Makefile can set abilist-pattern to something like
Packit 6c4009
# %-foo.abilist to look for libc-foo.abilist instead of libc.abilist.
Packit 6c4009
# This makes sense if multiple ABIs can be most cleanly supported by a
Packit 6c4009
# configuration without using separate sysdeps directories for each.
Packit 6c4009
ifdef abilist-pattern
Packit 6c4009
vpath $(abilist-pattern) $(+sysdep_dirs)
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
vpath %.abilist $(+sysdep_dirs)
Packit 6c4009
Packit 6c4009
# The .PRECIOUS rule prevents the files built by an implicit rule whose
Packit 6c4009
# target pattern is %.symlist from being considered "intermediate files"
Packit 6c4009
# and automatically removed.  We only want these files to be removed by
Packit 6c4009
# 'make clean', which is handled by the 'generated' variable.
Packit 6c4009
.PRECIOUS: %.symlist
Packit 6c4009
generated += $(extra-libs:=.symlist)
Packit 6c4009
Packit 6c4009
ifdef abilist-pattern
Packit 6c4009
$(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
Packit 6c4009
			  $(objpfx)%.symlist
Packit 6c4009
	$(check-abi-pattern); \
Packit 6c4009
	$(evaluate-test)
Packit 6c4009
$(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
Packit 6c4009
			  $(common-objpfx)%.symlist
Packit 6c4009
	$(check-abi-pattern); \
Packit 6c4009
	$(evaluate-test)
Packit 6c4009
endif
Packit 6c4009
$(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
Packit 6c4009
			  $(objpfx)%.symlist
Packit 6c4009
	$(check-abi); \
Packit 6c4009
	$(evaluate-test)
Packit 6c4009
$(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
Packit 6c4009
			  $(common-objpfx)%.symlist
Packit 6c4009
	$(check-abi); \
Packit 6c4009
	$(evaluate-test)
Packit 6c4009
define check-abi-pattern
Packit 6c4009
	diff -p -U 0 $(filter $(abilist-pattern),$^) $(filter %.symlist,$^) \
Packit 6c4009
	     > $@
Packit 6c4009
endef
Packit 6c4009
define check-abi
Packit 6c4009
	diff -p -U 0 $(filter %.abilist,$^) $(filter %.symlist,$^) > $@
Packit 6c4009
endef
Packit 6c4009
Packit 6c4009
ifdef abilist-pattern
Packit 6c4009
update-abi-%: $(objpfx)%.symlist $(abilist-pattern)
Packit 6c4009
	$(update-abi-pattern)
Packit 6c4009
update-abi-%: $(common-objpfx)%.symlist $(abilist-pattern)
Packit 6c4009
	$(update-abi-pattern)
Packit 6c4009
endif
Packit 6c4009
update-abi-%: $(objpfx)%.symlist %.abilist
Packit 6c4009
	$(update-abi)
Packit 6c4009
update-abi-%: $(common-objpfx)%.symlist %.abilist
Packit 6c4009
	$(update-abi)
Packit 6c4009
define update-abi-pattern
Packit 6c4009
@if cmp -s $^ 2> /dev/null; \
Packit 6c4009
 then \
Packit 6c4009
      echo '+++ $(filter $(abilist-pattern),$^) is unchanged'; \
Packit 6c4009
 else cp -f $^; \
Packit 6c4009
      echo '*** Now check $(filter $(abilist-pattern),$^) changes for correctness ***'; \
Packit 6c4009
 fi
Packit 6c4009
endef
Packit 6c4009
define update-abi
Packit 6c4009
@if cmp -s $^ 2> /dev/null; \
Packit 6c4009
 then \
Packit 6c4009
      echo '+++ $(filter %.abilist,$^) is unchanged'; \
Packit 6c4009
 else cp -f $^; \
Packit 6c4009
      echo '*** Now check $(filter %.abilist,$^) changes for correctness ***'; \
Packit 6c4009
 fi
Packit 6c4009
endef
Packit 6c4009
Packit 6c4009
# Patch all .abilist files for one DSO.  The find command locates
Packit 6c4009
# abilist files for all architectures.  The regular expression in the
Packit 6c4009
# find invocation is needed to separate libc.abilist and
Packit 6c4009
# libcrypt.abilist, for example.  It assumes that abilist-pattern, if
Packit 6c4009
# set, is of the form "%-SUFFIX", and not "%SUFFIX", that is, there is
Packit 6c4009
# a non-alphanumeric seperator between the pattern and the suffix
Packit 6c4009
# added.  The abilist files in /generic/ are filtered out because
Packit 6c4009
# these are expected to remain empty.
Packit 6c4009
define update-all-abi
Packit 6c4009
$(SHELL) $(..)scripts/update-abilist.sh $^ \
Packit 6c4009
  $$(find $(..)sysdeps \
Packit 6c4009
    -regextype posix-egrep -regex '.*/$*([^a-z0-9].*)?\.abilist$$' \
Packit 6c4009
    \! -regex '.*/generic/.*')
Packit 6c4009
endef
Packit 6c4009
ifdef abilist-pattern
Packit 6c4009
update-all-abi-%: $(abilist-pattern) $(objpfx)%.symlist
Packit 6c4009
	$(update-all-abi)
Packit 6c4009
update-all-abi-%: $(abilist-pattern) $(common-objpfx)%.symlist
Packit 6c4009
	$(update-all-abi)
Packit 6c4009
endif
Packit 6c4009
update-all-abi-%: %.abilist $(objpfx)%.symlist
Packit 6c4009
	$(update-all-abi)
Packit 6c4009
update-all-abi-%: %.abilist $(common-objpfx)%.symlist
Packit 6c4009
	$(update-all-abi)
Packit 6c4009
Packit 6c4009
.PHONY: update-abi update-all-abi check-abi
Packit 6c4009
update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
Packit 6c4009
update-all-abi: $(patsubst %.so,update-all-abi-%,$(install-lib.so-versioned))
Packit 6c4009
check-abi-list = $(patsubst %.so,$(objpfx)check-abi-%.out, \
Packit 6c4009
				 $(install-lib.so-versioned))
Packit 6c4009
check-abi: $(check-abi-list)
Packit 6c4009
ifdef subdir
Packit 6c4009
subdir_check-abi: check-abi
Packit 6c4009
subdir_update-abi: update-abi
Packit 6c4009
subdir_update-all-abi: update-all-abi
Packit 6c4009
else
Packit 6c4009
check-abi: subdir_check-abi
Packit 6c4009
	if grep -q '^FAIL:' $(objpfx)*/check-abi*.test-result; then \
Packit 6c4009
		cat $(objpfx)*/check-abi*.out && exit 1; fi
Packit 6c4009
update-abi: subdir_update-abi
Packit 6c4009
update-all-abi: subdir_update-all-abi
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
ifeq ($(subdir),elf)
Packit 6c4009
check-abi: $(objpfx)check-abi-libc.out
Packit 6c4009
tests-special += $(objpfx)check-abi-libc.out
Packit 6c4009
update-abi: update-abi-libc
Packit 6c4009
update-all-abi: update-all-abi-libc
Packit 6c4009
common-generated += libc.symlist
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
ifeq ($(build-shared),yes)
Packit 6c4009
ifdef subdir
Packit 6c4009
tests-special += $(check-abi-list)
Packit 6c4009
endif
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
endif
Packit 6c4009

Packit 6c4009
# These will have been set by sysdeps/posix/Makefile.
Packit 6c4009
L_tmpnam  ?= 1
Packit 6c4009
TMP_MAX   ?= 0
Packit 6c4009
L_ctermid ?= 1
Packit 6c4009
L_cuserid ?= 1
Packit 6c4009
Packit 6c4009
stdio_lim = $(common-objpfx)bits/stdio_lim.h
Packit 6c4009
Packit 6c4009
$(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
Packit 6c4009
$(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
Packit 6c4009
		   $(common-objpfx)config.make
Packit 6c4009
	$(make-target-directory)
Packit 6c4009
	{ echo '#include "$(..)posix/bits/posix1_lim.h"';		\
Packit 6c4009
	} |								\
Packit 6c4009
	$(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)' 	\
Packit 6c4009
	      $(CPPUNDEFS) $(+includes) -xc - -o $(@:st=hT)
Packit 6c4009
	sed $(sed-remove-objpfx) $(sed-remove-dotdot)			\
Packit 6c4009
	    $(@:st=dT) > $(@:st=dt)
Packit 6c4009
	mv -f $(@:st=dt) $(@:st=d)
Packit 6c4009
	fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`; 	\
Packit 6c4009
	filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`;	\
Packit 6c4009
	fopen_max=$${fopen_max:-16};					\
Packit 6c4009
	filename_max=$${filename_max:-1024};				\
Packit 6c4009
	sed -e "s/@FOPEN_MAX@/$$fopen_max/"				\
Packit 6c4009
	    -e "s/@FILENAME_MAX@/$$filename_max/"			\
Packit 6c4009
	    -e "s/@L_tmpnam@/$(L_tmpnam)/"				\
Packit 6c4009
	    -e "s/@TMP_MAX@/$(TMP_MAX)/"				\
Packit 6c4009
	    -e "s/@L_ctermid@/$(L_ctermid)/"				\
Packit 6c4009
	    -e "s/@L_cuserid@/$(L_cuserid)/"				\
Packit 6c4009
	    $< > $(@:st=h.new)
Packit 6c4009
	$(move-if-change) $(@:st=h.new) $(@:st=h)
Packit 6c4009
# Remove these last so that they can be examined if something went wrong.
Packit 6c4009
	rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
Packit 6c4009
	touch $@
Packit 6c4009
# Get dependencies.
Packit 6c4009
ifndef no_deps
Packit 6c4009
-include $(stdio_lim:h=d)
Packit 6c4009
endif
Packit 6c4009
common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
Packit 6c4009

Packit 6c4009
FORCE:
Packit 6c4009
Packit 6c4009
.PHONY: echo-headers
Packit 6c4009
echo-headers:
Packit 6c4009
	@echo $(headers)
Packit 6c4009
Packit 6c4009
%.bz2: %; bzip2 -9vk $<
Packit 6c4009
%.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
Packit 6c4009
%.xz: %; xz -9evk $<
Packit 6c4009

Packit 6c4009
# Common cleaning targets.
Packit 6c4009
Packit 6c4009
.PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
Packit 6c4009
clean: common-clean
Packit 6c4009
mostlyclean: common-mostlyclean
Packit 6c4009
Packit 6c4009
do-tests-clean:
Packit 6c4009
	-rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) \
Packit 6c4009
						      $(tests-internal) \
Packit 6c4009
						      $(xtests) \
Packit 6c4009
						      $(test-srcs)) \
Packit 6c4009
				     $(addsuffix .test-result,$(tests) \
Packit 6c4009
							      $(tests-internal) \
Packit 6c4009
							      $(xtests) \
Packit 6c4009
							      $(test-srcs)))
Packit 6c4009
Packit 6c4009
# Remove the object files.
Packit 6c4009
common-mostlyclean:
Packit 6c4009
	-rm -f $(addprefix $(objpfx),$(tests) $(tests-internal) $(xtests) \
Packit 6c4009
				     $(test-srcs) \
Packit 6c4009
				     $(others) $(sysdep-others) stubs \
Packit 6c4009
				     $(addsuffix .o,$(tests) \
Packit 6c4009
						    $(tests-internal) \
Packit 6c4009
						    $(xtests) \
Packit 6c4009
						    $(test-srcs) \
Packit 6c4009
						    $(others) \
Packit 6c4009
						    $(sysdep-others)) \
Packit 6c4009
				     $(addsuffix .out,$(tests) \
Packit 6c4009
						      $(tests-internal) \
Packit 6c4009
						      $(xtests) \
Packit 6c4009
						      $(test-srcs)) \
Packit 6c4009
				     $(addsuffix .test-result,$(tests) \
Packit 6c4009
							      $(tests-internal) \
Packit 6c4009
							      $(xtests) \
Packit 6c4009
							      $(test-srcs)))
Packit 6c4009
	-rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
Packit 6c4009
				     $(install-lib) $(install-lib.so) \
Packit 6c4009
				     $(install-lib.so:%.so=%_pic.a))
Packit 6c4009
	-rm -f core
Packit 6c4009
	-rm -f $(objpfx)rtld-*.os
Packit 6c4009
	$(rmobjs)
Packit 6c4009
define rmobjs
Packit 6c4009
$(foreach o,$(object-suffixes-for-libc),
Packit 6c4009
-rm -f $(objpfx)stamp$o $(o-objects))
Packit 6c4009
endef
Packit 6c4009
Packit 6c4009
# Also remove the dependencies and generated source files.
Packit 6c4009
common-clean: common-mostlyclean
Packit 6c4009
	-rm -f $(addprefix $(objpfx),$(generated))
Packit 6c4009
	-rm -f $(objpfx)*.d $(objpfx)*.dt
Packit 6c4009
	-rm -fr $(addprefix $(objpfx),$(generated-dirs))
Packit 6c4009
	-rm -f $(addprefix $(common-objpfx),$(common-generated))
Packit 6c4009
	-rm -f $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
Packit 6c4009

Packit 6c4009
# Produce a file `stubs' which contains `#define __stub_FUNCTION'
Packit 6c4009
# for each function which is a stub.
Packit 6c4009
Packit 6c4009
ifdef objpfx
Packit 6c4009
.PHONY: stubs # The parent Makefile calls this target.
Packit 6c4009
stubs: $(objpfx)stubs
Packit 6c4009
endif
Packit 6c4009
objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
Packit 6c4009
		  $(addprefix $(objpfx),$(extra-objs))
Packit 6c4009
$(objpfx)stubs: $(objs-for-stubs)
Packit 6c4009
ifneq (,$(strip $(objs-for-stubs)))
Packit 6c4009
	(cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
Packit 6c4009
	$(AWK) '/\.gnu\.glibc-stub\./ { \
Packit 6c4009
		  sub(/\.gnu\.glibc-stub\./, "", $$2); \
Packit 6c4009
		  stubs[$$2] = 1; } \
Packit 6c4009
		END { for (s in stubs) print "#define __stub_" s }' > $@T
Packit 6c4009
	mv -f $@T $@
Packit 6c4009
else
Packit 6c4009
	> $@
Packit 6c4009
endif
Packit 6c4009

Packit 6c4009
ifneq (,$(strip $(gpl2lgpl)))
Packit 6c4009
ifneq (,$(wildcard $(..)gpl2lgpl.sed))
Packit 6c4009
# Snarf from the master source and frob the copying notice.
Packit 6c4009
$(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
Packit 6c4009
	sed -f $^ > $@-tmp
Packit 6c4009
# So I don't edit them by mistake.
Packit 6c4009
	chmod a-w $@-tmp
Packit 6c4009
	mv -f $@-tmp $@
Packit 6c4009
endif
Packit 6c4009
endif
Packit 6c4009
Packit 6c4009
# Local Variables:
Packit 6c4009
# mode: makefile
Packit 6c4009
# End: