1 # Makefile for csu code for GNU C library.
3 # Copyright (C) 1995,96,97,98,99,2000,01 Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Library General Public License
8 # as published by the Free Software Foundation; either version 2 of
9 # the License, or (at your option) any later version.
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Library General Public License for more details.
16 # You should have received a copy of the GNU Library General Public
17 # License along with the GNU C Library; see the file COPYING.LIB. If not,
18 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 # Boston, MA 02111-1307, USA.
21 # This directory contains the C startup code (that which calls main). This
22 # consists of the startfile, built from start.c and installed as crt0.o
23 # (traditionally) or crt1.o (for ELF). In ELF we also install crti.o and
24 # crtn.o, special "initializer" and "finalizer" files used in the link
25 # to make the .init and .fini sections work right; both these files are
26 # built (in an arcane manner) from initfini.c.
30 routines
= init-first libc-start
$(libc-init
) sysdep version check_fds
31 csu-dummies
= $(filter-out $(start-installed-name
),crt1.o Mcrt1.o
)
32 extra-objs
= start.o gmon-start.o \
33 $(start-installed-name
) g
$(start-installed-name
) $(csu-dummies
)
34 omit-deps
= $(patsubst %.o
,%,$(start-installed-name
) g
$(start-installed-name
) \
35 b
$(start-installed-name
) $(csu-dummies
))
36 install-lib
= $(start-installed-name
) g
$(start-installed-name
) $(csu-dummies
)
37 distribute
= initfini.c gmon-start.c start.c defs.awk munch.awk \
38 abi-note.S init.c munch-tmpl.c
39 generated
= version-info.h
40 before-compile
= $(objpfx
)version-info.h
42 all: # Make this the default target; it will be defined in Rules.
46 ifeq (yes
,$(build-bounded
))
47 extra-objs
+= b
$(start-installed-name
)
48 install-lib
+= b
$(start-installed-name
)
51 ifneq ($(start-installed-name
),$(static-start-installed-name
))
52 extra-objs
+= $(static-start-installed-name
) g
$(static-start-installed-name
)
53 omit-deps
+= $(patsubst %.o
,%,$(static-start-installed-name
) \
54 g
$(static-start-installed-name
))
55 install-lib
+= $(static-start-installed-name
) g
$(static-start-installed-name
)
59 before-compile
+= $(objpfx
)abi-tag.h
60 generated
+= abi-tag.h
66 libc-init
= munch-init
67 $(objpfx
)munch-init.c
: munch.awk munch-tmpl.c
$(+subdir_inits
)
68 $(AWK
) -f
$< subdirs
='$(+init_subdirs)' $(word 2,$^
) > $@
-t
70 generated
+= munch-init.c
72 # All initialization source files.
73 +subdir_inits
:= $(wildcard $(foreach dir,$(subdirs
),$(dir)/init-
$(dir).c
))
74 # All subdirectories containing initialization source files.
75 +init_subdirs
:= $(patsubst %/,%,$(dir $(+subdir_inits
)))
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 $(objpfx
)crt
%.o
: $(objpfx
)crt
%.S
$(objpfx
)defs.h
94 $(compile.S
) -g0
$(ASFLAGS-.os
) -o
$@
96 CFLAGS-initfini.s
= -g0
-fPIC
-fno-inline-functions
98 vpath initfini.c
$(full_config_sysdirs
)
100 $(objpfx
)initfini.s
: initfini.c
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 $(objpfx
)defs.h
: $(objpfx
)initfini.s
117 sed
-n
-e
'/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
118 $(AWK
) -f defs.awk
> $@
123 extra-objs
+= abi-note.o init.o
124 asm-CPPFLAGS
+= -I
$(objpfx
).
129 # Make these in the lib pass so they're available in time to link things with.
130 subdir_lib
: $(extra-objs
:%=$(objpfx
)%)
132 define link-relocatable
133 $(CC
) -nostdlib
-nostartfiles
-r
-o
$@
$^
136 ifndef start-installed-name-rule
138 # We link the ELF startfile along with a SHT_NOTE section indicating
139 # the kernel ABI the binaries linked with this library will require.
140 $(objpfx
)$(start-installed-name
): $(objpfx
)start.o
$(objpfx
)abi-note.o \
143 $(objpfx
)b
$(start-installed-name
): $(objpfx
)start.ob
$(objpfx
)abi-note.ob \
147 # The startfile is installed under different names, so we just call our
148 # source file `start.c' and copy to the installed name after compiling.
149 $(objpfx
)$(start-installed-name
): $(objpfx
)start.o
152 $(objpfx
)b
$(start-installed-name
): $(objpfx
)start.ob
158 # The profiling startfile is made by linking together the normal
159 # startfile with gmon-start.o, which defines a constructor function
160 # to turn on profiling code at startup.
161 $(addprefix $(objpfx
),$(sort g
$(start-installed-name
) \
162 g
$(static-start-installed-name
))): \
163 $(objpfx
)g
%: $(objpfx
)% $(objpfx
)gmon-start.o
166 # These extra files are sometimes expected by system standard linking
167 # procedures, but we have nothing for them to do. So compile empty files.
168 $(addprefix $(objpfx
),$(filter-out $(start-installed-name
),$(csu-dummies
))):
171 $(COMPILE.c
) $(@
:.o
=.c
) $(OUTPUT_OPTION
)
174 # These headers are used by the startup code.
175 $(objpfx
)abi-tag.h
: $(..
)abi-tags
176 $(make-target-directory
)
178 sed
-e
's/#.*$$//' -e
'/^[ ]*$$/d' $< | \
179 while read conf tagos tagver
; do \
180 test `expr '$(config-machine)-$(config-vendor)-$(config-os)' \
181 : "$$conf"` != 0 || continue
; \
183 sed
-e
's/[^0-9xXa-fA-F ]//' \
184 -e
's/^/#define __ABI_TAG_OS /'; \
185 echo
"#ifndef __ABI_TAG_VERSION"; \
187 sed
-e
's/[^0-9xXa-fA-F]/ /g' -e
's/ *$$//' \
188 -e
's/ /,/g' -e
's/^/# define __ABI_TAG_VERSION /'; \
189 echo
"#endif" ) > $@.new
; \
191 if
test -r
$@.new
; then mv
-f
$@.new
$@
; \
192 else echo
>&2 'This configuration not matched in $<'; exit
1; fi
194 all-Banner-files
= $(wildcard $(addsuffix /Banner
, \
195 $(addprefix $(..
), $(subdirs
))))
196 $(objpfx
)version-info.h
: $(common-objpfx
)config.make
$(all-Banner-files
)
197 $(make-target-directory
)
198 (case
$(config-os
) in \
199 linux
*) version
=`(echo -e "#include <linux/version.h>\nUTS_RELEASE"\
201 sed -e 's/"\([^"]*\)".*/\1/p' -e d) 2>/dev/null`;\
202 if
[ -z
"$$version" ]; then \
203 if
[ -r
/proc
/version
]; then \
204 version
=`sed 's/.*Linux version \([^ ]*\) .*/>>\1<</' \
207 version
=`uname -r`; \
210 os
=`uname -s 2> /dev/null`; \
211 if
[ -z
"$$os" ]; then \
214 echo
"\"Compiled on a $$os $$version system" \
215 "on `date +%Y-%m-%d`.\\n\"" ;; \
218 files
="$(all-Banner-files)"; \
219 if
test -n
"$$files"; then \
220 echo
"\"Available extensions:\\n\""; \
221 sed
-e
'/^#/d' -e
's/^[[:space:]]*/ /' \
222 -e
's/\(^.*$$\)/\"\1\\n\"/' $$files; \