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