* Makefile (autoconf-it): Make it executable and unwritable.
[platform/upstream/glibc.git] / Makefile
1 # Copyright (C) 1991, 1992, 1993, 1994, 1995 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; $(autoconf-it)
40 %/configure: %/configure.in; $(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 locale math setjmp signal stdio stdlib      \
55            malloc string time dirent grp pwd posix io termios resource  \
56            socket misc gnulib $(wildcard crypt) manual                  \
57            $(sysdep-subdirs) elf
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 # the much of 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_echo-headers subdir_echo-distinfo             \
80                    subdir_install $(addprefix install-,                 \
81                                               no-libc.a bin lib         \
82                                               data headers others)
83 \f
84 headers := features.h errno.h sys/errno.h errnos.h limits.h values.h
85 aux      = sysdep $(libc-init) version
86
87 echo-headers: subdir_echo-headers
88
89 # What to install.
90 install-others = $(includedir)/stubs.h
91
92 ifeq (yes,$(gnu-ld))
93 libc-init = set-init
94 else
95 libc-init = munch-init
96 $(objpfx)munch-init.c: munch.awk munch-tmpl.c $(+subdir_inits)
97         awk -f $< subdirs='$(+init_subdirs)' $(word 2,$^) > $@-t
98         mv -f $@-t $@
99 generated := $(generated) munch-init.c
100 endif
101
102
103 include Makerules
104
105 # Install from subdirectories too.
106 install: subdir_install
107
108 # Build subdirectory lib objects.
109 lib-noranlib: subdir_lib
110
111 ifeq (yes,$(build-shared))
112 # Build the shared object from the PIC object library.
113 lib: $(common-objpfx)libc.so
114 endif
115
116 $(objpfx)sysd-dirs: $(+sysdir_pfx)config.make
117         (echo define sysdep-subdirs;                                          \
118          for dir in $(sysdirs); do                                            \
119            if [ -r $(sysdep_dir)/$$dir/Subdirs ]; then                        \
120              sed 's/#.*$$//' $(sysdep_dir)/$$dir/Subdirs;                     \
121            else true;                                                         \
122            fi;                                                                \
123          done;                                                                \
124          echo endef) > $@-tmp
125          mv -f $@-tmp $@
126 \f
127 # Makerules creates a file `stub-$(subdir)' for each subdirectory, which
128 # contains `#define __stub_FUNCTION' for each function which is a stub.
129 # Here we paste all of these together into <stubs.h>.
130
131 subdir-stubs := $(foreach dir,$(subdirs),$(common-objpfx)stub-$(dir))
132
133 # Since stubs.h is never needed when building the library, we simplify the
134 # hairy installation process by producing it in place only as the last part
135 # of the top-level `make install'.  It depends on subdir_install, which
136 # iterates over all the subdirs; subdir_install in each subdir depends on
137 # the subdir's stubs file.  Having more direct dependencies would result in
138 # extra iterations over the list for subdirs and many recursive makes.
139 $(includedir)/stubs.h: subdir_install
140         @rm -f $(objpfx)stubs.h
141         (echo '/* This file is automatically generated.';\
142          echo '   It defines a symbol `__stub_FUNCTION'\'' for each function';\
143          echo '   in the C library which is a stub, meaning it will fail';\
144          echo '   every time called, usually setting errno to ENOSYS.  */';\
145          sort $(subdir-stubs)) > $(objpfx)stubs.h
146         $(INSTALL_DATA) $(objpfx)stubs.h $@
147         rm -f $(objpfx)stubs.h
148 \f
149 # This makes the Info or DVI file of the documentation from the Texinfo source.
150 .PHONY: info dvi
151 info dvi:
152         $(MAKE) -C manual $@
153 \f
154 # This makes all the subdirectory targets.
155
156 # For each target, make it depend on DIR/target for each subdirectory DIR.
157 $(+subdir_targets): %: $(addsuffix /%,$(subdirs))
158
159 # Compute a list of all those targets.
160 all-subdirs-targets := $(foreach dir,$(subdirs),\
161                                  $(addprefix $(dir)/,$(+subdir_targets)))
162
163 # The action for each of those is to cd into the directory and make the
164 # target there.
165 $(all-subdirs-targets):
166         $(MAKE) -C $(@D) $(@F)
167
168 .PHONY: $(+subdir_targets) $(all-subdirs-targets)
169 \f
170 # Targets to clean things up to various degrees.
171
172 .PHONY: clean realclean distclean distclean-1 parent-clean parent-mostlyclean
173
174 # Subroutines of all cleaning targets.
175 parent-mostlyclean: common-mostlyclean # common-mostlyclean is in Makerules.
176         -rm -f $(common-objpfx)libc.a $(addprefix $(objpfx),$(install-lib))
177 parent-clean: parent-mostlyclean common-clean
178         -rm -f $(addprefix $(common-objpfx),$(common-generated))
179         -rm -f $(addprefix $(objpfx),sysd-Makefile sysd-dirs sysd-rules)
180
181 clean: parent-clean
182 # This is done this way rather than having `subdir_clean' be a
183 # dependency of this target so that libc.a will be removed before the
184 # subdirectories are dealt with and so they won't try to remove object
185 # files from it when it's going to be removed anyway.
186         @$(MAKE) subdir_clean no_deps=t
187 mostlyclean: parent-mostlyclean
188         @$(MAKE) subdir_mostlyclean no_deps=t
189
190 # The realclean target is just like distclean for the parent, but we want
191 # the subdirs to know the difference in case they care.
192 realclean distclean: parent-clean
193 # This is done this way rather than having `subdir_distclean' be a
194 # dependency of this target so that libc.a will be removed before the
195 # subdirectories are dealt with and so they won't try to remove object
196 # files from it when it's going to be removed anyway.
197         @$(MAKE) distclean-1 no_deps=t distclean-1=$@ avoid-generated=yes
198
199 # Subroutine of distclean and realclean.
200 distclean-1: subdir_$(distclean-1)
201         -rm -f $(config-generated)
202         -rm -f $(addprefix $(objpfx),config.status cache.cache)
203         -rm -f $(addprefix $(objpfx),config.make config-name.h)
204 ifdef objdir
205         -rm -f $(objpfx)Makefile
206 endif
207         -rm -f $(sysdep-$(distclean-1))
208 \f
209 .PHONY: echo_subdirs
210 echo_subdirs:;@echo '$(subdirs)'
211
212 .PHONY: echo-distinfo parent_echo-distinfo
213 echo-distinfo: parent_echo-distinfo subdir_echo-distinfo
214 parent_echo-distinfo:
215         @echo $(addprefix +header+,$(headers)) \
216               $(addprefix +nodist+,$(generated))
217 \f
218 # Make the distribution tarfile.
219
220 distribute  := README INSTALL NOTES COPYING.LIB COPYING NEWS            \
221                ChangeLog ChangeLog.[0-9]                                \
222                Makefile Makeconfig Makerules Rules Make-dist MakeTAGS   \
223                extra-lib.mk o-iterator.mk                               \
224                ansidecl.h mkinstalldirs move-if-change install-sh       \
225                configure configure.in aclocal.m4 config.sub config.guess\
226                config.make.in config-name.in Makefile.in                \
227                munch-tmpl.c munch.awk sysdep.h set-hooks.h libc-symbols.h
228
229 distribute := $(strip $(distribute))
230 generated := $(generated) stubs.h
231
232 README: README.template version.c ; # Make-dist should update README.
233
234 define format-me
235 @rm -f $@
236 makeinfo --no-validate --no-warn --no-headers $< -o $@
237 -chmod a-w $@
238 endef
239 INSTALL: manual/maint.texi; $(format-me)
240 NOTES: manual/creature.texi; $(format-me)