(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[glibc.git] / csu / Makefile
blobfbbfe0050a190a2873d10c0736704d0413aaf903
1 # Makefile for csu code for GNU C library.
2 # Copyright (C) 1995-2003, 2004 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
5 # The GNU C Library is free software; you can redistribute it and/or
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.
10 # The GNU C Library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
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.
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
22 # (traditionally) or crt1.o (for ELF). In ELF we also install crti.o and
23 # crtn.o, special "initializer" and "finalizer" files used in the link
24 # to make the .init and .fini sections work right; both these files are
25 # built (in an arcane manner) from initfini.c.
27 subdir := csu
29 routines = init-first libc-start $(libc-init) sysdep version check_fds \
30 libc-tls elf-init dso_handle
31 aux = errno
32 elide-routines.os = libc-tls
33 static-only-routines = elf-init
34 csu-dummies = $(filter-out $(start-installed-name),crt1.o Mcrt1.o)
35 extra-objs = start.o gmon-start.o \
36 $(start-installed-name) g$(start-installed-name) $(csu-dummies) \
37 S$(start-installed-name)
38 omit-deps = $(patsubst %.o,%,$(start-installed-name) g$(start-installed-name) \
39 b$(start-installed-name) $(csu-dummies) \
40 S$(start-installed-name))
41 install-lib = $(start-installed-name) g$(start-installed-name) $(csu-dummies)
42 distribute = initfini.c gmon-start.c start.c defs.awk munch.awk \
43 abi-note.S init.c munch-tmpl.c not-cancel.h
44 generated = version-info.h
45 before-compile = $(objpfx)version-info.h
47 tests := tst-empty tst-atomic tst-atomic-long
48 tests-static := tst-empty
50 all: # Make this the default target; it will be defined in Rules.
52 include ../Makeconfig
54 ifeq (yes,$(build-shared))
55 extra-objs += S$(start-installed-name)
56 install-lib += S$(start-installed-name)
57 endif
59 ifeq (yes,$(build-bounded))
60 extra-objs += b$(start-installed-name)
61 install-lib += b$(start-installed-name)
62 endif
64 ifneq ($(start-installed-name),$(static-start-installed-name))
65 extra-objs += $(static-start-installed-name) g$(static-start-installed-name)
66 omit-deps += $(patsubst %.o,%,$(static-start-installed-name) \
67 g$(static-start-installed-name))
68 install-lib += $(static-start-installed-name) g$(static-start-installed-name)
69 endif
71 ifeq (yes,$(elf))
72 before-compile += $(objpfx)abi-tag.h
73 generated += abi-tag.h
74 endif
76 ifneq (yes,$(gnu-ld))
77 libc-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 $@
81 generated += munch-init.c
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)))
87 endif
89 ifeq ($(have-initfini),yes)
91 CPPFLAGS += -DHAVE_INITFINI
93 # These are the special initializer/finalizer files. They are always the
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.
96 crtstuff = crti crtn
98 install-lib += $(crtstuff:=.o)
99 extra-objs += $(crtstuff:=.o)
100 generated += $(crtstuff:=.S) initfini.s defs.h
101 omit-deps += $(crtstuff)
103 # Special rules for the building of crti.o and crtn.o
104 $(crtstuff:%=$(objpfx)%.o): %.o: %.S $(objpfx)defs.h
105 $(compile.S) -g0 $(ASFLAGS-.os) -o $@
107 CFLAGS-initfini.s = -g0 -fPIC -fno-inline-functions $(fno-unit-at-a-time)
109 vpath initfini.c $(full_config_sysdirs)
111 $(objpfx)initfini.s: initfini.c $(before-compile)
112 $(compile.c) -S $(CFLAGS-initfini.s) -finhibit-size-directive \
113 $(patsubst -f%,-fno-%,$(exceptions)) -o $@
115 # We only have one kind of startup code files. Static binaries and
116 # shared libraries are build using the PIC version.
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' $< > $@
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' $< > $@
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
132 $(objpfx)defs.h: $(objpfx)initfini.s
133 sed -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
134 $(AWK) -f defs.awk > $@
136 endif
138 ifeq (yes,$(elf))
139 extra-objs += abi-note.o init.o
140 asm-CPPFLAGS += -I$(objpfx).
141 endif
143 include ../Rules
145 # Make these in the lib pass so they're available in time to link things with.
146 subdir_lib: $(extra-objs:%=$(objpfx)%)
148 define link-relocatable
149 $(CC) -nostdlib -nostartfiles -r -o $@ $^
150 endef
152 ifndef start-installed-name-rule
153 ifeq (yes,$(elf))
154 # We link the ELF startfile along with a SHT_NOTE section indicating
155 # the kernel ABI the binaries linked with this library will require.
156 $(objpfx)$(start-installed-name): $(objpfx)start.o $(objpfx)abi-note.o \
157 $(objpfx)init.o
158 $(link-relocatable)
159 $(objpfx)S$(start-installed-name): $(objpfx)start.os $(objpfx)abi-note.o \
160 $(objpfx)init.o
161 $(link-relocatable)
162 $(objpfx)b$(start-installed-name): $(objpfx)start.ob $(objpfx)abi-note.ob \
163 $(objpfx)init.ob
164 $(link-relocatable)
165 else
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
169 rm -f $@
170 ln $< $@
171 $(objpfx)S$(start-installed-name): $(objpfx)start.os
172 rm -f $@
173 ln $< $@
174 $(objpfx)b$(start-installed-name): $(objpfx)start.ob
175 rm -f $@
176 ln $< $@
177 endif
178 endif
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.
183 $(addprefix $(objpfx),$(sort g$(start-installed-name) \
184 g$(static-start-installed-name))): \
185 $(objpfx)g%: $(objpfx)% $(objpfx)gmon-start.o
186 $(link-relocatable)
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.
190 $(addprefix $(objpfx),$(filter-out $(start-installed-name), $(csu-dummies))):\
191 $(before-compile)
192 $(COMPILE.c) -o $@ -x c /dev/null
194 # These headers are used by the startup code.
195 $(objpfx)abi-tag.h: $(..)abi-tags
196 $(make-target-directory)
197 rm -f $@.new
198 sed -e 's/#.*$$//' -e '/^[ ]*$$/d' $< | \
199 while read conf tagos tagver; do \
200 test `expr '$(config-machine)-$(config-vendor)-$(config-os)' \
201 : "$$conf"` != 0 || continue; \
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; \
210 done
211 if test -r $@.new; then mv -f $@.new $@; \
212 else echo >&2 'This configuration not matched in $<'; exit 1; fi
214 all-Banner-files = $(wildcard $(addsuffix /Banner, \
215 $(addprefix $(..), $(subdirs))))
216 $(objpfx)version-info.h: $(common-objpfx)config.make $(all-Banner-files)
217 $(make-target-directory)
218 (case $(config-os) in \
219 linux*) version=`(printf '%s\n%s\n' \
220 '#include <linux/version.h>' \
221 UTS_RELEASE \
222 | $(CC) $(CPPFLAGS) -E -P - -DNOT_IN_libc=1 | \
223 sed -e 's/"\([^"]*\)".*/\1/p' -e d) 2>/dev/null`;\
224 if [ -z "$$version" ]; then \
225 if [ -r /proc/version ]; then \
226 version=`sed 's/.*Linux version \([^ ]*\) .*/>>\1<</' \
227 < /proc/version`; \
228 else \
229 version=`uname -r`; \
230 fi; \
231 fi; \
232 os=`uname -s 2> /dev/null`; \
233 if [ -z "$$os" ]; then \
234 os=Linux; \
235 fi; \
236 printf '"Compiled on a %s %s system on %s.\\n"\n' \
237 "$$os" "$$version" "`date +%Y-%m-%d`";; \
238 *) ;; \
239 esac; \
240 files="$(all-Banner-files)"; \
241 if test -n "$$files"; then \
242 echo "\"Available extensions:\\n\""; \
243 sed -e '/^#/d' -e 's/^[[:space:]]*/ /' \
244 -e 's/^\(.*\)$$/\"\1\\n\"/' $$files; \
245 fi) > $@T
246 mv -f $@T $@