]> sourceware.org Git - glibc.git/blame - csu/Makefile
2005-12-13 Ulrich Drepper <drepper@redhat.com>
[glibc.git] / csu / Makefile
CommitLineData
28f540f4 1# Makefile for csu code for GNU C library.
95fa8590 2# Copyright (C) 1995-2004, 2005 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)
57d44131
UD
42distribute = initfini.c gmon-start.c start.c defs.awk \
43 abi-note.S init.c 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)
95fa8590 57generated += start.os
bc4647a1
UD
58endif
59
ac556388
GM
60ifeq (yes,$(build-bounded))
61extra-objs += b$(start-installed-name)
62install-lib += b$(start-installed-name)
95fa8590 63generated += start.ob
ac556388
GM
64endif
65
083973f3
RM
66ifneq ($(start-installed-name),$(static-start-installed-name))
67extra-objs += $(static-start-installed-name) g$(static-start-installed-name)
68omit-deps += $(patsubst %.o,%,$(static-start-installed-name) \
69 g$(static-start-installed-name))
70install-lib += $(static-start-installed-name) g$(static-start-installed-name)
71endif
72
c7562c74
UD
73ifeq (yes,$(elf))
74before-compile += $(objpfx)abi-tag.h
da2d1bc5 75generated += abi-tag.h
a5a0310d 76endif
b8dc6a10 77
307bcd77 78ifeq ($(have-initfini),yes)
37f91d33 79
294897f4
RM
80CPPFLAGS += -DHAVE_INITFINI
81
37f91d33 82# These are the special initializer/finalizer files. They are always the
4e1bac76
RM
83# first and last file in the link. crti.o ... crtn.o define the global
84# "functions" _init and _fini to run the .init and .fini sections.
85crtstuff = crti crtn
37f91d33
RM
86
87install-lib += $(crtstuff:=.o)
88extra-objs += $(crtstuff:=.o)
9a0a462c 89generated += $(crtstuff:=.S) initfini.s defs.h
37f91d33 90omit-deps += $(crtstuff)
28f540f4 91
307bcd77 92# Special rules for the building of crti.o and crtn.o
4b0b5882 93$(crtstuff:%=$(objpfx)%.o): %.o: %.S $(objpfx)defs.h
f41c8091 94 $(compile.S) -g0 $(ASFLAGS-.os) -o $@
307bcd77 95
49803108 96CFLAGS-initfini.s = -g0 -fPIC -fno-inline-functions $(fno-unit-at-a-time)
9a0a462c 97
a334319f 98vpath initfini.c $(full_config_sysdirs)
93414bb9 99
05d3d580 100$(objpfx)initfini.s: initfini.c $(before-compile)
9a0a462c 101 $(compile.c) -S $(CFLAGS-initfini.s) -finhibit-size-directive \
e1b13a63 102 $(patsubst -f%,-fno-%,$(exceptions)) -o $@
307bcd77 103
0f9cc699 104# We only have one kind of startup code files. Static binaries and
5ae3e846 105# shared libraries are build using the PIC version.
307bcd77
UD
106$(objpfx)crti.S: $(objpfx)initfini.s
107 sed -n -e '1,/@HEADER_ENDS/p' \
108 -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
109 -e '/@TRAILER_BEGINS/,$$p' $< > $@
110
111$(objpfx)crtn.S: $(objpfx)initfini.s
112 sed -n -e '1,/@HEADER_ENDS/p' \
113 -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \
114 -e '/@TRAILER_BEGINS/,$$p' $< > $@
115
adee0e1f
RM
116# These explicit rules are necessary when the $(objpfx) subdirectory
117# did not exist at the time make considered the implicit rules using it.
118# This comes up with a fresh build using no_deps=t.
119$(patsubst %,$(objpfx)crt%.o,i n): %.o: %.S
120
307bcd77
UD
121$(objpfx)defs.h: $(objpfx)initfini.s
122 sed -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
5aa8ff62 123 $(AWK) -f defs.awk > $@
28f540f4 124
37f91d33 125endif
28f540f4 126
51702635 127ifeq (yes,$(elf))
6973fc01 128extra-objs += abi-note.o init.o
92f1da4d 129asm-CPPFLAGS += -I$(objpfx).
51702635
UD
130endif
131
28f540f4
RM
132include ../Rules
133
71cf0361
UD
134# Make these in the lib pass so they're available in time to link things with.
135subdir_lib: $(extra-objs:%=$(objpfx)%)
136
779ae82e
UD
137define link-relocatable
138$(CC) -nostdlib -nostartfiles -r -o $@ $^
139endef
140
b8dc6a10 141ifndef start-installed-name-rule
779ae82e
UD
142ifeq (yes,$(elf))
143# We link the ELF startfile along with a SHT_NOTE section indicating
3081378b 144# the kernel ABI the binaries linked with this library will require.
6973fc01
UD
145$(objpfx)$(start-installed-name): $(objpfx)start.o $(objpfx)abi-note.o \
146 $(objpfx)init.o
779ae82e 147 $(link-relocatable)
bc4647a1
UD
148$(objpfx)S$(start-installed-name): $(objpfx)start.os $(objpfx)abi-note.o \
149 $(objpfx)init.o
150 $(link-relocatable)
58ff985d
GM
151$(objpfx)b$(start-installed-name): $(objpfx)start.ob $(objpfx)abi-note.ob \
152 $(objpfx)init.ob
153 $(link-relocatable)
779ae82e 154else
28f540f4
RM
155# The startfile is installed under different names, so we just call our
156# source file `start.c' and copy to the installed name after compiling.
157$(objpfx)$(start-installed-name): $(objpfx)start.o
779ae82e 158 rm -f $@
28f540f4 159 ln $< $@
bc4647a1
UD
160$(objpfx)S$(start-installed-name): $(objpfx)start.os
161 rm -f $@
162 ln $< $@
98186375
GM
163$(objpfx)b$(start-installed-name): $(objpfx)start.ob
164 rm -f $@
165 ln $< $@
b8dc6a10 166endif
779ae82e 167endif
28f540f4 168
11c981a9
RM
169# The profiling startfile is made by linking together the normal
170# startfile with gmon-start.o, which defines a constructor function
171# to turn on profiling code at startup.
083973f3
RM
172$(addprefix $(objpfx),$(sort g$(start-installed-name) \
173 g$(static-start-installed-name))): \
174 $(objpfx)g%: $(objpfx)% $(objpfx)gmon-start.o
779ae82e 175 $(link-relocatable)
11c981a9 176
28f540f4
RM
177# These extra files are sometimes expected by system standard linking
178# procedures, but we have nothing for them to do. So compile empty files.
b6da933b 179$(addprefix $(objpfx),$(filter-out $(start-installed-name), $(csu-dummies))):\
c6696b79
RM
180 $(before-compile)
181 $(COMPILE.c) -o $@ -x c /dev/null
92f1da4d 182
c7562c74 183# These headers are used by the startup code.
92f1da4d 184$(objpfx)abi-tag.h: $(..)abi-tags
39e16978 185 $(make-target-directory)
92f1da4d 186 rm -f $@.new
0f9cc699 187 sed -e 's/#.*$$//' -e '/^[ ]*$$/d' $< | \
a986484f 188 while read conf tagos tagver; do \
92f1da4d
UD
189 test `expr '$(config-machine)-$(config-vendor)-$(config-os)' \
190 : "$$conf"` != 0 || continue; \
a986484f
UD
191 ( echo "$$tagos" | \
192 sed -e 's/[^0-9xXa-fA-F ]//' \
193 -e 's/^/#define __ABI_TAG_OS /'; \
194 echo "#ifndef __ABI_TAG_VERSION"; \
195 echo "$$tagver" | \
196 sed -e 's/[^0-9xXa-fA-F]/ /g' -e 's/ *$$//' \
197 -e 's/ /,/g' -e 's/^/# define __ABI_TAG_VERSION /'; \
198 echo "#endif" ) > $@.new; \
92f1da4d
UD
199 done
200 if test -r $@.new; then mv -f $@.new $@; \
201 else echo >&2 'This configuration not matched in $<'; exit 1; fi
c7562c74 202
a334319f
UD
203all-Banner-files = $(wildcard $(addsuffix /Banner, \
204 $(addprefix $(..), $(subdirs))))
c7562c74
UD
205$(objpfx)version-info.h: $(common-objpfx)config.make $(all-Banner-files)
206 $(make-target-directory)
207 (case $(config-os) in \
e7f4d2bf
RM
208 linux*) version=`(printf '%s\n%s\n' \
209 '#include <linux/version.h>' \
210 UTS_RELEASE \
b30542fb 211 | $(CC) $(CPPFLAGS) -E -P - -DNOT_IN_libc=1 | \
c7562c74
UD
212 sed -e 's/"\([^"]*\)".*/\1/p' -e d) 2>/dev/null`;\
213 if [ -z "$$version" ]; then \
214 if [ -r /proc/version ]; then \
b48abe3c 215 version=`sed 's/.*Linux version \([^ ]*\) .*/>>\1<</' \
c7562c74
UD
216 < /proc/version`; \
217 else \
218 version=`uname -r`; \
219 fi; \
220 fi; \
c269fdb4
UD
221 os=`uname -s 2> /dev/null`; \
222 if [ -z "$$os" ]; then \
223 os=Linux; \
224 fi; \
e7f4d2bf
RM
225 printf '"Compiled on a %s %s system on %s.\\n"\n' \
226 "$$os" "$$version" "`date +%Y-%m-%d`";; \
c7562c74
UD
227 *) ;; \
228 esac; \
229 files="$(all-Banner-files)"; \
230 if test -n "$$files"; then \
9db670f0 231 printf '"Available extensions:\\n"\n'; \
0f9cc699 232 sed -e '/^#/d' -e 's/^[[:space:]]*/ /' \
63461e75 233 -e 's/^\(.*\)$$/\"\1\\n\"/' $$files; \
c7562c74
UD
234 fi) > $@T
235 mv -f $@T $@
This page took 0.246657 seconds and 5 git commands to generate.