aboutsummaryrefslogtreecommitdiff
path: root/Makeconfig
blob: 8d4f7b4404bfba88d4c5e8631e913911420f5a68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
# Copyright (C) 1991-2003,2004,2005,2006,2007,2008,2009,2010,2011,2012
#	Free Software Foundation, Inc.
# This file is part of the GNU C Library.

# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.

# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with the GNU C Library; if not, see
# <http://www.gnu.org/licenses/>.

#
#	Makefile configuration options for the GNU C library.
#
ifneq (,)
This makefile requires GNU Make.
endif

all: # Make this the default goal

ifneq "$(origin +included-Makeconfig)" "file"

+included-Makeconfig := yes

ifdef subdir
.. := ../
endif

# If config.make exists, the source directory was configured,
# so don't try to be clever and find another directory to build in.
ifneq (,$(wildcard $(..)config.make))
ARCH =
machine =
else	# Not configured.
ifndef ARCH
ifdef machine
ARCH = $(machine)
endif # machine
endif # ARCH
endif # config.make

# Directory for object files and libc.a.  If this is not defined, the
# object files live in the subdirectories where their sources live, and
# libc.a lives in the parent directory (this probably doesn't work any
# more).
ifdef ARCH
ifeq ($(filter /%,$(ARCH)),)
objdir := $(..)$(ARCH)
else
objdir = $(ARCH)
endif
endif

