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 ifneq ($(findstring e,$(MAKEFLAGS)),)
37 You must not use the -e flag when building the GNU C library.
40 # If defined, these will determine the value of `sources'.
41 ifneq "$(findstring env,$(origin routines))" ""
44 ifneq "$(findstring env,$(origin aux))" ""
50 ifndef +included-Makeconfig
51 include $(..)Makeconfig
54 # In make v4, we'll be able to really do this right (or something like that).
56 up-one = $(patsubst %/,%,$(dir $0))
57 parents-of = $(foreach x,$0,$(notdir $x) \
58 $(ifeq $(dir $x),./,$(parents-of $(up-one $x))))
59 # Finish this someday....
63 +sysdir_pfx = $(objpfx)
68 # Right now, however, we do it with shell scripts and lots of strangeness.
69 sysdep_dir := $(..)sysdeps
71 include $(+sysdir_pfx)sysdirs
76 sysdirs := $(subst $(\n), ,$(sysdirs))
78 $(+sysdir_pfx)sysdirs: $(+sysdir_pfx)Sysnames $(..)find-sysdirs
79 (echo define sysdirs; \
80 $(dir $(word 2,$^))$(notdir $(word 2,$^)) < $<; \
82 $(+sysdir_pfx)Sysnames:
83 @(echo The GNU C Library has not been configured! ;\
84 echo Run \`configure\' to configure it before building.\
87 # Turn the list of sysdep names into a colon-separated list of directories
88 # under SYSDEP_DIR (the base directory for sysdep files), and tell Make to
89 # search for C and header files in those directories.
90 +sysdep_dirs := $(addprefix $(sysdep_dir)/,$(sysdirs))
92 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
94 sysdep_path := $(subst $+ ,:,$(+sysdep_dirs))
96 override VPATH := $(sysdep_path)
98 vpath %.c $(sysdep_path)
99 vpath %.S $(sysdep_path)
100 vpath %.s $(sysdep_path)
101 vpath %.h $(sysdep_path)
104 # Add -I switches to get the right sysdep directories.
105 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
106 override CPPFLAGS := $(strip $(filter-out $(+sysdep-includes),$(CPPFLAGS)) \
109 # Include any system-specific makefiles.
111 ifeq ($(wildcard $(+sysdir_pfx)sysdep-Makefile),)
112 # Don't do deps until this exists, because it might change the sources list.
116 include $(+sysdir_pfx)sysdep-Makefile
117 $(+sysdir_pfx)sysdep-Makefile: $(+sysdir_pfx)sysdirs
118 (for dir in `cat $<`; do \
119 file=sysdeps/$$dir/Makefile; \
120 if [ -r $(..)$$file ]; then \
121 echo include "\$$(..)$$file"; \
127 # Include the generated dependencies of the sources in this directory.
128 include $(objpfx)depend-$(subdir)
131 # Maximize efficiency by minimizing the number of rules.
132 .SUFFIXES: # Clear the suffix list.
133 # Remove the RCS and SCCS rules.
139 # Add the suffixes we use.
140 .SUFFIXES: .a .o .S .s .c .h .dep .m4
142 # Make sure that object files are not removed
143 # when they are intermediates between sources and library members.
144 # This can go away with make v4.
147 # Make sure that the parent library archive is never removed.
150 # Use the verbose option of ar and tar when not running silently.
151 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
157 ARFLAGS := r$(verbose)
159 # Figure out the source filenames in this directory.
161 override sources := $(addsuffix .c,$(routines) $(aux) \
164 # This is the list of all object files, gotten by
165 # replacing every ".c" in `sources' with a ".o".
166 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
168 # The order of these rules is important.
170 ifndef .S-rule # Bletch.
171 $(objpfx)%.o: %.S $(before-compile)
172 $(COMPILE.S) $< $(OUTPUT_OPTION)
174 $(objpfx)%.o: %.s $(before-compile)
175 $(COMPILE.s) $< $(OUTPUT_OPTION)
176 $(objpfx)%.o: %.c $(before-compile)
177 $(COMPILE.c) $< $(OUTPUT_OPTION)
179 # This makes all the object files in the parent library archive.
181 .PHONY: lib lib-noranlib libobjs
184 libobjs: lib-noranlib
185 lib-noranlib: $(libc.a) ar-it
186 $(libc.a): %: $(addprefix %,$(patsubst $(objpfx)%,(%),$(objects)))
187 # $(AR) $(ARFLAGS) $@ $(patsubst $@(%),%,$?)
189 define +libc_lock_open
190 @. $(..)libc-lock-open
192 define +libc_lock_close
193 @rm -f $(..)LOCK-libc.a
196 # Temporary until I get a better solution.
201 cd $(objdir); $(AR) ru$(verbose) libc.a $(patsubst $(objpfx)%,%,$^)
203 $(AR) u$(verbose) $(libc.a) $^
205 # $(+libc_lock_close)
208 $(patsubst %,$(libc.a)(%),$(notdir $(objects))): $(libc.a)(%): $(objpfx)%;
212 # This makes all the object files.
214 objects objs: $(objects)
216 # Make the ansi and trad versions of the headers from the ansidecl sources.
218 headers := $(headers) $(sysdep_headers)
221 +headers_pfx = $(objpfx)
226 +header_dirs := $(filter-out ./,$(dir $(headers)))
229 headers: $(+headers_pfx)ansi/ \
230 $(addprefix $(+headers_pfx)ansi/,$(+header_dirs) $(headers)) \
231 $(+headers_pfx)trad/ \
232 $(addprefix $(+headers_pfx)trad/,$(+header_dirs) $(headers))
235 # mkdir isn't smart enough to strip a trailing /.
238 $(+headers_pfx)ansi/%: % $(..)ansidecl $(..)ansidecl.m4;$(+ansideclificate)
239 $(+headers_pfx)trad/%: % $(..)ansidecl $(..)ansidecl.m4;$(+ansideclificate)
241 # The bit with awk is to remove all the newlines from
242 # ansidecl.m4, so the output doesn't have 20 blank
243 # lines at the beginning.
244 +ansideclificate = $(dir $(word 2,$^))$(notdir $(word 2,$^)) \
245 -$(firstword $(subst /, ,$(@:$(+headers_pfx)%=%))) $< > $@
254 ifneq "$(findstring env,$(origin install-lib))" ""
255 override install-lib :=
257 ifneq "$(findstring env,$(origin install-data))" ""
258 override install-data :=
260 ifneq "$(findstring env,$(origin install))" ""
264 # install-lib are installed from the object directory into libdir.
265 # install-data are installed as they are into datadir.
266 # headers are installed from the object directory header directories into
267 # one or both of ansi-incldir and trad-incldir.
269 do-install = $(INSTALL_DATA) $< $@
272 $(addprefix $(bindir)/,$(install)): $(bindir)/%: $(objpfx)%
276 $(addprefix $(libdir)/,$(install-lib)): $(libdir)/%: $(objpfx)%;$(do-install)
279 $(addprefix $(datadir)/,$(install-data)): $(datadir)/%: %;$(do-install)
281 +install := $(addprefix $(libdir)/,$(install-lib)) \
282 $(addprefix $(datadir)/,$(install-data)) \
283 $(addprefix $(bindir)/,$(install))
286 $(addprefix $(ansi-incldir)/,$(headers)): \
287 $(ansi-incldir)/%: $(objpfx)ansi/%;$(do-install)
288 +install := $(+install) $(addprefix $(ansi-incldir)/,$(headers))
291 $(addprefix $(trad-incldir)/,$(headers)): \
292 $(trad-incldir)/%: $(objpfx)trad/%;$(do-install)
293 +install := $(+install) $(addprefix $(trad-incldir)/,$(headers))
296 +install := $(filter-out $(addprefix %/,$(no-install)),$(+install))
299 install: $(dir $(+install)) $(+install)
302 $(+mkdep) $(CPPFLAGS) $< | sed 's,$*\.o,$(@:.dep=.o) $@,' > $@
305 # N.B.: The order of these two rules is important.
306 $(objpfx)%.dep: %.S $(before-compile)
308 $(objpfx)%.dep: %.c $(before-compile)
311 +depfiles := $(strip $(sources:.c=.dep) $(addsuffix .dep,$(others) $(tests)))
312 +depfiles := $(addprefix $(objpfx),$(+depfiles))
313 $(objpfx)depend-$(subdir): Makefile
315 (for file in $(patsubst $(objpfx)%,%,$(+depfiles)); do \
316 echo "include $(objpfx)$$file"; \