]> sourceware.org Git - glibc.git/blob - Makerules
* csu/Makefile ($(objpfx)g$(start-installed-name)): Turn this into a
[glibc.git] / Makerules
1 # Copyright (C) 1991-1999, 2000,2001 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 # 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 REQUIRED_MAKE_VERSION = 3.74
29 REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
30
31 ifneq ($(REQUIRED_MAKE_VERSION), \
32 $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
33 Wrong GNU Make version. See above for the version needed.
34 endif
35
36
37 ifdef subdir
38 .. := ../
39 endif # subdir
40
41 # If `sources' was defined by the parent makefile, undefine it so
42 # we will later get it from wildcard search in this directory.
43 ifneq "$(findstring env,$(origin sources))" ""
44 sources :=
45 endif
46
47 oPATH := $(PATH)
48 PATH := this definition should take precedence over $(oPATH)
49 ifeq ($(PATH),$(oPATH))
50 You must not use the -e flag when building the GNU C library.
51 else
52 PATH := $(oPATH)
53 endif
54 \f
55 ifndef +included-Makeconfig
56 include $(..)Makeconfig
57 endif
58
59 # `configure' writes a definition of `config-sysdirs' in `config.make'.
60 sysdirs = $(strip $(full_config_sysdirs))
61
62 +sysdir_pfx = $(common-objpfx)
63
64 export sysdirs := $(sysdirs)
65
66 +sysdep_dirs := $(full_config_sysdirs)
67 ifdef objdir
68 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
69 endif
70
71 # Add -I switches to get the right sysdep directories.
72 # `+includes' in Makeconfig references $(+sysdep-includes).
73 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
74
75 # This variable is used in ``include $(o-iterator)'' after defining
76 # $(o-iterator-doit) to produce some desired rule using $o for the object
77 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
78 # is produced for each object suffix in use.
79 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
80 \f
81 # Include any system-specific makefiles.
82
83 # This is here so things in sysdep Makefiles can easily depend on foo.h as
84 # appropriate and not worry about where foo.h comes from, which may be
85 # system dependent and not known by that Makefile.
86 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
87 $(+sysdep_dirs) $(..)))
88
89 # The same is true for RPC source files.
90 vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
91 $(+sysdep_dirs) $(..)))
92
93 # Some sysdep makefiles use this to distinguish being included here from
94 # being included individually by a subdir makefile (hurd/Makefile needs this).
95 in-Makerules := yes
96
97 sysdep-makefiles := $(wildcard $(full_config_sysdirs:=/Makefile))
98 ifneq (,$(sysdep-makefiles))
99 include $(sysdep-makefiles)
100 endif
101
102
103 # Reorder before-compile so that mach things come first, and hurd things
104 # second, before all else. The mach and hurd subdirectories have many
105 # generated header files which the much of rest of the library depends on,
106 # so it is best to build them first (and mach before hurd, at that).
107 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
108 $(before-compile)) \
109 $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
110 $(before-compile))
111
112 # Even before that, we need abi-versions.h which is generated right here.
113 ifeq ($(versioning),yes)
114 ifndef avoid-generated
115 before-compile := $(common-objpfx)abi-versions.h $(before-compile)
116 $(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
117 $(common-objpfx)Versions.all
118 LC_ALL=C $(AWK) -v oldest_abi=$(oldest-abi) -f $^ > $@T
119 mv -f $@T $@
120 endif # avoid-generated
121 endif # $(versioning) = yes
122
123
124 # Remove existing files from `before-compile'. Things are added there when
125 # they must exist for dependency generation to work right, but once they
126 # exist there is no further need for every single file to depend on them,
127 # and those gratuitous dependencies result in many gratuitous
128 # recompilations.
129 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
130
131 # Don't let any before-compile file be an intermediate and get removed.
132 ifdef before-compile
133 $(before-compile):
134 endif
135 \f
136 # Generate an ordered list of implicit rules which find the source files in
137 # each sysdep directory. The old method was to use vpath to search all the
138 # sysdep directories. However, that had the problem that a .S file in a
139 # later directory would be chosen over a .c file in an earlier directory,
140 # which does not preserve the desired sysdeps ordering behavior.
141
142 # When making the list of .d files to include, we can't know which ones
143 # have source in .s files, and thus do not in fact need a .d file.
144 # So we must define rules to make .d files for .s files.
145 define make-dummy-dep
146 $(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
147 endef
148 $(common-objpfx)dummy.d:
149 echo '# .s files cannot contain includes, so they need no deps.' > $@
150
151 # It matters that this set of rules, for compiling from sources in
152 # the current directory (the $srcdir/$subdir) come before the
153 # generated sysdep rules in included from sysd-rules below. When
154 # compiling in the source tree, generated sources go into the current
155 # directory, and those should be chosen before any sources in sysdeps.
156 define o-iterator-doit
157 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
158 endef
159 object-suffixes-left := $(all-object-suffixes)
160 include $(o-iterator)
161 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
162
163 define o-iterator-doit
164 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
165 endef
166 object-suffixes-left := $(all-object-suffixes)
167 include $(o-iterator)
168 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
169
170 define o-iterator-doit
171 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
172 endef
173 object-suffixes-left := $(all-object-suffixes)
174 include $(o-iterator)
175 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
176
177 # Omit the objpfx rules when building in the source tree, because
178 # objpfx is empty and so these rules just override the ones above.
179 ifdef objpfx
180 # Define first rules to find the source files in $(objpfx).
181 # Generated source files will end up there.
182 define o-iterator-doit
183 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
184 endef
185 object-suffixes-left := $(all-object-suffixes)
186 include $(o-iterator)
187 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
188
189 define o-iterator-doit
190 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
191 endef
192 object-suffixes-left := $(all-object-suffixes)
193 include $(o-iterator)
194 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
195
196 define o-iterator-doit
197 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
198 endef
199 object-suffixes-left := $(all-object-suffixes)
200 include $(o-iterator)
201 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
202 endif
203
204 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
205 # patterns matching sysdep directories whose assembly source files should
206 # be suppressed.
207 ifdef inhibit-sysdep-asm
208 define open-check-inhibit-asm
209 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
210 endef
211 close-check-inhibit-asm = ;; esac ;
212 endif
213
214 -include $(+sysdir_pfx)sysd-rules
215 ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
216 # The value of $(+sysdep_dirs) the sysd-rules was computed for
217 # differs from the one we are using now. So force a rebuild of sysd-rules.
218 sysd-rules-force = FORCE
219 FORCE:
220 endif
221 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
222 $(wildcard $(foreach dir,$(sysdirs),\
223 $(dir)/Makefile))\
224 $(sysd-rules-force)
225 -@rm -f $@T
226 (echo 'sysd-rules-sysdirs := $(config-sysdirs)'; \
227 for dir in $(config-sysdirs:%='$$(..)%'); do \
228 for o in $(all-object-suffixes); do \
229 $(open-check-inhibit-asm) \
230 echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
231 \$$(compile-command.S)"; \
232 echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
233 \$$(compile-command.s)"; \
234 $(close-check-inhibit-asm) \
235 echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
236 \$$(compile-command.c)"; \
237 done; \
238 $(open-check-inhibit-asm) \
239 echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
240 \$$(make-dummy-dep)"; \
241 echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
242 \$$(+make-deps)"; \
243 $(close-check-inhibit-asm) \
244 echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
245 \$$(+make-deps)"; \
246 done; \
247 echo 'sysd-rules-done = t') > $@T
248 mv -f $@T $@
249
250 ifndef sysd-rules-done
251 # Don't do deps until this exists, because it provides rules to make the deps.
252 no_deps=t
253 endif
254
255 # Generate version maps, but wait until sysdep-subdirs is known
256 ifeq ($(sysd-sorted-done),t)
257 ifeq ($(versioning),yes)
258 -include $(common-objpfx)sysd-versions
259 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
260 common-generated += $(version-maps)
261 postclean-generated += sysd-versions Versions.all abi-versions.h
262
263 ifndef avoid-generated
264 ifneq ($(sysd-versions-subdirs),$(all-subdirs) $(config-sysdirs))
265 sysd-versions-force = FORCE
266 FORCE:
267 endif
268 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
269 $(common-objpfx)soversions.i \
270 $(..)Versions.def \
271 $(wildcard $(add-ons:%=$(..)%/Versions.def))
272 { while read lib version setname; do \
273 test -z "$$setname" || echo "$$lib : $$setname"; \
274 done < $(word 2,$^); \
275 cat $(filter-out $< $(word 2,$^),$^) \
276 | $(preprocess-versions); \
277 } | LC_ALL=C $(AWK) -f $< > $@T
278 mv -f $@T $@
279 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
280 $(..)scripts/versions.awk \
281 $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
282 $(wildcard $(sysdirs:%=%/Versions)) \
283 $(sysd-versions-force)
284 ( echo 'sysd-versions-subdirs = $(all-subdirs) $(config-sysdirs)' ; \
285 cat $(filter-out $< $(word 2,$^) $(sysd-versions-force),$^) \
286 | $(preprocess-versions) \
287 | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
288 -v move_if_change='$(move-if-change)' \
289 -f $(word 2,$^); \
290 ) > $@T
291 mv -f $@T $@
292 endif # avoid-generated
293 endif # $(versioning) = yes
294 endif # sysd-sorted-done
295
296
297 ifndef compile-command.S
298 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
299 endif
300 ifndef compile-command.s
301 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
302 endif
303 ifndef compile-command.c
304 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
305 endif
306
307 # GCC can grok options after the file name, and it looks nicer that way.
308 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
309 compile.S = \
310 $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
311 COMPILE.S = \
312 $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
313 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
314
315 # If we want to generate MD% checksums for the sources do this now.
316 ifeq ($(md5),yes)
317 generate-md5 = ; rm -f $(@:.d=.md5); \
318 $(CC) -E $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
319 sed '/^\#/d;/^[[:space:]]*$$/d' | md5sum > $(@:.d=.md5)
320 else
321 generate-md5 =
322 endif
323
324 # We need this for the output to go in the right place. It will default to
325 # empty if make was configured to work with a cc that can't grok -c and -o
326 # together. You can't compile the C library with such a compiler.
327 OUTPUT_OPTION = -o $@
328
329 S-CPPFLAGS = $(asm-CPPFLAGS)
330 define +make-deps
331 $(make-target-directory)
332 -@rm -f $@
333 $(+mkdep) $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
334 sed \
335 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
336 $(sed-remove-objpfx) > $(@:.d=.T)
337 mv -f $(@:.d=.T) $@ $(generate-md5)
338 endef
339 ifneq (,$(objpfx))
340 # Continuation lines here are dangerous because they introduce spaces!
341 define sed-remove-objpfx
342 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
343 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
344 endef
345 endif
346 \f
347 # Modify the list of routines we build for different targets
348
349 ifeq (yes,$(build-shared))
350 ifndef libc.so-version
351 # Undefine this because it can't work when we libc.so is unversioned.
352 static-only-routines =
353 endif
354 endif
355
356 # Bounded pointer thunks are only built for *.ob
357 elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
358
359 elide-routines.oS += $(filter-out $(static-only-routines),\
360 $(routines) $(aux) $(sysdep_routines)) \
361 $(elide-bp-thunks)
362 elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
363
364 # If we have versioned code we don't need the old versions in any of the
365 # static libraries.
366 elide-routines.o += $(shared-only-routines) $(elide-bp-thunks)
367 elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
368 elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
369 elide-routines.ob += $(shared-only-routines)
370 \f
371 # Shared library building.
372
373 ifeq (yes,$(build-shared))
374
375 # Reference map file only when versioning is selected and a map file name
376 # is given.
377 ifeq ($(versioning),yes)
378 map-file = $(firstword $($(@F:.so=-map)) \
379 $(addprefix $(common-objpfx), \
380 $(filter $(@F:.so=.map),$(version-maps))))
381 load-map-file = $(map-file:%=-Wl,--version-script=%)
382 endif
383
384 # Pattern rule to build a shared object from an archive of PIC objects.
385 # This must come after the installation rules so Make doesn't try to
386 # build shared libraries in place from the installed *_pic.a files.
387 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
388 # on other shared objects.
389 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
390 $(build-shlib)
391
392 define build-shlib-helper
393 $(LINK.o) -shared -Wl,-O1 $(sysdep-LDFLAGS) $(config-LDFLAGS) \
394 $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
395 $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
396 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
397 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
398 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
399 endef
400
401 ifeq (yes,$(elf))
402 # binutils only position loadable notes into the first page for binaries,
403 # not for shared objects
404 define build-shlib
405 $(build-shlib-helper) \
406 -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
407 $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
408 sed -e '/^=========/,/^=========/!d;/^=========/d' \
409 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
410 > $@.lds
411 rm -f $@.new
412 $(build-shlib-helper) -o $@ -T $@.lds \
413 -Wl,--whole-archive $(csu-objpfx)abi-note.o \
414 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
415 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
416 rm -f $@.lds
417 endef
418 else
419 define build-shlib
420 $(build-shlib-helper) \
421 -o $@ -Wl,--whole-archive \
422 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
423 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
424 endef
425 endif
426
427 define build-module-helper
428 $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) \
429 -B$(csu-objpfx) $(load-map-file) \
430 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
431 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
432 endef
433
434 # This macro is similar to build-shlib but it does not define a soname
435 # and it does not depend on the destination name to start with `lib'.
436 ifeq (yes,$(elf))
437 # binutils only position loadable notes into the first page for binaries,
438 # not for shared objects
439 define build-module
440 $(build-module-helper) \
441 -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
442 $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
443 sed -e '/^=========/,/^=========/!d;/^=========/d' \
444 -e 's/^.*\.hash[ ]*:.*$$/ .note.ABI-tag : { *(.note.ABI-tag) } &/' \
445 > $@.lds
446 rm -f $@.new
447 $(build-module-helper) -o $@ -T $@.lds \
448 -Wl,--whole-archive $(csu-objpfx)abi-note.o \
449 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
450 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
451 rm -f $@.lds
452 endef
453 else
454 define build-module
455 $(build-module-helper) \
456 -o $@ -Wl,--whole-archive \
457 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
458 $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
459 endef
460 endif
461
462 # Don't try to use -lc when making libc.so itself.
463 # Also omits crti.o and crtn.o, which we do not want
464 # since we define our own `.init' section specially.
465 LDFLAGS-c.so = -nostdlib -nostartfiles
466 # But we still want to link libc.so against $(gnulib).
467 LDLIBS-c.so += $(gnulib)
468 # Give libc.so an entry point and make it directly runnable itself.
469 LDFLAGS-c.so += -e __libc_main
470 # Force the backward compatibility EH functions to be linked.
471 LDFLAGS-c.so += -u __register_frame
472 # Pre-link the objects of libc_pic.a so that we can locally resolve
473 # COMMON symbols before we link against ld.so. This is because ld.so
474 # contains some of libc_pic.a already, which will prevent the COMMONs
475 # from being allocated in libc.so, which introduces evil dependencies
476 # between libc.so and ld.so, which can make it impossible to upgrade.
477 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
478 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
479 $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
480 # Use our own special initializer and finalizer files for libc.so.
481 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
482 $(common-objpfx)libc_pic.os \
483 $(elfobjdir)/sofini.os \
484 $(elfobjdir)/interp.os $(elfobjdir)/ld.so
485 $(build-shlib)
486 ifeq ($(versioning),yes)
487 $(common-objpfx)libc.so: $(common-objpfx)libc.map
488 endif
489 common-generated += libc.so libc_pic.os
490 ifdef libc.so-version
491 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
492 $(make-link)
493 common-generated += libc.so$(libc.so-version)
494 endif
495 endif
496 \f
497 # Figure out the source filenames in this directory.
498
499 override sources := $(addsuffix .c,\
500 $(filter-out $(elided-routines),\
501 $(routines) $(aux) \
502 $(sysdep_routines)))
503 sysdep_routines := $(sysdep_routines)
504
505 headers := $(headers) $(sysdep_headers)
506
507 # This is the list of all object files, gotten by
508 # replacing every ".c" in `sources' with a ".o".
509 # We also add bounded-pointer thunks, which are later
510 # elided for all suffixes except for `.ob'.
511 override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
512 $(patsubst %,$(bppfx)%.o,\
513 $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
514
515
516 # The makefile may define $(extra-libs) with `libfoo libbar'
517 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
518 ifdef extra-libs
519 # extra-lib.mk is included once for each extra lib to define rules
520 # to build it, and to add its objects to the various variables.
521 # During its evaluation, $(lib) is set to the name of the library.
522 extra-libs-left := $(extra-libs)
523 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
524 endif
525 \f
526 +depfiles := $(sources:.c=.d) \
527 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
528 $(addsuffix .d,$(tests) $(test-srcs))
529 ifeq ($(build-programs),yes)
530 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
531 endif
532 +depfiles := $(addprefix $(objpfx),\
533 $(filter-out $(addsuffix .d,$(omit-deps)),\
534 $(+depfiles)))
535
536 ifdef +depfiles
537 ifneq ($(no_deps),t)
538 -include $(+depfiles)
539 endif
540 endif
541 \f\f
542 # Maximize efficiency by minimizing the number of rules.
543 .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
544 # Don't define any builtin rules.
545 MAKEFLAGS := $(MAKEFLAGS)r
546
547 # Generic rule for making directories.
548 %/:
549 # mkdir isn't smart enough to strip a trailing /.
550 mkdir $(@:%/=%)
551 \f
552 # Make sure that object files are not removed
553 # when they are intermediates between sources and library members.
554 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
555
556 # Make sure that the parent library archive is never removed.
557 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
558 \f
559 # Use the verbose option of ar and tar when not running silently.
560 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
561 verbose := v
562 else # -s
563 verbose :=
564 endif # not -s
565
566 ARFLAGS := r$(verbose)
567 CREATE_ARFLAGS := cru$(verbose)
568 \f
569 # This makes all the object files in the parent library archive.
570
571 .PHONY: lib lib-noranlib
572 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
573 lib-noranlib: libobjs
574
575 # For object-suffix $o, the list of objects with that suffix.
576 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
577 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
578 $(elide-routines$o)),\
579 $(objects))) \
580 $(addprefix $(objpfx),$(o-objects$o))
581
582 others: $(addprefix $(objpfx),$(install-lib))
583
584 ifndef objects
585
586 # Create the stamp$o files to keep the parent makefile happy.
587 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
588 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
589 $(make-target-directory)
590 rm -f $@; > $@
591 else
592
593 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
594 # timestamp file; these rules (one explicit rule is generated for each
595 # object suffix) write a list of objects to update in the stamp file.
596 # The parent will then actually add them all to the archive in the
597 # archive rule, below.
598 define o-iterator-doit
599 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
600 endef
601 define do-stamp
602 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
603 mv -f $@T $@
604 endef
605 object-suffixes-left := $(object-suffixes-for-libc)
606 include $(o-iterator)
607
608 endif
609
610 # Now define explicit rules to build the library archives; these depend
611 # on the stamp files built above.
612 define o-iterator-doit
613 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
614 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
615 endef
616 define do-makelib
617 cd $(common-objdir) && \
618 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
619 $(RANLIB) $@
620 endef
621 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
622 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
623 ifndef subdir
624 $(subdirs-stamps): subdir_lib;
625 endif
626 object-suffixes-left = $(object-suffixes-for-libc)
627 include $(o-iterator)
628
629
630 # This makes all the object files.
631 .PHONY: objects objs libobjs extra-objs
632 objects objs: libobjs extra-objs
633 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
634 extra-objs: $(addprefix $(objpfx),$(extra-objs))
635
636 # Canned sequence for building an extra library archive.
637 define build-extra-lib
638 $(patsubst %/,cd % &&,$(objpfx)) \
639 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
640 $(patsubst $(objpfx)%,%,$^)
641 $(RANLIB) $@
642 endef
643 \f
644 # Installation.
645
646 .PHONY: force-install
647 force-install:
648
649 # $(install-lib) are installed from the object directory into $(libdir);
650 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
651 # unless they also appear in $(non-lib.a). $(install-data) are installed
652 # as they are into $(datadir). $(headers) are installed as they are in
653 # $(includedir). $(install-bin) and $(install-sbin) are installed from the
654 # object directory into $(bindir) and $(sbindir), respectively.
655 # $(install-others) are absolute path names of files to install; rules to
656 # install them are defined elsewhere.
657
658 # The simple library name to install libc.a under.
659 # This could be defined by a sysdep Makefile.
660 ifndef libc-name
661 libc-name := c
662 endif
663
664 define do-install
665 $(make-target-directory)
666 $(INSTALL_DATA) $< $@
667 endef
668
669 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
670 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
671 define make-target-directory
672 $(addprefix $(..)./scripts/mkinstalldirs ,\
673 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
674 endef
675
676 # Any directory (parent or subdir) should install libc.a; this way
677 # "make install" in a subdir is guaranteed to install everything it changes.
678 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
679 $(inst_libdir)/$(patsubst %,$(libtype$o),\
680 $(libprefix)$(libc-name)))
681 install: $(installed-libcs)
682 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
683 $(make-target-directory)
684 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
685 # Running ranlib after installing makes the __.SYMDEF time stamp up to
686 # date, which avoids messages from some linkers.
687 $(RANLIB) $@
688
689 define do-install-program
690 $(make-target-directory)
691 $(INSTALL_PROGRAM) $< $@.new
692 mv -f $@.new $@
693 endef
694
695 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
696 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
697
698 ifeq (yes,$(build-shared))
699 # Find which .so's have versions.
700 versioned := $(strip $(foreach so,$(install-lib.so),\
701 $(patsubst %,$(so),$($(so)-version))))
702
703 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
704 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
705
706 install-lib-nosubdir: $(install-lib.so-versioned:%=$(inst_libdir)/%) \
707 $(install-lib.so-unversioned:%=$(inst_slibdir)/%)
708
709 # Install all the unversioned shared libraries.
710 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
711 $(objpfx)%.so $(+force)
712 $(do-install-program)
713
714 ifneq ($(findstring -s,$(LN_S)),)
715 define make-link
716 rm -f $@.new
717 $(SHELL) $(..)scripts/rellns-sh $< $@.new
718 mv -f $@.new $@
719 endef
720 else
721 # If we have no symbolic links don't bother with rellns-sh.
722 define make-link
723 rm -f $@.new
724 $(LN_S) $< $@.new
725 mv -f $@.new $@
726 endef
727 endif
728
729 ifeq (yes,$(build-shared))
730 ifeq (no,$(cross-compiling))
731 symbolic-link-prog := $(common-objpfx)elf/sln
732 symbolic-link-list := $(common-objpfx)elf/symlink.list
733 define make-shlib-link
734 echo $(<F) $@ >> $(symbolic-link-list)
735 endef
736 else # cross-compiling
737 # We need a definition that can be used by elf/Makefile's install rules.
738 symbolic-link-prog = $(LN_S)
739 endif
740 endif
741 ifndef make-shlib-link
742 define make-shlib-link
743 rm -f $@
744 $(LN_S) $(<F) $@
745 endef
746 endif
747
748 ifdef libc.so-version
749 # For a library specified to be version N, install three files:
750 # libc.so -> libc.so.N (e.g. libc.so.6)
751 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
752
753 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
754 $(+force)
755 $(make-shlib-link)
756 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
757 $(do-install-program)
758 install: $(inst_slibdir)/libc.so$(libc.so-version)
759
760 ifndef subdir
761 # What we install as libc.so for programs to link against is in fact a
762 # link script. It contains references for the various libraries we need.
763 # The libc.so object is not complete since some functions are only defined
764 # in libc_nonshared.a.
765 # We need to use absolute paths since otherwise local copies (if they exist)
766 # of the files are taken by the linker.
767 install: $(inst_libdir)/libc.so
768 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
769 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
770 $(libprefix)$(libc-name)) \
771 $(+force)
772 (echo '/* GNU ld script';\
773 echo ' Use the shared library, but some functions are only in';\
774 echo ' the static library, so try that secondarily. */';\
775 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
776 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
777 ')' \
778 ) > $@.new
779 mv -f $@.new $@
780
781 endif
782
783 else
784 install: $(inst_slibdir)/libc.so
785 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
786 $(do-install-program)
787 endif
788
789 ifneq (,$(versioned))
790 # Produce three sets of rules as above for all the smaller versioned libraries.
791
792 define o-iterator-doit
793 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
794 endef
795 object-suffixes-left := $(versioned)
796 include $(o-iterator)
797
798 # Make symlinks in the build directory, because the versioned names might
799 # be referenced by a DT_NEEDED in another library.
800 define o-iterator-doit
801 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
802 endef
803 object-suffixes-left := $(versioned)
804 include $(o-iterator)
805
806 generated += $(foreach o,$(versioned),$o$($o-version))
807
808 ifeq (,$($(subdir)-version))
809 define o-iterator-doit
810 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
811 $(+force);
812 $$(make-shlib-link)
813 endef
814 object-suffixes-left := $(versioned)
815 include $(o-iterator)
816
817 define o-iterator-doit
818 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
819 $$(do-install-program)
820 endef
821 object-suffixes-left := $(versioned)
822 include $(o-iterator)
823 else
824 define o-iterator-doit
825 $(inst_slibdir)/$o$($o-version): \
826 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
827 $$(make-shlib-link)
828 endef
829 object-suffixes-left := $(versioned)
830 include $(o-iterator)
831
832 define o-iterator-doit
833 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
834 $$(do-install-program)
835 endef
836 object-suffixes-left := $(versioned)
837 include $(o-iterator)
838 endif
839 endif
840
841 define do-install-so
842 $(do-install-program)
843 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
844 $(filter-out %.so,$@))
845 endef
846
847 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
848 $(foreach v,$(so-versions),\
849 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
850 $(+force)
851 $(do-install-so)
852 $(foreach v,$(so-versions),\
853 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
854 $(do-install-so)
855 endif
856
857 ifdef install-bin
858 $(addprefix $(inst_bindir)/,$(install-bin)): \
859 $(inst_bindir)/%: $(objpfx)% $(+force)
860 $(do-install-program)
861 endif
862 ifdef install-rootsbin
863 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
864 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
865 $(do-install-program)
866 endif
867 ifdef install-sbin
868 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
869 $(inst_sbindir)/%: $(objpfx)% $(+force)
870 $(do-install-program)
871 endif
872 ifdef install-lib
873 install-lib.a := $(filter lib%.a,$(install-lib))
874 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
875 ifdef install-lib-non.a
876 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
877 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
878 $(do-install)
879 endif
880 ifdef install-lib.a
881 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
882 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
883 $(do-install)
884 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
885 endif
886 endif
887 ifdef install-data
888 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
889 $(do-install)
890 endif
891 headers := $(strip $(headers))
892 ifdef headers
893 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
894 $(do-install)
895 endif # headers
896
897 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
898 install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
899 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
900 install-rootsbin-nosubdir: \
901 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
902 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
903 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
904 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
905 $(addprefix $(libprefix),$(install-lib-non.a)))
906 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
907 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
908 install-others-nosubdir: $(install-others)
909
910 # We need all the `-nosubdir' targets so that `install' in the parent
911 # doesn't depend on several things which each iterate over the subdirs.
912 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
913 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
914 install-%:: install-%-nosubdir ;
915
916 .PHONY: install install-no-libc.a-nosubdir
917 ifeq ($(build-programs),yes)
918 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
919 install-bin-nosubdir install-lib-nosubdir \
920 install-others-nosubdir install-rootsbin-nosubdir \
921 install-sbin-nosubdir
922 else
923 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
924 install-lib-nosubdir install-others-nosubdir
925 endif
926 install: install-no-libc.a-nosubdir
927 \f
928 # Command to compile $< in $(objdir) using the native libraries.
929 define native-compile
930 $(make-target-directory)
931 $(patsubst %/,cd % &&,$(objpfx)) \
932 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
933 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
934 endef
935
936 # Command to compile $< in $(common-objdir) using the native libraries.
937 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
938 define common-objdir-compile
939 $(patsubst %/,cd % &&,$(objpfx)) \
940 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
941 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
942 endef
943
944 # We always want to use configuration definitions.
945 # Note that this is only used for commands running in $(objpfx).
946 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
947
948 # Support the GNU standard name for this target.
949 .PHONY: check
950 check: tests
951 \f
952 .PHONY: TAGS
953 TAGS: $(objpfx)distinfo $(..)MakeTAGS
954 $(MAKE) $(addprefix -f ,$^) $@
955
956 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
957 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
958 FORCE:
959
960
961 .PHONY: echo-headers
962 echo-headers:
963 @echo $(headers)
964
965 \f
966 # Common cleaning targets.
967
968 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
969 clean: common-clean
970 mostlyclean: common-mostlyclean
971
972 do-tests-clean:
973 -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(test-srcs)) \
974 $(addsuffix -bp.out,$(tests) $(test-srcs)))
975
976 # Remove the object files.
977 common-mostlyclean:
978 -rm -f $(addprefix $(objpfx),$(tests) $(test-srcs) $(others) \
979 $(sysdep-others) stubs \
980 $(addsuffix .o,$(tests) $(test-srcs) \
981 $(others) \
982 $(sysdep-others)) \
983 $(addsuffix -bp,$(tests) $(test-srcs)) \
984 $(addsuffix .out,$(tests) $(test-srcs)) \
985 $(addsuffix -bp.out,$(tests) $(test-srcs)))
986 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
987 $(install-lib.so) \
988 $(install-lib.so:%.so=%_pic.a))
989 -rm -f core
990 $(rmobjs)
991 define rmobjs
992 $(foreach o,$(object-suffixes-for-libc),
993 -rm -f $(objpfx)stamp$o $(o-objects))
994 endef
995
996 # Also remove the dependencies and generated source files.
997 common-clean: common-mostlyclean
998 -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
999 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1000 -rm -f $(addprefix $(common-objpfx),$(common-generated))
1001 -rm -f $(objpfx)distinfo
1002 \f
1003 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1004 # for each function which is a stub. We grovel over all the .d files
1005 # looking for references to <stub-tag.h>. Then we grovel over each
1006 # referenced source file to see what stub function it defines.
1007
1008 ifdef objpfx
1009 .PHONY: stubs # The parent Makefile calls this target.
1010 stubs: $(objpfx)stubs
1011 endif
1012 s = $(sysdep_dir)/generic
1013 $(objpfx)stubs: $(+depfiles)
1014 # Use /dev/null since `...` might expand to empty.
1015 (s=`cd $s && $(PWD_P)`; \
1016 $(patsubst %/,cd % &&,$(objpfx)) \
1017 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
1018 `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
1019 -e '/stub-tag\.h/{; g; p; }' \
1020 $(patsubst $(objpfx)%,%,$^) /dev/null` \
1021 /dev/null) > $@T
1022 mv -f $@T $@
1023 \f
1024 # Make the distribution tar file.
1025
1026 .PHONY: dist
1027 dist: $(objpfx)distinfo $(..)Make-dist
1028 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
1029
1030 # Avoid depending on source files found in sysdeps dirs,
1031 # because the references affect implicit rule selection.
1032 dist: $(filter-out %.c %.S %.s,$(distribute))
1033
1034 # We used to simply export all these variables, but that frequently made the
1035 # environment get too large. Instead, we write all the information into
1036 # a generated makefile fragment `distinfo', and then include it with -f in
1037 # the sub-make that makes the distribution (above).
1038 $(objpfx)distinfo: Makefile $(..)Makerules \
1039 $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
1040 $(make-target-directory)
1041 $(distinfo-vars)
1042 mv -f $@.new $@
1043 .PHONY: subdir_distinfo
1044 subdir_distinfo: $(objpfx)distinfo
1045
1046 define distinfo-vars
1047 rm -f $@.new
1048 echo > $@.new 'subdir := $(subdir)'
1049 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
1050 headers sysdep_headers distribute dont_distribute generated \
1051 others tests test-srcs extra-libs $(extra-libs:%=%-routines) \
1052 versioned \
1053 $(addprefix install-,lib lib.so data bin sbin others),
1054 echo >> $@.new '$(subdir)-$(var) := $($(var))'
1055 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
1056 endef
1057 \f
1058 ifneq (,$(strip $(gpl2lgpl)))
1059 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1060 # Snarf from the master source and frob the copying notice.
1061 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1062 sed -f $^ > $@-tmp
1063 # So I don't edit them by mistake.
1064 chmod a-w $@-tmp
1065 mv -f $@-tmp $@
1066 ifeq ($(with-cvs),yes)
1067 test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
1068 endif
1069 endif
1070 endif
This page took 0.087186 seconds and 6 git commands to generate.