Update.
[platform/upstream/linaro-glibc.git] / Rules
1 # Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98 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 is benign and useless in GNU make before 3.63.
35 export subdir := $(subdir)
36 \f
37 # This is the default target; it makes the library and auxiliary programs.
38 .PHONY: all
39 all: objs lib others
40
41 ifeq ($(build-programs),yes)
42 others: $(addprefix $(objpfx),$(extra-objs) \
43                               $(install-lib) $(install-bin) \
44                               $(install-rootsbin) $(install-sbin))
45 else
46 others: $(addprefix $(objpfx),$(extra-objs) \
47                               $(install-lib))
48 endif
49
50 ifneq   "$(findstring env,$(origin headers))" ""
51 headers :=
52 endif
53
54 ifneq   "$(findstring env,$(origin generated))" ""
55 generated :=
56 endif
57
58 ifneq   "$(findstring env,$(origin common-generated))" ""
59 common-generated :=
60 endif
61
62 include ../Makerules
63
64 .PHONY: subdir_lib
65 subdir_lib: lib-noranlib
66
67 # Some subdirs need to install a dummy library.
68 # They can use "$(objpfx)libfnord.a: $(dep-dummy-lib); $(make-dummy-lib)".
69 dep-dummy-lib = $(common-objpfx)dummy.o
70 define make-dummy-lib
71 $(AR) cr$(verbose) $@ $<
72 endef
73
74 $(common-objpfx)dummy.c:
75         rm -f $@
76         echo 'void __dummy__ (void) { }' > $@
77 $(common-objpfx)empty.c:
78         cp -f /dev/null $@
79 common-generated += dummy.o dummy.c empty.c \
80                     $(addprefix empty,$(object-suffixes))
81 \f
82 # This makes all the auxiliary and test programs.
83
84 .PHONY: others tests
85 ifeq ($(build-programs),yes)
86 others: $(addprefix $(objpfx),$(others) $(extra-objs))
87 else
88 others: $(addprefix $(objpfx),$(extra-objs))
89 endif
90 ifeq ($(cross-compiling),yes)
91 tests: $(addprefix $(objpfx),$(tests) $(tests-static) $(test-srcs))
92 else
93 tests: $(tests:%=$(objpfx)%.out) $(tests-static:%=$(objpfx)%.sout)
94 endif
95
96 ifeq ($(build-programs),yes)
97 binaries-all = $(others) $(tests) $(test-srcs)
98 binaries-static = $(others-static) $(tests-static) $(test-srcs-static)
99 else
100 binaries-all = $(tests) $(test-srcs)
101 binaries-static = $(tests-static) $(test-srcs-static)
102 endif
103
104 binaries-shared = $(filter-out $(binaries-static), $(binaries-all))
105
106 ifneq "$(strip $(binaries-shared))" ""
107 $(addprefix $(objpfx),$(binaries-shared)): %: %.o \
108   $(sort $(filter $(common-objpfx)libc%,$(link-libc))) \
109   $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
110         $(+link)
111 endif
112
113 ifneq "$(strip $(binaries-static))" ""
114 $(addprefix $(objpfx),$(binaries-static)): %: %.o \
115   $(sort $(filter $(common-objpfx)libc%,$(link-libc-static))) \
116   $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
117         $(+link-static)
118 endif
119
120 ifneq "$(strip $(tests) $(test-srcs))" ""
121 # These are the implicit rules for making test outputs
122 # from the test programs and whatever input files are present.
123 $(objpfx)%.out: %.args $(objpfx)% %.input
124         $($*-ENV) $(built-program-cmd) `cat $(word 1,$^)` < $(word 3,$^) > $@
125 $(objpfx)%.out: %.args $(objpfx)%
126         $($*-ENV) $(built-program-cmd) `cat $(word 1,$^)` > $@
127 $(objpfx)%.out: %.input $(objpfx)%
128         $($*-ENV) $(built-program-cmd) < $(word 1,$^) > $@
129 $(objpfx)%.out: /dev/null $(objpfx)%    # Make it 2nd arg for canned sequence.
130         $($*-ENV) $(built-program-cmd) > $@
131 endif   # tests
132
133 ifneq "$(strip $(tests-static) $(test-static-srcs))" ""
134 # These are the implicit rules for making test outputs
135 # from the test programs and whatever input files are present.
136 $(objpfx)%.sout: %.args $(objpfx)% %.input
137         $($*-ENV) $(built-program-file) `cat $(word 1,$^)` < $(word 3,$^) > $@
138 $(objpfx)%.sout: %.args $(objpfx)%
139         $($*-ENV) $(built-program-file) `cat $(word 1,$^)` > $@
140 $(objpfx)%.sout: %.input $(objpfx)%
141         $($*-ENV) $(built-program-file) < $(word 1,$^) > $@
142 $(objpfx)%.sout: /dev/null $(objpfx)%   # Make it 2nd arg for canned sequence.
143         $($*-ENV) $(built-program-file) > $@
144 endif   # tests
145 \f
146 .PHONY: distclean realclean subdir_distclean subdir_realclean \
147         subdir_clean subdir_mostlyclean
148 subdir_mostlyclean: mostlyclean
149 subdir_clean: clean
150 subdir_distclean: distclean
151 subdir_realclean: realclean
152 realclean: distclean
153 distclean: clean
154
155 .PHONY: subdir_echo-headers
156 subdir_echo-headers: echo-headers
157
158 .PHONY: subdir_echo-distinfo
159 subdir_echo-distinfo:
160         @echo $(addprefix +header+,$(headers) $(filter %.h,$(distribute))) \
161               $(addprefix +nodist+,$(generated) $(common-generated) $(dont_distribute))
162
163 # We want to install everything except the library itself, but update all
164 # our portions of the library because the parent make will install it later
165 # (likewise the stubs file).
166 .PHONY: subdir_install
167 subdir_install: install-no-libc.a lib-noranlib stubs
168
169 .PHONY: subdir_TAGS subdir_dist
170 subdir_TAGS: TAGS
171 subdir_dist: dist
172
173 # Convenient target to update all the generated source files.
174 .PHONY: generated
175 generated: $(addprefix $(common-objpfx),$(common-generated)) \
176         $(addprefix $(objpfx),$(generated))
177
178 define o-iterator-doit
179 $(common-objpfx)empty$o: $(common-objpfx)empty.c $(before-compile);
180         $$(compile-command.c)
181 endef
182 object-suffixes-left := $(object-suffixes)
183 include $(o-iterator)
184
185 define o-iterator-doit
186 $(common-objpfx)dummy$o: $(common-objpfx)dummy.c $(before-compile);
187         $$(compile-command.c)
188 endef
189 object-suffixes-left := $(object-suffixes)
190 include $(o-iterator)