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.
31 # If `sources' was defined by the parent makefile, undefine it so
32 # we will later get it from wildcard search in this directory.
33 ifneq "$(findstring env,$(origin sources))" ""
38 ifneq "$(findstring env,$(origin headers))" ""
44 ifneq ($(findstring e,$(MAKEFLAGS)),)
45 You must not use the -e flag when building the GNU C library.
48 ifndef +included-Makeconfig
49 include $(..)Makeconfig
52 # In make v4, we'll be able to really do this right (or something like that).
54 up-one = $(patsubst %/,%,$(dir $0))
55 parents-of = $(foreach x,$0,$(notdir $x) \
56 $(ifeq $(dir $x),./,$(parents-of $(up-one $x))))
57 # Finish this someday....
61 +sysdir_pfx = $(objpfx)
66 # Right now, however, we do it with shell scripts and lots of strangeness.
67 sysdep_dir := $(..)sysdeps
69 include $(+sysdir_pfx)sysdirs
74 sysdirs := $(subst $(\n), ,$(sysdirs))
76 $(+sysdir_pfx)sysdirs: $(+sysdir_pfx)Sysnames $(..)find-sysdirs
77 (echo define sysdirs; \
78 $(dir $(word 2,$^))$(notdir $(word 2,$^)) < $<; \
80 $(+sysdir_pfx)Sysnames:
81 @(echo The GNU C Library has not been configured! ;\
82 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 libobjs lib-noranlib
186 +libobjs := $(patsubst %,$(libc.a)(%),$(notdir $(objects)))
188 $(+libobjs): $(libc.a)(%): $(objpfx)%;
191 lib-noranlib: libobjs ar-it
193 #$(libc.a): %: $(addprefix %,$(patsubst $(objpfx)%,(%),$(objects)))
194 # $(AR) $(ARFLAGS) $@ $(patsubst $@(%),%,$?)
196 define +libc_lock_open
197 @. $(..)libc-lock-open
199 define +libc_lock_close
200 @rm -f $(..)LOCK-libc.a
203 # Temporary until I get a better solution.
208 cd $(objdir); $(AR) ru$(verbose) libc.a $(patsubst $(objpfx)%,%,$^)
210 $(AR) u$(verbose) $(libc.a) $^
212 # $(+libc_lock_close)
216 # This makes all the object files.
218 objects objs: $(objects)
220 # Make the ansi and trad versions of the headers from the ansidecl sources.
222 headers := $(headers) $(sysdep_headers)
225 +headers_pfx = $(objpfx)
230 +header_dirs := $(filter-out ./,$(dir $(headers)))
233 headers: $(+headers_pfx)ansi/ \
234 $(addprefix $(+headers_pfx)ansi/,$(+header_dirs) $(headers)) \
235 $(+headers_pfx)trad/ \
236 $(addprefix $(+headers_pfx)trad/,$(+header_dirs) $(headers))
239 # mkdir isn't smart enough to strip a trailing /.
242 $(+headers_pfx)ansi/%: % $(..)ansidecl $(..)ansidecl.m4;$(+ansideclificate)
243 $(+headers_pfx)trad/%: % $(..)ansidecl $(..)ansidecl.m4;$(+ansideclificate)
245 # The bit with awk is to remove all the newlines from
246 # ansidecl.m4, so the output doesn't have 20 blank
247 # lines at the beginning.
248 +ansideclificate = $(dir $(word 2,$^))$(notdir $(word 2,$^)) \
249 -$(firstword $(subst /, ,$(@:$(+headers_pfx)%=%))) $< > $@
258 # install-lib are installed from the object directory into libdir.
259 # install-data are installed as they are into datadir.
260 # headers are installed from the object directory header directories into
261 # one or both of ansi-incldir and trad-incldir.
262 # install-others are absolute path names of files to install;
263 # rules to install them are defined elsewhere.
265 do-install = $(INSTALL_DATA) $< $@
268 $(addprefix $(bindir)/,$(install)): $(bindir)/%: $(objpfx)%
272 $(addprefix $(libdir)/,$(install-lib)): $(libdir)/%: $(objpfx)%;$(do-install)
275 $(addprefix $(datadir)/,$(install-data)): $(datadir)/%: %;$(do-install)
277 +install := $(addprefix $(libdir)/,$(install-lib)) \
278 $(addprefix $(datadir)/,$(install-data)) \
279 $(addprefix $(bindir)/,$(install)) \
281 headers := $(strip $(headers))
284 $(addprefix $(ansi-incldir)/,$(headers)): \
285 $(ansi-incldir)/%: $(objpfx)ansi/%;$(do-install)
286 +install := $(+install) $(addprefix $(ansi-incldir)/,$(headers))
289 $(addprefix $(trad-incldir)/,$(headers)): \
290 $(trad-incldir)/%: $(objpfx)trad/%;$(do-install)
291 +install := $(+install) $(addprefix $(trad-incldir)/,$(headers))
294 +install := $(filter-out $(addprefix %/,$(no-install)),$(+install))
297 install: $(dir $(+install)) $(+install)
300 $(+mkdep) $(CPPFLAGS) $< | sed 's,$*\.o,$(@:.dep=.o) $@,' > $@
303 # N.B.: The order of these two rules is important.
304 $(objpfx)%.dep: %.S $(before-compile)
306 $(objpfx)%.dep: %.c $(before-compile)
309 +depfiles := $(strip $(sources:.c=.dep) $(addsuffix .dep,$(others) $(tests)))
310 +depfiles := $(addprefix $(objpfx),$(+depfiles))
311 $(objpfx)depend-$(subdir): Makefile
313 (for file in $(patsubst $(objpfx)%,%,$(+depfiles)); do \
314 echo "include $(objpfx)$$file"; \
320 # Command to compile in $< in $(objdir) using the native libraries.
321 native-compile = cwd=`pwd`; cd $(objdir); $(CC) $$cwd/$< -o $(@:$(objpfx)%=%)