Wed Jul 17 17:08:48 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[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
16 # not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 # Cambridge, MA 02139, 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 $(sysdep-subdirs) nss elf crypt po
58 export subdirs := $(subdirs)    # Benign, useless in GNU make before 3.63.
59
60 # The mach and hurd subdirectories have many generated header files which
61 # much of the rest of the library depends on, so it is best to build them
62 # first (and mach before hurd, at that).  The before-compile additions in
63 # sysdeps/{mach,hurd}/Makefile should make it reliably work for these files
64 # not to exist when making in other directories, but it will be slower that
65 # way with more somewhat expensive `make' invocations.
66 subdirs := $(filter mach,$(subdirs)) $(filter hurd,$(subdirs)) \
67            $(filter-out mach hurd,$(subdirs))
68
69 # All initialization source files.
70 +subdir_inits   := $(wildcard $(foreach dir,$(subdirs),$(dir)/init-$(dir).c))
71 # All subdirectories containing initialization source files.
72 +init_subdirs   := $(patsubst %/,%,$(dir $(+subdir_inits)))
73
74
75 # These are the targets that are made by making them in each subdirectory.
76 +subdir_targets := subdir_lib objects objs others subdir_mostlyclean    \
77                    subdir_clean subdir_distclean subdir_realclean       \
78                    tests subdir_lint.out                                \
79                    subdir_distinfo                                      \
80                    subdir_echo-headers subdir_echo-distinfo             \
81                    subdir_install $(addprefix install-,                 \
82                                               no-libc.a bin lib         \
83                                               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
87 aux      = sysdep $(libc-init) version
88
89 echo-headers: subdir_echo-headers
90
91 # What to install.
92 install-others = $(includedir)/stubs.h
93
94 ifeq (yes,$(gnu-ld))
95 libc-init = set-init
96 else
97 libc-init = munch-init
98 $(objpfx)munch-init.c: munch.awk munch-tmpl.c $(+subdir_inits)
99         awk -f $< subdirs='$(+init_subdirs)' $(word 2,$^) > $@-t
100         mv -f $@-t $@
101 generated := $(generated) munch-init.c
102 endif
103
104
105 include Makerules
106
107 # Install from subdirectories too.
108 install: subdir_install
109
110 # Build subdirectory lib objects.
111 lib-noranlib: subdir_lib
112
113 ifeq (yes,$(build-shared))
114 # Build the shared object from the PIC object library.
115 lib: $(common-objpfx)libc.so
116 endif
117
118 $(objpfx)sysd-dirs: $(+sysdir_pfx)config.make
119         (echo define sysdep-subdirs;                                          \
120          for dir in $(sysdirs); do                                            \
121            if [ -r $(sysdep_dir)/$$dir/Subdirs ]; then                        \
122              sed 's/#.*$$//' $(sysdep_dir)/$$dir/Subdirs;                     \
123            else true;                                                         \
124            fi;                                                                \
125          done;                                                                \
126          echo endef) > $@-tmp
127          mv -f $@-tmp $@
128 \f
129 # Makerules creates a file `stub-$(subdir)' for each subdirectory, which
130 # contains `#define __stub_FUNCTION' for each function which is a stub.
131 # Here we paste all of these together into <stubs.h>.
132
133 subdir-stubs := $(foreach dir,$(subdirs),$(common-objpfx)stub-$(dir))
134
135 # Since stubs.h is never needed when building the library, we simplify the
136 # hairy installation process by producing it in place only as the last part
137 # of the top-level `make install'.  It depends on subdir_install, which
138 # iterates over all the subdirs; subdir_install in each subdir depends on
139 # the subdir's stubs file.  Having more direct dependencies would result in
140 # extra iterations over the list for subdirs and many recursive makes.
141 $(includedir)/stubs.h: subdir_install
142         @rm -f $(objpfx)stubs.h
143         (echo '/* This file is automatically generated.';\
144          echo '   It defines a symbol `__stub_FUNCTION'\'' for each function';\
145          echo '   in the C library which is a stub, meaning it will fail';\
146          echo '   every time called, usually setting errno to ENOSYS.  */';\
147          sort $(subdir-stubs)) > $(objpfx)stubs.h
148         if test -r $@ && cmp -s $(objpfx)stubs.h $@; \
149         then echo stubs.h unchanged ; \
150         else $(INSTALL_DATA) $(objpfx)stubs.h $@; fi
151         rm -f $(objpfx)stubs.h
152 \f
153 # This makes the Info or DVI file of the documentation from the Texinfo source.
154 .PHONY: info dvi
155 info dvi:
156         $(MAKE) -C manual $@
157 \f
158 # This makes all the subdirectory targets.
159
160 # For each target, make it depend on DIR/target for each subdirectory DIR.
161 $(+subdir_targets): %: $(addsuffix /%,$(subdirs))
162
163 # Compute a list of all those targets.
164 all-subdirs-targets := $(foreach dir,$(subdirs),\
165                                  $(addprefix $(dir)/,$(+subdir_targets)))
166
167 # The action for each of those is to cd into the directory and make the
168 # target there.
169 $(all-subdirs-targets):
170         $(MAKE) -C $(@D) $(@F)
171
172 .PHONY: $(+subdir_targets) $(all-subdirs-targets)
173 \f
174 # Targets to clean things up to various degrees.
175
176 .PHONY: clean realclean distclean distclean-1 parent-clean parent-mostlyclean
177
178 # Subroutines of all cleaning targets.
179 parent-mostlyclean: common-mostlyclean # common-mostlyclean is in Makerules.
180         -rm -f $(foreach o,$(object-suffixes),\
181                    $(common-objpfx)$(patsubst %,$(libtype$o),c)) \
182                $(addprefix $(objpfx),$(install-lib))
183 parent-clean: parent-mostlyclean common-clean
184         -rm -f $(addprefix $(common-objpfx),$(common-generated))
185         -rm -f $(addprefix $(objpfx),sysd-Makefile sysd-dirs sysd-rules)
186
187 clean: parent-clean
188 # This is done this way rather than having `subdir_clean' be a
189 # dependency of this target so that libc.a will be removed before the
190 # subdirectories are dealt with and so they won't try to remove object
191 # files from it when it's going to be removed anyway.
192         @$(MAKE) subdir_clean no_deps=t
193 mostlyclean: parent-mostlyclean
194         @$(MAKE) subdir_mostlyclean no_deps=t
195
196 # The realclean target is just like distclean for the parent, but we want
197 # the subdirs to know the difference in case they care.
198 realclean distclean: parent-clean
199 # This is done this way rather than having `subdir_distclean' be a
200 # dependency of this target so that libc.a will be removed before the
201 # subdirectories are dealt with and so they won't try to remove object
202 # files from it when it's going to be removed anyway.
203         @$(MAKE) distclean-1 no_deps=t distclean-1=$@ avoid-generated=yes
204
205 # Subroutine of distclean and realclean.
206 distclean-1: subdir_$(distclean-1)
207         -rm -f $(config-generated)
208         -rm -f $(addprefix $(objpfx),config.status config.cache config.log)
209         -rm -f $(addprefix $(objpfx),config.make config-name.h config.h)
210 ifdef objdir
211         -rm -f $(objpfx)Makefile
212 endif
213         -rm -f $(sysdep-$(distclean-1))
214 \f
215 .PHONY: echo_subdirs
216 echo_subdirs:;@echo '$(subdirs)'
217
218 .PHONY: echo-distinfo parent_echo-distinfo
219 echo-distinfo: parent_echo-distinfo subdir_echo-distinfo
220 parent_echo-distinfo:
221         @echo $(addprefix +header+,$(headers)) \
222               $(addprefix +nodist+,$(generated))
223
224 \f
225 # Make the distribution tarfile.
226
227 distribute  := README INSTALL FAQ NOTES NEWS PROJECTS                   \
228                COPYING.LIB COPYING ChangeLog ChangeLog.[0-9]            \
229                Makefile Makeconfig Makerules Rules Make-dist MakeTAGS   \
230                extra-lib.mk o-iterator.mk                               \
231                ansidecl.h mkinstalldirs move-if-change install-sh       \
232                configure configure.in aclocal.m4 config.sub config.guess\
233                config.h.in config.make.in config-name.in Makefile.in    \
234                munch-tmpl.c munch.awk \
235                sysdep.h set-hooks.h libc-symbols.h version.h shlib-versions \
236                rpm/Makefile rpm/template rpm/rpmrc
237
238 distribute := $(strip $(distribute))
239 generated := $(generated) stubs.h
240
241 README: README.template version.c ; # Make-dist should update README.
242
243 define format-me
244 @rm -f $@
245 makeinfo --no-validate --no-warn --no-headers $< -o $@
246 -chmod a-w $@
247 endef
248 INSTALL: manual/maint.texi; $(format-me)
249 NOTES: manual/creature.texi; $(format-me)
250
251 rpm/%: subdir_distinfo
252         $(MAKE) -C $(@D) subdirs='$(subdirs)' $(@F)