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