* sysdeps/i386/dl-machine.h (elf_machine_rela): Handle R_386_COPY.
[platform/upstream/glibc.git] / Makerules
1 # Copyright (C) 1991-1999,2000,01,02 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
3
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
8
9 # The GNU C Library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with the GNU C Library; if not, write to the Free
16 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 # 02111-1307 USA.
18
19 #
20 #       Common rules for making the GNU C library.  This file is included
21 #       by the top-level Makefile and by all subdirectory makefiles
22 #       (through Rules).
23 #
24 ifneq (,)
25 This makefile requires GNU Make.
26 endif
27
28 REQUIRED_MAKE_VERSION = 3.74
29 REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
30
31 ifneq ($(REQUIRED_MAKE_VERSION), \
32        $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
33 Wrong GNU Make version.  See above for the version needed.
34 endif
35
36
37 ifdef   subdir
38 ..      := ../
39 endif   # subdir
40
41 # If `sources' was defined by the parent makefile, undefine it so
42 # we will later get it from wildcard search in this directory.
43 ifneq   "$(findstring env,$(origin sources))" ""
44 sources :=
45 endif
46
47 oPATH := $(PATH)
48 PATH := this definition should take precedence over $(oPATH)
49 ifeq ($(PATH),$(oPATH))
50 You must not use the -e flag when building the GNU C library.
51 else
52 PATH := $(oPATH)
53 endif
54 \f
55 ifndef +included-Makeconfig
56 include $(..)Makeconfig
57 endif
58
59 # `configure' writes a definition of `config-sysdirs' in `config.make'.
60 sysdirs = $(strip $(full_config_sysdirs))
61
62 +sysdir_pfx = $(common-objpfx)
63
64 export sysdirs := $(sysdirs)
65
66 +sysdep_dirs := $(full_config_sysdirs)
67 ifdef objdir
68 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
69 endif
70
71 # Add -I switches to get the right sysdep directories.
72 # `+includes' in Makeconfig references $(+sysdep-includes).
73 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
74
75 # This variable is used in ``include $(o-iterator)'' after defining
76 # $(o-iterator-doit) to produce some desired rule using $o for the object
77 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
78 # is produced for each object suffix in use.
79 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
80 \f
81 # Include any system-specific makefiles.
82
83 # This is here so things in sysdep Makefiles can easily depend on foo.h as
84 # appropriate and not worry about where foo.h comes from, which may be
85 # system dependent and not known by that Makefile.
86 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
87                                       $(+sysdep_dirs) $(..)))
88
89 # The same is true for RPC source files.
90 vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
91                                       $(+sysdep_dirs) $(..)))
92
93 # Some sysdep makefiles use this to distinguish being included here from
94 # being included individually by a subdir makefile (hurd/Makefile needs this).
95 in-Makerules := yes
96
97 sysdep-makefiles := $(wildcard $(full_config_sysdirs:=/Makefile))
98 ifneq (,$(sysdep-makefiles))
99 include $(sysdep-makefiles)
100 endif
101
102
103 # Reorder before-compile so that mach things come first, and hurd things
104 # second, before all else.  The mach and hurd subdirectories have many
105 # generated header files which the much of rest of the library depends on,
106 # so it is best to build them first (and mach before hurd, at that).
107 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
108                            $(before-compile)) \
109                   $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
110                                $(before-compile))
111
112 # Even before that, we need abi-versions.h which is generated right here.
113 ifeq ($(versioning),yes)
114 ifndef avoid-generated
115 before-compile := $(common-objpfx)abi-versions.h $(before-compile)
116 $(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
117                                 $(common-objpfx)Versions.all
118         LC_ALL=C $(AWK) -v oldest_abi=$(oldest-abi) -f $^ > $@T
119         mv -f $@T $@
120
121 $(common-objpfx)%.latest: $(common-objpfx)abi-versions.h
122         sed -n '/ VERSION_$*_/{s/^.*_\([A-Z0-9_]*\).*$$/\1/;h;};$${g;p;}' \
123             $(common-objpfx)abi-versions.h > $@T
124         mv -f $@T $@
125 endif # avoid-generated
126 endif # $(versioning) = yes
127
128 # 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
137
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))
144
145 # Don't let any before-compile file be an intermediate and get removed.
146 ifdef before-compile
147 $(before-compile):
148 endif
149
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          cat $@.dT; rm -f $@.dT) > $@T
162         mv -f $@T $@
163 \f
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.
169
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.' > $@
178
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)
190
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)
197
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)
204
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)
216
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)
223
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
231
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
241
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              $(close-check-inhibit-asm) \
267              echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
268                   \$$(compile-command.c)";                                    \
269              echo "\$$(objpfx)rtld-%$$o: $$dir/%.c \$$(before-compile); \
270                   \$$(compile-command.c)";                                    \
271            done; \
272            $(open-check-inhibit-asm) \
273            echo "\$$(objpfx)%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
274                 \$$(make-dummy-dep)";                          \
275            echo "\$$(objpfx)rtld-%.d: $$dir/%.s \$$(common-objpfx)dummy.d; \
276                 \$$(make-dummy-dep)";                          \
277            echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
278                 \$$(+make-deps)";                                             \
279            echo "\$$(objpfx)rtld-%.d: $$dir/%.S \$$(before-compile); \
280                 \$$(+make-deps)";                                             \
281            $(close-check-inhibit-asm)   \
282            echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
283                 \$$(+make-deps)";                                             \
284            echo "\$$(objpfx)rtld-%.d: $$dir/%.c \$$(before-compile); \
285                 \$$(+make-deps)";                                             \
286            echo "\$$(objpfx)m_%.S: $$dir/s_%.S; \$$(+make-include-of-dep)";   \
287            echo "\$$(objpfx)m_%.c: $$dir/s_%.c; \$$(+make-include-of-dep)";   \
288          done;                                                                \
289          echo 'sysd-rules-done = t') > $@T
290         mv -f $@T $@
291
292 ifndef sysd-rules-done
293 # Don't do deps until this exists, because it provides rules to make the deps.
294 no_deps=t
295 endif
296
297 # This is used by the m_%.[Sc] pattern rules in sysd-rules.
298 define +make-include-of-dep
299 echo '#include <$<>' > $@T
300 mv -f $@T $@
301 endef
302
303 # Generate version maps, but wait until sysdep-subdirs is known
304 ifeq ($(sysd-sorted-done),t)
305 ifeq ($(versioning),yes)
306 -include $(common-objpfx)sysd-versions
307 $(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
308 common-generated += $(version-maps)
309 postclean-generated += sysd-versions Versions.all abi-versions.h \
310                        Versions.def.v.i Versions.def.v Versions.v.i Versions.v
311
312 ifndef avoid-generated
313 ifneq ($(sysd-versions-subdirs),$(all-subdirs) $(config-sysdirs))
314 sysd-versions-force = FORCE
315 FORCE:
316 endif
317 # See %.v/%.v.i implicit rules in Makeconfig.
318 $(common-objpfx)Versions.def.v.i: $(..)Versions.def \
319                                   $(wildcard $(add-ons:%=$(..)%/Versions.def))
320 $(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
321                               $(common-objpfx)soversions.i \
322                               $(common-objpfx)Versions.def.v
323         { while read lib version setname; do \
324             test -z "$$setname" || echo "$$lib : $$setname"; \
325           done < $(word 2,$^); \
326           cat $(word 3,$^); \
327         } | LC_ALL=C $(AWK) -f $< > $@T
328         mv -f $@T $@
329 # See %.v/%.v.i implicit rules in Makeconfig.
330 $(common-objpfx)Versions.v.i: $(wildcard $(all-subdirs:%=$(..)%/Versions)) \
331                               $(wildcard $(sysdirs:%=%/Versions)) \
332                               $(common-objpfx)abi-versions.h \
333                               $(sysd-versions-force)
334 $(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
335                                $(common-objpfx)Versions.v \
336                                $(..)scripts/versions.awk
337         ( echo 'sysd-versions-subdirs = $(all-subdirs) $(config-sysdirs)' ; \
338           cat $(word 2,$^) \
339           | LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
340                             -v move_if_change='$(move-if-change)' \
341                             -f $(word 3,$^); \
342         ) > $@T
343         mv -f $@T $@
344 endif # avoid-generated
345 endif # $(versioning) = yes
346 endif # sysd-sorted-done
347
348
349 ifndef compile-command.S
350 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
351 endif
352 ifndef compile-command.s
353 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
354 endif
355 ifndef compile-command.c
356 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
357 endif
358
359 # GCC can grok options after the file name, and it looks nicer that way.
360 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
361 compile.S = \
362   $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
363 COMPILE.S = \
364   $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) $(ASFLAGS-$(suffix $@))
365 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
366
367 # If we want to generate MD5 checksums for the sources do this now.
368 ifeq ($(md5),yes)
369 generate-md5 = ; rm -f $(@:.d=.md5); \
370 $(CC) -E $< $(CFLAGS) $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
371 sed '/^\#/d;/^[[:space:]]*$$/d' | md5sum > $(@:.d=.md5)
372 else
373 generate-md5 =
374 endif
375
376 # We need this for the output to go in the right place.  It will default to
377 # empty if make was configured to work with a cc that can't grok -c and -o
378 # together.  You can't compile the C library with such a compiler.
379 OUTPUT_OPTION = -o $@
380
381 # We need the $(CFLAGS) to be in there to have the right predefines during
382 # the dependency run for C sources.  But having it for assembly sources can
383 # get the wrong predefines.
384 S-CPPFLAGS = $(asm-CPPFLAGS)
385 define +make-deps
386 $(make-target-directory)
387 $(+mkdep) $< $(if $(filter %.c,$<),$(CFLAGS)) \
388              $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | sed \
389 -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(all-object-suffixes),$(@:.d=$o)) $@,' \
390 $(sed-remove-objpfx) > $(@:.d=.T)
391 mv -f $(@:.d=.T) $@ $(generate-md5)
392 endef
393 ifneq (,$(objpfx))
394 # Continuation lines here are dangerous because they introduce spaces!
395 define sed-remove-objpfx
396 -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
397 -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g'
398 endef
399 endif
400 \f
401 # Modify the list of routines we build for different targets
402
403 ifeq (yesyes,$(build-shared)$(elf))
404 ifndef libc.so-version
405 # Undefine this because it can't work when we libc.so is unversioned.
406 static-only-routines =
407 endif
408 endif
409
410 # Bounded pointer thunks are only built for *.ob
411 elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
412
413 elide-routines.oS += $(filter-out $(static-only-routines),\
414                                   $(routines) $(aux) $(sysdep_routines)) \
415                      $(elide-bp-thunks)
416 elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
417
418 # If we have versioned code we don't need the old versions in any of the
419 # static libraries.
420 elide-routines.o  += $(shared-only-routines) $(elide-bp-thunks)
421 elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
422 elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
423 elide-routines.ob += $(shared-only-routines)
424 \f
425 # Shared library building.
426
427 ifeq (yes,$(build-shared))
428
429 # Reference map file only when versioning is selected and a map file name
430 # is given.
431 ifeq ($(versioning),yes)
432 map-file = $(firstword $($(@F:.so=-map)) \
433                        $(addprefix $(common-objpfx), \
434                                    $(filter $(@F:.so=.map),$(version-maps))))
435 load-map-file = $(map-file:%=-Wl,--version-script=%)
436 endif
437
438 # Pattern rule to build a shared object from an archive of PIC objects.
439 # This must come after the installation rules so Make doesn't try to
440 # build shared libraries in place from the installed *_pic.a files.
441 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
442 # on other shared objects.
443 lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
444 ifneq (,$(findstring aix,$(config-os)))
445         (echo '#!'; \
446          dump -g $< | sed '1,6d' | cut -f2 | sort | uniq) > $(<:a=exp)
447 endif
448         $(build-shlib)
449
450 ifeq ($(elf),yes)
451 define build-shlib-helper
452 $(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) $(config-LDFLAGS) \
453           $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
454           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
455           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
456           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
457           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
458 endef
459 else
460 ifneq (,$(findstring aix,$(config-os)))
461 define build-shlib-helper
462 $(LINK.o) -Wl,-G,-bM:SRE,-bnoentry,-bE:$(<:a=exp) \
463           $(sysdep-LDFLAGS) $(config-LDFLAGS) $(extra-B-$(@F:lib%.so=%).so) \
464           $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
465           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
466           -L$(subst :, -L,$(rpath-link))
467 endef
468 else
469 endif
470 endif
471
472 ifeq (yes,$(elf))
473 # binutils only position loadable notes into the first page for binaries,
474 # not for shared objects
475 define build-shlib
476 $(build-shlib-helper) \
477           -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
478           $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
479           sed -e '/^=========/,/^=========/!d;/^=========/d' \
480               -e 's/^.*\.hash[  ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
481               $(LDSEDCMD-$(@F:lib%.so=%).so) > $@.lds
482 rm -f $@.new
483 $(build-shlib-helper) -o $@ -T $@.lds \
484           $(csu-objpfx)abi-note.o $(build-shlib-objlist)
485 rm -f $@.lds
486 endef
487 else
488 ifneq (,$(findstring aix,$(config-os)))
489 define build-shlib
490 $(build-shlib-helper) \
491         -o $@ \
492         $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
493         $(no-whole-archive) $(LDLIBS-$(@F:lib%.so=%).so)
494 endef
495 define build-shlib
496 $(build-shlib-helper) \
497           $(build-shlib-objlist)
498 endef
499 endif
500 endif
501
502 ifneq (,$(findstring aix,$(config-os)))
503 define build-module-helper
504 $(LINK.o) -Wl,-G -Wl,-bM:SRE -Wl,-bnoentry -Wl,-bexpall \
505           $(sysdep-LDFLAGS) $(config-LDFLAGS) \
506           $(load-map-file) \
507           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
508           -L$(subst :, -L,$(rpath-link)) -Wl,-L=$(rpath-link)
509 endef
510 else
511 define build-module-helper
512 $(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
513           -B$(csu-objpfx) $(load-map-file) \
514           $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
515           -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
516 endef
517 endif
518
519 # This macro is similar to build-shlib but it does not define a soname
520 # and it does not depend on the destination name to start with `lib'.
521 ifeq (yes,$(elf))
522 # binutils only position loadable notes into the first page for binaries,
523 # not for shared objects
524 define build-module
525 $(build-module-helper) \
526           -o $@.new $(csu-objpfx)abi-note.o -Wl,--verbose \
527           $(LDLIBS-$(@F:lib%.so=%).so) 2>&1 | \
528           sed -e '/^=========/,/^=========/!d;/^=========/d' \
529               -e 's/^.*\.hash[  ]*:.*$$/  .note.ABI-tag : { *(.note.ABI-tag) } &/' \
530           > $@.lds
531 rm -f $@.new
532 $(build-module-helper) -o $@ -T $@.lds \
533           $(csu-objpfx)abi-note.o $(build-module-objlist)
534 rm -f $@.lds
535 endef
536 else
537 ifneq (,$(findstring aix,$(config-os)))
538 define build-module
539 $(build-module-helper) \
540           -o $@ \
541           $(filter-out $(map-file) $(+preinit) $(+postinit),$^) \
542           $(no-whole-archive) $(LDLIBS-$(@F:%.so=%).so)
543 endef
544 else
545 define build-module
546 define build-module
547 $(build-module-helper) \
548           -o $@ \
549           $(build-module-objlist)
550 endef
551 endif
552 endif
553
554 build-module-helper-objlist = \
555         $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
556                    $(filter-out $(map-file) $(+preinit) $(+postinit),$^))
557 whole-archive := -Wl,--whole-archive
558
559 build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
560 build-shlib-objlist = $(build-module-helper-objlist) \
561                       $(LDLIBS-$(@F:lib%.so=%).so)
562
563 # Don't try to use -lc when making libc.so itself.
564 # Also omits crti.o and crtn.o, which we do not want
565 # since we define our own `.init' section specially.
566 LDFLAGS-c.so = -nostdlib -nostartfiles
567 # But we still want to link libc.so against $(gnulib).
568 LDLIBS-c.so += $(gnulib)
569 # Give libc.so an entry point and make it directly runnable itself.
570 LDFLAGS-c.so += -e __libc_main
571 # Force the backward compatibility EH functions to be linked.
572 LDFLAGS-c.so += -u __register_frame
573 # Pre-link the objects of libc_pic.a so that we can locally resolve
574 # COMMON symbols before we link against ld.so.  This is because ld.so
575 # contains some of libc_pic.a already, which will prevent the COMMONs
576 # from being allocated in libc.so, which introduces evil dependencies
577 # between libc.so and ld.so, which can make it impossible to upgrade.
578 ifeq ($(elf),yes)
579 $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
580         $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
581         $(LDFLAGS-c_pic.os) -Wl,-d -Wl,--whole-archive $^
582 LDSEDCMD-c.so = -e 's/^.*\*(\.dynbss).*$$/& __start___libc_freeres_ptrs = .; *(__libc_freeres_ptrs) __stop___libc_freeres_ptrs = .;/'
583 # Use our own special initializer and finalizer files for libc.so.
584 $(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
585                          $(common-objpfx)libc_pic.os \
586                          $(elfobjdir)/sofini.os \
587                          $(elfobjdir)/interp.os $(elfobjdir)/ld.so
588         $(build-shlib)
589 ifeq ($(versioning),yes)
590 $(common-objpfx)libc.so: $(common-objpfx)libc.map
591 endif
592 common-generated += libc.so libc_pic.os
593 ifdef libc.so-version
594 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
595         $(make-link)
596 common-generated += libc.so$(libc.so-version)
597 endif
598 endif
599 else
600 ifneq (,$(findstring aix,$(config-os)))
601 $(common-objpfx)libc.so: $(common-objpfx)libc_pic.a
602         @rm -f $@
603         (echo '#!'; \
604          dump -g $^ | sed '1,6d' | cut -f2 | sort | uniq) > $(^:a=exp)
605         sed '/__mulh/d;/__mull/d;/__divss/d;/__divus/d;/__quoss/d;/__quous/d' \
606             /lib/syscalls.exp > $(common-objpfx)syscalls.exp
607         $(LINK.o) -G -bM:SRE -bnoentry -bE:$(^:a=exp) \
608                   -bE:$(common-objpfx)syscalls.exp \
609                   -bI:$(common-objpfx)syscalls.exp \
610                   -L$(common-objpfx) -o $@ $^
611 # AIX runtime ld wants libc.so to be libc.a(shr.o) hardwired
612         cp $@ $(common-objpfx)shr.o
613         $(AR) $(ARFLAGS) $(common-objpfx)libc.a $(common-objpfx)shr.o
614 endif
615 endif
616 \f
617 # Figure out the source filenames in this directory.
618
619 override sources := $(addsuffix .c,\
620                         $(filter-out $(elided-routines),\
621                             $(routines) $(aux) \
622                             $(sysdep_routines)))
623 sysdep_routines := $(sysdep_routines)
624
625 headers := $(headers) $(sysdep_headers)
626
627 # This is the list of all object files, gotten by
628 # replacing every ".c" in `sources' with a ".o".
629 # We also add bounded-pointer thunks, which are later
630 # elided for all suffixes except for `.ob'.
631 override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
632                       $(patsubst %,$(bppfx)%.o,\
633                         $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
634
635
636 # The makefile may define $(extra-libs) with `libfoo libbar'
637 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
638 ifdef extra-libs
639 # extra-lib.mk is included once for each extra lib to define rules
640 # to build it, and to add its objects to the various variables.
641 # During its evaluation, $(lib) is set to the name of the library.
642 extra-libs-left := $(extra-libs)
643 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
644 endif
645 \f
646 +depfiles := $(sources:.c=.d) \
647              $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
648              $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
649 ifeq ($(build-programs),yes)
650 +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
651 endif
652 +depfiles := $(addprefix $(objpfx),\
653                          $(filter-out $(addsuffix .d,$(omit-deps)),\
654                                       $(+depfiles)))
655
656 ifdef +depfiles
657 ifneq ($(no_deps),t)
658 -include $(+depfiles)
659 endif
660 endif
661 \f\f
662 # Maximize efficiency by minimizing the number of rules.
663 .SUFFIXES:      # Clear the suffix list.  We don't use suffix rules.
664 # Don't define any builtin rules.
665 MAKEFLAGS := $(MAKEFLAGS)r
666
667 # Generic rule for making directories.
668 %/:
669 # mkdir isn't smart enough to strip a trailing /.
670         mkdir $(@:%/=%)
671 \f
672 # Make sure that object files are not removed
673 # when they are intermediates between sources and library members.
674 .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
675
676 # Make sure that the parent library archive is never removed.
677 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
678 \f
679 # Use the verbose option of ar and tar when not running silently.
680 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
681 verbose := v
682 else                                            # -s
683 verbose :=
684 endif                                           # not -s
685
686 ARFLAGS := r$(verbose)
687 CREATE_ARFLAGS := cru$(verbose)
688 \f
689 # This makes all the object files in the parent library archive.
690
691 .PHONY: lib lib-noranlib
692 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
693 lib-noranlib: libobjs
694
695 # For object-suffix $o, the list of objects with that suffix.
696 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
697 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
698                                                        $(elide-routines$o)),\
699                                             $(objects))) \
700             $(addprefix $(objpfx),$(o-objects$o))
701
702 others: $(addprefix $(objpfx),$(install-lib))
703
704 ifndef objects
705
706 # Create the stamp$o files to keep the parent makefile happy.
707 subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
708 $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
709         $(make-target-directory)
710         rm -f $@; > $@
711 else
712
713 # Define explicit rules to update each $(objpfx)stamp.SUFFIX
714 # timestamp file; these rules (one explicit rule is generated for each
715 # object suffix) write a list of objects to update in the stamp file.
716 # The parent will then actually add them all to the archive in the
717 # archive rule, below.
718 define o-iterator-doit
719 $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
720 endef
721 define do-stamp
722 echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
723 mv -f $@T $@
724 endef
725 object-suffixes-left := $(object-suffixes-for-libc)
726 include $(o-iterator)
727
728 endif
729
730 # Now define explicit rules to build the library archives; these depend
731 # on the stamp files built above.
732 define o-iterator-doit
733 $(common-objpfx)$(patsubst %,$(libtype$o),c): \
734                 $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
735 endef
736 define do-makelib
737 cd $(common-objdir) && \
738 $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
739 $(RANLIB) $@
740 endef
741 subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
742 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
743 ifndef subdir
744 $(subdirs-stamps): subdir_lib;
745 endif
746 object-suffixes-left = $(object-suffixes-for-libc)
747 include $(o-iterator)
748
749
750 # This makes all the object files.
751 .PHONY: objects objs libobjs extra-objs
752 objects objs: libobjs extra-objs
753 libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
754 extra-objs: $(addprefix $(objpfx),$(extra-objs))
755
756 # Canned sequence for building an extra library archive.
757 define build-extra-lib
758 $(patsubst %/,cd % &&,$(objpfx)) \
759 $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
760       $(patsubst $(objpfx)%,%,$^)
761 $(RANLIB) $@
762 endef
763 \f
764 # Installation.
765
766 .PHONY: force-install
767 force-install:
768
769 # $(install-lib) are installed from the object directory into $(libdir);
770 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
771 # unless they also appear in $(non-lib.a).  $(install-data) are installed
772 # as they are into $(datadir).  $(headers) are installed as they are in
773 # $(includedir).  $(install-bin), $(install-bin-script) and $(install-sbin)
774 # are installed from the object directory into $(bindir), $(bindir) and
775 # $(sbindir), respectively.  $(install-others) are absolute path names of
776 # files to install; rules to install them are defined elsewhere.
777
778 # The simple library name to install libc.a under.
779 # This could be defined by a sysdep Makefile.
780 ifndef libc-name
781 libc-name := c
782 endif
783
784 define do-install
785 $(make-target-directory)
786 $(INSTALL_DATA) $< $@
787 endef
788
789 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
790 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
791 define make-target-directory
792 $(addprefix $(..)./scripts/mkinstalldirs ,\
793             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
794 endef
795
796 # Any directory (parent or subdir) should install libc.a; this way
797 # "make install" in a subdir is guaranteed to install everything it changes.
798 installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
799                              $(inst_libdir)/$(patsubst %,$(libtype$o),\
800                                                      $(libprefix)$(libc-name)))
801 install: $(installed-libcs)
802 $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
803         $(make-target-directory)
804         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
805 # Running ranlib after installing makes the __.SYMDEF time stamp up to
806 # date, which avoids messages from some linkers.
807         $(RANLIB) $@
808
809 define do-install-program
810 $(make-target-directory)
811 $(INSTALL_PROGRAM) $< $@.new
812 mv -f $@.new $@
813 endef
814
815 define do-install-script
816 $(make-target-directory)
817 $(INSTALL_SCRIPT) $< $@.new
818 mv -f $@.new $@
819 endef
820
821 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
822 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
823
824 ifeq (yes,$(build-shared))
825 # Find which .so's have versions.
826 versioned := $(strip $(foreach so,$(install-lib.so),\
827                                $(patsubst %,$(so),$($(so)-version))))
828
829 install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
830 install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
831
832 install-lib-nosubdir: $(install-lib.so-versioned:%=$(inst_libdir)/%) \
833                       $(install-lib.so-unversioned:%=$(inst_slibdir)/%)
834
835 # Install all the unversioned shared libraries.
836 $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
837     $(objpfx)%.so $(+force)
838         $(do-install-program)
839
840 ifneq ($(findstring -s,$(LN_S)),)
841 define make-link
842 rm -f $@.new
843 $(SHELL) $(..)scripts/rellns-sh $< $@.new
844 mv -f $@.new $@
845 endef
846 else
847 # If we have no symbolic links don't bother with rellns-sh.
848 define make-link
849 rm -f $@.new
850 $(LN_S) $< $@.new
851 mv -f $@.new $@
852 endef
853 endif
854
855 ifeq (yes,$(build-shared))
856 ifeq (no,$(cross-compiling))
857 symbolic-link-prog := $(common-objpfx)elf/sln
858 symbolic-link-list := $(common-objpfx)elf/symlink.list
859 define make-shlib-link
860 echo $(<F) $@ >> $(symbolic-link-list)
861 endef
862 else # cross-compiling
863 # We need a definition that can be used by elf/Makefile's install rules.
864 symbolic-link-prog = $(LN_S)
865 endif
866 endif
867 ifndef make-shlib-link
868 define make-shlib-link
869 rm -f $@
870 $(LN_S) $(<F) $@
871 endef
872 endif
873
874 ifdef libc.so-version
875 # For a library specified to be version N, install three files:
876 # libc.so       ->      libc.so.N       (e.g. libc.so.6)
877 # libc.so.6     ->      libc-VERSION.so (e.g. libc-1.10.so)
878
879 $(inst_slibdir)/libc.so$(libc.so-version): $(inst_slibdir)/libc-$(version).so \
880                                            $(+force)
881         $(make-shlib-link)
882 $(inst_slibdir)/libc-$(version).so: $(common-objpfx)libc.so $(+force)
883         $(do-install-program)
884 install: $(inst_slibdir)/libc.so$(libc.so-version)
885
886 ifndef subdir
887 # What we install as libc.so for programs to link against is in fact a
888 # link script.  It contains references for the various libraries we need.
889 # The libc.so object is not complete since some functions are only defined
890 # in libc_nonshared.a.
891 # We need to use absolute paths since otherwise local copies (if they exist)
892 # of the files are taken by the linker.
893 install: $(inst_libdir)/libc.so
894 $(inst_libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
895                         $(inst_libdir)/$(patsubst %,$(libtype.oS),\
896                                                   $(libprefix)$(libc-name)) \
897                         $(+force)
898         (echo '/* GNU ld script';\
899          echo '   Use the shared library, but some functions are only in';\
900          echo '   the static library, so try that secondarily.  */';\
901          echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
902               '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
903               ')' \
904         ) > $@.new
905         mv -f $@.new $@
906
907 endif
908
909 else
910 install: $(inst_slibdir)/libc.so
911 $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
912         $(do-install-program)
913 endif
914
915 ifneq (,$(versioned))
916 # Produce three sets of rules as above for all the smaller versioned libraries.
917
918 define o-iterator-doit
919 $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
920 endef
921 object-suffixes-left := $(versioned)
922 include $(o-iterator)
923
924 # Make symlinks in the build directory, because the versioned names might
925 # be referenced by a DT_NEEDED in another library.
926 define o-iterator-doit
927 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
928 endef
929 object-suffixes-left := $(versioned)
930 include $(o-iterator)
931
932 generated += $(foreach o,$(versioned),$o$($o-version))
933
934 ifeq (,$($(subdir)-version))
935 define o-iterator-doit
936 $(inst_slibdir)/$o$($o-version): $(inst_slibdir)/$(o:.so=)-$(version).so \
937                                  $(+force);
938         $$(make-shlib-link)
939 endef
940 object-suffixes-left := $(versioned)
941 include $(o-iterator)
942
943 define o-iterator-doit
944 $(inst_slibdir)/$(o:.so=)-$(version).so: $(objpfx)$o $(+force);
945         $$(do-install-program)
946 endef
947 object-suffixes-left := $(versioned)
948 include $(o-iterator)
949 else
950 define o-iterator-doit
951 $(inst_slibdir)/$o$($o-version): \
952   $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so $(+force);
953         $$(make-shlib-link)
954 endef
955 object-suffixes-left := $(versioned)
956 include $(o-iterator)
957
958 define o-iterator-doit
959 $(inst_slibdir)/$(o:.so=)-$($(subdir)-version).so: $(objpfx)$o $(+force);
960         $$(do-install-program)
961 endef
962 object-suffixes-left := $(versioned)
963 include $(o-iterator)
964 endif
965 endif
966
967 define do-install-so
968 $(do-install-program)
969 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
970            $(filter-out %.so,$@))
971 endef
972
973 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
974 $(foreach v,$(so-versions),\
975           $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
976                                                $(+force)
977         $(do-install-so)
978 $(foreach v,$(so-versions),\
979           $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
980         $(do-install-so)
981 endif
982
983 ifdef install-bin
984 $(addprefix $(inst_bindir)/,$(install-bin)): \
985     $(inst_bindir)/%: $(objpfx)% $(+force)
986         $(do-install-program)
987 endif
988 ifdef install-bin-script
989 $(addprefix $(inst_bindir)/,$(install-bin-script)): \
990     $(inst_bindir)/%: $(objpfx)% $(+force)
991         $(do-install-script)
992 endif
993 ifdef install-rootsbin
994 $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
995    $(inst_rootsbindir)/%: $(objpfx)% $(+force)
996         $(do-install-program)
997 endif
998 ifdef install-sbin
999 $(addprefix $(inst_sbindir)/,$(install-sbin)): \
1000     $(inst_sbindir)/%: $(objpfx)% $(+force)
1001         $(do-install-program)
1002 endif
1003 ifdef install-lib
1004 install-lib.a := $(filter lib%.a,$(install-lib))
1005 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
1006 ifdef install-lib-non.a
1007 $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
1008   $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
1009         $(do-install)
1010 endif
1011 ifdef install-lib.a
1012 $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
1013   $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
1014         $(do-install)
1015         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
1016 endif
1017 endif
1018 ifdef install-data
1019 $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
1020         $(do-install)
1021 endif
1022 headers := $(strip $(headers))
1023 ifdef headers
1024 $(addprefix $(inst_includedir)/,$(headers)): $(inst_includedir)/%: % $(+force)
1025         $(do-install)
1026 endif   # headers
1027
1028 .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
1029         install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
1030         install-data-nosubdir install-headers-nosubdir
1031 install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
1032 install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
1033 install-rootsbin-nosubdir: \
1034         $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
1035 install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
1036 install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
1037                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
1038                        $(addprefix $(libprefix),$(install-lib-non.a)))
1039 install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
1040 install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
1041 install-others-nosubdir: $(install-others)
1042
1043 # We need all the `-nosubdir' targets so that `install' in the parent
1044 # doesn't depend on several things which each iterate over the subdirs.
1045 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
1046 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
1047 install-%:: install-%-nosubdir ;
1048
1049 .PHONY: install install-no-libc.a-nosubdir
1050 ifeq ($(build-programs),yes)
1051 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1052                             install-bin-nosubdir install-bin-script-nosubdir \
1053                             install-lib-nosubdir install-others-nosubdir \
1054                             install-rootsbin-nosubdir install-sbin-nosubdir
1055 else
1056 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
1057                             install-lib-nosubdir install-others-nosubdir
1058 endif
1059 install: install-no-libc.a-nosubdir
1060 \f
1061 # Command to compile $< in $(objdir) using the native libraries.
1062 define native-compile
1063 $(make-target-directory)
1064 $(patsubst %/,cd % &&,$(objpfx)) \
1065 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1066             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
1067 endef
1068
1069 # Command to compile $< in $(common-objdir) using the native libraries.
1070 # We must cd to $(objdir) anyway so that $(..)config.h is valid.
1071 define common-objdir-compile
1072 $(patsubst %/,cd % &&,$(objpfx)) \
1073 $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
1074             $(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(..)$(@F)
1075 endef
1076
1077 # We always want to use configuration definitions.
1078 # Note that this is only used for commands running in $(objpfx).
1079 ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) -include $(..)config.h
1080
1081 # Support the GNU standard name for this target.
1082 .PHONY: check
1083 check: tests
1084 # Special target to run tests which cannot be run unconditionally.
1085 # Maintainers should use this target.
1086 .PHONY: xcheck
1087 xcheck: xtests
1088
1089 all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
1090 ifneq (,$(all-nonlib))
1091 cpp-srcs-left = $(all-nonlib:=.c)
1092 lib := nonlib
1093 include $(patsubst %,$(..)cppflags-iterator.mk,$(all-nonlib))
1094 endif
1095
1096 # The include magic above causes those files to use this variable for flags.
1097 CPPFLAGS-nonlib = -DNOT_IN_libc=1
1098
1099
1100 ifeq ($(versioning),yes)
1101 # Generate normalized lists of symbols, versions, and data sizes.
1102 # This is handy for checking against existing library binaries.
1103
1104 %.symlist: $(..)scripts/abilist.awk %.dynsym
1105         $(AWK) -f $^ > $@T
1106         mv -f $@T $@
1107
1108 %.dynsym: %.so
1109         $(OBJDUMP) --dynamic-syms $< > $@T
1110         mv -f $@T $@
1111
1112 tests: $(patsubst %.so,$(objpfx)%.symlist,$(install-lib.so-versioned))
1113 generated += $(install-lib.so-versioned:.so=.symlist)
1114
1115 ifeq ($(subdir),elf)
1116 tests: $(common-objpfx)libc.symlist
1117 common-generated += libc.symlist
1118 endif
1119 endif
1120 \f
1121 .PHONY: TAGS
1122 TAGS: $(objpfx)distinfo $(..)MakeTAGS
1123         $(MAKE) $(addprefix -f ,$^) $@
1124
1125 $(..)po/%.pot: $(objpfx)distinfo $(..)MakeTAGS FORCE
1126         $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
1127 FORCE:
1128
1129
1130 .PHONY: echo-headers
1131 echo-headers:
1132         @echo $(headers)
1133
1134 \f
1135 # Common cleaning targets.
1136
1137 .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
1138 clean: common-clean
1139 mostlyclean: common-mostlyclean
1140
1141 do-tests-clean:
1142         -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
1143                                                       $(test-srcs)) \
1144                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1145                                                          $(test-srcs)))
1146
1147 # Remove the object files.
1148 common-mostlyclean:
1149         -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
1150                                      $(others) $(sysdep-others) stubs \
1151                                      $(addsuffix .o,$(tests) $(xtests) \
1152                                                     $(test-srcs) $(others) \
1153                                                     $(sysdep-others)) \
1154                                      $(addsuffix -bp,$(tests) $(xtests) \
1155                                                      $(test-srcs)) \
1156                                      $(addsuffix .out,$(tests) $(xtests) \
1157                                                       $(test-srcs)) \
1158                                      $(addsuffix -bp.out,$(tests) $(xtests) \
1159                                                          $(test-srcs)))
1160         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib) \
1161                                      $(install-lib.so) \
1162                                      $(install-lib.so:%.so=%_pic.a))
1163         -rm -f core
1164         -rm -f $(objpfx)rtld-*.os
1165         $(rmobjs)
1166 define rmobjs
1167 $(foreach o,$(object-suffixes-for-libc),
1168 -rm -f $(objpfx)stamp$o $(o-objects))
1169 endef
1170
1171 # Also remove the dependencies and generated source files.
1172 common-clean: common-mostlyclean
1173         -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
1174         -rm -f $(objpfx)rtld-*.d
1175         -rm -fr $(addprefix $(objpfx),$(generated-dirs))
1176         -rm -f $(addprefix $(common-objpfx),$(common-generated))
1177         -rm -f $(objpfx)distinfo
1178 \f
1179 # Produce a file `stubs' which contains `#define __stub_FUNCTION'
1180 # for each function which is a stub.  We grovel over all the .d files
1181 # looking for references to <stub-tag.h>.  Then we grovel over each
1182 # referenced source file to see what stub function it defines.
1183
1184 ifdef objpfx
1185 .PHONY: stubs # The parent Makefile calls this target.
1186 stubs: $(objpfx)stubs
1187 endif
1188 s = $(sysdep_dir)/generic
1189 $(objpfx)stubs: $(+depfiles)
1190 # Use /dev/null since `...` might expand to empty.
1191         (s=`cd $s && $(PWD_P)`; \
1192          $(patsubst %/,cd % &&,$(objpfx)) \
1193          sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
1194           `sed -n -e '\@ $s/[^ ]*\.c@{; s@^.* $s/\([^ ]*\.c\).*$$@'"$$s"'/\1@; h; }' \
1195                 -e '/stub-tag\.h/{; g; p; }' \
1196                   $(patsubst $(objpfx)%,%,$^) /dev/null` \
1197              /dev/null) > $@T
1198         mv -f $@T $@
1199 \f
1200 # Make the distribution tar file.
1201
1202 .PHONY: dist
1203 dist: $(objpfx)distinfo $(..)Make-dist
1204         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
1205
1206 # Avoid depending on source files found in sysdeps dirs,
1207 # because the references affect implicit rule selection.
1208 dist: $(filter-out %.c %.S %.s,$(distribute))
1209
1210 # We used to simply export all these variables, but that frequently made the
1211 # environment get too large.  Instead, we write all the information into
1212 # a generated makefile fragment `distinfo', and then include it with -f in
1213 # the sub-make that makes the distribution (above).
1214 $(objpfx)distinfo: Makefile $(..)Makerules \
1215                    $(wildcard $(foreach dir,$(sysdirs),$(dir)/Makefile))
1216         $(make-target-directory)
1217         $(distinfo-vars)
1218         mv -f $@.new $@
1219 .PHONY: subdir_distinfo
1220 subdir_distinfo: $(objpfx)distinfo
1221
1222 define distinfo-vars
1223 rm -f $@.new
1224 echo > $@.new 'subdir := $(subdir)'
1225 $(foreach var,subdir-dirs sources elided-routines sysdep_routines \
1226               headers sysdep_headers distribute dont_distribute generated \
1227               others tests xtests test-srcs extra-libs versioned \
1228               $(extra-libs:%=%-routines) \
1229               $(addprefix install-,lib lib.so data bin bin-script sbin others),
1230 echo >> $@.new '$(subdir)-$(var) := $($(var))'
1231 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
1232 endef
1233 \f
1234 ifneq (,$(strip $(gpl2lgpl)))
1235 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
1236 # Snarf from the master source and frob the copying notice.
1237 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
1238         sed -f $^ > $@-tmp
1239 # So I don't edit them by mistake.
1240         chmod a-w $@-tmp
1241         mv -f $@-tmp $@
1242 ifeq ($(with-cvs),yes)
1243         test ! -d CVS || cvs $(CVSOPTS) commit -m'Updated from $^' $@
1244 endif
1245 endif
1246 endif
1247
1248 # Local Variables:
1249 # mode: makefile
1250 # End: