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