update from main archive 961214
[platform/upstream/glibc.git] / Makefile
1 # Copyright (C) 1991, 92, 93, 94, 95, 96 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
3
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.
8
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.
13
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 not,
16 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
18
19 #
20 #       Master Makefile for the GNU C library
21 #
22 ifneq (,)
23 This makefile requires GNU Make.
24 endif
25
26
27 # This is the default target; it makes everything except the tests.
28 .PHONY: all
29 all: lib others
30 \f
31 define autoconf-it
32 @-rm -f $@.new
33 autoconf $(ACFLAGS) $< > $@.new
34 chmod a-w,a+x $@.new
35 mv -f $@.new $@
36 test ! -d CVS || cvs commit -m'Regenerated: autoconf $(ACFLAGS) $<' $@
37 endef
38
39 configure: configure.in aclocal.m4; $(autoconf-it)
40 %/configure: %/configure.in aclocal.m4; $(autoconf-it)
41
42 include Makeconfig
43
44 ifndef avoid-generated
45 -include $(objpfx)sysd-dirs
46 define \n
47
48
49 endef
50 sysdep-subdirs := $(subst $(\n), ,$(sysdep-subdirs))
51 endif
52
53 # These are the subdirectories containing the library source.
54 subdirs = csu assert ctype db locale intl catgets math setjmp signal stdlib \
55           stdio-common $(stdio) $(malloc) string wcsmbs time dirent grp pwd \
56           posix io termios resource misc login socket sysvipc gmon gnulib \
57           wctype manual shadow md5-crypt nss $(sysdep-subdirs) elf po \
58           $(add-ons)
59 export subdirs := $(subdirs)    # Benign, useless in GNU make before 3.63.
60
61 # The mach and hurd subdirectories have many generated header files which
62 # much of the rest of the library depends on, so it is best to build them
63 # first (and mach before hurd, at that).  The before-compile additions in
64 # sysdeps/{mach,hurd}/Makefile should make it reliably work for these files
65 # not to exist when making in other directories, but it will be slower that
66 # way with more somewhat expensive `make' invocations.
67 subdirs := $(filter mach,$(subdirs)) $(filter hurd,$(subdirs)) \
68            $(filter-out mach hurd,$(subdirs))
69
70 # All initialization source files.
71 +subdir_inits   := $(wildcard $(foreach dir,$(subdirs),$(dir)/init-$(dir).c))
72 # All subdirectories containing initialization source files.
73 +init_subdirs   := $(patsubst %/,%,$(dir $(+subdir_inits)))
74
75
76 # These are the targets that are made by making them in each subdirectory.
77 +subdir_targets := subdir_lib objects objs others subdir_mostlyclean    \
78                    subdir_clean subdir_distclean subdir_realclean       \
79                    tests subdir_lint.out                                \
80                    subdir_distinfo                                      \
81                    subdir_echo-headers subdir_echo-distinfo             \
82                    subdir_install                                       \
83                    $(addprefix install-, no-libc.a bin lib data headers others)
84 \f
85 headers := errno.h sys/errno.h errnos.h limits.h values.h       \
86            features.h gnu-versions.h libc-lock.h xopen_lim.h
87 aux      = sysdep $(libc-init) version
88 before-compile = $(objpfx)version-info.h
89
90 echo-headers: subdir_echo-headers
91
92 # What to install.
93 install-others = $(includedir)/stubs.h
94 ifeq (yes,$(build-shared))
95 install-others += $(includedir)/gnu/lib-names.h
96 endif
97
98 ifeq (yes,$(gnu-ld))
99 libc-init = set-init
100 else
101 libc-init = munch-init
102 $(objpfx)munch-init.c: munch.awk munch-tmpl.c $(+subdir_inits)
103         awk -f $< subdirs='$(+init_subdirs)' $(word 2,$^) > $@-t
104         mv -f $@-t $@
105 generated := $(generated) munch-init.c
106 endif
107
108
109 include Makerules
110
111 # Install from subdirectories too.
112 install: subdir_install
113
114 # Build subdirectory lib objects.
115 lib-noranlib: subdir_lib
116
117 ifeq (yes,$(build-shared))
118 # Build the shared object from the PIC object library.
119 lib: $(common-objpfx)libc.so
120 endif
121
122 all-Subdirs-files = $(wildcard $(addsuffix /Subdirs, $(config-sysdirs)))
123 $(objpfx)sysd-dirs: $(+sysdir_pfx)config.make $(all-Subdirs-files)
124         (echo define sysdep-subdirs;                            \
125          sed 's/#.*$$//' $(all-Subdirs-files) /dev/null;        \
126          echo endef) > $@-tmp
127         mv -f $@-tmp $@
128 \f
129 all-Banner-files = $(wildcard $(addsuffix /Banner, $(subdirs)))
130 $(objpfx)version-info.h: $(+sysdir_pfx)config.make $(all-Banner-files)
131         (case $(config-os) in \
132            linux*) version=`(echo -e "#include <linux/version.h>\nUTS_RELEASE"\
133                              | $(CC)  -E -P - | \
134                              sed -e 's/"\([^"]*\)".*/\1/p' -e d) 2>/dev/null`;\
135                    if [ -z "$$version" ]; then \
136                      if [ -r /proc/version ]; then \
137                        version=`sed 's/.*version \([^ ]*\) .*/>>\1<</' \
138                                 < /proc/version`; \
139                      else \
140                        version=`uname -r`; \
141                      fi; \
142                    fi; \
143                    echo -n "\"Compiled on a Linux $$version system "; \
144                    echo "on `date +%Y/%m/%d`.\\n\"" ;; \
145            *) ;; \
146          esac; \
147          files="$(all-Banner-files)";                           \
148          if test -n "$$files"; then                             \
149            echo "\"Available extensions:";                      \
150            sed -e '/^#/d' -e 's/^[[:space:]]*/  /' $$files;     \
151            echo "\"";                                           \
152          fi) > $@T
153         mv -f $@T $@
154 generated += version-info.h
155
156 version.c-objects := $(addprefix $(objpfx)version,$(object-suffixes))
157 $(version.c-objects): $(objpfx)version-info.h
158 \f
159 # Makerules creates a file `stub-$(subdir)' for each subdirectory, which
160 # contains `#define __stub_FUNCTION' for each function which is a stub.
161 # Here we paste all of these together into <stubs.h>.
162
163 subdir-stubs := $(foreach dir,$(subdirs),$(common-objpfx)stub-$(dir))
164
165 # Since stubs.h is never needed when building the library, we simplify the
166 # hairy installation process by producing it in place only as the last part
167 # of the top-level `make install'.  It depends on subdir_install, which
168 # iterates over all the subdirs; subdir_install in each subdir depends on
169 # the subdir's stubs file.  Having more direct dependencies would result in
170 # extra iterations over the list for subdirs and many recursive makes.
171 $(includedir)/stubs.h: subdir_install
172         @rm -f $(objpfx)stubs.h
173         (echo '/* This file is automatically generated.';\
174          echo '   It defines a symbol `__stub_FUNCTION'\'' for each function';\
175          echo '   in the C library which is a stub, meaning it will fail';\
176          echo '   every time called, usually setting errno to ENOSYS.  */';\
177          sort $(subdir-stubs)) > $(objpfx)stubs.h
178         if test -r $@ && cmp -s $(objpfx)stubs.h $@; \
179         then echo 'stubs.h unchanged'; \
180         else $(INSTALL_DATA) $(objpfx)stubs.h $@; fi
181         rm -f $(objpfx)stubs.h
182 \f
183 ifeq (yes,$(build-shared))
184
185 # Like stubs.h the gnu/lib-names.h header is not used while building the
186 # libc itself.  So we generate it while installing.
187 $(includedir)/gnu/lib-names.h: $(common-objpfx)soversions.mk
188         @rm -f $(objpfx)lib-names.h
189         (echo '/* This file is automatically generated.';\
190          echo '   It defines macros to allow user program to find the shared';\
191          echo '   library files which come as part of GNU libc.  */';\
192          echo '#ifndef __GNU_LIB_NAMES_H'; \
193          echo '#define __GNU_LIB_NAMES_H        1'; \
194          echo; \
195          (libs='$(all-sonames)';\
196           for l in $$libs; do \
197             upname=`echo $$l | sed 's/[.]so.*//' | \
198                     tr '[:lower:]-' '[:upper:]_'`; \
199             echo "#define       $${upname}_SO   $$l"; \
200           done;) | sort; \
201          echo; \
202          echo '#endif   /* gnu/lib-names.h */';) > $(objpfx)lib-names.h
203         if test -r $@ && cmp -s $(objpfx)lib-names.h $@; \
204         then echo 'gnu/lib-names.h unchanged'; \
205         else $(INSTALL_DATA) $(objpfx)lib-names.h $@; fi
206         rm -f $(objpfx)lib-names.h
207 endif
208 \f
209 # This makes the Info or DVI file of the documentation from the Texinfo source.
210 .PHONY: info dvi
211 info dvi:
212         $(MAKE) -C manual $@
213 \f
214 # This makes all the subdirectory targets.
215
216 # For each target, make it depend on DIR/target for each subdirectory DIR.
217 $(+subdir_targets): %: $(addsuffix /%,$(subdirs))
218
219 # Compute a list of all those targets.
220 all-subdirs-targets := $(foreach dir,$(subdirs),\
221                                  $(addprefix $(dir)/,$(+subdir_targets)))
222
223 # The action for each of those is to cd into the directory and make the
224 # target there.
225 $(all-subdirs-targets):
226         $(MAKE) -C $(@D) $(@F)
227
228 .PHONY: $(+subdir_targets) $(all-subdirs-targets)
229 \f
230 # Targets to clean things up to various degrees.
231
232 .PHONY: clean realclean distclean distclean-1 parent-clean parent-mostlyclean
233
234 # Subroutines of all cleaning targets.
235 parent-mostlyclean: common-mostlyclean # common-mostlyclean is in Makerules.
236         -rm -f $(foreach o,$(object-suffixes),\
237                    $(common-objpfx)$(patsubst %,$(libtype$o),c)) \
238                $(addprefix $(objpfx),$(install-lib))
239 parent-clean: parent-mostlyclean common-clean
240         -rm -f $(addprefix $(common-objpfx),$(common-generated))
241         -rm -f $(addprefix $(objpfx),sysd-Makefile sysd-dirs sysd-rules)
242
243 clean: parent-clean
244 # This is done this way rather than having `subdir_clean' be a
245 # dependency of this target so that libc.a will be removed before the
246 # subdirectories are dealt with and so they won't try to remove object
247 # files from it when it's going to be removed anyway.
248         @$(MAKE) subdir_clean no_deps=t
249 mostlyclean: parent-mostlyclean
250         @$(MAKE) subdir_mostlyclean no_deps=t
251
252 # The realclean target is just like distclean for the parent, but we want
253 # the subdirs to know the difference in case they care.
254 realclean distclean: parent-clean
255 # This is done this way rather than having `subdir_distclean' be a
256 # dependency of this target so that libc.a will be removed before the
257 # subdirectories are dealt with and so they won't try to remove object
258 # files from it when it's going to be removed anyway.
259         @$(MAKE) distclean-1 no_deps=t distclean-1=$@ avoid-generated=yes
260
261 # Subroutine of distclean and realclean.
262 distclean-1: subdir_$(distclean-1)
263         -rm -f $(config-generated)
264         -rm -f $(addprefix $(objpfx),config.status config.cache config.log)
265         -rm -f $(addprefix $(objpfx),config.make config-name.h config.h)
266 ifdef objdir
267         -rm -f $(objpfx)Makefile
268 endif
269         -rm -f $(sysdep-$(distclean-1))
270 \f
271 .PHONY: echo_subdirs
272 echo_subdirs:;@echo '$(subdirs)'
273
274 .PHONY: echo-distinfo parent_echo-distinfo
275 echo-distinfo: parent_echo-distinfo subdir_echo-distinfo
276 parent_echo-distinfo:
277         @echo $(addprefix +header+,$(headers)) \
278               $(addprefix +nodist+,$(generated))
279
280 \f
281 # Make the distribution tarfile.
282
283 distribute  := README INSTALL FAQ NOTES NEWS PROJECTS                   \
284                COPYING.LIB COPYING ChangeLog ChangeLog.[0-9]            \
285                Makefile Makeconfig Makerules Rules Make-dist MakeTAGS   \
286                extra-lib.mk o-iterator.mk                               \
287                ansidecl.h mkinstalldirs move-if-change install-sh       \
288                configure configure.in aclocal.m4 config.sub config.guess\
289                config.h.in config.make.in config-name.in Makefile.in    \
290                autolock.sh rellns-sh munch-tmpl.c munch.awk interp.c    \
291                sysdep.h set-hooks.h libc-symbols.h version.h shlib-versions \
292                rpm/Makefile rpm/template rpm/rpmrc nsswitch.h netgroup.h
293
294 distribute := $(strip $(distribute))
295 generated := $(generated) stubs.h version-info.h
296
297 README: README.template version.c ; # Make-dist should update README.
298
299 define format-me
300 @rm -f $@
301 makeinfo --no-validate --no-warn --no-headers $< -o $@
302 -chmod a-w $@
303 endef
304 INSTALL: manual/maint.texi; $(format-me)
305 NOTES: manual/creature.texi; $(format-me)
306
307 rpm/%: subdir_distinfo
308         $(MAKE) -C $(@D) subdirs='$(subdirs)' $(@F)