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