]>
Commit | Line | Data |
---|---|---|
aeb72b16 | 1 | # Copyright (C) 1991, 92, 93, 94, 95, 96 Free Software Foundation, Inc. |
28f540f4 RM |
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)) | |
dbdb6189 RM |
68 | |
69 | # The name of the symbol table archive member. The default is suitable for | |
70 | # BSD style archives. It can be overridden in sysdep Makefiles when SYSV | |
71 | # style archive are used. | |
01f3e03b | 72 | ifeq (no,$(elf)) |
dbdb6189 | 73 | ar-symtab-name = __.SYMDEF |
01f3e03b RM |
74 | else |
75 | ar-symtab-name = # The null name is used in ELF archives. | |
76 | endif | |
28f540f4 RM |
77 | \f |
78 | # Include any system-specific makefiles. | |
79 | ||
80 | # This is here so things in sysdep Makefiles can easily depend on foo.h as | |
81 | # appropriate and not worry about where foo.h comes from, which may be | |
82 | # system dependent and not known by that Makefile. | |
83 | vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) \ | |
84 | $(addprefix $(sysdep_dir)/,$(sysdirs)) \ | |
85 | $(..))) | |
86 | ||
28f540f4 RM |
87 | # Some sysdep makefiles use this to distinguish being included here from |
88 | # being included individually by a subdir makefile (hurd/Makefile needs this). | |
89 | in-Makerules := yes | |
90 | ||
91 | ifndef avoid-generated | |
555f3a39 | 92 | -include $(+sysdir_pfx)sysd-Makefile |
273d56ce RM |
93 | ifneq ($(sysd-Makefile-sysdirs),$(sysdirs)) |
94 | sysd-Makefile-force = FORCE | |
95 | FORCE: | |
96 | endif | |
97 | $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \ | |
98 | $(sysd-Makefile-force) | |
28f540f4 | 99 | -@rm -f $@T |
273d56ce RM |
100 | (echo 'sysd-Makefile-sysdirs := $(sysdirs)'; \ |
101 | for dir in $(sysdirs); do \ | |
28f540f4 RM |
102 | file=sysdeps/$$dir/Makefile; \ |
103 | if [ -f $(..)$$file ]; then \ | |
104 | echo include "\$$(..)$$file"; \ | |
105 | else true; fi; \ | |
106 | done; \ | |
107 | echo 'sysd-Makefile-done=t') > $@T | |
108 | mv -f $@T $@ | |
109 | endif | |
110 | ||
3bbceb12 RM |
111 | ifndef sysd-Makefile-done |
112 | # Don't do deps until this exists, because it might change the sources list. | |
113 | no_deps=t | |
114 | endif | |
115 | ||
116 | ||
28f540f4 RM |
117 | # Reorder before-compile so that mach things come first, and hurd things |
118 | # second, before all else. The mach and hurd subdirectories have many | |
119 | # generated header files which the much of rest of the library depends on, | |
120 | # so it is best to build them first (and mach before hurd, at that). | |
121 | before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\ | |
122 | $(before-compile)) \ | |
123 | $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\ | |
124 | $(before-compile)) | |
125 | ||
126 | # Remove existing files from `before-compile'. Things are added there when | |
127 | # they must exist for dependency generation to work right, but once they | |
128 | # exist there is no further need for every single file to depend on them, | |
129 | # and those gratuitous dependencies result in many gratuitous | |
130 | # recompilations. | |
131 | before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile)) | |
132 | ||
133 | # Don't let any before-compile file be an intermediate and get removed. | |
134 | ifdef before-compile | |
135 | $(before-compile): | |
136 | endif | |
137 | \f | |
138 | # Generate an ordered list of implicit rules which find the source files in | |
139 | # each sysdep directory. The old method was to use vpath to search all the | |
140 | # sysdep directories. However, that had the problem that a .S file in a | |
141 | # later directory would be chosen over a .c file in an earlier directory, | |
142 | # which does not preserve the desired sysdeps ordering behavior. | |
143 | ||
144 | # When making the list of .d files to include, we can't know which ones | |
145 | # have source in .s files, and thus do not in fact need a .d file. | |
146 | # So we must define rules to make .d files for .s files. | |
147 | define make-dummy-dep | |
148 | $(addprefix ln $(objpfx)dummy.d ,$(filter-out $(wildcard $@),$@)) | |
149 | endef | |
150 | $(objpfx)dummy.d: | |
151 | echo '# .s files cannot contain includes, so they need no deps.' > $@ | |
152 | ||
153 | # It matters that this set of rules, for compiling from sources in | |
154 | # the current directory (the $srcdir/$subdir) come before the | |
155 | # generated sysdep rules in included from sysd-rules below. When | |
156 | # compiling in the source tree, generated sources go into the current | |
157 | # directory, and those should be chosen before any sources in sysdeps. | |
158 | $(objpfx)%.o: %.S $(before-compile); $(compile-command.S) | |
51f75302 RM |
159 | $(objpfx)%.so: %.S $(before-compile); $(compile-command.S) |
160 | $(objpfx)%.po: %.S $(before-compile); $(compile-command.S) | |
161 | $(objpfx)%.go: %.S $(before-compile); $(compile-command.S) | |
28f540f4 RM |
162 | $(objpfx)%.d: %.S $(before-compile); $(+make-deps) |
163 | $(objpfx)%.o: %.s $(before-compile); $(compile-command.s) | |
51f75302 RM |
164 | $(objpfx)%.so: %.s $(before-compile); $(compile-command.s) |
165 | $(objpfx)%.po: %.s $(before-compile); $(compile-command.s) | |
166 | $(objpfx)%.go: %.s $(before-compile); $(compile-command.s) | |
28f540f4 RM |
167 | $(objpfx)%.d: %.s $(objpfx)dummy.d; $(make-dummy-dep) |
168 | $(objpfx)%.o: %.c $(before-compile); $(compile-command.c) | |
51f75302 RM |
169 | $(objpfx)%.so: %.c $(before-compile); $(compile-command.c) |
170 | $(objpfx)%.po: %.c $(before-compile); $(compile-command.c) | |
171 | $(objpfx)%.go: %.c $(before-compile); $(compile-command.c) | |
28f540f4 RM |
172 | $(objpfx)%.d: %.c $(before-compile); $(+make-deps) |
173 | ||
174 | # Omit the objpfx rules when building in the source tree, because | |
175 | # objpfx is empty and so these rules just override the ones above. | |
176 | ifdef objpfx | |
177 | # Define first rules to find the source files in $(objpfx). | |
178 | # Generated source files will end up there. | |
179 | $(objpfx)%.o: $(objpfx)%.S $(before-compile); $(compile-command.S) | |
51f75302 RM |
180 | $(objpfx)%.so: $(objpfx)%.S $(before-compile); $(compile-command.S) |
181 | $(objpfx)%.po: $(objpfx)%.S $(before-compile); $(compile-command.S) | |
182 | $(objpfx)%.go: $(objpfx)%.S $(before-compile); $(compile-command.S) | |
28f540f4 RM |
183 | $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps) |
184 | $(objpfx)%.o: $(objpfx)%.s $(before-compile); $(compile-command.s) | |
51f75302 RM |
185 | $(objpfx)%.so: $(objpfx)%.s $(before-compile); $(compile-command.s) |
186 | $(objpfx)%.po: $(objpfx)%.s $(before-compile); $(compile-command.s) | |
187 | $(objpfx)%.go: $(objpfx)%.s $(before-compile); $(compile-command.s) | |
28f540f4 RM |
188 | $(objpfx)%.d: $(objpfx)%.s $(objpfx)dummy.d; $(make-dummy-dep) |
189 | $(objpfx)%.o: $(objpfx)%.c $(before-compile); $(compile-command.c) | |
51f75302 RM |
190 | $(objpfx)%.so: $(objpfx)%.c $(before-compile); $(compile-command.c) |
191 | $(objpfx)%.po: $(objpfx)%.c $(before-compile); $(compile-command.c) | |
192 | $(objpfx)%.go: $(objpfx)%.c $(before-compile); $(compile-command.c) | |
28f540f4 RM |
193 | $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps) |
194 | endif | |
195 | ||
196 | # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard | |
197 | # patterns matching sysdep directories whose assembly source files should | |
198 | # be suppressed. | |
199 | ifdef inhibit-sysdep-asm | |
200 | define open-check-inhibit-asm | |
201 | case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *) | |
202 | endef | |
51f75302 | 203 | close-check-inhibit-asm = ;; esac ; |
28f540f4 RM |
204 | endif |
205 | ||
206 | # Don't include sysd-rules until sysd-Makefile is already there and has been | |
207 | # included. It might define inhibit-sysdep-asm, which would affect the | |
208 | # contents of sysd-rules. | |
209 | ifdef sysd-Makefile-done | |
555f3a39 | 210 | -include $(+sysdir_pfx)sysd-rules |
273d56ce RM |
211 | ifneq ($(sysd-rules-sysdirs),$(sysdirs)) |
212 | # The value of $(sysdirs) the sysd-rules was computed for | |
213 | # differs from the one we are using now. So force a rebuild of sysd-rules. | |
214 | sysd-rules-force = FORCE | |
215 | FORCE: | |
216 | endif | |
28f540f4 RM |
217 | endif |
218 | $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \ | |
219 | $(wildcard $(foreach dir,$(sysdirs),\ | |
273d56ce RM |
220 | $(sysdep_dir)/$(dir)/Makefile))\ |
221 | $(sysd-rules-force) | |
28f540f4 | 222 | -@rm -f $@T |
273d56ce RM |
223 | (echo 'sysd-rules-sysdirs := $(sysdirs)'; \ |
224 | for sysdir in $(sysdirs); do \ | |
28f540f4 | 225 | dir="\$$(sysdep_dir)/$$sysdir"; \ |
51f75302 RM |
226 | for o in $(object-suffixes); do \ |
227 | $(open-check-inhibit-asm) \ | |
228 | echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \ | |
229 | \$$(compile-command.S)"; \ | |
230 | echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \ | |
231 | \$$(compile-command.s)"; \ | |
232 | $(close-check-inhibit-asm) \ | |
233 | echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \ | |
234 | \$$(compile-command.c)"; \ | |
235 | done; \ | |
28f540f4 | 236 | $(open-check-inhibit-asm) \ |
51f75302 RM |
237 | echo "\$$(objpfx)%.d: $$dir/%.s \$$(objpfx)dummy.d; \ |
238 | \$$(make-dummy-dep)"; \ | |
28f540f4 RM |
239 | echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \ |
240 | \$$(+make-deps)"; \ | |
51f75302 | 241 | $(close-check-inhibit-asm) \ |
28f540f4 RM |
242 | echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \ |
243 | \$$(+make-deps)"; \ | |
3bbceb12 RM |
244 | done; \ |
245 | echo 'sysd-rules-done = t') > $@T | |
28f540f4 RM |
246 | mv -f $@T $@ |
247 | ||
3bbceb12 RM |
248 | ifndef sysd-rules-done |
249 | # Don't do deps until this exists, because it provides rules to make the deps. | |
250 | no_deps=t | |
251 | endif | |
252 | ||
253 | ||
28f540f4 RM |
254 | ifndef compile-command.S |
255 | compile-command.S = $(compile.S) $(OUTPUT_OPTION) | |
256 | endif | |
257 | ifndef compile-command.s | |
258 | compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION) | |
259 | endif | |
260 | ifndef compile-command.c | |
261 | compile-command.c = $(compile.c) $(OUTPUT_OPTION) | |
262 | endif | |
263 | ||
28f540f4 | 264 | # GCC can grok options after the file name, and it looks nicer that way. |
28f540f4 | 265 | compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS) |
aeb72b16 RM |
266 | compile.S = $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) |
267 | COMPILE.S = $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) | |
268 | COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS) | |
28f540f4 | 269 | |
28f540f4 RM |
270 | # We need this for the output to go in the right place. It will default to |
271 | # empty if make was configured to work with a cc that can't grok -c and -o | |
272 | # together. You can't compile the C library with such a compiler. | |
273 | OUTPUT_OPTION = -o $@ | |
28f540f4 RM |
274 | |
275 | S-CPPFLAGS = $(asm-CPPFLAGS) | |
276 | define +make-deps | |
277 | -@rm -f $@ | |
278 | $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \ | |
1177c8ba | 279 | sed -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(object-suffixes),$(@:.d=$o)) $@,' \ |
51f75302 | 280 | $(sed-remove-objpfx) > $(@:.d=.T) |
28f540f4 RM |
281 | mv -f $(@:.d=.T) $@ |
282 | endef | |
283 | ifneq (,$(objpfx)) | |
1177c8ba RM |
284 | sed-remove-objpfx = -e 's@ $(subst .,\., \ |
285 | $(subst @,\@,$(objpfx)))@ $$(objpfx)@g' \ | |
286 | -e 's@^$(subst .,\.,$(subst @,\@,$(objpfx)))@$$(objpfx)@g' | |
28f540f4 RM |
287 | endif |
288 | \f | |
289 | # Figure out the source filenames in this directory. | |
290 | ||
291 | override sources := $(addsuffix .c,$(filter-out $(elided-routines),\ | |
292 | $(routines) $(aux) \ | |
293 | $(sysdep_routines))) | |
294 | sysdep_routines := $(sysdep_routines) | |
295 | ||
296 | # This is the list of all object files, gotten by | |
297 | # replacing every ".c" in `sources' with a ".o". | |
298 | override objects := $(addprefix $(objpfx),$(sources:.c=.o)) | |
693e7b96 RM |
299 | |
300 | ||
301 | # This variable is used in ``include $(o-iterator)'' after defining | |
302 | # $(o-iterator-doit) to produce some desired rule using $o for the object | |
303 | # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy | |
304 | # is produced for each object suffix in use. | |
305 | o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes)) | |
306 | ||
307 | # The makefile may define $(extra-libs) with `libfoo libbar' | |
308 | # to build libfoo.a et al from the modules listed in $(libfoo-routines). | |
309 | ifdef extra-libs | |
310 | # extra-lib.mk is included once for each extra lib to define rules | |
311 | # to build it, and to add its objects to the various variables. | |
312 | # During its evaluation, $(lib) is set to the name of the library. | |
313 | extra-libs-left := $(extra-libs) | |
314 | include $(patsubst %,$(..)extra-lib.mk,$(extra-libs)) | |
315 | endif | |
28f540f4 RM |
316 | \f |
317 | +depfiles := $(strip $(sources:.c=.d) \ | |
8c0dc19c | 318 | $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.so=.o))) \ |
28f540f4 RM |
319 | $(addsuffix .d,$(others) $(tests))) |
320 | +depfiles := $(addprefix $(objpfx),\ | |
321 | $(filter-out $(addsuffix .d,$(omit-deps)),\ | |
322 | $(+depfiles))) | |
323 | ||
28f540f4 | 324 | ifdef +depfiles |
28f540f4 | 325 | ifneq ($(no_deps),t) |
555f3a39 | 326 | -include $(+depfiles) |
deab9dea | 327 | endif |
28f540f4 RM |
328 | endif |
329 | \f\f | |
330 | # Maximize efficiency by minimizing the number of rules. | |
331 | .SUFFIXES: # Clear the suffix list. | |
332 | # Add the suffixes we use. | |
51f75302 | 333 | .SUFFIXES: .a $(object-suffixes) .S .s .c .h .d |
28f540f4 RM |
334 | |
335 | # Generic rule for making directories. | |
336 | %/: | |
337 | # mkdir isn't smart enough to strip a trailing /. | |
338 | mkdir $(@:%/=%) | |
339 | \f | |
340 | # Make sure that object files are not removed | |
341 | # when they are intermediates between sources and library members. | |
51f75302 | 342 | .PRECIOUS: $(addprefix $(objpfx)%,$(object-suffixes)) |
28f540f4 RM |
343 | |
344 | # Make sure that the parent library archive is never removed. | |
51f75302 | 345 | .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c)) |
28f540f4 RM |
346 | \f |
347 | # Use the verbose option of ar and tar when not running silently. | |
348 | ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s | |
349 | verbose := v | |
350 | else # -s | |
351 | verbose := | |
352 | endif # not -s | |
353 | ||
354 | ARFLAGS := r$(verbose) | |
355 | \f | |
356 | # This makes all the object files in the parent library archive. | |
357 | ||
358 | .PHONY: lib libobjs lib-noranlib | |
4788ab46 | 359 | lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c)) |
51f75302 RM |
360 | |
361 | # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib. | |
dbdb6189 | 362 | lib%.a: lib%.a($(ar-symtab-name)) ; |
51f75302 | 363 | |
51f75302 RM |
364 | libobjs: $(foreach o,$(object-suffixes),\ |
365 | $(common-objpfx)$(patsubst %,$(libtype$o),c)(\ | |
366 | $(notdir $(objects:.o=$o)))) | |
3bbceb12 RM |
367 | lib-noranlib: libobjs |
368 | others: $(addprefix $(objpfx),$(install-lib)) | |
28f540f4 | 369 | |
28f540f4 | 370 | ifdef objects |
51f75302 RM |
371 | |
372 | # Define a pattern rule that will match many targets libc.a(foo.%), for | |
373 | # each foo.o in $(objects) (% will just happen always to match `o'). This is | |
374 | # the only way to define a rule that updates many targets at once with one | |
375 | # sequence of commands. We in fact define the pattern rule to match | |
376 | # targets libc.a(foo.%), libc_pic.a(foo.%), etc, to avoid repeating the rule. | |
377 | # Each match will only ever be called upon to make member objects of | |
378 | # the appropriate type in each library (i.e. libc_pic.a(foo.so)). | |
379 | $(foreach l,$(libtypes),\ | |
380 | $(common-objpfx)$(patsubst %,$l,c)($(notdir $(objects:.o=.%)))): \ | |
381 | $(objpfx)stamp.%-$(subdir) ; | |
382 | ||
383 | # The pattern rule tells Make to remake $(objpfx)stamp.%-$(subdir) as | |
384 | # the way to update all the foo.% object files in $(objects). | |
385 | # Now we define a static pattern rule to update each | |
386 | # $(objpfx)stamp.SUFFIX-$(subdir) timestamp file; | |
387 | # these rules (one explicit rule is generated for each object suffix) | |
388 | # will update the parent archive with | |
389 | $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir)): \ | |
390 | $(objpfx)stamp%-$(subdir): $(objects:.o=%) | |
391 | $(patsubst %,cd %;,$(objdir)) \ | |
392 | $(AR) cru$(verbose) ${O%-lib} \ | |
393 | $(patsubst $(objpfx)%,%,$^) | |
d819080c RM |
394 | # `touch' won't let me touch a world-writable file I don't own. Sigh. |
395 | rm -f $@ | |
28f540f4 | 396 | touch $@ |
e215c478 | 397 | ifdef subdir |
51f75302 | 398 | O%-lib = $(filter ../,$(firstword $(objdir) ../))$(patsubst %,$(libtype$*),c) |
e215c478 RM |
399 | else |
400 | O%-lib = $(patsubst %,$(libtype$*),c) | |
401 | endif | |
28f540f4 | 402 | |
51f75302 | 403 | endif |
28f540f4 | 404 | |
dbdb6189 RM |
405 | # Rules to update the $(ar-symtab-name) member with ranlib, |
406 | # one for each object flavor. | |
407 | define o-iterator-doit | |
408 | $(common-objpfx)$(patsubst %,$(libtype$o),c)($(ar-symtab-name)): \ | |
409 | $(common-objpfx)$(patsubst %,$(libtype$o),c)(\ | |
410 | $(patsubst $(objpfx)%.o,%$o,$(objects))) \ | |
411 | $(filter subdir_lib,$(firstword $(subdir) subdir_lib)); \ | |
412 | $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c) | |
413 | endef | |
414 | object-suffixes-left = $(object-suffixes) | |
415 | include $(o-iterator) | |
416 | ||
28f540f4 RM |
417 | |
418 | # This makes all the object files. | |
419 | .PHONY: objects objs | |
51f75302 RM |
420 | objects objs: $(foreach o,$(object-suffixes),$(objects:.o=$o)) \ |
421 | $(addprefix $(objpfx),$(extra-objs)) | |
f0bf9cb9 RM |
422 | |
423 | # Canned sequence for building an extra library archive. | |
424 | define build-extra-lib | |
425 | $(patsubst %,cd %;,$(objdir)) \ | |
426 | $(AR) cru$(verbose) $(@:$(objpfx)%=%) \ | |
427 | $(patsubst $(objpfx)%,%,$^) | |
428 | $(RANLIB) $@ | |
429 | endef | |
28f540f4 | 430 | \f |
0e3426bb RM |
431 | # Shared library building. |
432 | ||
433 | ifeq (yes,$(build-shared)) | |
434 | ||
435 | # Process the shlib-versions file, which tells us what shared library | |
436 | # version numbers to use when we install shared objects on this system. | |
437 | -include $(common-objpfx)soversions.mk | |
438 | $(common-objpfx)soversions.mk: $(..)shlib-versions $(..)Makerules \ | |
439 | $(common-objpfx)config.make | |
440 | sed 's/#.*$$//' $< | while read conf versions; do \ | |
441 | test -n "$$versions" || continue; \ | |
442 | case '$(config-machine)-$(config-vendor)-$(config-os)' in $$conf)\ | |
443 | for v in $$versions; do \ | |
444 | lib="$${v%%=*}"; if eval "test -z \"\$$vers_lib$$lib\""; then \ | |
445 | eval vers_lib$${lib}=yes; \ | |
446 | echo $$lib.so-version=.$${v##$$lib=}; fi; \ | |
447 | done ;; esac; done > $@T | |
448 | mv -f $@T $@ | |
449 | ||
450 | # Get $(version) defined with the release version number. | |
451 | -include $(common-objpfx)version.mk | |
452 | ||
453 | ||
454 | # Pattern rule to build a shared object from an archive of PIC objects. | |
455 | # This must come after the installation rules so Make doesn't try to | |
456 | # build shared libraries in place from the installed *_pic.a files. | |
457 | # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies | |
458 | # on other shared objects. | |
459 | lib%.so: lib%_pic.a; $(build-shlib) | |
460 | ||
461 | ifeq ($(have-no-whole-archive),yes) | |
462 | no-whole-archive = -Wl,--no-whole-archive | |
463 | else | |
464 | no-whole-archive = | |
465 | endif | |
466 | ||
467 | define build-shlib | |
468 | $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS) \ | |
469 | -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \ | |
470 | $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \ | |
471 | -Wl,-rpath-link=$(common-objdir) \ | |
472 | -Wl,--whole-archive $^ $(no-whole-archive) \ | |
473 | $(LDLIBS-$(@F:lib%.so=%).so) | |
474 | endef | |
475 | ||
476 | # Don't try to use -lc when making libc.so itself. | |
477 | # Also omits crti.o and crtn.o, which we do not want | |
478 | # since we define our own `.init' section specially. | |
479 | LDFLAGS-c.so = -nostdlib -nostartfiles | |
480 | # Give libc.so an entry point and make it directly runnable itself. | |
481 | LDFLAGS-c.so += -e __libc_print_version | |
482 | # Use our own special initializer and finalizer files for libc.so. | |
483 | elfobjdir := $(firstword $(objdir) $(..)elf) | |
484 | $(common-objpfx)libc.so: $(elfobjdir)/soinit.so \ | |
485 | $(common-objpfx)libc_pic.a \ | |
486 | $(elfobjdir)/sofini.so | |
487 | $(build-shlib) | |
488 | ||
489 | ifdef libc.so-version | |
490 | $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so | |
491 | rm -f $@ | |
492 | ln -s $(<F) $@ || ln $< $@ | |
493 | endif | |
494 | endif | |
495 | \f | |
28f540f4 RM |
496 | # Installation. |
497 | ||
498 | # $(install-lib) are installed from the object directory into $(libdir); | |
499 | # files in $(install-lib) matching `lib%.a' are ranlib'd after installation | |
500 | # unless they also appear in $(non-lib.a). $(install-data) are installed | |
501 | # as they are into $(datadir). $(headers) are installed as they are in | |
502 | # $(includedir). $(install-bin) and $(install-sbin) are installed from the | |
503 | # object directory into $(bindir) and $(sbindir), respectively. | |
504 | # $(install-others) are absolute path names of files to install; rules to | |
505 | # install them are defined elsewhere. | |
506 | ||
507 | # The simple library name to install libc.a under. | |
508 | # This could be defined by a sysdep Makefile. | |
509 | ifndef libc-name | |
510 | libc-name := c | |
511 | endif | |
512 | ||
513 | define do-install | |
514 | $(make-target-directory) | |
515 | $(INSTALL_DATA) $< $@ | |
516 | endef | |
517 | ||
a182affd RM |
518 | # Make the target directory if it doesn't exist, using the `mkinstalldirs' |
519 | # script that does `mkdir -p' even if `mkdir' doesn't support that flag. | |
28f540f4 | 520 | define make-target-directory |
a182affd RM |
521 | $(addprefix $(..)mkinstalldirs ,\ |
522 | $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%))) | |
28f540f4 RM |
523 | endef |
524 | ||
525 | # Any directory (parent or subdir) that has any object files to build | |
526 | # should install libc.a; this way "make install" in a subdir is guaranteed | |
527 | # to install everything it changes. | |
528 | ifdef objects | |
51f75302 RM |
529 | installed-libcs := $(foreach o,$(object-suffixes),\ |
530 | $(libdir)/$(patsubst %,$(libtype$o),\ | |
531 | $(libprefix)$(libc-name))) | |
75914335 | 532 | installed-libcs := $(filter-out %_pic.a,$(installed-libcs)) |
51f75302 | 533 | install: $(installed-libcs) |
9f2233e8 | 534 | $(installed-libcs): $(libdir)/lib$(libprefix)%: lib |
28f540f4 | 535 | $(make-target-directory) |
c316b486 | 536 | $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@ |
9f2233e8 RM |
537 | # Running ranlib after installing makes the __.SYMDEF time stamp up to |
538 | # date, which avoids messages from some linkers. | |
28f540f4 RM |
539 | $(RANLIB) $@ |
540 | endif | |
541 | ||
273d56ce RM |
542 | define do-install-program |
543 | $(make-target-directory) | |
544 | $(INSTALL_PROGRAM) $< $@.new | |
545 | mv -f $@.new $@ | |
546 | endef | |
547 | ||
5bf62f2d | 548 | install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so)) |
0700dfa1 | 549 | install-lib := $(filter-out %.so %_pic.a,$(install-lib)) |
51f75302 | 550 | ifeq (yes,$(build-shared)) |
5bf62f2d | 551 | |
0e3426bb | 552 | install-lib-nosubdir: $(install-lib.so:%=$(libdir)/%) |
0e3426bb RM |
553 | |
554 | # Find which .so's have versions. | |
05d4c982 RM |
555 | versioned := $(strip $(foreach so,$(install-lib.so),\ |
556 | $(patsubst %,$(so),$($(so)-version)))) | |
0e3426bb RM |
557 | |
558 | # Install all the unversioned shared libraries. | |
559 | $(addprefix $(libdir)/,$(filter-out $(versioned),$(install-lib.so))): \ | |
f0523145 | 560 | $(libdir)/%.so: $(objpfx)%.so; $(do-install-program) |
0e3426bb RM |
561 | |
562 | make-link = cd $(@D); rm -f $(@F); $(LN_S) $(<F) $(@F) | |
563 | ||
564 | ifdef libc.so-version | |
565 | # For a library specified to be version N, install three files: | |
566 | # libc.so -> libc.so.N (e.g. libc.so.6) | |
567 | # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so) | |
568 | ||
0e3426bb RM |
569 | $(slibdir)/libc.so$(libc.so-version): $(slibdir)/libc-$(version).so |
570 | $(make-link) | |
571 | $(slibdir)/libc-$(version).so: $(common-objpfx)libc.so; $(do-install-program) | |
7c713e28 RM |
572 | |
573 | # What we install as libc.so for programs to link against is in fact an | |
574 | # archive. It contains the various $(static-only-routines) objects, and | |
575 | # the special object libc-syms.so that contains just the dynamic symbol | |
576 | # table of the shared libc object. | |
577 | install: $(libdir)/libc.so | |
578 | $(libdir)/libc.so: $(common-objpfx)libc-syms.so subdir_install | |
579 | $(AR) crvs $@ $< `cat $(addprefix $(common-objpfx)sor-,$(subdirs))` | |
580 | ||
581 | # Extract from the shared object file just the dynamic symbol table | |
582 | # needed to link against the shared library. | |
583 | $(common-objpfx)libc-syms.so: $(common-objpfx)libc.so | |
584 | AWK='$(AWK)' OBJCOPY='$(OBJCOPY)' OBJDUMP='$(OBJDUMP)' \ | |
585 | ./extract-dynsym $< $@ | |
586 | ifndef subdir | |
587 | generated += libc-syms.so | |
588 | endif | |
589 | ||
0e3426bb | 590 | else |
7c713e28 | 591 | install: $(slibdir)/libc.so |
0e3426bb RM |
592 | $(slibdir)/libc.so: $(common-objpfx)libc.so; $(do-install-program) |
593 | endif | |
594 | ||
595 | ||
596 | ifneq (,$(versioned)) | |
597 | # Produce three sets of rules as above for all the smaller versioned libraries. | |
598 | ||
599 | define o-iterator-doit | |
f0523145 | 600 | $(libdir)/$o: $(libdir)/$o$($o-version); $$(make-link) |
0e3426bb RM |
601 | endef |
602 | object-suffixes-left := $(versioned) | |
603 | include $(..)o-iterator.mk | |
604 | ||
605 | define o-iterator-doit | |
f0523145 | 606 | $(libdir)/$o$($o-version): $(libdir)/$(o:.so=)-$(version).so; $$(make-link) |
0e3426bb RM |
607 | endef |
608 | object-suffixes-left := $(versioned) | |
609 | include $(..)o-iterator.mk | |
610 | ||
611 | define o-iterator-doit | |
f0523145 | 612 | $(libdir)/$(o:.so=)-$(version).so: $(objpfx)$o; $$(do-install-program) |
0e3426bb RM |
613 | endef |
614 | object-suffixes-left := $(versioned) | |
615 | include $(..)o-iterator.mk | |
616 | endif | |
102800e0 RM |
617 | |
618 | define do-install-so | |
619 | $(do-install-program) | |
620 | $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\ | |
621 | $(filter-out %.so,$@)) | |
622 | endef | |
094bacdb | 623 | |
102800e0 RM |
624 | so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version))) |
625 | $(foreach v,$(so-versions),\ | |
273d56ce | 626 | $(libdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so |
102800e0 RM |
627 | $(do-install-so) |
628 | $(foreach v,$(so-versions),\ | |
273d56ce | 629 | $(libdir)/$(libprefix)%$v): $(common-objpfx)%.so |
102800e0 | 630 | $(do-install-so) |
51f75302 RM |
631 | endif |
632 | ||
28f540f4 RM |
633 | ifdef install-bin |
634 | $(addprefix $(bindir)/,$(install-bin)): $(bindir)/%: $(objpfx)% | |
273d56ce | 635 | $(do-install-program) |
28f540f4 RM |
636 | endif |
637 | ifdef install-sbin | |
638 | $(addprefix $(sbindir)/,$(install-sbin)): $(sbindir)/%: $(objpfx)% | |
273d56ce | 639 | $(do-install-program) |
28f540f4 RM |
640 | endif |
641 | ifdef install-lib | |
642 | install-lib.a := $(filter lib%.a,$(install-lib)) | |
643 | install-lib-non.a := $(filter-out lib%.a,$(install-lib)) | |
644 | ifdef install-lib-non.a | |
645 | $(addprefix $(libdir)/$(libprefix),$(install-lib-non.a)): \ | |
2e516341 | 646 | $(libdir)/$(libprefix)%: $(common-objpfx)% |
28f540f4 RM |
647 | $(do-install) |
648 | endif | |
649 | ifdef install-lib.a | |
650 | $(install-lib.a:lib%.a=$(libdir)/lib$(libprefix)%.a): \ | |
2e516341 | 651 | $(libdir)/lib$(libprefix)%.a: $(common-objpfx)lib%.a |
28f540f4 RM |
652 | $(do-install) |
653 | $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F))) | |
654 | endif | |
655 | endif | |
656 | ifdef install-data | |
657 | $(addprefix $(datadir)/,$(install-data)): $(datadir)/%: %;$(do-install) | |
658 | endif | |
659 | headers := $(strip $(headers)) | |
660 | ifdef headers | |
661 | $(addprefix $(includedir)/,$(headers)): \ | |
662 | $(includedir)/%: %;$(do-install) | |
663 | endif # headers | |
664 | ||
665 | .PHONY: install-bin-nosubdir install-sbin-nosubdir install-lib-nosubdir \ | |
666 | install-data-nosubdir install-headers-nosubdir | |
667 | install-bin-nosubdir: $(addprefix $(bindir)/,$(install-bin)) | |
668 | install-sbin-nosubdir: $(addprefix $(sbindir)/,$(install-sbin)) | |
669 | install-lib-nosubdir: $(addprefix $(libdir)/,\ | |
670 | $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \ | |
671 | $(addprefix $(libprefix),$(install-lib-non.a))) | |
672 | install-data-nosubdir: $(addprefix $(datadir)/,$(install-data)) | |
673 | install-headers-nosubdir: $(addprefix $(includedir)/,$(headers)) | |
674 | install-others-nosubdir: $(install-others) | |
675 | ||
676 | # We need all the `-nosubdir' targets so that `install' in the parent | |
677 | # doesn't depend on several things which each iterate over the subdirs. | |
678 | # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a | |
679 | # subroutine. Then in the parent `install-FOO' also causes subdir makes. | |
680 | install-%:: install-%-nosubdir ; | |
681 | ||
682 | .PHONY: install install-no-libc.a-nosubdir | |
683 | install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\ | |
684 | install-bin-nosubdir install-lib-nosubdir \ | |
685 | install-others-nosubdir install-sbin-nosubdir | |
686 | install: install-no-libc.a-nosubdir | |
687 | \f | |
688 | # Command to compile $< in $(objdir) using the native libraries. | |
689 | define native-compile | |
690 | cwd=`pwd`; cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) \ | |
691 | $(addprefix $$cwd/,$^) -o $(@F) | |
692 | endef | |
693 | ||
694 | # Command to compile $< in $(common-objdir) using the native libraries. | |
695 | define common-objdir-compile | |
696 | cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=%) -o $(@F) | |
697 | endef | |
698 | ||
699 | # We always want to use configuration definitions. | |
299a95b9 | 700 | ifdef objdir |
ffcf9634 RM |
701 | # This is always used in $(common-objdir), so we use no directory name. |
702 | BUILD_CFLAGS = -include config.h | |
299a95b9 RM |
703 | else |
704 | BUILD_CFLAGS = -include $(..)config.h | |
705 | endif | |
28f540f4 RM |
706 | |
707 | # Support the GNU standard name for this target. | |
708 | .PHONY: check | |
709 | check: tests | |
710 | \f | |
711 | .PHONY: TAGS | |
712 | TAGS: distinfo $(..)MakeTAGS | |
dbdb6189 | 713 | $(MAKE) $(addprefix -f ,$^) $@ |
28f540f4 | 714 | |
ce563359 RM |
715 | $(..)po/%.pot: distinfo $(..)MakeTAGS FORCE |
716 | $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@ | |
717 | FORCE: | |
a182affd RM |
718 | |
719 | ||
28f540f4 RM |
720 | .PHONY: echo-headers |
721 | echo-headers: | |
722 | @echo $(headers) | |
723 | ||
724 | \f | |
725 | # Common cleaning targets. | |
726 | ||
727 | .PHONY: common-mostlyclean common-clean mostlyclean clean | |
728 | clean: common-clean | |
729 | mostlyclean: common-mostlyclean | |
730 | ||
731 | # Remove the object files. | |
732 | common-mostlyclean: | |
733 | -rm -f $(addprefix $(objpfx),$(tests) $(others) \ | |
734 | $(addsuffix .o,$(tests) $(others)) \ | |
735 | $(addsuffix .out,$(tests))) | |
4788ab46 RM |
736 | -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib)) |
737 | -rm -f core $(objpfx)stub-$(subdir) | |
51f75302 RM |
738 | $(rmobjs) |
739 | define rmobjs | |
740 | $(foreach o,$(object-suffixes), | |
741 | -rm -f $(addprefix $(objpfx),stamp$o-$(subdir)) $(objects:.o=$o)) | |
742 | endef | |
28f540f4 RM |
743 | |
744 | # Also remove the dependencies and generated source files. | |
745 | common-clean: common-mostlyclean | |
deab9dea | 746 | -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles) |
28f540f4 RM |
747 | \f |
748 | # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION' | |
749 | # for each function which is a stub. We grovel over all the .d files | |
750 | # looking for references to source files in sysdeps/stub. Then we grovel | |
751 | # over each referenced source file to see what stub function it defines. | |
752 | ||
753 | .PHONY: stubs # The parent Makefile calls this target. | |
754 | stubs: $(common-objpfx)stub-$(subdir) | |
755 | s = $(sysdep_dir)/stub | |
756 | $(common-objpfx)stub-$(subdir): $(+depfiles) | |
757 | # Use /dev/null since `...` might expand to empty. | |
758 | s=`cd $s; /bin/pwd`; \ | |
759 | $(patsubst %,cd %;,$(objdir)) \ | |
760 | sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \ | |
761 | `sed -n 's@^.*$s/\([a-z0-9_-]*\.c\).*$$@'"$$s"/'\1@p' \ | |
762 | $(patsubst $(objpfx)%,%,$^) /dev/null` \ | |
f0523145 | 763 | /dev/null > $(@F)T |
28f540f4 RM |
764 | mv -f $@T $@ |
765 | \f | |
766 | # Make the distribution tar file. | |
767 | ||
768 | .PHONY: dist | |
094bacdb | 769 | dist: distinfo $(..)Make-dist |
28f540f4 RM |
770 | $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args) |
771 | ||
10ceac89 RM |
772 | # Avoid depending on source files found in sysdeps dirs, |
773 | # because the references affect implicit rule selection. | |
774 | dist: $(filter-out %.c %.S %.s,$(distribute)) | |
28f540f4 RM |
775 | |
776 | # We used to simply export all these variables, but that frequently made the | |
777 | # environment get too large. Instead, we write all the information into | |
778 | # a generated makefile fragment `distinfo', and then include it with -f in | |
779 | # the sub-make that makes the distribution (above). | |
780 | distinfo: Makefile $(..)Makerules | |
781 | $(distinfo-vars) | |
782 | mv -f $@.new $@ | |
783 | ||
784 | define distinfo-vars | |
785 | rm -f $@.new | |
19c3f208 | 786 | $(foreach var,subdir subdir-dirs sources elided-routines headers distribute \ |
28f540f4 RM |
787 | dont_distribute generated others tests, |
788 | echo >> $@.new '$(var) := $($(var))') | |
789 | echo >> $@.new 'sources := $$(sources) $$(addsuffix .c,$$(elided-routines))' | |
790 | endef | |
791 | \f | |
792 | ifneq (,$(strip $(gpl2lgpl))) | |
793 | ifneq (,$(wildcard $(..)gpl2lgpl.sed)) | |
794 | # Snarf from the master source and frob the copying notice. | |
795 | $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/% | |
796 | sed -f $^ > $@-tmp | |
797 | # So I don't edit them by mistake. | |
798 | chmod a-w $@-tmp | |
799 | mv -f $@-tmp $@ | |
a2fe9c76 | 800 | test ! -d CVS || cvs commit -m'Updated from $^' $@ |
28f540f4 RM |
801 | endif |
802 | endif |