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