Add support for generated PIE link rules
[jlayton/glibc.git] / Rules
1 # Copyright (C) 1991-2000,2002,2003,2004,2005,2006,2011
2 #       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 #
21 #       Rules for making a subdirectory in the GNU C library.
22 #       Each subdirectory Makefile defines some variables and includes this.
23 #
24 ifneq (,)
25 This makefile requires GNU Make.
26 endif
27
28 all: # Don't let the default goal come from Makeconfig.
29
30 include $(firstword $(..) ../)Makeconfig
31
32 ifndef  subdir
33 Each subdirectory makefile must define the `subdir' variable.
34 endif
35 # This ` unconfuses emacs.
36 # This is benign and useless in GNU make before 3.63.
37 export subdir := $(subdir)
38 \f
39 # This is the default target; it makes the library and auxiliary programs.
40 .PHONY: all
41 all: objs lib others
42
43 ifeq ($(build-programs),yes)
44 others: $(addprefix $(objpfx),$(extra-objs) \
45                               $(install-lib) \
46                               $(install-bin) $(install-bin-script) \
47                               $(install-rootsbin) $(install-sbin))
48 else
49 others: $(addprefix $(objpfx),$(extra-objs) \
50                               $(install-lib))
51 endif
52
53 ifneq   "$(findstring env,$(origin headers))" ""
54 headers :=
55 endif
56
57 ifneq   "$(findstring env,$(origin generated))" ""
58 generated :=
59 endif
60
61 ifneq   "$(findstring env,$(origin common-generated))" ""
62 common-generated :=
63 endif
64
65 # See below.  This must be set before Makerules processes it.
66 before-compile += $(common-objpfx)bits/stdio_lim.h
67
68 include $(..)Makerules
69
70 .PHONY: subdir_lib
71 subdir_lib: lib-noranlib
72
73 # Some subdirs need to install a dummy library.
74 # They can use "$(objpfx)libfnord.a: $(dep-dummy-lib); $(make-dummy-lib)".
75 dep-dummy-lib = $(common-objpfx)dummy.o
76 define make-dummy-lib
77 $(AR) cr$(verbose) $@ $<
78 endef
79
80 $(common-objpfx)dummy.c:
81         rm -f $@
82         (echo 'extern void __dummy__ (void);'; \
83          echo 'void __dummy__ (void) { }') > $@
84 common-generated += dummy.o dummy.c
85 \f
86 # This makes all the auxiliary and test programs.
87
88 .PHONY: others tests
89 ifeq ($(build-programs),yes)
90 others: $(addprefix $(objpfx),$(others) $(sysdep-others) $(extra-objs))
91 else
92 others: $(addprefix $(objpfx),$(extra-objs))
93 endif
94 ifeq ($(cross-compiling),yes)
95 tests: $(addprefix $(objpfx),$(tests) $(test-srcs))
96 xtests: tests
97 else
98 ifeq ($(build-bounded),yes)
99 tests-bp.out = $(tests:%=$(objpfx)%-bp.out)
100 xtests-bp.out = $(xtests:%=$(objpfx)%-bp.out)
101 endif
102 tests: $(tests:%=$(objpfx)%.out) $(tests-bp.out)
103 xtests: tests $(xtests:%=$(objpfx)%.out) $(xtests-bp.out)
104 endif
105
106 ifeq ($(build-programs),yes)
107 binaries-all = $(others) $(sysdep-others) $(tests) $(xtests) $(test-srcs)
108 binaries-static = $(others-static) $(tests-static) $(xtests-static)
109 ifeq (yesyes,$(have-fpie)$(build-shared))
110 binaries-pie = $(others-pie) $(tests-pie) $(xtests-pie)
111 else
112 binaries-pie =
113 endif
114 else
115 binaries-all = $(tests) $(xtests) $(test-srcs)
116 binaries-static =
117 binaries-pie =
118 endif
119
120 binaries-shared = $(filter-out $(binaries-pie) $(binaries-static), \
121                                $(binaries-all))
122
123 ifneq "$(strip $(binaries-shared))" ""
124 $(addprefix $(objpfx),$(binaries-shared)): %: %.o \
125   $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
126   $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
127         $(+link)
128 endif
129
130 ifneq "$(strip $(binaries-pie))" ""
131 $(addprefix $(objpfx),$(binaries-pie)): %: %.o \
132   $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
133   $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
134         $(+link-pie)
135 endif
136
137 ifneq "$(strip $(binaries-static))" ""
138 $(addprefix $(objpfx),$(binaries-static)): %: %.o \
139   $(sort $(filter $(common-objpfx)lib%,$(link-libc-static))) \
140   $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
141         $(+link-static)
142 endif
143
144 ifeq ($(build-bounded),yes)
145 binaries-bounded = $(addsuffix -bp,$(tests) $(xtests) $(test-srcs))
146 $(addprefix $(objpfx),$(binaries-bounded)): %-bp: %.ob \
147   $(sort $(filter $(common-objpfx)lib%,$(link-libc-bounded))) \
148   $(addprefix $(csu-objpfx),start.ob) $(+preinit) $(+postinit)
149         $(+link-bounded)
150 endif
151
152 ifneq "$(strip $(tests) $(xtests) $(test-srcs))" ""
153 # These are the implicit rules for making test outputs
154 # from the test programs and whatever input files are present.
155
156 make-test-out = GCONV_PATH=$(common-objpfx)iconvdata LC_ALL=C \
157                 $($*-ENV) $(built-program-cmd) $($*-ARGS)
158 $(objpfx)%-bp.out: %.input $(objpfx)%-bp
159         $(make-test-out) > $@ < $(word 1,$^)
160 $(objpfx)%.out: %.input $(objpfx)%
161         $(make-test-out) > $@ < $(word 1,$^)
162 $(objpfx)%.out: /dev/null $(objpfx)%    # Make it 2nd arg for canned sequence.
163         $(make-test-out) > $@
164
165 endif   # tests
166 \f
167 .PHONY: distclean realclean subdir_distclean subdir_realclean \
168         subdir_clean subdir_mostlyclean subdir_testclean
169 subdir_mostlyclean: mostlyclean
170 subdir_clean: clean
171 subdir_distclean: distclean
172 subdir_realclean: realclean
173 subdir_testclean: do-tests-clean
174 realclean: distclean
175 distclean: clean
176
177 # We want to install everything except the library itself, but update all
178 # our portions of the library because the parent make will install it later
179 # (likewise the stubs file).
180 .PHONY: subdir_install
181 subdir_install: install-no-libc.a lib-noranlib stubs
182
183 .PHONY: subdir_objs subdir_stubs
184 subdir_objs: objs
185 subdir_stubs: stubs
186
187 # Target required by the Hurd to ensure that all the MiG-generated
188 # headers are in place before building a subdirectory.
189 .PHONY: before-compile
190 before-compile: $(before-compile)
191
192 $(common-objpfx)dummy.o: $(common-objpfx)dummy.c $(before-compile);
193         $(compile-command.c)
194
195 # Local Variables:
196 # mode: makefile
197 # End: