2002-12-27 Roland McGrath <roland@redhat.com>
[platform/upstream/glibc.git] / Makerules
1 # Copyright (C) 1991-1999,2000,01,02 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 Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the 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 # Lesser General Public License for more details.
13
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with the GNU C Library; if not, write to the Free
16 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 # 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 # 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))
80 \f
81 # Include any system-specific makefiles.
82
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) $(..)))
88
89 # The same is true for RPC source files.
90 vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
91                                       $(+sysdep_dirs) $(..)))
92
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
96
97 sysdep-makefiles := $(wildcard $(full_config_sysdirs:=/Makefile))
98 ifneq (,$(sysdep-makefiles))
99 include $(sysdep-makefiles)
100 endif
101
102
103 # Reorder before-compile so that mach things come first, and hurd things
104 # second, before all else.  The mach and hurd subdirectories have many
105 # generated header files which the much of rest of the library depends on,
106 # so it is best to build them first (and mach before hurd, at that).
107 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
108                            $(before-compile)) \
109                   $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
110                                $(before-compile))
111
112 # Even before that, we need abi-versions.h which is generated right here.
113 ifeq ($(versioning),yes)
114 ifndef avoid-generated
115 before-compile := $(common-objpfx)abi-versions.h $(before-compile)
116 $(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
117                                 $(common-objpfx)Versions.all
118         LC_ALL=C $(AWK) -v oldest_abi=$(oldest-abi) -f $^ > $@T
119         mv -f $@T $@
120
121 $(common-objpfx)%.latest: $(common-objpfx)abi-versions.h
122         sed -n '/ VERSION_$*_/{s/^.*_\([A-Z0-9_]*\).*$$/\1/;h;};$${g;p;}' \
123             $(common-objpfx)abi-versions.h > $@T
124         mv -f $@T $@
125 endif # avoid-generated
126 endif # $(versioning) = yes
127
128 # When we have no deps pass doing it, then make sure the subdirectory
129 # for object files gets created.
130 ifdef no_deps
131 ifdef objpfx
132 before-compile += $(objpfx).
133 $(objpfx).:
134         $(make-target-directory)
135 endif
136 endif
137
138 # Remove existing files from `before-compile'.  Things are added there when
139 # they must exist for dependency generation to work right, but once they
140 # exist there is no further need for every single file to depend on them,
141 # and those gratuitous dependencies result in many gratuitous
142 # recompilations.
143 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
144
145 # Don't let any before-compile file be an intermediate and get removed.
146 ifdef before-compile
147 $(before-compile):
148 endif
149
150 # If a makefile needs to do something conditional on something that
151 # can only be figured out from headers, write a FOO.make.c input
152 # file that uses cpp contructs and contains @@@ LINE @@@ for each LINE
153 # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
154 $(common-objpfx)%.make: $(..)%.make.c $(..)Makerules
155         rm -f $@T $@.dT
156         (echo '# Generated from $*.make.c by Makerules.'; \
157          SUNPRO_DEPENDENCIES='$@.dT $$(common-objpfx)$*.make' \
158          $(CC) $(CFLAGS) $(CPPFLAGS) -E $< \
159          | sed -n '/@@@/{s/@@@[  ]*\(.*\)@@@/\1/;s/[     ]*$$//p;}'; \
160          echo 'common-generated += $(@F)'; \
161          sed $(sed-remove-objpfx) $@.dT; rm -f $@.dT) > $@T
162         mv -f $@T $@
163 \f
164 # Generate an ordered list of implicit rules which find the source files in
165 # each sysdep directory.  The old method was to use vpath to search all the
166 # sysdep directories.  However, that had the problem that a .S file in a
167 # later directory would be chosen over a .c file in an earlier directory,
168 # which does not preserve the desired sysdeps ordering behavior.
169
170 # When making the list of .d files to include, we can't know which ones
171 # have source in .s files, and thus do not in fact need a .d file.
172 # So we must define rules to make .d files for .s files.
173 define make-dummy-dep
174 $(addprefix ln $(common-objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
175 endef
176 $(common-objpfx)dummy.d:
177         echo '# .s files cannot contain includes, so they need no deps.' > $@
178
179 # It matters that this set of rules, for compiling from sources in
180 # the current directory (the $srcdir/$subdir) come before the
181 # generated sysdep rules in included from sysd-rules below.  When
182 # compiling in the source tree, generated sources go into the current
183 # directory, and those should be chosen before any sources in sysdeps.
184 define o-iterator-doit
185 $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
186 endef
187 object-suffixes-left := $(all-object-suffixes)
188 include $(o-iterator)
189 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
190
191 define o-iterator-doit
192 $(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
193 endef
194 object-suffixes-left := $(all-object-suffixes)
195 include $(o-iterator)
196 $(objpfx)%.d: %.s $(common-objpfx)dummy.d; $(make-dummy-dep)
197
198 define o-iterator-doit
199 $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
200 endef
201 object-suffixes-left := $(all-object-suffixes)
202 include $(o-iterator)
203 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
204
205 # Omit the objpfx rules when building in the source tree, because
206 # objpfx is empty and so these rules just override the ones above.
207 ifdef objpfx
208 # Define first rules to find the source files in $(objpfx).
209 # Generated source files will end up there.
210 define o-iterator-doit
211 $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
212 endef
213 object-suffixes-left := $(all-object-suffixes)
214 include $(o-iterator)
215 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
216
217 define o-iterator-doit
218 $(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
219 endef
220 object-suffixes-left := $(all-object-suffixes)
221 include $(o-iterator)
222 $(objpfx)%.d: $(objpfx)%.s $(common-objpfx)dummy.d; $(make-dummy-dep)
223
224 define o-iterator-doit
225 $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
226 endef
227 object-suffixes-left := $(all-object-suffixes)
228 include $(o-iterator)
229 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
230 endif
231
232 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
233 # patterns matching sysdep directories whose assembly source files should
234 # be suppressed.
235 ifdef inhibit-sysdep-asm
236 define open-check-inhibit-asm
237 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
238 endef
239 close-check-inhibit-asm = ;; esac ;
240 endif
241
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 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
250                           $(wildcard $(foreach dir,$(sysdirs),\
251                                                $(dir)/Makefile))\
252                           $(sysd-rules-force)
253         -@rm -f $@T
254         (echo 'sysd-rules-sysdirs := $(config-sysdirs)';                      \
255          for dir in $(config-sysdirs:%='$$(..)%'); do                         \
256            for o in $(all-object-suffixes); do \
257              $(open-check-inhibit-asm) \
258              echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
259                   \$$(compile-command.S)";                                    \
260              echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
261                   \$$(compile-command.s)";                                    \
262              echo "\$$(objpfx)rtld-%$$o: $$dir/%.S \$$(before-compile); \
263                   \$$(compile-command.S)";                                    \
264              echo "\$$(objpfx)rtld-%$$o: $$dir/%.s \$$(before-compile); \
265                   \$$(compile-command.s)";                                    \
266              echo "\$$(objpfx)ptw-%$$o: $$dir/%.S \$$(before-compile); \
267                   \$$(compile-command.S)";                                    \
268              echo "\$$(objpfx)ptw-%$$o: $$dir/%.s \$$(before-compile); \
269                   \$$(compile-command.s)";                                    \
270              $(close-check-inhibit-asm) \
271              echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
272                   \$$(compile-command.c)";                                    \
273              echo "\$$(objpfx)rtld-%$$o: $$dir/%.c \$$(before-compile); \
274                   \$$(compile-command.c)";                                    \
275              echo "\$$(objpfx)ptw-%$$o: $$dir/%.c \$$(before-compile); \
276                   \$$(compile-command.c)";                                    \
277            done; \
278            $(open-check-inhibit-asm) \
279            echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
280                 \$$(make-dummy-dep)";                          \
281            echo "\$$(objpfx)rtld-%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
282                 \$$(make-dummy-dep)";                          \
283            echo "\$$(objpfx)ptw-%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
284                 \$$(make-dummy-dep)";                          \
285            echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
286                 \$$(+make-deps)";                                             \
287            echo "\$$(objpfx)rtld-%.d: $$dir/%.S \$$(before-compile); \
288                 \$$(+make-deps)";                                             \
289            echo "\$$(objpfx)ptw-%.d: $$dir/%.S \$$(before-compile); \
290                 \$$(+make-deps)";                                             \
291            $(close-check-inhibit-asm)   \
292            echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
293                 \$$(+make-deps)";                                             \
294            echo "\$$(objpfx)rtld-%.d: $$dir/%.c \$$(before-compile); \
295                 \$$(+make-deps)";                                             \
296            echo "\$$(objpfx)ptw-%.d: $$dir/%.c \$$(before-compile); \
297                 \$$(+make-deps)";                                             \
298            echo "\$$(objpfx)m_%.S: $$dir/s_%.S; \$$(+make-include-of-dep)";   \
299            echo "\$$(objpfx)m_%.c: $$dir/s_%.c; \$$(+make-include-of-dep)";   \
300          done;                                                                \
301          echo 'sysd-rules-done = t') > $@T
302         mv -f $@T $@
303
304 ifndef sysd-rules-done
305 # Don't do deps until this exists, because it provides rules to make the deps.
306 no_deps=t
307 endif
308
309 # This is used by the m_%.[Sc] pattern rules in sysd-rules.
310 define +make-include-of-dep
311 echo '#include <$<>' > $@T
312 mv -f $@T $@
313 endef
314
315 # Generate version maps, but wait until sysdep-subdirs is known
316 ifeq ($(sysd-sorted-done),t)
317 ifeq ($(versioning),yes)
318 -include $(common-objpfx)sysd-versions
319 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
320 common-generated += $(version-maps)
321 postclean-generated += sysd-versions Versions.all abi-versions.h \
322                        Versions.def.v.i Versions.def.v Versions.v.i Versions.v
323
324 ifndef avoid-generated
325 ifneq ($(sysd-versions-subdirs),$(all-subdirs) $(config-sysdirs))
326 sysd-versions-force = FORCE
327 FORCE:
328 endif
329 # See %.v/%.v.i implicit rules in Makeconfig.
330 $(common-objpfx)Versions.def.v.i: $(..)Versions.def \
331                                   $(wildcard $(add-ons:%=$(..)%/Versions.def))
332 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
333                               $(common-objpfx)soversions.i \
334                               $(common-objpfx)Versions.def.v
335         { while read lib version setname; do \
336             test -z "$$setname" || echo "$$lib : $$setname"; \
337           done < $(word 2,$^); \
338           cat $(word 3,$^); \
339         } | LC_ALL=C $(AWK) -f $< > $@T
340         mv -f $@T $@
341 # See %.v/%.v.i implicit rules in Makeconfig.
342 $(common-objpfx)Versions.v.i: $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
343                               $(wildcard $(sysdirs:%=%/Versions)) \
344                               $(common-objpfx)abi-versions.h \
345                               $(sysd-versions-force)
346 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
347                                $(common-objpfx)Versions.v \
348                                $(..)scripts/versions.awk
349         ( echo 'sysd-versions-subdirs = $(all-subdirs) $(config-sysdirs)' ; \
350           cat $(word 2,$^) \
351           | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
352                             -v move_if_change='$(move-if-change)' \
353                             -f $(word 3,$^); \
354         ) > $@T
355         mv -f $@T $@
356 endif # avoid-generated
357 endif # $(versioning) = yes
358 endif # sysd-sorted-done
359
360
361 ifndef compile-command.S
362 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
363 endif
364 ifndef compile-command.s
365 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
366 endif
367 ifndef compile-command.c
368 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
369 endif
370
371 # GCC can grok options after the file name, and it looks nicer that way.
372 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
373 compile.S = \
374   $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
375 COMPILE.S = \
376   $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
377 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
378
379 # If we want to generate MD5 checksums for the sources do this now.
380 ifeq ($(md5),yes)
381 generate-md5 = ; rm -f $(@:.d=.md5); \
382 $(CC) -E $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
383 sed '/^\#/d;/^[[:space:]]*$$/d' | md5sum > $(@:.d=.md5)
384 else
385 generate-md5 =
386 endif
387
388 # We need this for the output to go in the right place.  It will default to
389 # empty if make was configured to work with a cc that can't grok -c and -o
390 # together.  You can't compile the C library with such a compiler.
391 OUTPUT_OPTION = -o $@
392
393 # We need the $(CFLAGS) to be in there to have the right predefines during
394 # the dependency run for C sources.  But having it for assembly sources can
395 # get the wrong predefines.
396 S-CPPFLAGS = $(asm-CPPFLAGS)
397 define +make-deps
398 $(make-target-directory)
399 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
400              $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | sed \
401 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
402 $(sed-remove-objpfx) > $(@:.d=.T)
403 mv -f $(@:.d=.T) $@ $(generate-md5)
404 endef
405 ifneq (,$(objpfx))
406 # Continuation lines here are dangerous because they introduce spaces!
407 define sed-remove-objpfx
408 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
409 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
410 endef
411 endif
412 \f
413 # Modify the list of routines we build for different targets
414
415 ifeq (yesyes,$(build-shared)$(elf))
416 ifndef libc.so-version
417 # Undefine this because it can't work when we libc.so is unversioned.
418 static-only-routines =
419 endif
420 endif
421
422 # Bounded pointer thunks are only built for *.ob
423 elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
424
425 elide-routines.oS += $(filter-out $(static-only-routines),\
426                                   $(routines) $(aux) $(sysdep_routines)) \
427                      $(elide-bp-thunks)
428 elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
429
430 # If we have versioned code we don't need the old versions in any of the
431 # static libraries.
432 elide-routines.o  += $(shared-only-routines) $(elide-bp-thunks)
433 elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
434 elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
435 elide-routines.ob += $(shared-only-routines)
436 \f
437 # Shared library building.
438
439 ifeq (yes,$(build-shared))
440
441 # Reference map file only when versioning is selected and a map file name
442 # is given.
443 ifeq ($(versioning),yes)
444 map-file = $(firstword $($(@F:.so=-map)) \
445                        $(addprefix $(common-objpfx), \
446                                    $(filter $(@F:.so=.map),$(version-maps))))
447 load-map-file = $(map-file:%=-Wl,--version-script=%)
448 endif
449
450 # Pattern rule to build a shared object from an archive of PIC objects.
451 # This must come after the installation rules so Make doesn't try to
452 # build shared libraries in place from the installed *_pic.a files.
453 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
454 # on other shared objects.
455 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
456 ifneq (,$(findstring aix,$(config-os)))
457         (echo '#!'; \
458          dump -g $< | sed '1,6d' | cut -f2 | sort | uniq) > $(<:a=exp)
459 endif
460         $(build-shlib)
461
462 ifeq ($(elf),yes)
463 define build-shlib-helper
464 $(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) $(config-LDFLAGS) \
465           $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
466           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
467           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
468           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
469           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
470 endef
471 else
472 ifneq (,$(findstring aix,$(config-os)))
473 define build-shlib-helper
474 $(LINK.o) -Wl,-G,-bM:SRE,-bnoentry,-bE:$(<:a=exp) \
475           $(sysdep-LDFLAGS) $(config-LDFLAGS) $(extra-B-$(@F:lib%.so=%).so) \
476           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
477           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
478           -L$(subst :, -L,$(rpath-link))
479 endef
480 else
481 endif
482 endif
483
484 ifeq (yes,$(elf))
485 # binutils only position loadable notes into the first page for binaries,
486 # not for shared objects
487 define build-shlib
488 $(build-shlib-helper) \
489           -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
490           $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
491           sed -e '/^=========/,/^=========/!d;/^=========/d' \
492               -e 's/^.*\.hash[  ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
493               $(LDSEDCMD-$(@F:lib%.so=%).so) > $@.lds
494 rm -f $@.new
495 $(build-shlib-helper) -o $@ -T $@.lds \
496           $(csu-objpfx)abi-note.o $(build-shlib-objlist)
497 rm -f $@.lds
498 endef
499 else
500 ifneq (,$(findstring aix,$(config-os)))
501 define build-shlib
502 $(build-shlib-helper) \
503         -o $@ \
504         $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
505         $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
506 endef
507 define build-shlib
508 $(build-shlib-helper) \
509           $(build-shlib-objlist)
510 endef
511 endif
512 endif
513
514 ifneq (,$(findstring aix,$(config-os)))
515 define build-module-helper
516 $(LINK.o) -Wl,-G -Wl,-bM:SRE -Wl,-bnoentry -Wl,-bexpall \
517           $(sysdep-LDFLAGS) $(config-LDFLAGS) \
518           $(load-map-file) \
519           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
520           -L$(subst :, -L,$(rpath-link)) -Wl,-L=$(rpath-link)
521 endef
522 else
523 define build-module-helper
524 $(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
525           -B$(csu-objpfx) $(load-map-file) \
526           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
527           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
528 endef
529 endif
530
531 # This macro is similar to build-shlib but it does not define a soname
532 # and it does not depend on the destination name to start with `lib'.
533 ifeq (yes,$(elf))
534 # binutils only position loadable notes into the first page for binaries,
535 # not for shared objects
536 define build-module
537 $(build-module-helper) \
538           -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
539           $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
540           sed -e '/^=========/,/^=========/!d;/^=========/d' \
541               -e 's/^.*\.hash[  ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
542           > $@.lds
543 rm -f $@.new
544 $(build-module-helper) -o $@ -T $@.lds \
545           $(csu-objpfx)abi-note.o $(build-module-objlist)
546 rm -f $@.lds
547 endef
548 else
549 ifneq (,$(findstring aix,$(config-os)))
550 define build-module
551 $(build-module-helper) \
552           -o $@ \
553           $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
554           $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
555 endef
556 else
557 define build-module
558 define build-module
559 $(build-module-helper) \
560           -o $@ \
561           $(build-module-objlist)
562 endef
563 endif
564 endif
565
566 build-module-helper-objlist = \
567         $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
568                    $(filter-out $(map-file) $(+preinit) $(+postinit),$^))
569 whole-archive := -Wl,--whole-archive
570
571 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
572 build-shlib-objlist = $(build-module-helper-objlist) \
573                       $(LDLIBS-$(@F:lib%.so=%).so)
574
575 # Don't try to use -lc when making libc.so itself.
576 # Also omits crti.o and crtn.o, which we do not want
577 # since we define our own `.init' section specially.
578 LDFLAGS-c.so = -nostdlib -nostartfiles
579 # But we still want to link libc.so against $(gnulib).
580 LDLIBS-c.so += $(gnulib)
581 # Give libc.so an entry point and make it directly runnable itself.
582 LDFLAGS-c.so += -e __libc_main
583 # Force the backward compatibility EH functions to be linked.
584 LDFLAGS-c.so += -u __register_frame
585 # Pre-link the objects of libc_pic.a so that we can locally resolve
586 # COMMON symbols before we link against ld.so.  This is because ld.so
587 # contains some of libc_pic.a already, which will prevent the COMMONs
588 # from being allocated in libc.so, which introduces evil dependencies
589 # between libc.so and ld.so, which can make it impossible to upgrade.
590 ifeq ($(elf),yes)
591 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
592         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
593         $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
594 LDSEDCMD-c.so = -e 's/^.*\*(\.dynbss).*$$/& __start___libc_freeres_ptrs = .; *(__libc_freeres_ptrs) __stop___libc_freeres_ptrs = .;/'
595 # Use our own special initializer and finalizer files for libc.so.
596 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
597                          $(common-objpfx)libc_pic.os \
598                          $(elfobjdir)/sofini.os \
599                          $(elfobjdir)/interp.os $(elfobjdir)/ld.so
600         $(build-shlib)
601 ifeq ($(versioning),yes)
602 $(common-objpfx)libc.so: $(common-objpfx)libc.map
603 endif
604 common-generated += libc.so libc_pic.os
605 ifdef libc.so-version
606 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
607         $(make-link)
608 common-generated += libc.so$(libc.so-version)
609 endif
610 endif
611 else
612 ifneq (,$(findstring aix,$(config-os)))
613 $(common-objpfx)libc.so: $(common-objpfx)libc_pic.a
614         @rm -f $@
615         (echo '#!'; \
616          dump -g $^ | sed '1,6d' | cut -f2 | sort | uniq) > $(^:a=exp)
617         sed '/__mulh/d;/__mull/d;/__divss/d;/__divus/d;/__quoss/d;/__quous/d' \
618             /lib/syscalls.exp > $(common-objpfx)syscalls.exp
619         $(LINK.o) -G -bM:SRE -bnoentry -bE:$(^:a=exp) \
620                   -bE:$(common-objpfx)syscalls.exp \
621                   -bI:$(common-objpfx)syscalls.exp \
622                   -L$(common-objpfx) -o $@ $^
623 # AIX runtime ld wants libc.so to be libc.a(shr.o) hardwired
624         cp $@ $(common-objpfx)shr.o
625         $(AR) $(ARFLAGS) $(common-objpfx)libc.a $(common-objpfx)shr.o
626 endif
627 endif
628 \f
629 # Figure out the source filenames in this directory.
630
631 override sources := $(addsuffix .c,\
632                         $(filter-out $(elided-routines),\
633                             $(routines) $(aux) \
634                             $(sysdep_routines)))
635 sysdep_routines := $(sysdep_routines)
636
637 headers := $(headers) $(sysdep_headers)
638
639 # This is the list of all object files, gotten by
640 # replacing every ".c" in `sources' with a ".o".
641 # We also add bounded-pointer thunks, which are later
642 # elided for all suffixes except for `.ob'.
643 override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
644                       $(patsubst %,$(bppfx)%.o,\
645                         $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
646
647
648 # The makefile may define $(extra-libs) with `libfoo libbar'
649 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
650 ifdef extra-libs
651 # extra-lib.mk is included once for each extra lib to define rules
652 # to build it, and to add its objects to the various variables.
653 # During its evaluation, $(lib) is set to the name of the library.
654 extra-libs-left := $(extra-libs)
655 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
656 endif
657 \f
658 +depfiles := $(sources:.c=.d) \
659              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
660              $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
661 ifeq ($(build-programs),yes)
662 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
663 endif
664 +depfiles := $(addprefix $(objpfx),\
665                          $(filter-out $(addsuffix .d,$(omit-deps)),\
666                                       $(+depfiles))) \
667              $(addprefix $(common-objpfx),$(gen-as-const-headers:.sym=.h.d))
668
669 ifdef +depfiles
670 ifneq ($(no_deps),t)
671 -include $(+depfiles)
672 endif
673 endif
674 \f\f
675 # Maximize efficiency by minimizing the number of rules.
676 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
677 # Don't define any builtin rules.
678 MAKEFLAGS := $(MAKEFLAGS)r
679
680 # Generic rule for making directories.
681 %/:
682 # mkdir isn't smart enough to strip a trailing /.
683         mkdir $(@:%/=%)
684 \f
685 # Make sure that object files are not removed
686 # when they are intermediates between sources and library members.
687 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
688
689 # Make sure that the parent library archive is never removed.
690 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
691 \f
692 # Use the verbose option of ar and tar when not running silently.
693 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
694 verbose := v
695 else                                            # -s
696 verbose :=
697 endif                                           # not -s
698
699 ARFLAGS := r$(verbose)
700 CREATE_ARFLAGS := cru$(verbose)
701 \f
702 # This makes all the object files in the parent library archive.
703
704 .PHONY: lib lib-noranlib
705 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
706 lib-noranlib: libobjs
707
708 # For object-suffix $o, the list of objects with that suffix.
709 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
710 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
711                                                        $(elide-routines$o)),\
712                                             $(objects))) \
713             $(addprefix $(objpfx),$(o-objects$o))
714
715 others: $(addprefix $(objpfx),$(install-lib))
716
717 ifndef objects
718
719 # Create the stamp$o files to keep the parent makefile happy.
720 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
721 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
722         $(make-target-directory)
723         rm -f $@; > $@
724 else
725
726 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
727 # timestamp file; these rules (one explicit rule is generated for each
728 # object suffix) write a list of objects to update in the stamp file.
729 # The parent will then actually add them all to the archive in the
730 # archive rule, below.
731 define o-iterator-doit
732 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
733 endef
734 define do-stamp
735 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
736 mv -f $@T $@
737 endef
738 object-suffixes-left := $(object-suffixes-for-libc)
739 include $(o-iterator)
740
741 endif
742
743 # Now define explicit rules to build the library archives; these depend
744 # on the stamp files built above.
745 define o-iterator-doit
746 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
747                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
748 endef
749 define do-makelib
750 cd $(common-objdir) && \
751 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
752 $(RANLIB) $@
753 endef
754 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
755 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
756 ifndef subdir
757 $(subdirs-stamps): subdir_lib;
758 endif
759 object-suffixes-left = $(object-suffixes-for-libc)
760 include $(o-iterator)
761
762
763 # This makes all the object files.
764 .PHONY: objects objs libobjs extra-objs
765 objects objs: libobjs extra-objs
766 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
767 extra-objs: $(addprefix $(objpfx),$(extra-objs))
768
769 # Canned sequence for building an extra library archive.
770 define build-extra-lib
771 $(patsubst %/,cd % &&,$(objpfx)) \
772 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
773       $(patsubst $(objpfx)%,%,$^)
774 $(RANLIB) $@
775 endef
776 \f
777 # Installation.
778
779 .PHONY: force-install
780 force-install:
781
782 # $(install-lib) are installed from the object directory into $(libdir);
783 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
784 # unless they also appear in $(non-lib.a).  $(install-data) are installed
785 # as they are into $(datadir).  $(headers) are installed as they are in
786 # $(includedir).  $(install-bin), $(install-bin-script) and $(install-sbin)
787 # are installed from the object directory into $(bindir), $(bindir) and
788 # $(sbindir), respectively.  $(install-others) are absolute path names of
789 # files to install; rules to install them are defined elsewhere.
790
791 # The simple library name to install libc.a under.
792 # This could be defined by a sysdep Makefile.
793 ifndef libc-name
794 libc-name := c
795 endif
796
797 define do-install
798 $(make-target-directory)
799 $(INSTALL_DATA) $< $@
800 endef
801
802 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
803 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
804 define make-target-directory
805 $(addprefix $(..)./scripts/mkinstalldirs ,\
806             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
807 endef
808
809 # Any directory (parent or subdir) should install libc.a; this way
810 # "make install" in a subdir is guaranteed to install everything it changes.
811 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
812                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
813                                                      $(libprefix)$(libc-name)))
814 install: $(installed-libcs)
815 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
816         $(make-target-directory)
817         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
818 # Running ranlib after installing makes the __.SYMDEF time stamp up to
819 # date, which avoids messages from some linkers.
820         $(RANLIB) $@
821
822 define do-install-program
823 $(make-target-directory)
824 $(INSTALL_PROGRAM) $< $@.new
825 mv -f $@.new $@
826 endef
827
828 define do-install-script
829 $(make-target-directory)
830 $(INSTALL_SCRIPT) $< $@.new
831 mv -f $@.new $@
832 endef
833
834 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
835 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
836
837 ifeq (yes,$(build-shared))
838 # Find which .so's have versions.
839 versioned := $(strip $(foreach so,$(install-lib.so),\
840                                $(patsubst %,$(so),$($(so)-version))))
841
842 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
843 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
844
845 install-lib-nosubdir: $(install-lib.so-versioned:%=$(inst_libdir)/%) \
846                       $(install-lib.so-unversioned:%=$(inst_slibdir)/%)
847
848 # Install all the unversioned shared libraries.
849 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
850     $(objpfx)%.so $(+force)
851         $(do-install-program)
852
853 ifneq ($(findstring -s,$(LN_S)),)
854 define make-link
855 rm -f $@.new
856 $(SHELL) $(..)scripts/rellns-sh $< $@.new
857 mv -f $@.new $@
858 endef
859 else
860 # If we have no symbolic links don't bother with rellns-sh.
861 define make-link
862 rm -f $@.new
863 $(LN_S) $< $@.new
864 mv -f $@.new $@
865 endef
866 endif
867
868 ifeq (yes,$(build-shared))
869 ifeq (no,$(cross-compiling))
870 symbolic-link-prog := $(common-objpfx)elf/sln
871 symbolic-link-list := $(common-objpfx)elf/symlink.list
872 define make-shlib-link
873 echo $(<F) $@ >> $(symbolic-link-list)
874 endef
875 else # cross-compiling
876 # We need a definition that can be used by elf/Makefile's install rules.
877 symbolic-link-prog = $(LN_S)
878 endif
879 endif
880 ifndef make-shlib-link
881 define make-shlib-link
882 rm -f $@
883 $(LN_S) $(<F) $@
884 endef
885 endif
886
887 ifdef libc.so-version
888 # For a library specified to be version N, install three files:
889 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
890 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
891
892 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
893                                            $(+force)
894         $(make-shlib-link)
895 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
896         $(do-install-program)
897 install: $(inst_slibdir)/libc.so$(libc.so-version)
898
899 # This fragment of linker script gives the OUTPUT_FORMAT statement
900 # for the configuration we are building.  We put this statement into
901 # the linker scripts we install for -lc et al so that they will not be
902 # used by a link for a different format on a multi-architecture system.
903 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
904                             $(common-objpfx)config.make \
905                             $(common-objpfx)config.h $(..)Makerules
906         $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
907                   -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
908         | sed -n -f $< > $@.new
909         rm -f $@.so
910         mv -f $@.new $@
911 common-generated += format.lds
912
913 ifndef subdir
914 # What we install as libc.so for programs to link against is in fact a
915 # link script.  It contains references for the various libraries we need.
916 # The libc.so object is not complete since some functions are only defined
917 # in libc_nonshared.a.
918 # We need to use absolute paths since otherwise local copies (if they exist)
919 # of the files are taken by the linker.
920 install: $(inst_libdir)/libc.so
921 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
922                         $(common-objpfx)libc.so$(libc.so-version) \
923                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
924                                                   $(libprefix)$(libc-name)) \
925                         $(+force)
926         (echo '/* GNU ld script';\
927          echo '   Use the shared library, but some functions are only in';\
928          echo '   the static library, so try that secondarily.  */';\
929          cat $<; \
930          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
931               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
932               ')' \
933         ) > $@.new
934         mv -f $@.new $@
935
936 endif
937
938 else
939 install: $(inst_slibdir)/libc.so
940 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
941         $(do-install-program)
942 endif
943
944 ifneq (,$(versioned))
945 # Produce three sets of rules as above for all the smaller versioned libraries.
946
947 define o-iterator-doit
948 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
949 endef
950 object-suffixes-left := $(versioned)
951 include $(o-iterator)
952
953 # Make symlinks in the build directory, because the versioned names might
954 # be referenced by a DT_NEEDED in another library.
955 define o-iterator-doit
956 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
957 endef
958 object-suffixes-left := $(versioned)
959 include $(o-iterator)
960
961 generated += $(foreach o,$(versioned),$o$($o-version))
962
963 ifeq (,$($(subdir)-version))
964 define o-iterator-doit
965 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
966                                  $(+force);
967         $$(make-shlib-link)
968 endef
969 object-suffixes-left := $(versioned)
970 include $(o-iterator)
971
972 define o-iterator-doit
973 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
974         $$(do-install-program)
975 endef
976 object-suffixes-left := $(versioned)
977 include $(o-iterator)
978 else
979 define o-iterator-doit
980 $(inst_slibdir)/$o$($o-version): \
981   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
982         $$(make-shlib-link)
983 endef
984 object-suffixes-left := $(versioned)
985 include $(o-iterator)
986
987 define o-iterator-doit
988 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
989         $$(do-install-program)
990 endef
991 object-suffixes-left := $(versioned)
992 include $(o-iterator)
993 endif
994 endif
995
996 define do-install-so
997 $(do-install-program)
998 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
999            $(filter-out %.so,$@))
1000 endef
1001
1002 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1003 $(foreach v,$(so-versions),\
1004           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1005                                                $(+force)
1006         $(do-install-so)
1007 $(foreach v,$(so-versions),\
1008           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1009         $(do-install-so)
1010 endif
1011
1012 ifdef install-bin
1013 $(addprefix $(inst_bindir)/,$(install-bin)): \
1014     $(inst_bindir)/%: $(objpfx)% $(+force)
1015         $(do-install-program)
1016 endif
1017 ifdef install-bin-script
1018 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1019     $(inst_bindir)/%: $(objpfx)% $(+force)
1020         $(do-install-script)
1021 endif
1022 ifdef install-rootsbin
1023 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1024    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1025         $(do-install-program)
1026 endif
1027 ifdef install-sbin
1028 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1029     $(inst_sbindir)/%: $(objpfx)% $(+force)
1030         $(do-install-program)
1031 endif
1032 ifdef install-lib
1033 install-lib.a := $(filter lib%.a,$(install-lib))
1034 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1035 ifdef install-lib-non.a
1036 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1037   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1038         $(do-install)
1039 endif
1040 ifdef install-lib.a
1041 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1042   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1043         $(do-install)
1044         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
1045 endif
1046 endif
1047 ifdef install-data
1048 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1049         $(do-install)
1050 endif
1051 headers := $(strip $(headers))
1052 ifdef headers
1053 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
1054         $(do-install)
1055 endif   # headers
1056
1057 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1058         install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1059         install-data-nosubdir install-headers-nosubdir
1060 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1061 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1062 install-rootsbin-nosubdir: \
1063         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1064 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1065 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1066                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1067                        $(addprefix $(libprefix),$(install-lib-non.a)))
1068 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1069 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1070 install-others-nosubdir: $(install-others)
1071
1072 # We need all the `-nosubdir' targets so that `install' in the parent
1073 # doesn't depend on several things which each iterate over the subdirs.
1074 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1075 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
1076 install-%:: install-%-nosubdir ;
1077
1078 .PHONY: install install-no-libc.a-nosubdir
1079 ifeq ($(build-programs),yes)
1080 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1081                             install-bin-nosubdir install-bin-script-nosubdir \
1082                             install-lib-nosubdir install-others-nosubdir \
1083                             install-rootsbin-nosubdir install-sbin-nosubdir
1084 else
1085 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1086                             install-lib-nosubdir install-others-nosubdir
1087 endif
1088 install: install-no-libc.a-nosubdir
1089 \f
1090 # Command to compile $< in $(objdir) using the native libraries.
1091 define native-compile
1092 $(make-target-directory)
1093 $(patsubst %/,cd % &&,$(objpfx)) \
1094 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1095             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
1096 endef
1097
1098 # Command to compile $< in $(common-objdir) using the native libraries.
1099 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
1100 define common-objdir-compile
1101 $(patsubst %/,cd % &&,$(objpfx)) \
1102 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1103             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
1104 endef
1105
1106 # We always want to use configuration definitions.
1107 # Note that this is only used for commands running in $(objpfx).
1108 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
1109
1110 # Support the GNU standard name for this target.
1111 .PHONY: check
1112 check: tests
1113 # Special target to run tests which cannot be run unconditionally.
1114 # Maintainers should use this target.
1115 .PHONY: xcheck
1116 xcheck: xtests
1117
1118 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1119 ifneq (,$(all-nonlib))
1120 cpp-srcs-left = $(all-nonlib:=.c)
1121 lib := nonlib
1122 include $(patsubst %,$(..)cppflags-iterator.mk,$(all-nonlib))
1123 endif
1124
1125 # The include magic above causes those files to use this variable for flags.
1126 CPPFLAGS-nonlib = -DNOT_IN_libc=1
1127
1128
1129 ifeq ($(versioning),yes)
1130 # Generate normalized lists of symbols, versions, and data sizes.
1131 # This is handy for checking against existing library binaries.
1132
1133 %.symlist: $(..)scripts/abilist.awk %.dynsym
1134         LC_ALL=C $(AWK) -f $^ > $@T
1135         mv -f $@T $@
1136
1137 %.dynsym: %.so
1138         $(OBJDUMP) --dynamic-syms $< > $@T
1139         mv -f $@T $@
1140
1141 vpath %.symlist $(objpfx) $(common-objpfx)
1142 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1143              %.abilist %.symlist
1144         LC_ALL=C \
1145         $(AWK) -f $< \
1146                -v 'config=$(config-machine)-$(config-vendor)-$(config-os)' \
1147                $(filter %.abilist,$^) \
1148         | diff -pu0 - $(filter %.symlist,$^)
1149
1150 update-abi-%: $(..)scripts/merge-abilist.awk %.abilist %.symlist
1151 ifndef update-abi-config
1152         @echo 'Run $(MAKE) $@ update-abi-config=REGEXP'; exit 2
1153 else
1154         LC_ALL=C $(AWK) -v config=$(update-abi-config) -f $^ > $*.abilist.new
1155         mv -f $*.abilist.new $*.abilist
1156         @echo '*** Now check $*.abilist changes for correctness ***'
1157 endif
1158
1159 .PHONY: update-abi check-abi
1160 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1161 check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
1162 ifdef subdir
1163 subdir_check-abi: check-abi
1164 subdir_update-abi: update-abi
1165 else
1166 check-abi: subdir_check-abi
1167 update-abi: subdir_update-abi
1168 endif
1169
1170 # Enable this well all the .abilist files are in place.
1171 #tests: check-abi
1172 generated += $(install-lib.so-versioned:.so=.symlist)
1173
1174 ifeq ($(subdir),elf)
1175 check-abi: check-abi-libc
1176 update-abi: update-abi-libc
1177 common-generated += libc.symlist
1178 endif
1179
1180 endif
1181
1182 # Generating headers for assembly constants.
1183 $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk %.sym
1184         $(AWK) -f $^ \
1185         | $(CC) -S -o - $(CFLAGS) $(CPPFLAGS) -x c - \
1186                 -MD -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)' \
1187         | sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^@]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' > $(@:.h.d=.h)T
1188         sed $(sed-remove-objpfx) \
1189             -e 's@  *\([^       \/][^   \]*\)@ $$(..)\1@g' \
1190             -e 's@  *\.\.\/\([^         \]*\)@ $$(..)\1@g' \
1191             $(@:.h=.h.d)T > $(@:.h=.h.d)T2
1192         rm -f $(@:.h=.h.d)T
1193         mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
1194         mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
1195 vpath %.sym $(sysdirs)
1196
1197 before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
1198 \f
1199 .PHONY: TAGS
1200 TAGS: $(objpfx)distinfo $(..)MakeTAGS
1201         $(MAKE) $(addprefix -f ,$^) $@
1202
1203 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
1204         $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
1205 FORCE:
1206
1207
1208 .PHONY: echo-headers
1209 echo-headers:
1210         @echo $(headers)
1211
1212 \f
1213 # Common cleaning targets.
1214
1215 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1216 clean: common-clean
1217 mostlyclean: common-mostlyclean
1218
1219 do-tests-clean:
1220         -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1221                                                       $(test-srcs)) \
1222                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1223                                                          $(test-srcs)))
1224
1225 # Remove the object files.
1226 common-mostlyclean:
1227         -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1228                                      $(others) $(sysdep-others) stubs \
1229                                      $(addsuffix .o,$(tests) $(xtests) \
1230                                                     $(test-srcs) $(others) \
1231                                                     $(sysdep-others)) \
1232                                      $(addsuffix -bp,$(tests) $(xtests) \
1233                                                      $(test-srcs)) \
1234                                      $(addsuffix .out,$(tests) $(xtests) \
1235                                                       $(test-srcs)) \
1236                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1237                                                          $(test-srcs)))
1238         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
1239                                      $(install-lib.so) \
1240                                      $(install-lib.so:%.so=%_pic.a))
1241         -rm -f core
1242         -rm -f $(objpfx)rtld-*.os
1243         $(rmobjs)
1244 define rmobjs
1245 $(foreach o,$(object-suffixes-for-libc),
1246 -rm -f $(objpfx)stamp$o $(o-objects))
1247 endef
1248
1249 # Also remove the dependencies and generated source files.
1250 common-clean: common-mostlyclean
1251         -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
1252         -rm -f $(objpfx)rtld-*.d
1253         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1254         -rm -f $(addprefix $(common-objpfx),$(common-generated))
1255         -rm -f $(objpfx)distinfo
1256 \f
1257 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1258 # for each function which is a stub.  We grovel over all the .d files
1259 # looking for references to <stub-tag.h>.  Then we grovel over each
1260 # referenced source file to see what stub function it defines.
1261
1262 ifdef objpfx
1263 .PHONY: stubs # The parent Makefile calls this target.
1264 stubs: $(objpfx)stubs
1265 endif
1266 s = $(sysdep_dir)/generic
1267 $(objpfx)stubs: $(+depfiles)
1268 # Use /dev/null since `...` might expand to empty.
1269         (s=`cd $s && $(PWD_P)`; \
1270          $(patsubst %/,cd % &&,$(objpfx)) \
1271          sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
1272           `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
1273                 -e '/stub-tag\.h/{; g; p; }' \
1274                   $(patsubst $(objpfx)%,%,$^) /dev/null` \
1275              /dev/null) > $@T
1276         mv -f $@T $@
1277 \f
1278 # Make the distribution tar file.
1279
1280 .PHONY: dist
1281 dist: $(objpfx)distinfo $(..)Make-dist
1282         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
1283
1284 # Avoid depending on source files found in sysdeps dirs,
1285 # because the references affect implicit rule selection.
1286 dist: $(filter-out %.c %.S %.s,$(distribute))
1287
1288 # We used to simply export all these variables, but that frequently made the
1289 # environment get too large.  Instead, we write all the information into
1290 # a generated makefile fragment `distinfo', and then include it with -f in
1291 # the sub-make that makes the distribution (above).
1292 $(objpfx)distinfo: Makefile $(..)Makerules \
1293                    $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
1294         $(make-target-directory)
1295         $(distinfo-vars)
1296         mv -f $@.new $@
1297 .PHONY: subdir_distinfo
1298 subdir_distinfo: $(objpfx)distinfo
1299
1300 define distinfo-vars
1301 rm -f $@.new
1302 echo > $@.new 'subdir := $(subdir)'
1303 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
1304               headers sysdep_headers distribute dont_distribute generated \
1305               others tests xtests test-srcs extra-libs versioned \
1306               $(extra-libs:%=%-routines) \
1307               $(addprefix install-,lib lib.so data bin bin-script sbin others),
1308 echo >> $@.new '$(subdir)-$(var) := $($(var))'
1309 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
1310 endef
1311 \f
1312 ifneq (,$(strip $(gpl2lgpl)))
1313 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1314 # Snarf from the master source and frob the copying notice.
1315 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1316         sed -f $^ > $@-tmp
1317 # So I don't edit them by mistake.
1318         chmod a-w $@-tmp
1319         mv -f $@-tmp $@
1320 ifeq ($(with-cvs),yes)
1321         test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
1322 endif
1323 endif
1324 endif
1325
1326 # Local Variables:
1327 # mode: makefile
1328 # End: