Mon Dec 18 13:40:37 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
[glibc.git] / Makerules
blob530b1acb3f428bfbddfba55cf8c7df64ceae4677
1 # Copyright (C) 1991, 1992, 1993, 1994, 1995 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.S = $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
257 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
259 # We need this for the output to go in the right place.  It will default to
260 # empty if make was configured to work with a cc that can't grok -c and -o
261 # together.  You can't compile the C library with such a compiler.
262 OUTPUT_OPTION = -o $@
264 S-CPPFLAGS = $(asm-CPPFLAGS)
265 define +make-deps
266 -@rm -f $@
267 $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
268 sed -e 's,$*\.o,$(foreach o,$(object-suffixes),$(@:.d=$o)) $@,' \
269 $(sed-remove-objpfx) > $(@:.d=.T)
270 mv -f $(@:.d=.T) $@
271 endef
272 ifneq (,$(objpfx))
273 sed-remove-objpfx = -e 's@ $(subst @,\@,$(objpfx))@ $$(objpfx)@g' \
274                     -e 's@^$(subst @,\@,$(objpfx))@$$(objpfx)@g'
275 endif
277 # Figure out the source filenames in this directory.
279 override sources        := $(addsuffix .c,$(filter-out $(elided-routines),\
280                                                        $(routines) $(aux) \
281                                                        $(sysdep_routines)))
282 sysdep_routines := $(sysdep_routines)
284 # This is the list of all object files, gotten by
285 # replacing every ".c" in `sources' with a ".o".
286 override objects        := $(addprefix $(objpfx),$(sources:.c=.o))
289 # This variable is used in ``include $(o-iterator)'' after defining
290 # $(o-iterator-doit) to produce some desired rule using $o for the object
291 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
292 # is produced for each object suffix in use.
293 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes))
295 # The makefile may define $(extra-libs) with `libfoo libbar'
296 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
297 ifdef extra-libs
298 # extra-lib.mk is included once for each extra lib to define rules
299 # to build it, and to add its objects to the various variables.
300 # During its evaluation, $(lib) is set to the name of the library.
301 extra-libs-left := $(extra-libs)
302 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
303 endif
305 +depfiles := $(strip $(sources:.c=.d) \
306                      $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.so=.o))) \
307                      $(addsuffix .d,$(others) $(tests)))
308 +depfiles := $(addprefix $(objpfx),\
309                          $(filter-out $(addsuffix .d,$(omit-deps)),\
310                                       $(+depfiles)))
312 ifdef +depfiles
313 ifneq ($(no_deps),t)
314 include $(+depfiles)
315 endif
316 endif
317 \f\f
318 # Maximize efficiency by minimizing the number of rules.
319 .SUFFIXES:      # Clear the suffix list.
320 # Add the suffixes we use.
321 .SUFFIXES: .a $(object-suffixes) .S .s .c .h .d
323 # Generic rule for making directories.
325 # mkdir isn't smart enough to strip a trailing /.
326         mkdir $(@:%/=%)
328 # Make sure that object files are not removed
329 # when they are intermediates between sources and library members.
330 .PRECIOUS: $(addprefix $(objpfx)%,$(object-suffixes))
332 # Make sure that the parent library archive is never removed.
333 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
335 # Use the verbose option of ar and tar when not running silently.
336 ifeq    "$(findstring s,$(MAKEFLAGS))" ""       # if not -s
337 verbose := v
338 else                                            # -s
339 verbose :=
340 endif                                           # not -s
342 ARFLAGS := r$(verbose)
344 # This makes all the object files in the parent library archive.
346 .PHONY: lib libobjs lib-noranlib
347 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
349 # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib.
350 lib%.a: lib%.a(__.SYMDEF) ;
352 libobjs: $(foreach o,$(object-suffixes),\
353                    $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
354                    $(notdir $(objects:.o=$o))))
355 lib-noranlib: libobjs
356 others: $(addprefix $(objpfx),$(install-lib))
358 ifdef objects
360 # Define a pattern rule that will match many targets libc.a(foo.%), for
361 # each foo.o in $(objects) (% will just happen always to match `o').  This is
362 # the only way to define a rule that updates many targets at once with one
363 # sequence of commands.  We in fact define the pattern rule to match
364 # targets libc.a(foo.%), libc_pic.a(foo.%), etc, to avoid repeating the rule.
365 # Each match will only ever be called upon to make member objects of
366 # the appropriate type in each library (i.e. libc_pic.a(foo.so)).
367 $(foreach l,$(libtypes),\
368           $(common-objpfx)$(patsubst %,$l,c)($(notdir $(objects:.o=.%)))): \
369   $(objpfx)stamp.%-$(subdir) ;
371 # The pattern rule tells Make to remake $(objpfx)stamp.%-$(subdir) as
372 # the way to update all the foo.% object files in $(objects).
373 # Now we define a static pattern rule to update each
374 # $(objpfx)stamp.SUFFIX-$(subdir) timestamp file;
375 # these rules (one explicit rule is generated for each object suffix)
376 # will update the parent archive with
377 $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir)): \
378   $(objpfx)stamp%-$(subdir): $(objects:.o=%)
379         $(patsubst %,cd %;,$(objdir)) \
380         $(AR) cru$(verbose) ${O%-lib} \
381               $(patsubst $(objpfx)%,%,$^)
382 # `touch' won't let me touch a world-writable file I don't own.  Sigh.
383         rm -f $@
384         touch $@
385 ifdef subdir
386 O%-lib = $(filter ../,$(firstword $(objdir) ../))$(patsubst %,$(libtype$*),c)
387 else
388 O%-lib = $(patsubst %,$(libtype$*),c)
389 endif
391 endif
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)
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))
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
422 # Installation.
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.
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
439 define do-install
440 $(make-target-directory)
441 $(INSTALL_DATA) $< $@
442 endef
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
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 installed-libcs := $(filter-out %_pic.a,$(installed-libcs))
461 install: $(installed-libcs)
462 $(installed-libcs): $(libdir)/lib$(libprefix)%: lib
463         $(make-target-directory)
464         $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
465 # Running ranlib after installing makes the __.SYMDEF time stamp up to
466 # date, which avoids messages from some linkers.
467         $(RANLIB) $@
468 endif
470 define do-install-program
471 $(make-target-directory)
472 $(INSTALL_PROGRAM) $< $@.new
473 mv -f $@.new $@
474 endef
476 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
477 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
478 ifeq (yes,$(build-shared))
479 install-lib-nosubdir: $(foreach so,$(install-lib.so),\
480   $(libdir)/$(patsubst $(libprefix)lib%,lib$(libprefix)%,\
481                        $(libprefix)$(so))$($(so)-version))
483 install: $(slibdir)/libc.so$(libc.so-version)
484 $(slibdir)/lib$(libprefix)c.so$(libc.so-version): $(common-objpfx)libc.so
485         $(do-install-so)
487 define do-install-so
488 $(do-install-program)
489 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
490            $(filter-out %.so,$@))
491 endef
493 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
494 $(foreach v,$(so-versions),\
495           $(libdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so
496         $(do-install-so)
497 $(foreach v,$(so-versions),\
498           $(libdir)/$(libprefix)%$v): $(common-objpfx)%.so
499         $(do-install-so)
500 endif
502 ifdef install-bin
503 $(addprefix $(bindir)/,$(install-bin)): $(bindir)/%: $(objpfx)%
504         $(do-install-program)
505 endif
506 ifdef install-sbin
507 $(addprefix $(sbindir)/,$(install-sbin)): $(sbindir)/%: $(objpfx)%
508         $(do-install-program)
509 endif
510 ifdef install-lib
511 install-lib.a := $(filter lib%.a,$(install-lib))
512 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
513 ifdef install-lib-non.a
514 $(addprefix $(libdir)/$(libprefix),$(install-lib-non.a)): \
515   $(libdir)/$(libprefix)%: $(objpfx)%
516         $(do-install)
517 endif
518 ifdef install-lib.a
519 $(install-lib.a:lib%.a=$(libdir)/lib$(libprefix)%.a): \
520   $(libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
521         $(do-install)
522         $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
523 endif
524 endif
525 ifdef install-data
526 $(addprefix $(datadir)/,$(install-data)): $(datadir)/%: %;$(do-install)
527 endif
528 headers := $(strip $(headers))
529 ifdef headers
530 $(addprefix $(includedir)/,$(headers)): \
531         $(includedir)/%: %;$(do-install)
532 endif   # headers
534 .PHONY: install-bin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
535         install-data-nosubdir install-headers-nosubdir
536 install-bin-nosubdir: $(addprefix $(bindir)/,$(install-bin))
537 install-sbin-nosubdir: $(addprefix $(sbindir)/,$(install-sbin))
538 install-lib-nosubdir: $(addprefix $(libdir)/,\
539                        $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
540                        $(addprefix $(libprefix),$(install-lib-non.a)))
541 install-data-nosubdir: $(addprefix $(datadir)/,$(install-data))
542 install-headers-nosubdir: $(addprefix $(includedir)/,$(headers))
543 install-others-nosubdir: $(install-others)
545 # We need all the `-nosubdir' targets so that `install' in the parent
546 # doesn't depend on several things which each iterate over the subdirs.
547 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
548 # subroutine.  Then in the parent `install-FOO' also causes subdir makes.
549 install-%:: install-%-nosubdir ;
551 .PHONY: install install-no-libc.a-nosubdir
552 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
553                             install-bin-nosubdir install-lib-nosubdir   \
554                             install-others-nosubdir install-sbin-nosubdir
555 install: install-no-libc.a-nosubdir
557 ifeq (yes,$(build-shared))
558 # Pattern rule to build a shared object from an archive of PIC objects.
559 # This must come after the installation rules so Make doesn't try to
560 # build shared libraries in place from the installed *_pic.a files.
561 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
562 # on other shared objects.
563 lib%.so: lib%_pic.a; $(build-shlib)
565 define build-shlib
566 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS)  \
567           -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
568           $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
569           -Wl,-rpath-link=$(common-objdir) -Wl,-rpath=$(libdir) \
570           -Wl,--whole-archive $^ $(LDLIBS-$(@F:lib%.so=%).so)
571 endef
573 # Don't try to use -lc when making libc.so itself.
574 # Also omits crti.o and crtn.o, which we do not want
575 # since we define our own `.init' section specially.
576 LDFLAGS-c.so = -nostdlib -nostartfiles
577 # Give libc.so an entry point and make it directly runnable itself.
578 LDFLAGS-c.so += -e __libc_print_version
579 # Use our own special initializer and finalizer files for libc.so.
580 elfobjdir := $(firstword $(objdir) $(..)elf)
581 $(common-objpfx)libc.so: $(elfobjdir)/soinit.so \
582                          $(common-objpfx)libc_pic.a \
583                          $(elfobjdir)/sofini.so
584         $(build-shlib)
586 ifdef libc.so-version
587 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
588         rm -f $@
589         ln -s $(<F) $@ || ln $< $@
590 endif
591 endif
594 # Command to compile $< in $(objdir) using the native libraries.
595 define native-compile
596 cwd=`pwd`; cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) \
597            $(addprefix $$cwd/,$^) -o $(@F)
598 endef
600 # Command to compile $< in $(common-objdir) using the native libraries.
601 define common-objdir-compile
602 cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=%) -o $(@F)
603 endef
605 # We always want to use configuration definitions.
606 BUILD_CFLAGS = -include $(common-objpfx)config.h
608 # Support the GNU standard name for this target.
609 .PHONY: check
610 check: tests
612 .PHONY: TAGS
613 TAGS: distinfo $(..)MakeTAGS
614         $(MAKE) $(addprefix -f ,$^)
616 .PHONY: echo-headers
617 echo-headers:
618         @echo $(headers)
621 # Common cleaning targets.
623 .PHONY: common-mostlyclean common-clean mostlyclean clean
624 clean: common-clean
625 mostlyclean: common-mostlyclean
627 # Remove the object files.
628 common-mostlyclean:
629         -rm -f $(addprefix $(objpfx),$(tests) $(others) \
630                                      $(addsuffix .o,$(tests) $(others)) \
631                                      $(addsuffix .out,$(tests)))
632         -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib))
633         -rm -f core $(objpfx)stub-$(subdir)
634         $(rmobjs)
635 define rmobjs
636 $(foreach o,$(object-suffixes),
637 -rm -f $(addprefix $(objpfx),stamp$o-$(subdir)) $(objects:.o=$o))
638 endef
640 # Also remove the dependencies and generated source files.
641 common-clean: common-mostlyclean
642         -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
644 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
645 # for each function which is a stub.  We grovel over all the .d files
646 # looking for references to source files in sysdeps/stub.  Then we grovel
647 # over each referenced source file to see what stub function it defines.
649 .PHONY: stubs # The parent Makefile calls this target.
650 stubs: $(common-objpfx)stub-$(subdir)
651 s = $(sysdep_dir)/stub
652 $(common-objpfx)stub-$(subdir): $(+depfiles)
653 # Use /dev/null since `...` might expand to empty.
654         s=`cd $s; /bin/pwd`; \
655         $(patsubst %,cd %;,$(objdir)) \
656         sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
657             `sed -n 's@^.*$s/\([a-z0-9_-]*\.c\).*$$@'"$$s"/'\1@p' \
658                  $(patsubst $(objpfx)%,%,$^) /dev/null` \
659             /dev/null > $@T
660         mv -f $@T $@
662 # Make the distribution tar file.
664 .PHONY: dist
665 dist: distinfo $(..)Make-dist
666         $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
668 # Avoid depending on source files found in sysdeps dirs,
669 # because the references affect implicit rule selection.
670 dist: $(filter-out %.c %.S %.s,$(distribute))
672 # We used to simply export all these variables, but that frequently made the
673 # environment get too large.  Instead, we write all the information into
674 # a generated makefile fragment `distinfo', and then include it with -f in
675 # the sub-make that makes the distribution (above).
676 distinfo: Makefile $(..)Makerules
677         $(distinfo-vars)
678         mv -f $@.new $@
680 define distinfo-vars
681 rm -f $@.new
682 $(foreach var,subdir sources elided-routines headers distribute \
683               dont_distribute generated others tests,
684 echo >> $@.new '$(var)  := $($(var))')
685 echo >> $@.new 'sources := $$(sources) $$(addsuffix .c,$$(elided-routines))'
686 endef
688 ifneq (,$(strip $(gpl2lgpl)))
689 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
690 # Snarf from the master source and frob the copying notice.
691 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
692         sed -f $^ > $@-tmp
693 # So I don't edit them by mistake.
694         chmod a-w $@-tmp
695         mv -f $@-tmp $@
696         test ! -d CVS || cvs commit -m'Updated from $^' $@
697 endif
698 endif