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