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