# $(common-objdir) is the place to put objects and
# such that are not specific to a single subdir.
ifdef objdir
objpfx := $(patsubst %//,%/,$(objdir)/$(subdir)/)
common-objpfx = $(objdir)/
common-objdir = $(objdir)
else
objpfx :=
ifdef ..
common-objpfx = $(..)
common-objdir = ..
else
# This is a kludge.  make wizards might grok.
common-objpfx = sysdeps/../
common-objdir = .
endif
endif

# Root of the sysdeps tree.
sysdep_dir := $(..)sysdeps
export sysdep_dir := $(sysdep_dir)

# Get the values defined by options to `configure'.
include $(common-objpfx)config.make

# What flags to give to sources which call user provided callbacks
uses-callbacks = $(exceptions)

# What flags to give to tests which test stack alignment
stack-align-test-flags =

# Complete path to sysdep dirs.
# `configure' writes a definition of `config-sysdirs' in `config.make'.
sysdirs := $(foreach D,$(config-sysdirs),$(firstword $(filter /%,$D) $(..)$D))

# Add-ons that contribute sysdeps trees get added to the include list
# after sysdeps/generic.  This makes #include <sysdeps/...> work right
# to find specific add-on files without assuming the add-on directory name.
# It also means that headers can go into an add-on's base directory
# instead of the add-on needing a sysdeps/generic of its own.
sysdeps-srcdirs := $(foreach add-on,$(sysdeps-add-ons),\
			     $(firstword $(filter /%,$(add-on)) \
					 $(..)$(add-on)))
+sysdep_dirs = $(sysdirs) $(sysdeps-srcdirs)
ifdef objdir
+sysdep_dirs := $(objdir) $(+sysdep_dirs)
endif

# Run config.status to update config.make and config.h.  We don't show the
# dependence of config.h to Make, because it is only touched when it
# changes and so config.status would be run every time; the dependence of
# config.make should suffice to force regeneration and re-exec, and the new
# image will notice if config.h changed.
$(common-objpfx)config.make: $(common-objpfx)config.status \
			     $(..)config.make.in $(..)config.h.in
	cd $(<D); $(SHELL) $(<F)

# Find all the add-on and sysdeps configure fragments, to make sure we
# re-run configure when any of them changes.
$(common-objpfx)config.status: $(..)version.h $(..)configure \
			       $(foreach dir,$(sysdirs),\
					 $(wildcard $(dir)/Implies) \
					 $(patsubst %.in,%,\
						    $(firstword $(wildcard \
 $(addprefix $(dir)/,configure configure.in))))) \
			       $(patsubst %.in,%,\
					  $(foreach add-on,$(add-ons),\
						    $(firstword $(wildcard \
 $(addprefix $(firstword $(filter /%,$(add-on)) $(..)$(add-on))/,\
	     configure configure.in)))))
	@cd $(@D); if test -f $(@F); then exec $(SHELL) $(@F) --recheck; else \
	 echo The GNU C library has not been configured. >&2; \
	 echo Run \`configure\' to configure it before building. >&2; \
	 echo Try \`configure --help\' for more details. >&2; \
	 exit 1; fi

# We don't want CPPFLAGS to be exported to the command running configure.
unexport CPPFLAGS

# Get the user's configuration parameters.
ifneq ($(wildcard $(..)configparms),)
include $(..)configparms
endif
ifneq ($(objpfx),)
ifneq ($(wildcard $(common-objpfx)configparms),)
include $(common-objpfx)configparms
endif
endif

####
####	These are the configuration variables.  You can define values for
####	the variables below in the file `configparms'.
####	Do NOT edit this file.
####


# Common prefix for machine-independent installation directories.
ifeq ($(origin prefix),undefined) # ifndef would override explicit empty value.
prefix = /usr/local
endif

# Decide whether we shall build the programs or not.  We always do this
# unless the user tells us (in configparms) or we are building for a
# standalone target.
ifndef build-programs
ifneq ($(config-os),none)
build-programs=yes
else
build-programs=no
endif
endif

# Common prefix for machine-dependent installation directories.
ifeq ($(origin exec_prefix),undefined)
exec_prefix = $(prefix)
endif

# Where to install the library and object files.
ifndef libdir
libdir = $(exec_prefix)/lib
endif
inst_libdir = $(install_root)$(libdir)

# Where to install the shared library and dynamic linker.
ifndef slibdir
slibdir = $(exec_prefix)/lib
endif
inst_slibdir = $(install_root)$(slibdir)

# Prefix to put on files installed in $(libdir).  For libraries `libNAME.a',
# the prefix is spliced between `lib' and the name, so the linker switch
# `-l$(libprefix)NAME' finds the library; for other files the prefix is
# just prepended to the whole file name.
ifeq ($(origin libprefix),undefined)
libprefix =
endif

# Where to install the header files.
ifndef includedir
includedir = $(prefix)/include
endif
inst_includedir = $(install_root)$(includedir)

# Where to install machine-independent data files.
# These are the timezone database, and the locale database.
ifndef datadir
datadir = $(prefix)/share
endif
inst_datadir = $(install_root)$(datadir)

# Where to install the timezone data files (which are machine-independent).
ifndef zonedir
zonedir = $(datadir)/zoneinfo
endif
inst_zonedir = $(install_root)$(zonedir)

# Where to install the locale files.
ifndef localedir
localedir = $(libdir)/locale
endif
inst_localedir = $(install_root)$(localedir)

# Where to install the message catalog data files (which are
# machine-independent).
ifndef msgcatdir
msgcatdir = $(datadir)/locale
endif
inst_msgcatdir = $(install_root)$(msgcatdir)

# Where to install the locale charmap source files.
ifndef i18ndir
i18ndir = $(datadir)/i18n
endif
inst_i18ndir = $(install_root)$(i18ndir)

# Where to install the shared object for charset transformation.
ifndef gconvdir
gconvdir = $(libdir)/gconv
endif
inst_gconvdir = $(install_root)$(gconvdir)

# Where to install programs.
ifndef bindir
bindir = $(exec_prefix)/bin
endif
inst_bindir = $(install_root)$(bindir)

# Where to install internal programs.
ifndef libexecdir
libexecdir = $(exec_prefix)/libexec
endif
inst_libexecdir = $(install_root)$(libexecdir)

# Where to install administrative programs.
ifndef rootsbindir
rootsbindir = $(exec_prefix)/sbin
endif
inst_rootsbindir = $(install_root)$(rootsbindir)

ifndef sbindir
sbindir = $(exec_prefix)/sbin
endif
inst_sbindir = $(install_root)$(sbindir)

# Where to install the Info files.
ifndef infodir
infodir = $(prefix)/info
endif
inst_infodir = $(install_root)$(infodir)

# Where to install audit libraries.
ifndef auditdir
auditdir = $(libdir)/audit
endif
inst_auditdir = $(install_root)$(auditdir)

# Where to install default configuration files.  These include the local
# timezone specification and network data base files.
ifndef sysconfdir
sysconfdir = $(prefix)/etc
endif
inst_sysconfdir = $(install_root)$(sysconfdir)

# Directory for the database files and Makefile for nss_db.
ifndef vardbdir
vardbdir = $(localstatedir)/db
endif
inst_vardbdir = $(install_root)$(vardbdir)

# Where to install the "localtime" timezone file; this is the file whose
# contents $(localtime) specifies.  If this is a relative pathname, it is
# relative to $(zonedir).  It is a good idea to put this somewhere
# other than there, so the zoneinfo directory contains only universal data,
# localizing the configuration data elsewhere.
ifndef localtime-file
localtime-file = $(sysconfdir)/localtime
endif

# What to use for leap second specifications in compiling the default
# timezone files.  Set this to `/dev/null' for no leap second handling as
# 1003.1 requires, or to `leapseconds' for proper leap second handling.
# Both zone flavors are always available as `posix/ZONE' and `right/ZONE'.
# This variable determines the default: if it's `/dev/null',
# ZONE==posix/ZONE; if it's `leapseconds', ZONE==right/ZONE.
ifndef leapseconds
leapseconds = /dev/null
endif

# What timezone's DST rules should be used when a POSIX-style TZ
# environment variable doesn't specify any rules.  For 1003.1 compliance
# this timezone must use rules that are as U.S. federal law defines DST.
# Run `make -C time echo-zonenames' to see a list of available zone names.
# This setting can be changed with `zic -p TIMEZONE' at any time.
# If you want POSIX.1 compatibility, use `America/New_York'.
ifndef posixrules
posixrules = America/New_York
endif

# Where to install the "posixrules" timezone file; this is file
# whose contents $(posixrules) specifies.  If this is a relative
# pathname, it is relative to $(zonedir).
ifndef posixrules-file
posixrules-file = posixrules
endif


# Directory where your system's native header files live.
# This is used on Unix systems to generate some GNU libc header files.
ifndef sysincludedir
sysincludedir = /usr/include
endif


# Commands to install files.
ifndef INSTALL_DATA
INSTALL_DATA = $(INSTALL) -m 644
endif
ifndef INSTALL_SCRIPT
INSTALL_SCRIPT = $(INSTALL)
endif
ifndef INSTALL_PROGRAM
INSTALL_PROGRAM = $(INSTALL)
endif
ifndef INSTALL
INSTALL = install
endif


# The name of the C compiler.
# If you've got GCC, and it works, use it.
ifeq ($(origin CC),default)
CC := gcc
endif

# The name of the C compiler to use for compilations of programs to run on
# the host that is building the library.  If you set CC to a
# cross-compiler, you must set this to the normal compiler.
ifndef BUILD_CC
BUILD_CC = $(CC)
endif

# Default flags to pass the C compiler.
ifndef default_cflags
ifeq ($(release),stable)
default_cflags := -g -O2
else
default_cflags := -g -O
endif
endif

# Flags to pass the C compiler when assembling preprocessed assembly code
# (`.S' files).  On some systems the assembler doesn't understand the `#' line
# directives the preprocessor produces.  If you have troubling compiling
# assembly code, try using -P here to suppress these directives.
ifndef asm-CPPFLAGS
asm-CPPFLAGS =
endif

as-needed := -Wl,--as-needed
no-as-needed := -Wl,--no-as-needed

# Must be supported by the linker.
no-whole-archive = -Wl,--no-whole-archive
whole-archive = -Wl,--whole-archive

# Installed name of the startup code.
# The ELF convention is that the startfile is called crt1.o
start-installed-name = crt1.o
# On systems that do not need a special startfile for statically linked
# binaries, simply set it to the normal name.
ifndef static-start-installed-name
static-start-installed-name = $(start-installed-name)
endif

ifeq (yesyes,$(build-shared)$(have-z-combreloc))
combreloc-LDFLAGS = -Wl,-z,combreloc
LDFLAGS.so += $(combreloc-LDFLAGS)
LDFLAGS-rtld += $(combreloc-LDFLAGS)
endif

relro-LDFLAGS = -Wl,-z,relro
LDFLAGS.so += $(relro-LDFLAGS)
LDFLAGS-rtld += $(relro-LDFLAGS)

ifeq (yes,$(have-hash-style))
# For the time being we unconditionally use 'both'.  At some time we
# should declare statically linked code as 'out of luck' and compile
# with --hash-style=gnu only.
hashstyle-LDFLAGS = -Wl,--hash-style=both
LDFLAGS.so += $(hashstyle-LDFLAGS)
LDFLAGS-rtld += $(hashstyle-LDFLAGS)
endif

# Commands for linking programs with the C library.
ifndef +link
+link-before-libc = $(CC) -nostdlib -nostartfiles -o $@ \
	      $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
	      $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
	      $(addprefix $(csu-objpfx),$(start-installed-name)) \
	      $(+preinit) $(+prector) \
	      $(filter-out $(addprefix $(csu-objpfx),start.o \
						     $(start-installed-name))\
			   $(+preinit) $(link-extra-libs) \
			   $(common-objpfx)libc% $(+postinit),$^) \
	      $(link-extra-libs)
+link-after-libc = $(+postctor) $(+postinit)
+link = $(+link-before-libc) $(link-libc) $(+link-after-libc)
+link-tests = $(+link-before-libc) $(link-libc-tests) $(+link-after-libc)
endif
# Command for linking PIE programs with the C library.
ifndef +link-pie
+link-pie = $(CC) -pie -Wl,-O1 -nostdlib -nostartfiles -o $@ \
	     $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F)) \
	     $(combreloc-LDFLAGS) $(relro-LDFLAGS) $(hashstyle-LDFLAGS) \
	     $(addprefix $(csu-objpfx),S$(start-installed-name)) \
	     $(+preinit) $(+prectorS) \
	     $(filter-out $(addprefix $(csu-objpfx),start.o \
						    S$(start-installed-name))\
			  $(+preinit) $(link-extra-libs) \
			  $(common-objpfx)libc% $(+postinit),$^) \
	     $(link-extra-libs) $(link-libc) $(+postctorS) $(+postinit)
