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