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