endif
# Command for statically linking programs with the C library.
ifndef +link-static
+link-static-before-libc = $(CC) -nostdlib -nostartfiles -static -o $@ \
	      $(sysdep-LDFLAGS) $(LDFLAGS) $(LDFLAGS-$(@F))  \
	      $(addprefix $(csu-objpfx),$(static-start-installed-name)) \
	      $(+preinit) $(+prectorT) \
	      $(filter-out $(addprefix $(csu-objpfx),start.o \
						     $(start-installed-name))\
			   $(+preinit) $(link-extra-libs-static) \
			   $(common-objpfx)libc% $(+postinit),$^) \
	      $(link-extra-libs-static) $(link-libc-static)
+link-static-after-libc = $(+postctorT) $(+postinit)
+link-static = $(+link-static-before-libc) $(link-libc-static) \
	       $(+link-static-after-libc)
+link-static-tests = $(+link-static-before-libc) $(link-libc-static-tests) \
		     $(+link-static-after-libc)
endif
# Command for statically linking bounded-pointer programs with the C library.
ifndef +link-bounded
+link-bounded = $(CC) -nostdlib -nostartfiles -static -fbounded-pointers -o $@ \
	      $(sysdep-LDFLAGS) $(LDFLAGS)  \
	      $(addprefix $(csu-objpfx),b$(static-start-installed-name)) \
	      $(+preinit) $(+prectorT) \
	      $(filter-out $(addprefix $(csu-objpfx),start.ob \
						     $(start-installed-name))\
			   $(+preinit) $(link-extra-libs-bounded) \
			   $(common-objpfx)libc% $(+postinit),$^) \
	      $(link-extra-libs-bounded) $(link-libc-bounded) $(+postctorT) $(+postinit)
