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