]>
Commit | Line | Data |
---|---|---|
28f540f4 RM |
1 | # Copyright (C) 1991, 1992, 1993, 1994, 1995 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 | |
16 | # not, write to the Free Software Foundation, Inc., 675 Mass Ave, | |
17 | # Cambridge, MA 02139, USA. | |
18 | ||
19 | # | |
20 | # Common rules for making the GNU C library. This file is included | |
21 | # by the top-level Makefile and by all subdirectory makefiles | |
22 | # (through Rules). | |
23 | # | |
24 | ifneq (,) | |
25 | This makefile requires GNU Make. | |
26 | endif | |
27 | ||
28 | ||
29 | ifdef subdir | |
30 | .. := ../ | |
31 | endif # subdir | |
32 | ||
33 | # If `sources' was defined by the parent makefile, undefine it so | |
34 | # we will later get it from wildcard search in this directory. | |
35 | ifneq "$(findstring env,$(origin sources))" "" | |
36 | sources := | |
37 | endif | |
38 | ||
39 | headers := $(headers) $(sysdep_headers) | |
40 | ||
41 | oPATH := $(PATH) | |
42 | PATH := this definition should take precedence over $(oPATH) | |
43 | ifeq ($(PATH),$(oPATH)) | |
44 | You must not use the -e flag when building the GNU C library. | |
45 | else | |
46 | PATH := $(oPATH) | |
47 | endif | |
48 | \f | |
49 | ifndef +included-Makeconfig | |
50 | include $(..)Makeconfig | |
51 | endif | |
52 | ||
53 | # `configure' writes a definition of `config-sysdirs' in `config.make'. | |
54 | sysdirs = $(config-sysdirs) | |
55 | ||
56 | +sysdir_pfx = $(common-objpfx) | |
57 | ||
58 | export sysdirs := $(sysdirs) | |
59 | ||
60 | +sysdep_dirs := $(addprefix $(sysdep_dir)/,$(sysdirs)) | |
61 | ifdef objdir | |
62 | +sysdep_dirs := $(objdir) $(+sysdep_dirs) | |
63 | endif | |
64 | ||
65 | # Add -I switches to get the right sysdep directories. | |
66 | # `+includes' in Makeconfig references $(+sysdep-includes). | |
67 | +sysdep-includes := $(addprefix -I,$(+sysdep_dirs)) | |
68 | \f | |
69 | # Include any system-specific makefiles. | |
70 | ||
71 | # This is here so things in sysdep Makefiles can easily depend on foo.h as | |
72 | # appropriate and not worry about where foo.h comes from, which may be | |
73 | # system dependent and not known by that Makefile. | |
74 | vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) \ | |
75 | $(addprefix $(sysdep_dir)/,$(sysdirs)) \ | |
76 | $(..))) | |
77 | ||
78 | ifeq ($(wildcard $(+sysdir_pfx)sysd-Makefile),) | |
79 | # Don't do deps until this exists, because it might change the sources list. | |
80 | no_deps=t | |
81 | endif | |
82 | ||
83 | # Some sysdep makefiles use this to distinguish being included here from | |
84 | # being included individually by a subdir makefile (hurd/Makefile needs this). | |
85 | in-Makerules := yes | |
86 | ||
87 | ifndef avoid-generated | |
88 | include $(+sysdir_pfx)sysd-Makefile | |
273d56ce RM |
89 | ifneq ($(sysd-Makefile-sysdirs),$(sysdirs)) |
90 | sysd-Makefile-force = FORCE | |
91 | FORCE: | |
92 | endif | |
93 | $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \ | |
94 | $(sysd-Makefile-force) | |
28f540f4 | 95 | -@rm -f $@T |
273d56ce RM |
96 | (echo 'sysd-Makefile-sysdirs := $(sysdirs)'; \ |
97 | for dir in $(sysdirs); do \ | |
28f540f4 RM |
98 | file=sysdeps/$$dir/Makefile; \ |
99 | if [ -f $(..)$$file ]; then \ | |
100 | echo include "\$$(..)$$file"; \ | |
101 | else true; fi; \ | |
102 | done; \ | |
103 | echo 'sysd-Makefile-done=t') > $@T | |
104 | mv -f $@T $@ | |
105 | endif | |
106 | ||
107 | # Reorder before-compile so that mach things come first, and hurd things | |
108 | # second, before all else. The mach and hurd subdirectories have many | |
109 | # generated header files which the much of rest of the library depends on, | |
110 | # so it is best to build them first (and mach before hurd, at that). | |
111 | before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\ | |
112 | $(before-compile)) \ | |
113 | $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\ | |
114 | $(before-compile)) | |
115 | ||
116 | # Remove existing files from `before-compile'. Things are added there when | |
117 | # they must exist for dependency generation to work right, but once they | |
118 | # exist there is no further need for every single file to depend on them, | |
119 | # and those gratuitous dependencies result in many gratuitous | |
120 | # recompilations. | |
121 | before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile)) | |
122 | ||
123 | # Don't let any before-compile file be an intermediate and get removed. | |
124 | ifdef before-compile | |
125 | $(before-compile): | |
126 | endif | |
127 | \f | |
128 | # Generate an ordered list of implicit rules which find the source files in | |
129 | # each sysdep directory. The old method was to use vpath to search all the | |
130 | # sysdep directories. However, that had the problem that a .S file in a | |
131 | # later directory would be chosen over a .c file in an earlier directory, | |
132 | # which does not preserve the desired sysdeps ordering behavior. | |
133 | ||
134 | # When making the list of .d files to include, we can't know which ones | |
135 | # have source in .s files, and thus do not in fact need a .d file. | |
136 | # So we must define rules to make .d files for .s files. | |
137 | define make-dummy-dep | |
138 | $(addprefix ln $(objpfx)dummy.d ,$(filter-out $(wildcard $@),$@)) | |
139 | endef | |
140 | $(objpfx)dummy.d: | |
141 | echo '# .s files cannot contain includes, so they need no deps.' > $@ | |
142 | ||
143 | # It matters that this set of rules, for compiling from sources in | |
144 | # the current directory (the $srcdir/$subdir) come before the | |
145 | # generated sysdep rules in included from sysd-rules below. When | |
146 | # compiling in the source tree, generated sources go into the current | |
147 | # directory, and those should be chosen before any sources in sysdeps. | |
148 | $(objpfx)%.o: %.S $(before-compile); $(compile-command.S) | |
51f75302 RM |
149 | $(objpfx)%.so: %.S $(before-compile); $(compile-command.S) |
150 | $(objpfx)%.po: %.S $(before-compile); $(compile-command.S) | |
151 | $(objpfx)%.go: %.S $(before-compile); $(compile-command.S) | |
28f540f4 RM |
152 | $(objpfx)%.d: %.S $(before-compile); $(+make-deps) |
153 | $(objpfx)%.o: %.s $(before-compile); $(compile-command.s) | |
51f75302 RM |
154 | $(objpfx)%.so: %.s $(before-compile); $(compile-command.s) |
155 | $(objpfx)%.po: %.s $(before-compile); $(compile-command.s) | |
156 | $(objpfx)%.go: %.s $(before-compile); $(compile-command.s) | |
28f540f4 RM |
157 | $(objpfx)%.d: %.s $(objpfx)dummy.d; $(make-dummy-dep) |
158 | $(objpfx)%.o: %.c $(before-compile); $(compile-command.c) | |
51f75302 RM |
159 | $(objpfx)%.so: %.c $(before-compile); $(compile-command.c) |
160 | $(objpfx)%.po: %.c $(before-compile); $(compile-command.c) | |
161 | $(objpfx)%.go: %.c $(before-compile); $(compile-command.c) | |
28f540f4 RM |
162 | $(objpfx)%.d: %.c $(before-compile); $(+make-deps) |
163 | ||
164 | # Omit the objpfx rules when building in the source tree, because | |
165 | # objpfx is empty and so these rules just override the ones above. | |
166 | ifdef objpfx | |
167 | # Define first rules to find the source files in $(objpfx). | |
168 | # Generated source files will end up there. | |
169 | $(objpfx)%.o: $(objpfx)%.S $(before-compile); $(compile-command.S) | |
51f75302 RM |
170 | $(objpfx)%.so: $(objpfx)%.S $(before-compile); $(compile-command.S) |
171 | $(objpfx)%.po: $(objpfx)%.S $(before-compile); $(compile-command.S) | |
172 | $(objpfx)%.go: $(objpfx)%.S $(before-compile); $(compile-command.S) | |
28f540f4 RM |
173 | $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps) |
174 | $(objpfx)%.o: $(objpfx)%.s $(before-compile); $(compile-command.s) | |
51f75302 RM |
175 | $(objpfx)%.so: $(objpfx)%.s $(before-compile); $(compile-command.s) |
176 | $(objpfx)%.po: $(objpfx)%.s $(before-compile); $(compile-command.s) | |
177 | $(objpfx)%.go: $(objpfx)%.s $(before-compile); $(compile-command.s) | |
28f540f4 RM |
178 | $(objpfx)%.d: $(objpfx)%.s $(objpfx)dummy.d; $(make-dummy-dep) |
179 | $(objpfx)%.o: $(objpfx)%.c $(before-compile); $(compile-command.c) | |
51f75302 RM |
180 | $(objpfx)%.so: $(objpfx)%.c $(before-compile); $(compile-command.c) |
181 | $(objpfx)%.po: $(objpfx)%.c $(before-compile); $(compile-command.c) | |
182 | $(objpfx)%.go: $(objpfx)%.c $(before-compile); $(compile-command.c) | |
28f540f4 RM |
183 | $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps) |
184 | endif | |
185 | ||
186 | # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard | |
187 | # patterns matching sysdep directories whose assembly source files should | |
188 | # be suppressed. | |
189 | ifdef inhibit-sysdep-asm | |
190 | define open-check-inhibit-asm | |
191 | case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *) | |
192 | endef | |
51f75302 | 193 | close-check-inhibit-asm = ;; esac ; |
28f540f4 RM |
194 | endif |
195 | ||
196 | # Don't include sysd-rules until sysd-Makefile is already there and has been | |
197 | # included. It might define inhibit-sysdep-asm, which would affect the | |
198 | # contents of sysd-rules. | |
199 | ifdef sysd-Makefile-done | |
200 | include $(+sysdir_pfx)sysd-rules | |
273d56ce RM |
201 | ifneq ($(sysd-rules-sysdirs),$(sysdirs)) |
202 | # The value of $(sysdirs) the sysd-rules was computed for | |
203 | # differs from the one we are using now. So force a rebuild of sysd-rules. | |
204 | sysd-rules-force = FORCE | |
205 | FORCE: | |
206 | endif | |
28f540f4 RM |
207 | endif |
208 | $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \ | |
209 | $(wildcard $(foreach dir,$(sysdirs),\ | |
273d56ce RM |
210 | $(sysdep_dir)/$(dir)/Makefile))\ |
211 | $(sysd-rules-force) | |
28f540f4 | 212 | -@rm -f $@T |
273d56ce RM |
213 | (echo 'sysd-rules-sysdirs := $(sysdirs)'; \ |
214 | for sysdir in $(sysdirs); do \ | |
28f540f4 | 215 | dir="\$$(sysdep_dir)/$$sysdir"; \ |
51f75302 RM |
216 | for o in $(object-suffixes); do \ |
217 | $(open-check-inhibit-asm) \ | |
218 | echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \ | |
219 | \$$(compile-command.S)"; \ | |
220 | echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \ | |
221 | \$$(compile-command.s)"; \ | |
222 | $(close-check-inhibit-asm) \ | |
223 | echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \ | |
224 | \$$(compile-command.c)"; \ | |
225 | done; \ | |
28f540f4 | 226 | $(open-check-inhibit-asm) \ |
51f75302 RM |
227 | echo "\$$(objpfx)%.d: $$dir/%.s \$$(objpfx)dummy.d; \ |
228 | \$$(make-dummy-dep)"; \ | |
28f540f4 RM |
229 | echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \ |
230 | \$$(+make-deps)"; \ | |
51f75302 | 231 | $(close-check-inhibit-asm) \ |
28f540f4 RM |
232 | echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \ |
233 | \$$(+make-deps)"; \ | |
234 | done) > $@T | |
235 | mv -f $@T $@ | |
236 | ||
237 | ifndef compile-command.S | |
238 | compile-command.S = $(compile.S) $(OUTPUT_OPTION) | |
239 | endif | |
240 | ifndef compile-command.s | |
241 | compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION) | |
242 | endif | |
243 | ifndef compile-command.c | |
244 | compile-command.c = $(compile.c) $(OUTPUT_OPTION) | |
245 | endif | |
246 | ||
28f540f4 RM |
247 | # GCC can grok options after the file name, and it looks nicer that way. |
248 | compile.S = $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) | |
249 | compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS) | |
28f540f4 | 250 | |
28f540f4 RM |
251 | # We need this for the output to go in the right place. It will default to |
252 | # empty if make was configured to work with a cc that can't grok -c and -o | |
253 | # together. You can't compile the C library with such a compiler. | |
254 | OUTPUT_OPTION = -o $@ | |
28f540f4 RM |
255 | |
256 | S-CPPFLAGS = $(asm-CPPFLAGS) | |
257 | define +make-deps | |
258 | -@rm -f $@ | |
259 | $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \ | |
51f75302 RM |
260 | sed -e 's,$*\.o,$(foreach o,$(object-suffixes),$(@:.d=$o)) $@,' \ |
261 | $(sed-remove-objpfx) > $(@:.d=.T) | |
28f540f4 RM |
262 | mv -f $(@:.d=.T) $@ |
263 | endef | |
264 | ifneq (,$(objpfx)) | |
265 | sed-remove-objpfx = -e 's@ $(subst @,\@,$(objpfx))@ $$(objpfx)@g' \ | |
266 | -e 's@^$(subst @,\@,$(objpfx))@$$(objpfx)@g' | |
267 | endif | |
268 | \f | |
269 | # Figure out the source filenames in this directory. | |
270 | ||
271 | override sources := $(addsuffix .c,$(filter-out $(elided-routines),\ | |
272 | $(routines) $(aux) \ | |
273 | $(sysdep_routines))) | |
274 | sysdep_routines := $(sysdep_routines) | |
275 | ||
276 | # This is the list of all object files, gotten by | |
277 | # replacing every ".c" in `sources' with a ".o". | |
278 | override objects := $(addprefix $(objpfx),$(sources:.c=.o)) | |
693e7b96 RM |
279 | |
280 | ||
281 | # This variable is used in ``include $(o-iterator)'' after defining | |
282 | # $(o-iterator-doit) to produce some desired rule using $o for the object | |
283 | # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy | |
284 | # is produced for each object suffix in use. | |
285 | o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes)) | |
286 | ||
287 | # The makefile may define $(extra-libs) with `libfoo libbar' | |
288 | # to build libfoo.a et al from the modules listed in $(libfoo-routines). | |
289 | ifdef extra-libs | |
290 | # extra-lib.mk is included once for each extra lib to define rules | |
291 | # to build it, and to add its objects to the various variables. | |
292 | # During its evaluation, $(lib) is set to the name of the library. | |
293 | extra-libs-left := $(extra-libs) | |
294 | include $(patsubst %,$(..)extra-lib.mk,$(extra-libs)) | |
295 | endif | |
28f540f4 RM |
296 | \f |
297 | +depfiles := $(strip $(sources:.c=.d) \ | |
8c0dc19c | 298 | $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.so=.o))) \ |
28f540f4 RM |
299 | $(addsuffix .d,$(others) $(tests))) |
300 | +depfiles := $(addprefix $(objpfx),\ | |
301 | $(filter-out $(addsuffix .d,$(omit-deps)),\ | |
302 | $(+depfiles))) | |
303 | ||
304 | $(objpfx)depend-$(subdir): Makefile | |
305 | ifdef +depfiles | |
306 | for file in $(+depfiles:$(objpfx)%=%); do \ | |
307 | echo "include \$$(objpfx)$$file"; \ | |
308 | done > $@-tmp | |
309 | mv -f $@-tmp $@ | |
310 | else | |
311 | cp /dev/null $@ | |
312 | endif | |
313 | ||
314 | ifneq ($(no_deps),t) | |
315 | # Include the generated dependencies of the sources in this directory. | |
316 | include $(objpfx)depend-$(subdir) | |
317 | endif | |
318 | \f\f | |
319 | # Maximize efficiency by minimizing the number of rules. | |
320 | .SUFFIXES: # Clear the suffix list. | |
321 | # Add the suffixes we use. | |
51f75302 | 322 | .SUFFIXES: .a $(object-suffixes) .S .s .c .h .d |
28f540f4 RM |
323 | |
324 | # Generic rule for making directories. | |
325 | %/: | |
326 | # mkdir isn't smart enough to strip a trailing /. | |
327 | mkdir $(@:%/=%) | |
328 | \f | |
329 | # Make sure that object files are not removed | |
330 | # when they are intermediates between sources and library members. | |
51f75302 | 331 | .PRECIOUS: $(addprefix $(objpfx)%,$(object-suffixes)) |
28f540f4 RM |
332 | |
333 | # Make sure that the parent library archive is never removed. | |
51f75302 | 334 | .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c)) |
28f540f4 RM |
335 | \f |
336 | # Use the verbose option of ar and tar when not running silently. | |
337 | ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s | |
338 | verbose := v | |
339 | else # -s | |
340 | verbose := | |
341 | endif # not -s | |
342 | ||
343 | ARFLAGS := r$(verbose) | |
344 | \f | |
345 | # This makes all the object files in the parent library archive. | |
346 | ||
347 | .PHONY: lib libobjs lib-noranlib | |
4788ab46 | 348 | lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c)) |
51f75302 RM |
349 | |
350 | # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib. | |
351 | lib%.a: lib%.a(__.SYMDEF) ; | |
352 | ||
51f75302 RM |
353 | libobjs: $(foreach o,$(object-suffixes),\ |
354 | $(common-objpfx)$(patsubst %,$(libtype$o),c)(\ | |
355 | $(notdir $(objects:.o=$o)))) | |
4788ab46 | 356 | lib-noranlib: libobjs $(addprefix $(objpfx),$(install-lib)) |
28f540f4 | 357 | |
28f540f4 | 358 | ifdef objects |
51f75302 RM |
359 | |
360 | # Define a pattern rule that will match many targets libc.a(foo.%), for | |
361 | # each foo.o in $(objects) (% will just happen always to match `o'). This is | |
362 | # the only way to define a rule that updates many targets at once with one | |
363 | # sequence of commands. We in fact define the pattern rule to match | |
364 | # targets libc.a(foo.%), libc_pic.a(foo.%), etc, to avoid repeating the rule. | |
365 | # Each match will only ever be called upon to make member objects of | |
366 | # the appropriate type in each library (i.e. libc_pic.a(foo.so)). | |
367 | $(foreach l,$(libtypes),\ | |
368 | $(common-objpfx)$(patsubst %,$l,c)($(notdir $(objects:.o=.%)))): \ | |
369 | $(objpfx)stamp.%-$(subdir) ; | |
370 | ||
371 | # The pattern rule tells Make to remake $(objpfx)stamp.%-$(subdir) as | |
372 | # the way to update all the foo.% object files in $(objects). | |
373 | # Now we define a static pattern rule to update each | |
374 | # $(objpfx)stamp.SUFFIX-$(subdir) timestamp file; | |
375 | # these rules (one explicit rule is generated for each object suffix) | |
376 | # will update the parent archive with | |
377 | $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir)): \ | |
378 | $(objpfx)stamp%-$(subdir): $(objects:.o=%) | |
379 | $(patsubst %,cd %;,$(objdir)) \ | |
380 | $(AR) cru$(verbose) ${O%-lib} \ | |
381 | $(patsubst $(objpfx)%,%,$^) | |
d819080c RM |
382 | # `touch' won't let me touch a world-writable file I don't own. Sigh. |
383 | rm -f $@ | |
28f540f4 | 384 | touch $@ |
e215c478 | 385 | ifdef subdir |
51f75302 | 386 | O%-lib = $(filter ../,$(firstword $(objdir) ../))$(patsubst %,$(libtype$*),c) |
e215c478 RM |
387 | else |
388 | O%-lib = $(patsubst %,$(libtype$*),c) | |
389 | endif | |
28f540f4 | 390 | |
51f75302 | 391 | endif |
28f540f4 | 392 | |
51f75302 RM |
393 | # Rules to update the __.SYMDEF member with ranlib. |
394 | # To consolidate, each flavor library's __.SYMDEF member | |
395 | # depends on the imaginary intermediate file `symdef.SUFFIX', | |
396 | # where SUFFIX is that flavor's object suffix; then a pattern rule | |
397 | # "remakes" symdef.% depending on all the libc.a(foo.%) files in $(objects). | |
398 | $(common-objpfx)$(patsubst %,$(libtype.o),c)(__.SYMDEF): symdef.o | |
399 | $(common-objpfx)$(patsubst %,$(libtype.so),c)(__.SYMDEF): symdef.so | |
400 | $(common-objpfx)$(patsubst %,$(libtype.po),c)(__.SYMDEF): symdef.po | |
401 | $(common-objpfx)$(patsubst %,$(libtype.go),c)(__.SYMDEF): symdef.go | |
402 | symdef.%: $(foreach o,$(object-suffixes),\ | |
403 | $(common-objpfx)$(patsubst %,$(libtype$o),c)(\ | |
404 | $(patsubst $(objpfx)%.o,%.%,$(objects)))) \ | |
405 | $(filter subdir_lib,$(firstword $(subdir) subdir_lib)) | |
406 | # The last line above makes it also depend on subdir_lib for the parent. | |
407 | $(RANLIB) $(common-objpfx)$(patsubst %,$(libtype.$*),c) | |
28f540f4 RM |
408 | |
409 | # This makes all the object files. | |
410 | .PHONY: objects objs | |
51f75302 RM |
411 | objects objs: $(foreach o,$(object-suffixes),$(objects:.o=$o)) \ |
412 | $(addprefix $(objpfx),$(extra-objs)) | |
f0bf9cb9 RM |
413 | |
414 | # Canned sequence for building an extra library archive. | |
415 | define build-extra-lib | |
416 | $(patsubst %,cd %;,$(objdir)) \ | |
417 | $(AR) cru$(verbose) $(@:$(objpfx)%=%) \ | |
418 | $(patsubst $(objpfx)%,%,$^) | |
419 | $(RANLIB) $@ | |
420 | endef | |
28f540f4 RM |
421 | \f |
422 | # Installation. | |
423 | ||
424 | # $(install-lib) are installed from the object directory into $(libdir); | |
425 | # files in $(install-lib) matching `lib%.a' are ranlib'd after installation | |
426 | # unless they also appear in $(non-lib.a). $(install-data) are installed | |
427 | # as they are into $(datadir). $(headers) are installed as they are in | |
428 | # $(includedir). $(install-bin) and $(install-sbin) are installed from the | |
429 | # object directory into $(bindir) and $(sbindir), respectively. | |
430 | # $(install-others) are absolute path names of files to install; rules to | |
431 | # install them are defined elsewhere. | |
432 | ||
433 | # The simple library name to install libc.a under. | |
434 | # This could be defined by a sysdep Makefile. | |
435 | ifndef libc-name | |
436 | libc-name := c | |
437 | endif | |
438 | ||
439 | define do-install | |
440 | $(make-target-directory) | |
441 | $(INSTALL_DATA) $< $@ | |
442 | endef | |
443 | ||
444 | # Make the target directory if it doesn't exist. Because of make's | |
445 | # directory cache, this will produce the `mkdir' command when the directory | |
446 | # already exists, if it didn't exist at the start of the `make' run. The | |
447 | # `-' prefix ignores errors from mkdir, so there will just be some | |
448 | # gratuitous but harmless `File exists' messages. | |
449 | define make-target-directory | |
450 | $(addprefix -mkdir ,$(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%))) | |
451 | endef | |
452 | ||
453 | # Any directory (parent or subdir) that has any object files to build | |
454 | # should install libc.a; this way "make install" in a subdir is guaranteed | |
455 | # to install everything it changes. | |
456 | ifdef objects | |
51f75302 RM |
457 | installed-libcs := $(foreach o,$(object-suffixes),\ |
458 | $(libdir)/$(patsubst %,$(libtype$o),\ | |
459 | $(libprefix)$(libc-name))) | |
460 | install: $(installed-libcs) | |
28f540f4 RM |
461 | # We avoid depending on lib-noranlib because that makes the parent make |
462 | # subdir_lib in all the subdirs, when the make install run they do will | |
463 | # update the library anyway. Running ranlib after installing makes the | |
464 | # __.SYMDEF time stamp up to date, which avoids messages from some linkers. | |
465 | # Depending on subdir_install gets all the subdirs to update the library, | |
466 | # and is optimal for `make install' at top level. | |
c316b486 | 467 | $(installed-libcs): $(libdir)/lib$(libprefix)%: libobjs subdir_install |
28f540f4 | 468 | $(make-target-directory) |
c316b486 | 469 | $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@ |
28f540f4 RM |
470 | $(RANLIB) $@ |
471 | endif | |
472 | ||
273d56ce RM |
473 | define do-install-program |
474 | $(make-target-directory) | |
475 | $(INSTALL_PROGRAM) $< $@.new | |
476 | mv -f $@.new $@ | |
477 | endef | |
478 | ||
5bf62f2d | 479 | install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so)) |
273d56ce | 480 | install-lib := $(filter-out %.so,$(install-lib)) |
51f75302 | 481 | ifeq (yes,$(build-shared)) |
5bf62f2d RM |
482 | install: $(libdir)/libc.so$(libc.so-version) |
483 | install-no-libc.a: $(foreach so,$(install-lib.so),\ | |
273d56ce RM |
484 | $(libdir)/$(patsubst $(libprefix)lib%,lib$(libprefix)%,\ |
485 | $(libprefix)$(so))$($(so)-version)) | |
5bf62f2d RM |
486 | |
487 | install-lib.so += libc.so | |
87220b35 | 488 | $(foreach v,$(sort $(foreach so,$(install-lib.so),.so$($(so)-version))),\ |
273d56ce RM |
489 | $(libdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so |
490 | $(do-install-program) | |
87220b35 | 491 | $(foreach v,$(sort $(foreach so,$(install-lib.so),.so$($(so)-version))),\ |
273d56ce RM |
492 | $(libdir)/$(libprefix)%$v): $(common-objpfx)%.so |
493 | $(do-install-program) | |
51f75302 RM |
494 | endif |
495 | ||
28f540f4 RM |
496 | ifdef install-bin |
497 | $(addprefix $(bindir)/,$(install-bin)): $(bindir)/%: $(objpfx)% | |
273d56ce | 498 | $(do-install-program) |
28f540f4 RM |
499 | endif |
500 | ifdef install-sbin | |
501 | $(addprefix $(sbindir)/,$(install-sbin)): $(sbindir)/%: $(objpfx)% | |
273d56ce | 502 | $(do-install-program) |
28f540f4 RM |
503 | endif |
504 | ifdef install-lib | |
505 | install-lib.a := $(filter lib%.a,$(install-lib)) | |
506 | install-lib-non.a := $(filter-out lib%.a,$(install-lib)) | |
507 | ifdef install-lib-non.a | |
508 | $(addprefix $(libdir)/$(libprefix),$(install-lib-non.a)): \ | |
509 | $(libdir)/$(libprefix)%: $(objpfx)% | |
510 | $(do-install) | |
511 | endif | |
512 | ifdef install-lib.a | |
513 | $(install-lib.a:lib%.a=$(libdir)/lib$(libprefix)%.a): \ | |
514 | $(libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a | |
515 | $(do-install) | |
516 | $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F))) | |
517 | endif | |
518 | endif | |
519 | ifdef install-data | |
520 | $(addprefix $(datadir)/,$(install-data)): $(datadir)/%: %;$(do-install) | |
521 | endif | |
522 | headers := $(strip $(headers)) | |
523 | ifdef headers | |
524 | $(addprefix $(includedir)/,$(headers)): \ | |
525 | $(includedir)/%: %;$(do-install) | |
526 | endif # headers | |
527 | ||
528 | .PHONY: install-bin-nosubdir install-sbin-nosubdir install-lib-nosubdir \ | |
529 | install-data-nosubdir install-headers-nosubdir | |
530 | install-bin-nosubdir: $(addprefix $(bindir)/,$(install-bin)) | |
531 | install-sbin-nosubdir: $(addprefix $(sbindir)/,$(install-sbin)) | |
532 | install-lib-nosubdir: $(addprefix $(libdir)/,\ | |
533 | $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \ | |
534 | $(addprefix $(libprefix),$(install-lib-non.a))) | |
535 | install-data-nosubdir: $(addprefix $(datadir)/,$(install-data)) | |
536 | install-headers-nosubdir: $(addprefix $(includedir)/,$(headers)) | |
537 | install-others-nosubdir: $(install-others) | |
538 | ||
539 | # We need all the `-nosubdir' targets so that `install' in the parent | |
540 | # doesn't depend on several things which each iterate over the subdirs. | |
541 | # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a | |
542 | # subroutine. Then in the parent `install-FOO' also causes subdir makes. | |
543 | install-%:: install-%-nosubdir ; | |
544 | ||
545 | .PHONY: install install-no-libc.a-nosubdir | |
546 | install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\ | |
547 | install-bin-nosubdir install-lib-nosubdir \ | |
548 | install-others-nosubdir install-sbin-nosubdir | |
549 | install: install-no-libc.a-nosubdir | |
550 | \f | |
1a2df358 RM |
551 | ifeq (yes,$(build-shared)) |
552 | # Pattern rule to build a shared object from an archive of PIC objects. | |
553 | # This must come after the installation rules so Make doesn't try to | |
554 | # build shared libraries in place from the installed *_pic.a files. | |
555 | # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies | |
556 | # on other shared objects. | |
557 | lib%.so: lib%_pic.a | |
d819080c RM |
558 | $(LINK.o) -shared -o $@ -Wl,-soname \ |
559 | -Wl,lib$(libprefix)$(notdir $*).so$($(@F)-version) \ | |
1a2df358 RM |
560 | $(LDFLAGS.so) $(LDFLAGS-$(notdir $*).so) \ |
561 | -L$(firstword $(objdir) .) -L$(common-objpfx:%/=%) \ | |
562 | $(LDLIBS-$(notdir $*).so) -Wl,--whole-archive $< \ | |
563 | ||
564 | # Don't try to use -lc when making libc.so itself. | |
565 | # Also omits crti.o and crtn.o, which we do not want | |
566 | # since we define our own `.init' section specially. | |
567 | LDFLAGS-c.so = -nostdlib -nostartfiles | |
568 | # Give libc.so an entry point and make it directly runnable itself. | |
569 | LDFLAGS-c.so += -Wl,-dynamic-linker -Wl,/lib/ld.so -e __libc_print_version | |
570 | endif | |
571 | ||
572 | ||
28f540f4 RM |
573 | # Command to compile $< in $(objdir) using the native libraries. |
574 | define native-compile | |
575 | cwd=`pwd`; cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) \ | |
576 | $(addprefix $$cwd/,$^) -o $(@F) | |
577 | endef | |
578 | ||
579 | # Command to compile $< in $(common-objdir) using the native libraries. | |
580 | define common-objdir-compile | |
581 | cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=%) -o $(@F) | |
582 | endef | |
583 | ||
584 | # We always want to use configuration definitions. | |
585 | BUILD_CFLAGS = -include $(common-objpfx)config.h | |
586 | ||
587 | # Support the GNU standard name for this target. | |
588 | .PHONY: check | |
589 | check: tests | |
590 | \f | |
591 | .PHONY: TAGS | |
592 | TAGS: distinfo $(..)MakeTAGS | |
593 | $(MAKE) $(addprefix -f ,$^) | |
594 | ||
595 | .PHONY: echo-headers | |
596 | echo-headers: | |
597 | @echo $(headers) | |
598 | ||
599 | \f | |
600 | # Common cleaning targets. | |
601 | ||
602 | .PHONY: common-mostlyclean common-clean mostlyclean clean | |
603 | clean: common-clean | |
604 | mostlyclean: common-mostlyclean | |
605 | ||
606 | # Remove the object files. | |
607 | common-mostlyclean: | |
608 | -rm -f $(addprefix $(objpfx),$(tests) $(others) \ | |
609 | $(addsuffix .o,$(tests) $(others)) \ | |
610 | $(addsuffix .out,$(tests))) | |
4788ab46 RM |
611 | -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib)) |
612 | -rm -f core $(objpfx)stub-$(subdir) | |
51f75302 RM |
613 | $(rmobjs) |
614 | define rmobjs | |
615 | $(foreach o,$(object-suffixes), | |
616 | -rm -f $(addprefix $(objpfx),stamp$o-$(subdir)) $(objects:.o=$o)) | |
617 | endef | |
28f540f4 RM |
618 | |
619 | # Also remove the dependencies and generated source files. | |
620 | common-clean: common-mostlyclean | |
621 | -rm -f $(objpfx)depend-$(subdir) $(+depfiles) | |
622 | -rm -f $(addprefix $(objpfx),$(generated)) | |
623 | \f | |
624 | # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION' | |
625 | # for each function which is a stub. We grovel over all the .d files | |
626 | # looking for references to source files in sysdeps/stub. Then we grovel | |
627 | # over each referenced source file to see what stub function it defines. | |
628 | ||
629 | .PHONY: stubs # The parent Makefile calls this target. | |
630 | stubs: $(common-objpfx)stub-$(subdir) | |
631 | s = $(sysdep_dir)/stub | |
632 | $(common-objpfx)stub-$(subdir): $(+depfiles) | |
633 | # Use /dev/null since `...` might expand to empty. | |
634 | s=`cd $s; /bin/pwd`; \ | |
635 | $(patsubst %,cd %;,$(objdir)) \ | |
636 | sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \ | |
637 | `sed -n 's@^.*$s/\([a-z0-9_-]*\.c\).*$$@'"$$s"/'\1@p' \ | |
638 | $(patsubst $(objpfx)%,%,$^) /dev/null` \ | |
639 | /dev/null > $@T | |
640 | mv -f $@T $@ | |
641 | \f | |
642 | # Make the distribution tar file. | |
643 | ||
644 | .PHONY: dist | |
645 | dist: distinfo $(..)Make-dist | |
646 | $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args) | |
647 | ||
10ceac89 RM |
648 | # Avoid depending on source files found in sysdeps dirs, |
649 | # because the references affect implicit rule selection. | |
650 | dist: $(filter-out %.c %.S %.s,$(distribute)) | |
28f540f4 RM |
651 | |
652 | # We used to simply export all these variables, but that frequently made the | |
653 | # environment get too large. Instead, we write all the information into | |
654 | # a generated makefile fragment `distinfo', and then include it with -f in | |
655 | # the sub-make that makes the distribution (above). | |
656 | distinfo: Makefile $(..)Makerules | |
657 | $(distinfo-vars) | |
658 | mv -f $@.new $@ | |
659 | ||
660 | define distinfo-vars | |
661 | rm -f $@.new | |
662 | $(foreach var,subdir sources elided-routines headers distribute \ | |
663 | dont_distribute generated others tests, | |
664 | echo >> $@.new '$(var) := $($(var))') | |
665 | echo >> $@.new 'sources := $$(sources) $$(addsuffix .c,$$(elided-routines))' | |
666 | endef | |
667 | \f | |
668 | ifneq (,$(strip $(gpl2lgpl))) | |
669 | ifneq (,$(wildcard $(..)gpl2lgpl.sed)) | |
670 | # Snarf from the master source and frob the copying notice. | |
671 | $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/% | |
672 | sed -f $^ > $@-tmp | |
673 | # So I don't edit them by mistake. | |
674 | chmod a-w $@-tmp | |
675 | mv -f $@-tmp $@ | |
a2fe9c76 | 676 | test ! -d CVS || cvs commit -m'Updated from $^' $@ |
28f540f4 RM |
677 | endif |
678 | endif |