endif
ifndef config-LDFLAGS
ifeq (yes,$(build-shared))
config-LDFLAGS = -Wl,-dynamic-linker=$(slibdir)/$(rtld-installed-name)
endif
endif
ifndef link-libc
ifeq (yes,$(build-shared))
# We need the versioned name of libc.so in the deps of $(others) et al
# so that the symlink to libc.so is created before anything tries to
# run the linked programs.
link-libc-before-gnulib = -Wl,-rpath-link=$(rpath-link) \
	    $(common-objpfx)libc.so$(libc.so-version) \
	    $(common-objpfx)$(patsubst %,$(libtype.oS),c) \
	    $(as-needed) $(common-objpfx)elf/ld.so $(no-as-needed)
link-libc = $(link-libc-before-gnulib) $(gnulib)
link-libc-tests = $(link-libc-before-gnulib) $(gnulib-tests)
# This is how to find at build-time things that will be installed there.
rpath-dirs = math elf dlfcn nss nis rt resolv crypt
rpath-link = \
$(common-objdir):$(subst $(empty) ,:,$(patsubst ../$(subdir),.,$(rpath-dirs:%=$(common-objpfx)%)))
elfobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)elf)
else
nssobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)nss)
resolvobjdir := $(patsubst ../$(subdir),.,$(common-objpfx)resolv)
link-libc = $(common-objpfx)libc.a $(otherlibs) $(gnulib) $(common-objpfx)libc.a $(gnulib)
link-libc-tests = $(common-objpfx)libc.a $(otherlibs) $(gnulib-tests) $(common-objpfx)libc.a $(gnulib-tests)
endif
endif

# Differences in the linkers on the various platforms.
LDFLAGS-rpath-ORIGIN = -Wl,-rpath,'$$ORIGIN'
LDFLAGS-soname-fname = -Wl,-soname,$(@F)
LDFLAGS-rdynamic = -rdynamic
LDFLAGS-Bsymbolic = -Bsymbolic

# Choose the default search path for the dynamic linker based on
# where we will install libraries.
ifneq ($(libdir),$(slibdir))
default-rpath = $(slibdir):$(libdir)
else
default-rpath = $(libdir)
endif

ifndef link-extra-libs
link-extra-libs = $(LDLIBS-$(@F))
link-extra-libs-static = $(link-extra-libs)
link-extra-libs-bounded = $(link-extra-libs)
endif

# The static libraries.
link-libc-static = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib) -Wl,--end-group
link-libc-static-tests = -Wl,--start-group $(common-objpfx)libc.a $(static-gnulib-tests) -Wl,--end-group
link-libc-bounded = $(common-objpfx)libc_b.a $(gnulib) $(common-objpfx)libc_b.a

# How to link against libgcc.  Some libgcc functions, such as those
# for "long long" arithmetic or software floating point, can always be
# built without use of C library headers and do not have any global
# state so can safely be linked statically into any executable or
# shared library requiring them; these functions are in libgcc.a.
# Other functions, relating to exception handling, may require C
# library headers to build and it may not be safe to have more than
# one copy of them in a process; these functions are only in
# libgcc_s.so and libgcc_eh.a.
#
# To avoid circular dependencies when bootstrapping, it is desirable
# to avoid use of libgcc_s and libgcc_eh in building glibc.  Where any
# glibc functionality (in particular, thread cancellation) requires
# exception handling, this is implemented through dlopen of libgcc_s
# to avoid unnecessary dependencies on libgcc_s by programs not using
# that functionality; executables built with glibc do not use
# exception handling other than through thread cancellation.
#
# Undefined references to functions from libgcc_eh or libgcc_s may
# arise for code built with -fexceptions.  In the case of statically
# linked programs installed by glibc, unwinding will never actually
# occur at runtime and the use of elf/static-stubs.c to resolve these
# references is safe.  In the case of statically linked test programs
# and test programs built with -fexceptions, unwinding may occur in
# some cases and it is preferable to link with libgcc_eh or libgcc_s
# so that the testing is as similar as possible to how programs will
# be built with the installed glibc.
#
# Some architectures have architecture-specific systems for exception
# handling that may involve undefined references to
# architecture-specific functions.  On those architectures,
# gnulib-arch and static-gnulib-arch may be defined in sysdeps
# makefiles to use additional libraries for linking executables and
# shared libraries built by glibc.
ifndef gnulib
ifneq ($(have-cc-with-libunwind),yes)
  libunwind =
