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