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