]> git.ipfire.org Git - thirdparty/glibc.git/blob - csu/Makefile
7482cafc9ce816aabecdd11e16735702c33e6f41
[thirdparty/glibc.git] / csu / Makefile
1 # Makefile for csu code for GNU C library.
2
3 # Copyright (C) 1995, 1996, 1997, 1998 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 not,
18 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 # Boston, MA 02111-1307, 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). In ELF we also install crti.o and
24 # crtn.o, special "initializer" and "finalizer" files in used in the link
25 # to make the .init and .fini sections work right; both these files are
26 # built (in an arcane manner) from initfini.c.
27
28 subdir := csu
29
30 routines = init-first libc-start
31 csu-dummies = $(filter-out $(start-installed-name),crt1.o Mcrt1.o)
32 extra-objs = start.o gmon-start.o \
33 $(start-installed-name) g$(start-installed-name) \
34 $(csu-dummies)
35 omit-deps = $(patsubst %.o,%,$(start-installed-name) g$(start-installed-name) \
36 $(csu-dummies))
37 install-lib = $(start-installed-name) g$(start-installed-name) \
38 $(csu-dummies)
39 distribute = initfini.c gmon-start.c start.c defs.awk abi-note.S init.c
40
41 all: # Make this the default target; it will be defined in Rules.
42
43 include ../Makeconfig
44
45 ifeq ($(elf),yes)
46 before-compile = $(objpfx)abi-tag.h
47 generated += abi-tag.h
48 endif
49
50 ifeq ($(have-initfini),yes)
51
52 CPPFLAGS += -DHAVE_INITFINI
53
54 # These are the special initializer/finalizer files. They are always the
55 # first and last file in the link. crti.o ... crtn.o define the global
56 # "functions" _init and _fini to run the .init and .fini sections.
57 crtstuff = crti crtn
58
59 install-lib += $(crtstuff:=.o)
60 extra-objs += $(crtstuff:=.o)
61 generated += $(crtstuff:=.S) initfini.s defs.h
62 omit-deps += $(crtstuff)
63
64 # Special rules for the building of crti.o and crtn.o
65 $(objpfx)crt%.o: $(objpfx)crt%.S $(objpfx)defs.h
66 $(compile.S) -g0 $(ASFLAGS-.os) -o $@
67
68 CFLAGS-initfini.s = -g0 -fPIC -fno-inline-functions
69
70 $(objpfx)initfini.s: initfini.c
71 $(compile.c) -S $(CFLAGS-initfini.s) -finhibit-size-directive \
72 $(no-exceptions) -o $@
73
74 # We only have one kind of startup code files. Static binaries and
75 # shared libraries are build using the PIC version.
76 $(objpfx)crti.S: $(objpfx)initfini.s
77 sed -n -e '1,/@HEADER_ENDS/p' \
78 -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
79 -e '/@TRAILER_BEGINS/,$$p' $< > $@
80
81 $(objpfx)crtn.S: $(objpfx)initfini.s
82 sed -n -e '1,/@HEADER_ENDS/p' \
83 -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \
84 -e '/@TRAILER_BEGINS/,$$p' $< > $@
85
86 $(objpfx)defs.h: $(objpfx)initfini.s
87 sed -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
88 awk -f defs.awk > $@
89
90 endif
91
92 ifeq (yes,$(elf))
93 extra-objs += abi-note.o init.o
94 asm-CPPFLAGS += -I$(objpfx).
95 endif
96
97 include ../Rules
98
99 define link-relocatable
100 $(CC) -nostdlib -nostartfiles -r -o $@ $^
101 endef
102
103 ifndef start-installed-name-rule
104 ifeq (yes,$(elf))
105 # We link the ELF startfile along with a SHT_NOTE section indicating
106 # the the kernel ABI the binaries linked with this library will require.
107 $(objpfx)$(start-installed-name): $(objpfx)start.o $(objpfx)abi-note.o \
108 $(objpfx)init.o
109 $(link-relocatable)
110 else
111 # The startfile is installed under different names, so we just call our
112 # source file `start.c' and copy to the installed name after compiling.
113 $(objpfx)$(start-installed-name): $(objpfx)start.o
114 rm -f $@
115 ln $< $@
116 endif
117 endif
118
119 # The profiling startfile is made by linking together the normal
120 # startfile with gmon-start.o, which defines a constructor function
121 # to turn on profiling code at startup.
122 $(objpfx)g$(start-installed-name): $(objpfx)$(start-installed-name) \
123 $(objpfx)gmon-start.o
124 $(link-relocatable)
125
126 # These extra files are sometimes expected by system standard linking
127 # procedures, but we have nothing for them to do. So compile empty files.
128 $(addprefix $(objpfx),$(filter-out $(start-installed-name),$(csu-dummies))):
129 cp /dev/null $(@:.o=.c)
130 $(COMPILE.c) $(@:.o=.c) $(OUTPUT_OPTION)
131 rm -f $(@:.o=.c)
132
133 / := $$/# bite me.
134 $(objpfx)abi-tag.h: $(..)abi-tags
135 $(make-target-directory)
136 rm -f $@.new
137 sed 's/#.*$//;/^[ ]*$$/d' $< | while read conf tag; do \
138 test `expr '$(config-machine)-$(config-vendor)-$(config-os)' \
139 : "$$conf"` != 0 || continue; \
140 echo "$$tag" | sed > $@.new \
141 's/[^0-9xXa-fA-F]/ /g;s/ *$//;s/ /,/g;s/^ */#define ABI_TAG /';\
142 done
143 if test -r $@.new; then mv -f $@.new $@; \
144 else echo >&2 'This configuration not matched in $<'; exit 1; fi