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