* Makeconfig (+link-bounded, link-libc-bounded,
[platform/upstream/linaro-glibc.git] / Rules
1 # Copyright (C) 1991,92,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
3
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Library General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # License, or (at your option) any later version.
8
9 # The GNU C Library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Library General Public License for more details.
13
14 # You should have received a copy of the GNU Library General Public
15 # License along with the GNU C Library; see the file COPYING.LIB.  If not,
16 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
18
19 #
20 #       Rules for making a subdirectory in the GNU C library.
21 #       Each subdirectory Makefile defines some variables and includes this.
22 #
23 ifneq (,)
24 This makefile requires GNU Make.
25 endif
26
27 all: # Don't let the default goal come from Makeconfig.
28
29 include ../Makeconfig
30
31 ifndef  subdir
32 Each subdirectory makefile must define the `subdir' variable.
33 endif
34 # This ` unconfuses emacs.
35 # This is benign and useless in GNU make before 3.63.
36 export subdir := $(subdir)
37 \f
38 # This is the default target; it makes the library and auxiliary programs.
39 .PHONY: all
40 all: objs lib others
41
42 ifeq ($(build-programs),yes)
43 others: $(addprefix $(objpfx),$(extra-objs) \
44                               $(install-lib) $(install-bin) \
45                               $(install-rootsbin) $(install-sbin))
46 else
47 others: $(addprefix $(objpfx),$(extra-objs) \
48                               $(install-lib))
49 endif
50
51 ifneq   "$(findstring env,$(origin headers))" ""
52 headers :=
53 endif
54
55 ifneq   "$(findstring env,$(origin generated))" ""
56 generated :=
57 endif
58
59 ifneq   "$(findstring env,$(origin common-generated))" ""
60 common-generated :=
61 endif
62
63 include ../Makerules
64
65 .PHONY: subdir_lib
66 subdir_lib: lib-noranlib
67
68 # Some subdirs need to install a dummy library.
69 # They can use "$(objpfx)libfnord.a: $(dep-dummy-lib); $(make-dummy-lib)".
70 dep-dummy-lib = $(common-objpfx)dummy.o
71 define make-dummy-lib
72 $(AR) cr$(verbose) $@ $<
73 endef
74
75 $(common-objpfx)dummy.c:
76         rm -f $@
77         echo 'void __dummy__ (void) { }' > $@
78 common-generated += dummy.o dummy.c
79 \f
80 # This makes all the auxiliary and test programs.
81
82 .PHONY: others tests
83 ifeq ($(build-programs),yes)
84 others: $(addprefix $(objpfx),$(others) $(sysdep-others) $(extra-objs))
85 else
86 others: $(addprefix $(objpfx),$(extra-objs))
87 endif
88 ifeq ($(cross-compiling),yes)
89 tests: $(addprefix $(objpfx),$(tests) $(test-srcs))
90 else
91 ifeq ($(build-bounded),yes)
92 tests-bp.out = $(tests:%=$(objpfx)%-bp.out)
93 endif
94 tests: $(tests:%=$(objpfx)%.out) $(tests-bp.out)
95 endif
96
97 ifeq ($(build-programs),yes)
98 binaries-all = $(others) $(sysdep-others) $(tests) $(test-srcs)
99 binaries-static = $(others-static)
100 else
101 binaries-all = $(tests) $(test-srcs)
102 binaries-static =
103 endif
104
105 binaries-shared = $(filter-out $(binaries-static), $(binaries-all))
106
107 ifneq "$(strip $(binaries-shared))" ""
108 $(addprefix $(objpfx),$(binaries-shared)): %: %.o \
109   $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
110   $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
111         $(+link)
112 endif
113
114 ifneq "$(strip $(binaries-static))" ""
115 $(addprefix $(objpfx),$(binaries-static)): %: %.o \
116   $(sort $(filter $(common-objpfx)lib%,$(link-libc-static))) \
117   $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
118         $(+link-static)
119 endif
120
121 ifeq ($(build-bounded),yes)
122 binaries-bounded = $(addsuffix -bp,$(tests) $(test-srcs))
123 $(addprefix $(objpfx),$(binaries-bounded)): %-bp: %.ob \
124   $(sort $(filter $(common-objpfx)lib%,$(link-libc-bounded))) \
125   $(addprefix $(csu-objpfx),start.ob) $(+preinit) $(+postinit)
126         $(+link-bounded)
127 endif
128
129 ifneq "$(strip $(tests) $(test-srcs))" ""
130 # These are the implicit rules for making test outputs
131 # from the test programs and whatever input files are present.
132 $(objpfx)%.out: %.input $(objpfx)%
133         GCONV_PATH=$(common-objpfx)iconvdata LC_ALL=C \
134           $($*-ENV) $(built-program-cmd) $($*-ARGS) < $(word 1,$^) > $@
135 $(objpfx)%.out: /dev/null $(objpfx)%    # Make it 2nd arg for canned sequence.
136         GCONV_PATH=$(common-objpfx)iconvdata LC_ALL=C \
137           $($*-ENV) $(built-program-cmd) $($*-ARGS) > $@
138 endif   # tests
139 \f
140 .PHONY: distclean realclean subdir_distclean subdir_realclean \
141         subdir_clean subdir_mostlyclean subdir_testclean
142 subdir_mostlyclean: mostlyclean
143 subdir_clean: clean
144 subdir_distclean: distclean
145 subdir_realclean: realclean
146 subdir_testclean: do-tests-clean
147 realclean: distclean
148 distclean: clean
149
150 .PHONY: subdir_echo-headers
151 subdir_echo-headers: echo-headers
152
153 .PHONY: subdir_echo-distinfo
154 subdir_echo-distinfo:
155         @echo $(addprefix +header+,$(headers) $(filter %.h,$(distribute))) \
156               $(addprefix +nodist+,$(generated) $(common-generated) $(dont_distribute))
157
158 # We want to install everything except the library itself, but update all
159 # our portions of the library because the parent make will install it later
160 # (likewise the stubs file).
161 .PHONY: subdir_install
162 subdir_install: install-no-libc.a lib-noranlib stubs
163
164 .PHONY: subdir_TAGS subdir_dist
165 subdir_TAGS: TAGS
166 subdir_dist: dist
167
168 # Convenient target to update all the generated source files.
169 .PHONY: generated
170 generated: $(addprefix $(common-objpfx),$(common-generated)) \
171         $(addprefix $(objpfx),$(generated))
172
173 # Target required by the Hurd to ensure that all the MiG-generated
174 # headers are in place before building a subdirectory.
175 .PHONY: before-compile
176 before-compile: $(before-compile)
177
178 $(common-objpfx)dummy.o: $(common-objpfx)dummy.c $(before-compile);
179         $(compile-command.c)
180
181 # There's no good place to put this - here will do.
182 # The dependencies are wrong if it's run from the top level.
183 ifeq ($(filter %posix, $(sysdirs)),)
184 L_tmpnam  = 1
185 TMP_MAX   = 0
186 L_ctermid = 1
187 L_cuserid = 1
188 else
189 L_tmpnam  = 20
190 TMP_MAX   = 238328
191 L_ctermid = 9
192 L_cuserid = 9
193 endif
194 stdio_lim = $(common-objpfx)bits/stdio_lim.h
195
196 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
197 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
198                    $(common-objpfx)config.make
199         $(make-target-directory)
200         echo '#include "$(..)posix/bits/posix1_lim.h"' |                \
201         SUNPRO_DEPENDENCIES='$(@:st=dT) $@'                             \
202         $(CC) $(+includes) -E -dM -xc - -o $(@:st=hT)
203         echo '#include "$(..)misc/sys/uio.h"' |                         \
204         SUNPRO_DEPENDENCIES='$(@:st=dT) $@'                             \
205         $(CC) $(+includes) -E -dM -xc - | cat - >> $(@:st=hT)
206 ifdef sed-remove-objpfx
207         sed $(sed-remove-objpfx) $(@:st=dT) > $(@:st=dt)
208         cat $(@:st=dt) >> $(@:st=d)
209 else
210         cat $(@:st=dT) >> $(@:st=d)
211 endif
212         fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`;       \
213         filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`;    \
214         iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`;        \
215         fopen_max=$${fopen_max:-16};                                    \
216         filename_max=$${filename_max:-1024};                            \
217         if [ -z $$iov_max ]; then                                       \
218           define_iov_max="# undef IOV_MAX";                             \
219         else                                                            \
220           define_iov_max="# define IOV_MAX $$iov_max";                  \
221         fi;                                                             \
222         sed -e "s/@FOPEN_MAX@/$$fopen_max/"                             \
223             -e "s/@FILENAME_MAX@/$$filename_max/"                       \
224             -e "s/@L_tmpnam@/$(L_tmpnam)/"                              \
225             -e "s/@TMP_MAX@/$(TMP_MAX)/"                                \
226             -e "s/@L_ctermid@/$(L_ctermid)/"                            \
227             -e "s/@L_cuserid@/$(L_cuserid)/"                            \
228             -e "s/@define_IOV_MAX@/$$define_iov_max/"                   \
229             $< > $(@:st=h.new)
230         $(move-if-change) $(@:st=h.new) $(@:st=h)
231 # Remove these last so that they can be examined if something went wrong.
232         rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
233         touch $@
234 # Get dependencies.
235 ifndef no_deps
236 -include $(stdio_lim:h=d)
237 endif
238 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st