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