]> git.ipfire.org Git - thirdparty/glibc.git/blame - Makeconfig
x86: HAVE_X86_LAHF_SAHF, HAVE_X86_MOVBE and -march=x86-64-vN (bug 28782)
[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
0269750c 361ifeq (yesyes,$(build-shared)$(have-z-combreloc))
f13df7c7
UD
362combreloc-LDFLAGS = -Wl,-z,combreloc
363LDFLAGS.so += $(combreloc-LDFLAGS)
364LDFLAGS-rtld += $(combreloc-LDFLAGS)
365endif
366
1c563add
UD
367relro-LDFLAGS = -Wl,-z,relro
368LDFLAGS.so += $(relro-LDFLAGS)
369LDFLAGS-rtld += $(relro-LDFLAGS)
1c563add 370
871b9158
UD
371ifeq (yes,$(have-hash-style))
372# For the time being we unconditionally use 'both'. At some time we
373# should declare statically linked code as 'out of luck' and compile
374# with --hash-style=gnu only.
375hashstyle-LDFLAGS = -Wl,--hash-style=both
376LDFLAGS.so += $(hashstyle-LDFLAGS)
377LDFLAGS-rtld += $(hashstyle-LDFLAGS)
378endif
379
23645707
SP
380ifeq (no,$(build-pie-default))
381pie-default = $(no-pie-ccflag)
382else # build-pie-default
9d7a3741
L
383pic-default = -DPIC
384# Compile libc.a and libc_p.a with -fPIE/-fpie for static PIE.
385pie-default = $(pie-ccflag)
23645707
SP
386
387ifeq (yes,$(enable-static-pie))
9d7a3741 388ifeq (yes,$(have-static-pie))
23645707 389static-pie-ldflag = -static-pie
9d7a3741
L
390else
391# Static PIE can't have dynamic relocations in read-only segments since
392# static PIE is mapped into memory by kernel. --eh-frame-hdr is needed
393# for PIE to support exception.
23645707
SP
394static-pie-ldflag = -Wl,-pie,--no-dynamic-linker,--eh-frame-hdr,-z,text
395endif # have-static-pie
396endif # enable-static-pie
397endif # build-pie-default
9d7a3741 398
2d6ab5df
FW
399# If lazy relocations are disabled, add the -z now flag. Use
400# LDFLAGS-lib.so instead of LDFLAGS.so, to avoid adding the flag to
401# test modules.
402ifeq ($(bind-now),yes)
403LDFLAGS-lib.so += -Wl,-z,now
94a4e9e4
FW
404# Extra flags for dynamically linked non-test main programs.
405link-extra-flags += -Wl,-z,now
2d6ab5df
FW
406endif
407
04f5a636
RM
408# Command to run after every final link (executable or shared object).
409# This is invoked with $(call after-link,...), so it should operate on
410# the file $1. This can be set to do some sort of post-processing on
411# binaries, or to perform some sort of static sanity check.
412ifndef after-link
413after-link =
414endif
415
c23de0aa
FW
416# Additional libraries to link into every test.
417link-extra-libs-tests = $(libsupport)
418
435aa54b
L
419# Command for linking PIE programs with the C library.
420ifndef +link-pie
f3eef963
JM
421+link-pie-before-inputs = $(if $($(@F)-no-pie),$(no-pie-ldflag),-pie) \
422 -Wl,-O1 -nostdlib -nostartfiles \
740b3dbe 423 $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
435aa54b 424 $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
34d6a3cb 425 $(firstword $(CRT-$(@F)) $(csu-objpfx)S$(start-installed-name)) \
f3eef963
JM
426 $(+preinit) $(+prectorS)
427+link-pie-before-libc = -o $@ $(+link-pie-before-inputs) \
435aa54b 428 $(filter-out $(addprefix $(csu-objpfx),start.o \
da62f81b
AS
429 S$(start-installed-name))\
430 $(+preinit) $(link-extra-libs) \
431 $(common-objpfx)libc% $(+postinit),$^) \
740b3dbe
L
432 $(link-extra-libs)
433+link-pie-after-libc = $(+postctorS) $(+postinit)
04f5a636 434define +link-pie
a8ff215e
FW
435$(CC) $(link-libc-rpath-link) $(+link-pie-before-libc) $(rtld-LDFLAGS) \
436 $(link-extra-flags) $(link-libc) $(+link-pie-after-libc)
04f5a636
RM
437$(call after-link,$@)
438endef
439define +link-pie-tests
e30fb31c
FW
440$(CC) $(+link-pie-before-libc) $(rtld-tests-LDFLAGS) $(link-libc-tests) \
441 $(+link-pie-after-libc)
04f5a636
RM
442$(call after-link,$@)
443endef
23b5cae1 444define +link-pie-printers-tests
e30fb31c
FW
445$(CC) $(+link-pie-before-libc) $(built-rtld-LDFLAGS) \
446 $(link-libc-printers-tests) $(+link-pie-after-libc)
23b5cae1
MG
447$(call after-link,$@)
448endef
435aa54b 449endif
e1586792
UD
450# Command for statically linking programs with the C library.
451ifndef +link-static
f3eef963 452+link-static-before-inputs = -nostdlib -nostartfiles -static \
23645707 453 $(if $($(@F)-no-pie),$(no-pie-ldflag),$(static-pie-ldflag)) \
9f0d7b6d 454 $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
9d7a3741 455 $(firstword $(CRT-$(@F)) $(csu-objpfx)$(real-static-start-installed-name)) \
f3eef963
JM
456 $(+preinit) $(+prectorT)
457+link-static-before-libc = -o $@ $(+link-static-before-inputs) \
e1586792
UD
458 $(filter-out $(addprefix $(csu-objpfx),start.o \
459 $(start-installed-name))\
460 $(+preinit) $(link-extra-libs-static) \
461 $(common-objpfx)libc% $(+postinit),$^) \
d173d12e 462 $(link-extra-libs-static)
a5055ad1 463+link-static-after-libc = $(+postctorT) $(+postinit)
04f5a636 464define +link-static
e30fb31c
FW
465$(CC) $(+link-static-before-libc) $(link-extra-flags) $(link-libc-static) \
466 $(+link-static-after-libc)
04f5a636
RM
467$(call after-link,$@)
468endef
469define +link-static-tests
e30fb31c
FW
470$(CC) $(+link-static-before-libc) $(link-libc-static-tests) \
471 $(+link-static-after-libc)
04f5a636
RM
472$(call after-link,$@)
473endef
e1586792 474endif
94b32c39
L
475# Commands for linking programs with the C library.
476ifndef +link
477ifeq (yes,$(build-shared))
00c714df 478ifeq (yes,$(cc-pie-default))
cc08749b 479no-pie-ldflag = -no-pie
00c714df
L
480endif
481ifeq (yes,$(build-pie-default))
cc08749b
L
482+link = $(+link-pie)
483+link-tests = $(+link-pie-tests)
f3eef963
JM
484+link-tests-before-inputs = $(+link-pie-before-inputs) $(rtld-tests-LDFLAGS)
485+link-tests-after-inputs = $(link-libc-tests) $(+link-pie-after-libc)
23b5cae1
MG
486+link-printers-tests = $(+link-pie-printers-tests)
487else # not build-pie-default
23645707 488+link-before-inputs = -nostdlib -nostartfiles $(no-pie-ldflag) \
740b3dbe 489 $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
94b32c39 490 $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
6014c65d 491 $(firstword $(CRT-$(@F)) $(csu-objpfx)$(start-installed-name)) \
f3eef963
JM
492 $(+preinit) $(+prector)
493+link-before-libc = -o $@ $(+link-before-inputs) \
94b32c39
L
494 $(filter-out $(addprefix $(csu-objpfx),start.o \
495 $(start-installed-name))\
496 $(+preinit) $(link-extra-libs) \
497 $(common-objpfx)libc% $(+postinit),$^) \
498 $(link-extra-libs)
499+link-after-libc = $(+postctor) $(+postinit)
04f5a636 500define +link
a8ff215e
FW
501$(CC) $(link-libc-rpath-link) $(+link-before-libc) $(rtld-LDFLAGS) \
502 $(link-extra-flags) $(link-libc) $(+link-after-libc)
04f5a636
RM
503$(call after-link,$@)
504endef
f3eef963
JM
505+link-tests-before-inputs = $(+link-before-inputs) $(rtld-tests-LDFLAGS)
506+link-tests-after-inputs = $(link-libc-tests) $(+link-after-libc)
04f5a636 507define +link-tests
e30fb31c 508$(CC) $(+link-before-libc) $(rtld-tests-LDFLAGS) $(link-libc-tests) \
76dcbf42 509 $(+link-after-libc)
04f5a636
RM
510$(call after-link,$@)
511endef
23b5cae1 512define +link-printers-tests
e30fb31c 513$(CC) $(+link-before-libc) $(built-rtld-LDFLAGS) $(link-libc-printers-tests) \
23b5cae1
MG
514 $(+link-after-libc)
515$(call after-link,$@)
516endef
517endif # build-pie-default
518else # build-static
94b32c39
L
519+link = $(+link-static)
520+link-tests = $(+link-static-tests)
f3eef963
JM
521+link-tests-before-inputs = $(+link-static-before-inputs)
522+link-tests-after-inputs = $(link-libc-static-tests) $(+link-static-after-libc)
23b5cae1
MG
523+link-printers-tests = $(+link-static-tests)
524endif # build-shared
525endif # +link
526
527# The pretty printer test programs need to be compiled without optimizations
528# so they won't confuse gdb. We could use either the 'GCC optimize' pragma
529# or the 'optimize' function attribute to achieve this; however, at least on
530# ARM, gcc always produces different debugging symbols when invoked with
531# a -O greater than 0 than when invoked with -O0, regardless of anything else
532# we're using to suppress optimizations. Therefore, we need to explicitly pass
533# -O0 to it through CFLAGS.
534# Additionally, the build system will try to -include $(common-objpfx)/config.h
535# when compiling the tests, which will throw an error if some special macros
536# (such as __OPTIMIZE__ and IS_IN_build) aren't defined. To avoid this, we
537# tell gcc to define IS_IN_build.
538CFLAGS-printers-tests := -O0 -ggdb3 -DIS_IN_build
539
0269750c 540ifeq (yes,$(build-shared))
23b5cae1
MG
541# These indicate whether to link using the built ld.so or the installed one.
542installed-rtld-LDFLAGS = -Wl,-dynamic-linker=$(rtlddir)/$(rtld-installed-name)
543built-rtld-LDFLAGS = -Wl,-dynamic-linker=$(elf-objpfx)ld.so
544
740b3dbe 545ifndef rtld-LDFLAGS
23b5cae1 546rtld-LDFLAGS = $(installed-rtld-LDFLAGS)
740b3dbe 547endif
23b5cae1 548
740b3dbe
L
549ifndef rtld-tests-LDFLAGS
550ifeq (yes,$(build-hardcoded-path-in-tests))
23b5cae1 551rtld-tests-LDFLAGS = $(built-rtld-LDFLAGS)
740b3dbe 552else
23b5cae1
MG
553rtld-tests-LDFLAGS = $(installed-rtld-LDFLAGS)
554endif # build-hardcoded-path-in-tests
555endif # rtld-tests-LDFLAGS
556
557endif # build-shared
558
3fe9de0d
RM
559ifndef link-libc
560ifeq (yes,$(build-shared))
aa1075ea
RM
561# We need the versioned name of libc.so in the deps of $(others) et al
562# so that the symlink to libc.so is created before anything tries to
563# run the linked programs.
23b5cae1 564link-libc-rpath = -Wl,-rpath=$(rpath-link)
740b3dbe 565link-libc-rpath-link = -Wl,-rpath-link=$(rpath-link)
23b5cae1 566
a8ff215e
FW
567# For programs which are not tests, $(link-libc-rpath-link) is added
568# directly in $(+link), $(+link-pie) above, so that -Wl,-rpath-link
569# comes before the expansion of LDLIBS-* and affects libraries added
570# there. For shared objects, -Wl,-rpath-link is added via
571# $(build-shlib-helper) and $(build-module-helper) in Makerules (also
572# before the expansion of LDLIBS-* variables).
573
574# Tests use -Wl,-rpath instead of -Wl,-rpath-link for
575# build-hardcoded-path-in-tests.
740b3dbe 576ifeq (yes,$(build-hardcoded-path-in-tests))
23b5cae1 577link-libc-tests-rpath-link = $(link-libc-rpath)
740b3dbe
L
578else
579link-libc-tests-rpath-link = $(link-libc-rpath-link)
23b5cae1
MG
580endif # build-hardcoded-path-in-tests
581
3618e5fe
PM
582link-libc-between-gnulib = $(common-objpfx)libc.so$(libc.so-version) \
583 $(common-objpfx)$(patsubst %,$(libtype.oS),c) \
584 -Wl,--as-needed $(elf-objpfx)ld.so \
585 -Wl,--no-as-needed
586link-libc = $(link-libc-between-gnulib) $(gnulib)
23b5cae1 587
3618e5fe 588link-libc-tests-after-rpath-link = $(gnulib-tests) $(link-libc-between-gnulib) $(gnulib-tests)
740b3dbe 589link-libc-tests = $(link-libc-tests-rpath-link) \
23b5cae1
MG
590 $(link-libc-tests-after-rpath-link)
591# Pretty printer test programs always require rpath instead of rpath-link.
592link-libc-printers-tests = $(link-libc-rpath) \
593 $(link-libc-tests-after-rpath-link)
594
4d6acc61 595# This is how to find at build-time things that will be installed there.
e69d994a 596rpath-dirs = math elf dlfcn nss nis rt resolv mathvec support
e72bfd87
UD
597rpath-link = \
598$(common-objdir):$(subst $(empty) ,:,$(patsubst ../$(subdir),.,$(rpath-dirs:%=$(common-objpfx)%)))
23b5cae1 599else # build-static
4ac5087b 600link-libc = $(common-objpfx)libc.a $(otherlibs) $(gnulib) $(common-objpfx)libc.a $(gnulib)
95f5a9a8 601link-libc-tests = $(common-objpfx)libc.a $(otherlibs) $(gnulib-tests) $(common-objpfx)libc.a $(gnulib-tests)
23b5cae1
MG
602endif # build-shared
603endif # link-libc
900bec85 604
ad10cac8 605# Differences in the linkers on the various platforms.
ad10cac8
UD
606LDFLAGS-rpath-ORIGIN = -Wl,-rpath,'$$ORIGIN'
607LDFLAGS-soname-fname = -Wl,-soname,$(@F)
608LDFLAGS-rdynamic = -rdynamic
609LDFLAGS-Bsymbolic = -Bsymbolic
ad10cac8 610
f01010de
UD
611# Choose the default search path for the dynamic linker based on
612# where we will install libraries.
613ifneq ($(libdir),$(slibdir))
614default-rpath = $(slibdir):$(libdir)
615else
616default-rpath = $(libdir)
617endif
618
57ba7bb4 619ifndef link-extra-libs
1d038b6b
RM
620link-extra-libs = $(LDLIBS-$(@F))
621link-extra-libs-static = $(link-extra-libs)
57ba7bb4 622endif
e1586792
UD
623
624# The static libraries.
b9af1301 625link-libc-static = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib) -Wl,--end-group
95f5a9a8 626link-libc-static-tests = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib-tests) -Wl,--end-group
e1586792 627
95f5a9a8
JM
628# How to link against libgcc. Some libgcc functions, such as those
629# for "long long" arithmetic or software floating point, can always be
630# built without use of C library headers and do not have any global
631# state so can safely be linked statically into any executable or
632# shared library requiring them; these functions are in libgcc.a.
633# Other functions, relating to exception handling, may require C
634# library headers to build and it may not be safe to have more than
635# one copy of them in a process; these functions are only in
636# libgcc_s.so and libgcc_eh.a.
637#
638# To avoid circular dependencies when bootstrapping, it is desirable
639# to avoid use of libgcc_s and libgcc_eh in building glibc. Where any
640# glibc functionality (in particular, thread cancellation) requires
641# exception handling, this is implemented through dlopen of libgcc_s
642# to avoid unnecessary dependencies on libgcc_s by programs not using
643# that functionality; executables built with glibc do not use
644# exception handling other than through thread cancellation.
645#
646# Undefined references to functions from libgcc_eh or libgcc_s may
647# arise for code built with -fexceptions. In the case of statically
648# linked programs installed by glibc, unwinding will never actually
649# occur at runtime and the use of elf/static-stubs.c to resolve these
650# references is safe. In the case of statically linked test programs
651# and test programs built with -fexceptions, unwinding may occur in
652# some cases and it is preferable to link with libgcc_eh or libgcc_s
653# so that the testing is as similar as possible to how programs will
654# be built with the installed glibc.
655#
656# Some architectures have architecture-specific systems for exception
657# handling that may involve undefined references to
658# architecture-specific functions. On those architectures,
659# gnulib-arch and static-gnulib-arch may be defined in sysdeps
660# makefiles to use additional libraries for linking executables and
661# shared libraries built by glibc.
28f540f4 662ifndef gnulib
cbdb12de
UD
663ifneq ($(have-cc-with-libunwind),yes)
664 libunwind =
feca5e0b 665else
cbdb12de 666 libunwind = -lunwind
feca5e0b 667endif
a3cc4f48 668libgcc_eh := -Wl,--as-needed -lgcc_s $(libunwind) -Wl,--no-as-needed
95f5a9a8
JM
669gnulib-arch =
670gnulib = -lgcc $(gnulib-arch)
671gnulib-tests := -lgcc $(libgcc_eh)
672static-gnulib-arch =
94b32c39
L
673# By default, elf/static-stubs.o, instead of -lgcc_eh, is used to
674# statically link programs. When --disable-shared is used, we use
675# -lgcc_eh since elf/static-stubs.o isn't sufficient.
676ifeq (yes,$(build-shared))
95f5a9a8 677static-gnulib = -lgcc $(static-gnulib-arch)
94b32c39
L
678else
679static-gnulib = -lgcc -lgcc_eh $(static-gnulib-arch)
680endif
95f5a9a8 681static-gnulib-tests := -lgcc -lgcc_eh $(libunwind)
cbdb12de 682libc.so-gnulib := -lgcc
28f540f4 683endif
e75154a6
RM
684+preinit = $(addprefix $(csu-objpfx),crti.o)
685+postinit = $(addprefix $(csu-objpfx),crtn.o)
35e65999
RA
686+prector = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbegin.o`
687+postctor = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
435aa54b 688# Variants of the two previous definitions for linking PIE programs.
35e65999
RA
689+prectorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginS.o`
690+postctorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtendS.o`
a5055ad1 691# Variants of the two previous definitions for statically linking programs.
9d7a3741
L
692ifeq (yes,$(enable-static-pie))
693# Static PIE must use PIE variants.
694+prectorT = $(+prectorS)
695+postctorT = $(+postctorS)
696else
a5055ad1 697+prectorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginT.o`
189e935b 698+postctorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
9d7a3741 699endif
6e953631
UD
700csu-objpfx = $(common-objpfx)csu/
701elf-objpfx = $(common-objpfx)elf/
28f540f4 702
cc1290d0
JM
703# A command that, prepended to the name and arguments of a program,
704# and run on the build system, causes that program with those
705# arguments to be run on the host for which the library is built.
706ifndef test-wrapper
707test-wrapper =
708endif
709# Likewise, but the name of the program is preceded by
710# <variable>=<value> assignments for environment variables.
711ifndef test-wrapper-env
712test-wrapper-env = $(test-wrapper) env
713endif
9162c01d
RM
714# Likewise, but the program's environment will be empty except for any
715# explicit <variable>=<value> assignments preceding the program name.
716ifndef test-wrapper-env-only
717test-wrapper-env-only = $(test-wrapper) env -i
718endif
cc1290d0 719
03ac099f
JM
720# Whether to run test programs built for the library's host system.
721ifndef run-built-tests
cc1290d0 722ifeq (yes|,$(cross-compiling)|$(test-wrapper))
03ac099f
JM
723run-built-tests = no
724else
725run-built-tests = yes
726endif
727endif
728
d6fe5e58
JM
729# Whether to stop immediately when a test fails. Nonempty means to
730# stop, empty means not to stop.
731ifndef stop-on-test-failure
732stop-on-test-failure =
733endif
734
03a75825
RM
735# How to run a program we just linked with our library.
736# The program binary is assumed to be $(word 2,$^).
737built-program-file = $(dir $(word 2,$^))$(notdir $(word 2,$^))
01dc6df9
SP
738rtld-prefix = $(elf-objpfx)$(rtld-installed-name) \
739 --library-path \
740 $(rpath-link)$(patsubst %,:%,$(sysdep-library-path))
0269750c 741ifeq (yes,$(build-shared))
196980f5 742comma = ,
11336c16
UD
743sysdep-library-path = \
744$(subst $(empty) ,:,$(strip $(patsubst -Wl$(comma)-rpath-link=%, %,\
745 $(filter -Wl$(comma)-rpath-link=%,\
746 $(sysdep-LDFLAGS)))))
88866099
JM
747# $(run-via-rtld-prefix) is a command that, when prepended to the name
748# of a program built with the newly built library, produces a command
749# that, executed on the host for which the library is built, runs that
daaa7713
JM
750# program. For tests listed in tests-static or xtests-static, it is
751# empty.
88866099
JM
752run-via-rtld-prefix = \
753 $(if $(strip $(filter $(notdir $(built-program-file)), \
01dc6df9 754 $(tests-static) $(xtests-static))),, $(rtld-prefix))
8658ceda 755else
88866099
JM
756run-via-rtld-prefix =
757endif
8540f6d2
JM
758# $(run-program-env) is the default environment variable settings to
759# use when running a program built with the newly built library.
760run-program-env = GCONV_PATH=$(common-objpfx)iconvdata \
761 LOCPATH=$(common-objpfx)localedata LC_ALL=C
25fe8932 762# $(run-program-prefix) is a command that, when prepended to the name
88866099
JM
763# of a program built with the newly built library, produces a command
764# that, executed on the build system on which "make" is run, runs that
8540f6d2
JM
765# program. $(run-program-prefix-before-env) and
766# $(run-program-prefix-after-env) are similar, but separate parts
767# before and after a list of environment variables.
768run-program-prefix-before-env = $(test-wrapper-env)
769run-program-prefix-after-env = $(run-via-rtld-prefix)
770run-program-prefix = $(run-program-prefix-before-env) $(run-program-env) \
771 $(run-program-prefix-after-env)
88866099
JM
772# $(built-program-cmd) is a command that, executed on the build system
773# on which "make" is run, runs the newly built program that is the
774# second dependency of the makefile target in which
8540f6d2
JM
775# $(built-program-cmd) is used. $(built-program-cmd-before-env) and
776# $(built-program-cmd-after-env) are similar, before and after a list
777# of environment variables.
778built-program-cmd-before-env = $(test-wrapper-env)
779built-program-cmd-after-env = $(run-via-rtld-prefix) $(built-program-file)
780built-program-cmd = $(built-program-cmd-before-env) $(run-program-env) \
781 $(built-program-cmd-after-env)
166bca24
JB
782# $(host-built-program-cmd) is a command that, executed on the host
783# for which the library is built, runs the newly built program that is
784# the second dependency of the makefile target in which
785# $(host-built-program-cmd) is used.
786host-built-program-cmd = $(run-via-rtld-prefix) $(built-program-file)
3dbbd2ff
ST
787# $(ld-library-path) is the common content to be set in LD_LIBRARY_PATH
788# for running static binaries that may load dynamic objects.
789ld-library-path = $(objpfx):$(common-objpfx)$(addprefix :,$(sysdep-ld-library-path))
03a75825 790
28f540f4
RM
791ifndef LD
792LD := ld -X
793endif
794
740b3dbe
L
795# $(test-via-rtld-prefix) is a command that, when prepended to the name
796# of a test program built with the newly built library, produces a command
797# that, executed on the host for which the library is built, runs that
daaa7713
JM
798# program. For tests listed in tests-static or xtests-static as well
799# as when test programs are hardcoded to the newly built libraries, it
800# is empty.
740b3dbe
L
801
802# $(test-program-prefix) is a command that, when prepended to the name
803# of a test program built with the newly built library, produces a command
804# that, executed on the build system on which "make" is run, runs that
8540f6d2
JM
805# test program. $(test-program-prefix-before-env) and
806# $(test-program-prefix-after-env) are similar, before and after a
807# list of environment variables.
740b3dbe
L
808
809# $(test-program-cmd) is a command that, executed on the build system
810# on which "make" is run, runs the newly built test program that is the
811# second dependency of the makefile target in which
8540f6d2
JM
812# $(test-program-cmd) is used. $(test-program-cmd-before-env) and
813# $(test-program-cmd-after-env) are similar, before and after a list
814# of environment variables.
740b3dbe
L
815
816# $(host-test-program-cmd) is a command that, executed on the host
817# for which the library is built, runs the newly built test program that
818# is the second dependency of the makefile target in which
819# $(host-test-program-cmd) is used.
820
821ifeq (yes,$(build-hardcoded-path-in-tests))
822test-via-rtld-prefix =
8540f6d2
JM
823test-program-prefix-before-env = $(test-wrapper-env)
824test-program-prefix-after-env =
825test-program-prefix = $(test-program-prefix-before-env) $(run-program-env) \
826 $(test-program-prefix-after-env)
827test-program-cmd-before-env = $(test-wrapper-env)
828test-program-cmd-after-env = $(built-program-file)
829test-program-cmd = $(test-program-cmd-before-env) $(run-program-env) \
830 $(test-program-cmd-after-env)
740b3dbe
L
831host-test-program-cmd = $(built-program-file)
832else
833test-via-rtld-prefix = $(run-via-rtld-prefix)
8540f6d2
JM
834test-program-prefix-before-env = $(run-program-prefix-before-env)
835test-program-prefix-after-env = $(run-program-prefix-after-env)
740b3dbe 836test-program-prefix = $(run-program-prefix)
8540f6d2
JM
837test-program-cmd-before-env = $(built-program-cmd-before-env)
838test-program-cmd-after-env = $(built-program-cmd-after-env)
740b3dbe
L
839test-program-cmd = $(built-program-cmd)
840host-test-program-cmd = $(host-built-program-cmd)
841endif
842
28f540f4 843# Extra flags to pass to GCC.
6cc7d725 844ifeq ($(all-warnings),yes)
ed159672 845+gccwarn := -Wall -Wwrite-strings -Wcast-qual -Wbad-function-cast -Wmissing-noreturn -Wmissing-prototypes -Wmissing-declarations -Wcomment -Wcomments -Wtrigraphs -Wsign-compare -Wfloat-equal -Wmultichar
6cc7d725 846else
ed159672 847+gccwarn := -Wall -Wwrite-strings
6cc7d725 848endif
498a2233 849+gccwarn += -Wundef
a4ecc9eb 850ifeq ($(enable-werror),yes)
48bb14bd 851+gccwarn += -Werror
a4ecc9eb 852endif
8e2f7c68 853+gccwarn-c = -Wstrict-prototypes -Wold-style-definition
28f540f4 854
dec36b4f
UD
855# We do not depend on the address of constants in different files to be
856# actually different, so allow the compiler to merge them all.
857+merge-constants = -fmerge-all-constants
858
29ba805c
AJ
859# We have to assume that glibc functions are called in any rounding
860# mode and also change the rounding mode in a few functions. So,
861# disable any optimization that assume default rounding mode.
862+math-flags = -frounding-math
863
2ef42716
AJ
864# Logically only "libnldbl", "nonlib" and "testsuite" should be using
865# -fno-math-errno. However due to GCC bug #88576, only "libm" can use
866# -fno-math-errno.
867+extra-math-flags = $(if $(filter libm,$(in-module)),-fno-math-errno,-fmath-errno)
1294b189 868
a6d2f948 869# Use 64 bit time_t support for installed programs
f0ed50e1 870installed-modules = nonlib nscd lddlibc4 ldconfig locale_programs \
a6d2f948
AZ
871 iconvprogs libnss_files libnss_compat libnss_db libnss_hesiod \
872 libutil libpcprofile libSegFault
873+extra-time-flags = $(if $(filter $(installed-modules),\
874 $(in-module)),-D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64)
875
cecbc796
NA
876# We might want to compile with some stack-protection flag.
877ifneq ($(stack-protector),)
878+stack-protector=$(stack-protector)
879endif
880
8b8f13b6
SP
881# Some routines are unsafe to build with stack-protection since they're called
882# before the stack check guard is set up. Provide a way to disable stack
883# protector. The first argument is the extension (.o, .os, .oS) and the second
884# is a list of routines that this path should be applied to.
885define elide-stack-protector
886$(if $(filter $(@F),$(patsubst %,%$(1),$(2))), $(no-stack-protector))
887endef
888
28f540f4 889# The program that makes Emacs-style TAGS files.
78759725 890ETAGS := etags
28f540f4 891
9de06f3c
RM
892# The `xgettext' program for producing .pot files from sources.
893ifndef XGETTEXT
894XGETTEXT = xgettext
895endif
896
28f540f4
RM
897# The `m4' macro processor; this is used by sysdeps/sparc/Makefile (and
898# perhaps others) to preprocess assembly code in some cases.
899M4 = m4
900
73237de3
UD
901# To force installation of files even if they are older than the
902# installed files. This variable is included in the dependency list
903# of all installation targets.
904ifeq ($(force-install),yes)
905+force = force-install
906else
907+force =
908endif
909
28f540f4
RM
910####
911#### End of configuration variables.
912####
913\f
914# This tells some versions of GNU make before 3.63 not to export all variables.
915.NOEXPORT:
916
917# We want to echo the commands we're running without
6d52618b 918# umpteen zillion filenames along with it (we use `...' instead)
28f540f4
RM
919# but we don't want this echoing done when the user has said
920# he doesn't want to see commands echoed by using -s.
921ifneq "$(findstring s,$(MAKEFLAGS))" "" # if -s
922+cmdecho := echo >/dev/null
923else # not -s
924+cmdecho := echo
925endif # -s
926
927# These are the flags given to the compiler to tell
928# it what sort of optimization and/or debugging output to do.
929ifndef +cflags
930# If `CFLAGS' was defined, use that.
931ifdef CFLAGS
932+cflags := $(filter-out -I%,$(CFLAGS))
933endif # CFLAGS
934endif # +cflags
935
fd26970f 936# If none of the above worked, default to "-g -O".
28f540f4
RM
937ifeq "$(strip $(+cflags))" ""
938+cflags := $(default_cflags)
939endif # $(+cflags) == ""
940
7c241325
FW
941# Force building with -fno-common because hidden_def, compat_symbol
942# and other constructs do not work for common symbols (and would
943# otherwise require specifying __attribute__ ((nocommon)) on a
944# case-by-case basis).
cecbc796 945+cflags += $(cflags-cpu) $(+gccwarn) $(+merge-constants) $(+math-flags) \
7c241325 946 $(+stack-protector) -fno-common
28f540f4 947+gcc-nowarn := -w
28f540f4 948
b84660a8
RM
949# Each sysdeps directory can contain header files that both will be
950# used to compile and will be installed. Each can also contain an
951# include/ subdirectory, whose header files will be used to compile
952# but will not be installed, and will take precedence over the
953# installed files. This mirrors the top-level include/ subdirectory.
954+sysdep-includes := $(foreach dir,$(+sysdep_dirs),\
955 $(addprefix -I,$(wildcard $(dir)/include) $(dir)))
956
b6ab06ce
UD
957# These are flags given to the C compiler to tell it to look for
958# include files (including ones given in angle brackets) in the parent
959# library source directory, in the include directory, and in the
960# current directory.
e0a3ed4f 961+includes = -I$(..)include $(if $(subdir),$(objpfx:%/=-I%)) \
4ae73ca0
RM
962 $(+sysdep-includes) $(includes) \
963 $(patsubst %/,-I%,$(..)) $(libio-include) -I. $(sysincludes)
28f540f4 964
96aa2d94 965# Since libio has several internal header files, we use a -I instead
762a2918 966# of many little headers in the include directory.
96aa2d94 967libio-include = -I$(..)libio
28f540f4 968
130ac68c
SP
969# List of non-library modules that we build.
970built-modules = iconvprogs iconvdata ldconfig lddlibc4 libmemusage \
971 libSegFault libpcprofile librpcsvc locale-programs \
7c3018f9 972 memusagestat nonlib nscd extramodules libnldbl libsupport \
a6d2f948 973 testsuite testsuite-internal
130ac68c 974
9cd47470
SP
975in-module = $(subst -,_,$(firstword $(libof-$(basename $(@F))) \
976 $(libof-$(<F)) \
977 $(libof-$(@F)) \
978 libc))
979
e400f3cc
SP
980# Build ld.so, libc.so and libpthread.so with -ftls-model=initial-exec
981tls-model = $(if $(filter libpthread rtld \
982 libc,$(in-module)),-ftls-model=initial-exec,)
983
130ac68c 984module-cppflags-real = -include $(common-objpfx)libc-modules.h \
279bc5b3 985 -DMODULE_NAME=$(in-module)
130ac68c 986
8a257e2c
RM
987# We don't need libc-modules.h and the MODULE_NAME definition for .v.i
988# files. These targets don't (and will likely never need to) use the IS_IN
989# facility. In fact, shlib-versions should not use it because that will
990# create a circular dependency as libc-modules.h is generated from
991# shlib-versions.
6b229222 992module-cppflags = $(if $(filter %.mk.i %.v.i,$(@F)),,$(module-cppflags-real))
130ac68c 993
28f540f4 994# These are the variables that the implicit compilation rules use.
ce460d04
RM
995# Note that we can't use -std=* in CPPFLAGS, because it overrides
996# the implicit -lang-asm and breaks cpp behavior for .S files--notably
997# it causes cpp to stop predefining __ASSEMBLER__.
7ffa9423
AZ
998CPPFLAGS = $(config-extra-cppflags) $(CPPUNDEFS) $(CPPFLAGS-config) \
999 $($(subdir)-CPPFLAGS) \
130ac68c 1000 $(+includes) $(defines) $(module-cppflags) \
ae8b36f7 1001 -include $(..)include/libc-symbols.h $(sysdep-CPPFLAGS) \
130ac68c 1002 $(CPPFLAGS-$(suffix $@)) \
d29724f8 1003 $(foreach lib,$(libof-$(basename $(@F))) \
bc96fbda 1004 $(libof-$(<F)) $(libof-$(@F)),$(CPPFLAGS-$(lib))) \
0a951d0e 1005 $(CPPFLAGS-$(<F)) $(CPPFLAGS-$(@F)) $(CPPFLAGS-$(basename $(@F)))
67e58f39 1006
6765d5d3 1007ifneq (no,$(have-tunables))
67e58f39
SP
1008CPPFLAGS += -DTOP_NAMESPACE=glibc
1009endif
1010
783dd2d3 1011override CFLAGS = -std=gnu11 -fgnu89-inline $(config-extra-cflags) \
7735afa2 1012 $(filter-out %frame-pointer,$(+cflags)) $(+gccwarn-c) \
a6d2f948 1013 $(+extra-math-flags) $(+extra-time-flags) \
7735afa2 1014 $(sysdep-CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) \
e400f3cc 1015 $(CFLAGS-$(@F)) $(tls-model) \
44f0a71e
UD
1016 $(foreach lib,$(libof-$(basename $(@F))) \
1017 $(libof-$(<F)) $(libof-$(@F)),$(CFLAGS-$(lib)))
83212868
L
1018# Use our copies of cstdlib and cmath.
1019override CXXFLAGS = -I$(common-objpfx) $(c++-sysincludes) \
ef226fec 1020 $(filter-out %frame-pointer,$(+cflags)) $(sysdep-CFLAGS) \
7735afa2 1021 $(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) $(CFLAGS-$(@F))
28f540f4 1022
cc3fa755
UD
1023# If everything is compiled with -fPIC (implicitly) we must tell this by
1024# defining the PIC symbol.
1025ifeq (yes,$(build-pic-default))
1026pic-default = -DPIC
1027endif
1028
f0bf9cb9
RM
1029# Enable object files for different versions of the library.
1030# Various things use $(object-suffixes) to know what all to make.
1031# The compilation rules use $(CPPFLAGS-${SUFFIX}) and $(CFLAGS-${SUFFIX})
1032# to pass different flags for each flavor.
91641c65 1033libtypes = $(foreach o,$(object-suffixes-for-libc),$(libtype$o))
612148c6
FW
1034# .op may be added to all-object-suffixes below.
1035all-object-suffixes := .o .os .oS
650425ce 1036object-suffixes :=
cc3fa755 1037CPPFLAGS-.o = $(pic-default)
9d7a3741
L
1038# libc.a must be compiled with -fPIE/-fpie for static PIE.
1039CFLAGS-.o = $(filter %frame-pointer,$(+cflags)) $(pie-default)
f0bf9cb9 1040libtype.o := lib%.a
650425ce 1041object-suffixes += .o
f0bf9cb9
RM
1042ifeq (yes,$(build-shared))
1043# Under --enable-shared, we will build a shared library of PIC objects.
40a55d20
UD
1044# The PIC object files are named foo.os.
1045object-suffixes += .os
b5567b2a 1046CPPFLAGS-.os = -DPIC -DSHARED
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
462d348c
AS
1205# Generate version maps, but wait until sysdep-subdirs is known
1206ifeq ($(sysd-sorted-done),t)
1207ifeq ($(build-shared),yes)
1208-include $(common-objpfx)sysd-versions
1209-include $(common-objpfx)Versions.mk
1210$(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
1211common-generated += $(version-maps)
1212postclean-generated += sysd-versions Versions.all abi-versions.h \
1213 Versions.def Versions.v.i Versions.v Versions.mk
1214
1215ifndef avoid-generated
1216ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
1217sysd-versions-force = FORCE
1218FORCE:
1219endif
1220
1221$(common-objpfx)Versions.def: $(..)scripts/versionlist.awk \
1222 $(common-objpfx)Versions.v
1223 LC_ALL=C $(AWK) -f $^ > $@T
1224 mv -f $@T $@
1225
1226$(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
1227 $(common-objpfx)soversions.i \
1228 $(common-objpfx)Versions.def
1229 { while read which lib version setname; do \
1230 test x"$$which" = xDEFAULT || continue; \
1231 test -z "$$setname" || echo "$$lib : $$setname"; \
1232 done < $(word 2,$^); \
1233 cat $(word 3,$^); \
1234 } | LC_ALL=C $(AWK) -f $< > $@T
1235 mv -f $@T $@
1236$(common-objpfx)Versions.mk: $(..)scripts/haveversions.awk \
1237 $(common-objpfx)Versions.all
1238 $(AWK) -f $^ > $@T
1239 mv -f $@T $@
1240# See %.v/%.v.i implicit rules in Makeconfig.
1241$(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
1242 $(wildcard $(sysdirs:%=%/Versions)) \
1243 $(sysd-versions-force)
1244$(common-objpfx)sysd-versions: $(common-objpfx)versions.stmp
1245$(common-objpfx)versions.stmp: $(common-objpfx)Versions.all \
1246 $(common-objpfx)Versions.v \
1247 $(..)scripts/versions.awk
1248 ( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
1249 cat $(word 2,$^) \
1250 | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
1251 -v move_if_change='$(move-if-change)' \
1252 -f $(word 3,$^); \
1253 ) > $(common-objpfx)sysd-versionsT
1254 mv -f $(common-objpfx)sysd-versionsT $(common-objpfx)sysd-versions
1255 touch $@
1256endif # avoid-generated
1257endif # $(build-shared) = yes
088d3291
AZ
1258
1259-include $(common-objpfx)time64-compat.mk
1260postclean-generated += time64-compat.mk
1261
6b229222
SP
1262$(common-objpfx)time64-compat.mk: $(common-objpfx)time64-compat.mk.i \
1263 $(sysd-versions-force)
088d3291
AZ
1264 sed '/^[ ]*#/d;/^[ ]*$$/d' $< > $@T
1265 mv -f $@T $@
6b229222 1266$(common-objpfx)time64-compat.mk.i: $(..)Makeconfig
088d3291
AZ
1267 printf "#include <time64-compat.h>\n#ifdef TIME64_NON_DEFAULT\nhave-time64-compat = yes\n#endif" \
1268 | $(CC) -E -undef $(CPPFLAGS) -x assembler-with-cpp - > $@T
1269 mv -f $@T $@
1270
1271
462d348c
AS
1272endif # sysd-sorted-done
1273
d41c6f61
UD
1274# The name under which the run-time dynamic linker is installed.
1275# We are currently going for the convention that `/lib/ld.so.1'
1276# names the SVR4/ELF ABI-compliant dynamic linker.
1277ifndef rtld-installed-name
1278ifdef ld.so-version
1279rtld-installed-name = $(ld.so-version)
1280else
1281rtld-installed-name = ld.so.1
1282endif
1283endif
1284
1ef32c3d
UD
1285ifndef rtld-version-installed-name
1286rtld-version-installed-name = ld-$(version).so
1287endif
1288
f649c201
UD
1289endif # build-shared
1290
cbdee279 1291
6ee65ed6
UD
1292ifeq ($(build-shared),yes)
1293libm = $(common-objpfx)math/libm.so$(libm.so-version)
5695d46f 1294libmvec = $(common-objpfx)mathvec/libmvec.so$(libmvec.so-version)
6ee65ed6
UD
1295else
1296libm = $(common-objpfx)math/libm.a
5695d46f 1297libmvec = $(common-objpfx)mathvec/libmvec.a
6ee65ed6
UD
1298endif
1299
c23de0aa
FW
1300ifeq ($(build-shared),yes)
1301libsupport = $(common-objpfx)support/libsupport_nonshared.a
1302else
1303libsupport = $(common-objpfx)support/libsupport.a
1304endif
1305
354e4c1a
TMQMF
1306# This is a partial list of subdirectories containing the library source.
1307# The order is more or less arbitrary. The sorting step will take care of the
1308# dependencies and generate sorted-subdirs dynamically.
8d6f1731 1309all-subdirs = csu assert ctype locale intl catgets math setjmp signal \
e0a3ed4f 1310 stdlib stdio-common libio malloc string wcsmbs time dirent \
b0b67c47 1311 grp pwd posix io termios resource misc socket sysvipc gmon \
829fea46 1312 gnulib iconv iconvdata wctype manual shadow gshadow po argp \
e69d994a 1313 localedata timezone rt conform debug mathvec support \
644d3857 1314 dlfcn elf
b22fc5f5 1315
e69d994a
ZW
1316ifeq ($(build-crypt),yes)
1317all-subdirs += crypt
1318rpath-dirs += crypt
1319endif
1320
b7e2d9a5 1321ifndef avoid-generated
7bd642f5
RM
1322# sysd-sorted itself will contain rules making the sysd-sorted target
1323# depend on Depend files. But if you just added a Depend file to an
1324# existing directory not in all-subdirs, then sysd-sorted needs to
1325# be regenerated, so it depends on existing $(sorted-subdirs:=/Depend) files.
1326all-Depend-files := $(wildcard $(sort \
95afbbe5 1327 $(foreach dir,$(all-subdirs),\
7bd642f5
RM
1328 $(firstword $($(dir)-srcdir) \
1329 $(..)$(dir))/Depend) \
1330 $(sorted-subdirs:=/Depend)))
e0a3ed4f
RM
1331$(common-objpfx)sysd-sorted: $(..)scripts/gen-sorted.awk \
1332 $(common-objpfx)config.make $(..)Makeconfig \
1333 $(wildcard $(sysdirs:=/Subdirs)) \
1334 $(all-Depend-files)
1335 $(AWK) -f $< \
1336 -v subdirs='$(all-subdirs)' \
1337 -v srcpfx='$(..)' \
1338 $(filter %/Subdirs %/Depend,$^) > $@-tmp
bb41a976 1339 mv -f $@-tmp $@
9de06f3c 1340$(all-Depend-files): ;
b7e2d9a5 1341endif
bb41a976 1342
16cd816f
RM
1343# This gives partial TARGET:SOURCE pattern pairs to have rules
1344# emitted into sysd-rules. A sysdeps Makeconfig fragment can
1345# add its own special object file prefix to this list with e.g. foo-%:%
1346# to have foo-*.? compiled from *.? using $(foo-CPPFLAGS).
bc96fbda 1347sysd-rules-patterns := %:% rtld-%:rtld-% rtld-%:% m_%:s_%
16cd816f 1348
083973f3 1349# Let sysdeps/ subdirs contain a Makeconfig fragment for us to include here.
e0a3ed4f 1350sysdep-makeconfigs := $(wildcard $(+sysdep_dirs:=/Makeconfig))
083973f3 1351ifneq (,$(sysdep-makeconfigs))
e0a3ed4f 1352include $(sysdep-makeconfigs)
083973f3
RM
1353endif
1354
363a641b 1355# Compute just the target patterns. Makeconfig has set sysd-rules-patterns.
bc96fbda
AS
1356sysd-rules-targets := $(sort $(foreach p,$(sysd-rules-patterns),\
1357 $(firstword $(subst :, ,$p))))
083973f3 1358
ad201afe
FW
1359# $(libpthread-routines-var) and $(librt-routines-var) are the make
1360# variable to which pthread routines need to be added to land in the
1361# right library.
1362ifeq ($(pthread-in-libc),yes)
1363libpthread-routines-var = routines
1364librt-routines-var = routines
dbb949f5 1365libanl-routines-var = routines
ad201afe
FW
1366else
1367libpthread-routines-var = libpthread-routines
a2014d31 1368librt-routines-var = librt-routines
dbb949f5 1369libanl-routines-var = libanl-routines
ad201afe
FW
1370endif
1371
c75ccd4c
RM
1372# A sysdeps Makeconfig fragment may set libc-reentrant to yes.
1373ifeq (yes,$(libc-reentrant))
1374defines += -D_LIBC_REENTRANT
1375
1376libio-mtsafe = -D_IO_MTSAFE_IO
1377endif
1378
591aeaf7
TD
1379# The name to give to a test in test results summaries.
1380test-name = $(strip $(patsubst %.out, %, $(patsubst $(common-objpfx)%, %, $@)))
1381
54ee292d
JM
1382# Likewise, in XFAIL variable names.
1383test-xfail-name = $(strip $(patsubst %.out, %, $(patsubst $(objpfx)%, %, $@)))
1384
f8c17e79 1385# Command to output a test status line (such as PASS: test-name). If
54ee292d 1386# test-xfail-$(test-xfail-name) has a nonempty value, the status will be
f8c17e79 1387# XPASS or XFAIL rather than PASS or FAIL.
591aeaf7 1388evaluate-test = $(..)scripts/evaluate-test.sh $(test-name) $$? \
54ee292d 1389 $(if $(test-xfail-$(test-xfail-name)),true,false) \
d6fe5e58 1390 $(if $(stop-on-test-failure),true,false) \
591aeaf7
TD
1391 > $(common-objpfx)$(test-name).test-result
1392
28f540f4 1393endif # Makeconfig not yet included
c238ecf7
UD
1394
1395# Local Variables:
1396# mode: makefile
1397# End: