]> git.ipfire.org Git - thirdparty/glibc.git/blob - csu/Makefile
2003-04-11 Roland McGrath <roland@redhat.com>
[thirdparty/glibc.git] / csu / Makefile
1 # Makefile for csu code for GNU C library.
2 # Copyright (C) 1995,96,97,98,99,2000,01,02,2003 Free Software Foundation, Inc.
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
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.
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
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14
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.
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
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.
26
27 subdir := csu
28
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 omit-deps = $(patsubst %.o,%,$(start-installed-name) g$(start-installed-name) \
38 b$(start-installed-name) $(csu-dummies))
39 install-lib = $(start-installed-name) g$(start-installed-name) $(csu-dummies)
40 distribute = initfini.c gmon-start.c start.c defs.awk munch.awk \
41 abi-note.S init.c munch-tmpl.c
42 generated = version-info.h
43 before-compile = $(objpfx)version-info.h
44
45 tests := tst-empty tst-atomic tst-atomic-long
46 tests-static := tst-empty
47
48 all: # Make this the default target; it will be defined in Rules.
49
50 include ../Makeconfig
51
52 ifeq (yes,$(build-bounded))
53 extra-objs += b$(start-installed-name)
54 install-lib += b$(start-installed-name)
55 endif
56
57 ifneq ($(start-installed-name),$(static-start-installed-name))
58 extra-objs += $(static-start-installed-name) g$(static-start-installed-name)
59 omit-deps += $(patsubst %.o,%,$(static-start-installed-name) \
60 g$(static-start-installed-name))
61 install-lib += $(static-start-installed-name) g$(static-start-installed-name)
62 endif
63
64 ifeq (yes,$(elf))
65 before-compile += $(objpfx)abi-tag.h
66 generated += abi-tag.h
67 endif
68
69 ifneq (yes,$(gnu-ld))
70 libc-init = munch-init
71 $(objpfx)munch-init.c: munch.awk munch-tmpl.c $(+subdir_inits)
72 $(AWK) -f $< subdirs='$(+init_subdirs)' $(word 2,$^) > $@-t
73 mv -f $@-t $@
74 generated += munch-init.c
75
76 # All initialization source files.
77 +subdir_inits := $(wildcard $(foreach dir,$(subdirs),$(dir)/init-$(dir).c))
78 # All subdirectories containing initialization source files.
79 +init_subdirs := $(patsubst %/,%,$(dir $(+subdir_inits)))
80 endif
81
82 ifeq ($(have-initfini),yes)
83
84 CPPFLAGS += -DHAVE_INITFINI
85
86 # We don't want this compiled with PIC.
87 # It's never included in shared libraries, unlike the rest of libc_nonshared.a.
88 CPPFLAGS-elf-init.oS = $(patsubst %,-UPIC,$(pic-ccflag))
89 CFLAGS-elf-init.oS = $(patsubst -f%,-fno-%,$(pic-ccflag))
90
91 # These are the special initializer/finalizer files. They are always the
92 # first and last file in the link. crti.o ... crtn.o define the global
93 # "functions" _init and _fini to run the .init and .fini sections.
94 crtstuff = crti crtn
95
96 install-lib += $(crtstuff:=.o)
97 extra-objs += $(crtstuff:=.o)
98 generated += $(crtstuff:=.S) initfini.s defs.h
99 omit-deps += $(crtstuff)
100
101 # Special rules for the building of crti.o and crtn.o
102 $(objpfx)crt%.o: $(objpfx)crt%.S $(objpfx)defs.h
103 $(compile.S) -g0 $(ASFLAGS-.os) -o $@
104
105 CFLAGS-initfini.s = -g0 -fPIC -fno-inline-functions
106
107 vpath initfini.c $(full_config_sysdirs)
108
109 $(objpfx)initfini.s: initfini.c
110 $(compile.c) -S $(CFLAGS-initfini.s) -finhibit-size-directive \
111 $(patsubst -f%,-fno-%,$(exceptions)) -o $@
112
113 # We only have one kind of startup code files. Static binaries and
114 # shared libraries are build using the PIC version.
115 $(objpfx)crti.S: $(objpfx)initfini.s
116 sed -n -e '1,/@HEADER_ENDS/p' \
117 -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
118 -e '/@TRAILER_BEGINS/,$$p' $< > $@
119
120 $(objpfx)crtn.S: $(objpfx)initfini.s
121 sed -n -e '1,/@HEADER_ENDS/p' \
122 -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \
123 -e '/@TRAILER_BEGINS/,$$p' $< > $@
124
125 # These explicit rules are necessary when the $(objpfx) subdirectory
126 # did not exist at the time make considered the implicit rules using it.
127 # This comes up with a fresh build using no_deps=t.
128 $(patsubst %,$(objpfx)crt%.o,i n): %.o: %.S
129
130 $(objpfx)defs.h: $(objpfx)initfini.s
131 sed -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
132 $(AWK) -f defs.awk > $@
133
134 endif
135
136 ifeq (yes,$(elf))
137 extra-objs += abi-note.o init.o
138 asm-CPPFLAGS += -I$(objpfx).
139 endif
140
141 include ../Rules
142
143 # Make these in the lib pass so they're available in time to link things with.
144 subdir_lib: $(extra-objs:%=$(objpfx)%)
145
146 define link-relocatable
147 $(CC) -nostdlib -nostartfiles -r -o $@ $^
148 endef
149
150 ifndef start-installed-name-rule
151 ifeq (yes,$(elf))
152 # We link the ELF startfile along with a SHT_NOTE section indicating
153 # the kernel ABI the binaries linked with this library will require.
154 $(objpfx)$(start-installed-name): $(objpfx)start.o $(objpfx)abi-note.o \
155 $(objpfx)init.o
156 $(link-relocatable)
157 $(objpfx)b$(start-installed-name): $(objpfx)start.ob $(objpfx)abi-note.ob \
158 $(objpfx)init.ob
159 $(link-relocatable)
160 else
161 # The startfile is installed under different names, so we just call our
162 # source file `start.c' and copy to the installed name after compiling.
163 $(objpfx)$(start-installed-name): $(objpfx)start.o
164 rm -f $@
165 ln $< $@
166 $(objpfx)b$(start-installed-name): $(objpfx)start.ob
167 rm -f $@
168 ln $< $@
169 endif
170 endif
171
172 # The profiling startfile is made by linking together the normal
173 # startfile with gmon-start.o, which defines a constructor function
174 # to turn on profiling code at startup.
175 $(addprefix $(objpfx),$(sort g$(start-installed-name) \
176 g$(static-start-installed-name))): \
177 $(objpfx)g%: $(objpfx)% $(objpfx)gmon-start.o
178 $(link-relocatable)
179
180 # These extra files are sometimes expected by system standard linking
181 # procedures, but we have nothing for them to do. So compile empty files.
182 $(addprefix $(objpfx),$(filter-out $(start-installed-name),$(csu-dummies))):
183 @-rm -f $(@:.o=.c)
184 echo > $(@:.o=.c)
185 $(COMPILE.c) $(@:.o=.c) $(OUTPUT_OPTION)
186 rm -f $(@:.o=.c)
187
188 # These headers are used by the startup code.
189 $(objpfx)abi-tag.h: $(..)abi-tags
190 $(make-target-directory)
191 rm -f $@.new
192 sed -e 's/#.*$$//' -e '/^[ ]*$$/d' $< | \
193 while read conf tagos tagver; do \
194 test `expr '$(config-machine)-$(config-vendor)-$(config-os)' \
195 : "$$conf"` != 0 || continue; \
196 ( echo "$$tagos" | \
197 sed -e 's/[^0-9xXa-fA-F ]//' \
198 -e 's/^/#define __ABI_TAG_OS /'; \
199 echo "#ifndef __ABI_TAG_VERSION"; \
200 echo "$$tagver" | \
201 sed -e 's/[^0-9xXa-fA-F]/ /g' -e 's/ *$$//' \
202 -e 's/ /,/g' -e 's/^/# define __ABI_TAG_VERSION /'; \
203 echo "#endif" ) > $@.new; \
204 done
205 if test -r $@.new; then mv -f $@.new $@; \
206 else echo >&2 'This configuration not matched in $<'; exit 1; fi
207
208 all-Banner-files = $(wildcard $(addsuffix /Banner, \
209 $(addprefix $(..), $(subdirs))))
210 $(objpfx)version-info.h: $(common-objpfx)config.make $(all-Banner-files)
211 $(make-target-directory)
212 (case $(config-os) in \
213 linux*) version=`(echo -e "#include <linux/version.h>\nUTS_RELEASE"\
214 | $(CC) -E -P - | \
215 sed -e 's/"\([^"]*\)".*/\1/p' -e d) 2>/dev/null`;\
216 if [ -z "$$version" ]; then \
217 if [ -r /proc/version ]; then \
218 version=`sed 's/.*Linux version \([^ ]*\) .*/>>\1<</' \
219 < /proc/version`; \
220 else \
221 version=`uname -r`; \
222 fi; \
223 fi; \
224 os=`uname -s 2> /dev/null`; \
225 if [ -z "$$os" ]; then \
226 os=Linux; \
227 fi; \
228 echo "\"Compiled on a $$os $$version system" \
229 "on `date +%Y-%m-%d`.\\n\"" ;; \
230 *) ;; \
231 esac; \
232 files="$(all-Banner-files)"; \
233 if test -n "$$files"; then \
234 echo "\"Available extensions:\\n\""; \
235 sed -e '/^#/d' -e 's/^[[:space:]]*/ /' \
236 -e 's/\(^.*$$\)/\"\1\\n\"/' $$files; \
237 fi) > $@T
238 mv -f $@T $@