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