]> git.ipfire.org Git - thirdparty/glibc.git/blame - Makeconfig
hurd: Fix vm_size_t incoherencies
[thirdparty/glibc.git] / Makeconfig
CommitLineData
581c785b 1# Copyright (C) 1991-2022 Free Software Foundation, Inc.
72e4a717 2# Copyright The GNU Toolchain Authors.
28f540f4
RM
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
41bdb6e2
AJ
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.
28f540f4
RM
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
41bdb6e2 13# Lesser General Public License for more details.
28f540f4 14
41bdb6e2 15# You should have received a copy of the GNU Lesser General Public
59ba27a6 16# License along with the GNU C Library; if not, see
5a82c748 17# <https://www.gnu.org/licenses/>.
28f540f4
RM
18
19#
20# Makefile configuration options for the GNU C library.
21#
22ifneq (,)
23This makefile requires GNU Make.
24endif
25
3e5f5557
UD
26all: # Make this the default goal
27
28f540f4
RM
28ifneq "$(origin +included-Makeconfig)" "file"
29
30+included-Makeconfig := yes
31
32ifdef subdir
33.. := ../
34endif
35
094bacdb 36# $(common-objdir) is the place to put objects and
28f540f4
RM
37# such that are not specific to a single subdir.
38ifdef objdir
6e953631
UD
39objpfx := $(patsubst %//,%/,$(objdir)/$(subdir)/)
40common-objpfx = $(objdir)/
28f540f4
RM
41common-objdir = $(objdir)
42else
9207e30d 43$(error objdir must be defined by the build-directory Makefile)
28f540f4
RM
44endif
45
f332db02
RM
46# Root of the sysdeps tree.
47sysdep_dir := $(..)sysdeps
48export sysdep_dir := $(sysdep_dir)
49
28f540f4
RM
50# Get the values defined by options to `configure'.
51include $(common-objpfx)config.make
52
e07bb02a 53# What flags to give to sources which call user provided callbacks
56ab3869 54uses-callbacks = -fexceptions
e07bb02a 55
a4db3439
UD
56# What flags to give to tests which test stack alignment
57stack-align-test-flags =
58
57ba7bb4 59# Complete path to sysdep dirs.
e0a3ed4f
RM
60# `configure' writes a definition of `config-sysdirs' in `config.make'.
61sysdirs := $(foreach D,$(config-sysdirs),$(firstword $(filter /%,$D) $(..)$D))
62
644d3857 63+sysdep_dirs = $(sysdirs)
e0a3ed4f
RM
64ifdef objdir
65+sysdep_dirs := $(objdir) $(+sysdep_dirs)
66endif
57ba7bb4 67
273d56ce
RM
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.
19361cb7
UD
73$(common-objpfx)config.make: $(common-objpfx)config.status \
74 $(..)config.make.in $(..)config.h.in
273d56ce
RM
75 cd $(<D); $(SHELL) $(<F)
76
644d3857
JM
77# Find all the sysdeps configure fragments, to make sure we re-run
78# configure when any of them changes.
5290baf0 79$(common-objpfx)config.status: $(..)version.h $(..)configure \
e0a3ed4f
RM
80 $(foreach dir,$(sysdirs),\
81 $(wildcard $(dir)/Implies) \
95afbbe5 82 $(patsubst %.ac,%,\
f332db02 83 $(firstword $(wildcard \
cb8a6dbd 84 $(addprefix $(dir)/,configure configure.ac))))) \
95afbbe5 85 $(patsubst %.ac,%,\
644d3857 86 $(wildcard $(..)sysdeps/*/preconfigure $(..)sysdeps/*/preconfigure.ac))
273d56ce
RM
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
28f540f4 92
74015205
UD
93# We don't want CPPFLAGS to be exported to the command running configure.
94unexport CPPFLAGS
95
28f540f4
RM
96# Get the user's configuration parameters.
97ifneq ($(wildcard $(..)configparms),)
98include $(..)configparms
99endif
100ifneq ($(objpfx),)
6e953631
UD
101ifneq ($(wildcard $(common-objpfx)configparms),)
102include $(common-objpfx)configparms
28f540f4
RM
103endif
104endif
28f540f4
RM
105\f
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.
487253ea 114ifeq ($(origin prefix),undefined) # ifndef would override explicit empty value.
28f540f4
RM
115prefix = /usr/local
116endif
117
0413b54c
UD
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
28f540f4 129# Common prefix for machine-dependent installation directories.
487253ea 130ifeq ($(origin exec_prefix),undefined)
28f540f4
RM
131exec_prefix = $(prefix)
132endif
133
134# Where to install the library and object files.
135ifndef libdir
136libdir = $(exec_prefix)/lib
137endif
8d57beea 138inst_libdir = $(install_root)$(libdir)
28f540f4 139
aaa8cb4b 140# Where to install the shared library.
094bacdb
RM
141ifndef slibdir
142slibdir = $(exec_prefix)/lib
143endif
8d57beea 144inst_slibdir = $(install_root)$(slibdir)
094bacdb 145
aaa8cb4b
AS
146# Where to install the dynamic linker.
147ifndef rtlddir
148rtlddir = $(slibdir)
149endif
150inst_rtlddir = $(install_root)$(rtlddir)
151
28f540f4
RM
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.
487253ea 156ifeq ($(origin libprefix),undefined)
28f540f4
RM
157libprefix =
158endif
159
160# Where to install the header files.
161ifndef includedir
25c751d0 162includedir = $(prefix)/include
28f540f4 163endif
8d57beea 164inst_includedir = $(install_root)$(includedir)
28f540f4 165
28f540f4 166# Where to install machine-independent data files.
a2fe9c76 167# These are the timezone database, and the locale database.
28f540f4
RM
168ifndef datadir
169datadir = $(prefix)/share
170endif
8d57beea 171inst_datadir = $(install_root)$(datadir)
28f540f4
RM
172
173# Where to install the timezone data files (which are machine-independent).
174ifndef zonedir
175zonedir = $(datadir)/zoneinfo
176endif
8d57beea 177inst_zonedir = $(install_root)$(zonedir)
28f540f4 178
90fe682d
CD
179# Where to install the compiled binary locale archive and compiled
180# binary locale files.
181ifndef complocaledir
182complocaledir = $(libdir)/locale
a2fe9c76 183endif
90fe682d 184inst_complocaledir = $(install_root)$(complocaledir)
a2fe9c76 185
4a33c2f5
UD
186# Where to install the message catalog data files (which are
187# machine-independent).
314f6dee
CD
188ifndef localedir
189localedir = $(datadir)/locale
4a33c2f5 190endif
314f6dee 191inst_localedir = $(install_root)$(localedir)
4a33c2f5 192
3ec41e03 193# Where to install the locale charmap source files.
19bc17a9
RM
194ifndef i18ndir
195i18ndir = $(datadir)/i18n
a2fe9c76 196endif
8d57beea 197inst_i18ndir = $(install_root)$(i18ndir)
a2fe9c76 198
6973fc01
UD
199# Where to install the shared object for charset transformation.
200ifndef gconvdir
201gconvdir = $(libdir)/gconv
202endif
203inst_gconvdir = $(install_root)$(gconvdir)
204
28f540f4
RM
205# Where to install programs.
206ifndef bindir
207bindir = $(exec_prefix)/bin
208endif
8d57beea 209inst_bindir = $(install_root)$(bindir)
28f540f4 210
7f0ff1b0
UD
211# Where to install internal programs.
212ifndef libexecdir
213libexecdir = $(exec_prefix)/libexec
214endif
215inst_libexecdir = $(install_root)$(libexecdir)
216
28f540f4 217# Where to install administrative programs.
1ef32c3d
UD
218ifndef rootsbindir
219rootsbindir = $(exec_prefix)/sbin
220endif
8d57beea 221inst_rootsbindir = $(install_root)$(rootsbindir)
1ef32c3d 222
28f540f4
RM
223ifndef sbindir
224sbindir = $(exec_prefix)/sbin
225endif
8d57beea 226inst_sbindir = $(install_root)$(sbindir)
28f540f4
RM
227
228# Where to install the Info files.
229ifndef infodir
230infodir = $(prefix)/info
231endif
8d57beea 232inst_infodir = $(install_root)$(infodir)
28f540f4 233
a9171047
UD
234# Where to install audit libraries.
235ifndef auditdir
236auditdir = $(libdir)/audit
237endif
238inst_auditdir = $(install_root)$(auditdir)
239
28f540f4
RM
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
8d57beea 245inst_sysconfdir = $(install_root)$(sysconfdir)
28f540f4 246
77fb9117
UD
247# Directory for the database files and Makefile for nss_db.
248ifndef vardbdir
4248b1b1 249vardbdir = $(localstatedir)/db
77fb9117
UD
250endif
251inst_vardbdir = $(install_root)$(vardbdir)
252
28f540f4
RM
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
0d8733c4 259localtime-file = $(sysconfdir)/localtime
28f540f4
RM
260endif
261
59dd8641
RM
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
28f540f4
RM
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
07627f49
UD
301ifndef INSTALL_SCRIPT
302INSTALL_SCRIPT = $(INSTALL)
303endif
28f540f4
RM
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
1d5c2feb
UD
327ifeq ($(release),stable)
328default_cflags := -g -O2
329else
a8922de8 330default_cflags := -g -O
28f540f4 331endif
1d5c2feb 332endif
28f540f4
RM
333
334# Flags to pass the C compiler when assembling preprocessed assembly code
e4f5eae8 335# (`.S' files).
28f540f4
RM
336ifndef asm-CPPFLAGS
337asm-CPPFLAGS =
338endif
339
3ce1f295
UD
340# Must be supported by the linker.
341no-whole-archive = -Wl,--no-whole-archive
342whole-archive = -Wl,--whole-archive
343
779ae82e 344# Installed name of the startup code.
26ecc33a 345# The ELF convention is that the startfile is called crt1.o
779ae82e 346start-installed-name = crt1.o
af09bfb5
RM
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
779ae82e 352
9d7a3741
L
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
1c563add
UD
361relro-LDFLAGS = -Wl,-z,relro
362LDFLAGS.so += $(relro-LDFLAGS)
363LDFLAGS-rtld += $(relro-LDFLAGS)
1c563add 364
2d5ec669
L
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
23645707
SP
374ifeq (no,$(build-pie-default))
375pie-default = $(no-pie-ccflag)
376else # build-pie-default
9d7a3741
L
377pic-default = -DPIC
378# Compile libc.a and libc_p.a with -fPIE/-fpie for static PIE.
379pie-default = $(pie-ccflag)
23645707
SP
380
381ifeq (yes,$(enable-static-pie))
2d5ec669 382static-pie-dt-relr-ldflag = $(dt-relr-ldflag)
9d7a3741 383ifeq (yes,$(have-static-pie))
23645707 384static-pie-ldflag = -static-pie
9d7a3741
L
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.
23645707
SP
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
9d7a3741 393
2d6ab5df
FW
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
94a4e9e4
FW
399# Extra flags for dynamically linked non-test main programs.
400link-extra-flags += -Wl,-z,now
2d6ab5df
FW
401endif
402
04f5a636
RM
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
c23de0aa
FW
411# Additional libraries to link into every test.
412link-extra-libs-tests = $(libsupport)
413
435aa54b
L
414# Command for linking PIE programs with the C library.
415ifndef +link-pie
f3eef963 416+link-pie-before-inputs = $(if $($(@F)-no-pie),$(no-pie-ldflag),-pie) \
2d5ec669 417 $(if $($(@F)-no-dt-relr),$(no-dt-relr-ldflag),$(dt-relr-ldflag)) \
f3eef963 418 -Wl,-O1 -nostdlib -nostartfiles \
740b3dbe 419 $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
3ee318c9 420 $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
34d6a3cb 421 $(firstword $(CRT-$(@F)) $(csu-objpfx)S$(start-installed-name)) \
f3eef963
JM
422 $(+preinit) $(+prectorS)
423+link-pie-before-libc = -o $@ $(+link-pie-before-inputs) \
435aa54b 424 $(filter-out $(addprefix $(csu-objpfx),start.o \
da62f81b
AS
425 S$(start-installed-name))\
426 $(+preinit) $(link-extra-libs) \
427 $(common-objpfx)libc% $(+postinit),$^) \
740b3dbe
L
428 $(link-extra-libs)
429+link-pie-after-libc = $(+postctorS) $(+postinit)
04f5a636 430define +link-pie
a8ff215e
FW
431$(CC) $(link-libc-rpath-link) $(+link-pie-before-libc) $(rtld-LDFLAGS) \
432 $(link-extra-flags) $(link-libc) $(+link-pie-after-libc)
04f5a636
RM
433$(call after-link,$@)
434endef
435define +link-pie-tests
e30fb31c
FW
436$(CC) $(+link-pie-before-libc) $(rtld-tests-LDFLAGS) $(link-libc-tests) \
437 $(+link-pie-after-libc)
04f5a636
RM
438$(call after-link,$@)
439endef
23b5cae1 440define +link-pie-printers-tests
e30fb31c
FW
441$(CC) $(+link-pie-before-libc) $(built-rtld-LDFLAGS) \
442 $(link-libc-printers-tests) $(+link-pie-after-libc)
23b5cae1
MG
443$(call after-link,$@)
444endef
435aa54b 445endif
e1586792
UD
446# Command for statically linking programs with the C library.
447ifndef +link-static
f3eef963 448+link-static-before-inputs = -nostdlib -nostartfiles -static \
23645707 449 $(if $($(@F)-no-pie),$(no-pie-ldflag),$(static-pie-ldflag)) \
2d5ec669 450 $(if $($(@F)-no-dt-relr),$(no-dt-relr-ldflag),$(static-pie-dt-relr-ldflag)) \
9f0d7b6d 451 $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
9d7a3741 452 $(firstword $(CRT-$(@F)) $(csu-objpfx)$(real-static-start-installed-name)) \
f3eef963
JM
453 $(+preinit) $(+prectorT)
454+link-static-before-libc = -o $@ $(+link-static-before-inputs) \
e1586792
UD
455 $(filter-out $(addprefix $(csu-objpfx),start.o \
456 $(start-installed-name))\
457 $(+preinit) $(link-extra-libs-static) \
458 $(common-objpfx)libc% $(+postinit),$^) \
d173d12e 459 $(link-extra-libs-static)
a5055ad1 460+link-static-after-libc = $(+postctorT) $(+postinit)
04f5a636 461define +link-static
e30fb31c
FW
462$(CC) $(+link-static-before-libc) $(link-extra-flags) $(link-libc-static) \
463 $(+link-static-after-libc)
04f5a636
RM
464$(call after-link,$@)
465endef
466define +link-static-tests
e30fb31c
FW
467$(CC) $(+link-static-before-libc) $(link-libc-static-tests) \
468 $(+link-static-after-libc)
04f5a636
RM
469$(call after-link,$@)
470endef
e1586792 471endif
94b32c39
L
472# Commands for linking programs with the C library.
473ifndef +link
474ifeq (yes,$(build-shared))
00c714df 475ifeq (yes,$(cc-pie-default))
cc08749b 476no-pie-ldflag = -no-pie
00c714df
L
477endif
478ifeq (yes,$(build-pie-default))
cc08749b
L
479+link = $(+link-pie)
480+link-tests = $(+link-pie-tests)
f3eef963
JM
481+link-tests-before-inputs = $(+link-pie-before-inputs) $(rtld-tests-LDFLAGS)
482+link-tests-after-inputs = $(link-libc-tests) $(+link-pie-after-libc)
23b5cae1
MG
483+link-printers-tests = $(+link-pie-printers-tests)
484else # not build-pie-default
23645707 485+link-before-inputs = -nostdlib -nostartfiles $(no-pie-ldflag) \
740b3dbe 486 $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
3ee318c9 487 $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
6014c65d 488 $(firstword $(CRT-$(@F)) $(csu-objpfx)$(start-installed-name)) \
f3eef963
JM
489 $(+preinit) $(+prector)
490+link-before-libc = -o $@ $(+link-before-inputs) \
94b32c39
L
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)
04f5a636 497define +link
a8ff215e
FW
498$(CC) $(link-libc-rpath-link) $(+link-before-libc) $(rtld-LDFLAGS) \
499 $(link-extra-flags) $(link-libc) $(+link-after-libc)
04f5a636
RM
500$(call after-link,$@)
501endef
f3eef963
JM
502+link-tests-before-inputs = $(+link-before-inputs) $(rtld-tests-LDFLAGS)
503+link-tests-after-inputs = $(link-libc-tests) $(+link-after-libc)
04f5a636 504define +link-tests
e30fb31c 505$(CC) $(+link-before-libc) $(rtld-tests-LDFLAGS) $(link-libc-tests) \
76dcbf42 506 $(+link-after-libc)
04f5a636
RM
507$(call after-link,$@)
508endef
23b5cae1 509define +link-printers-tests
e30fb31c 510$(CC) $(+link-before-libc) $(built-rtld-LDFLAGS) $(link-libc-printers-tests) \
23b5cae1
MG
511 $(+link-after-libc)
512$(call after-link,$@)
513endef
514endif # build-pie-default
515else # build-static
94b32c39
L
516+link = $(+link-static)
517+link-tests = $(+link-static-tests)
f3eef963
JM
518+link-tests-before-inputs = $(+link-static-before-inputs)
519+link-tests-after-inputs = $(link-libc-static-tests) $(+link-static-after-libc)
23b5cae1
MG
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
0269750c 537ifeq (yes,$(build-shared))
23b5cae1
MG
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
740b3dbe 542ifndef rtld-LDFLAGS
23b5cae1 543rtld-LDFLAGS = $(installed-rtld-LDFLAGS)
740b3dbe 544endif
23b5cae1 545
740b3dbe
L
546ifndef rtld-tests-LDFLAGS
547ifeq (yes,$(build-hardcoded-path-in-tests))
23b5cae1 548rtld-tests-LDFLAGS = $(built-rtld-LDFLAGS)
740b3dbe 549else
23b5cae1
MG
550rtld-tests-LDFLAGS = $(installed-rtld-LDFLAGS)
551endif # build-hardcoded-path-in-tests
552endif # rtld-tests-LDFLAGS
553
554endif # build-shared
555
3fe9de0d
RM
556ifndef link-libc
557ifeq (yes,$(build-shared))
aa1075ea
RM
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.
23b5cae1 561link-libc-rpath = -Wl,-rpath=$(rpath-link)
740b3dbe 562link-libc-rpath-link = -Wl,-rpath-link=$(rpath-link)
23b5cae1 563
a8ff215e
FW
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.
740b3dbe 573ifeq (yes,$(build-hardcoded-path-in-tests))
23b5cae1 574link-libc-tests-rpath-link = $(link-libc-rpath)
114d07fd 575link-test-modules-rpath-link = $(link-libc-rpath)
740b3dbe
L
576else
577link-libc-tests-rpath-link = $(link-libc-rpath-link)
114d07fd 578link-test-modules-rpath-link =
23b5cae1
MG
579endif # build-hardcoded-path-in-tests
580
3618e5fe
PM
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)
23b5cae1 586
3618e5fe 587link-libc-tests-after-rpath-link = $(gnulib-tests) $(link-libc-between-gnulib) $(gnulib-tests)
740b3dbe 588link-libc-tests = $(link-libc-tests-rpath-link) \
23b5cae1
MG
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
4d6acc61 594# This is how to find at build-time things that will be installed there.
e69d994a 595rpath-dirs = math elf dlfcn nss nis rt resolv mathvec support
e72bfd87
UD
596rpath-link = \
597$(common-objdir):$(subst $(empty) ,:,$(patsubst ../$(subdir),.,$(rpath-dirs:%=$(common-objpfx)%)))
23b5cae1 598else # build-static
4ac5087b 599link-libc = $(common-objpfx)libc.a $(otherlibs) $(gnulib) $(common-objpfx)libc.a $(gnulib)
95f5a9a8 600link-libc-tests = $(common-objpfx)libc.a $(otherlibs) $(gnulib-tests) $(common-objpfx)libc.a $(gnulib-tests)
23b5cae1
MG
601endif # build-shared
602endif # link-libc
900bec85 603
ad10cac8 604# Differences in the linkers on the various platforms.
ad10cac8
UD
605LDFLAGS-rpath-ORIGIN = -Wl,-rpath,'$$ORIGIN'
606LDFLAGS-soname-fname = -Wl,-soname,$(@F)
607LDFLAGS-rdynamic = -rdynamic
608LDFLAGS-Bsymbolic = -Bsymbolic
ad10cac8 609
f01010de
UD
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
57ba7bb4 618ifndef link-extra-libs
1d038b6b
RM
619link-extra-libs = $(LDLIBS-$(@F))
620link-extra-libs-static = $(link-extra-libs)
57ba7bb4 621endif
e1586792
UD
622
623# The static libraries.
b9af1301 624link-libc-static = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib) -Wl,--end-group
95f5a9a8 625link-libc-static-tests = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib-tests) -Wl,--end-group
e1586792 626
95f5a9a8
JM
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.
28f540f4 661ifndef gnulib
cbdb12de
UD
662ifneq ($(have-cc-with-libunwind),yes)
663 libunwind =
feca5e0b 664else
cbdb12de 665 libunwind = -lunwind
feca5e0b 666endif
a3cc4f48 667libgcc_eh := -Wl,--as-needed -lgcc_s $(libunwind) -Wl,--no-as-needed
95f5a9a8
JM
668gnulib-arch =
669gnulib = -lgcc $(gnulib-arch)
670gnulib-tests := -lgcc $(libgcc_eh)
671static-gnulib-arch =
94b32c39
L
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))
95f5a9a8 676static-gnulib = -lgcc $(static-gnulib-arch)
94b32c39
L
677else
678static-gnulib = -lgcc -lgcc_eh $(static-gnulib-arch)
679endif
95f5a9a8 680static-gnulib-tests := -lgcc -lgcc_eh $(libunwind)
cbdb12de 681libc.so-gnulib := -lgcc
28f540f4 682endif
e75154a6
RM
683+preinit = $(addprefix $(csu-objpfx),crti.o)
684+postinit = $(addprefix $(csu-objpfx),crtn.o)
35e65999
RA
685+prector = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbegin.o`
686+postctor = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
435aa54b 687# Variants of the two previous definitions for linking PIE programs.
35e65999
RA
688+prectorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginS.o`
689+postctorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtendS.o`
a5055ad1 690# Variants of the two previous definitions for statically linking programs.
9d7a3741
L
691ifeq (yes,$(enable-static-pie))
692# Static PIE must use PIE variants.
693+prectorT = $(+prectorS)
694+postctorT = $(+postctorS)
695else
a5055ad1 696+prectorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginT.o`
189e935b 697+postctorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
9d7a3741 698endif
6e953631
UD
699csu-objpfx = $(common-objpfx)csu/
700elf-objpfx = $(common-objpfx)elf/
28f540f4 701
cc1290d0
JM
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
9162c01d
RM
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
cc1290d0 718
03ac099f
JM
719# Whether to run test programs built for the library's host system.
720ifndef run-built-tests
cc1290d0 721ifeq (yes|,$(cross-compiling)|$(test-wrapper))
03ac099f
JM
722run-built-tests = no
723else
724run-built-tests = yes
725endif
726endif
727
d6fe5e58
JM
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
03a75825
RM
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,$^))
01dc6df9
SP
737rtld-prefix = $(elf-objpfx)$(rtld-installed-name) \
738 --library-path \
739 $(rpath-link)$(patsubst %,:%,$(sysdep-library-path))
0269750c 740ifeq (yes,$(build-shared))
196980f5 741comma = ,
11336c16
UD
742sysdep-library-path = \
743$(subst $(empty) ,:,$(strip $(patsubst -Wl$(comma)-rpath-link=%, %,\
744 $(filter -Wl$(comma)-rpath-link=%,\
745 $(sysdep-LDFLAGS)))))
88866099
JM
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
daaa7713
JM
749# program. For tests listed in tests-static or xtests-static, it is
750# empty.
88866099
JM
751run-via-rtld-prefix = \
752 $(if $(strip $(filter $(notdir $(built-program-file)), \
01dc6df9 753 $(tests-static) $(xtests-static))),, $(rtld-prefix))
8658ceda 754else
88866099
JM
755run-via-rtld-prefix =
756endif
8540f6d2
JM
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
25fe8932 761# $(run-program-prefix) is a command that, when prepended to the name
88866099
JM
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
8540f6d2
JM
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)
88866099
JM
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
8540f6d2
JM
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)
166bca24
JB
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)
3dbbd2ff
ST
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))
03a75825 789
28f540f4
RM
790ifndef LD
791LD := ld -X
792endif
793
740b3dbe
L
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
daaa7713
JM
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.
740b3dbe
L
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
8540f6d2
JM
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.
740b3dbe
L
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
8540f6d2
JM
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.
740b3dbe
L
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 =
8540f6d2
JM
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)
740b3dbe
L
830host-test-program-cmd = $(built-program-file)
831else
832test-via-rtld-prefix = $(run-via-rtld-prefix)
8540f6d2
JM
833test-program-prefix-before-env = $(run-program-prefix-before-env)
834test-program-prefix-after-env = $(run-program-prefix-after-env)
740b3dbe 835test-program-prefix = $(run-program-prefix)
8540f6d2
JM
836test-program-cmd-before-env = $(built-program-cmd-before-env)
837test-program-cmd-after-env = $(built-program-cmd-after-env)
740b3dbe
L
838test-program-cmd = $(built-program-cmd)
839host-test-program-cmd = $(host-built-program-cmd)
840endif
841
28f540f4 842# Extra flags to pass to GCC.
6cc7d725 843ifeq ($(all-warnings),yes)
ed159672 844+gccwarn := -Wall -Wwrite-strings -Wcast-qual -Wbad-function-cast -Wmissing-noreturn -Wmissing-prototypes -Wmissing-declarations -Wcomment -Wcomments -Wtrigraphs -Wsign-compare -Wfloat-equal -Wmultichar
6cc7d725 845else
ed159672 846+gccwarn := -Wall -Wwrite-strings
6cc7d725 847endif
498a2233 848+gccwarn += -Wundef
a4ecc9eb 849ifeq ($(enable-werror),yes)
48bb14bd 850+gccwarn += -Werror
a4ecc9eb 851endif
8e2f7c68 852+gccwarn-c = -Wstrict-prototypes -Wold-style-definition
28f540f4 853
dec36b4f
UD
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
29ba805c
AJ
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
2ef42716
AJ
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)
1294b189 867
a6d2f948 868# Use 64 bit time_t support for installed programs
36676f5e 869installed-modules = nonlib nscd ldconfig locale_programs \
a6d2f948
AZ
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
cecbc796
NA
875# We might want to compile with some stack-protection flag.
876ifneq ($(stack-protector),)
877+stack-protector=$(stack-protector)
878endif
879
8b8f13b6
SP
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
28f540f4 888# The program that makes Emacs-style TAGS files.
78759725 889ETAGS := etags
28f540f4 890
9de06f3c
RM
891# The `xgettext' program for producing .pot files from sources.
892ifndef XGETTEXT
893XGETTEXT = xgettext
894endif
895
28f540f4
RM
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
73237de3
UD
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
28f540f4
RM
909####
910#### End of configuration variables.
911####
912\f
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
6d52618b 917# umpteen zillion filenames along with it (we use `...' instead)
28f540f4
RM
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
fd26970f 935# If none of the above worked, default to "-g -O".
28f540f4
RM
936ifeq "$(strip $(+cflags))" ""
937+cflags := $(default_cflags)
938endif # $(+cflags) == ""
939
7c241325
FW
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).
cecbc796 944+cflags += $(cflags-cpu) $(+gccwarn) $(+merge-constants) $(+math-flags) \
7c241325 945 $(+stack-protector) -fno-common
28f540f4 946+gcc-nowarn := -w
28f540f4 947
b84660a8
RM
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
b6ab06ce
UD
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.
e0a3ed4f 960+includes = -I$(..)include $(if $(subdir),$(objpfx:%/=-I%)) \
4ae73ca0
RM
961 $(+sysdep-includes) $(includes) \
962 $(patsubst %/,-I%,$(..)) $(libio-include) -I. $(sysincludes)
28f540f4 963
96aa2d94 964# Since libio has several internal header files, we use a -I instead
762a2918 965# of many little headers in the include directory.
96aa2d94 966libio-include = -I$(..)libio
28f540f4 967
130ac68c 968# List of non-library modules that we build.
36676f5e 969built-modules = iconvprogs iconvdata ldconfig libmemusage \
130ac68c 970 libSegFault libpcprofile librpcsvc locale-programs \
7c3018f9 971 memusagestat nonlib nscd extramodules libnldbl libsupport \
a6d2f948 972 testsuite testsuite-internal
130ac68c 973
9cd47470
SP
974in-module = $(subst -,_,$(firstword $(libof-$(basename $(@F))) \
975 $(libof-$(<F)) \
976 $(libof-$(@F)) \
977 libc))
978
e400f3cc
SP
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
130ac68c 983module-cppflags-real = -include $(common-objpfx)libc-modules.h \
279bc5b3 984 -DMODULE_NAME=$(in-module)
130ac68c 985
8a257e2c
RM
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.
6b229222 991module-cppflags = $(if $(filter %.mk.i %.v.i,$(@F)),,$(module-cppflags-real))
130ac68c 992
28f540f4 993# These are the variables that the implicit compilation rules use.
ce460d04
RM
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__.
7ffa9423
AZ
997CPPFLAGS = $(config-extra-cppflags) $(CPPUNDEFS) $(CPPFLAGS-config) \
998 $($(subdir)-CPPFLAGS) \
130ac68c 999 $(+includes) $(defines) $(module-cppflags) \
ae8b36f7 1000 -include $(..)include/libc-symbols.h $(sysdep-CPPFLAGS) \
130ac68c 1001 $(CPPFLAGS-$(suffix $@)) \
d29724f8 1002 $(foreach lib,$(libof-$(basename $(@F))) \
bc96fbda 1003 $(libof-$(<F)) $(libof-$(@F)),$(CPPFLAGS-$(lib))) \
0a951d0e 1004 $(CPPFLAGS-$(<F)) $(CPPFLAGS-$(@F)) $(CPPFLAGS-$(basename $(@F)))
67e58f39 1005
6765d5d3 1006ifneq (no,$(have-tunables))
67e58f39
SP
1007CPPFLAGS += -DTOP_NAMESPACE=glibc
1008endif
1009
783dd2d3 1010override CFLAGS = -std=gnu11 -fgnu89-inline $(config-extra-cflags) \
7735afa2 1011 $(filter-out %frame-pointer,$(+cflags)) $(+gccwarn-c) \
a6d2f948 1012 $(+extra-math-flags) $(+extra-time-flags) \
7735afa2 1013 $(sysdep-CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) \
e400f3cc 1014 $(CFLAGS-$(@F)) $(tls-model) \
44f0a71e
UD
1015 $(foreach lib,$(libof-$(basename $(@F))) \
1016 $(libof-$(<F)) $(libof-$(@F)),$(CFLAGS-$(lib)))
83212868
L
1017# Use our copies of cstdlib and cmath.
1018override CXXFLAGS = -I$(common-objpfx) $(c++-sysincludes) \
ef226fec 1019 $(filter-out %frame-pointer,$(+cflags)) $(sysdep-CFLAGS) \
7735afa2 1020 $(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) $(CFLAGS-$(@F))
28f540f4 1021
cc3fa755
UD
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
f0bf9cb9
RM
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.
91641c65 1032libtypes = $(foreach o,$(object-suffixes-for-libc),$(libtype$o))
612148c6
FW
1033# .op may be added to all-object-suffixes below.
1034all-object-suffixes := .o .os .oS
650425ce 1035object-suffixes :=
cc3fa755 1036CPPFLAGS-.o = $(pic-default)
9d7a3741
L
1037# libc.a must be compiled with -fPIE/-fpie for static PIE.
1038CFLAGS-.o = $(filter %frame-pointer,$(+cflags)) $(pie-default)
f0bf9cb9 1039libtype.o := lib%.a
650425ce 1040object-suffixes += .o
f0bf9cb9
RM
1041ifeq (yes,$(build-shared))
1042# Under --enable-shared, we will build a shared library of PIC objects.
40a55d20
UD
1043# The PIC object files are named foo.os.
1044object-suffixes += .os
900fa257
AZ
1045pic-cppflags = -DPIC -DSHARED
1046CPPFLAGS-.os = $(pic-cppflags)
14e9dd67 1047CFLAGS-.os = $(filter %frame-pointer,$(+cflags)) $(pic-ccflag)
40a55d20 1048libtype.os := lib%_pic.a
26b4d766
UD
1049# This can be changed by a sysdep makefile
1050pic-ccflag = -fPIC
231e88a4
UD
1051# This one should always stay like this unless there is a very good reason.
1052PIC-ccflag = -fPIC
f0bf9cb9 1053endif
7b91359b
UD
1054# This can be changed by a sysdep makefile
1055pie-ccflag = -fpie
23645707 1056no-pie-ccflag = -fno-pie
7b91359b
UD
1057# This one should always stay like this unless there is a very good reason.
1058PIE-ccflag = -fPIE
f0bf9cb9
RM
1059ifeq (yes,$(build-profile))
1060# Under --enable-profile, we will build a static library of profiled objects.
40a55d20 1061# The profiled object files are named foo.op.
612148c6 1062all-object-suffixes += .op
40a55d20 1063object-suffixes += .op
cc3fa755 1064CPPFLAGS-.op = -DPROF $(pic-default)
9d7a3741
L
1065# libc_p.a must be compiled with -fPIE/-fpie for static PIE.
1066CFLAGS-.op = -pg $(pie-default)
40a55d20 1067libtype.op = lib%_p.a
f0bf9cb9 1068endif
ab95290c 1069
c1487492
RM
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
9afc8a59
UD
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.
6413fcde 1083CFLAGS-.oS = $(CFLAGS-.o) $(PIC-ccflag) $(extra-nonshared-cflags)
06b31ad3 1084CPPFLAGS-.oS = $(CPPFLAGS-.o) -DPIC -DLIBC_NONSHARED=1
9afc8a59
UD
1085libtype.oS = lib%_nonshared.a
1086endif
1087
073e82bf
RM
1088# The assembler can generate debug information too.
1089ifndef ASFLAGS
2e7c805d 1090ASFLAGS := $(filter -g% -fdebug-prefix-map=%,$(CFLAGS))
073e82bf 1091endif
93a2584c 1092override ASFLAGS += -Werror=undef $(ASFLAGS-config) $(asflags-cpu)
9afc8a59 1093
96bda0ea
RM
1094ifndef BUILD_CC
1095BUILD_CC = $(CC)
1096endif
e72bfd87
UD
1097
1098move-if-change = $(SHELL) $(..)scripts/move-if-change
a641835a 1099\f
281e6031
UD
1100-include $(common-objpfx)sysd-sorted
1101subdirs = $(sorted-subdirs)
e0a3ed4f
RM
1102subdir-srcdirs = $(foreach dir,$(subdirs),\
1103 $(firstword $($(dir)-srcdir) $(..)$(dir)))
9a0a462c 1104
f3787738
RM
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).
8744841f
RM
1113%.v.i: $(common-objpfx)config.h $(..)Makeconfig
1114 sed '/^[ ]*%/!s/#.*$$//;/^[ ]*$$/d;s/^[ ]*%/#/' \
90f42071 1115 $(filter-out FORCE %.h $(..)Makeconfig,$^) \
02838201 1116 | $(CC) -E -undef $(CPPFLAGS) -x assembler-with-cpp - \
f3787738
RM
1117 > $@T
1118 mv -f $@T $@
1119%.v: %.v.i
1120 sed '/^[ ]*#/d;/^[ ]*$$/d' $< > $@T
1121 mv -f $@T $@
480d827b 1122
7e80ddb8
RM
1123ifeq (yes, $(build-shared))
1124
0ab0291b
L
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
88a4576f
JM
1131# suffice. default-abi is defined to be the ABI for the current glibc
1132# build.
0ab0291b
L
1133
1134ifndef abi-includes
1135abi-includes := bits/wordsize.h
1136endif
1137
4de1d597
RM
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.
281e6031
UD
1140# We need to wait until $(subdirs) is complete.
1141ifeq ($(sysd-sorted-done),t)
4de1d597 1142-include $(common-objpfx)soversions.mk
eca3eb3b 1143ifndef avoid-generated
f3787738 1144$(common-objpfx)shlib-versions.v.i: \
e0a3ed4f
RM
1145 $(wildcard $(+sysdep_dirs:=/shlib-versions) \
1146 $(subdir-srcdirs:=/shlib-versions)) \
9632aaee 1147 $(..)shlib-versions
6d864d15 1148
6d864d15
RM
1149$(common-objpfx)soversions.i: $(..)scripts/soversions.awk \
1150 $(common-objpfx)shlib-versions.v
af296fcd 1151 $(AWK) -f $^ > $@T
ba7e89ec 1152 mv -f $@T $@
3e1e123d 1153$(common-objpfx)soversions.mk: $(common-objpfx)soversions.i $(..)Makeconfig
0ab0291b 1154 (while read which lib number setname; do \
3e1e123d 1155 eval seen_$$which=1; \
91adb529 1156 test x"$$which" = xDEFAULT || continue; \
1bc777b8
UD
1157 case $$number in \
1158 [0-9]*) echo "$$lib.so-version=.$$number"; \
1159 echo "all-sonames+=$$lib=$$lib.so\$$($$lib.so-version)";;\
93ae1eba 1160 *) echo "$$lib.so-version=$$number"; \
1bc777b8
UD
1161 echo "all-sonames+=$$lib=\$$($$lib.so-version)";;\
1162 esac; \
1163 done; \
1164 echo soversions.mk-done = t;) < $< > $@T; exit 0
4de1d597 1165 mv -f $@T $@
eca3eb3b 1166endif
281e6031 1167endif
eca3eb3b 1168
f3787738
RM
1169postclean-generated += soversions.mk soversions.i \
1170 shlib-versions.v shlib-versions.v.i
4de1d597 1171
130ac68c 1172before-compile += $(common-objpfx)libc-modules.h
65b6d8b7 1173common-generated += libc-modules.h libc-modules.stmp
130ac68c
SP
1174ifeq ($(soversions.mk-done),t)
1175# Generate a header with macro definitions for use with the IS_IN macro.
279bc5b3 1176# These are the possible values for the MODULE_NAME macro defined when building
130ac68c
SP
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
67e58f39
SP
1188# Build the tunables list header early since it could be used by any module in
1189# glibc.
6765d5d3 1190ifneq (no,$(have-tunables))
67e58f39 1191before-compile += $(common-objpfx)dl-tunable-list.h
65b6d8b7
ZW
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 $@
67e58f39
SP
1203endif
1204
ef7c6d42
FW
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
462d348c
AS
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
088d3291
AZ
1267
1268-include $(common-objpfx)time64-compat.mk
1269postclean-generated += time64-compat.mk
1270
6b229222
SP
1271$(common-objpfx)time64-compat.mk: $(common-objpfx)time64-compat.mk.i \
1272 $(sysd-versions-force)
088d3291
AZ
1273 sed '/^[ ]*#/d;/^[ ]*$$/d' $< > $@T
1274 mv -f $@T $@
6b229222 1275$(common-objpfx)time64-compat.mk.i: $(..)Makeconfig
088d3291
AZ
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
462d348c
AS
1281endif # sysd-sorted-done
1282
d41c6f61
UD
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
1ef32c3d
UD
1294ifndef rtld-version-installed-name
1295rtld-version-installed-name = ld-$(version).so
1296endif
1297
f649c201
UD
1298endif # build-shared
1299
cbdee279 1300
6ee65ed6
UD
1301ifeq ($(build-shared),yes)
1302libm = $(common-objpfx)math/libm.so$(libm.so-version)
5695d46f 1303libmvec = $(common-objpfx)mathvec/libmvec.so$(libmvec.so-version)
6ee65ed6
UD
1304else
1305libm = $(common-objpfx)math/libm.a
5695d46f 1306libmvec = $(common-objpfx)mathvec/libmvec.a
6ee65ed6
UD
1307endif
1308
c23de0aa
FW
1309ifeq ($(build-shared),yes)
1310libsupport = $(common-objpfx)support/libsupport_nonshared.a
1311else
1312libsupport = $(common-objpfx)support/libsupport.a
1313endif
1314
354e4c1a
TMQMF
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.
8d6f1731 1318all-subdirs = csu assert ctype locale intl catgets math setjmp signal \
e0a3ed4f 1319 stdlib stdio-common libio malloc string wcsmbs time dirent \
b0b67c47 1320 grp pwd posix io termios resource misc socket sysvipc gmon \
829fea46 1321 gnulib iconv iconvdata wctype manual shadow gshadow po argp \
e69d994a 1322 localedata timezone rt conform debug mathvec support \
644d3857 1323 dlfcn elf
b22fc5f5 1324
e69d994a
ZW
1325ifeq ($(build-crypt),yes)
1326all-subdirs += crypt
1327rpath-dirs += crypt
1328endif
1329
b7e2d9a5 1330ifndef avoid-generated
7bd642f5
RM
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 \
95afbbe5 1336 $(foreach dir,$(all-subdirs),\
7bd642f5
RM
1337 $(firstword $($(dir)-srcdir) \
1338 $(..)$(dir))/Depend) \
1339 $(sorted-subdirs:=/Depend)))
e0a3ed4f
RM
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
bb41a976 1348 mv -f $@-tmp $@
9de06f3c 1349$(all-Depend-files): ;
b7e2d9a5 1350endif
bb41a976 1351
16cd816f
RM
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).
bc96fbda 1356sysd-rules-patterns := %:% rtld-%:rtld-% rtld-%:% m_%:s_%
16cd816f 1357
083973f3 1358# Let sysdeps/ subdirs contain a Makeconfig fragment for us to include here.
e0a3ed4f 1359sysdep-makeconfigs := $(wildcard $(+sysdep_dirs:=/Makeconfig))
083973f3 1360ifneq (,$(sysdep-makeconfigs))
e0a3ed4f 1361include $(sysdep-makeconfigs)
083973f3
RM
1362endif
1363
363a641b 1364# Compute just the target patterns. Makeconfig has set sysd-rules-patterns.
bc96fbda
AS
1365sysd-rules-targets := $(sort $(foreach p,$(sysd-rules-patterns),\
1366 $(firstword $(subst :, ,$p))))
083973f3 1367
ad201afe
FW
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
dbb949f5 1374libanl-routines-var = routines
ad201afe
FW
1375else
1376libpthread-routines-var = libpthread-routines
a2014d31 1377librt-routines-var = librt-routines
dbb949f5 1378libanl-routines-var = libanl-routines
ad201afe
FW
1379endif
1380
c75ccd4c
RM
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
591aeaf7
TD
1388# The name to give to a test in test results summaries.
1389test-name = $(strip $(patsubst %.out, %, $(patsubst $(common-objpfx)%, %, $@)))
1390
54ee292d
JM
1391# Likewise, in XFAIL variable names.
1392test-xfail-name = $(strip $(patsubst %.out, %, $(patsubst $(objpfx)%, %, $@)))
1393
f8c17e79 1394# Command to output a test status line (such as PASS: test-name). If
54ee292d 1395# test-xfail-$(test-xfail-name) has a nonempty value, the status will be
f8c17e79 1396# XPASS or XFAIL rather than PASS or FAIL.
591aeaf7 1397evaluate-test = $(..)scripts/evaluate-test.sh $(test-name) $$? \
54ee292d 1398 $(if $(test-xfail-$(test-xfail-name)),true,false) \
d6fe5e58 1399 $(if $(stop-on-test-failure),true,false) \
591aeaf7
TD
1400 > $(common-objpfx)$(test-name).test-result
1401
28f540f4 1402endif # Makeconfig not yet included
c238ecf7
UD
1403
1404# Local Variables:
1405# mode: makefile
1406# End: