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