1 # Copyright (C) 1991, 1992, 1993, 1994 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
25 This makefile requires GNU Make.
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))" ""
39 headers := $(headers) $(sysdep_headers)
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.
49 ifndef +included-Makeconfig
50 include $(..)Makeconfig
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))
62 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
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)) \
78 ifeq ($(wildcard $(+sysdir_pfx)sysd-Makefile),)
79 # Don't do deps until this exists, because it might change the sources list.
83 # Some sysdep makefiles use this to distinguish being included here from
84 # being included individually by a subdir makefile (hurd/Makefile needs this).
87 include $(+sysdir_pfx)sysd-Makefile
88 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules
90 (for dir in $(sysdirs); do \
91 file=sysdeps/$$dir/Makefile; \
92 if [ -f $(..)$$file ]; then \
93 echo include "\$$(..)$$file"; \
96 echo 'sysd-Makefile-done=t') > $@T
100 # Reorder before-compile so that mach things come first, and hurd things
101 # second, before all else. The mach and hurd subdirectories have many
102 # generated header files which the much of rest of the library depends on,
103 # so it is best to build them first (and mach before hurd, at that).
104 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
106 $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
109 # Remove existing files from `before-compile'. Things are added there when
110 # they must exist for dependency generation to work right, but once they
111 # exist there is no further need for every single file to depend on them,
112 # and those gratuitous dependencies result in many gratuitous
114 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
116 # Don't let any before-compile file be an intermediate and get removed.
121 # Generate an ordered list of implicit rules which find the source files in
122 # each sysdep directory. The old method was to use vpath to search all the
123 # sysdep directories. However, that had the problem that a .S file in a
124 # later directory would be chosen over a .c file in an earlier directory,
125 # which does not preserve the desired sysdeps ordering behavior.
127 # When making the list of .d files to include, we can't know which ones
128 # have source in .s files, and thus do not in fact need a .d file.
129 # So we must define rules to make .d files for .s files.
130 define make-dummy-dep
131 $(addprefix ln $(objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
134 echo '# .s files cannot contain includes, so they need no deps.' > $@
136 # It matters that this set of rules, for compiling from sources in
137 # the current directory (the $srcdir/$subdir) come before the
138 # generated sysdep rules in included from sysd-rules below. When
139 # compiling in the source tree, generated sources go into the current
140 # directory, and those should be chosen before any sources in sysdeps.
141 $(objpfx)%.o: %.S $(before-compile); $(compile-command.S)
142 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
143 $(objpfx)%.o: %.s $(before-compile); $(compile-command.s)
144 $(objpfx)%.d: %.s $(objpfx)dummy.d; $(make-dummy-dep)
145 $(objpfx)%.o: %.c $(before-compile); $(compile-command.c)
146 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
148 # Omit the objpfx rules when building in the source tree, because
149 # objpfx is empty and so these rules just override the ones above.
151 # Define first rules to find the source files in $(objpfx).
152 # Generated source files will end up there.
153 $(objpfx)%.o: $(objpfx)%.S $(before-compile); $(compile-command.S)
154 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
155 $(objpfx)%.o: $(objpfx)%.s $(before-compile); $(compile-command.s)
156 $(objpfx)%.d: $(objpfx)%.s $(objpfx)dummy.d; $(make-dummy-dep)
157 $(objpfx)%.o: $(objpfx)%.c $(before-compile); $(compile-command.c)
158 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
161 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
162 # patterns matching sysdep directories whose assembly source files should
164 ifdef inhibit-sysdep-asm
165 define open-check-inhibit-asm
166 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
168 close-check-inhibit-asm = ;; esac
171 # Don't include sysd-rules until sysd-Makefile is already there and has been
172 # included. It might define inhibit-sysdep-asm, which would affect the
173 # contents of sysd-rules.
174 ifdef sysd-Makefile-done
175 include $(+sysdir_pfx)sysd-rules
177 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
178 $(wildcard $(foreach dir,$(sysdirs),\
179 $(sysdep_dir)/$(dir)/Makefile))
181 (for sysdir in $(sysdirs); do \
182 dir="\$$(sysdep_dir)/$$sysdir"; \
183 $(open-check-inhibit-asm) \
184 echo "\$$(objpfx)%.o: $$dir/%.S \$$(before-compile); \
185 \$$(compile-command.S)"; \
186 echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
188 echo "\$$(objpfx)%.o: $$dir/%.s \$$(before-compile); \
189 \$$(compile-command.s)"; \
190 echo "\$$(objpfx)%.d: $$dir/%.s \$$(objpfx)dummy.d; \
191 \$$(make-dummy-dep)" $(close-check-inhibit-asm); \
192 echo "\$$(objpfx)%.o: $$dir/%.c \$$(before-compile); \
193 \$$(compile-command.c)"; \
194 echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
199 ifndef compile-command.S
200 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
202 ifndef compile-command.s
203 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
205 ifndef compile-command.c
206 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
209 ifeq ($(notdir $(firstword $(CC))),gcc)
210 # GCC can grok options after the file name, and it looks nicer that way.
211 compile.S = $(CC) $< -c $(CPPFLAGS) $(asm-CPPFLAGS)
212 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
214 compile.S = $(COMPILE.S) $(asm-CPPFLAGS) $<
215 compile.c = $(COMPILE.c) $<
220 # We need this for the output to go in the right place. It will default to
221 # empty if make was configured to work with a cc that can't grok -c and -o
222 # together. You can't compile the C library with such a compiler.
223 OUTPUT_OPTION = -o $@
227 S-CPPFLAGS = $(asm-CPPFLAGS)
230 $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
231 sed -e 's,$*\.o,$(@:.d=.o) $@,' $(sed-remove-objpfx) > $(@:.d=.T)
235 sed-remove-objpfx = -e 's@ $(subst @,\@,$(objpfx))@ $$(objpfx)@g' \
236 -e 's@^$(subst @,\@,$(objpfx))@$$(objpfx)@g'
239 # Figure out the source filenames in this directory.
241 override sources := $(addsuffix .c,$(routines) $(aux) \
243 sysdep_routines := $(sysdep_routines)
245 # This is the list of all object files, gotten by
246 # replacing every ".c" in `sources' with a ".o".
247 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
249 +depfiles := $(strip $(sources:.c=.d) \
250 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs))) \
251 $(addsuffix .d,$(others) $(tests)))
252 +depfiles := $(addprefix $(objpfx),\
253 $(filter-out $(addsuffix .d,$(omit-deps)),\
256 $(objpfx)depend-$(subdir): Makefile
258 for file in $(+depfiles:$(objpfx)%=%); do \
259 echo "include \$$(objpfx)$$file"; \
267 # Include the generated dependencies of the sources in this directory.
268 include $(objpfx)depend-$(subdir)
271 # Maximize efficiency by minimizing the number of rules.
272 .SUFFIXES: # Clear the suffix list.
273 # Add the suffixes we use.
274 .SUFFIXES: .a .o .S .s .c .h .d
276 # Generic rule for making directories.
278 # mkdir isn't smart enough to strip a trailing /.
281 # Make sure that object files are not removed
282 # when they are intermediates between sources and library members.
283 # This can go away with make v4.
286 # Make sure that the parent library archive is never removed.
289 # Use the verbose option of ar and tar when not running silently.
290 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
296 ARFLAGS := r$(verbose)
298 # This makes all the object files in the parent library archive.
300 .PHONY: lib libobjs lib-noranlib
301 $(libc.a): $(libc.a)(__.SYMDEF)
304 +libobjs := $(patsubst %,$(libc.a)(%),$(notdir $(objects)))
306 lib-noranlib: libobjs
308 # Define a pattern rule that will match many targets libc.%(foo.o), for
309 # each foo in $(objects) (% will just happen always to match `a'). This is
310 # the only way to define a rule that updates many targets at once with one
311 # sequence of commands.
313 $(patsubst %,$(libc.a:a=)\%(%),$(notdir $(objects))): $(objpfx)stamp-$(subdir);
314 $(objpfx)stamp-$(subdir): $(objects)
317 cd $(objdir); $(AR) cru$(verbose) libc.a $(patsubst $(objpfx)%,%,$^)
319 $(AR) cru$(verbose) $(..)libc.a $^
321 # $(+libc_lock_close)
325 $(libc.a)(__.SYMDEF): $(+libobjs)
328 define +libc_lock_open
329 @. $(..)libc-lock-open
331 define +libc_lock_close
332 @rm -f $(..)LOCK-libc.a
335 # This makes all the object files.
337 objects objs: $(objects)
341 # $(install-lib) are installed from the object directory into $(libdir);
342 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
343 # unless they also appear in $(non-lib.a). $(install-data) are installed
344 # as they are into $(datadir). $(headers) are installed as they are in
345 # $(includedir). $(install-bin) and $(install-sbin) are installed from the
346 # object directory into $(bindir) and $(sbindir), respectively.
347 # $(install-others) are absolute path names of files to install; rules to
348 # install them are defined elsewhere.
350 # The simple library name to install libc.a under.
351 # This could be defined by a sysdep Makefile.
357 $(make-target-directory)
358 $(INSTALL_DATA) $< $@
361 # Make the target directory if it doesn't exist. Because of make's
362 # directory cache, this will produce the `mkdir' command when the directory
363 # already exists, if it didn't exist at the start of the `make' run. The
364 # `-' prefix ignores errors from mkdir, so there will just be some
365 # gratuitous but harmless `File exists' messages.
366 define make-target-directory
367 $(addprefix -mkdir ,$(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
370 # Any directory (parent or subdir) that has any object files to build
371 # should install libc.a; this way "make install" in a subdir is guaranteed
372 # to install everything it changes.
374 install: $(libdir)/lib$(libprefix)$(libc-name).a
375 # We avoid depending on lib-noranlib because that makes the parent make
376 # subdir_lib in all the subdirs, when the make install run they do will
377 # update the library anyway. Running ranlib after installing makes the
378 # __.SYMDEF time stamp up to date, which avoids messages from some linkers.
379 # Depending on subdir_install gets all the subdirs to update the library,
380 # and is optimal for `make install' at top level.
381 $(libdir)/lib$(libprefix)$(libc-name).a: libobjs subdir_install
382 $(make-target-directory)
383 $(INSTALL_DATA) $(libc.a) $@
388 $(addprefix $(bindir)/,$(install-bin)): $(bindir)/%: $(objpfx)%
389 $(make-target-directory)
390 $(INSTALL_PROGRAM) $< $@
393 $(addprefix $(sbindir)/,$(install-sbin)): $(sbindir)/%: $(objpfx)%
394 $(make-target-directory)
395 $(INSTALL_PROGRAM) $< $@
398 install-lib.a := $(filter-out $(non-lib.a),$(filter lib%.a,$(install-lib)))
399 install-lib-non.a := $(filter-out lib%.a,$(install-lib)) $(non-lib.a)
400 ifdef install-lib-non.a
401 $(addprefix $(libdir)/$(libprefix),$(install-lib-non.a)): \
402 $(libdir)/$(libprefix)%: $(objpfx)%
406 $(install-lib.a:lib%.a=$(libdir)/lib$(libprefix)%.a): \
407 $(libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
413 $(addprefix $(datadir)/,$(install-data)): $(datadir)/%: %;$(do-install)
415 headers := $(strip $(headers))
417 $(addprefix $(includedir)/,$(headers)): \
418 $(includedir)/%: %;$(do-install)
421 .PHONY: install-bin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
422 install-data-nosubdir install-headers-nosubdir
423 install-bin-nosubdir: $(addprefix $(bindir)/,$(install-bin))
424 install-sbin-nosubdir: $(addprefix $(sbindir)/,$(install-sbin))
425 install-lib-nosubdir: $(addprefix $(libdir)/,\
426 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
427 $(addprefix $(libprefix),$(install-lib-non.a)))
428 install-data-nosubdir: $(addprefix $(datadir)/,$(install-data))
429 install-headers-nosubdir: $(addprefix $(includedir)/,$(headers))
430 install-others-nosubdir: $(install-others)
432 # We need all the `-nosubdir' targets so that `install' in the parent
433 # doesn't depend on several things which each iterate over the subdirs.
434 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
435 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
436 install-%:: install-%-nosubdir ;
438 .PHONY: install install-no-libc.a-nosubdir
439 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
440 install-bin-nosubdir install-lib-nosubdir \
441 install-others-nosubdir install-sbin-nosubdir
442 install: install-no-libc.a-nosubdir
444 # Command to compile $< in $(objdir) using the native libraries.
445 define native-compile
446 cwd=`pwd`; cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) \
447 $(addprefix $$cwd/,$^) -o $(@F)
450 # Command to compile $< in $(common-objdir) using the native libraries.
451 define common-objdir-compile
452 cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=%) -o $(@F)
455 # We always want to use configuration -D switches.
456 BUILD_CFLAGS = $(config-defines)
458 # Support the GNU standard name for this target.
463 TAGS: distinfo $(..)MakeTAGS
464 $(MAKE) $(addprefix -f ,$^)
471 # Common cleaning targets.
473 .PHONY: common-mostlyclean common-clean mostlyclean clean
475 mostlyclean: common-mostlyclean
477 # Remove the object files.
479 -rm -f $(addprefix $(objpfx),$(tests) $(others) \
480 $(addsuffix .o,$(tests) $(others)))
481 -rm -f $(objects) $(addprefix $(objpfx),$(extra-objs) stamp-$(subdir))
484 # Also remove the dependencies and generated source files.
485 common-clean: common-mostlyclean
486 -rm -f $(objpfx)depend-$(subdir) $(+depfiles)
487 -rm -f $(addprefix $(objpfx),$(generated))
489 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
490 # for each function which is a stub. We grovel over all the .d files
491 # looking for references to source files in sysdeps/stub. Then we grovel
492 # over each referenced source file to see what stub function it defines.
494 .PHONY: stubs # The parent Makefile calls this target.
495 stubs: $(common-objpfx)stub-$(subdir)
496 $(common-objpfx)stub-$(subdir): $(+depfiles)
497 # Use /dev/null since `...` might expand to empty.
498 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
499 `sed -n 's@^.*\($(sysdep_dir)/stub/[a-z0-9_]*\.c\).*$$@\1@p' \
504 # Make the distribution tar file.
507 dist: distinfo $(..)Make-dist
508 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
512 # We used to simply export all these variables, but that frequently made the
513 # environment get too large. Instead, we write all the information into
514 # a generated makefile fragment `distinfo', and then include it with -f in
515 # the sub-make that makes the distribution (above).
516 distinfo: Makefile $(..)Makerules
522 $(foreach var,subdir sources elided-routines headers distribute \
523 dont_distribute generated others tests,
524 echo >> $@.new '$(var) := $($(var))')
525 echo >> $@.new 'sources := $$(sources) $$(addsuffix .c,$$(elided-routines))'
528 ifneq (,$(strip $(gpl2lgpl)))
529 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
530 # Snarf from the master source and frob the copying notice.
531 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
533 # So I don't edit them by mistake.