Replace FSF snail mail address with URLs.
[glibc.git] / csu / Makefile
blobc36c42c420cd87c656a68ecd097efa4ac57890c5
1 # Makefile for csu code for GNU C library.
2 # Copyright (C) 1995-2006, 2010, 2012 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, see
17 # <http://www.gnu.org/licenses/>.
19 # This directory contains the C startup code (that which calls main). This
20 # consists of the startfile, built from start.c and installed as crt0.o
21 # (traditionally) or crt1.o (for ELF). In ELF we also install crti.o and
22 # crtn.o, special "initializer" and "finalizer" files used in the link
23 # to make the .init and .fini sections work right; both these files are
24 # built (in an arcane manner) from initfini.c.
26 subdir := csu
28 routines = init-first libc-start $(libc-init) sysdep version check_fds \
29 libc-tls elf-init dso_handle
30 aux = errno
31 elide-routines.os = libc-tls
32 static-only-routines = elf-init
33 csu-dummies = $(filter-out $(start-installed-name),crt1.o Mcrt1.o)
34 extra-objs = start.o gmon-start.o \
35 $(start-installed-name) g$(start-installed-name) $(csu-dummies) \
36 S$(start-installed-name)
37 omit-deps = $(patsubst %.o,%,$(start-installed-name) g$(start-installed-name) \
38 b$(start-installed-name) $(csu-dummies) \
39 S$(start-installed-name))
40 install-lib = $(start-installed-name) g$(start-installed-name) $(csu-dummies)
41 distribute = initfini.c gmon-start.c start.c defs.awk \
42 abi-note.S init.c c not-cancel.h
43 generated = version-info.h
44 before-compile = $(objpfx)version-info.h
46 tests := tst-empty tst-atomic tst-atomic-long
47 tests-static := tst-empty
49 all: # Make this the default target; it will be defined in Rules.
51 include ../Makeconfig
53 ifeq (yes,$(build-shared))
54 extra-objs += S$(start-installed-name)
55 install-lib += S$(start-installed-name)
56 generated += start.os
57 endif
59 ifeq (yes,$(build-bounded))
60 extra-objs += b$(start-installed-name)
61 install-lib += b$(start-installed-name)
62 generated += start.ob
63 endif
65 ifneq ($(start-installed-name),$(static-start-installed-name))
66 extra-objs += $(static-start-installed-name) g$(static-start-installed-name)
67 omit-deps += $(patsubst %.o,%,$(static-start-installed-name) \
68 g$(static-start-installed-name))
69 install-lib += $(static-start-installed-name) g$(static-start-installed-name)
70 endif
72 before-compile += $(objpfx)abi-tag.h
73 generated += abi-tag.h
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
80 install-lib += $(crtstuff:=.o)
81 extra-objs += $(crtstuff:=.o)
83 # Conditionals on the existence of a sysdeps version of crti.S are
84 # temporary until all targets either have such a file or have been
85 # removed, after which the old approach of postprocessing compiler
86 # output will be removed.
87 ifeq (,$(wildcard $(sysdirs:%=%/crti.S)))
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 $(crtstuff:%=$(objpfx)%.o): %.o: %.S $(objpfx)defs.h
94 $(compile.S) -g0 $(ASFLAGS-.os) -o $@
96 CFLAGS-initfini.s = -g0 -fPIC -fno-inline-functions $(fno-unit-at-a-time)
98 vpath initfini.c $(sysdirs)
100 $(objpfx)initfini.s: initfini.c $(before-compile)
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 # These explicit rules are necessary when the $(objpfx) subdirectory
117 # did not exist at the time make considered the implicit rules using it.
118 # This comes up with a fresh build using no_deps=t.
119 $(patsubst %,$(objpfx)crt%.o,i n): %.o: %.S
121 $(objpfx)defs.h: $(objpfx)initfini.s
122 sed -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
123 $(AWK) -f defs.awk > $@
125 endif
127 extra-objs += abi-note.o init.o
128 asm-CPPFLAGS += -I$(objpfx).
130 include ../Rules
132 # Make these in the lib pass so they're available in time to link things with.
133 subdir_lib: $(extra-objs:%=$(objpfx)%)
135 define link-relocatable
136 $(CC) -nostdlib -nostartfiles -r -o $@ $^
137 endef
139 ifndef start-installed-name-rule
140 # We link the ELF startfile along with a SHT_NOTE section indicating
141 # the kernel ABI the binaries linked with this library will require.
142 $(objpfx)$(start-installed-name): $(objpfx)start.o $(objpfx)abi-note.o \
143 $(objpfx)init.o
144 $(link-relocatable)
145 $(objpfx)S$(start-installed-name): $(objpfx)start.os $(objpfx)abi-note.o \
146 $(objpfx)init.o
147 $(link-relocatable)
148 $(objpfx)b$(start-installed-name): $(objpfx)start.ob $(objpfx)abi-note.ob \
149 $(objpfx)init.ob
150 $(link-relocatable)
151 endif
153 # The profiling startfile is made by linking together the normal
154 # startfile with gmon-start.o, which defines a constructor function
155 # to turn on profiling code at startup.
156 $(addprefix $(objpfx),$(sort g$(start-installed-name) \
157 g$(static-start-installed-name))): \
158 $(objpfx)g%: $(objpfx)% $(objpfx)gmon-start.o
159 $(link-relocatable)
161 # These extra files are sometimes expected by system standard linking
162 # procedures, but we have nothing for them to do. So compile empty files.
163 $(addprefix $(objpfx),$(filter-out $(start-installed-name), $(csu-dummies))):\
164 $(before-compile)
165 $(COMPILE.c) -o $@ -x c /dev/null
167 # These headers are used by the startup code.
168 $(objpfx)abi-tag.h: $(..)abi-tags
169 $(make-target-directory)
170 rm -f $@.new
171 sed -e 's/#.*$$//' -e '/^[ ]*$$/d' $< | \
172 while read conf tagos tagver; do \
173 test `expr '$(config-machine)-$(config-vendor)-$(config-os)' \
174 : "$$conf"` != 0 || continue; \
175 ( echo "$$tagos" | \
176 sed -e 's/[^0-9xXa-fA-F ]//' \
177 -e 's/^/#define __ABI_TAG_OS /'; \
178 echo "#ifndef __ABI_TAG_VERSION"; \
179 echo "$$tagver" | \
180 sed -e 's/[^0-9xXa-fA-F]/ /g' -e 's/ *$$//' \
181 -e 's/ /,/g' -e 's/^/# define __ABI_TAG_VERSION /'; \
182 echo "#endif" ) > $@.new; \
183 done
184 if test -r $@.new; then mv -f $@.new $@; \
185 else echo >&2 'This configuration not matched in $<'; exit 1; fi
187 all-Banner-files = $(wildcard $(addsuffix /Banner,\
188 $(sort $(subdir-srcdirs) \
189 $(sysdeps-srcdirs))))
190 $(objpfx)version-info.h: $(common-objpfx)config.make $(all-Banner-files)
191 $(make-target-directory)
192 (case $(config-os) in \
193 linux*) version=`(printf '%s\n%s\n' \
194 '#include <linux/version.h>' \
195 UTS_RELEASE \
196 | $(CC) $(CPPFLAGS) -O -E -P - -DNOT_IN_libc=1 | \
197 sed -e 's/"\([^"]*\)".*/\1/p' -e d) 2>/dev/null`;\
198 if [ -z "$$version" ]; then \
199 version=`(printf '%s\n%s\n' \
200 '#include <linux/version.h>' \
201 LINUX_VERSION_CODE \
202 | $(CC) $(CPPFLAGS) -O -E -P - -DNOT_IN_libc=1 \
203 | sed -n -e '/^[123456789].*/p' \
204 | awk '{v=$$1; \
205 printf("%d.%d.%d\n", \
206 v/65535, v/256%256, v%256)}') \
207 2>/dev/null`; \
208 fi; \
209 if [ -z "$$version" ]; then \
210 if [ -r /proc/version ]; then \
211 version=`sed 's/.*Linux version \([^ ]*\) .*/>>\1<</' \
212 < /proc/version`; \
213 else \
214 version=`uname -r`; \
215 fi; \
216 fi; \
217 os=`uname -s 2> /dev/null`; \
218 if [ -z "$$os" ]; then \
219 os=Linux; \
220 fi; \
221 printf '"Compiled on a %s %s system on %s.\\n"\n' \
222 "$$os" "$$version" "`date +%Y-%m-%d`";; \
223 *) ;; \
224 esac; \
225 files="$(all-Banner-files)"; \
226 if test -n "$$files"; then \
227 printf '"Available extensions:\\n"\n'; \
228 sed -e '/^#/d' -e 's/^[[:space:]]*/ /' \
229 -e 's/^\(.*\)$$/\"\1\\n\"/' $$files; \
230 fi) > $@T
231 mv -f $@T $@