# Copyright (C) 1991, 92, 93, 94, 95, 96 Free Software Foundation, Inc. # This file is part of the GNU C Library. # The GNU C Library is free software; you can redistribute it and/or # modify it under the terms of the GNU Library General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # The GNU C Library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Library General Public License for more details. # You should have received a copy of the GNU Library General Public # License along with the GNU C Library; see the file COPYING.LIB. If # not, write to the Free Software Foundation, Inc., 675 Mass Ave, # Cambridge, MA 02139, USA. # # Common rules for making the GNU C library. This file is included # by the top-level Makefile and by all subdirectory makefiles # (through Rules). # ifneq (,) This makefile requires GNU Make. endif ifdef subdir .. := ../ endif # subdir # If `sources' was defined by the parent makefile, undefine it so # we will later get it from wildcard search in this directory. ifneq "$(findstring env,$(origin sources))" "" sources := endif headers := $(headers) $(sysdep_headers) oPATH := $(PATH) PATH := this definition should take precedence over $(oPATH) ifeq ($(PATH),$(oPATH)) You must not use the -e flag when building the GNU C library. else PATH := $(oPATH) endif ifndef +included-Makeconfig include $(..)Makeconfig endif # `configure' writes a definition of `config-sysdirs' in `config.make'. sysdirs = $(config-sysdirs) +sysdir_pfx = $(common-objpfx) export sysdirs := $(sysdirs) +sysdep_dirs := $(addprefix $(sysdep_dir)/,$(sysdirs)) ifdef objdir +sysdep_dirs := $(objdir) $(+sysdep_dirs) endif # Add -I switches to get the right sysdep directories. # `+includes' in Makeconfig references $(+sysdep-includes). +sysdep-includes := $(addprefix -I,$(+sysdep_dirs)) # The name of the symbol table archive member. The default is suitable for # BSD style archives. It can be overridden in sysdep Makefiles when SYSV # style archive are used. ifeq (no,$(elf)) ar-symtab-name = __.SYMDEF else ar-symtab-name = # The null name is used in ELF archives. endif # Include any system-specific makefiles. # This is here so things in sysdep Makefiles can easily depend on foo.h as # appropriate and not worry about where foo.h comes from, which may be # system dependent and not known by that Makefile. vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) \ $(addprefix $(sysdep_dir)/,$(sysdirs)) \ $(..))) # Some sysdep makefiles use this to distinguish being included here from # being included individually by a subdir makefile (hurd/Makefile needs this). in-Makerules := yes ifndef avoid-generated -include $(+sysdir_pfx)sysd-Makefile ifneq ($(sysd-Makefile-sysdirs),$(sysdirs)) sysd-Makefile-force = FORCE FORCE: endif $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \ $(sysd-Makefile-force) -@rm -f $@T (echo 'sysd-Makefile-sysdirs := $(sysdirs)'; \ for dir in $(sysdirs); do \ file=sysdeps/$$dir/Makefile; \ if [ -f $(..)$$file ]; then \ echo include "\$$(..)$$file"; \ else true; fi; \ done; \ echo 'sysd-Makefile-done=t') > $@T mv -f $@T $@ endif ifndef sysd-Makefile-done # Don't do deps until this exists, because it might change the sources list. no_deps=t endif # Reorder before-compile so that mach things come first, and hurd things # second, before all else. The mach and hurd subdirectories have many # generated header files which the much of rest of the library depends on, # so it is best to build them first (and mach before hurd, at that). before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\ $(before-compile)) \ $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\ $(before-compile)) # Remove existing files from `before-compile'. Things are added there when # they must exist for dependency generation to work right, but once they # exist there is no further need for every single file to depend on them, # and those gratuitous dependencies result in many gratuitous # recompilations. before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile)) # Don't let any before-compile file be an intermediate and get removed. ifdef before-compile $(before-compile): endif # Generate an ordered list of implicit rules which find the source files in # each sysdep directory. The old method was to use vpath to search all the # sysdep directories. However, that had the problem that a .S file in a # later directory would be chosen over a .c file in an earlier directory, # which does not preserve the desired sysdeps ordering behavior. # When making the list of .d files to include, we can't know which ones # have source in .s files, and thus do not in fact need a .d file. # So we must define rules to make .d files for .s files. define make-dummy-dep $(addprefix ln $(objpfx)dummy.d ,$(filter-out $(wildcard $@),$@)) endef $(objpfx)dummy.d: echo '# .s files cannot contain includes, so they need no deps.' > $@ # It matters that this set of rules, for compiling from sources in # the current directory (the $srcdir/$subdir) come before the # generated sysdep rules in included from sysd-rules below. When # compiling in the source tree, generated sources go into the current # directory, and those should be chosen before any sources in sysdeps. $(objpfx)%.o: %.S $(before-compile); $(compile-command.S) $(objpfx)%.so: %.S $(before-compile); $(compile-command.S) $(objpfx)%.po: %.S $(before-compile); $(compile-command.S) $(objpfx)%.go: %.S $(before-compile); $(compile-command.S) $(objpfx)%.d: %.S $(before-compile); $(+make-deps) $(objpfx)%.o: %.s $(before-compile); $(compile-command.s) $(objpfx)%.so: %.s $(before-compile); $(compile-command.s) $(objpfx)%.po: %.s $(before-compile); $(compile-command.s) $(objpfx)%.go: %.s $(before-compile); $(compile-command.s) $(objpfx)%.d: %.s $(objpfx)dummy.d; $(make-dummy-dep) $(objpfx)%.o: %.c $(before-compile); $(compile-command.c) $(objpfx)%.so: %.c $(before-compile); $(compile-command.c) $(objpfx)%.po: %.c $(before-compile); $(compile-command.c) $(objpfx)%.go: %.c $(before-compile); $(compile-command.c) $(objpfx)%.d: %.c $(before-compile); $(+make-deps) # Omit the objpfx rules when building in the source tree, because # objpfx is empty and so these rules just override the ones above. ifdef objpfx # Define first rules to find the source files in $(objpfx). # Generated source files will end up there. $(objpfx)%.o: $(objpfx)%.S $(before-compile); $(compile-command.S) $(objpfx)%.so: $(objpfx)%.S $(before-compile); $(compile-command.S) $(objpfx)%.po: $(objpfx)%.S $(before-compile); $(compile-command.S) $(objpfx)%.go: $(objpfx)%.S $(before-compile); $(compile-command.S) $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps) $(objpfx)%.o: $(objpfx)%.s $(before-compile); $(compile-command.s) $(objpfx)%.so: $(objpfx)%.s $(before-compile); $(compile-command.s) $(objpfx)%.po: $(objpfx)%.s $(before-compile); $(compile-command.s) $(objpfx)%.go: $(objpfx)%.s $(before-compile); $(compile-command.s) $(objpfx)%.d: $(objpfx)%.s $(objpfx)dummy.d; $(make-dummy-dep) $(objpfx)%.o: $(objpfx)%.c $(before-compile); $(compile-command.c) $(objpfx)%.so: $(objpfx)%.c $(before-compile); $(compile-command.c) $(objpfx)%.po: $(objpfx)%.c $(before-compile); $(compile-command.c) $(objpfx)%.go: $(objpfx)%.c $(before-compile); $(compile-command.c) $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps) endif # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard # patterns matching sysdep directories whose assembly source files should # be suppressed. ifdef inhibit-sysdep-asm define open-check-inhibit-asm case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *) endef close-check-inhibit-asm = ;; esac ; endif # Don't include sysd-rules until sysd-Makefile is already there and has been # included. It might define inhibit-sysdep-asm, which would affect the # contents of sysd-rules. ifdef sysd-Makefile-done -include $(+sysdir_pfx)sysd-rules ifneq ($(sysd-rules-sysdirs),$(sysdirs)) # The value of $(sysdirs) the sysd-rules was computed for # differs from the one we are using now. So force a rebuild of sysd-rules. sysd-rules-force = FORCE FORCE: endif endif $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \ $(wildcard $(foreach dir,$(sysdirs),\ $(sysdep_dir)/$(dir)/Makefile))\ $(sysd-rules-force) -@rm -f $@T (echo 'sysd-rules-sysdirs := $(sysdirs)'; \ for sysdir in $(sysdirs); do \ dir="\$$(sysdep_dir)/$$sysdir"; \ for o in $(object-suffixes); do \ $(open-check-inhibit-asm) \ echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \ \$$(compile-command.S)"; \ echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \ \$$(compile-command.s)"; \ $(close-check-inhibit-asm) \ echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \ \$$(compile-command.c)"; \ done; \ $(open-check-inhibit-asm) \ echo "\$$(objpfx)%.d: $$dir/%.s \$$(objpfx)dummy.d; \ \$$(make-dummy-dep)"; \ echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \ \$$(+make-deps)"; \ $(close-check-inhibit-asm) \ echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \ \$$(+make-deps)"; \ done; \ echo 'sysd-rules-done = t') > $@T mv -f $@T $@ ifndef sysd-rules-done # Don't do deps until this exists, because it provides rules to make the deps. no_deps=t endif ifndef compile-command.S compile-command.S = $(compile.S) $(OUTPUT_OPTION) endif ifndef compile-command.s compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION) endif ifndef compile-command.c compile-command.c = $(compile.c) $(OUTPUT_OPTION) endif # GCC can grok options after the file name, and it looks nicer that way. compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS) compile.S = $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) COMPILE.S = $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS) COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS) # We need this for the output to go in the right place. It will default to # empty if make was configured to work with a cc that can't grok -c and -o # together. You can't compile the C library with such a compiler. OUTPUT_OPTION = -o $@ S-CPPFLAGS = $(asm-CPPFLAGS) define +make-deps -@rm -f $@ $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \ sed -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(object-suffixes),$(@:.d=$o)) $@,' \ $(sed-remove-objpfx) > $(@:.d=.T) mv -f $(@:.d=.T) $@ endef ifneq (,$(objpfx)) sed-remove-objpfx = -e 's@ $(subst .,\.,\ $(subst @,\@,$(objpfx)))@ $$(objpfx)@g' \ -e 's@^$(subst .,\.,$(subst @,\@,$(objpfx)))@$$(objpfx)@g' endif # Figure out the source filenames in this directory. override sources := $(addsuffix .c,$(filter-out $(elided-routines),\ $(routines) $(aux) \ $(sysdep_routines))) sysdep_routines := $(sysdep_routines) # This is the list of all object files, gotten by # replacing every ".c" in `sources' with a ".o". override objects := $(addprefix $(objpfx),$(sources:.c=.o)) # This variable is used in ``include $(o-iterator)'' after defining # $(o-iterator-doit) to produce some desired rule using $o for the object # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy # is produced for each object suffix in use. o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes)) # The makefile may define $(extra-libs) with `libfoo libbar' # to build libfoo.a et al from the modules listed in $(libfoo-routines). ifdef extra-libs # extra-lib.mk is included once for each extra lib to define rules # to build it, and to add its objects to the various variables. # During its evaluation, $(lib) is set to the name of the library. extra-libs-left := $(extra-libs) include $(patsubst %,$(..)extra-lib.mk,$(extra-libs)) endif +depfiles := $(strip $(sources:.c=.d) \ $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.so=.o))) \ $(addsuffix .d,$(others) $(tests))) +depfiles := $(addprefix $(objpfx),\ $(filter-out $(addsuffix .d,$(omit-deps)),\ $(+depfiles))) ifdef +depfiles ifneq ($(no_deps),t) -include $(+depfiles) endif endif # Maximize efficiency by minimizing the number of rules. .SUFFIXES: # Clear the suffix list. # Add the suffixes we use. .SUFFIXES: .a $(object-suffixes) .S .s .c .h .d # Generic rule for making directories. %/: # mkdir isn't smart enough to strip a trailing /. mkdir $(@:%/=%) # Make sure that object files are not removed # when they are intermediates between sources and library members. .PRECIOUS: $(addprefix $(objpfx)%,$(object-suffixes)) # Make sure that the parent library archive is never removed. .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c)) # Use the verbose option of ar and tar when not running silently. ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s verbose := v else # -s verbose := endif # not -s ARFLAGS := r$(verbose) # This makes all the object files in the parent library archive. .PHONY: lib libobjs lib-noranlib lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c)) # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib. lib%.a: lib%.a($(ar-symtab-name)) ; libobjs: $(foreach o,$(object-suffixes),\ $(common-objpfx)$(patsubst %,$(libtype$o),c)(\ $(notdir $(objects:.o=$o)))) lib-noranlib: libobjs others: $(addprefix $(objpfx),$(install-lib)) ifdef objects # Define a pattern rule that will match many targets libc.a(foo.%), for # each foo.o in $(objects) (% will just happen always to match `o'). This is # the only way to define a rule that updates many targets at once with one # sequence of commands. We in fact define the pattern rule to match # targets libc.a(foo.%), libc_pic.a(foo.%), etc, to avoid repeating the rule. # Each match will only ever be called upon to make member objects of # the appropriate type in each library (i.e. libc_pic.a(foo.so)). $(foreach l,$(libtypes),\ $(common-objpfx)$(patsubst %,$l,c)($(notdir $(objects:.o=.%)))): \ $(objpfx)stamp.%-$(subdir) ; # The pattern rule tells Make to remake $(objpfx)stamp.%-$(subdir) as # the way to update all the foo.% object files in $(objects). # Now we define a static pattern rule to update each # $(objpfx)stamp.SUFFIX-$(subdir) timestamp file; # these rules (one explicit rule is generated for each object suffix) # will update the parent archive with $(foreach o,$(object-suffixes),$(objpfx)stamp$o-$(subdir)): \ $(objpfx)stamp%-$(subdir): $(objects:.o=%) $(patsubst %,cd %;,$(objdir)) \ $(AR) cru$(verbose) ${O%-lib} \ $(patsubst $(objpfx)%,%,$^) # `touch' won't let me touch a world-writable file I don't own. Sigh. rm -f $@ touch $@ ifdef subdir O%-lib = $(filter ../,$(firstword $(objdir) ../))$(patsubst %,$(libtype$*),c) else O%-lib = $(patsubst %,$(libtype$*),c) endif endif # Rules to update the $(ar-symtab-name) member with ranlib, # one for each object flavor. define o-iterator-doit $(common-objpfx)$(patsubst %,$(libtype$o),c)($(ar-symtab-name)): \ $(common-objpfx)$(patsubst %,$(libtype$o),c)(\ $(patsubst $(objpfx)%.o,%$o,$(objects))) \ $(filter subdir_lib,$(firstword $(subdir) subdir_lib)); \ $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c) endef object-suffixes-left = $(object-suffixes) include $(o-iterator) # This makes all the object files. .PHONY: objects objs objects objs: $(foreach o,$(object-suffixes),$(objects:.o=$o)) \ $(addprefix $(objpfx),$(extra-objs)) # Canned sequence for building an extra library archive. define build-extra-lib $(patsubst %,cd %;,$(objdir)) \ $(AR) cru$(verbose) $(@:$(objpfx)%=%) \ $(patsubst $(objpfx)%,%,$^) $(RANLIB) $@ endef # Shared library building. ifeq (yes,$(build-shared)) # Process the shlib-versions file, which tells us what shared library # version numbers to use when we install shared objects on this system. -include $(common-objpfx)soversions.mk $(common-objpfx)soversions.mk: $(..)shlib-versions $(..)Makerules \ $(common-objpfx)config.make sed 's/#.*$$//' $< | while read conf versions; do \ test -n "$$versions" || continue; \ case '$(config-machine)-$(config-vendor)-$(config-os)' in $$conf)\ for v in $$versions; do \ lib="$${v%%=*}"; if eval "test -z \"\$$vers_lib$$lib\""; then \ eval vers_lib$${lib}=yes; \ echo $$lib.so-version=.$${v##$$lib=}; fi; \ done ;; esac; done > $@T mv -f $@T $@ # Get $(version) defined with the release version number. -include $(common-objpfx)version.mk # Pattern rule to build a shared object from an archive of PIC objects. # This must come after the installation rules so Make doesn't try to # build shared libraries in place from the installed *_pic.a files. # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies # on other shared objects. lib%.so: lib%_pic.a; $(build-shlib) ifeq ($(have-no-whole-archive),yes) no-whole-archive = -Wl,--no-whole-archive else no-whole-archive = endif define build-shlib $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS) \ -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \ $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \ -Wl,-rpath-link=$(common-objdir) \ -Wl,--whole-archive $^ $(no-whole-archive) \ $(LDLIBS-$(@F:lib%.so=%).so) endef # Don't try to use -lc when making libc.so itself. # Also omits crti.o and crtn.o, which we do not want # since we define our own `.init' section specially. LDFLAGS-c.so = -nostdlib -nostartfiles # Give libc.so an entry point and make it directly runnable itself. LDFLAGS-c.so += -e __libc_print_version # Use our own special initializer and finalizer files for libc.so. elfobjdir := $(firstword $(objdir) $(..)elf) $(common-objpfx)libc.so: $(elfobjdir)/soinit.so \ $(common-objpfx)libc_pic.a \ $(elfobjdir)/sofini.so $(build-shlib) ifdef libc.so-version $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so rm -f $@ ln -s $( libc.so.N (e.g. libc.so.6) # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so) $(slibdir)/libc.so$(libc.so-version): $(slibdir)/libc-$(version).so $(make-link) $(slibdir)/libc-$(version).so: $(common-objpfx)libc.so; $(do-install-program) install: $(slibdir)/libc.so$(libc.so-version) ifndef subdir # What we install as libc.so for programs to link against is in fact an # archive. It contains the various $(static-only-routines) objects, and # the special object libc-syms.so that contains just the dynamic symbol # table of the shared libc object. install: $(libdir)/libc.so $(libdir)/libc.so: $(common-objpfx)libc-syms.so subdir_install $(AR) crvs $@ $< `cat $(addprefix $(common-objpfx)sor-,$(subdirs))` # Extract from the shared object file just the dynamic symbol table # needed to link against the shared library. $(common-objpfx)libc-syms.so: $(common-objpfx)libc.so AWK='$(AWK)' OBJCOPY='$(OBJCOPY)' OBJDUMP='$(OBJDUMP)' \ ./extract-dynsym $< $@ ifndef subdir generated += libc-syms.so endif endif else install: $(slibdir)/libc.so $(slibdir)/libc.so: $(common-objpfx)libc.so; $(do-install-program) endif ifneq (,$(versioned)) # Produce three sets of rules as above for all the smaller versioned libraries. define o-iterator-doit $(libdir)/$o: $(libdir)/$o$($o-version); $$(make-link) endef object-suffixes-left := $(versioned) include $(..)o-iterator.mk define o-iterator-doit $(libdir)/$o$($o-version): $(libdir)/$(o:.so=)-$(version).so; $$(make-link) endef object-suffixes-left := $(versioned) include $(..)o-iterator.mk define o-iterator-doit $(libdir)/$(o:.so=)-$(version).so: $(objpfx)$o; $$(do-install-program) endef object-suffixes-left := $(versioned) include $(..)o-iterator.mk endif define do-install-so $(do-install-program) $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$( $(@F)T mv -f $@T $@ # Make the distribution tar file. .PHONY: dist dist: distinfo $(..)Make-dist $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args) # Avoid depending on source files found in sysdeps dirs, # because the references affect implicit rule selection. dist: $(filter-out %.c %.S %.s,$(distribute)) # We used to simply export all these variables, but that frequently made the # environment get too large. Instead, we write all the information into # a generated makefile fragment `distinfo', and then include it with -f in # the sub-make that makes the distribution (above). distinfo: Makefile $(..)Makerules $(distinfo-vars) mv -f $@.new $@ define distinfo-vars rm -f $@.new $(foreach var,subdir subdir-dirs sources elided-routines headers distribute \ dont_distribute generated others tests, echo >> $@.new '$(var) := $($(var))') echo >> $@.new 'sources := $$(sources) $$(addsuffix .c,$$(elided-routines))' endef ifneq (,$(strip $(gpl2lgpl))) ifneq (,$(wildcard $(..)gpl2lgpl.sed)) # Snarf from the master source and frob the copying notice. $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/% sed -f $^ > $@-tmp # So I don't edit them by mistake. chmod a-w $@-tmp mv -f $@-tmp $@ test ! -d CVS || cvs commit -m'Updated from $^' $@ endif endif