1 # Copyright (C) 1991, 1992, 1993 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))" ""
37 headers := $(headers) $(sysdep_headers)
39 # This is benign and useless in GNU make before version 3.63.
40 export sources := $(sources)
41 export headers := $(headers)
43 ifneq ($(findstring e,$(MAKEFLAGS)),)
44 You must not use the -e flag when building the GNU C library.
47 ifndef +included-Makeconfig
48 include $(..)Makeconfig
51 # In make v4, we'll be able to really do this right (or something like that).
53 up-one = $(patsubst %/,%,$(dir $0))
54 parents-of = $(foreach x,$0,$(notdir $x) \
55 $(ifeq $(dir $x),./,$(parents-of $(up-one $x))))
56 # Finish this someday....
59 +sysdir_pfx = $(common-objpfx)
61 # Right now, however, we do it with shell scripts and lots of strangeness.
62 sysdep_dir := $(..)sysdeps
64 include $(+sysdir_pfx)sysdirs
69 sysdirs := $(subst $(\n), ,$(sysdirs))
71 $(+sysdir_pfx)sysdirs: $(+sysdir_pfx)Sysnames $(..)find-sysdirs
72 (echo define sysdirs; \
73 sysdep_dir=$(sysdep_dir) \
74 $(dir $(word 2,$^))$(notdir $(word 2,$^)) < $<; \
76 $(+sysdir_pfx)Sysnames:
77 @(echo The GNU C Library has not been configured! ;\
78 echo Run \`configure\' to configure it before building.\
80 export sysdirs := $(sysdirs)
81 export sysdep_dir := $(sysdep_dir)
83 +sysdep_dirs := $(addprefix $(sysdep_dir)/,$(sysdirs))
85 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
88 # Add -I switches to get the right sysdep directories.
89 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
90 +includes := $(+includes) $(+sysdep-includes)
92 # Include any system-specific makefiles.
93 # Also generate an ordered list of implicit rules which find the source
94 # files in each sysdep directory. The old method was to use vpath to
95 # search all the sysdep directories. However, that had the problem that a
96 # .S file in a later directory would be chosen over a .c file in an earlier
97 # directory, which does not preserve the desired sysdeps ordering behavior.
99 ifeq ($(wildcard $(+sysdir_pfx)sysd-Makefile),)
100 # Don't do deps until this exists, because it might change the sources list.
104 # Define first rules to find the source files in $(objpfx).
105 # Generated source files will end up there.
106 $(objpfx)%.o: $(objpfx)/%.S $(before-compile); $(compile-command.S)
107 $(objpfx)%.dep: $(objpfx)/%.S $(before-compile); $(+make-deps)
108 $(objpfx)%.o: $(objpfx)/%.s $(before-compile); $(compile-command.s)
109 $(objpfx)%.o: $(objpfx)/%.c $(before-compile); $(compile-command.c)
110 $(objpfx)%.dep: $(objpfx)/%.c $(before-compile); $(+make-deps)
112 include $(+sysdir_pfx)sysd-Makefile
113 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)sysdirs $(..)Makerules
114 (for dir in `sed -e 1d -e '$$d' $<`; do \
115 file=sysdeps/$$dir/Makefile; \
116 if [ -f $(..)$$file ]; then \
117 echo include "\$$(..)$$file"; \
120 dir="\$$(sysdep_dir)/$$dir"; \
121 echo "\$$(objpfx)%.o: $$dir/%.S \$$(before-compile); \
122 \$$(compile-command.S)"; \
123 echo "\$$(objpfx)%.dep: $$dir/%.S \$$(before-compile); \
125 echo "\$$(objpfx)%.o: $$dir/%.s \$$(before-compile); \
126 \$$(compile-command.s)"; \
127 echo "\$$(objpfx)%.o: $$dir/%.c \$$(before-compile); \
128 \$$(compile-command.c)"; \
129 echo "\$$(objpfx)%.dep: $$dir/%.c \$$(before-compile); \
133 # Maximize efficiency by minimizing the number of rules.
134 .SUFFIXES: # Clear the suffix list.
135 # Add the suffixes we use.
136 .SUFFIXES: .a .o .S .s .c .h .dep
138 # Generic rule for making directories.
140 # mkdir isn't smart enough to strip a trailing /.
143 # Make sure that object files are not removed
144 # when they are intermediates between sources and library members.
145 # This can go away with make v4.
148 # Make sure that the parent library archive is never removed.
151 # Use the verbose option of ar and tar when not running silently.
152 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
158 ARFLAGS := r$(verbose)
160 # Figure out the source filenames in this directory.
162 override sources := $(addsuffix .c,$(routines) $(aux) \
164 export sysdep_routines := $(sysdep_routines)
166 # This is the list of all object files, gotten by
167 # replacing every ".c" in `sources' with a ".o".
168 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
170 # The order of these rules is important.
172 $(objpfx)%.o: %.S $(before-compile); $(compile-command.S)
173 $(objpfx)%.o: %.s $(before-compile); $(compile-command.s)
174 $(objpfx)%.o: %.c $(before-compile); $(compile-command.c)
176 ifndef compile-command.S
177 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
179 ifndef compile-command.s
180 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
182 ifndef compile-command.c
183 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
186 ifeq ($(notdir $(firstword $(CC))),gcc)
187 # GCC can grok options after the file name.
188 compile.S = $(CC) $< -c $(CPPFLAGS) $(asm-CPPFLAGS)
189 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
191 compile.S = $(COMPILE.S) $(asm-CPPFLAGS) $<
192 compile.c = $(COMPILE.c) $<
197 # We need this for the output to go in the right place. It will default to
198 # empty if make was configured to work with a cc that can't grok -c and -o
199 # together. You can't compile the C library with such a compiler.
200 OUTPUT_OPTION = -o $@
204 # This makes all the object files in the parent library archive.
206 .PHONY: lib libobjs lib-noranlib
211 +libobjs := $(patsubst %,$(libc.a)(%),$(notdir $(objects)))
213 $(+libobjs): $(libc.a)(%): $(objpfx)%;
216 lib-noranlib: libobjs ar-it
218 #$(libc.a): %: $(addprefix %,$(patsubst $(objpfx)%,(%),$(objects)))
219 # $(AR) $(ARFLAGS) $@ $(patsubst $@(%),%,$?)
221 define +libc_lock_open
222 @. $(..)libc-lock-open
224 define +libc_lock_close
225 @rm -f $(..)LOCK-libc.a
228 # Temporary until I get a better solution.
234 cd $(objdir); $(AR) ru$(verbose) libc.a $(patsubst $(objpfx)%,%,$^)
236 $(AR) ru$(verbose) $(..)libc.a $^
238 # $(+libc_lock_close)
243 # This makes all the object files.
245 objects objs: $(objects)
249 # install-lib are installed from the object directory into $(libdir).
250 # install-data are installed as they are into $(datadir). headers are
251 # installed as they are in $(includedir). install-others are absolute path
252 # names of files to install; rules to install them are defined elsewhere.
254 do-install = $(INSTALL_DATA) $< $@
256 # Any directory (parent or subdir) that has any object files to build
257 # should install libc.a; this way "make install" in a subdir is guaranteed
258 # to install everything it changes.
260 install-lib := $(install-lib) libc.a
264 $(addprefix $(bindir)/,$(install)): $(bindir)/%: $(objpfx)%
268 $(addprefix $(libdir)/,$(install-lib)): $(libdir)/%: $(objpfx)%;$(do-install)
271 $(addprefix $(datadir)/,$(install-data)): $(datadir)/%: %;$(do-install)
273 +install := $(addprefix $(libdir)/,$(install-lib)) \
274 $(addprefix $(datadir)/,$(install-data)) \
275 $(addprefix $(bindir)/,$(install)) \
277 headers := $(strip $(headers))
279 $(addprefix $(includedir)/,$(headers)): \
280 $(includedir)/%: %;$(do-install)
281 +install := $(+install) $(addprefix $(includedir)/,$(headers))
283 +install := $(filter-out $(addprefix %/,$(no-install)),$(+install))
285 +install-dirs := $(dir $(+install))
286 # Get two levels of directories so $(datadir)/zoneinfo wins.
287 +install-dirs := $(+install-dirs) $(filter-out ./,$(dir $(+install-dirs)))
288 # Sort them so containing dirs are guaranteed to come first.
289 +install-dirs := $(sort $(+install-dirs))
292 install: $(+install-dirs) $(+install)
294 S-CPPFLAGS = $(asm-CPPFLAGS)
295 +make-deps = $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
296 sed 's,$*\.o,$(@:.dep=.o) $@,' > $@
298 # N.B.: The order of these two rules is important.
299 $(objpfx)%.dep: %.S $(before-compile)
301 $(objpfx)%.dep: %.c $(before-compile)
304 +depfiles := $(strip $(sources:.c=.dep) $(addsuffix .dep,$(others) $(tests)))
305 +depfiles := $(addprefix $(objpfx),$(+depfiles))
307 $(objpfx)depend-$(subdir): Makefile
309 (for file in $(patsubst $(objpfx)%,%,$(+depfiles)); do \
310 echo "include $(objpfx)$$file"; \
317 # Include the generated dependencies of the sources in this directory.
318 ifdef have.make.that.groks.multiple.includes
319 # Avoid the extra file and waiting for it, since we can.
320 +depfiles := $(strip $(+depfiles))
325 include $(objpfx)depend-$(subdir)
329 # Command to compile $< in $(objdir) using the native libraries.
330 native-compile = cwd=`pwd`; cd $(@D); $(CC) $(native-CFLAGS) $$cwd/$< -o $(@F)
332 # Command to compile $< in $(common-objdir) using the native libraries.
333 define common-objdir-compile
334 cd $(@D); $(CC) $(native-CFLAGS) $(<:$(common-objpfx)%=%) -o $(@F)
337 # We always want to use configuration -D switches.
338 native-CFLAGS = $(config-defines)
340 # Support the GNU standard name for this target.
353 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
354 # for each function which is a stub. We grovel over all the .dep files
355 # looking for references to source files in sysdeps/stub. Then we grovel
356 # over each referenced source file to see what stub function it defines.
359 .PHONY: stubs # The parent Makefile calls this target.
360 stubs: $(common-objpfx)stub-$(subdir)
361 $(common-objpfx)stub-$(subdir): $(+depfiles)
362 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' > $@T \
363 `sed -n 's/^.*\($(sysdep_dir)/stub/[a-z0-9_]*\.c\).*$$/\1/p' $^`
368 ifneq (,$(wildcard /home/gd/gnu/lib/ChangeLog))
369 # Snarf from the master source and frob the copying notice.
370 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
372 # So I don't edit them by mistake.