1 # Copyright (C) 1991, 1992 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 # Propagated rules for making the GNU C library.
23 This makefile requires GNU Make.
30 # If `sources' was defined by the parent makefile, undefine it so
31 # we will later get it from wildcard search in this directory.
32 ifneq "$(findstring env,$(origin sources))" ""
36 # If defined, these will determine the value of `sources'.
37 ifneq "$(findstring env,$(origin routines))" ""
40 ifneq "$(findstring env,$(origin aux))" ""
46 ifndef +included-Makeconfig
47 include $(..)Makeconfig
50 # In make v4, we'll be able to really do this right (or something like that).
52 up-one = $(patsubst %/,%,$(dir $0))
53 parents-of = $(foreach x,$0,$(notdir $x) \
54 $(ifeq $(dir $x),./,$(parents-of $(up-one $x))))
55 # Finish this someday....
59 +sysdir_pfx = $(objpfx)
64 # Right now, however, we do it with shell scripts and lots of strangeness.
65 sysdep_dir := $(..)sysdeps
67 include $(+sysdir_pfx)sysdirs
72 sysdirs := $(subst $(\n), ,$(sysdirs))
73 $(+sysdir_pfx)sysdirs: $(+sysdir_pfx)Sysnames $(..)find-sysdirs
74 (echo define sysdirs; \
75 $(dir $(word 2,$^))$(notdir $(word 2,$^)) < $<; \
77 $(+sysdir_pfx)Sysnames:
78 @echo The GNU C Library has not been configured! >&2
79 @echo Run \`configure\' to configure it before building. >&2
83 # Turn the list of sysdep names into a colon-separated list of directories
84 # under SYSDEP_DIR (the base directory for sysdep files), and tell Make to
85 # search for C and header files in those directories.
86 +sysdep_dirs := $(addprefix $(sysdep_dir)/,$(sysdirs))
88 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
90 sysdep_path := $(subst $+ ,:,$(+sysdep_dirs))
92 override VPATH := $(sysdep_path)
94 vpath %.c $(sysdep_path)
95 vpath %.S $(sysdep_path)
96 vpath %.s $(sysdep_path)
97 vpath %.h $(sysdep_path)
100 # Add -I switches to get the right sysdep directories.
101 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
102 override CPPFLAGS := $(strip $(filter-out $(+sysdep-includes),$(CPPFLAGS)) \
105 # Include any system-specific makefiles.
107 +sysdep-makefiles := $(wildcard $(addsuffix /Makefile,$(+sysdep_dirs)))
109 ifneq ($(+sysdep-makefiles),)
110 include $(+sysdir_pfx)sysdep-Makefile
111 $(+sysdir_pfx)sysdep-Makefile: $(+sysdep-makefiles)
112 (for file in $(^:$(..)%=%); do \
113 echo include "\$$(..)$$file"; done) > $@
117 # Include the generated dependencies of the sources in this directory.
118 include $(objpfx)depend-$(subdir)
121 # Maximize efficiency by minimizing the number of rules.
122 .SUFFIXES: # Clear the suffix list.
123 # Remove the RCS and SCCS rules.
129 # Add the suffixes we use.
130 .SUFFIXES: .a .o .S .s .c .h .dep .m4
132 # Make sure that object files are not removed
133 # when they are intermediates between sources and library members.
134 # This can go away with make v4.
137 # Make sure that the parent library archive is never removed.
140 # Use the verbose option of ar and tar when not running silently.
141 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
147 ARFLAGS := r$(verbose)
149 # Figure out the source filenames in this directory.
151 override sources := $(addsuffix .c,$(routines) $(aux) \
154 # This is the list of all object files, gotten by
155 # replacing every ".c" in `sources' with a ".o".
156 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
158 # The order of these rules is important.
160 ifndef .S-rule # Bletch.
161 $(objpfx)%.o: %.S $(before-compile)
162 $(COMPILE.S) $< $(OUTPUT_OPTION)
164 $(objpfx)%.o: %.s $(before-compile)
165 $(COMPILE.s) $< $(OUTPUT_OPTION)
166 $(objpfx)%.o: %.c $(before-compile)
167 $(COMPILE.c) $< $(OUTPUT_OPTION)
169 # This makes all the object files in the parent library archive.
171 .PHONY: lib lib-noranlib libobjs
174 libobjs: lib-noranlib
175 lib-noranlib: $(libc.a) ar-it
176 $(libc.a): %: $(addprefix %,$(patsubst $(objpfx)%,(%),$(objects)))
177 # $(AR) $(ARFLAGS) $@ $(patsubst $@(%),%,$?)
179 define +libc_lock_open
180 @. $(..)libc-lock-open
182 define +libc_lock_close
183 @rm -f $(..)LOCK-libc.a
186 # Temporary until I get a better solution.
191 cd $(objdir); $(AR) ru$(verbose) libc.a $(patsubst $(objpfx)%,%,$^)
193 $(AR) u$(verbose) $(libc.a) $^
195 # $(+libc_lock_close)
198 $(patsubst %,$(libc.a)(%),$(notdir $(objects))): $(libc.a)(%): $(objpfx)%;
202 # This makes all the object files.
204 objects objs: $(objects)
206 # Make the ansi and trad versions of the headers from the ansidecl sources.
208 headers := $(headers) $(sysdep_headers)
211 +headers_pfx = $(objpfx)
216 +header_dirs := $(filter-out ./,$(dir $(headers)))
219 headers: $(+headers_pfx)ansi/ \
220 $(addprefix $(+headers_pfx)ansi/,$(+header_dirs) $(headers)) \
221 $(+headers_pfx)trad/ \
222 $(addprefix $(+headers_pfx)trad/,$(+header_dirs) $(headers))
225 # mkdir isn't smart enough to strip a trailing /.
228 $(+headers_pfx)ansi/%: % $(..)ansidecl.m4;$(+ansideclificate)
229 $(+headers_pfx)trad/%: % $(..)ansidecl.m4;$(+ansideclificate)
231 # The bit with awk is to remove all the newlines from
232 # ansidecl.m4, so the output doesn't have 20 blank
233 # lines at the beginning.
234 +ansideclificate = $(dir $(..)ansidecl)$(notdir $(..)ansidecl) \
235 -$(firstword $(subst /, ,$(@:$(+headers_pfx)%=%))) $< > $@
243 $(+mkdep) $(CPPFLAGS) $< | sed 's,$*\.o,$(@:.dep=.o) $@,' > $@
246 # N.B.: The order of these two rules is important.
247 $(objpfx)%.dep: %.S $(before-compile)
249 $(objpfx)%.dep: %.c $(before-compile)
252 +depfiles := $(strip $(sources:.c=.dep) $(addsuffix .dep,$(others) $(tests)))
253 +depfiles := $(addprefix $(objpfx),$(+depfiles))
254 $(objpfx)depend-$(subdir): Makefile
256 (for file in $(patsubst $(objpfx)%,%,$(+depfiles)); do \
257 echo "include $(objpfx)$$file"; \