1 # Makefile for csu code for GNU C library.
2 # Copyright (C) 1995,96,97,98,99,2000,01,2002 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 \
31 elide-routines.os
= libc-tls
32 csu-dummies
= $(filter-out $(start-installed-name
),crt1.o Mcrt1.o
)
33 extra-objs
= start.o gmon-start.o \
34 $(start-installed-name
) g
$(start-installed-name
) $(csu-dummies
)
35 omit-deps
= $(patsubst %.o
,%,$(start-installed-name
) g
$(start-installed-name
) \
36 b
$(start-installed-name
) $(csu-dummies
))
37 install-lib
= $(start-installed-name
) g
$(start-installed-name
) $(csu-dummies
)
38 distribute
= initfini.c gmon-start.c start.c defs.awk munch.awk \
39 abi-note.S init.c munch-tmpl.c
40 generated
= version-info.h
41 before-compile
= $(objpfx
)version-info.h
43 all: # Make this the default target; it will be defined in Rules.
47 ifeq (yes
,$(build-bounded
))
48 extra-objs
+= b
$(start-installed-name
)
49 install-lib
+= b
$(start-installed-name
)
52 ifneq ($(start-installed-name
),$(static-start-installed-name
))
53 extra-objs
+= $(static-start-installed-name
) g
$(static-start-installed-name
)
54 omit-deps
+= $(patsubst %.o
,%,$(static-start-installed-name
) \
55 g
$(static-start-installed-name
))
56 install-lib
+= $(static-start-installed-name
) g
$(static-start-installed-name
)
60 before-compile
+= $(objpfx
)abi-tag.h
61 generated
+= abi-tag.h
65 libc-init
= munch-init
66 $(objpfx
)munch-init.c
: munch.awk munch-tmpl.c
$(+subdir_inits
)
67 $(AWK
) -f
$< subdirs
='$(+init_subdirs)' $(word 2,$^
) > $@
-t
69 generated
+= munch-init.c
71 # All initialization source files.
72 +subdir_inits
:= $(wildcard $(foreach dir,$(subdirs
),$(dir)/init-
$(dir).c
))
73 # All subdirectories containing initialization source files.
74 +init_subdirs
:= $(patsubst %/,%,$(dir $(+subdir_inits
)))
77 ifeq ($(have-initfini
),yes
)
79 CPPFLAGS
+= -DHAVE_INITFINI
81 # These are the special initializer/finalizer files. They are always the
82 # first and last file in the link. crti.o ... crtn.o define the global
83 # "functions" _init and _fini to run the .init and .fini sections.
86 install-lib
+= $(crtstuff
:=.o
)
87 extra-objs
+= $(crtstuff
:=.o
)
88 generated
+= $(crtstuff
:=.S
) initfini.s defs.h
89 omit-deps
+= $(crtstuff
)
91 # Special rules for the building of crti.o and crtn.o
92 $(objpfx
)crt
%.o
: $(objpfx
)crt
%.S
$(objpfx
)defs.h
93 $(compile.S
) -g0
$(ASFLAGS-.os
) -o
$@
95 CFLAGS-initfini.s
= -g0
-fPIC
-fno-inline-functions
97 vpath initfini.c
$(full_config_sysdirs
)
99 $(objpfx
)initfini.s
: initfini.c
100 $(compile.c
) -S
$(CFLAGS-initfini.s
) -finhibit-size-directive \
101 $(patsubst -f
%,-fno-
%,$(exceptions
)) -o
$@
103 # We only have one kind of startup code files. Static binaries and
104 # shared libraries are build using the PIC version.
105 $(objpfx
)crti.S
: $(objpfx
)initfini.s
106 sed
-n
-e
'1,/@HEADER_ENDS/p' \
107 -e
'/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
108 -e
'/@TRAILER_BEGINS/,$$p' $< > $@
110 $(objpfx
)crtn.S
: $(objpfx
)initfini.s
111 sed
-n
-e
'1,/@HEADER_ENDS/p' \
112 -e
'/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \
113 -e
'/@TRAILER_BEGINS/,$$p' $< > $@
115 $(objpfx
)defs.h
: $(objpfx
)initfini.s
116 sed
-n
-e
'/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
117 $(AWK
) -f defs.awk
> $@
122 extra-objs
+= abi-note.o init.o
123 asm-CPPFLAGS
+= -I
$(objpfx
).
128 # Make these in the lib pass so they're available in time to link things with.
129 subdir_lib
: $(extra-objs
:%=$(objpfx
)%)
131 define link-relocatable
132 $(CC
) -nostdlib
-nostartfiles
-r
-o
$@
$^
135 ifndef start-installed-name-rule
137 # We link the ELF startfile along with a SHT_NOTE section indicating
138 # the kernel ABI the binaries linked with this library will require.
139 $(objpfx
)$(start-installed-name
): $(objpfx
)start.o
$(objpfx
)abi-note.o \
142 $(objpfx
)b
$(start-installed-name
): $(objpfx
)start.ob
$(objpfx
)abi-note.ob \
146 # The startfile is installed under different names, so we just call our
147 # source file `start.c' and copy to the installed name after compiling.
148 $(objpfx
)$(start-installed-name
): $(objpfx
)start.o
151 $(objpfx
)b
$(start-installed-name
): $(objpfx
)start.ob
157 # The profiling startfile is made by linking together the normal
158 # startfile with gmon-start.o, which defines a constructor function
159 # to turn on profiling code at startup.
160 $(addprefix $(objpfx
),$(sort g
$(start-installed-name
) \
161 g
$(static-start-installed-name
))): \
162 $(objpfx
)g
%: $(objpfx
)% $(objpfx
)gmon-start.o
165 # These extra files are sometimes expected by system standard linking
166 # procedures, but we have nothing for them to do. So compile empty files.
167 $(addprefix $(objpfx
),$(filter-out $(start-installed-name
),$(csu-dummies
))):
170 $(COMPILE.c
) $(@
:.o
=.c
) $(OUTPUT_OPTION
)
173 # These headers are used by the startup code.
174 $(objpfx
)abi-tag.h
: $(..
)abi-tags
175 $(make-target-directory
)
177 sed
-e
's/#.*$$//' -e
'/^[ ]*$$/d' $< | \
178 while read conf tagos tagver
; do \
179 test `expr '$(config-machine)-$(config-vendor)-$(config-os)' \
180 : "$$conf"` != 0 || continue
; \
182 sed
-e
's/[^0-9xXa-fA-F ]//' \
183 -e
's/^/#define __ABI_TAG_OS /'; \
184 echo
"#ifndef __ABI_TAG_VERSION"; \
186 sed
-e
's/[^0-9xXa-fA-F]/ /g' -e
's/ *$$//' \
187 -e
's/ /,/g' -e
's/^/# define __ABI_TAG_VERSION /'; \
188 echo
"#endif" ) > $@.new
; \
190 if
test -r
$@.new
; then mv
-f
$@.new
$@
; \
191 else echo
>&2 'This configuration not matched in $<'; exit
1; fi
193 all-Banner-files
= $(wildcard $(addsuffix /Banner
, \
194 $(addprefix $(..
), $(subdirs
))))
195 $(objpfx
)version-info.h
: $(common-objpfx
)config.make
$(all-Banner-files
)
196 $(make-target-directory
)
197 (case
$(config-os
) in \
198 linux
*) version
=`(echo -e "#include <linux/version.h>\nUTS_RELEASE"\
200 sed -e 's/"\([^"]*\)".*/\1/p' -e d) 2>/dev/null`;\
201 if
[ -z
"$$version" ]; then \
202 if
[ -r
/proc
/version
]; then \
203 version
=`sed 's/.*Linux version \([^ ]*\) .*/>>\1<</' \
206 version
=`uname -r`; \
209 os
=`uname -s 2> /dev/null`; \
210 if
[ -z
"$$os" ]; then \
213 echo
"\"Compiled on a $$os $$version system" \
214 "on `date +%Y-%m-%d`.\\n\"" ;; \
217 files
="$(all-Banner-files)"; \
218 if
test -n
"$$files"; then \
219 echo
"\"Available extensions:\\n\""; \
220 sed
-e
'/^#/d' -e
's/^[[:space:]]*/ /' \
221 -e
's/\(^.*$$\)/\"\1\\n\"/' $$files; \