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