Whitespace fix.
[glibc.git] / Makerules
blobd8eae55a3b31c1fe42f834b2ddf7c43a763b0cae
1 # Copyright (C) 1991-2002, 2003 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU 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.
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.
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.
20 #       Common rules for making the GNU C library.  This file is included
21 #       by the top-level Makefile and by all subdirectory makefiles
22 #       (through Rules).
24 ifneq (,)
25 This makefile requires GNU Make.
26 endif
28 REQUIRED_MAKE_VERSION = 3.74
29 REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
31 ifneq ($(REQUIRED_MAKE_VERSION), \
32        $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
33 Wrong GNU Make version.  See above for the version needed.
34 endif
37 ifdef   subdir
38 ..      := ../
39 endif   # subdir
41 # If `sources' was defined by the parent makefile, undefine it so
42 # we will later get it from wildcard search in this directory.
43 ifneq   "$(findstring env,$(origin sources))" ""
44 sources :=
45 endif
47 oPATH := $(PATH)
48 PATH := this definition should take precedence over $(oPATH)
49 ifeq ($(PATH),$(oPATH))
50 You must not use the -e flag when building the GNU C library.
51 else
52 PATH := $(oPATH)
53 endif
55 ifndef +included-Makeconfig
56 include $(..)Makeconfig
57 endif
59 # `configure' writes a definition of `config-sysdirs' in `config.make'.
60 sysdirs = $(strip $(full_config_sysdirs))
62 +sysdir_pfx = $(common-objpfx)
64 export sysdirs := $(sysdirs)
66 +sysdep_dirs := $(full_config_sysdirs)
67 ifdef objdir
68 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
69 endif
71 # Add -I switches to get the right sysdep directories.
72 # `+includes' in Makeconfig references $(+sysdep-includes).
73 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
75 # This variable is used in ``include $(o-iterator)'' after defining
76 # $(o-iterator-doit) to produce some desired rule using $o for the object
77 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
78 # is produced for each object suffix in use.
79 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
81 # Include any system-specific makefiles.
83 # This is here so things in sysdep Makefiles can easily depend on foo.h as
84 # appropriate and not worry about where foo.h comes from, which may be
85 # system dependent and not known by that Makefile.
86 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
87                                       $(+sysdep_dirs) $(..)))
89 # The same is true for RPC source files.
90 vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
91                                       $(+sysdep_dirs) $(..)))
93 # Some sysdep makefiles use this to distinguish being included here from
94 # being included individually by a subdir makefile (hurd/Makefile needs this).
95 in-Makerules := yes
97 sysdep-makefiles := $(wildcard $(full_config_sysdirs:=/Makefile))
98 ifneq (,$(sysdep-makefiles))
99 include $(sysdep-makefiles)
100 endif
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))
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 $@
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
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)
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
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))
164 # Don't let any before-compile file be an intermediate and get removed.
165 ifdef before-compile
166 $(before-compile):
167 endif
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 $@
184 ifdef subdir
185 sed-remove-dotdot := -e 's@  *\.\.\/\([^        \]*\)@ $$(..)\1@g'
186 else
187 sed-remove-dotdot := -e 's@  *\([^      \/$$][^         \]*\)@ $$(..)\1@g'
188 endif
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.
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.' > $@
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)
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)
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)
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)
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)
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
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
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 $@
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
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
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
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
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
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) \
400                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
401 COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
402                   $(ASFLAGS) $(ASFLAGS-$(suffix $@))
403 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
405 # If we want to generate MD5 checksums for the sources do this now.
406 ifeq ($(md5),yes)
407 generate-md5 = ; rm -f $(@:.d=.md5); \
408 $(CC) -E $< $(CFLAGS) $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | \
409 sed '/^\#/d;/^[[:space:]]*$$/d' | md5sum > $(@:.d=.md5)
410 else
411 generate-md5 =
412 endif
414 # We need this for the output to go in the right place.  It will default to
415 # empty if make was configured to work with a cc that can't grok -c and -o
416 # together.  You can't compile the C library with such a compiler.
417 OUTPUT_OPTION = -o $@
419 # We need the $(CFLAGS) to be in there to have the right predefines during
420 # the dependency run for C sources.  But having it for assembly sources can
421 # get the wrong predefines.
422 S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
423 define +make-deps
424 $(make-target-directory)
425 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
426              $(CPPFLAGS) $($(patsubst .%,%,$(suffix $(<F)))-CPPFLAGS) | sed \
427 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
428 $(sed-remove-objpfx) > $(@:.d=.T)
429 mv -f $(@:.d=.T) $@ $(generate-md5)
430 endef
431 ifneq (,$(objpfx))
432 # Continuation lines here are dangerous because they introduce spaces!
433 define sed-remove-objpfx
434 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
435 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
436 endef
437 endif
439 # Modify the list of routines we build for different targets
441 ifeq (yesyes,$(build-shared)$(elf))
442 ifndef libc.so-version
443 # Undefine this because it can't work when we libc.so is unversioned.
444 static-only-routines =
445 endif
446 endif
448 # Bounded pointer thunks are only built for *.ob
449 elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
451 elide-routines.oS += $(filter-out $(static-only-routines),\
452                                   $(routines) $(aux) $(sysdep_routines)) \
453                      $(elide-bp-thunks)
454 elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
456 # If we have versioned code we don't need the old versions in any of the
457 # static libraries.
458 elide-routines.o  += $(shared-only-routines) $(elide-bp-thunks)
459 elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
460 elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
461 elide-routines.ob += $(shared-only-routines)
463 # Shared library building.
465 ifeq (yes,$(build-shared))
467 # Reference map file only when versioning is selected and a map file name
468 # is given.
469 ifeq ($(versioning),yes)
470 map-file = $(firstword $($(@F:.so=-map)) \
471                        $(addprefix $(common-objpfx), \
472                                    $(filter $(@F:.so=.map),$(version-maps))))
473 load-map-file = $(map-file:%=-Wl,--version-script=%)
474 endif
476 # Pattern rule to build a shared object from an archive of PIC objects.
477 # This must come after the installation rules so Make doesn't try to
478 # build shared libraries in place from the installed *_pic.a files.
479 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
480 # on other shared objects.
481 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
482 ifneq (,$(findstring aix,$(config-os)))
483         (echo '#!'; \
484          dump -g $< | sed '1,6d' | cut -f2 | sort | uniq) > $(<:a=exp)
485 endif
486         $(build-shlib)
488 ifeq ($(elf),yes)
489 define build-shlib-helper
490 $(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) \
491           $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(config-LDFLAGS) \
492           $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
493           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
494           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
495           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
496           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
497 endef
498 else
499 ifneq (,$(findstring aix,$(config-os)))
500 define build-shlib-helper
501 $(LINK.o) -Wl,-G,-bM:SRE,-bnoentry,-bE:$(<:a=exp) \
502           $(sysdep-LDFLAGS) $(config-LDFLAGS) $(extra-B-$(@F:lib%.so=%).so) \
503           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
504           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
505           -L$(subst :, -L,$(rpath-link))
506 endef
507 else
508 endif
509 endif
511 ifeq (yes,$(elf))
512 # binutils only position loadable notes into the first page for binaries,
513 # not for shared objects
514 define build-shlib
515 $(build-shlib-helper) \
516           -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
517           $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
518           sed -e '/^=========/,/^=========/!d;/^=========/d' \
519               -e 's/^.*\.hash[  ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
520               $(LDSEDCMD-$(@F:lib%.so=%).so) > $@.lds
521 rm -f $@.new
522 $(build-shlib-helper) -o $@ -T $@.lds \
523           $(csu-objpfx)abi-note.o $(build-shlib-objlist)
524 rm -f $@.lds
525 endef
526 else
527 ifneq (,$(findstring aix,$(config-os)))
528 define build-shlib
529 $(build-shlib-helper) \
530         -o $@ \
531         $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
532         $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
533 endef
534 define build-shlib
535 $(build-shlib-helper) \
536           $(build-shlib-objlist)
537 endef
538 endif
539 endif
541 ifneq (,$(findstring aix,$(config-os)))
542 define build-module-helper
543 $(LINK.o) -Wl,-G -Wl,-bM:SRE -Wl,-bnoentry -Wl,-bexpall \
544           $(sysdep-LDFLAGS) $(config-LDFLAGS) \
545           $(load-map-file) \
546           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
547           -L$(subst :, -L,$(rpath-link)) -Wl,-L=$(rpath-link)
548 endef
549 else
550 define build-module-helper
551 $(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
552           -B$(csu-objpfx) $(load-map-file) \
553           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
554           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
555 endef
556 endif
558 # This macro is similar to build-shlib but it does not define a soname
559 # and it does not depend on the destination name to start with `lib'.
560 ifeq (yes,$(elf))
561 # binutils only position loadable notes into the first page for binaries,
562 # not for shared objects
563 define build-module
564 $(build-module-helper) \
565           -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
566           $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
567           sed -e '/^=========/,/^=========/!d;/^=========/d' \
568               -e 's/^.*\.hash[  ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
569           > $@.lds
570 rm -f $@.new
571 $(build-module-helper) -o $@ -T $@.lds \
572           $(csu-objpfx)abi-note.o $(build-module-objlist)
573 rm -f $@.lds
574 endef
575 else
576 ifneq (,$(findstring aix,$(config-os)))
577 define build-module
578 $(build-module-helper) \
579           -o $@ \
580           $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
581           $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
582 endef
583 else
584 define build-module
585 define build-module
586 $(build-module-helper) \
587           -o $@ \
588           $(build-module-objlist)
589 endef
590 endif
591 endif
593 build-module-helper-objlist = \
594         $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
595                    $(filter-out $(map-file) $(+preinit) $(+postinit),$^))
596 whole-archive := -Wl,--whole-archive
598 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
599 build-shlib-objlist = $(build-module-helper-objlist) \
600                       $(LDLIBS-$(@F:lib%.so=%).so)
602 # Don't try to use -lc when making libc.so itself.
603 # Also omits crti.o and crtn.o, which we do not want
604 # since we define our own `.init' section specially.
605 LDFLAGS-c.so = -nostdlib -nostartfiles
606 # But we still want to link libc.so against $(gnulib).
607 LDLIBS-c.so += $(gnulib)
608 # Give libc.so an entry point and make it directly runnable itself.
609 LDFLAGS-c.so += -e __libc_main
610 # Force the backward compatibility EH functions to be linked.
611 LDFLAGS-c.so += -u __register_frame
612 # Pre-link the objects of libc_pic.a so that we can locally resolve
613 # COMMON symbols before we link against ld.so.  This is because ld.so
614 # contains some of libc_pic.a already, which will prevent the COMMONs
615 # from being allocated in libc.so, which introduces evil dependencies
616 # between libc.so and ld.so, which can make it impossible to upgrade.
617 ifeq ($(elf),yes)
618 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
619         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
620         $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
621 LDSEDCMD-c.so = -e 's/^.*\*(\.dynbss).*$$/& __start___libc_freeres_ptrs = .; *(__libc_freeres_ptrs) __stop___libc_freeres_ptrs = .;/'
622 # Use our own special initializer and finalizer files for libc.so.
623 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
624                          $(common-objpfx)libc_pic.os \
625                          $(elfobjdir)/sofini.os \
626                          $(elfobjdir)/interp.os $(elfobjdir)/ld.so
627         $(build-shlib)
628 ifeq ($(versioning),yes)
629 $(common-objpfx)libc.so: $(common-objpfx)libc.map
630 endif
631 common-generated += libc.so libc_pic.os
632 ifdef libc.so-version
633 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
634         $(make-link)
635 common-generated += libc.so$(libc.so-version)
636 endif
637 endif
638 else
639 ifneq (,$(findstring aix,$(config-os)))
640 $(common-objpfx)libc.so: $(common-objpfx)libc_pic.a
641         @rm -f $@
642         (echo '#!'; \
643          dump -g $^ | sed '1,6d' | cut -f2 | sort | uniq) > $(^:a=exp)
644         sed '/__mulh/d;/__mull/d;/__divss/d;/__divus/d;/__quoss/d;/__quous/d' \
645             /lib/syscalls.exp > $(common-objpfx)syscalls.exp
646         $(LINK.o) -G -bM:SRE -bnoentry -bE:$(^:a=exp) \
647                   -bE:$(common-objpfx)syscalls.exp \
648                   -bI:$(common-objpfx)syscalls.exp \
649                   -L$(common-objpfx) -o $@ $^
650 # AIX runtime ld wants libc.so to be libc.a(shr.o) hardwired
651         cp $@ $(common-objpfx)shr.o
652         $(AR) $(ARFLAGS) $(common-objpfx)libc.a $(common-objpfx)shr.o
653 endif
654 endif
656 # Figure out the source filenames in this directory.
658 override sources := $(addsuffix .c,\
659                         $(filter-out $(elided-routines),\
660                             $(routines) $(aux) \
661                             $(sysdep_routines)))
662 sysdep_routines := $(sysdep_routines)
664 headers := $(headers) $(sysdep_headers)
666 # This is the list of all object files, gotten by
667 # replacing every ".c" in `sources' with a ".o".
668 # We also add bounded-pointer thunks, which are later
669 # elided for all suffixes except for `.ob'.
670 override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
671                       $(patsubst %,$(bppfx)%.o,\
672                         $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
675 # The makefile may define $(extra-libs) with `libfoo libbar'
676 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
677 ifdef extra-libs
678 # extra-lib.mk is included once for each extra lib to define rules
679 # to build it, and to add its objects to the various variables.
680 # During its evaluation, $(lib) is set to the name of the library.
681 extra-libs-left := $(extra-libs)
682 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
683 endif
685 +depfiles := $(sources:.c=.d) \
686              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
687              $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
688 ifeq ($(build-programs),yes)
689 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
690 endif
691 +depfiles := $(addprefix $(objpfx),\
692                          $(filter-out $(addsuffix .d,$(omit-deps)),\
693                                       $(+depfiles)))
695 # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
696 # They will be generated when they're needed, and trying too early won't work.
697 +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
698 +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
699                                                 $(+gen-as-const)))
701 ifdef +depfiles
702 ifneq ($(no_deps),t)
703 -include $(+depfiles)
704 endif
705 endif
706 \f\f
707 # Maximize efficiency by minimizing the number of rules.
708 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
709 # Don't define any builtin rules.
710 MAKEFLAGS := $(MAKEFLAGS)r
712 # Generic rule for making directories.
714 # mkdir isn't smart enough to strip a trailing /.
715         mkdir $(@:%/=%)
717 # Make sure that object files are not removed
718 # when they are intermediates between sources and library members.
719 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
721 # Make sure that the parent library archive is never removed.
722 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
724 # Use the verbose option of ar and tar when not running silently.
725 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
726 verbose := v
727 else                                            # -s
728 verbose :=
729 endif                                           # not -s
731 ARFLAGS := r$(verbose)
732 CREATE_ARFLAGS := cru$(verbose)
734 # This makes all the object files in the parent library archive.
736 .PHONY: lib lib-noranlib
737 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
738 lib-noranlib: libobjs
740 # For object-suffix $o, the list of objects with that suffix.
741 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
742 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
743                                                        $(elide-routines$o)),\
744                                             $(objects))) \
745             $(addprefix $(objpfx),$(o-objects$o))
747 others: $(addprefix $(objpfx),$(install-lib))
749 ifndef objects
751 # Create the stamp$o files to keep the parent makefile happy.
752 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
753 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
754         $(make-target-directory)
755         rm -f $@; > $@
756 else
758 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
759 # timestamp file; these rules (one explicit rule is generated for each
760 # object suffix) write a list of objects to update in the stamp file.
761 # The parent will then actually add them all to the archive in the
762 # archive rule, below.
763 define o-iterator-doit
764 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
765 endef
766 define do-stamp
767 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
768 mv -f $@T $@
769 endef
770 object-suffixes-left := $(object-suffixes-for-libc)
771 include $(o-iterator)
773 endif
775 # Now define explicit rules to build the library archives; these depend
776 # on the stamp files built above.
777 define o-iterator-doit
778 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
779                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
780 endef
781 define do-makelib
782 cd $(common-objdir) && \
783 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
784 $(RANLIB) $@
785 endef
786 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
787 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
788 ifndef subdir
789 $(subdirs-stamps): subdir_lib;
790 endif
791 object-suffixes-left = $(object-suffixes-for-libc)
792 include $(o-iterator)
795 # This makes all the object files.
796 .PHONY: objects objs libobjs extra-objs
797 objects objs: libobjs extra-objs
798 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
799 extra-objs: $(addprefix $(objpfx),$(extra-objs))
801 # Canned sequence for building an extra library archive.
802 define build-extra-lib
803 $(patsubst %/,cd % &&,$(objpfx)) \
804 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
805       $(patsubst $(objpfx)%,%,$^)
806 $(RANLIB) $@
807 endef
809 # Installation.
811 .PHONY: force-install
812 force-install:
814 # $(install-lib) are installed from the object directory into $(libdir);
815 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
816 # unless they also appear in $(non-lib.a).  $(install-data) are installed
817 # as they are into $(datadir).  $(headers) are installed as they are in
818 # $(includedir).  $(install-bin), $(install-bin-script) and $(install-sbin)
819 # are installed from the object directory into $(bindir), $(bindir) and
820 # $(sbindir), respectively.  $(install-others) are absolute path names of
821 # files to install; rules to install them are defined elsewhere.
823 # The simple library name to install libc.a under.
824 # This could be defined by a sysdep Makefile.
825 ifndef libc-name
826 libc-name := c
827 endif
829 define do-install
830 $(make-target-directory)
831 $(INSTALL_DATA) $< $@
832 endef
834 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
835 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
836 define make-target-directory
837 $(addprefix $(..)./scripts/mkinstalldirs ,\
838             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
839 endef
841 # Any directory (parent or subdir) should install libc.a; this way
842 # "make install" in a subdir is guaranteed to install everything it changes.
843 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
844                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
845                                                      $(libprefix)$(libc-name)))
846 install: $(installed-libcs)
847 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
848         $(make-target-directory)
849         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
850 # Running ranlib after installing makes the __.SYMDEF time stamp up to
851 # date, which avoids messages from some linkers.
852         $(RANLIB) $@
854 define do-install-program
855 $(make-target-directory)
856 $(INSTALL_PROGRAM) $< $@.new
857 mv -f $@.new $@
858 endef
860 define do-install-script
861 $(make-target-directory)
862 $(INSTALL_SCRIPT) $< $@.new
863 mv -f $@.new $@
864 endef
866 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
867 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
869 ifeq (yes,$(build-shared))
870 # Find which .so's have versions.
871 versioned := $(strip $(foreach so,$(install-lib.so),\
872                                $(patsubst %,$(so),$($(so)-version))))
874 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
875 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
877 # For versioned libraries, we install three files:
878 #       $(inst_libdir)/libfoo.so        -- for linking, symlink or ld script
879 #       $(inst_slibdir)/libfoo.so.NN    -- for loading by SONAME, symlink
880 #       $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
881 V := $(firstword $($(subdir)-version) $(version))
882 install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
883                       $(foreach L,$(install-lib.so-versioned),\
884                                 $(inst_libdir)/$L \
885                                 $(inst_slibdir)/$(L:.so=)-$V.so \
886                                 $(inst_slibdir)/$L$($L-version))
888 # Install all the unversioned shared libraries.
889 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
890     $(objpfx)%.so $(+force)
891         $(do-install-program)
893 ifneq ($(findstring -s,$(LN_S)),)
894 define make-link
895 rm -f $@.new
896 $(SHELL) $(..)scripts/rellns-sh $< $@.new
897 mv -f $@.new $@
898 endef
899 else
900 # If we have no symbolic links don't bother with rellns-sh.
901 define make-link
902 rm -f $@.new
903 $(LN_S) $< $@.new
904 mv -f $@.new $@
905 endef
906 endif
908 ifeq (yes,$(build-shared))
909 ifeq (no,$(cross-compiling))
910 symbolic-link-prog := $(common-objpfx)elf/sln
911 symbolic-link-list := $(common-objpfx)elf/symlink.list
912 define make-shlib-link
913 echo $(<F) $@ >> $(symbolic-link-list)
914 endef
915 else # cross-compiling
916 # We need a definition that can be used by elf/Makefile's install rules.
917 symbolic-link-prog = $(LN_S)
918 endif
919 endif
920 ifndef make-shlib-link
921 define make-shlib-link
922 rm -f $@
923 $(LN_S) $(<F) $@
924 endef
925 endif
927 ifdef libc.so-version
928 # For a library specified to be version N, install three files:
929 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
930 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
932 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
933                                            $(+force)
934         $(make-shlib-link)
935 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
936         $(do-install-program)
937 install: $(inst_slibdir)/libc.so$(libc.so-version)
939 # This fragment of linker script gives the OUTPUT_FORMAT statement
940 # for the configuration we are building.  We put this statement into
941 # the linker scripts we install for -lc et al so that they will not be
942 # used by a link for a different format on a multi-architecture system.
943 $(common-objpfx)format.lds: $(..)scripts/output-format.sed \
944                             $(common-objpfx)config.make \
945                             $(common-objpfx)config.h $(..)Makerules
946         $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
947                   -x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
948         | sed -n -f $< > $@.new
949         rm -f $@.so
950         mv -f $@.new $@
951 common-generated += format.lds
953 ifndef subdir
954 # What we install as libc.so for programs to link against is in fact a
955 # link script.  It contains references for the various libraries we need.
956 # The libc.so object is not complete since some functions are only defined
957 # in libc_nonshared.a.
958 # We need to use absolute paths since otherwise local copies (if they exist)
959 # of the files are taken by the linker.
960 install: $(inst_libdir)/libc.so
961 $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
962                         $(common-objpfx)libc.so$(libc.so-version) \
963                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
964                                                   $(libprefix)$(libc-name)) \
965                         $(+force)
966         (echo '/* GNU ld script';\
967          echo '   Use the shared library, but some functions are only in';\
968          echo '   the static library, so try that secondarily.  */';\
969          cat $<; \
970          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
971               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
972               ')' \
973         ) > $@.new
974         mv -f $@.new $@
976 endif
978 else
979 install: $(inst_slibdir)/libc.so
980 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
981         $(do-install-program)
982 endif
984 ifneq (,$(versioned))
985 # Produce three sets of rules as above for all the smaller versioned libraries.
987 define o-iterator-doit
988 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
989 endef
990 object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
991 ifneq (,$(object-suffixes-left))
992 include $(o-iterator)
993 endif
995 # Make symlinks in the build directory, because the versioned names might
996 # be referenced by a DT_NEEDED in another library.
997 define o-iterator-doit
998 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
999 endef
1000 object-suffixes-left := $(versioned)
1001 include $(o-iterator)
1003 generated += $(foreach o,$(versioned),$o$($o-version))
1005 ifeq (,$($(subdir)-version))
1006 define o-iterator-doit
1007 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
1008                                  $(+force);
1009         $$(make-shlib-link)
1010 endef
1011 object-suffixes-left := $(versioned)
1012 include $(o-iterator)
1014 define o-iterator-doit
1015 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
1016         $$(do-install-program)
1017 endef
1018 object-suffixes-left := $(versioned)
1019 include $(o-iterator)
1020 else
1021 define o-iterator-doit
1022 $(inst_slibdir)/$o$($o-version): \
1023   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
1024         $$(make-shlib-link)
1025 endef
1026 object-suffixes-left := $(versioned)
1027 include $(o-iterator)
1029 define o-iterator-doit
1030 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
1031         $$(do-install-program)
1032 endef
1033 object-suffixes-left := $(versioned)
1034 include $(o-iterator)
1035 endif
1036 endif
1038 define do-install-so
1039 $(do-install-program)
1040 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
1041            $(filter-out %.so,$@))
1042 endef
1044 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
1045 $(foreach v,$(so-versions),\
1046           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
1047                                                $(+force)
1048         $(do-install-so)
1049 $(foreach v,$(so-versions),\
1050           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
1051         $(do-install-so)
1052 endif
1054 ifdef install-bin
1055 $(addprefix $(inst_bindir)/,$(install-bin)): \
1056     $(inst_bindir)/%: $(objpfx)% $(+force)
1057         $(do-install-program)
1058 endif
1059 ifdef install-bin-script
1060 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
1061     $(inst_bindir)/%: $(objpfx)% $(+force)
1062         $(do-install-script)
1063 endif
1064 ifdef install-rootsbin
1065 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
1066    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
1067         $(do-install-program)
1068 endif
1069 ifdef install-sbin
1070 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1071     $(inst_sbindir)/%: $(objpfx)% $(+force)
1072         $(do-install-program)
1073 endif
1074 ifdef install-lib
1075 install-lib.a := $(filter lib%.a,$(install-lib))
1076 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1077 ifdef install-lib-non.a
1078 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1079   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1080         $(do-install)
1081 endif
1082 ifdef install-lib.a
1083 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1084   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1085         $(do-install)
1086         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
1087 endif
1088 endif
1089 ifdef install-data
1090 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1091         $(do-install)
1092 endif
1093 headers := $(strip $(headers))
1094 ifdef headers
1095 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
1096         $(do-install)
1097 endif   # headers
1099 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1100         install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1101         install-data-nosubdir install-headers-nosubdir
1102 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1103 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1104 install-rootsbin-nosubdir: \
1105         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1106 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1107 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1108                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1109                        $(addprefix $(libprefix),$(install-lib-non.a)))
1110 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1111 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1112 install-others-nosubdir: $(install-others)
1114 # We need all the `-nosubdir' targets so that `install' in the parent
1115 # doesn't depend on several things which each iterate over the subdirs.
1116 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1117 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
1118 install-%:: install-%-nosubdir ;
1120 .PHONY: install install-no-libc.a-nosubdir
1121 ifeq ($(build-programs),yes)
1122 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1123                             install-bin-nosubdir install-bin-script-nosubdir \
1124                             install-lib-nosubdir install-others-nosubdir \
1125                             install-rootsbin-nosubdir install-sbin-nosubdir
1126 else
1127 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1128                             install-lib-nosubdir install-others-nosubdir
1129 endif
1130 install: install-no-libc.a-nosubdir
1132 # Command to compile $< in $(objdir) using the native libraries.
1133 define native-compile
1134 $(make-target-directory)
1135 $(patsubst %/,cd % &&,$(objpfx)) \
1136 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1137             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
1138 endef
1140 # Command to compile $< in $(common-objdir) using the native libraries.
1141 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
1142 define common-objdir-compile
1143 $(patsubst %/,cd % &&,$(objpfx)) \
1144 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1145             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
1146 endef
1148 # We always want to use configuration definitions.
1149 # Note that this is only used for commands running in $(objpfx).
1150 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
1152 # Support the GNU standard name for this target.
1153 .PHONY: check
1154 check: tests
1155 # Special target to run tests which cannot be run unconditionally.
1156 # Maintainers should use this target.
1157 .PHONY: xcheck
1158 xcheck: xtests
1160 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1161 ifneq (,$(all-nonlib))
1162 cpp-srcs-left = $(all-nonlib:=.c)
1163 lib := nonlib
1164 include $(patsubst %,$(..)cppflags-iterator.mk,$(all-nonlib))
1165 endif
1167 # The include magic above causes those files to use this variable for flags.
1168 CPPFLAGS-nonlib = -DNOT_IN_libc=1
1171 ifeq ($(versioning),yes)
1172 # Generate normalized lists of symbols, versions, and data sizes.
1173 # This is handy for checking against existing library binaries.
1175 %.symlist: $(..)scripts/abilist.awk %.dynsym
1176         LC_ALL=C $(AWK) -f $^ > $@T
1177         mv -f $@T $@
1179 %.dynsym: %.so
1180         $(OBJDUMP) --dynamic-syms $< > $@T
1181         mv -f $@T $@
1183 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1184              $(..)abilist/%.abilist $(objpfx)%.symlist
1185         $(check-abi)
1186 check-abi-%: $(..)scripts/extract-abilist.awk $(common-objpfx)config.make \
1187              $(..)abilist/%.abilist $(common-objpfx)%.symlist
1188         $(check-abi)
1189 define check-abi
1190         LC_ALL=C \
1191         $(AWK) -f $< -v 'config=$(check-abi-config)' \
1192                $(filter %.abilist,$^) \
1193         | { diff -pu0 - $(filter %.symlist,$^) $(check-abi-warn) ; }
1194 endef
1195 ifeq ($(enable-check-abi),warn)
1196 check-abi-warn = || echo '*** WARNING: $*.so failed ABI check'
1197 endif
1199 ifeq ($(firstword $(sysd-sorted-done) f)$(firstword $(generating) f),tf)
1200 -include $(common-objpfx)tls.make
1201 config-tls := notls
1202 ifeq ($(use-tls),yes)
1203 config-tls := tls
1204 endif
1205 ifeq ($(use-thread),yes)
1206 config-tls := thread
1207 endif
1208 check-abi-config := \
1209   $(config-machine)-$(config-vendor)-$(config-os)/$(config-tls)
1210 endif
1212 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1213               $(objpfx)%.symlist
1214         $(update-abi)
1215 update-abi-%: $(..)scripts/merge-abilist.awk $(..)abilist/%.abilist \
1216               $(common-objpfx)%.symlist
1217         $(update-abi)
1218 ifndef update-abi-config
1219 define update-abi
1220         @echo 'Run $(MAKE) $@ update-abi-config=REGEXP'; exit 2
1221 endef
1222 else
1223 define update-abi
1224 LC_ALL=C $(AWK) -v config='$(update-abi-config)' -f $^ \
1225          > $(..)abilist/$*.abilist.new
1226 @if cmp -s $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist 2> /dev/null; \
1227  then rm -f $(..)abilist/$*.abilist.new; \
1228       echo '+++ $(..)abilist/$*.abilist is unchanged'; \
1229  else mv -f $(..)abilist/$*.abilist.new $(..)abilist/$*.abilist; \
1230       echo '*** Now check $*.abilist changes for correctness ***'; \
1231  fi
1232 endef
1233 endif
1235 .PHONY: update-abi check-abi
1236 update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
1237 check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
1238 ifdef subdir
1239 subdir_check-abi: check-abi
1240 subdir_update-abi: update-abi
1241 else
1242 check-abi: subdir_check-abi
1243 update-abi: subdir_update-abi
1244 endif
1246 ifeq ($(subdir),elf)
1247 check-abi: check-abi-libc
1248 update-abi: update-abi-libc
1249 common-generated += libc.symlist
1250 endif
1252 ifeq ($(build-shared),yes)
1253 ifneq ($(enable-check-abi),no)
1254 ifdef subdir
1255 tests: check-abi
1256 endif
1257 endif
1258 endif
1260 endif
1262 # There's no good place to put this - here will do.
1263 # The dependencies are wrong if it's run from the top level.
1264 ifeq ($(filter %posix, $(sysdirs)),)
1265 L_tmpnam  = 1
1266 TMP_MAX   = 0
1267 L_ctermid = 1
1268 L_cuserid = 1
1269 else
1270 L_tmpnam  = 20
1271 TMP_MAX   = 238328
1272 L_ctermid = 9
1273 L_cuserid = 9
1274 endif
1275 stdio_lim = $(common-objpfx)bits/stdio_lim.h
1277 $(stdio_lim:lim.h=%.h) $(stdio_lim:lim.h=%.d): $(stdio_lim:lim.h=%.st); @:
1278 $(stdio_lim:h=st): $(..)stdio-common/stdio_lim.h.in $(..)Rules \
1279                    $(common-objpfx)config.make
1280         $(make-target-directory)
1281         echo '#include "$(..)posix/bits/posix1_lim.h"' |                \
1282         SUNPRO_DEPENDENCIES='$(@:st=dT) $@'                             \
1283         $(CC) $(+includes) -E -dM -xc - -o $(@:st=hT)
1284         echo '#include "$(..)misc/sys/uio.h"' |                         \
1285         SUNPRO_DEPENDENCIES='$(@:st=dT) $@'                             \
1286         $(CC) -D_LIBC=1 $(+includes) -E -dM -xc - | cat - >> $(@:st=hT)
1287 ifdef sed-remove-objpfx
1288         sed $(sed-remove-objpfx) $(@:st=dT) > $(@:st=dt)
1289         cat $(@:st=dt) >> $(@:st=d)
1290 else
1291         cat $(@:st=dT) >> $(@:st=d)
1292 endif
1293         fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`;       \
1294         filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`;    \
1295         iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`;        \
1296         fopen_max=$${fopen_max:-16};                                    \
1297         filename_max=$${filename_max:-1024};                            \
1298         if [ -z $$iov_max ]; then                                       \
1299           define_iov_max="# undef IOV_MAX";                             \
1300         else                                                            \
1301           define_iov_max="# define IOV_MAX $$iov_max";                  \
1302         fi;                                                             \
1303         sed -e "s/@FOPEN_MAX@/$$fopen_max/"                             \
1304             -e "s/@FILENAME_MAX@/$$filename_max/"                       \
1305             -e "s/@L_tmpnam@/$(L_tmpnam)/"                              \
1306             -e "s/@TMP_MAX@/$(TMP_MAX)/"                                \
1307             -e "s/@L_ctermid@/$(L_ctermid)/"                            \
1308             -e "s/@L_cuserid@/$(L_cuserid)/"                            \
1309             -e "s/@define_IOV_MAX@/$$define_iov_max/"                   \
1310             $< > $(@:st=h.new)
1311         $(move-if-change) $(@:st=h.new) $(@:st=h)
1312 # Remove these last so that they can be examined if something went wrong.
1313         rm -f $(@:st=hT) $(@:st=dT) $(@:st=dt)
1314         touch $@
1315 # Get dependencies.
1316 ifndef no_deps
1317 -include $(stdio_lim:h=d)
1318 endif
1319 common-generated += bits/stdio_lim.h bits/stdio_lim.d bits/stdio_lim.st
1321 .PHONY: TAGS
1322 TAGS: $(objpfx)distinfo $(..)MakeTAGS
1323         $(MAKE) $(addprefix -f ,$^) $@
1325 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
1326         $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
1327 FORCE:
1330 .PHONY: echo-headers
1331 echo-headers:
1332         @echo $(headers)
1335 # Common cleaning targets.
1337 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1338 clean: common-clean
1339 mostlyclean: common-mostlyclean
1341 do-tests-clean:
1342         -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1343                                                       $(test-srcs)) \
1344                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1345                                                          $(test-srcs)))
1347 # Remove the object files.
1348 common-mostlyclean:
1349         -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1350                                      $(others) $(sysdep-others) stubs \
1351                                      $(addsuffix .o,$(tests) $(xtests) \
1352                                                     $(test-srcs) $(others) \
1353                                                     $(sysdep-others)) \
1354                                      $(addsuffix -bp,$(tests) $(xtests) \
1355                                                      $(test-srcs)) \
1356                                      $(addsuffix .out,$(tests) $(xtests) \
1357                                                       $(test-srcs)) \
1358                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1359                                                          $(test-srcs)))
1360         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
1361                                      $(install-lib.so) \
1362                                      $(install-lib.so:%.so=%_pic.a))
1363         -rm -f core
1364         -rm -f $(objpfx)rtld-*.os
1365         $(rmobjs)
1366 define rmobjs
1367 $(foreach o,$(object-suffixes-for-libc),
1368 -rm -f $(objpfx)stamp$o $(o-objects))
1369 endef
1371 # Also remove the dependencies and generated source files.
1372 common-clean: common-mostlyclean
1373         -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
1374         -rm -f $(objpfx)rtld-*.d
1375         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1376         -rm -f $(addprefix $(common-objpfx),$(common-generated))
1377         -rm -f $(objpfx)distinfo
1379 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1380 # for each function which is a stub.  We grovel over all the .d files
1381 # looking for references to <stub-tag.h>.  Then we grovel over each
1382 # referenced source file to see what stub function it defines.
1384 ifdef objpfx
1385 .PHONY: stubs # The parent Makefile calls this target.
1386 stubs: $(objpfx)stubs
1387 endif
1388 $(objpfx)stubs: $(+depfiles)
1389 # Use /dev/null since `...` might expand to empty.
1390         (s=`cd $(sysdep_dir) && $(PWD_P)`; \
1391          $(patsubst %/,cd % &&,$(objpfx)) \
1392          sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
1393           `sed -n -e 's@$(sysdep_dir)/@'"$$s"'/@g' \
1394                   -e 's@\$$(common-objpfx)@$(..)@g' -e 's@\$$(objpfx)@@g' \
1395                   -e '/:  *[^ ]/{s@^.*: *\([^ ]*\) .*$$@\1@; h; }' \
1396                   -e '/:$$/d' \
1397                   -e '/stub-tag\.h/{; g; p; }' \
1398                   $(patsubst $(objpfx)%,%,$^) /dev/null` \
1399              /dev/null) > $@T
1400         mv -f $@T $@
1402 # Make the distribution tar file.
1404 .PHONY: dist
1405 dist: $(objpfx)distinfo $(..)Make-dist
1406         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
1408 # Avoid depending on source files found in sysdeps dirs,
1409 # because the references affect implicit rule selection.
1410 dist: $(filter-out %.c %.S %.s,$(distribute))
1412 # We used to simply export all these variables, but that frequently made the
1413 # environment get too large.  Instead, we write all the information into
1414 # a generated makefile fragment `distinfo', and then include it with -f in
1415 # the sub-make that makes the distribution (above).
1416 $(objpfx)distinfo: Makefile $(..)Makerules \
1417                    $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
1418         $(make-target-directory)
1419         $(distinfo-vars)
1420         mv -f $@.new $@
1421 .PHONY: subdir_distinfo
1422 subdir_distinfo: $(objpfx)distinfo
1424 define distinfo-vars
1425 rm -f $@.new
1426 echo > $@.new 'subdir := $(subdir)'
1427 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
1428               headers sysdep_headers distribute dont_distribute generated \
1429               others tests xtests test-srcs extra-libs versioned \
1430               $(extra-libs:%=%-routines) \
1431               $(addprefix install-,lib lib.so data bin bin-script sbin others),
1432 echo >> $@.new '$(subdir)-$(var) := $($(var))'
1433 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
1434 endef
1436 ifneq (,$(strip $(gpl2lgpl)))
1437 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1438 # Snarf from the master source and frob the copying notice.
1439 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1440         sed -f $^ > $@-tmp
1441 # So I don't edit them by mistake.
1442         chmod a-w $@-tmp
1443         mv -f $@-tmp $@
1444 ifeq ($(with-cvs),yes)
1445         test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
1446 endif
1447 endif
1448 endif
1450 # Local Variables:
1451 # mode: makefile
1452 # End: