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