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