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