1# Copyright (C) 1991-2022 Free Software Foundation, Inc.
2# Copyright The GNU Toolchain Authors.
3# This file is part of the GNU C Library.
4
5# The GNU C Library is free software; you can redistribute it and/or
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
9
10# The GNU C Library is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13# Lesser General Public License for more details.
14
15# You should have received a copy of the GNU Lesser General Public
16# License along with the GNU C Library; if not, see
17# <https://www.gnu.org/licenses/>.
18
19#
20#	Makefile configuration options for the GNU C library.
21#
22ifneq (,)
23This makefile requires GNU Make.
24endif
25
26all: # Make this the default goal
27
28ifneq "$(origin +included-Makeconfig)" "file"
29
30+included-Makeconfig := yes
31
32ifdef subdir
33.. := ../
34endif
35
36# $(common-objdir) is the place to put objects and
37# such that are not specific to a single subdir.
38ifdef objdir
39objpfx := $(patsubst %//,%/,$(objdir)/$(subdir)/)
40common-objpfx = $(objdir)/
41common-objdir = $(objdir)
42else
43$(error objdir must be defined by the build-directory Makefile)
44endif
45
46# Root of the sysdeps tree.
47sysdep_dir := $(..)sysdeps
48export sysdep_dir := $(sysdep_dir)
49
50# Get the values defined by options to `configure'.
51include $(common-objpfx)config.make
52
53# What flags to give to sources which call user provided callbacks
54uses-callbacks = -fexceptions
55
56# What flags to give to tests which test stack alignment
57stack-align-test-flags =
58
59# Complete path to sysdep dirs.
60# `configure' writes a definition of `config-sysdirs' in `config.make'.
61sysdirs := $(foreach D,$(config-sysdirs),$(firstword $(filter /%,$D) $(..)$D))
62
63+sysdep_dirs = $(sysdirs)
64ifdef objdir
65+sysdep_dirs := $(objdir) $(+sysdep_dirs)
66endif
67
68# Run config.status to update config.make and config.h.  We don't show the
69# dependence of config.h to Make, because it is only touched when it
70# changes and so config.status would be run every time; the dependence of
71# config.make should suffice to force regeneration and re-exec, and the new
72# image will notice if config.h changed.
73$(common-objpfx)config.make: $(common-objpfx)config.status \
74			     $(..)config.make.in $(..)config.h.in
75	cd $(<D); $(SHELL) $(<F)
76
77# Find all the sysdeps configure fragments, to make sure we re-run
78# configure when any of them changes.
79$(common-objpfx)config.status: $(..)version.h $(..)configure \
80			       $(foreach dir,$(sysdirs),\
81					 $(wildcard $(dir)/Implies) \
82					 $(patsubst %.ac,%,\
83						    $(firstword $(wildcard \
84 $(addprefix $(dir)/,configure configure.ac))))) \
85			       $(patsubst %.ac,%,\
86 $(wildcard $(..)sysdeps/*/preconfigure $(..)sysdeps/*/preconfigure.ac))
87	@cd $(@D); if test -f $(@F); then exec $(SHELL) $(@F) --recheck; else \
88	 echo The GNU C library has not been configured. >&2; \
89	 echo Run \`configure\' to configure it before building. >&2; \
90	 echo Try \`configure --help\' for more details. >&2; \
91	 exit 1; fi
92
93# We don't want CPPFLAGS to be exported to the command running configure.
94unexport CPPFLAGS
95
96# Get the user's configuration parameters.
97ifneq ($(wildcard $(..)configparms),)
98include $(..)configparms
99endif
100ifneq ($(objpfx),)
101ifneq ($(wildcard $(common-objpfx)configparms),)
102include $(common-objpfx)configparms
103endif
104endif
105
106####
107####	These are the configuration variables.  You can define values for
108####	the variables below in the file `configparms'.
109####	Do NOT edit this file.
110####
111
112
113# Common prefix for machine-independent installation directories.
114ifeq ($(origin prefix),undefined) # ifndef would override explicit empty value.
115prefix = /usr/local
116endif
117
118# Decide whether we shall build the programs or not.  We always do this
119# unless the user tells us (in configparms) or we are building for a
120# standalone target.
121ifndef build-programs
122ifneq ($(config-os),none)
123build-programs=yes
124else
125build-programs=no
126endif
127endif
128
129# Common prefix for machine-dependent installation directories.
130ifeq ($(origin exec_prefix),undefined)
131exec_prefix = $(prefix)
132endif
133
134# Where to install the library and object files.
135ifndef libdir
136libdir = $(exec_prefix)/lib
137endif
138inst_libdir = $(install_root)$(libdir)
139
140# Where to install the shared library.
141ifndef slibdir
142slibdir = $(exec_prefix)/lib
143endif
144inst_slibdir = $(install_root)$(slibdir)
145
146# Where to install the dynamic linker.
147ifndef rtlddir
148rtlddir = $(slibdir)
149endif
150inst_rtlddir = $(install_root)$(rtlddir)
151
152# Prefix to put on files installed in $(libdir).  For libraries `libNAME.a',
153# the prefix is spliced between `lib' and the name, so the linker switch
154# `-l$(libprefix)NAME' finds the library; for other files the prefix is
155# just prepended to the whole file name.
156ifeq ($(origin libprefix),undefined)
157libprefix =
158endif
159
160# Where to install the header files.
161ifndef includedir
162includedir = $(prefix)/include
163endif
164inst_includedir = $(install_root)$(includedir)
165
166# Where to install machine-independent data files.
167# These are the timezone database, and the locale database.
168ifndef datadir
169datadir = $(prefix)/share
170endif
171inst_datadir = $(install_root)$(datadir)
172
173# Where to install the timezone data files (which are machine-independent).
174ifndef zonedir
175zonedir = $(datadir)/zoneinfo
176endif
177inst_zonedir = $(install_root)$(zonedir)
178
179# Where to install the compiled binary locale archive and compiled
180# binary locale files.
181ifndef complocaledir
182complocaledir = $(libdir)/locale
183endif
184inst_complocaledir = $(install_root)$(complocaledir)
185
186# Where to install the message catalog data files (which are
187# machine-independent).
188ifndef localedir
189localedir = $(datadir)/locale
190endif
191inst_localedir = $(install_root)$(localedir)
192
193# Where to install the locale charmap source files.
194ifndef i18ndir
195i18ndir = $(datadir)/i18n
196endif
197inst_i18ndir = $(install_root)$(i18ndir)
198
199# Where to install the shared object for charset transformation.
200ifndef gconvdir
201gconvdir = $(libdir)/gconv
202endif
203inst_gconvdir = $(install_root)$(gconvdir)
204
205# Where to install programs.
206ifndef bindir
207bindir = $(exec_prefix)/bin
208endif
209inst_bindir = $(install_root)$(bindir)
210
211# Where to install internal programs.
212ifndef libexecdir
213libexecdir = $(exec_prefix)/libexec
214endif
215inst_libexecdir = $(install_root)$(libexecdir)
216
217# Where to install administrative programs.
218ifndef rootsbindir
219rootsbindir = $(exec_prefix)/sbin
220endif
221inst_rootsbindir = $(install_root)$(rootsbindir)
222
223ifndef sbindir
224sbindir = $(exec_prefix)/sbin
225endif
226inst_sbindir = $(install_root)$(sbindir)
227
228# Where to install the Info files.
229ifndef infodir
230infodir = $(prefix)/info
231endif
232inst_infodir = $(install_root)$(infodir)
233
234# Where to install audit libraries.
235ifndef auditdir
236auditdir = $(libdir)/audit
237endif
238inst_auditdir = $(install_root)$(auditdir)
239
240# Where to install default configuration files.  These include the local
241# timezone specification and network data base files.
242ifndef sysconfdir
243sysconfdir = $(prefix)/etc
244endif
245inst_sysconfdir = $(install_root)$(sysconfdir)
246
247# Directory for the database files and Makefile for nss_db.
248ifndef vardbdir
249vardbdir = $(localstatedir)/db
250endif
251inst_vardbdir = $(install_root)$(vardbdir)
252
253# Where to install the "localtime" timezone file; this is the file whose
254# contents $(localtime) specifies.  If this is a relative pathname, it is
255# relative to $(zonedir).  It is a good idea to put this somewhere
256# other than there, so the zoneinfo directory contains only universal data,
257# localizing the configuration data elsewhere.
258ifndef localtime-file
259localtime-file = $(sysconfdir)/localtime
260endif
261
262# What to use for leap second specifications in compiling the default
263# timezone files.  Set this to `/dev/null' for no leap second handling as
264# 1003.1 requires, or to `leapseconds' for proper leap second handling.
265# Both zone flavors are always available as `posix/ZONE' and `right/ZONE'.
266# This variable determines the default: if it's `/dev/null',
267# ZONE==posix/ZONE; if it's `leapseconds', ZONE==right/ZONE.
268ifndef leapseconds
269leapseconds = /dev/null
270endif
271
272# What timezone's DST rules should be used when a POSIX-style TZ
273# environment variable doesn't specify any rules.  For 1003.1 compliance
274# this timezone must use rules that are as U.S. federal law defines DST.
275# Run `make -C time echo-zonenames' to see a list of available zone names.
276# This setting can be changed with `zic -p TIMEZONE' at any time.
277# If you want POSIX.1 compatibility, use `America/New_York'.
278ifndef posixrules
279posixrules = America/New_York
280endif
281
282# Where to install the "posixrules" timezone file; this is file
283# whose contents $(posixrules) specifies.  If this is a relative
284# pathname, it is relative to $(zonedir).
285ifndef posixrules-file
286posixrules-file = posixrules
287endif
288
289
290# Directory where your system's native header files live.
291# This is used on Unix systems to generate some GNU libc header files.
292ifndef sysincludedir
293sysincludedir = /usr/include
294endif
295
296
297# Commands to install files.
298ifndef INSTALL_DATA
299INSTALL_DATA = $(INSTALL) -m 644
300endif
301ifndef INSTALL_SCRIPT
302INSTALL_SCRIPT = $(INSTALL)
303endif
304ifndef INSTALL_PROGRAM
305INSTALL_PROGRAM = $(INSTALL)
306endif
307ifndef INSTALL
308INSTALL = install
309endif
310
311
312# The name of the C compiler.
313# If you've got GCC, and it works, use it.
314ifeq ($(origin CC),default)
315CC := gcc
316endif
317
318# The name of the C compiler to use for compilations of programs to run on
319# the host that is building the library.  If you set CC to a
320# cross-compiler, you must set this to the normal compiler.
321ifndef BUILD_CC
322BUILD_CC = $(CC)
323endif
324
325# Default flags to pass the C compiler.
326ifndef default_cflags
327ifeq ($(release),stable)
328default_cflags := -g -O2
329else
330default_cflags := -g -O
331endif
332endif
333
334# Flags to pass the C compiler when assembling preprocessed assembly code
335# (`.S' files).
336ifndef asm-CPPFLAGS
337asm-CPPFLAGS =
338endif
339
340# Must be supported by the linker.
341no-whole-archive = -Wl,--no-whole-archive
342whole-archive = -Wl,--whole-archive
343
344# Installed name of the startup code.
345# The ELF convention is that the startfile is called crt1.o
346start-installed-name = crt1.o
347# On systems that do not need a special startfile for statically linked
348# binaries, simply set it to the normal name.
349ifndef static-start-installed-name
350static-start-installed-name = $(start-installed-name)
351endif
352
353ifeq (yes,$(enable-static-pie))
354# Link with rcrt1.o, instead of crt1.o, to call _dl_relocate_static_pie
355# to relocate static PIE.
356real-static-start-installed-name = r$(static-start-installed-name)
357else
358real-static-start-installed-name = $(static-start-installed-name)
359endif
360
361relro-LDFLAGS = -Wl,-z,relro
362LDFLAGS.so += $(relro-LDFLAGS)
363LDFLAGS-rtld += $(relro-LDFLAGS)
364
365# Linker options to enable and disable DT_RELR.
366ifeq ($(have-dt-relr),yes)
367dt-relr-ldflag = -Wl,-z,pack-relative-relocs
368no-dt-relr-ldflag = -Wl,-z,nopack-relative-relocs
369else
370dt-relr-ldflag =
371no-dt-relr-ldflag =
372endif
373
374ifeq (no,$(build-pie-default))
375pie-default = $(no-pie-ccflag)
376else # build-pie-default
377pic-default = -DPIC
378# Compile libc.a and libc_p.a with -fPIE/-fpie for static PIE.
379pie-default = $(pie-ccflag)
380
381ifeq (yes,$(enable-static-pie))
382static-pie-dt-relr-ldflag = $(dt-relr-ldflag)
383ifeq (yes,$(have-static-pie))
384static-pie-ldflag = -static-pie
385else
386# Static PIE can't have dynamic relocations in read-only segments since
387# static PIE is mapped into memory by kernel.  --eh-frame-hdr is needed
388# for PIE to support exception.
389static-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
390endif # have-static-pie
391endif # enable-static-pie
392endif # build-pie-default
393
394# If lazy relocations are disabled, add the -z now flag.  Use
395# LDFLAGS-lib.so instead of LDFLAGS.so, to avoid adding the flag to
396# test modules.
397ifeq ($(bind-now),yes)
398LDFLAGS-lib.so += -Wl,-z,now
399# Extra flags for dynamically linked non-test main programs.
400link-extra-flags += -Wl,-z,now
401endif
402
403# Command to run after every final link (executable or shared object).
404# This is invoked with $(call after-link,...), so it should operate on
405# the file $1.  This can be set to do some sort of post-processing on
406# binaries, or to perform some sort of static sanity check.
407ifndef after-link
408after-link =
409endif
410
411# Additional libraries to link into every test.
412link-extra-libs-tests = $(libsupport)
413
414# Command for linking PIE programs with the C library.
415ifndef +link-pie
416+link-pie-before-inputs = $(if $($(@F)-no-pie),$(no-pie-ldflag),-pie) \
417	     $(if $($(@F)-no-dt-relr),$(no-dt-relr-ldflag),$(dt-relr-ldflag)) \
418	     -Wl,-O1 -nostdlib -nostartfiles \
419	     $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
420	     $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
421	     $(firstword $(CRT-$(@F)) $(csu-objpfx)S$(start-installed-name)) \
422	     $(+preinit) $(+prectorS)
423+link-pie-before-libc = -o $@ $(+link-pie-before-inputs) \
424	     $(filter-out $(addprefix $(csu-objpfx),start.o \
425						    S$(start-installed-name))\
426			  $(+preinit) $(link-extra-libs) \
427			  $(common-objpfx)libc% $(+postinit),$^) \
428	     $(link-extra-libs)
429+link-pie-after-libc = $(+postctorS) $(+postinit)
430define +link-pie
431$(CC) $(link-libc-rpath-link) $(+link-pie-before-libc) $(rtld-LDFLAGS) \
432  $(link-extra-flags) $(link-libc) $(+link-pie-after-libc)
433$(call after-link,$@)
434endef
435define +link-pie-tests
436$(CC) $(+link-pie-before-libc) $(rtld-tests-LDFLAGS) $(link-libc-tests) \
437  $(+link-pie-after-libc)
438$(call after-link,$@)
439endef
440define +link-pie-printers-tests
441$(CC) $(+link-pie-before-libc) $(built-rtld-LDFLAGS) \
442  $(link-libc-printers-tests) $(+link-pie-after-libc)
443$(call after-link,$@)
444endef
445endif
446# Command for statically linking programs with the C library.
447ifndef +link-static
448+link-static-before-inputs = -nostdlib -nostartfiles -static \
449	      $(if $($(@F)-no-pie),$(no-pie-ldflag),$(static-pie-ldflag)) \
450	      $(if $($(@F)-no-dt-relr),$(no-dt-relr-ldflag),$(static-pie-dt-relr-ldflag)) \
451	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F))  \
452	      $(firstword $(CRT-$(@F)) $(csu-objpfx)$(real-static-start-installed-name)) \
453	      $(+preinit) $(+prectorT)
454+link-static-before-libc = -o $@ $(+link-static-before-inputs) \
455	      $(filter-out $(addprefix $(csu-objpfx),start.o \
456						     $(start-installed-name))\
457			   $(+preinit) $(link-extra-libs-static) \
458			   $(common-objpfx)libc% $(+postinit),$^) \
459	      $(link-extra-libs-static)
460+link-static-after-libc = $(+postctorT) $(+postinit)
461define +link-static
462$(CC) $(+link-static-before-libc) $(link-extra-flags) $(link-libc-static) \
463  $(+link-static-after-libc)
464$(call after-link,$@)
465endef
466define +link-static-tests
467$(CC) $(+link-static-before-libc) $(link-libc-static-tests) \
468  $(+link-static-after-libc)
469$(call after-link,$@)
470endef
471endif
472# Commands for linking programs with the C library.
473ifndef +link
474ifeq (yes,$(build-shared))
475ifeq (yes,$(cc-pie-default))
476no-pie-ldflag = -no-pie
477endif
478ifeq (yes,$(build-pie-default))
479+link = $(+link-pie)
480+link-tests = $(+link-pie-tests)
481+link-tests-before-inputs = $(+link-pie-before-inputs) $(rtld-tests-LDFLAGS)
482+link-tests-after-inputs = $(link-libc-tests) $(+link-pie-after-libc)
483+link-printers-tests = $(+link-pie-printers-tests)
484else  # not build-pie-default
485+link-before-inputs = -nostdlib -nostartfiles $(no-pie-ldflag) \
486	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
487	      $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
488	      $(firstword $(CRT-$(@F)) $(csu-objpfx)$(start-installed-name)) \
489	      $(+preinit) $(+prector)
490+link-before-libc = -o $@ $(+link-before-inputs) \
491	      $(filter-out $(addprefix $(csu-objpfx),start.o \
492						     $(start-installed-name))\
493			   $(+preinit) $(link-extra-libs) \
494			   $(common-objpfx)libc% $(+postinit),$^) \
495	      $(link-extra-libs)
496+link-after-libc = $(+postctor) $(+postinit)
497define +link
498$(CC) $(link-libc-rpath-link) $(+link-before-libc) $(rtld-LDFLAGS) \
499  $(link-extra-flags) $(link-libc) $(+link-after-libc)
500$(call after-link,$@)
501endef
502+link-tests-before-inputs = $(+link-before-inputs) $(rtld-tests-LDFLAGS)
503+link-tests-after-inputs = $(link-libc-tests) $(+link-after-libc)
504define +link-tests
505$(CC) $(+link-before-libc) $(rtld-tests-LDFLAGS) $(link-libc-tests) \
506		     $(+link-after-libc)
507$(call after-link,$@)
508endef
509define +link-printers-tests
510$(CC) $(+link-before-libc) $(built-rtld-LDFLAGS) $(link-libc-printers-tests) \
511		     $(+link-after-libc)
512$(call after-link,$@)
513endef
514endif  # build-pie-default
515else  # build-static
516+link = $(+link-static)
517+link-tests = $(+link-static-tests)
518+link-tests-before-inputs = $(+link-static-before-inputs)
519+link-tests-after-inputs = $(link-libc-static-tests) $(+link-static-after-libc)
520+link-printers-tests = $(+link-static-tests)
521endif  # build-shared
522endif  # +link
523
524# The pretty printer test programs need to be compiled without optimizations
525# so they won't confuse gdb.  We could use either the 'GCC optimize' pragma
526# or the 'optimize' function attribute to achieve this; however, at least on
527# ARM, gcc always produces different debugging symbols when invoked with
528# a -O greater than 0 than when invoked with -O0, regardless of anything else
529# we're using to suppress optimizations.  Therefore, we need to explicitly pass
530# -O0 to it through CFLAGS.
531# Additionally, the build system will try to -include $(common-objpfx)/config.h
532# when compiling the tests, which will throw an error if some special macros
533# (such as __OPTIMIZE__ and IS_IN_build) aren't defined.  To avoid this, we
534# tell gcc to define IS_IN_build.
535CFLAGS-printers-tests := -O0 -ggdb3 -DIS_IN_build
536
537ifeq (yes,$(build-shared))
538# These indicate whether to link using the built ld.so or the installed one.
539installed-rtld-LDFLAGS = -Wl,-dynamic-linker=$(rtlddir)/$(rtld-installed-name)
540built-rtld-LDFLAGS = -Wl,-dynamic-linker=$(elf-objpfx)ld.so
541
542ifndef rtld-LDFLAGS
543rtld-LDFLAGS = $(installed-rtld-LDFLAGS)
544endif
545
546ifndef rtld-tests-LDFLAGS
547ifeq (yes,$(build-hardcoded-path-in-tests))
548rtld-tests-LDFLAGS = $(built-rtld-LDFLAGS)
549else
550rtld-tests-LDFLAGS = $(installed-rtld-LDFLAGS)
551endif  # build-hardcoded-path-in-tests
552endif  # rtld-tests-LDFLAGS
553
554endif  # build-shared
555
556ifndef link-libc
557ifeq (yes,$(build-shared))
558# We need the versioned name of libc.so in the deps of $(others) et al
559# so that the symlink to libc.so is created before anything tries to
560# run the linked programs.
561link-libc-rpath = -Wl,-rpath=$(rpath-link)
562link-libc-rpath-link = -Wl,-rpath-link=$(rpath-link)
563
564# For programs which are not tests, $(link-libc-rpath-link) is added
565# directly in $(+link), $(+link-pie) above, so that -Wl,-rpath-link
566# comes before the expansion of LDLIBS-* and affects libraries added
567# there.  For shared objects, -Wl,-rpath-link is added via
568# $(build-shlib-helper) and $(build-module-helper) in Makerules (also
569# before the expansion of LDLIBS-* variables).
570
571# Tests use -Wl,-rpath instead of -Wl,-rpath-link for
572# build-hardcoded-path-in-tests.
573ifeq (yes,$(build-hardcoded-path-in-tests))
574link-libc-tests-rpath-link = $(link-libc-rpath)
575link-test-modules-rpath-link = $(link-libc-rpath)
576else
577link-libc-tests-rpath-link = $(link-libc-rpath-link)
578link-test-modules-rpath-link =
579endif  # build-hardcoded-path-in-tests
580
581link-libc-between-gnulib = $(common-objpfx)libc.so$(libc.so-version) \
582			   $(common-objpfx)$(patsubst %,$(libtype.oS),c) \
583			   -Wl,--as-needed $(elf-objpfx)ld.so \
584			   -Wl,--no-as-needed
585link-libc = $(link-libc-between-gnulib) $(gnulib)
586
587link-libc-tests-after-rpath-link = $(gnulib-tests) $(link-libc-between-gnulib) $(gnulib-tests)
588link-libc-tests = $(link-libc-tests-rpath-link) \
589		  $(link-libc-tests-after-rpath-link)
590# Pretty printer test programs always require rpath instead of rpath-link.
591link-libc-printers-tests = $(link-libc-rpath) \
592			   $(link-libc-tests-after-rpath-link)
593
594# This is how to find at build-time things that will be installed there.
595rpath-dirs = math elf dlfcn nss nis rt resolv mathvec support
596rpath-link = \
597$(common-objdir):$(subst $(empty) ,:,$(patsubst ../$(subdir),.,$(rpath-dirs:%=$(common-objpfx)%)))
598else  # build-static
599link-libc = $(common-objpfx)libc.a $(otherlibs) $(gnulib) $(common-objpfx)libc.a $(gnulib)
600link-libc-tests = $(common-objpfx)libc.a $(otherlibs) $(gnulib-tests) $(common-objpfx)libc.a $(gnulib-tests)
601endif  # build-shared
602endif  # link-libc
603
604# Differences in the linkers on the various platforms.
605LDFLAGS-rpath-ORIGIN = -Wl,-rpath,'$$ORIGIN'
606LDFLAGS-soname-fname = -Wl,-soname,$(@F)
607LDFLAGS-rdynamic = -rdynamic
608LDFLAGS-Bsymbolic = -Bsymbolic
609
610# Choose the default search path for the dynamic linker based on
611# where we will install libraries.
612ifneq ($(libdir),$(slibdir))
613default-rpath = $(slibdir):$(libdir)
614else
615default-rpath = $(libdir)
616endif
617
618ifndef link-extra-libs
619link-extra-libs = $(LDLIBS-$(@F))
620link-extra-libs-static = $(link-extra-libs)
621endif
622
623# The static libraries.
624link-libc-static = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib) -Wl,--end-group
625link-libc-static-tests = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib-tests) -Wl,--end-group
626
627# How to link against libgcc.  Some libgcc functions, such as those
628# for "long long" arithmetic or software floating point, can always be
629# built without use of C library headers and do not have any global
630# state so can safely be linked statically into any executable or
631# shared library requiring them; these functions are in libgcc.a.
632# Other functions, relating to exception handling, may require C
633# library headers to build and it may not be safe to have more than
634# one copy of them in a process; these functions are only in
635# libgcc_s.so and libgcc_eh.a.
636#
637# To avoid circular dependencies when bootstrapping, it is desirable
638# to avoid use of libgcc_s and libgcc_eh in building glibc.  Where any
639# glibc functionality (in particular, thread cancellation) requires
640# exception handling, this is implemented through dlopen of libgcc_s
641# to avoid unnecessary dependencies on libgcc_s by programs not using
642# that functionality; executables built with glibc do not use
643# exception handling other than through thread cancellation.
644#
645# Undefined references to functions from libgcc_eh or libgcc_s may
646# arise for code built with -fexceptions.  In the case of statically
647# linked programs installed by glibc, unwinding will never actually
648# occur at runtime and the use of elf/static-stubs.c to resolve these
649# references is safe.  In the case of statically linked test programs
650# and test programs built with -fexceptions, unwinding may occur in
651# some cases and it is preferable to link with libgcc_eh or libgcc_s
652# so that the testing is as similar as possible to how programs will
653# be built with the installed glibc.
654#
655# Some architectures have architecture-specific systems for exception
656# handling that may involve undefined references to
657# architecture-specific functions.  On those architectures,
658# gnulib-arch and static-gnulib-arch may be defined in sysdeps
659# makefiles to use additional libraries for linking executables and
660# shared libraries built by glibc.
661ifndef gnulib
662ifneq ($(have-cc-with-libunwind),yes)
663  libunwind =
664else
665  libunwind = -lunwind
666endif
667libgcc_eh := -Wl,--as-needed -lgcc_s $(libunwind) -Wl,--no-as-needed
668gnulib-arch =
669gnulib = -lgcc $(gnulib-arch)
670gnulib-tests := -lgcc $(libgcc_eh)
671static-gnulib-arch =
672# By default, elf/static-stubs.o, instead of -lgcc_eh, is used to
673# statically link programs.  When --disable-shared is used, we use
674# -lgcc_eh since elf/static-stubs.o isn't sufficient.
675ifeq (yes,$(build-shared))
676static-gnulib = -lgcc $(static-gnulib-arch)
677else
678static-gnulib = -lgcc -lgcc_eh $(static-gnulib-arch)
679endif
680static-gnulib-tests := -lgcc -lgcc_eh $(libunwind)
681libc.so-gnulib := -lgcc
682endif
683+preinit = $(addprefix $(csu-objpfx),crti.o)
684+postinit = $(addprefix $(csu-objpfx),crtn.o)
685+prector = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbegin.o`
686+postctor = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
687# Variants of the two previous definitions for linking PIE programs.
688+prectorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginS.o`
689+postctorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtendS.o`
690# Variants of the two previous definitions for statically linking programs.
691ifeq (yes,$(enable-static-pie))
692# Static PIE must use PIE variants.
693+prectorT = $(+prectorS)
694+postctorT = $(+postctorS)
695else
696+prectorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginT.o`
697+postctorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
698endif
699csu-objpfx = $(common-objpfx)csu/
700elf-objpfx = $(common-objpfx)elf/
701
702# A command that, prepended to the name and arguments of a program,
703# and run on the build system, causes that program with those
704# arguments to be run on the host for which the library is built.
705ifndef test-wrapper
706test-wrapper =
707endif
708# Likewise, but the name of the program is preceded by
709# <variable>=<value> assignments for environment variables.
710ifndef test-wrapper-env
711test-wrapper-env = $(test-wrapper) env
712endif
713# Likewise, but the program's environment will be empty except for any
714# explicit <variable>=<value> assignments preceding the program name.
715ifndef test-wrapper-env-only
716test-wrapper-env-only = $(test-wrapper) env -i
717endif
718
719# Whether to run test programs built for the library's host system.
720ifndef run-built-tests
721ifeq (yes|,$(cross-compiling)|$(test-wrapper))
722run-built-tests = no
723else
724run-built-tests = yes
725endif
726endif
727
728# Whether to stop immediately when a test fails.  Nonempty means to
729# stop, empty means not to stop.
730ifndef stop-on-test-failure
731stop-on-test-failure =
732endif
733
734# How to run a program we just linked with our library.
735# The program binary is assumed to be $(word 2,$^).
736built-program-file = $(dir $(word 2,$^))$(notdir $(word 2,$^))
737rtld-prefix = $(elf-objpfx)$(rtld-installed-name)			      \
738	      --library-path						      \
739	      $(rpath-link)$(patsubst %,:%,$(sysdep-library-path))
740ifeq (yes,$(build-shared))
741comma = ,
742sysdep-library-path = \
743$(subst $(empty) ,:,$(strip $(patsubst -Wl$(comma)-rpath-link=%, %,\
744				       $(filter -Wl$(comma)-rpath-link=%,\
745						$(sysdep-LDFLAGS)))))
746# $(run-via-rtld-prefix) is a command that, when prepended to the name
747# of a program built with the newly built library, produces a command
748# that, executed on the host for which the library is built, runs that
749# program.  For tests listed in tests-static or xtests-static, it is
750# empty.
751run-via-rtld-prefix =							      \
752  $(if $(strip $(filter $(notdir $(built-program-file)),		      \
753			$(tests-static) $(xtests-static))),, $(rtld-prefix))
754else
755run-via-rtld-prefix =
756endif
757# $(run-program-env) is the default environment variable settings to
758# use when running a program built with the newly built library.
759run-program-env = GCONV_PATH=$(common-objpfx)iconvdata \
760		  LOCPATH=$(common-objpfx)localedata LC_ALL=C
761# $(run-program-prefix) is a command that, when prepended to the name
762# of a program built with the newly built library, produces a command
763# that, executed on the build system on which "make" is run, runs that
764# program.  $(run-program-prefix-before-env) and
765# $(run-program-prefix-after-env) are similar, but separate parts
766# before and after a list of environment variables.
767run-program-prefix-before-env = $(test-wrapper-env)
768run-program-prefix-after-env = $(run-via-rtld-prefix)
769run-program-prefix = $(run-program-prefix-before-env) $(run-program-env) \
770		     $(run-program-prefix-after-env)
771# $(built-program-cmd) is a command that, executed on the build system
772# on which "make" is run, runs the newly built program that is the
773# second dependency of the makefile target in which
774# $(built-program-cmd) is used.  $(built-program-cmd-before-env) and
775# $(built-program-cmd-after-env) are similar, before and after a list
776# of environment variables.
777built-program-cmd-before-env = $(test-wrapper-env)
778built-program-cmd-after-env = $(run-via-rtld-prefix) $(built-program-file)
779built-program-cmd = $(built-program-cmd-before-env) $(run-program-env) \
780		    $(built-program-cmd-after-env)
781# $(host-built-program-cmd) is a command that, executed on the host
782# for which the library is built, runs the newly built program that is
783# the second dependency of the makefile target in which
784# $(host-built-program-cmd) is used.
785host-built-program-cmd = $(run-via-rtld-prefix) $(built-program-file)
786# $(ld-library-path) is the common content to be set in LD_LIBRARY_PATH
787# for running static binaries that may load dynamic objects.
788ld-library-path = $(objpfx):$(common-objpfx)$(addprefix :,$(sysdep-ld-library-path))
789
790ifndef LD
791LD := ld -X
792endif
793
794# $(test-via-rtld-prefix) is a command that, when prepended to the name
795# of a test program built with the newly built library, produces a command
796# that, executed on the host for which the library is built, runs that
797# program.  For tests listed in tests-static or xtests-static as well
798# as when test programs are hardcoded to the newly built libraries, it
799# is empty.
800
801# $(test-program-prefix) is a command that, when prepended to the name
802# of a test program built with the newly built library, produces a command
803# that, executed on the build system on which "make" is run, runs that
804# test program.  $(test-program-prefix-before-env) and
805# $(test-program-prefix-after-env) are similar, before and after a
806# list of environment variables.
807
808# $(test-program-cmd) is a command that, executed on the build system
809# on which "make" is run, runs the newly built test program that is the
810# second dependency of the makefile target in which
811# $(test-program-cmd) is used.  $(test-program-cmd-before-env) and
812# $(test-program-cmd-after-env) are similar, before and after a list
813# of environment variables.
814
815# $(host-test-program-cmd) is a command that, executed on the host
816# for which the library is built, runs the newly built test program that
817# is the second dependency of the makefile target in which
818# $(host-test-program-cmd) is used.
819
820ifeq (yes,$(build-hardcoded-path-in-tests))
821test-via-rtld-prefix =
822test-program-prefix-before-env = $(test-wrapper-env)
823test-program-prefix-after-env =
824test-program-prefix = $(test-program-prefix-before-env) $(run-program-env) \
825		      $(test-program-prefix-after-env)
826test-program-cmd-before-env = $(test-wrapper-env)
827test-program-cmd-after-env = $(built-program-file)
828test-program-cmd = $(test-program-cmd-before-env) $(run-program-env) \
829		   $(test-program-cmd-after-env)
830host-test-program-cmd = $(built-program-file)
831else
832test-via-rtld-prefix = $(run-via-rtld-prefix)
833test-program-prefix-before-env = $(run-program-prefix-before-env)
834test-program-prefix-after-env = $(run-program-prefix-after-env)
835test-program-prefix = $(run-program-prefix)
836test-program-cmd-before-env = $(built-program-cmd-before-env)
837test-program-cmd-after-env = $(built-program-cmd-after-env)
838test-program-cmd = $(built-program-cmd)
839host-test-program-cmd = $(host-built-program-cmd)
840endif
841
842# Extra flags to pass to GCC.
843ifeq ($(all-warnings),yes)
844+gccwarn := -Wall -Wwrite-strings -Wcast-qual -Wbad-function-cast -Wmissing-noreturn -Wmissing-prototypes -Wmissing-declarations -Wcomment -Wcomments -Wtrigraphs -Wsign-compare -Wfloat-equal -Wmultichar
845else
846+gccwarn := -Wall -Wwrite-strings
847endif
848+gccwarn += -Wundef
849ifeq ($(enable-werror),yes)
850+gccwarn += -Werror
851endif
852+gccwarn-c = -Wstrict-prototypes -Wold-style-definition
853
854# We do not depend on the address of constants in different files to be
855# actually different, so allow the compiler to merge them all.
856+merge-constants = -fmerge-all-constants
857
858# We have to assume that glibc functions are called in any rounding
859# mode and also change the rounding mode in a few functions. So,
860# disable any optimization that assume default rounding mode.
861+math-flags = -frounding-math
862
863# Logically only "libnldbl", "nonlib" and "testsuite" should be using
864# -fno-math-errno. However due to GCC bug #88576, only "libm" can use
865# -fno-math-errno.
866+extra-math-flags = $(if $(filter libm,$(in-module)),-fno-math-errno,-fmath-errno)
867
868# Use 64 bit time_t support for installed programs
869installed-modules = nonlib nscd lddlibc4 ldconfig locale_programs \
870		    iconvprogs libnss_files libnss_compat libnss_db libnss_hesiod \
871		    libutil libpcprofile libSegFault
872+extra-time-flags = $(if $(filter $(installed-modules),\
873                           $(in-module)),-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64)
874
875# We might want to compile with some stack-protection flag.
876ifneq ($(stack-protector),)
877+stack-protector=$(stack-protector)
878endif
879
880# Some routines are unsafe to build with stack-protection since they're called
881# before the stack check guard is set up.  Provide a way to disable stack
882# protector.  The first argument is the extension (.o, .os, .oS) and the second
883# is a list of routines that this path should be applied to.
884define elide-stack-protector
885$(if $(filter $(@F),$(patsubst %,%$(1),$(2))), $(no-stack-protector))
886endef
887
888# The program that makes Emacs-style TAGS files.
889ETAGS	:= etags
890
891# The `xgettext' program for producing .pot files from sources.
892ifndef XGETTEXT
893XGETTEXT = xgettext
894endif
895
896# The `m4' macro processor; this is used by sysdeps/sparc/Makefile (and
897# perhaps others) to preprocess assembly code in some cases.
898M4 = m4
899
900# To force installation of files even if they are older than the
901# installed files.  This variable is included in the dependency list
902# of all installation targets.
903ifeq ($(force-install),yes)
904+force = force-install
905else
906+force =
907endif
908
909####
910#### End of configuration variables.
911####
912
913# This tells some versions of GNU make before 3.63 not to export all variables.
914.NOEXPORT:
915
916# We want to echo the commands we're running without
917# umpteen zillion filenames along with it (we use `...' instead)
918# but we don't want this echoing done when the user has said
919# he doesn't want to see commands echoed by using -s.
920ifneq	"$(findstring s,$(MAKEFLAGS))" ""	# if -s
921+cmdecho	:= echo >/dev/null
922else						# not -s
923+cmdecho	:= echo
924endif	   					# -s
925
926# These are the flags given to the compiler to tell
927# it what sort of optimization and/or debugging output to do.
928ifndef	+cflags
929# If `CFLAGS' was defined, use that.
930ifdef		CFLAGS
931+cflags	:= $(filter-out -I%,$(CFLAGS))
932endif		# CFLAGS
933endif	# +cflags
934
935# If none of the above worked, default to "-g -O".
936ifeq	"$(strip $(+cflags))" ""
937+cflags	:= $(default_cflags)
938endif	# $(+cflags) == ""
939
940# Force building with -fno-common because hidden_def, compat_symbol
941# and other constructs do not work for common symbols (and would
942# otherwise require specifying __attribute__ ((nocommon)) on a
943# case-by-case basis).
944+cflags += $(cflags-cpu) $(+gccwarn) $(+merge-constants) $(+math-flags) \
945	   $(+stack-protector) -fno-common
946+gcc-nowarn := -w
947
948# Each sysdeps directory can contain header files that both will be
949# used to compile and will be installed.  Each can also contain an
950# include/ subdirectory, whose header files will be used to compile
951# but will not be installed, and will take precedence over the
952# installed files.  This mirrors the top-level include/ subdirectory.
953+sysdep-includes := $(foreach dir,$(+sysdep_dirs),\
954			      $(addprefix -I,$(wildcard $(dir)/include) $(dir)))
955
956# These are flags given to the C compiler to tell it to look for
957# include files (including ones given in angle brackets) in the parent
958# library source directory, in the include directory, and in the
959# current directory.
960+includes = -I$(..)include $(if $(subdir),$(objpfx:%/=-I%)) \
961	    $(+sysdep-includes) $(includes) \
962	    $(patsubst %/,-I%,$(..)) $(libio-include) -I. $(sysincludes)
963
964# Since libio has several internal header files, we use a -I instead
965# of many little headers in the include directory.
966libio-include = -I$(..)libio
967
968# List of non-library modules that we build.
969built-modules = iconvprogs iconvdata ldconfig lddlibc4 libmemusage \
970		libSegFault libpcprofile librpcsvc locale-programs \
971		memusagestat nonlib nscd extramodules libnldbl libsupport \
972		testsuite testsuite-internal
973
974in-module = $(subst -,_,$(firstword $(libof-$(basename $(@F))) \
975				    $(libof-$(<F)) \
976				    $(libof-$(@F)) \
977				    libc))
978
979# Build ld.so, libc.so and libpthread.so with -ftls-model=initial-exec
980tls-model = $(if $(filter libpthread rtld \
981			  libc,$(in-module)),-ftls-model=initial-exec,)
982
983module-cppflags-real = -include $(common-objpfx)libc-modules.h \
984		       -DMODULE_NAME=$(in-module)
985
986# We don't need libc-modules.h and the MODULE_NAME definition for .v.i
987# files.  These targets don't (and will likely never need to) use the IS_IN
988# facility.  In fact, shlib-versions should not use it because that will
989# create a circular dependency as libc-modules.h is generated from
990# shlib-versions.
991module-cppflags = $(if $(filter %.mk.i %.v.i,$(@F)),,$(module-cppflags-real))
992
993# These are the variables that the implicit compilation rules use.
994# Note that we can't use -std=* in CPPFLAGS, because it overrides
995# the implicit -lang-asm and breaks cpp behavior for .S files--notably
996# it causes cpp to stop predefining __ASSEMBLER__.
997CPPFLAGS = $(config-extra-cppflags) $(CPPUNDEFS) $(CPPFLAGS-config) \
998	   $($(subdir)-CPPFLAGS) \
999	   $(+includes) $(defines) $(module-cppflags) \
1000	   -include $(..)include/libc-symbols.h $(sysdep-CPPFLAGS) \
1001	   $(CPPFLAGS-$(suffix $@)) \
1002	   $(foreach lib,$(libof-$(basename $(@F))) \
1003			 $(libof-$(<F)) $(libof-$(@F)),$(CPPFLAGS-$(lib))) \
1004	   $(CPPFLAGS-$(<F)) $(CPPFLAGS-$(@F)) $(CPPFLAGS-$(basename $(@F)))
1005
1006ifneq (no,$(have-tunables))
1007CPPFLAGS += -DTOP_NAMESPACE=glibc
1008endif
1009
1010override CFLAGS	= -std=gnu11 -fgnu89-inline $(config-extra-cflags) \
1011		  $(filter-out %frame-pointer,$(+cflags)) $(+gccwarn-c) \
1012		  $(+extra-math-flags) $(+extra-time-flags) \
1013		  $(sysdep-CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) \
1014		  $(CFLAGS-$(@F)) $(tls-model) \
1015		  $(foreach lib,$(libof-$(basename $(@F))) \
1016				$(libof-$(<F)) $(libof-$(@F)),$(CFLAGS-$(lib)))
1017# Use our copies of cstdlib and cmath.
1018override CXXFLAGS = -I$(common-objpfx) $(c++-sysincludes) \
1019		    $(filter-out %frame-pointer,$(+cflags)) $(sysdep-CFLAGS) \
1020		    $(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) $(CFLAGS-$(@F))
1021
1022# If everything is compiled with -fPIC (implicitly) we must tell this by
1023# defining the PIC symbol.
1024ifeq (yes,$(build-pic-default))
1025pic-default = -DPIC
1026endif
1027
1028# Enable object files for different versions of the library.
1029# Various things use $(object-suffixes) to know what all to make.
1030# The compilation rules use $(CPPFLAGS-${SUFFIX}) and $(CFLAGS-${SUFFIX})
1031# to pass different flags for each flavor.
1032libtypes = $(foreach o,$(object-suffixes-for-libc),$(libtype$o))
1033# .op may be added to all-object-suffixes below.
1034all-object-suffixes := .o .os .oS
1035object-suffixes :=
1036CPPFLAGS-.o = $(pic-default)
1037# libc.a must be compiled with -fPIE/-fpie for static PIE.
1038CFLAGS-.o = $(filter %frame-pointer,$(+cflags)) $(pie-default)
1039libtype.o := lib%.a
1040object-suffixes += .o
1041ifeq (yes,$(build-shared))
1042# Under --enable-shared, we will build a shared library of PIC objects.
1043# The PIC object files are named foo.os.
1044object-suffixes += .os
1045pic-cppflags = -DPIC -DSHARED
1046CPPFLAGS-.os = $(pic-cppflags)
1047CFLAGS-.os = $(filter %frame-pointer,$(+cflags)) $(pic-ccflag)
1048libtype.os := lib%_pic.a
1049# This can be changed by a sysdep makefile
1050pic-ccflag = -fPIC
1051# This one should always stay like this unless there is a very good reason.
1052PIC-ccflag = -fPIC
1053endif
1054# This can be changed by a sysdep makefile
1055pie-ccflag = -fpie
1056no-pie-ccflag = -fno-pie
1057# This one should always stay like this unless there is a very good reason.
1058PIE-ccflag = -fPIE
1059ifeq (yes,$(build-profile))
1060# Under --enable-profile, we will build a static library of profiled objects.
1061# The profiled object files are named foo.op.
1062all-object-suffixes += .op
1063object-suffixes += .op
1064CPPFLAGS-.op = -DPROF $(pic-default)
1065# libc_p.a must be compiled with -fPIE/-fpie for static PIE.
1066CFLAGS-.op = -pg $(pie-default)
1067libtype.op = lib%_p.a
1068endif
1069
1070# Convenience variable for when we want to treat shared-library cases
1071# differently from the rest.
1072object-suffixes-noshared := $(filter-out .os,$(object-suffixes))
1073
1074object-suffixes-for-libc := $(object-suffixes)
1075
1076ifeq (yes,$(build-shared))
1077# Build special library that contains the static-only routines for libc.
1078object-suffixes-for-libc += .oS
1079
1080# Must build the routines as PIC, though, because they can end up in (users')
1081# shared objects.  We don't want to use CFLAGS-os because users may, for
1082# example, make that processor-specific.
1083CFLAGS-.oS = $(CFLAGS-.o) $(PIC-ccflag) $(extra-nonshared-cflags)
1084CPPFLAGS-.oS = $(CPPFLAGS-.o) -DPIC -DLIBC_NONSHARED=1
1085libtype.oS = lib%_nonshared.a
1086endif
1087
1088# The assembler can generate debug information too.
1089ifndef ASFLAGS
1090ASFLAGS := $(filter -g% -fdebug-prefix-map=%,$(CFLAGS))
1091endif
1092override ASFLAGS += -Werror=undef $(ASFLAGS-config) $(asflags-cpu)
1093
1094ifndef BUILD_CC
1095BUILD_CC = $(CC)
1096endif
1097
1098move-if-change = $(SHELL) $(..)scripts/move-if-change
1099
1100-include $(common-objpfx)sysd-sorted
1101subdirs = $(sorted-subdirs)
1102subdir-srcdirs = $(foreach dir,$(subdirs),\
1103			   $(firstword $($(dir)-srcdir) $(..)$(dir)))
1104
1105# This is a pair of implicit rules to preprocess a file with # comments,
1106# %ifdef et al, based on config.h settings or other %include'd files.
1107# We use chained rules instead of a pipeline here so that we can properly
1108# check the exit status of cpp rather than using its bad output when there
1109# is a preprocessing error.  Another rule should depend on the output file
1110# `FOO.v', and along with that `FOO.v.i' should be given dependencies
1111# listing both its input files, and any header files that it may reference
1112# (but no commands).
1113%.v.i: $(common-objpfx)config.h $(..)Makeconfig
1114	sed '/^[ 	]*%/!s/#.*$$//;/^[ 	]*$$/d;s/^[ 	]*%/#/' \
1115	    $(filter-out FORCE %.h $(..)Makeconfig,$^) \
1116	| $(CC) -E -undef $(CPPFLAGS) -x assembler-with-cpp - \
1117		   > $@T
1118	mv -f $@T $@
1119%.v: %.v.i
1120	sed '/^[ 	]*#/d;/^[ 	]*$$/d' $< > $@T
1121	mv -f $@T $@
1122
1123ifeq (yes, $(build-shared))
1124
1125# To generate a header to support more than one ABI for different
1126# architecture variants, the CPU/Makefile defines abi-variants to be a
1127# list of names for those variants (e.g. 32 64), and, for each variant,
1128# defines abi-$(variant)-condition to be the condition for those options
1129# to use in a C #if condition.  abi-includes may be defined to a list of
1130# headers to include in the generated header, if the default does not
1131# suffice.  default-abi is defined to be the ABI for the current glibc
1132# build.
1133
1134ifndef abi-includes
1135abi-includes := bits/wordsize.h
1136endif
1137
1138# Process the shlib-versions file, which tells us what shared library
1139# version numbers to use when we install shared objects on this system.
1140# We need to wait until $(subdirs) is complete.
1141ifeq ($(sysd-sorted-done),t)
1142-include $(common-objpfx)soversions.mk
1143ifndef avoid-generated
1144$(common-objpfx)shlib-versions.v.i: \
1145	$(wildcard $(+sysdep_dirs:=/shlib-versions) \
1146		   $(subdir-srcdirs:=/shlib-versions)) \
1147	$(..)shlib-versions
1148
1149$(common-objpfx)soversions.i: $(..)scripts/soversions.awk \
1150			      $(common-objpfx)shlib-versions.v
1151	$(AWK) -f $^ > $@T
1152	mv -f $@T $@
1153$(common-objpfx)soversions.mk: $(common-objpfx)soversions.i $(..)Makeconfig
1154	(while read which lib number setname; do \
1155	   eval seen_$$which=1; \
1156	   test x"$$which" = xDEFAULT || continue; \
1157	   case $$number in \
1158	     [0-9]*) echo "$$lib.so-version=.$$number"; \
1159		     echo "all-sonames+=$$lib=$$lib.so\$$($$lib.so-version)";;\
1160	     *)	     echo "$$lib.so-version=$$number"; \
1161		     echo "all-sonames+=$$lib=\$$($$lib.so-version)";;\
1162	   esac; \
1163	 done; \
1164	 echo soversions.mk-done = t;) < $< > $@T; exit 0
1165	mv -f $@T $@
1166endif
1167endif
1168
1169postclean-generated += soversions.mk soversions.i \
1170		       shlib-versions.v shlib-versions.v.i
1171
1172before-compile += $(common-objpfx)libc-modules.h
1173common-generated += libc-modules.h libc-modules.stmp
1174ifeq ($(soversions.mk-done),t)
1175# Generate a header with macro definitions for use with the IS_IN macro.
1176# These are the possible values for the MODULE_NAME macro defined when building
1177# sources, to identify which module the translation unit is going to be built
1178# into.
1179$(common-objpfx)libc-modules.h: $(common-objpfx)libc-modules.stmp; @:
1180$(common-objpfx)libc-modules.stmp: $(..)scripts/gen-libc-modules.awk \
1181				   $(common-objpfx)soversions.i
1182	$(AWK) -v buildlist="$(subst -,_,$(built-modules))" -f $^ > ${@:stmp=T}
1183	$(move-if-change) ${@:stmp=T} ${@:stmp=h}
1184	touch $@
1185
1186endif
1187
1188# Build the tunables list header early since it could be used by any module in
1189# glibc.
1190ifneq (no,$(have-tunables))
1191before-compile += $(common-objpfx)dl-tunable-list.h
1192common-generated += dl-tunable-list.h dl-tunable-list.stmp
1193
1194$(common-objpfx)dl-tunable-list.h: $(common-objpfx)dl-tunable-list.stmp; @:
1195$(common-objpfx)dl-tunable-list.stmp: \
1196		$(..)scripts/gen-tunables.awk \
1197		$(..)elf/dl-tunables.list \
1198		$(wildcard $(subdirs:%=$(..)%/dl-tunables.list)) \
1199		$(wildcard $(sysdirs:%=%/dl-tunables.list))
1200	$(AWK) -f $^ > ${@:stmp=T}
1201	$(move-if-change) ${@:stmp=T} ${@:stmp=h}
1202	touch $@
1203endif
1204
1205# Dump the GCC macros used by the default compiler flags to a header
1206# file, so that they can be inspected when using different compiler
1207# flags.  Add the GCCMACRO prefix to make these macro names unique.
1208$(common-objpfx)gcc-macros.h.in: $(common-objpfx)config.status
1209	$(CC) $(CFLAGS) $(CPPFLAGS) -E -dM -x c -o $@ /dev/null
1210$(common-objpfx)gcc-macros.h: $(common-objpfx)gcc-macros.h.in
1211	sed 's/^#define /#define GCCMACRO/' < $< > $@
1212before-compile += $(common-objpfx)gcc-macros.h
1213
1214# Generate version maps, but wait until sysdep-subdirs is known
1215ifeq ($(sysd-sorted-done),t)
1216ifeq ($(build-shared),yes)
1217-include $(common-objpfx)sysd-versions
1218-include $(common-objpfx)Versions.mk
1219$(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
1220common-generated += $(version-maps)
1221postclean-generated += sysd-versions Versions.all abi-versions.h \
1222		       Versions.def Versions.v.i Versions.v Versions.mk
1223
1224ifndef avoid-generated
1225ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
1226sysd-versions-force = FORCE
1227FORCE:
1228endif
1229
1230$(common-objpfx)Versions.def: $(..)scripts/versionlist.awk \
1231			      $(common-objpfx)Versions.v
1232	LC_ALL=C $(AWK) -f $^ > $@T
1233	mv -f $@T $@
1234
1235$(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
1236			      $(common-objpfx)soversions.i \
1237			      $(common-objpfx)Versions.def
1238	{ while read which lib version setname; do \
1239	    test x"$$which" = xDEFAULT || continue; \
1240	    test -z "$$setname" || echo "$$lib : $$setname"; \
1241	  done < $(word 2,$^); \
1242	  cat $(word 3,$^); \
1243	} | LC_ALL=C $(AWK) -f $< > $@T
1244	mv -f $@T $@
1245$(common-objpfx)Versions.mk: $(..)scripts/haveversions.awk \
1246			     $(common-objpfx)Versions.all
1247	$(AWK) -f $^ > $@T
1248	mv -f $@T $@
1249# See %.v/%.v.i implicit rules in Makeconfig.
1250$(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
1251			      $(wildcard $(sysdirs:%=%/Versions)) \
1252			      $(sysd-versions-force)
1253$(common-objpfx)sysd-versions: $(common-objpfx)versions.stmp
1254$(common-objpfx)versions.stmp: $(common-objpfx)Versions.all \
1255			       $(common-objpfx)Versions.v \
1256			       $(..)scripts/versions.awk
1257	( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
1258	  cat $(word 2,$^) \
1259	  | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
1260			    -v move_if_change='$(move-if-change)' \
1261			    -f $(word 3,$^); \
1262	) > $(common-objpfx)sysd-versionsT
1263	mv -f $(common-objpfx)sysd-versionsT $(common-objpfx)sysd-versions
1264	touch $@
1265endif # avoid-generated
1266endif # $(build-shared) = yes
1267
1268-include $(common-objpfx)time64-compat.mk
1269postclean-generated += time64-compat.mk
1270
1271$(common-objpfx)time64-compat.mk: $(common-objpfx)time64-compat.mk.i \
1272				  $(sysd-versions-force)
1273	sed '/^[        ]*#/d;/^[       ]*$$/d' $< > $@T
1274	mv -f $@T $@
1275$(common-objpfx)time64-compat.mk.i: $(..)Makeconfig
1276	printf "#include <time64-compat.h>\n#ifdef TIME64_NON_DEFAULT\nhave-time64-compat = yes\n#endif" \
1277	| $(CC) -E -undef $(CPPFLAGS) -x assembler-with-cpp - > $@T
1278	mv -f $@T $@
1279
1280
1281endif # sysd-sorted-done
1282
1283# The name under which the run-time dynamic linker is installed.
1284# We are currently going for the convention that `/lib/ld.so.1'
1285# names the SVR4/ELF ABI-compliant dynamic linker.
1286ifndef rtld-installed-name
1287ifdef ld.so-version
1288rtld-installed-name = $(ld.so-version)
1289else
1290rtld-installed-name = ld.so.1
1291endif
1292endif
1293
1294ifndef rtld-version-installed-name
1295rtld-version-installed-name = ld-$(version).so
1296endif
1297
1298endif # build-shared
1299
1300
1301ifeq ($(build-shared),yes)
1302libm = $(common-objpfx)math/libm.so$(libm.so-version)
1303libmvec = $(common-objpfx)mathvec/libmvec.so$(libmvec.so-version)
1304else
1305libm = $(common-objpfx)math/libm.a
1306libmvec = $(common-objpfx)mathvec/libmvec.a
1307endif
1308
1309ifeq ($(build-shared),yes)
1310libsupport = $(common-objpfx)support/libsupport_nonshared.a
1311else
1312libsupport = $(common-objpfx)support/libsupport.a
1313endif
1314
1315# This is a partial list of subdirectories containing the library source.
1316# The order is more or less arbitrary.  The sorting step will take care of the
1317# dependencies and generate sorted-subdirs dynamically.
1318all-subdirs = csu assert ctype locale intl catgets math setjmp signal	    \
1319	      stdlib stdio-common libio malloc string wcsmbs time dirent    \
1320	      grp pwd posix io termios resource misc socket sysvipc gmon    \
1321	      gnulib iconv iconvdata wctype manual shadow gshadow po argp   \
1322	      localedata timezone rt conform debug mathvec support	    \
1323	      dlfcn elf
1324
1325ifeq ($(build-crypt),yes)
1326all-subdirs += crypt
1327rpath-dirs += crypt
1328endif
1329
1330ifndef avoid-generated
1331# sysd-sorted itself will contain rules making the sysd-sorted target
1332# depend on Depend files.  But if you just added a Depend file to an
1333# existing directory not in all-subdirs, then sysd-sorted needs to
1334# be regenerated, so it depends on existing $(sorted-subdirs:=/Depend) files.
1335all-Depend-files := $(wildcard $(sort \
1336			$(foreach dir,$(all-subdirs),\
1337				  $(firstword $($(dir)-srcdir) \
1338				  $(..)$(dir))/Depend) \
1339			$(sorted-subdirs:=/Depend)))
1340$(common-objpfx)sysd-sorted: $(..)scripts/gen-sorted.awk \
1341			     $(common-objpfx)config.make $(..)Makeconfig \
1342			     $(wildcard $(sysdirs:=/Subdirs)) \
1343			     $(all-Depend-files)
1344	$(AWK) -f $< \
1345	       -v subdirs='$(all-subdirs)' \
1346	       -v srcpfx='$(..)' \
1347	       $(filter %/Subdirs %/Depend,$^) > $@-tmp
1348	mv -f $@-tmp $@
1349$(all-Depend-files): ;
1350endif
1351
1352# This gives partial TARGET:SOURCE pattern pairs to have rules
1353# emitted into sysd-rules.  A sysdeps Makeconfig fragment can
1354# add its own special object file prefix to this list with e.g. foo-%:%
1355# to have foo-*.? compiled from *.? using $(foo-CPPFLAGS).
1356sysd-rules-patterns := %:% rtld-%:rtld-% rtld-%:% m_%:s_%
1357
1358# Let sysdeps/ subdirs contain a Makeconfig fragment for us to include here.
1359sysdep-makeconfigs := $(wildcard $(+sysdep_dirs:=/Makeconfig))
1360ifneq (,$(sysdep-makeconfigs))
1361include $(sysdep-makeconfigs)
1362endif
1363
1364# Compute just the target patterns.  Makeconfig has set sysd-rules-patterns.
1365sysd-rules-targets := $(sort $(foreach p,$(sysd-rules-patterns),\
1366					 $(firstword $(subst :, ,$p))))
1367
1368# $(libpthread-routines-var) and $(librt-routines-var) are the make
1369# variable to which pthread routines need to be added to land in the
1370# right library.
1371ifeq ($(pthread-in-libc),yes)
1372libpthread-routines-var = routines
1373librt-routines-var = routines
1374libanl-routines-var = routines
1375else
1376libpthread-routines-var = libpthread-routines
1377librt-routines-var = librt-routines
1378libanl-routines-var = libanl-routines
1379endif
1380
1381# A sysdeps Makeconfig fragment may set libc-reentrant to yes.
1382ifeq (yes,$(libc-reentrant))
1383defines += -D_LIBC_REENTRANT
1384
1385libio-mtsafe = -D_IO_MTSAFE_IO
1386endif
1387
1388# The name to give to a test in test results summaries.
1389test-name = $(strip $(patsubst %.out, %, $(patsubst $(common-objpfx)%, %, $@)))
1390
1391# Likewise, in XFAIL variable names.
1392test-xfail-name = $(strip $(patsubst %.out, %, $(patsubst $(objpfx)%, %, $@)))
1393
1394# Command to output a test status line (such as PASS: test-name).  If
1395# test-xfail-$(test-xfail-name) has a nonempty value, the status will be
1396# XPASS or XFAIL rather than PASS or FAIL.
1397evaluate-test = $(..)scripts/evaluate-test.sh $(test-name) $$? \
1398		  $(if $(test-xfail-$(test-xfail-name)),true,false) \
1399		  $(if $(stop-on-test-failure),true,false) \
1400		  > $(common-objpfx)$(test-name).test-result
1401
1402endif # Makeconfig not yet included
1403
1404# Local Variables:
1405# mode: makefile
1406# End:
1407