else
  libunwind = -lunwind
endif
libgcc_eh := -Wl,--as-needed -lgcc_s $(libunwind) -Wl,--no-as-needed
gnulib-arch =
gnulib = -lgcc $(gnulib-arch)
gnulib-tests := -lgcc $(libgcc_eh)
static-gnulib-arch =
static-gnulib = -lgcc $(static-gnulib-arch)
static-gnulib-tests := -lgcc -lgcc_eh $(libunwind)
libc.so-gnulib := -lgcc
endif
+preinit = $(addprefix $(csu-objpfx),crti.o)
+postinit = $(addprefix $(csu-objpfx),crtn.o)
+prector = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbegin.o`
+postctor = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtend.o`
# Variants of the two previous definitions for linking PIE programs.
+prectorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginS.o`
+postctorS = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtendS.o`
# Variants of the two previous definitions for statically linking programs.
+prectorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtbeginT.o`
+postctorT = `$(CC) $(sysdep-LDFLAGS) --print-file-name=crtendS.o`
+interp = $(addprefix $(elf-objpfx),interp.os)
csu-objpfx = $(common-objpfx)csu/
elf-objpfx = $(common-objpfx)elf/

# How to run a program we just linked with our library.
# The program binary is assumed to be $(word 2,$^).
built-program-file = $(dir $(word 2,$^))$(notdir $(word 2,$^))
ifeq (yes,$(build-shared))
comma = ,
sysdep-library-path = \
$(subst $(empty) ,:,$(strip $(patsubst -Wl$(comma)-rpath-link=%, %,\
				       $(filter -Wl$(comma)-rpath-link=%,\
						$(sysdep-LDFLAGS)))))
run-program-prefix = $(if $(filter $(notdir $(built-program-file)),\
				   $(tests-static) $(xtests-static)),, \
			  $(elf-objpfx)$(rtld-installed-name) \
			  --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)))
else
run-program-prefix =
endif
# Never use $(run-program-prefix) for the statically-linked %-bp test programs
built-program-cmd = $(patsubst %,$(run-program-prefix),\
			$(filter-out %-bp,$(built-program-file))) \
		    $(built-program-file)

ifndef LD
LD := ld -X
endif

# Extra flags to pass to GCC.
ifeq ($(all-warnings),yes)
+gccwarn := -Wall -Wwrite-strings -Winline -Wcast-qual -Wbad-function-cast -Wmissing-noreturn -Wmissing-prototypes -Wmissing-declarations -Wcomment -Wcomments -Wtrigraphs -Wsign-compare -Wfloat-equal -Wmultichar
else
+gccwarn := -Wall -Wwrite-strings -Winline
endif
+gccwarn-c = -Wstrict-prototypes

# We do not depend on the address of constants in different files to be
# actually different, so allow the compiler to merge them all.
+merge-constants = -fmerge-all-constants

# We have to assume that glibc functions are called in any rounding
# mode and also change the rounding mode in a few functions. So,
# disable any optimization that assume default rounding mode.
+math-flags = -frounding-math

# This is the program that generates makefile dependencies from C source files.
# The -MP flag tells GCC >= 3.2 (which we now require) to produce dummy
# targets for headers so that removed headers don't break the build.
ifndef +mkdep
+mkdep = $(CC) -M -MP
endif

# The program that makes Emacs-style TAGS files.
ETAGS	:= etags

# The `xgettext' program for producing .pot files from sources.
ifndef XGETTEXT
XGETTEXT = xgettext
endif

# The `m4' macro processor; this is used by sysdeps/sparc/Makefile (and
# perhaps others) to preprocess assembly code in some cases.
M4 = m4

# To force installation of files even if they are older than the
# installed files.  This variable is included in the dependency list
# of all installation targets.
ifeq ($(force-install),yes)
+force = force-install
else
+force =
endif

####
#### End of configuration variables.
####

# This tells some versions of GNU make before 3.63 not to export all variables.
.NOEXPORT:

# We want to echo the commands we're running without
# umpteen zillion filenames along with it (we use `...' instead)
# but we don't want this echoing done when the user has said
# he doesn't want to see commands echoed by using -s.
ifneq	"$(findstring s,$(MAKEFLAGS))" ""	# if -s
+cmdecho	:= echo >/dev/null
else						# not -s
+cmdecho	:= echo
endif	   					# -s

# These are the flags given to the compiler to tell
# it what sort of optimization and/or debugging output to do.
ifndef	+cflags
# If `CFLAGS' was defined, use that.
ifdef		CFLAGS
+cflags	:= $(filter-out -I%,$(CFLAGS))
endif		# CFLAGS
endif	# +cflags

# If none of the above worked, default to "-g -O".
ifeq	"$(strip $(+cflags))" ""
+cflags	:= $(default_cflags)
endif	# $(+cflags) == ""

