]> sourceware.org Git - glibc.git/blob - Makerules
202c92239f0075a84b44da2eee6ebc3f0783fc57
[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 $(..)Versions.def \
295 $(wildcard $(add-ons:%=$(..)%/Versions.def)) \
296 $(common-objpfx)soversions.mk
297 { $(foreach map,$(map-firstversions),echo '$(subst :, : ,$(map))';) \
298 cat $(filter-out $< $(common-objpfx)soversions.mk,$^); \
299 } | LC_ALL=C $(AWK) -f $< > $@T
300 mv -f $@T $@
301 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
302 $(..)scripts/versions.awk \
303 $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
304 $(wildcard $(sysdirs:%=%/Versions)) \
305 $(sysd-versions-force)
306 { echo 'sysd-versions-subdirs = $(all-subdirs) $(config-sysdirs)' ; \
307 LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
308 -v move_if_change='$(move-if-change)' \
309 -f $(filter-out $< $(sysd-versions-force),$^); \
310 } > $@T
311 mv -f $@T $@
312 endif # avoid-generated
313 endif # $(versioning) = yes
314 endif # sysd-dirs-done
315
316
317 ifndef compile-command.S
318 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
319 endif
320 ifndef compile-command.s
321 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
322 endif
323 ifndef compile-command.c
324 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
325 endif
326
327 # GCC can grok options after the file name, and it looks nicer that way.
328 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
329 compile.S = \
330 $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
331 COMPILE.S = \
332 $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
333 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
334
335 # We need this for the output to go in the right place. It will default to
336 # empty if make was configured to work with a cc that can't grok -c and -o
337 # together. You can't compile the C library with such a compiler.
338 OUTPUT_OPTION = -o $@
339
340 S-CPPFLAGS = $(asm-CPPFLAGS)
341 define +make-deps
342 $(make-target-directory)
343 -@rm -f $@
344 $(+mkdep) $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
345 sed \
346 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
347 $(sed-remove-objpfx) > $(@:.d=.T)
348 mv -f $(@:.d=.T) $@
349 endef
350 ifneq (,$(objpfx))
351 # Continuation lines here are dangerous because they introduce spaces!
352 define sed-remove-objpfx
353 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
354 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
355 endef
356 endif
357 \f
358 # Shared library building.
359
360 ifeq (yes,$(build-shared))
361
362 # Reference map file only when versioning is selected and a map file name
363 # is given.
364 ifeq ($(versioning),yes)
365 map-file = $(firstword $($(@F:.so=-map)) \
366 $(addprefix $(common-objpfx), \
367 $(filter $(@F:.so=.map),$(version-maps))))
368 load-map-file = $(map-file:%=-Wl,--version-script=%)
369 endif
370
371 # Pattern rule to build a shared object from an archive of PIC objects.
372 # This must come after the installation rules so Make doesn't try to
373 # build shared libraries in place from the installed *_pic.a files.
374 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
375 # on other shared objects.
376 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
377 $(build-shlib)
378
379 define build-shlib
380 $(LINK.o) -shared -Wl,-O1 -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS) \
381 -B$(csu-objpfx) $(load-map-file) \
382 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
383 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
384 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
385 -Wl,--whole-archive \
386 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
387 $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
388 endef
389
390 # This macro is similar to build-shlib but it does not define a soname
391 # and it does not depend on the destination name to start with `lib'.
392 define build-module
393 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS) \
394 -B$(csu-objpfx) $(load-map-file) \
395 $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
396 -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link) \
397 -Wl,--whole-archive \
398 $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
399 $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
400 endef
401
402 ifndef libc.so-version
403 # Undefine this because it can't work when we libc.so is unversioned.
404 static-only-routines =
405 endif
406
407 elide-routines.oS += $(filter-out $(static-only-routines),\
408 $(routines) $(aux) $(sysdep_routines))
409 elide-routines.os += $(static-only-routines)
410
411 # If we have versioned code we don't need the old versions in any of the
412 # static libraries.
413 elide-routines.o += $(shared-only-routines)
414 elide-routines.op += $(shared-only-routines)
415 elide-routines.og += $(shared-only-routines)
416 elide-routines.ob += $(shared-only-routines)
417
418 # Don't try to use -lc when making libc.so itself.
419 # Also omits crti.o and crtn.o, which we do not want
420 # since we define our own `.init' section specially.
421 LDFLAGS-c.so = -nostdlib -nostartfiles
422 # But we still want to link libc.so against $(gnulib).
423 LDLIBS-c.so += $(gnulib)
424 # Give libc.so an entry point and make it directly runnable itself.
425 LDFLAGS-c.so += -e __libc_main
426 # Force the backward compatibility EH functions to be linked.
427 LDFLAGS-c.so += -u __register_frame
428 # Pre-link the objects of libc_pic.a so that we can locally resolve
429 # COMMON symbols before we link against ld.so. This is because ld.so
430 # contains some of libc_pic.a already, which will prevent the COMMONs
431 # from being allocated in libc.so, which introduces evil dependencies
432 # between libc.so and ld.so, which can make it impossible to upgrade.
433 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
434 $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
435 -Wl,-d -Wl,--whole-archive $^
436 # Use our own special initializer and finalizer files for libc.so.
437 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
438 $(common-objpfx)libc_pic.os \
439 $(elfobjdir)/sofini.os \
440 $(elfobjdir)/interp.os $(elfobjdir)/ld.so
441 $(build-shlib)
442 ifeq ($(versioning),yes)
443 $(common-objpfx)libc.so: $(common-objpfx)libc.map
444 endif
445 common-generated += libc.so libc_pic.os
446 ifdef libc.so-version
447 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
448 $(make-link)
449 common-generated += libc.so$(libc.so-version)
450 endif
451 endif
452 \f
453 # Figure out the source filenames in this directory.
454
455 override sources := $(addsuffix .c,$(filter-out $(elided-routines),\
456 $(routines) $(aux) \
457 $(sysdep_routines)))
458 sysdep_routines := $(sysdep_routines)
459
460 headers := $(headers) $(sysdep_headers)
461
462 # This is the list of all object files, gotten by
463 # replacing every ".c" in `sources' with a ".o".
464 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
465
466
467 # The makefile may define $(extra-libs) with `libfoo libbar'
468 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
469 ifdef extra-libs
470 # extra-lib.mk is included once for each extra lib to define rules
471 # to build it, and to add its objects to the various variables.
472 # During its evaluation, $(lib) is set to the name of the library.
473 extra-libs-left := $(extra-libs)
474 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
475 endif
476 \f
477 +depfiles := $(sources:.c=.d) \
478 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
479 $(addsuffix .d,$(tests) $(test-srcs))
480 ifeq ($(build-programs),yes)
481 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
482 endif
483 +depfiles := $(addprefix $(objpfx),\
484 $(filter-out $(addsuffix .d,$(omit-deps)),\
485 $(+depfiles)))
486
487 ifdef +depfiles
488 ifneq ($(no_deps),t)
489 -include $(+depfiles)
490 endif
491 endif
492 \f\f
493 # Maximize efficiency by minimizing the number of rules.
494 .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
495 # Don't define any builtin rules.
496 MAKEFLAGS := $(MAKEFLAGS)r
497
498 # Generic rule for making directories.
499 %/:
500 # mkdir isn't smart enough to strip a trailing /.
501 mkdir $(@:%/=%)
502 \f
503 # Make sure that object files are not removed
504 # when they are intermediates between sources and library members.
505 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
506
507 # Make sure that the parent library archive is never removed.
508 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
509 \f
510 # Use the verbose option of ar and tar when not running silently.
511 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
512 verbose := v
513 else # -s
514 verbose :=
515 endif # not -s
516
517 ARFLAGS := r$(verbose)
518 CREATE_ARFLAGS := cru$(verbose)
519 \f
520 # This makes all the object files in the parent library archive.
521
522 .PHONY: lib lib-noranlib
523 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
524 lib-noranlib: libobjs
525
526 # For object-suffix $o, the list of objects with that suffix.
527 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
528 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
529 $(elide-routines$o)),\
530 $(objects)))
531 others: $(addprefix $(objpfx),$(install-lib))
532
533 ifndef objects
534
535 # Create the stamp$o files to keep the parent makefile happy.
536 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
537 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
538 $(make-target-directory)
539 rm -f $@; > $@
540 else
541
542 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
543 # timestamp file; these rules (one explicit rule is generated for each
544 # object suffix) write a list of objects to update in the stamp file.
545 # The parent will then actually add them all to the archive in the
546 # archive rule, below.
547 define o-iterator-doit
548 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
549 endef
550 define do-stamp
551 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
552 mv -f $@T $@
553 endef
554 object-suffixes-left := $(object-suffixes-for-libc)
555 include $(o-iterator)
556
557 endif
558
559 # Now define explicit rules to build the library archives; these depend
560 # on the stamp files built above.
561 define o-iterator-doit
562 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
563 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
564 endef
565 define do-makelib
566 cd $(common-objdir) && \
567 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
568 $(RANLIB) $@
569 endef
570 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
571 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
572 ifndef subdir
573 $(subdirs-stamps): subdir_lib;
574 endif
575 object-suffixes-left = $(object-suffixes-for-libc)
576 include $(o-iterator)
577
578
579 # This makes all the object files.
580 .PHONY: objects objs libobjs extra-objs
581 objects objs: libobjs extra-objs
582 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
583 extra-objs: $(addprefix $(objpfx),$(extra-objs))
584
585 # Canned sequence for building an extra library archive.
586 define build-extra-lib
587 $(patsubst %/,cd % &&,$(objpfx)) \
588 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
589 $(patsubst $(objpfx)%,%,$^)
590 $(RANLIB) $@
591 endef
592 \f
593 # Installation.
594
595 .PHONY: force-install
596 force-install:
597
598 # $(install-lib) are installed from the object directory into $(libdir);
599 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
600 # unless they also appear in $(non-lib.a). $(install-data) are installed
601 # as they are into $(datadir). $(headers) are installed as they are in
602 # $(includedir). $(install-bin) and $(install-sbin) are installed from the
603 # object directory into $(bindir) and $(sbindir), respectively.
604 # $(install-others) are absolute path names of files to install; rules to
605 # install them are defined elsewhere.
606
607 # The simple library name to install libc.a under.
608 # This could be defined by a sysdep Makefile.
609 ifndef libc-name
610 libc-name := c
611 endif
612
613 define do-install
614 $(make-target-directory)
615 $(INSTALL_DATA) $< $@
616 endef
617
618 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
619 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
620 define make-target-directory
621 $(addprefix $(..)./scripts/mkinstalldirs ,\
622 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
623 endef
624
625 # Any directory (parent or subdir) should install libc.a; this way
626 # "make install" in a subdir is guaranteed to install everything it changes.
627 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
628 $(inst_libdir)/$(patsubst %,$(libtype$o),\
629 $(libprefix)$(libc-name)))
630 install: $(installed-libcs)
631 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
632 $(make-target-directory)
633 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
634 # Running ranlib after installing makes the __.SYMDEF time stamp up to
635 # date, which avoids messages from some linkers.
636 $(RANLIB) $@
637
638 define do-install-program
639 $(make-target-directory)
640 $(INSTALL_PROGRAM) $< $@.new
641 mv -f $@.new $@
642 endef
643
644 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
645 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
646
647 ifeq (yes,$(build-shared))
648 # Find which .so's have versions.
649 versioned := $(strip $(foreach so,$(install-lib.so),\
650 $(patsubst %,$(so),$($(so)-version))))
651
652 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
653 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
654
655 install-lib-nosubdir: $(install-lib.so-versioned:%=$(inst_libdir)/%) \
656 $(install-lib.so-unversioned:%=$(inst_slibdir)/%)
657
658 # Install all the unversioned shared libraries.
659 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
660 $(objpfx)%.so $(+force)
661 $(do-install-program)
662
663 ifneq ($(findstring -s,$(LN_S)),)
664 define make-link
665 rm -f $@.new
666 $(SHELL) $(..)scripts/rellns-sh $< $@.new
667 mv -f $@.new $@
668 endef
669 else
670 # If we have no symbolic links don't bother with rellns-sh.
671 define make-link
672 rm -f $@.new
673 $(LN_S) $< $@.new
674 mv -f $@.new $@
675 endef
676 endif
677
678 ifeq (no,$(cross-compiling))
679 ifeq (yes,$(build-shared))
680 symbolic-link-prog := $(common-objpfx)elf/sln
681 symbolic-link-list := $(common-objpfx)elf/symlink.list
682 define make-shlib-link
683 echo $(<F) $@ >> $(symbolic-link-list)
684 endef
685 endif
686 endif
687 ifndef make-shlib-link
688 define make-shlib-link
689 rm -f $@
690 $(LN_S) $(<F) $@
691 endef
692 endif
693
694 ifdef libc.so-version
695 # For a library specified to be version N, install three files:
696 # libc.so -> libc.so.N (e.g. libc.so.6)
697 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
698
699 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
700 $(+force)
701 $(make-shlib-link)
702 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
703 $(do-install-program)
704 install: $(inst_slibdir)/libc.so$(libc.so-version)
705
706 ifndef subdir
707 # What we install as libc.so for programs to link against is in fact a
708 # link script. It contains references for the various libraries we need.
709 # The libc.so object is not complete since some functions are only defined
710 # in libc_nonshared.a.
711 # We need to use absolute paths since otherwise local copies (if they exist)
712 # of the files are taken by the linker.
713 install: $(inst_libdir)/libc.so
714 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
715 $(inst_libdir)/$(patsubst %,$(libtype.oS),\
716 $(libprefix)$(libc-name)) \
717 $(+force)
718 (echo '/* GNU ld script';\
719 echo ' Use the shared library, but some functions are only in';\
720 echo ' the static library, so try that secondarily. */';\
721 echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
722 '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
723 ')' \
724 ) > $@.new
725 mv -f $@.new $@
726
727 endif
728
729 else
730 install: $(inst_slibdir)/libc.so
731 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
732 $(do-install-program)
733 endif
734
735 ifneq (,$(versioned))
736 # Produce three sets of rules as above for all the smaller versioned libraries.
737
738 define o-iterator-doit
739 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
740 endef
741 object-suffixes-left := $(versioned)
742 include $(o-iterator)
743
744 # Make symlinks in the build directory, because the versioned names might
745 # be referenced by a DT_NEEDED in another library.
746 define o-iterator-doit
747 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
748 endef
749 object-suffixes-left := $(versioned)
750 include $(o-iterator)
751
752 generated += $(foreach o,$(versioned),$o$($o-version))
753
754 ifeq (,$($(subdir)-version))
755 define o-iterator-doit
756 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
757 $(+force);
758 $$(make-shlib-link)
759 endef
760 object-suffixes-left := $(versioned)
761 include $(o-iterator)
762
763 define o-iterator-doit
764 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
765 $$(do-install-program)
766 endef
767 object-suffixes-left := $(versioned)
768 include $(o-iterator)
769 else
770 define o-iterator-doit
771 $(inst_slibdir)/$o$($o-version): \
772 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
773 $$(make-shlib-link)
774 endef
775 object-suffixes-left := $(versioned)
776 include $(o-iterator)
777
778 define o-iterator-doit
779 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
780 $$(do-install-program)
781 endef
782 object-suffixes-left := $(versioned)
783 include $(o-iterator)
784 endif
785 endif
786
787 define do-install-so
788 $(do-install-program)
789 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
790 $(filter-out %.so,$@))
791 endef
792
793 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
794 $(foreach v,$(so-versions),\
795 $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
796 $(+force)
797 $(do-install-so)
798 $(foreach v,$(so-versions),\
799 $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
800 $(do-install-so)
801 endif
802
803 ifdef install-bin
804 $(addprefix $(inst_bindir)/,$(install-bin)): \
805 $(inst_bindir)/%: $(objpfx)% $(+force)
806 $(do-install-program)
807 endif
808 ifdef install-rootsbin
809 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
810 $(inst_rootsbindir)/%: $(objpfx)% $(+force)
811 $(do-install-program)
812 endif
813 ifdef install-sbin
814 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
815 $(inst_sbindir)/%: $(objpfx)% $(+force)
816 $(do-install-program)
817 endif
818 ifdef install-lib
819 install-lib.a := $(filter lib%.a,$(install-lib))
820 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
821 ifdef install-lib-non.a
822 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
823 $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
824 $(do-install)
825 endif
826 ifdef install-lib.a
827 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
828 $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
829 $(do-install)
830 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
831 endif
832 endif
833 ifdef install-data
834 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
835 $(do-install)
836 endif
837 headers := $(strip $(headers))
838 ifdef headers
839 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
840 $(do-install)
841 endif # headers
842
843 .PHONY: install-bin-nosubdir install-rootsbin-nosubdir install-sbin-nosubdir \
844 install-lib-nosubdir install-data-nosubdir install-headers-nosubdir
845 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
846 install-rootsbin-nosubdir: \
847 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
848 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
849 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
850 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
851 $(addprefix $(libprefix),$(install-lib-non.a)))
852 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
853 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
854 install-others-nosubdir: $(install-others)
855
856 # We need all the `-nosubdir' targets so that `install' in the parent
857 # doesn't depend on several things which each iterate over the subdirs.
858 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
859 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
860 install-%:: install-%-nosubdir ;
861
862 .PHONY: install install-no-libc.a-nosubdir
863 ifeq ($(build-programs),yes)
864 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
865 install-bin-nosubdir install-lib-nosubdir \
866 install-others-nosubdir install-rootsbin-nosubdir \
867 install-sbin-nosubdir
868 else
869 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
870 install-lib-nosubdir install-others-nosubdir
871 endif
872 install: install-no-libc.a-nosubdir
873 \f
874 # Command to compile $< in $(objdir) using the native libraries.
875 define native-compile
876 $(make-target-directory)
877 $(patsubst %/,cd % &&,$(objpfx)) \
878 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
879 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
880 endef
881
882 # Command to compile $< in $(common-objdir) using the native libraries.
883 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
884 define common-objdir-compile
885 $(patsubst %/,cd % &&,$(objpfx)) \
886 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
887 $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
888 endef
889
890 # We always want to use configuration definitions.
891 # Note that this is only used for commands running in $(objpfx).
892 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
893
894 # Support the GNU standard name for this target.
895 .PHONY: check
896 check: tests
897 \f
898 .PHONY: TAGS
899 TAGS: $(objpfx)distinfo $(..)MakeTAGS
900 $(MAKE) $(addprefix -f ,$^) $@
901
902 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
903 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
904 FORCE:
905
906
907 .PHONY: echo-headers
908 echo-headers:
909 @echo $(headers)
910
911 \f
912 # Common cleaning targets.
913
914 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
915 clean: common-clean
916 mostlyclean: common-mostlyclean
917
918 do-tests-clean:
919 -rm -f $(patsubst %,$(objpfx)%.out,$(tests) $(test-srcs))
920
921 # Remove the object files.
922 common-mostlyclean:
923 -rm -f $(addprefix $(objpfx),$(tests) $(test-srcs) $(others) \
924 $(sysdep-others) stubs \
925 $(addsuffix .o,$(tests) $(test-srcs) \
926 $(others) \
927 $(sysdep-others)) \
928 $(addsuffix .out,$(tests) $(test-srcs)))
929 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
930 $(install-lib.so) \
931 $(install-lib.so:%.so=%_pic.a))
932 -rm -f core
933 $(rmobjs)
934 define rmobjs
935 $(foreach o,$(object-suffixes-for-libc),
936 -rm -f $(objpfx)stamp$o $(o-objects))
937 endef
938
939 # Also remove the dependencies and generated source files.
940 common-clean: common-mostlyclean
941 -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
942 -rm -fr $(addprefix $(objpfx),$(generated-dirs))
943 -rm -f $(addprefix $(common-objpfx),$(common-generated))
944 -rm -f $(objpfx)distinfo
945 \f
946 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
947 # for each function which is a stub. We grovel over all the .d files
948 # looking for references to <stub-tag.h>. Then we grovel over each
949 # referenced source file to see what stub function it defines.
950
951 ifdef objpfx
952 .PHONY: stubs # The parent Makefile calls this target.
953 stubs: $(objpfx)stubs
954 endif
955 s = $(sysdep_dir)/generic
956 $(objpfx)stubs: $(+depfiles)
957 # Use /dev/null since `...` might expand to empty.
958 (s=`cd $s && /bin/pwd`; \
959 $(patsubst %/,cd % &&,$(objpfx)) \
960 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
961 `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
962 -e '/stub-tag\.h/{; g; p; }' \
963 $(patsubst $(objpfx)%,%,$^) /dev/null` \
964 /dev/null) > $@T
965 mv -f $@T $@
966 \f
967 # Make the distribution tar file.
968
969 .PHONY: dist
970 dist: $(objpfx)distinfo $(..)Make-dist
971 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
972
973 # Avoid depending on source files found in sysdeps dirs,
974 # because the references affect implicit rule selection.
975 dist: $(filter-out %.c %.S %.s,$(distribute))
976
977 # We used to simply export all these variables, but that frequently made the
978 # environment get too large. Instead, we write all the information into
979 # a generated makefile fragment `distinfo', and then include it with -f in
980 # the sub-make that makes the distribution (above).
981 $(objpfx)distinfo: Makefile $(..)Makerules \
982 $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
983 $(make-target-directory)
984 $(distinfo-vars)
985 mv -f $@.new $@
986 .PHONY: subdir_distinfo
987 subdir_distinfo: $(objpfx)distinfo
988
989 define distinfo-vars
990 rm -f $@.new
991 echo > $@.new 'subdir := $(subdir)'
992 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
993 headers sysdep_headers distribute dont_distribute generated \
994 others tests test-srcs extra-libs $(extra-libs:%=%-routines) \
995 versioned \
996 $(addprefix install-,lib lib.so data bin sbin others),
997 echo >> $@.new '$(subdir)-$(var) := $($(var))'
998 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
999 endef
1000 \f
1001 ifneq (,$(strip $(gpl2lgpl)))
1002 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1003 # Snarf from the master source and frob the copying notice.
1004 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1005 sed -f $^ > $@-tmp
1006 # So I don't edit them by mistake.
1007 chmod a-w $@-tmp
1008 mv -f $@-tmp $@
1009 ifeq ($(with-cvs),yes)
1010 test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
1011 endif
1012 endif
1013 endif
This page took 0.082389 seconds and 5 git commands to generate.