1 # Makefile for csu code for GNU C library.
2 # Copyright (C) 1995-2004, 2005, 2006 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
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.
29 routines
= init-first libc-start
$(libc-init
) sysdep version check_fds \
30 libc-tls elf-init dso_handle
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 \
43 abi-note.S init.c 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.
54 ifeq (yes
,$(build-shared
))
55 extra-objs
+= S
$(start-installed-name
)
56 install-lib
+= S
$(start-installed-name
)
60 ifeq (yes
,$(build-bounded
))
61 extra-objs
+= b
$(start-installed-name
)
62 install-lib
+= b
$(start-installed-name
)
66 ifneq ($(start-installed-name
),$(static-start-installed-name
))
67 extra-objs
+= $(static-start-installed-name
) g
$(static-start-installed-name
)
68 omit-deps
+= $(patsubst %.o
,%,$(static-start-installed-name
) \
69 g
$(static-start-installed-name
))
70 install-lib
+= $(static-start-installed-name
) g
$(static-start-installed-name
)
74 before-compile
+= $(objpfx
)abi-tag.h
75 generated
+= abi-tag.h
78 ifeq ($(have-initfini
),yes
)
80 CPPFLAGS
+= -DHAVE_INITFINI
82 # These are the special initializer/finalizer files. They are always the
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.
87 install-lib
+= $(crtstuff
:=.o
)
88 extra-objs
+= $(crtstuff
:=.o
)
89 generated
+= $(crtstuff
:=.S
) initfini.s defs.h
90 omit-deps
+= $(crtstuff
)
92 # Special rules for the building of crti.o and crtn.o
93 $(crtstuff
:%=$(objpfx
)%.o
): %.o
: %.S
$(objpfx
)defs.h
94 $(compile.S
) -g0
$(ASFLAGS-.os
) -o
$@
96 CFLAGS-initfini.s
= -g0
-fPIC
-fno-inline-functions
$(fno-unit-at-a-time
)
98 vpath initfini.c
$(sysdirs
)
100 $(objpfx
)initfini.s
: initfini.c
$(before-compile
)
101 $(compile.c
) -S
$(CFLAGS-initfini.s
) -finhibit-size-directive \
102 $(patsubst -f
%,-fno-
%,$(exceptions
)) -o
$@
104 # We only have one kind of startup code files. Static binaries and
105 # shared libraries are build using the PIC version.
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' $< > $@
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' $< > $@
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
121 $(objpfx
)defs.h
: $(objpfx
)initfini.s
122 sed
-n
-e
'/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
123 $(AWK
) -f defs.awk
> $@
128 extra-objs
+= abi-note.o init.o
129 asm-CPPFLAGS
+= -I
$(objpfx
).
134 # Make these in the lib pass so they're available in time to link things with.
135 subdir_lib
: $(extra-objs
:%=$(objpfx
)%)
137 define link-relocatable
138 $(CC
) -nostdlib
-nostartfiles
-r
-o
$@
$^
141 ifndef start-installed-name-rule
143 # We link the ELF startfile along with a SHT_NOTE section indicating
144 # the kernel ABI the binaries linked with this library will require.
145 $(objpfx
)$(start-installed-name
): $(objpfx
)start.o
$(objpfx
)abi-note.o \
148 $(objpfx
)S
$(start-installed-name
): $(objpfx
)start.os
$(objpfx
)abi-note.o \
151 $(objpfx
)b
$(start-installed-name
): $(objpfx
)start.ob
$(objpfx
)abi-note.ob \
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
160 $(objpfx
)S
$(start-installed-name
): $(objpfx
)start.os
163 $(objpfx
)b
$(start-installed-name
): $(objpfx
)start.ob
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.
172 $(addprefix $(objpfx
),$(sort g
$(start-installed-name
) \
173 g
$(static-start-installed-name
))): \
174 $(objpfx
)g
%: $(objpfx
)% $(objpfx
)gmon-start.o
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.
179 $(addprefix $(objpfx
),$(filter-out $(start-installed-name
), $(csu-dummies
))):\
181 $(COMPILE.c
) -o
$@
-x c
/dev
/null
183 # These headers are used by the startup code.
184 $(objpfx
)abi-tag.h
: $(..
)abi-tags
185 $(make-target-directory
)
187 sed
-e
's/#.*$$//' -e
'/^[ ]*$$/d' $< | \
188 while read conf tagos tagver
; do \
189 test `expr '$(config-machine)-$(config-vendor)-$(config-os)' \
190 : "$$conf"` != 0 || continue
; \
192 sed
-e
's/[^0-9xXa-fA-F ]//' \
193 -e
's/^/#define __ABI_TAG_OS /'; \
194 echo
"#ifndef __ABI_TAG_VERSION"; \
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
; \
200 if
test -r
$@.new
; then mv
-f
$@.new
$@
; \
201 else echo
>&2 'This configuration not matched in $<'; exit
1; fi
203 all-Banner-files
= $(wildcard $(addsuffix /Banner
,\
204 $(sort $(subdir-srcdirs
) \
205 $(sysdeps-srcdirs
))))
206 $(objpfx
)version-info.h
: $(common-objpfx
)config.make
$(all-Banner-files
)
207 $(make-target-directory
)
208 (case
$(config-os
) in \
209 linux
*) version
=`(printf '%s\n%s\n' \
210 '#include <linux/version.h>' \
212 | $(CC) $(CPPFLAGS) -E -P - -DNOT_IN_libc=1 | \
213 sed -e 's/"\([^"]*\)".*/\1/p' -e d) 2>/dev/null`;\
214 if
[ -z
"$$version" ]; then \
215 if
[ -r
/proc
/version
]; then \
216 version
=`sed 's/.*Linux version \([^ ]*\) .*/>>\1<</' \
219 version
=`uname -r`; \
222 os
=`uname -s 2> /dev/null`; \
223 if
[ -z
"$$os" ]; then \
226 printf
'"Compiled on a %s %s system on %s.\\n"\n' \
227 "$$os" "$$version" "`date +%Y-%m-%d`";; \
230 files
="$(all-Banner-files)"; \
231 if
test -n
"$$files"; then \
232 printf
'"Available extensions:\\n"\n'; \
233 sed
-e
'/^#/d' -e
's/^[[:space:]]*/ /' \
234 -e
's/^\(.*\)$$/\"\1\\n\"/' $$files; \