Thu Jan 18 00:32:43 1996 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
[glibc.git] / Makerules
blob0013b539930b05c98d9206565ac0c7015760bc10
1 # Copyright (C) 1991, 92, 93, 94, 95, 96 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 Library General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # 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 # Library General Public License for more details.
14 # You should have received a copy of the GNU Library General Public
15 # License along with the GNU C Library; see the file COPYING.LIB.  If
16 # not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 # Cambridge, MA 02139, 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
29 ifdef   subdir
30 ..      := ../
31 endif   # subdir
33 # If `sources' was defined by the parent makefile, undefine it so
34 # we will later get it from wildcard search in this directory.
35 ifneq   "$(findstring env,$(origin sources))" ""
36 sources :=
37 endif
39 headers := $(headers) $(sysdep_headers)
41 oPATH := $(PATH)
42 PATH := this definition should take precedence over $(oPATH)
43 ifeq ($(PATH),$(oPATH))
44 You must not use the -e flag when building the GNU C library.
45 else
46 PATH := $(oPATH)
47 endif
49 ifndef +included-Makeconfig
50 include $(..)Makeconfig
51 endif
53 # `configure' writes a definition of `config-sysdirs' in `config.make'.
54 sysdirs = $(config-sysdirs)
56 +sysdir_pfx = $(common-objpfx)
58 export sysdirs := $(sysdirs)
60 +sysdep_dirs := $(addprefix $(sysdep_dir)/,$(sysdirs))
61 ifdef objdir
62 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
63 endif
65 # Add -I switches to get the right sysdep directories.
66 # `+includes' in Makeconfig references $(+sysdep-includes).
67 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
69 # Include any system-specific makefiles.
71 # This is here so things in sysdep Makefiles can easily depend on foo.h as
72 # appropriate and not worry about where foo.h comes from, which may be
73 # system dependent and not known by that Makefile.
74 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) \
75                                       $(addprefix $(sysdep_dir)/,$(sysdirs)) \
76                                       $(..)))
78 # Some sysdep makefiles use this to distinguish being included here from
79 # being included individually by a subdir makefile (hurd/Makefile needs this).
80 in-Makerules := yes
82 ifndef avoid-generated
83 include $(+sysdir_pfx)sysd-Makefile
84 ifneq ($(sysd-Makefile-sysdirs),$(sysdirs))
85 sysd-Makefile-force = FORCE
86 FORCE:
87 endif
88 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \
89                              $(sysd-Makefile-force)
90         -@rm -f $@T
91         (echo 'sysd-Makefile-sysdirs := $(sysdirs)';                          \
92          for dir in $(sysdirs); do                                            \
93            file=sysdeps/$$dir/Makefile;                                       \
94            if [ -f $(..)$$file ]; then                                        \
95              echo include "\$$(..)$$file";                                    \
96            else true; fi;                                                     \
97          done; \
98          echo 'sysd-Makefile-done=t') > $@T
99         mv -f $@T $@
100 endif
102 ifndef sysd-Makefile-done
103 # Don't do deps until this exists, because it might change the sources list.
104 no_deps=t
105 endif
108 # Reorder before-compile so that mach things come first, and hurd things
109 # second, before all else.  The mach and hurd subdirectories have many
110 # generated header files which the much of rest of the library depends on,
111 # so it is best to build them first (and mach before hurd, at that).
112 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
113                            $(before-compile)) \
114                   $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
115                                $(before-compile))
117 # Remove existing files from `before-compile'.  Things are added there when
118 # they must exist for dependency generation to work right, but once they
119 # exist there is no further need for every single file to depend on them,
120 # and those gratuitous dependencies result in many gratuitous
121 # recompilations.
122 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
124 # Don't let any before-compile file be an intermediate and get removed.
125 ifdef before-compile
126 $(before-compile):
127 endif
129 # Generate an ordered list of implicit rules which find the source files in
130 # each sysdep directory.  The old method was to use vpath to search all the
131 # sysdep directories.  However, that had the problem that a .S file in a
132 # later directory would be chosen over a .c file in an earlier directory,
133 # which does not preserve the desired sysdeps ordering behavior.
135 # When making the list of .d files to include, we can't know which ones
136 # have source in .s files, and thus do not in fact need a .d file.
137 # So we must define rules to make .d files for .s files.
138 define make-dummy-dep
139 $(addprefix ln $(objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
140 endef
141 $(objpfx)dummy.d:
142         echo '# .s files cannot contain includes, so they need no deps.' > $@
144 # It matters that this set of rules, for compiling from sources in
145 # the current directory (the $srcdir/$subdir) come before the
146 # generated sysdep rules in included from sysd-rules below.  When
147 # compiling in the source tree, generated sources go into the current
148 # directory, and those should be chosen before any sources in sysdeps.
149 $(objpfx)%.o: %.S $(before-compile); $(compile-command.S)
150 $(objpfx)%.so: %.S $(before-compile); $(compile-command.S)
151 $(objpfx)%.po: %.S $(before-compile); $(compile-command.S)
152 $(objpfx)%.go: %.S $(before-compile); $(compile-command.S)
153 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
154 $(objpfx)%.o: %.s $(before-compile); $(compile-command.s)
155 $(objpfx)%.so: %.s $(before-compile); $(compile-command.s)
156 $(objpfx)%.po: %.s $(before-compile); $(compile-command.s)
157 $(objpfx)%.go: %.s $(before-compile); $(compile-command.s)
158 $(objpfx)%.d: %.s $(objpfx)dummy.d; $(make-dummy-dep)
159 $(objpfx)%.o: %.c $(before-compile); $(compile-command.c)
160 $(objpfx)%.so: %.c $(before-compile); $(compile-command.c)
161 $(objpfx)%.po: %.c $(before-compile); $(compile-command.c)
162 $(objpfx)%.go: %.c $(before-compile); $(compile-command.c)
163 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
165 # Omit the objpfx rules when building in the source tree, because
166 # objpfx is empty and so these rules just override the ones above.
167 ifdef objpfx
168 # Define first rules to find the source files in $(objpfx).
169 # Generated source files will end up there.
170 $(objpfx)%.o: $(objpfx)%.S $(before-compile); $(compile-command.S)
171 $(objpfx)%.so: $(objpfx)%.S $(before-compile); $(compile-command.S)
172 $(objpfx)%.po: $(objpfx)%.S $(before-compile); $(compile-command.S)
173 $(objpfx)%.go: $(objpfx)%.S $(before-compile); $(compile-command.S)
174 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
175 $(objpfx)%.o: $(objpfx)%.s $(before-compile); $(compile-command.s)
176 $(objpfx)%.so: $(objpfx)%.s $(before-compile); $(compile-command.s)
177 $(objpfx)%.po: $(objpfx)%.s $(before-compile); $(compile-command.s)
178 $(objpfx)%.go: $(objpfx)%.s $(before-compile); $(compile-command.s)
179 $(objpfx)%.d: $(objpfx)%.s $(objpfx)dummy.d; $(make-dummy-dep)
180 $(objpfx)%.o: $(objpfx)%.c $(before-compile); $(compile-command.c)
181 $(objpfx)%.so: $(objpfx)%.c $(before-compile); $(compile-command.c)
182 $(objpfx)%.po: $(objpfx)%.c $(before-compile); $(compile-command.c)
183 $(objpfx)%.go: $(objpfx)%.c $(before-compile); $(compile-command.c)
184 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
185 endif
187 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
188 # patterns matching sysdep directories whose assembly source files should
189 # be suppressed.
190 ifdef inhibit-sysdep-asm
191 define open-check-inhibit-asm
192 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
193 endef
194 close-check-inhibit-asm = ;; esac ;
195 endif
197 # Don't include sysd-rules until sysd-Makefile is already there and has been
198 # included.  It might define inhibit-sysdep-asm, which would affect the
199 # contents of sysd-rules.
200 ifdef sysd-Makefile-done
201 include $(+sysdir_pfx)sysd-rules
202 ifneq ($(sysd-rules-sysdirs),$(sysdirs))
203 # The value of $(sysdirs) the sysd-rules was computed for
204 # differs from the one we are using now.  So force a rebuild of sysd-rules.
205 sysd-rules-force = FORCE
206 FORCE:
207 endif
208 endif
209 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
210                           $(wildcard $(foreach dir,$(sysdirs),\
211                                                $(sysdep_dir)/$(dir)/Makefile))\
212                           $(sysd-rules-force)
213         -@rm -f $@T
214         (echo 'sysd-rules-sysdirs := $(sysdirs)';                             \
215          for sysdir in $(sysdirs); do                                         \
216            dir="\$$(sysdep_dir)/$$sysdir";                                    \
217            for o in $(object-suffixes); do \
218              $(open-check-inhibit-asm) \
219              echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
220                   \$$(compile-command.S)";                                    \
221              echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
222                   \$$(compile-command.s)";                                    \
223              $(close-check-inhibit-asm) \
224              echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
225                   \$$(compile-command.c)";                                    \
226            done; \
227            $(open-check-inhibit-asm) \
228            echo "\$$(objpfx)%.d: $$dir/%.s \$$(objpfx)dummy.d; \
229                 \$$(make-dummy-dep)";                          \
230            echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
231                 \$$(+make-deps)";                                             \
232            $(close-check-inhibit-asm)   \
233            echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
234                 \$$(+make-deps)";                                             \
235          done;                                                                \
236          echo 'sysd-rules-done = t') > $@T
237         mv -f $@T $@
239 ifndef sysd-rules-done
240 # Don't do deps until this exists, because it provides rules to make the deps.
241 no_deps=t
242 endif
245 ifndef compile-command.S
246 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
247 endif
248 ifndef compile-command.s
249 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
250 endif
251 ifndef compile-command.c
252 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
253 endif
255 # GCC can grok options after the file name, and it looks nicer that way.
256 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
257 compile.S = $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
258 COMPILE.S = $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
259 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
261 # We need this for the output to go in the right place.  It will default to
262 # empty if make was configured to work with a cc that can't grok -c and -o
263 # together.  You can't compile the C library with such a compiler.
264 OUTPUT_OPTION = -o $@
266 S-CPPFLAGS = $(asm-CPPFLAGS)
267 define +make-deps
268 -@rm -f $@
269 $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
270 sed -e 's,$*\.o,$(foreach o,$(object-suffixes),$(@:.d=$o)) $@,' \
271 $(sed-remove-objpfx) > $(@:.d=.T)
272 mv -f $(@:.d=.T) $@
273 endef
274 ifneq (,$(objpfx))
275 sed-remove-objpfx = -e 's@ $(subst @,\@,$(objpfx))@ $$(objpfx)@g' \
276                     -e 's@^$(subst @,\@,$(objpfx))@$$(objpfx)@g'
277 endif
279 # Figure out the source filenames in this directory.
281 override sources        := $(addsuffix .c,$(filter-out $(elided-routines),\
282                                                        $(routines) $(aux) \
283                                                        $(sysdep_routines)))
284 sysdep_routines := $(sysdep_routines)
286 # This is the list of all object files, gotten by
287 # replacing every ".c" in `sources' with a ".o".
288 override objects        := $(addprefix $(objpfx),$(sources:.c=.o))
291 # This variable is used in ``include $(o-iterator)'' after defining
292 # $(o-iterator-doit) to produce some desired rule using $o for the object
293 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
294 # is produced for each object suffix in use.
295 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes))
297 # The makefile may define $(extra-libs) with `libfoo libbar'
298 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
299 ifdef extra-libs
300 # extra-lib.mk is included once for each extra lib to define rules
301 # to build it, and to add its objects to the various variables.
302 # During its evaluation, $(lib) is set to the name of the library.
303 extra-libs-left := $(extra-libs)
304 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
305 endif
307 +depfiles := $(strip $(sources:.c=.d) \
308                      $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.so=.o))) \
309                      $(addsuffix .d,$(others) $(tests)))
310 +depfiles := $(addprefix $(objpfx),\
311                          $(filter-out $(addsuffix .d,$(omit-deps)),\
312                                       $(+depfiles)))
314 ifdef +depfiles
315 ifneq ($(no_deps),t)
316 include $(+depfiles)
317 endif
318 endif
319 \f\f
320 # Maximize efficiency by minimizing the number of rules.
321 .SUFFIXES:      # Clear the suffix list.
322 # Add the suffixes we use.
323 .SUFFIXES: .a $(object-suffixes) .S .s .c .h .d
325 # Generic rule for making directories.
327 # mkdir isn't smart enough to strip a trailing /.
328         mkdir $(@:%/=%)
330 # Make sure that object files are not removed
331 # when they are intermediates between sources and library members.
332 .PRECIOUS: $(addprefix $(objpfx)%,$(object-suffixes))
334 # Make sure that the parent library archive is never removed.
335 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
337 # Use the verbose option of ar and tar when not running silently.
338 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
339 verbose := v
340 else                                            # -s
341 verbose :=
342 endif                                           # not -s
344 ARFLAGS := r$(verbose)
346 # This makes all the object files in the parent library archive.
348 .PHONY: lib libobjs lib-noranlib
349 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
351 # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib.
352 lib%.a: lib%.a(__.SYMDEF) ;
354 libobjs: $(foreach o,$(object-suffixes),\
355                    $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
356                    $(notdir $(objects:.o=$o))))
357 lib-noranlib: libobjs
358 others: $(addprefix $(objpfx),$(install-lib))
360 ifdef objects
362 # Define a pattern rule that will match many targets libc.a(foo.%), for
363 # each foo.o in $(objects) (% will just happen always to match `o').  This is
364 # the only way to define a rule that updates many targets at once with one
365 # sequence of commands.  We in fact define the pattern rule to match
366 # targets libc.a(foo.%), libc_pic.a(foo.%), etc, to avoid repeating the rule.
367 # Each match will only ever be called upon to make member objects of
368 # the appropriate type in each library (i.e. libc_pic.a(foo.so)).
369 $(foreach l,$(libtypes),\
370           $(common-objpfx)$(patsubst %,$l,c)($(notdir $(objects:.o=.%)))): \
371   $(objpfx)stamp.%-$(subdir) ;
373 # The pattern rule tells Make to remake $(objpfx)stamp.%-$(subdir) as
374 # the way to update all the foo.% object files in $(objects).
375 # Now we define a static pattern rule to update each
376 # $(objpfx)stamp.SUFFIX-$(subdir) timestamp file;
377 # these rules (one explicit rule is generated for each object suffix)
378 # will update the parent archive with
379 $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir)): \
380   $(objpfx)stamp%-$(subdir): $(objects:.o=%)
381         $(patsubst %,cd %;,$(objdir)) \
382         $(AR) cru$(verbose) ${O%-lib} \
383               $(patsubst $(objpfx)%,%,$^)
384 # `touch' won't let me touch a world-writable file I don't own.  Sigh.
385         rm -f $@
386         touch $@
387 ifdef subdir
388 O%-lib = $(filter ../,$(firstword $(objdir) ../))$(patsubst %,$(libtype$*),c)
389 else
390 O%-lib = $(patsubst %,$(libtype$*),c)
391 endif
393 endif
395 # Rules to update the __.SYMDEF member with ranlib.
396 # To consolidate, each flavor library's __.SYMDEF member
397 # depends on the imaginary intermediate file `symdef.SUFFIX',
398 # where SUFFIX is that flavor's object suffix; then a pattern rule
399 # "remakes" symdef.% depending on all the libc.a(foo.%) files in $(objects).
400 $(common-objpfx)$(patsubst %,$(libtype.o),c)(__.SYMDEF): symdef.o
401 $(common-objpfx)$(patsubst %,$(libtype.so),c)(__.SYMDEF): symdef.so
402 $(common-objpfx)$(patsubst %,$(libtype.po),c)(__.SYMDEF): symdef.po
403 $(common-objpfx)$(patsubst %,$(libtype.go),c)(__.SYMDEF): symdef.go
404 symdef.%: $(foreach o,$(object-suffixes),\
405                     $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
406           $(patsubst $(objpfx)%.o,%.%,$(objects)))) \
407           $(filter subdir_lib,$(firstword $(subdir) subdir_lib))
408 # The last line above makes it also depend on subdir_lib for the parent.
409         $(RANLIB) $(common-objpfx)$(patsubst %,$(libtype.$*),c)
411 # This makes all the object files.
412 .PHONY: objects objs
413 objects objs: $(foreach o,$(object-suffixes),$(objects:.o=$o)) \
414               $(addprefix $(objpfx),$(extra-objs))
416 # Canned sequence for building an extra library archive.
417 define build-extra-lib
418 $(patsubst %,cd %;,$(objdir)) \
419 $(AR) cru$(verbose) $(@:$(objpfx)%=%) \
420       $(patsubst $(objpfx)%,%,$^)
421 $(RANLIB) $@
422 endef
424 # Installation.
426 # $(install-lib) are installed from the object directory into $(libdir);
427 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
428 # unless they also appear in $(non-lib.a).  $(install-data) are installed
429 # as they are into $(datadir).  $(headers) are installed as they are in
430 # $(includedir).  $(install-bin) and $(install-sbin) are installed from the
431 # object directory into $(bindir) and $(sbindir), respectively.
432 # $(install-others) are absolute path names of files to install; rules to
433 # install them are defined elsewhere.
435 # The simple library name to install libc.a under.
436 # This could be defined by a sysdep Makefile.
437 ifndef libc-name
438 libc-name := c
439 endif
441 define do-install
442 $(make-target-directory)
443 $(INSTALL_DATA) $< $@
444 endef
446 # Make the target directory if it doesn't exist.  Because of make's
447 # directory cache, this will produce the `mkdir' command when the directory
448 # already exists, if it didn't exist at the start of the `make' run.  The
449 # `-' prefix ignores errors from mkdir, so there will just be some
450 # gratuitous but harmless `File exists' messages.
451 define make-target-directory
452 $(addprefix -mkdir ,$(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
453 endef
455 # Any directory (parent or subdir) that has any object files to build
456 # should install libc.a; this way "make install" in a subdir is guaranteed
457 # to install everything it changes.
458 ifdef objects
459 installed-libcs := $(foreach o,$(object-suffixes),\
460                              $(libdir)/$(patsubst %,$(libtype$o),\
461                                                   $(libprefix)$(libc-name)))
462 installed-libcs := $(filter-out %_pic.a,$(installed-libcs))
463 install: $(installed-libcs)
464 $(installed-libcs): $(libdir)/lib$(libprefix)%: lib
465         $(make-target-directory)
466         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
467 # Running ranlib after installing makes the __.SYMDEF time stamp up to
468 # date, which avoids messages from some linkers.
469         $(RANLIB) $@
470 endif
472 define do-install-program
473 $(make-target-directory)
474 $(INSTALL_PROGRAM) $< $@.new
475 mv -f $@.new $@
476 endef
478 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
479 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
480 ifeq (yes,$(build-shared))
481 install-lib-nosubdir: $(foreach so,$(install-lib.so),\
482   $(libdir)/$(patsubst $(libprefix)lib%,lib$(libprefix)%,\
483                        $(libprefix)$(so))$($(so)-version))
485 install: $(slibdir)/libc.so$(libc.so-version)
486 $(slibdir)/lib$(libprefix)c.so$(libc.so-version): $(common-objpfx)libc.so
487         $(do-install-so)
489 define do-install-so
490 $(do-install-program)
491 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
492            $(filter-out %.so,$@))
493 endef
495 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
496 $(foreach v,$(so-versions),\
497           $(libdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so
498         $(do-install-so)
499 $(foreach v,$(so-versions),\
500           $(libdir)/$(libprefix)%$v): $(common-objpfx)%.so
501         $(do-install-so)
502 endif
504 ifdef install-bin
505 $(addprefix $(bindir)/,$(install-bin)): $(bindir)/%: $(objpfx)%
506         $(do-install-program)
507 endif
508 ifdef install-sbin
509 $(addprefix $(sbindir)/,$(install-sbin)): $(sbindir)/%: $(objpfx)%
510         $(do-install-program)
511 endif
512 ifdef install-lib
513 install-lib.a := $(filter lib%.a,$(install-lib))
514 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
515 ifdef install-lib-non.a
516 $(addprefix $(libdir)/$(libprefix),$(install-lib-non.a)): \
517   $(libdir)/$(libprefix)%: $(objpfx)%
518         $(do-install)
519 endif
520 ifdef install-lib.a
521 $(install-lib.a:lib%.a=$(libdir)/lib$(libprefix)%.a): \
522   $(libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
523         $(do-install)
524         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
525 endif
526 endif
527 ifdef install-data
528 $(addprefix $(datadir)/,$(install-data)): $(datadir)/%: %;$(do-install)
529 endif
530 headers := $(strip $(headers))
531 ifdef headers
532 $(addprefix $(includedir)/,$(headers)): \
533         $(includedir)/%: %;$(do-install)
534 endif   # headers
536 .PHONY: install-bin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
537         install-data-nosubdir install-headers-nosubdir
538 install-bin-nosubdir: $(addprefix $(bindir)/,$(install-bin))
539 install-sbin-nosubdir: $(addprefix $(sbindir)/,$(install-sbin))
540 install-lib-nosubdir: $(addprefix $(libdir)/,\
541                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
542                        $(addprefix $(libprefix),$(install-lib-non.a)))
543 install-data-nosubdir: $(addprefix $(datadir)/,$(install-data))
544 install-headers-nosubdir: $(addprefix $(includedir)/,$(headers))
545 install-others-nosubdir: $(install-others)
547 # We need all the `-nosubdir' targets so that `install' in the parent
548 # doesn't depend on several things which each iterate over the subdirs.
549 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
550 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
551 install-%:: install-%-nosubdir ;
553 .PHONY: install install-no-libc.a-nosubdir
554 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
555                             install-bin-nosubdir install-lib-nosubdir   \
556                             install-others-nosubdir install-sbin-nosubdir
557 install: install-no-libc.a-nosubdir
559 ifeq (yes,$(build-shared))
560 # Pattern rule to build a shared object from an archive of PIC objects.
561 # This must come after the installation rules so Make doesn't try to
562 # build shared libraries in place from the installed *_pic.a files.
563 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
564 # on other shared objects.
565 lib%.so: lib%_pic.a; $(build-shlib)
567 define build-shlib
568 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
569           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
570           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
571           -Wl,-rpath-link=$(common-objdir) -Wl,-rpath=$(libdir) \
572           -Wl,--whole-archive $^ $(LDLIBS-$(@F:lib%.so=%).so)
573 endef
575 # Don't try to use -lc when making libc.so itself.
576 # Also omits crti.o and crtn.o, which we do not want
577 # since we define our own `.init' section specially.
578 LDFLAGS-c.so = -nostdlib -nostartfiles
579 # Give libc.so an entry point and make it directly runnable itself.
580 LDFLAGS-c.so += -e __libc_print_version
581 # Use our own special initializer and finalizer files for libc.so.
582 elfobjdir := $(firstword $(objdir) $(..)elf)
583 $(common-objpfx)libc.so: $(elfobjdir)/soinit.so \
584                          $(common-objpfx)libc_pic.a \
585                          $(elfobjdir)/sofini.so
586         $(build-shlib)
588 ifdef libc.so-version
589 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
590         rm -f $@
591         ln -s $(<F) $@ || ln $< $@
592 endif
593 endif
596 # Command to compile $< in $(objdir) using the native libraries.
597 define native-compile
598 cwd=`pwd`; cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) \
599            $(addprefix $$cwd/,$^) -o $(@F)
600 endef
602 # Command to compile $< in $(common-objdir) using the native libraries.
603 define common-objdir-compile
604 cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=%) -o $(@F)
605 endef
607 # We always want to use configuration definitions.
608 BUILD_CFLAGS = -include $(common-objpfx)config.h
610 # Support the GNU standard name for this target.
611 .PHONY: check
612 check: tests
614 .PHONY: TAGS
615 TAGS: distinfo $(..)MakeTAGS
616         $(MAKE) $(addprefix -f ,$^)
618 .PHONY: echo-headers
619 echo-headers:
620         @echo $(headers)
623 # Common cleaning targets.
625 .PHONY: common-mostlyclean common-clean mostlyclean clean
626 clean: common-clean
627 mostlyclean: common-mostlyclean
629 # Remove the object files.
630 common-mostlyclean:
631         -rm -f $(addprefix $(objpfx),$(tests) $(others) \
632                                      $(addsuffix .o,$(tests) $(others)) \
633                                      $(addsuffix .out,$(tests)))
634         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib))
635         -rm -f core $(objpfx)stub-$(subdir)
636         $(rmobjs)
637 define rmobjs
638 $(foreach o,$(object-suffixes),
639 -rm -f $(addprefix $(objpfx),stamp$o-$(subdir)) $(objects:.o=$o))
640 endef
642 # Also remove the dependencies and generated source files.
643 common-clean: common-mostlyclean
644         -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
646 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
647 # for each function which is a stub.  We grovel over all the .d files
648 # looking for references to source files in sysdeps/stub.  Then we grovel
649 # over each referenced source file to see what stub function it defines.
651 .PHONY: stubs # The parent Makefile calls this target.
652 stubs: $(common-objpfx)stub-$(subdir)
653 s = $(sysdep_dir)/stub
654 $(common-objpfx)stub-$(subdir): $(+depfiles)
655 # Use /dev/null since `...` might expand to empty.
656         s=`cd $s; /bin/pwd`; \
657         $(patsubst %,cd %;,$(objdir)) \
658         sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
659             `sed -n 's@^.*$s/\([a-z0-9_-]*\.c\).*$$@'"$$s"/'\1@p' \
660                  $(patsubst $(objpfx)%,%,$^) /dev/null` \
661             /dev/null > $@T
662         mv -f $@T $@
664 # Make the distribution tar file.
666 .PHONY: dist
667 dist: distinfo $(..)Make-dist
668         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
670 # Avoid depending on source files found in sysdeps dirs,
671 # because the references affect implicit rule selection.
672 dist: $(filter-out %.c %.S %.s,$(distribute))
674 # We used to simply export all these variables, but that frequently made the
675 # environment get too large.  Instead, we write all the information into
676 # a generated makefile fragment `distinfo', and then include it with -f in
677 # the sub-make that makes the distribution (above).
678 distinfo: Makefile $(..)Makerules
679         $(distinfo-vars)
680         mv -f $@.new $@
682 define distinfo-vars
683 rm -f $@.new
684 $(foreach var,subdir sources elided-routines headers distribute \
685               dont_distribute generated others tests,
686 echo >> $@.new '$(var)  := $($(var))')
687 echo >> $@.new 'sources := $$(sources) $$(addsuffix .c,$$(elided-routines))'
688 endef
690 ifneq (,$(strip $(gpl2lgpl)))
691 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
692 # Snarf from the master source and frob the copying notice.
693 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
694         sed -f $^ > $@-tmp
695 # So I don't edit them by mistake.
696         chmod a-w $@-tmp
697         mv -f $@-tmp $@
698         test ! -d CVS || cvs commit -m'Updated from $^' $@
699 endif
700 endif