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