BZ #13792: License manual example source files under GPL.
[platform/upstream/glibc.git] / manual / Makefile
1 # Copyright (C) 1992-2012
2 #       Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
4
5 # The GNU C Library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9
10 # The GNU C Library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with the GNU C Library; if not, see
17 # <http://www.gnu.org/licenses/>.
18
19 # Makefile for the GNU C Library manual.
20
21 subdir := manual
22 export subdir := $(subdir)
23
24 # Allow override
25 INSTALL_INFO = install-info
26
27 .PHONY: all dvi pdf info html
28 all: dvi
29 dvi: libc.dvi
30 pdf: libc.pdf
31
32 # Get glibc's configuration info.
33 ifneq (,$(wildcard ../Makeconfig))
34 include ../Makeconfig
35 else
36 MAKEINFO = makeinfo
37 TEXI2DVI = texi2dvi
38 AWK = gawk
39 endif
40
41 TEXI2PDF = texi2dvi --pdf
42
43 ifneq ($(strip $(MAKEINFO)),:)
44 all: info
45 info: libc.info
46 endif
47
48 # scripts we use
49 ifndef move-if-change
50 move-if-change = ./move-if-change
51 endif
52 mkinstalldirs = $(..)scripts/mkinstalldirs
53
54 chapters = $(addsuffix .texi, \
55                        intro errno memory ctype string charset locale   \
56                        message search pattern io stdio llio filesys     \
57                        pipe socket terminal syslog math arith time      \
58                        resource setjmp signal startup process job nss   \
59                        users sysinfo conf crypt debug)
60 add-chapters = $(wildcard $(foreach d, $(add-ons), ../$d/$d.texi))
61 appendices = lang.texi header.texi install.texi maint.texi contrib.texi
62 licenses = freemanuals.texi lgpl-2.1.texi fdl-1.3.texi
63
64 -include texis
65 texis: texis.awk $(chapters) $(add-chapters) $(appendices) $(licenses)
66         $(AWK) -f $^ > $@.T
67         mv -f $@.T $@
68
69 nonexamples = $(filter-out $(add-chapters) %.c.texi, $(texis))
70 examples = $(filter-out $(foreach d, $(add-ons), ../$d/%.c.texi), \
71                         $(filter %.c.texi, $(texis)))
72
73 # Kludge: implicit rule so Make knows the one command does it all.
74 chapters.% top-menu.%: libc-texinfo.sh $(texis) Makefile
75         AWK=$(AWK) $(SHELL) $< '$(chapters)' \
76                                '$(add-chapters)' \
77                                '$(appendices) $(licenses)'
78
79 # Generated files directly included from libc.texinfo.
80 libc-texi-generated = chapters.texi top-menu.texi dir-add.texi \
81                       libm-err.texi version.texi
82
83 libc.dvi libc.pdf libc.info: $(libc-texi-generated)
84 libc.dvi libc.pdf: texinfo.tex
85
86 html: libc/index.html
87 libc/index.html: $(libc-texi-generated)
88         $(MAKEINFO) --html libc.texinfo
89
90 # Generate the summary from the Texinfo source files for each chapter.
91 summary.texi: stamp-summary ;
92 stamp-summary: summary.awk $(filter-out summary.texi, $(texis))
93         $(AWK) -f $^ | sort -t'\f' -df -k 1,1 | tr '\014' '\012' > summary-tmp
94         $(move-if-change) summary-tmp summary.texi
95         touch $@
96
97 # Generate a file which can be added to the `dir' content to provide direct
98 # access to the documentation of the function, variables, and other
99 # definitions.
100 dir-add.texi: xtract-typefun.awk $(texis)
101         (echo "@dircategory GNU C library functions and macros";        \
102          echo "@direntry";                                              \
103          $(AWK) -f $^ | sort;                                           \
104          echo "@end direntry") > $@.new
105         mv -f $@.new $@
106
107 # The table with the math errors is generated.
108 libm-err.texi: stamp-libm-err
109 stamp-libm-err: libm-err-tab.pl $(wildcard $(foreach dir,$(sysdirs),\
110                                                      $(dir)/libm-test-ulps))
111         pwd=`pwd`; \
112         $(PERL) $< $$pwd/.. > libm-err-tmp
113         $(move-if-change) libm-err-tmp libm-err.texi
114         touch $@
115
116 # Generate a file with the version number.
117 version.texi: stamp-version ;
118 stamp-version: $(common-objpfx)config.make
119         echo "@set VERSION $(version)" > version-tmp
120         $(move-if-change) version-tmp version.texi
121         touch $@
122
123 # Generate Texinfo files from the C source for the example programs.
124 %.c.texi: examples/%.c
125         sed -e '1,/^\*\/$$/d'                           \
126             -e 's,[{}],@&,g'                            \
127             -e 's,/\*\(@.*\)\*/,\1,g'                   \
128             -e 's,/\*  *,/* @r{,g' -e 's,  *\*/,} */,'  \
129             -e 's/\(@[a-z][a-z]*\)@{\([^}]*\)@}/\1{\2}/g'\
130             $< | expand > $@.new
131         mv -f $@.new $@
132
133 %.info: %.texinfo
134         LANGUAGE=C LC_ALL=C $(MAKEINFO) $<
135
136 %.dvi: %.texinfo
137         $(TEXI2DVI) $<
138
139 %.pdf: %.texinfo
140         $(TEXI2PDF) $<
141
142 # Distribution.
143 minimal-dist = summary.awk texis.awk tsort.awk libc-texinfo.sh libc.texinfo \
144                libm-err.texi stamp-libm-err                                 \
145                $(filter-out summary.texi, $(nonexamples))                   \
146                $(patsubst %.c.texi,examples/%.c, $(examples))
147
148 doc-only-dist = Makefile COPYING.LIB
149 distribute = $(minimal-dist) $(examples) stdio-fp.c     \
150              libc.info* libc.?? libc.??s texinfo.tex    \
151              xtract-typefun.awk dir-add.texi dir libm-err-tab.pl
152 export distribute := $(distribute)
153
154 tar-it = tar chovf $@ $^
155
156 manual.tar: $(doc-only-dist) $(minimal-dist) ; $(tar-it)
157 mandist.tar: $(doc-only-dist) $(distribute) ; $(tar-it)
158
159 edition := $(shell sed -n 's/^@set EDITION \([0-9][0-9.]*\)[^0-9.]*.*$$/\1/p' \
160                        libc.texinfo)
161
162 glibc-doc-$(edition).tar: $(doc-only-dist) $(distribute)
163         @rm -f glibc-doc-$(edition)
164         ln -s . glibc-doc-$(edition)
165         tar chovf $@ $(addprefix glibc-doc-$(edition)/,$^)
166         rm -f glibc-doc-$(edition)
167
168 %.Z: %
169         compress -c $< > $@.new
170         mv -f $@.new $@
171 %.gz: %
172         gzip -9 -c $< > $@.new
173         mv -f $@.new $@
174 %.uu: %
175         uuencode $< < $< > $@.new
176         mv -f $@.new $@
177
178 .PHONY: mostlyclean distclean realclean clean
179 mostlyclean:
180         -rm -f libc.dvi libc.pdf libc.tmp libc.info*
181         -rm -f $(objpfx)stubs
182         -rm -f $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
183 clean: mostlyclean
184 distclean: clean
185 indices = cp fn pg tp vr ky
186 realclean: distclean
187         -rm -f texis summary.texi stamp-summary *.c.texi
188         -rm -f $(foreach index,$(indices),libc.$(index) libc.$(index)s)
189         -rm -f libc.log libc.aux libc.toc
190         -rm -f $(libc-texi-generated)
191
192 .PHONY: install subdir_install installdirs install-data
193 install-data subdir_install: install
194 ifneq ($(strip $(MAKEINFO)),:)
195 install: $(inst_infodir)/libc.info
196         @if $(SHELL) -c '$(INSTALL_INFO) --version' >/dev/null 2>&1; then \
197          test -f $(inst_infodir)/dir || $(INSTALL_DATA) dir $(inst_infodir);\
198          $(INSTALL_INFO) --info-dir=$(inst_infodir) $(inst_infodir)/libc.info;\
199         else : ; fi
200 endif
201 # Catchall implicit rule for other installation targets from the parent.
202 install-%: ;
203
204 $(inst_infodir)/libc.info: libc.info installdirs
205         for file in $<*; do \
206           $(INSTALL_DATA) $$file $(@D)/$$file; \
207         done
208
209 installdirs:
210         $(mkinstalldirs) $(inst_infodir)
211
212 .PHONY: dist
213 dist: # glibc-doc-$(edition).tar.gz
214
215 ifneq (,$(wildcard ../Make-dist))
216 dist: ../Make-dist
217         $(MAKE) -f $< $(Make-dist-args)
218 endif
219
220 ifndef ETAGS
221 ETAGS = etags -T
222 endif
223 TAGS: $(minimal-dist)
224         $(ETAGS) -o $@ $^
225 \f
226 # The parent makefile sometimes invokes us with targets `subdir_REAL-TARGET'.
227 subdir_%: % ;
228 # For targets we don't define, do nothing.
229 subdir_%: ;
230
231 # These are targets that each glibc subdirectory is expected to understand.
232 # ../Rules defines them for code subdirectories; for us, they are no-ops.
233 # None of these should be `subdir_TARGET'; those targets are transformed
234 # by the implicit rule above into `TARGET' deps.
235 glibc-targets   := lib objects objs others tests xtests lint.out echo-headers
236 .PHONY: $(glibc-targets)
237 $(glibc-targets):
238
239 # Create stamp files if they don't exist, so the parent makefile's rules for
240 # updating the library archives are happy with us, and never think we have
241 # changed the library.
242 lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
243 ifdef objpfx
244 .PHONY: stubs
245 stubs: $(objpfx)stubs
246 endif
247 $(objpfx)stubs ../po/manual.pot:
248         $(make-target-directory)
249         touch $@
250 $(objpfx)stamp%:
251         $(make-target-directory)
252         touch $@
253
254 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
255 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
256 define make-target-directory
257 $(addprefix $(mkinstalldirs) ,\
258             $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
259 endef
260
261 # The top-level glibc Makefile expects subdir_install to update the stubs file.
262 subdir_install: stubs
263 \f
264 # Get rid of these variables if they came from the parent.
265 routines =
266 aux =
267 sources =
268 objects =
269 headers =