Update copyright notices with scripts/update-copyrights
[glibc.git] / csu / Makefile
blobb5afea0decd9014b1180fc7977ca3776d438b9d6
1 # Makefile for csu code for GNU C library.
2 # Copyright (C) 1995-2014 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
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.
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.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with the GNU C Library; if not, see
17 # <http://www.gnu.org/licenses/>.
19 # This directory contains the C startup code (that which calls main). This
20 # consists of the startfile, built from start.c and installed as crt0.o
21 # (traditionally) or crt1.o (for ELF). In ELF we also install crti.o and
22 # crtn.o, special "initializer" and "finalizer" files used in the link
23 # to make the .init and .fini sections work right.
25 subdir := csu
27 routines = init-first libc-start $(libc-init) sysdep version check_fds \
28 libc-tls elf-init dso_handle
29 aux = errno
30 elide-routines.os = libc-tls
31 static-only-routines = elf-init
32 csu-dummies = $(filter-out $(start-installed-name),crt1.o Mcrt1.o)
33 extra-objs = start.o gmon-start.o \
34 $(start-installed-name) g$(start-installed-name) $(csu-dummies) \
35 S$(start-installed-name)
36 omit-deps = $(patsubst %.o,%,$(start-installed-name) g$(start-installed-name) \
37 b$(start-installed-name) $(csu-dummies) \
38 S$(start-installed-name))
39 install-lib = $(start-installed-name) g$(start-installed-name) $(csu-dummies)
40 generated = version-info.h
41 before-compile = $(objpfx)version-info.h
43 tests := tst-empty tst-atomic tst-atomic-long
44 tests-static := tst-empty
46 all: # Make this the default target; it will be defined in Rules.
48 include ../Makeconfig
50 ifeq (yes,$(build-shared))
51 extra-objs += S$(start-installed-name)
52 install-lib += S$(start-installed-name)
53 generated += start.os
54 endif
56 ifneq ($(start-installed-name),$(static-start-installed-name))
57 extra-objs += $(static-start-installed-name) g$(static-start-installed-name)
58 omit-deps += $(patsubst %.o,%,$(static-start-installed-name) \
59 g$(static-start-installed-name))
60 install-lib += $(static-start-installed-name) g$(static-start-installed-name)
61 endif
63 before-compile += $(objpfx)abi-tag.h
64 generated += abi-tag.h
66 # These are the special initializer/finalizer files. They are always the
67 # first and last file in the link. crti.o ... crtn.o define the global
68 # "functions" _init and _fini to run the .init and .fini sections.
69 crtstuff = crti crtn
71 install-lib += $(crtstuff:=.o)
72 extra-objs += $(crtstuff:=.o)
74 extra-objs += abi-note.o init.o
75 asm-CPPFLAGS += -I$(objpfx).
77 include ../Rules
79 # Make these in the lib pass so they're available in time to link things with.
80 subdir_lib: $(extra-objs:%=$(objpfx)%)
82 define link-relocatable
83 $(CC) -nostdlib -nostartfiles -r -o $@ $^
84 endef
86 ifndef start-installed-name-rule
87 # We link the ELF startfile along with a SHT_NOTE section indicating
88 # the kernel ABI the binaries linked with this library will require.
89 $(objpfx)$(start-installed-name): $(objpfx)start.o $(objpfx)abi-note.o \
90 $(objpfx)init.o
91 $(link-relocatable)
92 $(objpfx)S$(start-installed-name): $(objpfx)start.os $(objpfx)abi-note.o \
93 $(objpfx)init.o
94 $(link-relocatable)
95 endif
97 # The profiling startfile is made by linking together the normal
98 # startfile with gmon-start.o, which defines a constructor function
99 # to turn on profiling code at startup.
100 $(addprefix $(objpfx),$(sort g$(start-installed-name) \
101 g$(static-start-installed-name))): \
102 $(objpfx)g%: $(objpfx)% $(objpfx)gmon-start.o
103 $(link-relocatable)
105 # These extra files are sometimes expected by system standard linking
106 # procedures, but we have nothing for them to do. So compile empty files.
107 $(addprefix $(objpfx),$(filter-out $(start-installed-name), $(csu-dummies))):\
108 $(before-compile)
109 $(COMPILE.c) -o $@ -x c /dev/null
111 # These headers are used by the startup code.
112 $(objpfx)abi-tag.h: $(..)abi-tags
113 $(make-target-directory)
114 rm -f $@.new
115 sed -e 's/#.*$$//' -e '/^[ ]*$$/d' $< | \
116 while read conf tagos tagver; do \
117 test `expr '$(config-machine)-$(config-vendor)-$(config-os)' \
118 : "$$conf"` != 0 || continue; \
119 ( echo "$$tagos" | \
120 sed -e 's/[^0-9xXa-fA-F ]//' \
121 -e 's/^/#define __ABI_TAG_OS /'; \
122 echo "#ifndef __ABI_TAG_VERSION"; \
123 echo "$$tagver" | \
124 sed -e 's/[^0-9xXa-fA-F]/ /g' -e 's/ *$$//' \
125 -e 's/ /,/g' -e 's/^/# define __ABI_TAG_VERSION /'; \
126 echo "#endif" ) > $@.new; \
127 done
128 if test -r $@.new; then mv -f $@.new $@; \
129 else echo >&2 'This configuration not matched in $<'; exit 1; fi
131 all-Banner-files = $(wildcard $(addsuffix /Banner,\
132 $(sort $(subdir-srcdirs) \
133 $(sysdeps-srcdirs))))
134 $(objpfx)version-info.h: $(common-objpfx)config.make $(all-Banner-files)
135 $(make-target-directory)
136 (case $(config-os) in \
137 linux*) version=`(printf '%s\n%s\n' \
138 '#include <linux/version.h>' \
139 UTS_RELEASE \
140 | $(CC) $(CPPFLAGS) -O -E -P - -DNOT_IN_libc=1 | \
141 sed -e 's/"\([^"]*\)".*/\1/p' -e d) 2>/dev/null`;\
142 if [ -z "$$version" ]; then \
143 version=`(printf '%s\n%s\n' \
144 '#include <linux/version.h>' \
145 LINUX_VERSION_CODE \
146 | $(CC) $(CPPFLAGS) -O -E -P - -DNOT_IN_libc=1 \
147 | sed -n -e '/^[123456789].*/p' \
148 | awk '{v=$$1; \
149 printf("%d.%d.%d\n", \
150 v/65535, v/256%256, v%256)}') \
151 2>/dev/null`; \
152 fi; \
153 if [ -z "$$version" ]; then \
154 if [ -r /proc/version ]; then \
155 version=`sed 's/.*Linux version \([^ ]*\) .*/>>\1<</' \
156 < /proc/version`; \
157 else \
158 version=`uname -r`; \
159 fi; \
160 fi; \
161 os=`uname -s 2> /dev/null`; \
162 if [ -z "$$os" ]; then \
163 os=Linux; \
164 fi; \
165 printf '"Compiled on a %s %s system on %s.\\n"\n' \
166 "$$os" "$$version" "`date +%Y-%m-%d`";; \
167 *) ;; \
168 esac; \
169 files="$(all-Banner-files)"; \
170 if test -n "$$files"; then \
171 printf '"Available extensions:\\n"\n'; \
172 sed -e '/^#/d' -e 's/^[[:space:]]*/ /' \
173 -e 's/^\(.*\)$$/\"\1\\n\"/' $$files; \
174 fi) > $@T
175 mv -f $@T $@