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