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