Sat Apr 22 14:48:03 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
[platform/upstream/glibc.git] / Makerules
1 # Copyright (C) 1991, 1992, 1993, 1994, 1995 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 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.
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 # Library General Public License for more details.
13
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.
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
29 ifdef   subdir
30 ..      := ../
31 endif   # subdir
32
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
38
39 headers := $(headers) $(sysdep_headers)
40
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
48 \f
49 ifndef +included-Makeconfig
50 include $(..)Makeconfig
51 endif
52
53 # `configure' writes a definition of `config-sysdirs' in `config.make'.
54 sysdirs = $(config-sysdirs)
55
56 +sysdir_pfx = $(common-objpfx)
57
58 export sysdirs := $(sysdirs)
59
60 +sysdep_dirs := $(addprefix $(sysdep_dir)/,$(sysdirs))
61 ifdef objdir
62 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
63 endif
64
65 # Add -I switches to get the right sysdep directories.
66 # `+includes' in Makeconfig references $(+sysdep-includes).
67 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
68 \f
69 # Include any system-specific makefiles.
70
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                                       $(..)))
77
78 ifeq ($(wildcard $(+sysdir_pfx)sysd-Makefile),)
79 # Don't do deps until this exists, because it might change the sources list.
80 no_deps=t
81 endif
82
83 # Some sysdep makefiles use this to distinguish being included here from
84 # being included individually by a subdir makefile (hurd/Makefile needs this).
85 in-Makerules := yes
86
87 ifndef avoid-generated
88 include $(+sysdir_pfx)sysd-Makefile
89 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules
90         -@rm -f $@T
91         (for dir in $(sysdirs); do                                            \
92            file=sysdeps/$$dir/Makefile;                                       \
93            if [ -f $(..)$$file ]; then                                        \
94              echo include "\$$(..)$$file";                                    \
95            else true; fi;                                                     \
96          done; \
97          echo 'sysd-Makefile-done=t') > $@T
98         mv -f $@T $@
99 endif
100
101 # Reorder before-compile so that mach things come first, and hurd things
102 # second, before all else.  The mach and hurd subdirectories have many
103 # generated header files which the much of rest of the library depends on,
104 # so it is best to build them first (and mach before hurd, at that).
105 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
106                            $(before-compile)) \
107                   $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
108                                $(before-compile))
109
110 # Remove existing files from `before-compile'.  Things are added there when
111 # they must exist for dependency generation to work right, but once they
112 # exist there is no further need for every single file to depend on them,
113 # and those gratuitous dependencies result in many gratuitous
114 # recompilations.
115 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
116
117 # Don't let any before-compile file be an intermediate and get removed.
118 ifdef before-compile
119 $(before-compile):
120 endif
121 \f
122 # Generate an ordered list of implicit rules which find the source files in
123 # each sysdep directory.  The old method was to use vpath to search all the
124 # sysdep directories.  However, that had the problem that a .S file in a
125 # later directory would be chosen over a .c file in an earlier directory,
126 # which does not preserve the desired sysdeps ordering behavior.
127
128 # When making the list of .d files to include, we can't know which ones
129 # have source in .s files, and thus do not in fact need a .d file.
130 # So we must define rules to make .d files for .s files.
131 define make-dummy-dep
132 $(addprefix ln $(objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
133 endef
134 $(objpfx)dummy.d:
135         echo '# .s files cannot contain includes, so they need no deps.' > $@
136
137 # It matters that this set of rules, for compiling from sources in
138 # the current directory (the $srcdir/$subdir) come before the
139 # generated sysdep rules in included from sysd-rules below.  When
140 # compiling in the source tree, generated sources go into the current
141 # directory, and those should be chosen before any sources in sysdeps.
142 $(objpfx)%.o: %.S $(before-compile); $(compile-command.S)
143 $(objpfx)%.so: %.S $(before-compile); $(compile-command.S)
144 $(objpfx)%.po: %.S $(before-compile); $(compile-command.S)
145 $(objpfx)%.go: %.S $(before-compile); $(compile-command.S)
146 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
147 $(objpfx)%.o: %.s $(before-compile); $(compile-command.s)
148 $(objpfx)%.so: %.s $(before-compile); $(compile-command.s)
149 $(objpfx)%.po: %.s $(before-compile); $(compile-command.s)
150 $(objpfx)%.go: %.s $(before-compile); $(compile-command.s)
151 $(objpfx)%.d: %.s $(objpfx)dummy.d; $(make-dummy-dep)
152 $(objpfx)%.o: %.c $(before-compile); $(compile-command.c)
153 $(objpfx)%.so: %.c $(before-compile); $(compile-command.c)
154 $(objpfx)%.po: %.c $(before-compile); $(compile-command.c)
155 $(objpfx)%.go: %.c $(before-compile); $(compile-command.c)
156 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
157
158 # Omit the objpfx rules when building in the source tree, because
159 # objpfx is empty and so these rules just override the ones above.
160 ifdef objpfx
161 # Define first rules to find the source files in $(objpfx).
162 # Generated source files will end up there.
163 $(objpfx)%.o: $(objpfx)%.S $(before-compile); $(compile-command.S)
164 $(objpfx)%.so: $(objpfx)%.S $(before-compile); $(compile-command.S)
165 $(objpfx)%.po: $(objpfx)%.S $(before-compile); $(compile-command.S)
166 $(objpfx)%.go: $(objpfx)%.S $(before-compile); $(compile-command.S)
167 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
168 $(objpfx)%.o: $(objpfx)%.s $(before-compile); $(compile-command.s)
169 $(objpfx)%.so: $(objpfx)%.s $(before-compile); $(compile-command.s)
170 $(objpfx)%.po: $(objpfx)%.s $(before-compile); $(compile-command.s)
171 $(objpfx)%.go: $(objpfx)%.s $(before-compile); $(compile-command.s)
172 $(objpfx)%.d: $(objpfx)%.s $(objpfx)dummy.d; $(make-dummy-dep)
173 $(objpfx)%.o: $(objpfx)%.c $(before-compile); $(compile-command.c)
174 $(objpfx)%.so: $(objpfx)%.c $(before-compile); $(compile-command.c)
175 $(objpfx)%.po: $(objpfx)%.c $(before-compile); $(compile-command.c)
176 $(objpfx)%.go: $(objpfx)%.c $(before-compile); $(compile-command.c)
177 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
178 endif
179
180 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
181 # patterns matching sysdep directories whose assembly source files should
182 # be suppressed.
183 ifdef inhibit-sysdep-asm
184 define open-check-inhibit-asm
185 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
186 endef
187 close-check-inhibit-asm = ;; esac ;
188 endif
189
190 # Don't include sysd-rules until sysd-Makefile is already there and has been
191 # included.  It might define inhibit-sysdep-asm, which would affect the
192 # contents of sysd-rules.
193 ifdef sysd-Makefile-done
194 include $(+sysdir_pfx)sysd-rules
195 endif
196 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
197                           $(wildcard $(foreach dir,$(sysdirs),\
198                                                $(sysdep_dir)/$(dir)/Makefile))
199         -@rm -f $@T
200         (for sysdir in $(sysdirs); do                                         \
201            dir="\$$(sysdep_dir)/$$sysdir";                                    \
202            for o in $(object-suffixes); do \
203              $(open-check-inhibit-asm) \
204              echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
205                   \$$(compile-command.S)";                                    \
206              echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
207                   \$$(compile-command.s)";                                    \
208              $(close-check-inhibit-asm) \
209              echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
210                   \$$(compile-command.c)";                                    \
211            done; \
212            $(open-check-inhibit-asm) \
213            echo "\$$(objpfx)%.d: $$dir/%.s \$$(objpfx)dummy.d; \
214                 \$$(make-dummy-dep)";                          \
215            echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
216                 \$$(+make-deps)";                                             \
217            $(close-check-inhibit-asm)   \
218            echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
219                 \$$(+make-deps)";                                             \
220          done) > $@T
221         mv -f $@T $@
222
223 ifndef compile-command.S
224 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
225 endif
226 ifndef compile-command.s
227 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
228 endif
229 ifndef compile-command.c
230 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
231 endif
232
233 # GCC can grok options after the file name, and it looks nicer that way.
234 compile.S = $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
235 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
236
237 # We need this for the output to go in the right place.  It will default to
238 # empty if make was configured to work with a cc that can't grok -c and -o
239 # together.  You can't compile the C library with such a compiler.
240 OUTPUT_OPTION = -o $@
241
242 S-CPPFLAGS = $(asm-CPPFLAGS)
243 define +make-deps
244 -@rm -f $@
245 $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
246 sed -e 's,$*\.o,$(foreach o,$(object-suffixes),$(@:.d=$o)) $@,' \
247 $(sed-remove-objpfx) > $(@:.d=.T)
248 mv -f $(@:.d=.T) $@
249 endef
250 ifneq (,$(objpfx))
251 sed-remove-objpfx = -e 's@ $(subst @,\@,$(objpfx))@ $$(objpfx)@g' \
252                     -e 's@^$(subst @,\@,$(objpfx))@$$(objpfx)@g'
253 endif
254 \f
255 # Figure out the source filenames in this directory.
256
257 override sources        := $(addsuffix .c,$(filter-out $(elided-routines),\
258                                                        $(routines) $(aux) \
259                                                        $(sysdep_routines)))
260 sysdep_routines := $(sysdep_routines)
261
262 # This is the list of all object files, gotten by
263 # replacing every ".c" in `sources' with a ".o".
264 override objects        := $(addprefix $(objpfx),$(sources:.c=.o))
265
266
267 # This variable is used in ``include $(o-iterator)'' after defining
268 # $(o-iterator-doit) to produce some desired rule using $o for the object
269 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
270 # is produced for each object suffix in use.
271 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes))
272
273 # The makefile may define $(extra-libs) with `libfoo libbar'
274 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
275 ifdef extra-libs
276 # extra-lib.mk is included once for each extra lib to define rules
277 # to build it, and to add its objects to the various variables.
278 # During its evaluation, $(lib) is set to the name of the library.
279 extra-libs-left := $(extra-libs)
280 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
281 endif
282 \f
283 +depfiles := $(strip $(sources:.c=.d) \
284                      $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.so=.o))) \
285                      $(addsuffix .d,$(others) $(tests)))
286 +depfiles := $(addprefix $(objpfx),\
287                          $(filter-out $(addsuffix .d,$(omit-deps)),\
288                                       $(+depfiles)))
289
290 $(objpfx)depend-$(subdir): Makefile
291 ifdef +depfiles
292         for file in $(+depfiles:$(objpfx)%=%); do \
293           echo "include \$$(objpfx)$$file";     \
294         done > $@-tmp
295         mv -f $@-tmp $@
296 else
297         cp /dev/null $@
298 endif
299
300 ifneq ($(no_deps),t)
301 # Include the generated dependencies of the sources in this directory.
302 include $(objpfx)depend-$(subdir)
303 endif
304 \f\f
305 # Maximize efficiency by minimizing the number of rules.
306 .SUFFIXES:      # Clear the suffix list.
307 # Add the suffixes we use.
308 .SUFFIXES: .a $(object-suffixes) .S .s .c .h .d
309
310 # Generic rule for making directories.
311 %/:
312 # mkdir isn't smart enough to strip a trailing /.
313         mkdir $(@:%/=%)
314 \f
315 # Make sure that object files are not removed
316 # when they are intermediates between sources and library members.
317 .PRECIOUS: $(addprefix $(objpfx)%,$(object-suffixes))
318
319 # Make sure that the parent library archive is never removed.
320 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
321 \f
322 # Use the verbose option of ar and tar when not running silently.
323 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
324 verbose := v
325 else                                            # -s
326 verbose :=
327 endif                                           # not -s
328
329 ARFLAGS := r$(verbose)
330 \f
331 # This makes all the object files in the parent library archive.
332
333 .PHONY: lib libobjs lib-noranlib
334 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
335
336 # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib.
337 lib%.a: lib%.a(__.SYMDEF) ;
338
339 ifeq (yes,$(build-shared))
340 # Pattern rule to build a shared object from an archive of PIC objects.
341 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
342 # on other shared objects.
343 lib%.so: lib%_pic.a
344         $(LINK.o) -shared -o $@ -Wl,--whole-archive $< \
345                   $(LDFLAGS-$(notdir $*).so) \
346                   -L$(firstword $(objdir) .)  -L$(common-objpfx:%/=%) \
347                   $(LDLIBS-$(notdir $*).so)
348
349 # Don't try to use -lc when making libc.so itself.
350 # Also omits crti.o and crtn.o, which we do not want
351 # since we define our own `.init' section specially.
352 LDFLAGS-c.so = -nostdlib
353 endif
354
355 libobjs: $(foreach o,$(object-suffixes),\
356                    $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
357                    $(notdir $(objects:.o=$o))))
358 lib-noranlib: libobjs $(addprefix $(objpfx),$(install-lib))
359
360 ifdef objects
361
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) ;
372
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 $@
385 ifdef subdir
386 O%-lib = $(filter ../,$(firstword $(objdir) ../))$(patsubst %,$(libtype$*),c)
387 else
388 O%-lib = $(patsubst %,$(libtype$*),c)
389 endif
390
391 endif
392
393 # Rules to update the __.SYMDEF member with ranlib.
394 # To consolidate, each flavor library's __.SYMDEF member
395 # depends on the imaginary intermediate file `symdef.SUFFIX',
396 # where SUFFIX is that flavor's object suffix; then a pattern rule
397 # "remakes" symdef.% depending on all the libc.a(foo.%) files in $(objects).
398 $(common-objpfx)$(patsubst %,$(libtype.o),c)(__.SYMDEF): symdef.o
399 $(common-objpfx)$(patsubst %,$(libtype.so),c)(__.SYMDEF): symdef.so
400 $(common-objpfx)$(patsubst %,$(libtype.po),c)(__.SYMDEF): symdef.po
401 $(common-objpfx)$(patsubst %,$(libtype.go),c)(__.SYMDEF): symdef.go
402 symdef.%: $(foreach o,$(object-suffixes),\
403                     $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
404           $(patsubst $(objpfx)%.o,%.%,$(objects)))) \
405           $(filter subdir_lib,$(firstword $(subdir) subdir_lib))
406 # The last line above makes it also depend on subdir_lib for the parent.
407         $(RANLIB) $(common-objpfx)$(patsubst %,$(libtype.$*),c)
408
409 # This makes all the object files.
410 .PHONY: objects objs
411 objects objs: $(foreach o,$(object-suffixes),$(objects:.o=$o)) \
412               $(addprefix $(objpfx),$(extra-objs))
413
414 # Canned sequence for building an extra library archive.
415 define build-extra-lib
416 $(patsubst %,cd %;,$(objdir)) \
417 $(AR) cru$(verbose) $(@:$(objpfx)%=%) \
418       $(patsubst $(objpfx)%,%,$^)
419 $(RANLIB) $@
420 endef
421 \f
422 # Installation.
423
424 # $(install-lib) are installed from the object directory into $(libdir);
425 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
426 # unless they also appear in $(non-lib.a).  $(install-data) are installed
427 # as they are into $(datadir).  $(headers) are installed as they are in
428 # $(includedir).  $(install-bin) and $(install-sbin) are installed from the
429 # object directory into $(bindir) and $(sbindir), respectively.
430 # $(install-others) are absolute path names of files to install; rules to
431 # install them are defined elsewhere.
432
433 # The simple library name to install libc.a under.
434 # This could be defined by a sysdep Makefile.
435 ifndef libc-name
436 libc-name := c
437 endif
438
439 define do-install
440 $(make-target-directory)
441 $(INSTALL_DATA) $< $@
442 endef
443
444 # Make the target directory if it doesn't exist.  Because of make's
445 # directory cache, this will produce the `mkdir' command when the directory
446 # already exists, if it didn't exist at the start of the `make' run.  The
447 # `-' prefix ignores errors from mkdir, so there will just be some
448 # gratuitous but harmless `File exists' messages.
449 define make-target-directory
450 $(addprefix -mkdir ,$(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
451 endef
452
453 # Any directory (parent or subdir) that has any object files to build
454 # should install libc.a; this way "make install" in a subdir is guaranteed
455 # to install everything it changes.
456 ifdef objects
457 installed-libcs := $(foreach o,$(object-suffixes),\
458                              $(libdir)/$(patsubst %,$(libtype$o),\
459                                                   $(libprefix)$(libc-name)))
460 install: $(installed-libcs)
461 # We avoid depending on lib-noranlib because that makes the parent make
462 # subdir_lib in all the subdirs, when the make install run they do will
463 # update the library anyway.  Running ranlib after installing makes the
464 # __.SYMDEF time stamp up to date, which avoids messages from some linkers.
465 # Depending on subdir_install gets all the subdirs to update the library,
466 # and is optimal for `make install' at top level.
467 $(installed-libcs): $(libdir)/lib$(libprefix)%: libobjs subdir_install
468         $(make-target-directory)
469         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
470         $(RANLIB) $@
471 endif
472
473 install-lib.so := libc.so $(filter lib%.so,$(install-lib))
474 install-lib := $(filter-out lib%.so,$(install-lib))
475 ifeq (yes,$(build-shared))
476 install: $(foreach so,$(install-lib.so), \
477                    $(libdir)/$(so:lib%=lib$(libprefix)%).$($(so)-version))
478 $(libdir)/lib$(libprefix)%.so: $(common-objpfx)lib%.so; $(do-install)
479 endif
480
481 ifdef install-bin
482 $(addprefix $(bindir)/,$(install-bin)): $(bindir)/%: $(objpfx)%
483         $(make-target-directory)
484         $(INSTALL_PROGRAM) $< $@
485 endif
486 ifdef install-sbin
487 $(addprefix $(sbindir)/,$(install-sbin)): $(sbindir)/%: $(objpfx)%
488         $(make-target-directory)
489         $(INSTALL_PROGRAM) $< $@
490 endif
491 ifdef install-lib
492 install-lib.a := $(filter lib%.a,$(install-lib))
493 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
494 ifdef install-lib-non.a
495 $(addprefix $(libdir)/$(libprefix),$(install-lib-non.a)): \
496   $(libdir)/$(libprefix)%: $(objpfx)%
497         $(do-install)
498 endif
499 ifdef install-lib.a
500 $(install-lib.a:lib%.a=$(libdir)/lib$(libprefix)%.a): \
501   $(libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
502         $(do-install)
503         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
504 endif
505 endif
506 ifdef install-data
507 $(addprefix $(datadir)/,$(install-data)): $(datadir)/%: %;$(do-install)
508 endif
509 headers := $(strip $(headers))
510 ifdef headers
511 $(addprefix $(includedir)/,$(headers)): \
512         $(includedir)/%: %;$(do-install)
513 endif   # headers
514
515 .PHONY: install-bin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
516         install-data-nosubdir install-headers-nosubdir
517 install-bin-nosubdir: $(addprefix $(bindir)/,$(install-bin))
518 install-sbin-nosubdir: $(addprefix $(sbindir)/,$(install-sbin))
519 install-lib-nosubdir: $(addprefix $(libdir)/,\
520                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
521                        $(addprefix $(libprefix),$(install-lib-non.a)))
522 install-data-nosubdir: $(addprefix $(datadir)/,$(install-data))
523 install-headers-nosubdir: $(addprefix $(includedir)/,$(headers))
524 install-others-nosubdir: $(install-others)
525
526 # We need all the `-nosubdir' targets so that `install' in the parent
527 # doesn't depend on several things which each iterate over the subdirs.
528 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
529 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
530 install-%:: install-%-nosubdir ;
531
532 .PHONY: install install-no-libc.a-nosubdir
533 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
534                             install-bin-nosubdir install-lib-nosubdir   \
535                             install-others-nosubdir install-sbin-nosubdir
536 install: install-no-libc.a-nosubdir
537 \f
538 # Command to compile $< in $(objdir) using the native libraries.
539 define native-compile
540 cwd=`pwd`; cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) \
541            $(addprefix $$cwd/,$^) -o $(@F)
542 endef
543
544 # Command to compile $< in $(common-objdir) using the native libraries.
545 define common-objdir-compile
546 cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=%) -o $(@F)
547 endef
548
549 # We always want to use configuration definitions.
550 BUILD_CFLAGS = -include $(common-objpfx)config.h
551
552 # Support the GNU standard name for this target.
553 .PHONY: check
554 check: tests
555 \f
556 .PHONY: TAGS
557 TAGS: distinfo $(..)MakeTAGS
558         $(MAKE) $(addprefix -f ,$^)
559
560 .PHONY: echo-headers
561 echo-headers:
562         @echo $(headers)
563
564 \f
565 # Common cleaning targets.
566
567 .PHONY: common-mostlyclean common-clean mostlyclean clean
568 clean: common-clean
569 mostlyclean: common-mostlyclean
570
571 # Remove the object files.
572 common-mostlyclean:
573         -rm -f $(addprefix $(objpfx),$(tests) $(others) \
574                                      $(addsuffix .o,$(tests) $(others)) \
575                                      $(addsuffix .out,$(tests)))
576         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib))
577         -rm -f core $(objpfx)stub-$(subdir)
578         $(rmobjs)
579 define rmobjs
580 $(foreach o,$(object-suffixes),
581 -rm -f $(addprefix $(objpfx),stamp$o-$(subdir)) $(objects:.o=$o))
582 endef
583
584 # Also remove the dependencies and generated source files.
585 common-clean: common-mostlyclean
586         -rm -f $(objpfx)depend-$(subdir) $(+depfiles)
587         -rm -f $(addprefix $(objpfx),$(generated))
588 \f
589 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
590 # for each function which is a stub.  We grovel over all the .d files
591 # looking for references to source files in sysdeps/stub.  Then we grovel
592 # over each referenced source file to see what stub function it defines.
593
594 .PHONY: stubs # The parent Makefile calls this target.
595 stubs: $(common-objpfx)stub-$(subdir)
596 s = $(sysdep_dir)/stub
597 $(common-objpfx)stub-$(subdir): $(+depfiles)
598 # Use /dev/null since `...` might expand to empty.
599         s=`cd $s; /bin/pwd`; \
600         $(patsubst %,cd %;,$(objdir)) \
601         sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
602             `sed -n 's@^.*$s/\([a-z0-9_-]*\.c\).*$$@'"$$s"/'\1@p' \
603                  $(patsubst $(objpfx)%,%,$^) /dev/null` \
604             /dev/null > $@T
605         mv -f $@T $@
606 \f
607 # Make the distribution tar file.
608
609 .PHONY: dist
610 dist: distinfo $(..)Make-dist 
611         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
612
613 dist: $(distribute)
614
615 # We used to simply export all these variables, but that frequently made the
616 # environment get too large.  Instead, we write all the information into
617 # a generated makefile fragment `distinfo', and then include it with -f in
618 # the sub-make that makes the distribution (above).
619 distinfo: Makefile $(..)Makerules
620         $(distinfo-vars)
621         mv -f $@.new $@
622
623 define distinfo-vars
624 rm -f $@.new
625 $(foreach var,subdir sources elided-routines headers distribute \
626               dont_distribute generated others tests,
627 echo >> $@.new '$(var)  := $($(var))')
628 echo >> $@.new 'sources := $$(sources) $$(addsuffix .c,$$(elided-routines))'
629 endef
630 \f
631 ifneq (,$(strip $(gpl2lgpl)))
632 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
633 # Snarf from the master source and frob the copying notice.
634 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
635         sed -f $^ > $@-tmp
636 # So I don't edit them by mistake.
637         chmod a-w $@-tmp
638         mv -f $@-tmp $@
639         test -d CVS && cvs commit -m'Updated from $^' $@
640 endif
641 endif