+cflags += $(cflags-cpu) $(+gccwarn) $(+merge-constants) $(+math-flags)
+gcc-nowarn := -w

# Don't duplicate options if we inherited variables from the parent.
+cflags	:= $(sort $(+cflags))

# These are flags given to the C compiler to tell it to look for
# include files (including ones given in angle brackets) in the parent
# library source directory, in the include directory, and in the
# current directory.
+sysdep-includes = $(addprefix -I,$(+sysdep_dirs))
+includes = -I$(..)include $(if $(subdir),$(objpfx:%/=-I%)) \
	    $(+sysdep-includes) $(includes) \
	    $(patsubst %/,-I%,$(..)) $(libio-include) -I. $(sysincludes)

# Since libio has several internal header files, we use a -I instead
# of many little headers in the include directory.
libio-include = -I$(..)libio

# These are the variables that the implicit compilation rules use.
# Note that we can't use -std=* in CPPFLAGS, because it overrides
# the implicit -lang-asm and breaks cpp behavior for .S files--notably
# it causes cpp to stop predefining __ASSEMBLER__.
CPPFLAGS = $(CPPUNDEFS) $(CPPFLAGS-config) $($(subdir)-CPPFLAGS) \
	   $(+includes) $(defines) \
	   -include $(..)include/libc-symbols.h $(sysdep-CPPFLAGS) \
	   $(CPPFLAGS-$(suffix $@)) \
	   $(foreach lib,$(libof-$(basename $(@F))) \
			 $(libof-$(<F)) $(libof-$(@F)),$(CPPFLAGS-$(lib))) \
	   $(CPPFLAGS-$(<F)) $(CPPFLAGS-$(@F)) $(CPPFLAGS-$(basename $(@F)))
override CFLAGS	= -std=gnu99 $(gnu89-inline-CFLAGS) $(config-extra-cflags) \
		  $(filter-out %frame-pointer,$(+cflags)) $(+gccwarn-c) \
		  $(sysdep-CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) \
		  $(CFLAGS-$(@F)) \
		  $(foreach lib,$(libof-$(basename $(@F))) \
				$(libof-$(<F)) $(libof-$(@F)),$(CFLAGS-$(lib)))
override CXXFLAGS = $(c++-sysincludes) \
		    $(filter-out %frame-pointer,$(+cflags)) $(sysdep-CFLAGS) \
		    $(CFLAGS-$(suffix $@)) $(CFLAGS-$(<F)) $(CFLAGS-$(@F))

# If everything is compiled with -fPIC (implicitly) we must tell this by
# defining the PIC symbol.
ifeq (yes,$(build-pic-default))
pic-default = -DPIC
endif

# Enable object files for different versions of the library.
# Various things use $(object-suffixes) to know what all to make.
# The compilation rules use $(CPPFLAGS-${SUFFIX}) and $(CFLAGS-${SUFFIX})
# to pass different flags for each flavor.
libtypes = $(foreach o,$(object-suffixes-for-libc),$(libtype$o))
all-object-suffixes := .o .os .op .og .ob .oS
object-suffixes :=
CPPFLAGS-.o = $(pic-default)
CFLAGS-.o = $(filter %frame-pointer,$(+cflags))
libtype.o := lib%.a
object-suffixes += .o
ifeq (yes,$(build-shared))
# Under --enable-shared, we will build a shared library of PIC objects.
# The PIC object files are named foo.os.
object-suffixes += .os
CPPFLAGS-.os = -DPIC -DSHARED
CFLAGS-.os = $(filter %frame-pointer,$(+cflags)) $(pic-ccflag)
libtype.os := lib%_pic.a
# This can be changed by a sysdep makefile
pic-ccflag = -fPIC
# This one should always stay like this unless there is a very good reason.
PIC-ccflag = -fPIC
endif
# This can be changed by a sysdep makefile
pie-ccflag = -fpie
# This one should always stay like this unless there is a very good reason.
PIE-ccflag = -fPIE
ifeq (yes,$(build-profile))
# Under --enable-profile, we will build a static library of profiled objects.
# The profiled object files are named foo.op.
object-suffixes += .op
CPPFLAGS-.op = -DPROF $(pic-default)
CFLAGS-.op = -pg
libtype.op = lib%_p.a
endif

# Convenience variable for when we want to treat shared-library cases
# differently from the rest.
object-suffixes-noshared := $(filter-out .os,$(object-suffixes))

bppfx = BP-
ifeq (yes,$(build-bounded))
# Under --enable-bounded, we build the library with `-fbounded-pointers -g'
# to runtime bounds checking.  The bounded-pointer objects are named foo.ob.
# We disable sibling-call optimizations so that stack traces will be complete
# and thus aid debugging, since after all, BPs are a debugging tool.
object-suffixes += .ob
CPPFLAGS-.ob = -fbounded-pointers $(pic-default)
CFLAGS-.ob = -g -O2 -fno-optimize-sibling-calls -fno-strict-aliasing
libtype.ob = lib%_b.a
endif

object-suffixes-for-libc := $(object-suffixes)

