* csu/Makefile [$(elf)=yes] (have-initfini): Set to yes.
[platform/upstream/glibc.git] / csu / Makefile
1 # Makefile for csu code for GNU C library.
2
3 # Copyright (C) 1995 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
18 # not, write to the Free Software Foundation, Inc., 675 Mass Ave,
19 # Cambridge, MA 02139, 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); and some initialization code which
24 # is in the C library itself.  In ELF we also install crti.o and crtn.o,
25 # special "initializer" and "finalizer" files in used in the link to make
26 # the .init and .fini sections work right; both these files are built (in
27 # an arcane manner) from initfini.c.
28
29 subdir := csu
30
31 csu-dummies = $(filter-out $(start-installed-name),crt1.o Mcrt1.o)
32 extra-objs = start.o $(start-installed-name) $(csu-dummies)
33 omit-deps = $(patsubst %.o,%,$(start-installed-name) $(csu-dummies))
34 install-lib = $(start-installed-name) $(csu-dummies)
35 distribute = initfini.c
36
37 all: # Make this the default target; it will be defined in Rules.
38
39 include ../Makeconfig
40
41 ifneq ($(elf),yes)
42
43 # When not using ELF, there is just one startfile, called crt0.o.
44 start-installed-name = crt0.o
45
46 else
47
48 # In the ELF universe, crt0.o is called crt1.o, and there are 
49 # some additional bizarre files.
50 start-installed-name = crt1.o
51 have-initfini = yes
52
53 endif
54
55 ifeq (yes,$(have-initfini))
56
57 # These are the special initializer/finalizer files.  They are always the
58 # first and last file in the link.  crti.o ... crtn.o define the global
59 # "functions" _init and _fini to run the .init and .fini sections.
60 crtstuff = crti crtn
61
62 install-lib += $(crtstuff:=.o)
63 extra-objs += $(crtstuff:=.o)
64 generated += $(crtstuff:=.s)
65 omit-deps += $(crtstuff)
66
67 # Compile initfini.c to assembly code, which contains embedded shell
68 # commands that prodice crti.s-new and crtn.s-new when run.  We need to
69 # disable emission of .size directives and debugging information, since
70 # they will get confused by the splitting of the output we do.
71 $(objpfx)cr%i.s $(objpfx)cr%n.s: initfini.c; $(initfini)
72
73 define initfini
74 -rm -f $(objpfx)crtcommon.tmp
75 (echo 'cat > crtcommon.tmp <<\EOF_common'; \
76  $(CC) $< $(CPPFLAGS) $(CFLAGS) \
77        -finhibit-size-directive -g0 -S -o -; \
78  echo 'EOF_common') | (cd $(@D); $(SHELL))
79 cat $(objpfx)crtcommon.tmp >> $(objpfx)crti.s-new
80 cat $(objpfx)crtcommon.tmp >> $(objpfx)crtn.s-new
81 rm -f $(objpfx)crtcommon.tmp
82 mv -f $(objpfx)crti.s-new $(subst crtn,crti,$@)
83 mv -f $(objpfx)crtn.s-new $(subst crti,crtn,$@)
84 endef
85
86 endif
87
88 include ../Rules
89
90 ifndef start-installed-name-rule
91 # The startfile is installed under different names, so we just call our
92 # source file `start.c' and copy to the installed name after compiling.
93 $(objpfx)$(start-installed-name): $(objpfx)start.o
94         -rm -f $@
95         ln $< $@
96 endif
97
98 # These extra files are sometimes expected by system standard linking
99 # procedures, but we have nothing for them to do.  So compile empty files.
100 $(addprefix $(objpfx),$(filter-out $(start-installed-name),$(csu-dummies))):
101         cp /dev/null $(@:.o=.c)
102         $(COMPILE.c) $(@:.o=.c) $(OUTPUT_OPTION)
103         rm -f $(@:.o=.c)
104