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