ifeq (yes,$(build-shared))
# Build special library that contains the static-only routines for libc.
object-suffixes-for-libc += .oS

# Must build the routines as PIC, though, because they can end up in (users')
# shared objects.  We don't want to use CFLAGS-os because users may, for
# example, make that processor-specific.
CFLAGS-.oS = $(CFLAGS-.o) $(PIC-ccflag)
CPPFLAGS-.oS = $(CPPFLAGS-.o) -DPIC -DLIBC_NONSHARED=1
libtype.oS = lib%_nonshared.a
endif

# The assembler can generate debug information too.
ifndef ASFLAGS
ASFLAGS := $(filter -g% -fdebug-prefix-map=%,$(CFLAGS))
endif
ASFLAGS += $(ASFLAGS-config) $(asflags-cpu)

ifndef BUILD_CC
BUILD_CC = $(CC)
endif

move-if-change = $(SHELL) $(..)scripts/move-if-change

-include $(common-objpfx)sysd-sorted
subdirs = $(sorted-subdirs)
subdir-srcdirs = $(foreach dir,$(subdirs),\
			   $(firstword $($(dir)-srcdir) $(..)$(dir)))

ifeq (yes, $(build-shared))

# This is a pair of implicit rules to preprocess a file with # comments,
# %ifdef et al, based on config.h settings or other %include'd files.
# We use chained rules instead of a pipeline here so that we can properly
# check the exit status of cpp rather than using its bad output when there
# is a preprocessing error.  Another rule should depend on the output file
# `FOO.v', and along with that `FOO.v.i' should be given dependencies
# listing both its input files, and any header files that it may reference
# (but no commands).
%.v.i: $(common-objpfx)config.h $(..)Makeconfig
	sed '/^[ 	]*%/!s/#.*$$//;/^[ 	]*$$/d;s/^[ 	]*%/#/' \
	    $(filter-out FORCE %.h $(..)Makeconfig,$^) \
	| $(CC) -E -undef $(CPPFLAGS) -x assembler-with-cpp - \
		   > $@T
	mv -f $@T $@
%.v: %.v.i
	sed '/^[ 	]*#/d;/^[ 	]*$$/d' $< > $@T
	mv -f $@T $@

# To generate a header to support more than one ABI for different
# architecture variants, the CPU/Makefile defines abi-variants to be a
# list of names for those variants (e.g. 32 64), and, for each variant,
# defines abi-$(variant)-condition to be the condition for those options
# to use in a C #if condition.  abi-includes may be defined to a list of
# headers to include in the generated header, if the default does not
# suffice.  default-abi is defined to be the ABI for the current glibc
# build.

ifndef abi-includes
abi-includes := bits/wordsize.h
endif

# Process the shlib-versions file, which tells us what shared library
# version numbers to use when we install shared objects on this system.
# We need to wait until $(subdirs) is complete.
ifeq ($(sysd-sorted-done),t)
-include $(common-objpfx)soversions.mk
ifndef avoid-generated
# This lets add-ons give more-specific matches that override defaults
# in the top-level file.
$(common-objpfx)shlib-versions.v.i: \
	$(wildcard $(+sysdep_dirs:=/shlib-versions) \
		   $(subdir-srcdirs:=/shlib-versions)) \
	$(..)shlib-versions

soversions-default-setname = $(patsubst %, %,\
					$(filter-out %_default,\
						     $(oldest-abi:%=GLIBC_%)))
$(common-objpfx)soversions.i: $(..)scripts/soversions.awk \
			      $(common-objpfx)shlib-versions.v
	$(AWK) -v default_setname='$(soversions-default-setname)' \
	       -v cpu='$(config-machine)' \
	       -v vendor='$(config-vendor)' \
	       -v os='$(config-os)' \
	       -f $^ > $@T
	mv -f $@T $@
$(common-objpfx)soversions.mk: $(common-objpfx)soversions.i $(..)Makeconfig
	(while read which lib number setname; do \
	   eval seen_$$which=1; \
	   test x"$$which" != xABI || echo abi-name = "$$lib"; \
	   test x"$$which" = xDEFAULT || continue; \
	   case $$number in \
	     [0-9]*) echo "$$lib.so-version=.$$number"; \
		     echo "all-sonames+=$$lib=$$lib.so\$$($$lib.so-version)";;\
	     *)	     echo "$$lib.so-version=\$$(if \$$(abi-$(default-abi)-$$lib-soname),\$$(abi-$(default-abi)-$$lib-soname),$$number)"; \
		     echo "all-sonames+=$$lib=\$$($$lib.so-version)";;\
	   esac; \
	 done; \
	 echo soversions.mk-done = t;) < $< > $@T; exit 0
	mv -f $@T $@
endif
endif

postclean-generated += soversions.mk soversions.i \
		       shlib-versions.v shlib-versions.v.i

