]> git.ipfire.org Git - thirdparty/glibc.git/blame - csu/Makefile
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[thirdparty/glibc.git] / csu / Makefile
CommitLineData
28f540f4 1# Makefile for csu code for GNU C library.
a334319f 2# Copyright (C) 1995-2003, 2004 Free Software Foundation, Inc.
28f540f4
RM
3# This file is part of the GNU C Library.
4
5# The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
6# modify it under the terms of the GNU Lesser General Public
7# License as published by the Free Software Foundation; either
8# version 2.1 of the License, or (at your option) any later version.
28f540f4
RM
9
10# The GNU C Library is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
41bdb6e2
AJ
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
28f540f4 14
41bdb6e2
AJ
15# You should have received a copy of the GNU Lesser General Public
16# License along with the GNU C Library; if not, write to the Free
17# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18# 02111-1307 USA.
28f540f4
RM
19
20# This directory contains the C startup code (that which calls main). This
21# consists of the startfile, built from start.c and installed as crt0.o
0f9cc699 22# (traditionally) or crt1.o (for ELF). In ELF we also install crti.o and
b5ca0fb0 23# crtn.o, special "initializer" and "finalizer" files used in the link
11c981a9
RM
24# to make the .init and .fini sections work right; both these files are
25# built (in an arcane manner) from initfini.c.
28f540f4
RM
26
27subdir := csu
28
8a30f00f 29routines = init-first libc-start $(libc-init) sysdep version check_fds \
ee2a5ae8 30 libc-tls elf-init dso_handle
ce460d04 31aux = errno
2a76f7ef 32elide-routines.os = libc-tls
06b31ad3 33static-only-routines = elf-init
b6da933b 34csu-dummies = $(filter-out $(start-installed-name),crt1.o Mcrt1.o)
11c981a9 35extra-objs = start.o gmon-start.o \
b6da933b
UD
36 $(start-installed-name) g$(start-installed-name) $(csu-dummies) \
37 S$(start-installed-name)
11c981a9 38omit-deps = $(patsubst %.o,%,$(start-installed-name) g$(start-installed-name) \
bc4647a1
UD
39 b$(start-installed-name) $(csu-dummies) \
40 S$(start-installed-name))
98186375 41install-lib = $(start-installed-name) g$(start-installed-name) $(csu-dummies)
a334319f
UD
42distribute = initfini.c gmon-start.c start.c defs.awk munch.awk \
43 abi-note.S init.c munch-tmpl.c not-cancel.h
c7562c74
UD
44generated = version-info.h
45before-compile = $(objpfx)version-info.h
28f540f4 46
78c9da10
RM
47tests := tst-empty tst-atomic tst-atomic-long
48tests-static := tst-empty
d15851ec 49
28f540f4
RM
50all: # Make this the default target; it will be defined in Rules.
51
52include ../Makeconfig
53
bc4647a1
UD
54ifeq (yes,$(build-shared))
55extra-objs += S$(start-installed-name)
56install-lib += S$(start-installed-name)
57endif
58
ac556388
GM
59ifeq (yes,$(build-bounded))
60extra-objs += b$(start-installed-name)
61install-lib += b$(start-installed-name)
62endif
63
083973f3
RM
64ifneq ($(start-installed-name),$(static-start-installed-name))
65extra-objs += $(static-start-installed-name) g$(static-start-installed-name)
66omit-deps += $(patsubst %.o,%,$(static-start-installed-name) \
67 g$(static-start-installed-name))
68install-lib += $(static-start-installed-name) g$(static-start-installed-name)
69endif
70
c7562c74
UD
71ifeq (yes,$(elf))
72before-compile += $(objpfx)abi-tag.h
da2d1bc5 73generated += abi-tag.h
a5a0310d 74endif
b8dc6a10 75
a334319f
UD
76ifneq (yes,$(gnu-ld))
77libc-init = munch-init
78$(objpfx)munch-init.c: munch.awk munch-tmpl.c $(+subdir_inits)
79 $(AWK) -f $< subdirs='$(+init_subdirs)' $(word 2,$^) > $@-t
80 mv -f $@-t $@
81generated += munch-init.c
82
83# All initialization source files.
84+subdir_inits := $(wildcard $(foreach dir,$(subdirs),$(dir)/init-$(dir).c))
85# All subdirectories containing initialization source files.
86+init_subdirs := $(patsubst %/,%,$(dir $(+subdir_inits)))
87endif
88
307bcd77 89ifeq ($(have-initfini),yes)
37f91d33 90
294897f4
RM
91CPPFLAGS += -DHAVE_INITFINI
92
37f91d33 93# These are the special initializer/finalizer files. They are always the
4e1bac76
RM
94# first and last file in the link. crti.o ... crtn.o define the global
95# "functions" _init and _fini to run the .init and .fini sections.
96crtstuff = crti crtn
37f91d33
RM
97
98install-lib += $(crtstuff:=.o)
99extra-objs += $(crtstuff:=.o)
9a0a462c 100generated += $(crtstuff:=.S) initfini.s defs.h
37f91d33 101omit-deps += $(crtstuff)
28f540f4 102
307bcd77 103# Special rules for the building of crti.o and crtn.o
4b0b5882 104$(crtstuff:%=$(objpfx)%.o): %.o: %.S $(objpfx)defs.h
f41c8091 105 $(compile.S) -g0 $(ASFLAGS-.os) -o $@
307bcd77 106
49803108 107CFLAGS-initfini.s = -g0 -fPIC -fno-inline-functions $(fno-unit-at-a-time)
9a0a462c 108
a334319f 109vpath initfini.c $(full_config_sysdirs)
93414bb9 110
05d3d580 111$(objpfx)initfini.s: initfini.c $(before-compile)
9a0a462c 112 $(compile.c) -S $(CFLAGS-initfini.s) -finhibit-size-directive \
e1b13a63 113 $(patsubst -f%,-fno-%,$(exceptions)) -o $@
307bcd77 114
0f9cc699 115# We only have one kind of startup code files. Static binaries and
5ae3e846 116# shared libraries are build using the PIC version.
307bcd77
UD
117$(objpfx)crti.S: $(objpfx)initfini.s
118 sed -n -e '1,/@HEADER_ENDS/p' \
119 -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
120 -e '/@TRAILER_BEGINS/,$$p' $< > $@
121
122$(objpfx)crtn.S: $(objpfx)initfini.s
123 sed -n -e '1,/@HEADER_ENDS/p' \
124 -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \
125 -e '/@TRAILER_BEGINS/,$$p' $< > $@
126
adee0e1f
RM
127# These explicit rules are necessary when the $(objpfx) subdirectory
128# did not exist at the time make considered the implicit rules using it.
129# This comes up with a fresh build using no_deps=t.
130$(patsubst %,$(objpfx)crt%.o,i n): %.o: %.S
131
307bcd77
UD
132$(objpfx)defs.h: $(objpfx)initfini.s
133 sed -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
5aa8ff62 134 $(AWK) -f defs.awk > $@
28f540f4 135
37f91d33 136endif
28f540f4 137
51702635 138ifeq (yes,$(elf))
6973fc01 139extra-objs += abi-note.o init.o
92f1da4d 140asm-CPPFLAGS += -I$(objpfx).
51702635
UD
141endif
142
28f540f4
RM
143include ../Rules
144
71cf0361
UD
145# Make these in the lib pass so they're available in time to link things with.
146subdir_lib: $(extra-objs:%=$(objpfx)%)
147
779ae82e
UD
148define link-relocatable
149$(CC) -nostdlib -nostartfiles -r -o $@ $^
150endef
151
b8dc6a10 152ifndef start-installed-name-rule
779ae82e
UD
153ifeq (yes,$(elf))
154# We link the ELF startfile along with a SHT_NOTE section indicating
3081378b 155# the kernel ABI the binaries linked with this library will require.
6973fc01
UD
156$(objpfx)$(start-installed-name): $(objpfx)start.o $(objpfx)abi-note.o \
157 $(objpfx)init.o
779ae82e 158 $(link-relocatable)
bc4647a1
UD
159$(objpfx)S$(start-installed-name): $(objpfx)start.os $(objpfx)abi-note.o \
160 $(objpfx)init.o
161 $(link-relocatable)
58ff985d
GM
162$(objpfx)b$(start-installed-name): $(objpfx)start.ob $(objpfx)abi-note.ob \
163 $(objpfx)init.ob
164 $(link-relocatable)
779ae82e 165else
28f540f4
RM
166# The startfile is installed under different names, so we just call our
167# source file `start.c' and copy to the installed name after compiling.
168$(objpfx)$(start-installed-name): $(objpfx)start.o
779ae82e 169 rm -f $@
28f540f4 170 ln $< $@
bc4647a1
UD
171$(objpfx)S$(start-installed-name): $(objpfx)start.os
172 rm -f $@
173 ln $< $@
98186375
GM
174$(objpfx)b$(start-installed-name): $(objpfx)start.ob
175 rm -f $@
176 ln $< $@
b8dc6a10 177endif
779ae82e 178endif
28f540f4 179
11c981a9
RM
180# The profiling startfile is made by linking together the normal
181# startfile with gmon-start.o, which defines a constructor function
182# to turn on profiling code at startup.
083973f3
RM
183$(addprefix $(objpfx),$(sort g$(start-installed-name) \
184 g$(static-start-installed-name))): \
185 $(objpfx)g%: $(objpfx)% $(objpfx)gmon-start.o
779ae82e 186 $(link-relocatable)
11c981a9 187
28f540f4
RM
188# These extra files are sometimes expected by system standard linking
189# procedures, but we have nothing for them to do. So compile empty files.
b6da933b 190$(addprefix $(objpfx),$(filter-out $(start-installed-name), $(csu-dummies))):\
c6696b79
RM
191 $(before-compile)
192 $(COMPILE.c) -o $@ -x c /dev/null
92f1da4d 193
c7562c74 194# These headers are used by the startup code.
92f1da4d 195$(objpfx)abi-tag.h: $(..)abi-tags
39e16978 196 $(make-target-directory)
92f1da4d 197 rm -f $@.new
0f9cc699 198 sed -e 's/#.*$$//' -e '/^[ ]*$$/d' $< | \
a986484f 199 while read conf tagos tagver; do \
92f1da4d
UD
200 test `expr '$(config-machine)-$(config-vendor)-$(config-os)' \
201 : "$$conf"` != 0 || continue; \
a986484f
UD
202 ( echo "$$tagos" | \
203 sed -e 's/[^0-9xXa-fA-F ]//' \
204 -e 's/^/#define __ABI_TAG_OS /'; \
205 echo "#ifndef __ABI_TAG_VERSION"; \
206 echo "$$tagver" | \
207 sed -e 's/[^0-9xXa-fA-F]/ /g' -e 's/ *$$//' \
208 -e 's/ /,/g' -e 's/^/# define __ABI_TAG_VERSION /'; \
209 echo "#endif" ) > $@.new; \
92f1da4d
UD
210 done
211 if test -r $@.new; then mv -f $@.new $@; \
212 else echo >&2 'This configuration not matched in $<'; exit 1; fi
c7562c74 213
a334319f
UD
214all-Banner-files = $(wildcard $(addsuffix /Banner, \
215 $(addprefix $(..), $(subdirs))))
c7562c74
UD
216$(objpfx)version-info.h: $(common-objpfx)config.make $(all-Banner-files)
217 $(make-target-directory)
218 (case $(config-os) in \
e7f4d2bf
RM
219 linux*) version=`(printf '%s\n%s\n' \
220 '#include <linux/version.h>' \
221 UTS_RELEASE \
b30542fb 222 | $(CC) $(CPPFLAGS) -E -P - -DNOT_IN_libc=1 | \
c7562c74
UD
223 sed -e 's/"\([^"]*\)".*/\1/p' -e d) 2>/dev/null`;\
224 if [ -z "$$version" ]; then \
225 if [ -r /proc/version ]; then \
b48abe3c 226 version=`sed 's/.*Linux version \([^ ]*\) .*/>>\1<</' \
c7562c74
UD
227 < /proc/version`; \
228 else \
229 version=`uname -r`; \
230 fi; \
231 fi; \
c269fdb4
UD
232 os=`uname -s 2> /dev/null`; \
233 if [ -z "$$os" ]; then \
234 os=Linux; \
235 fi; \
e7f4d2bf
RM
236 printf '"Compiled on a %s %s system on %s.\\n"\n' \
237 "$$os" "$$version" "`date +%Y-%m-%d`";; \
c7562c74
UD
238 *) ;; \
239 esac; \
240 files="$(all-Banner-files)"; \
241 if test -n "$$files"; then \
a334319f 242 echo "\"Available extensions:\\n\""; \
0f9cc699 243 sed -e '/^#/d' -e 's/^[[:space:]]*/ /' \
63461e75 244 -e 's/^\(.*\)$$/\"\1\\n\"/' $$files; \
c7562c74
UD
245 fi) > $@T
246 mv -f $@T $@