# Generate the header containing the names of all shared libraries.
# We use a stamp file to avoid unnecessary recompilations.
before-compile += $(common-objpfx)gnu/lib-names.h
ifeq ($(soversions.mk-done),t)
$(common-objpfx)gnu/lib-names.h: $(common-objpfx)gnu/lib-names.stmp; @:
$(common-objpfx)gnu/lib-names.stmp: $(..)scripts/lib-names.awk \
				    $(common-objpfx)soversions.i
	$(make-target-directory)
	{ \
	 echo '/* This file is automatically generated.';\
	 echo '   It defines macros to allow user program to find the shared'; \
	 echo '   library files which come as part of GNU libc.  */'; \
	 echo '#ifndef __GNU_LIB_NAMES_H'; \
	 echo '#define __GNU_LIB_NAMES_H	1'; \
	 echo ''; \
	 $(if $(abi-includes), \
	  $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
	  echo '';) \
	 $(if $(abi-variants), \
	 $(foreach v,$(abi-variants),\
	 $(if $(abi-$(v)-condition),\
	 echo '#if $(abi-$(v)-condition)'; \
	 ($(foreach s,$(all-sonames), \
	   $(if $(abi-$(v)-$(firstword $(subst =, ,$(s)))-soname),\
	     echo $(firstword $(subst =, ,$(s)))=$(abi-$(v)-$(firstword $(subst =, ,$(s)))-soname);, \
	     echo $(s);))) \
	 | LC_ALL=C $(AWK) -v multi=1 -f $(firstword $^) | LC_ALL=C sort;) \
	 $(if $(abi-$(v)-condition),echo '#endif';)), \
	 ($(foreach s,$(all-sonames), echo $(s);)) \
	 | LC_ALL=C $(AWK) -f $(firstword $^) | LC_ALL=C sort;) \
	 echo ''; \
	 echo '#endif	/* gnu/lib-names.h */'; \
	} >  ${@:stmp=T}
	$(move-if-change) ${@:stmp=T} ${@:stmp=h}
	touch $@
endif

common-generated += gnu/lib-names.h gnu/lib-names.stmp

# The name under which the run-time dynamic linker is installed.
# We are currently going for the convention that `/lib/ld.so.1'
# names the SVR4/ELF ABI-compliant dynamic linker.
ifndef rtld-installed-name
ifdef ld.so-version
rtld-installed-name = $(ld.so-version)
else
rtld-installed-name = ld.so.1
endif
endif

ifndef rtld-version-installed-name
rtld-version-installed-name = ld-$(version).so
endif

endif # build-shared


ifeq ($(build-shared),yes)
libdl = $(common-objpfx)dlfcn/libdl.so$(libdl.so-version)
else
libdl = $(common-objpfx)dlfcn/libdl.a
endif

ifeq ($(build-shared),yes)
libm = $(common-objpfx)math/libm.so$(libm.so-version)
else
libm = $(common-objpfx)math/libm.a
endif

# These are the subdirectories containing the library source.  The order
# is more or less arbitrary.  The sorting step will take care of the
# dependencies.
all-subdirs = csu assert ctype locale intl catgets math setjmp signal	    \
	      stdlib stdio-common libio malloc string wcsmbs time dirent    \
	      grp pwd posix io termios resource misc socket sysvipc gmon    \
	      gnulib iconv iconvdata wctype manual shadow gshadow po argp   \
	      crypt nss localedata timezone rt conform debug		    \
	      $(add-on-subdirs) dlfcn elf

ifndef avoid-generated
all-Depend-files := $(wildcard $(foreach dir,$(all-subdirs),\
					 $(firstword $($(dir)-srcdir) \
						     $(..)$(dir))/Depend))
$(common-objpfx)sysd-sorted: $(..)scripts/gen-sorted.awk \
			     $(common-objpfx)config.make $(..)Makeconfig \
			     $(wildcard $(sysdirs:=/Subdirs)) \
			     $(all-Depend-files)
	$(AWK) -f $< \
	       -v subdirs='$(all-subdirs)' \
	       -v srcpfx='$(..)' \
	       $(filter %/Subdirs %/Depend,$^) > $@-tmp
	mv -f $@-tmp $@
$(all-Depend-files): ;
endif

# This gives partial TARGET:SOURCE pattern pairs to have rules
# emitted into sysd-rules.  A sysdeps Makeconfig fragment can
# add its own special object file prefix to this list with e.g. foo-%:%
# to have foo-*.? compiled from *.? using $(foo-CPPFLAGS).
sysd-rules-patterns := %:% rtld-%:rtld-% rtld-%:% m_%:s_%

# Let sysdeps/ subdirs contain a Makeconfig fragment for us to include here.
sysdep-makeconfigs := $(wildcard $(+sysdep_dirs:=/Makeconfig))
ifneq (,$(sysdep-makeconfigs))
include $(sysdep-makeconfigs)
endif

# Compute just the target patterns.  Makeconfig has set sysd-rules-patterns.
sysd-rules-targets := $(sort $(foreach p,$(sysd-rules-patterns),\
					 $(firstword $(subst :, ,$p))))

# A sysdeps Makeconfig fragment may set libc-reentrant to yes.
ifeq (yes,$(libc-reentrant))
defines += -D_LIBC_REENTRANT

libio-mtsafe = -D_IO_MTSAFE_IO
endif

endif # Makeconfig not yet included

# Local Variables:
# mode: makefile
# End: