summaryrefslogtreecommitdiff
path: root/tools/make/Makefile.DocBook
blob: ebf9fbba5f372220783b99d214d9b254879a6299 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
# $Source$
# $Author: xmldoc $
# $Date: 2008-03-03 09:20:29 +0000 (Mon, 03 Mar 2008) $
# $Revision: 7787 $
# vim: number
#
# -----------------------------------------------------------------
#  ** Makefile.DocBook -- generate output from DocBook sources **
# -----------------------------------------------------------------
#
#   This file is part of the DocBook Project XSL Stylesheet
#   distribution.
#
#   See http://docbook.sourceforge.net/release/xsl/current/
#   for copyright and other information.

# DOCBOOK_OUTPUT_FORMATS is the default set of targets (output
# formats) that get built when you type "make" without any targets
# explicitly specified. To generate a different set of output
# formats, change the value of DOCBOOK_OUTPUT_FORMATS here or set
# it in your environment; for example:
#
#   set DOCBOOK_OUTPUT_FORMATS="html pdf"; export DOCBOOK_OUTPUT_FORMATS
#
# Of course by explicitly specifying particular targets when you
# invoke "make", you can always override generation of the default
# set of targets; for example:
#
#   make html txt
#
# That would generate just HTML (unchunked) and plain-text output.
#
DOCBOOK_OUTPUT_FORMATS ?= xml man man-pdf chunk txt pdf

# If you want XHTML output instead of HTML, set HTML_OR_XHTML to
# 'xhtml' or just specify 'xhtml" in DOCBOOK_OUTPUT_FORMATS.
ifeq ($(findstring xhtml,$(DOCBOOK_OUTPUT_FORMATS)),)
HTML_OR_XHTML ?= html
else
HTML_OR_XHTML ?= xhtml
endif

# if your source is in asciidoc instead of DocBook, set
# ASCII_OR_DOCBOOK to "ascii"
ASCII_OR_DOCBOOK ?= docbook

# -----------------------------------------------------------------
#                *** TOOLS and other DEPENDENCIES ***
# -----------------------------------------------------------------
# we use rmdir(1) to remove dirs we create for chunked HTML output
RMDIR = rmdir
# "-p" causes empty parent dirs to be deleted as well
RMDIR_FLAGS = --ignore-fail-on-non-empty -p

# possible values for PDF_MAKER are:
#   dblatex|fop|xep|xmlroff|passivetex
PDF_MAKER = dblatex

# possible values for TXT_MAKER are:
#   links|lynx|w3m|w3mmee
TXT_MAKER = links
TXT_MAKER_FLAGS = -dump

# xsl
XSLT = xsltproc
XSLT_FLAGS = --xinclude

# http://dblatex.sourceforge.net/
DBLATEX = dblatex
DBLATEX_FLAGS = -b pdftex

FOP = fop
FOP_FLAGS =

XEP = xep
XEP_FLAGS =

# http://xmlroff.sourceforge.net/
XMLROFF = xmlroff
XMLROFF_FLAGS =

PDFTEX = pdftex
PDFTEX_FLAGS =

# used by PassiveTeX
PDFXMLTEX = pdfxmltex

# http://docbook2x.sourceforge.net/
DB2X_XSLTPROC = db2x_xsltproc
DB2X_XSLTPROC_FLAGS = 
DB2X_TEXIXML = db2x_texixml
DB2X_TEXIXML_FLAGS = 

# we call the man(1) command to generate "foo.N.pdf" and
# "foo.N.txt" output (see "man-pdf" & "man-txt" targets)
MAN = man
MAN_FLAGS =

# The "ps2pdf" command is part of GhostSript (gs) distro.
# It is just a wrapper script around gs that does this:
#
#   gs -dCompatibilityLevel=1.2 -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite \
#     "-sOutputFile=$outfile" -dCompatibilityLevel=1.2 -c .setpdfwrite -f "$infile"
#
# Where, for example: $outfile = foo.pdf and $infile = foo.1
PS2PDF = ps2pdf
PS2PDF_FLAGS =

# asciidoc is used to generate DocBook XML from asciidoc source
ASCIIDOC=asciidoc
ASCIIDOCFLAGS=

# asciidoc source seems to have DOS line endings, so we use
# DOS2UNIX to be able to grep them correctly
DOS2UNIX=dos2unix
DOS2UNIXFLAGS=

# The "col" command is needed for stripping backspaces and
# underscores from man(1) output to get pure plain-text
COL = col
COL_FLAGS =

# The "expand" command is needed for expanding tabs from files
# generated from "man foo.1 | col -b" output
# output to get pure plain-text
EXPAND = expand
EXPAND_FLAGS =

# value of DOCBOOK_XSL should either be the canonical
# (docbook.sourceforge.net) URL for the DocBook Project XSL
# stylesheets OR it can be a local system path
DOCBOOK_XSL = http://docbook.sourceforge.net/release/xsl/current

# -----------------------------------------------------------------
#       names of some DIRECTORIES and FILES we need
# -----------------------------------------------------------------
# We create a tmp directory once per make invocation; it's needed
# for holding a temporary copy of the custom DBLaTeX stylesheet
# (because dblatex currently can't read a stylesheet from stdin)
TMP ?= /tmp
TMPNUM := $(shell echo $$$$)
DOCBOOK_TMP := $(TMP)/docbook-make-$(TMPNUM)

# MAN_MANIFEST_EXT is file extension added to individual manifest
# files
MAN_MANIFEST_EXT = manifest_man

# HTML_MANIFEST_EXT is file extension added to HTML manifest files
HTML_MANIFEST_EXT = manifest_html

# BASEDIR_SUFFIX is a what you need to set if you want a suffix
# added to the end of each "base.dir" we create while generating
# chunked HTML output
#BASEDIR_SUFFIX = -html
#BASEDIR_SUFFIX = _html
BASEDIR_SUFFIX = 

# -----------------------------------------------------------------
#                        assorted OPTIONS
# -----------------------------------------------------------------
# HTML_STYLESHEET -> $html.stylesheet stylesheet param
# http://docbook.sourceforge.net/snapshots/xsl/doc/html/html.stylesheet.html
HTML_STYLESHEET = style.css
# HTML_IMAGES -> $admon.graphics.path
# http://docbook.sourceforge.net/snapshots/xsl/doc/html/admon.graphics.path.html
HTML_IMAGES = images/
# HTML_IMAGES_EXT -> $admon.graphics.extension
# http://docbook.sourceforge.net/snapshots/xsl/doc/html/admon.graphics.extension.html
HTML_IMAGES_EXT = .png

# use these to set params on the command-line
# format is, e.g., HTML_PARAMS="--stringparam variablelist.as.table 1..."
FO_PARAMS =
HTML_PARAMS =
MAN_PARAMS =

# DBX_PARAMS is for dblatex(1); format uses "-p":
# DBX_PARAMS="-p doc.publisher.show 1 -p term.breakline 1...
DBX_PARAMS=

# What file extension do you use for DocBook source files?
DOCBOOK_FILE_EXTENSION = .xml

# -----------------------------------------------------------------
#       make(1) functions for building file lists
# -----------------------------------------------------------------
#
#    the values of the following are used for determing what needs
#    to be built and/or cleaned up

ifeq ($(ASCII_OR_DOCBOOK),docbook)
SOURCE_FILES_DBK = $(wildcard *$(DOCBOOK_FILE_EXTENSION))
else
SOURCE_FILES_DBK = $(foreach base,$(basename $(wildcard *.txt)),$(base)$(DOCBOOK_FILE_EXTENSION))
endif

FILES_FO   = $(foreach base,$(basename $(SOURCE_FILES_DBK)),$(base).fo)
FILES_TXT  = $(foreach base,$(basename $(SOURCE_FILES_DBK)),$(base).out.txt)
FILES_PDF  = $(foreach base,$(basename $(SOURCE_FILES_DBK)),$(base).pdf)
FILES_LOG  = $(foreach base,$(basename $(SOURCE_FILES_DBK)),$(base).log)
FILES_OUT  = $(foreach base,$(basename $(SOURCE_FILES_DBK)),$(base).out)
FILES_AUX  = $(foreach base,$(basename $(SOURCE_FILES_DBK)),$(base).aux)
FILES_HTML = $(foreach base,$(basename $(SOURCE_FILES_DBK)),$(base).html)
FILES_INFO = $(foreach base,$(basename $(SOURCE_FILES_DBK)),$(base).info)
DIRS_CHUNK = $(foreach base,$(basename $(SOURCE_FILES_DBK)),$(base)$(BASEDIR_SUFFIX))
LISTS_HTML = $(foreach base,$(basename $(SOURCE_FILES_DBK)),$(base).$(HTML_MANIFEST_EXT))
LISTS_MAN  = $(foreach base,$(basename $(SOURCE_FILES_DBK)),$(base).$(MAN_MANIFEST_EXT))
FILES_CHNK = $(shell for manifest in $(LISTS_HTML); do if [ -f "$$manifest" ]; then cat $$manifest; fi done)
FILES_MAN  = $(shell for manifest in $(LISTS_MAN);  do if [ -f "$$manifest" ]; then cat $$manifest; fi done)
FILES_MANP = $(foreach base,$(FILES_MAN),$(base).man.pdf)
FILES_MANT = $(foreach base,$(FILES_MAN),$(base).out.txt)
DIRS_MAN   = $(shell for file in $(FILES_MAN); do dirname $$file; done | uniq)

# -----------------------------------------------------------------
#   ** stylesheet for testing whether a file has a refentry
# -----------------------------------------------------------------
REFENTRY_CHECK := <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" \
                version="1.0" \
                xmlns:db="http://docbook.org/ns/docbook" \
                > \
  <xsl:output method="text"/> \
  <xsl:template match="/"> \
    <xsl:if test="//refentry|//db:refentry"> \
      <xsl:text>true</xsl:text> \
    </xsl:if> \
  </xsl:template> \
</xsl:stylesheet>

# -----------------------------------------------------------------
#             ** Stylesheet Customization Layers ** 
# -----------------------------------------------------------------
#
# for DBLaTeX
DBX_CUSTOM := <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" \
                 version="1.0"> \
  <xsl:param name="co.linkends.show">0</xsl:param> \
  <xsl:param name="callout.markup.circled">1</xsl:param> \
  <xsl:param name="callout.linkends.hot">0</xsl:param> \
  <xsl:param name="doc.publisher.show">1</xsl:param> \
  <xsl:param name="term.breakline">1</xsl:param> \
  <xsl:param name="doc.alignment">left</xsl:param> \
  <xsl:param name="newtbl.use">1</xsl:param> \
  <xsl:param name="latex.hyperparam"/> \
  <xsl:param name="latex.style">docbook</xsl:param> \
  <xsl:param name="latex.biblio.output">all</xsl:param> \
  <xsl:param name="latex.bibfiles">""</xsl:param> \
  <xsl:param name="latex.bibwidelabel">WIDELABEL</xsl:param> \
  <xsl:param name="latex.output.revhistory">0</xsl:param> \
  <xsl:param name="latex.figure.position">[htbp]</xsl:param> \
  <xsl:param name="latex.figure.boxed">0</xsl:param> \
  <xsl:param name="latex.babel.use">1</xsl:param> \
  <xsl:param name="latex.babel.language"></xsl:param> \
  <xsl:param name="latex.class.options">twoside</xsl:param> \
  <xsl:param name="biblioentry.item.separator">, </xsl:param> \
  <xsl:param name="refentry.xref.manvolnum">1</xsl:param> \
  <xsl:param name="refsynopsis.title">Synopsis</xsl:param> \
  <xsl:param name="refnamediv.title"></xsl:param> \
  <xsl:param name="funcsynopsis.style">ansi</xsl:param> \
  <xsl:param name="funcsynopsis.decoration">1</xsl:param> \
  <xsl:param name="function.parens">0</xsl:param> \
  <xsl:param name="classsynopsis.default.language">java</xsl:param> \
  <xsl:param name="show.comments">0</xsl:param> \
</xsl:stylesheet>

# for FO output
FO_CUSTOM := <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" \
                xmlns:fo="http://www.w3.org/1999/XSL/Format" \
                version="1.0"> \
  <xsl:import href="$(DOCBOOK_XSL)/fo/docbook.xsl"/> \
  <xsl:param name="$(PDF_MAKER).extensions">1</xsl:param> \
  <xsl:param name="paper.type">A4</xsl:param> \
  <xsl:param name="draft.watermark.image"></xsl:param> \
  <xsl:param name="hyphenation">false</xsl:param> \
  <xsl:param name="hyphenate.verbatim">1</xsl:param> \
  <xsl:param name="alignment">left</xsl:param> \
  <xsl:param name="refentry.generate.name">1</xsl:param> \
  <xsl:param name="refentry.generate.title">0</xsl:param> \
  <xsl:param name="refentry.pagebreak">1</xsl:param> \
  <xsl:param name="shade.verbatim">1</xsl:param> \
  <xsl:param name="variablelist.as.blocks">1</xsl:param> \
  <xsl:param name="ulink.show">1</xsl:param> \
  <xsl:param name="ulink.footnotes">1</xsl:param> \
  <xsl:param name="index.on.type">1</xsl:param> \
  <xsl:attribute-set name="xref.properties"> \
    <xsl:attribute name="color">blue</xsl:attribute> \
  </xsl:attribute-set> \
  <xsl:attribute-set name="shade.verbatim.style"> \
    <xsl:attribute name="background-color">\#E0E0E0</xsl:attribute> \
    <xsl:attribute name="padding-left">4pt</xsl:attribute> \
    <xsl:attribute name="padding-right">4pt</xsl:attribute> \
    <xsl:attribute name="padding-top">4pt</xsl:attribute> \
    <xsl:attribute name="padding-bottom">4pt</xsl:attribute> \
  </xsl:attribute-set> \
  <xsl:attribute-set name="section.title.level1.properties"> \
    <xsl:attribute name="font-size"> \
      <xsl:value-of select="$$body.font.master * 1.5"></xsl:value-of> \
      <xsl:text>pt</xsl:text> \
    </xsl:attribute> \
  </xsl:attribute-set> \
  <xsl:attribute-set name="section.title.level2.properties"> \
    <xsl:attribute name="font-size"> \
      <xsl:value-of select="$$body.font.master * 1.3"></xsl:value-of> \
      <xsl:text>pt</xsl:text> \
    </xsl:attribute> \
  </xsl:attribute-set> \
  <xsl:attribute-set name="section.title.level3.properties"> \
    <xsl:attribute name="font-size"> \
      <xsl:value-of select="$$body.font.master * 1.1"></xsl:value-of> \
      <xsl:text>pt</xsl:text> \
    </xsl:attribute> \
  </xsl:attribute-set> \
  <xsl:attribute-set name="section.title.level4.properties"> \
    <xsl:attribute name="font-size"> \
      <xsl:value-of select="$$body.font.master"></xsl:value-of> \
      <xsl:text>pt</xsl:text> \
    </xsl:attribute> \
  </xsl:attribute-set> \
  <xsl:attribute-set name="component.title.properties"> \
    <xsl:attribute name="font-size"> \
      <xsl:value-of select="$$body.font.master * 1.5"></xsl:value-of> \
      <xsl:text>pt</xsl:text> \
    </xsl:attribute> \
  </xsl:attribute-set> \
  <xsl:attribute-set name="monospace.verbatim.properties"> \
    <xsl:attribute name="wrap-option">wrap</xsl:attribute> \
    <xsl:attribute name="hyphenation-character">\</xsl:attribute> \
    <xsl:attribute name="font-size"> \
      <xsl:value-of select="$$body.font.master * 0.8"></xsl:value-of> \
      <xsl:text>pt</xsl:text> \
    </xsl:attribute> \
  </xsl:attribute-set> \
</xsl:stylesheet>

# for single-file (X)HTML outpout
HTML_CUSTOM := <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" \
                version="1.0"> \
  <xsl:import href="$(DOCBOOK_XSL)/$(HTML_OR_XHTML)/docbook.xsl"/> \
  <xsl:param name="gentext.custom">local.l10n.xml</xsl:param> \
  <xsl:param name="local.l10n.xml" select="document($$gentext.custom)"/> \
  <xsl:param name="refentry.generate.name">1</xsl:param> \
  <xsl:param name="refentry.generate.title">0</xsl:param> \
  <xsl:param name="root.filename"></xsl:param> \
  <xsl:param name="variablelist.as.table">0</xsl:param> \
  <xsl:param name="html.stylesheet">$(HTML_STYLESHEET)</xsl:param> \
  <xsl:param name="admon.graphics">0</xsl:param> \
  <xsl:param name="index.on.type">1</xsl:param> \
</xsl:stylesheet>

# for chunked (X)HTML output
CHNK_CUSTOM := <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" \
                version="1.0"> \
  <xsl:import href="$(DOCBOOK_XSL)/$(HTML_OR_XHTML)/chunk.xsl"/> \
  <xsl:param name="refentry.generate.name">0</xsl:param> \
  <xsl:param name="refentry.generate.title">1</xsl:param> \
  <xsl:param name="variablelist.as.table">0</xsl:param> \
  <xsl:param name="html.stylesheet">$(HTML_STYLESHEET)</xsl:param> \
  <xsl:param name="admon.graphics">1</xsl:param> \
  <xsl:param name="admon.graphics.path">$(HTML_IMAGES)</xsl:param> \
  <xsl:param name="admon.graphics.extension">$(HTML_IMAGES_EXT)</xsl:param> \
  <xsl:param name="root.filename"></xsl:param> \
  <xsl:param name="generate.manifest">1</xsl:param> \
  <xsl:param name="use.id.as.filename">1</xsl:param> \
  <xsl:param name="chunker.output.indent">yes</xsl:param> \
  <xsl:param name="index.on.type">1</xsl:param> \
</xsl:stylesheet>

# for man-page output
MAN_CUSTOM := <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" \
                version="1.0"> \
  <xsl:import href="$(DOCBOOK_XSL)/manpages/docbook.xsl"/> \
  <xsl:param name="man.output.manifest.enabled" select="1"/> \
  <xsl:param name="man.output.in.separate.dir" select="1"/> \
  <xsl:param name="man.output.base.dir">man/</xsl:param> \
  <xsl:param name="man.output.subdirs.enabled" select="1"/> \
</xsl:stylesheet>

# -----------------------------------------------------------------
#                  ** TARGETS START HERE ** 
# -----------------------------------------------------------------
#  prevents make from deleting, e.g. foo.1, after making foo.1.pdf
#  and foo.1.txt from it.
.PRECIOUS: %.1 %.2 %.3 %.4 %.5 %.6 %.7 %.8 %.9

docbook: $(DOCBOOK_OUTPUT_FORMATS)

xml: $(SOURCE_FILES_DBK)

man: $(LISTS_MAN)

# we can generate PDFs from man pages
man-pdf: man
	$(MAKE) $(FILES_MANP)

# we can generate plain text from man pages
man-txt: man
	$(MAKE) $(FILES_MANT)

html: $(FILES_HTML)

chunk: $(LISTS_HTML)

txt: $(FILES_TXT)

pdf: $(FILES_PDF)

info: $(FILES_INFO)

# use the "debug" target to echo variables, etc., to
# test/troubleshoot changes you make to this makefile
debug:
	echo $(wildcard *$(DOCBOOK_FILE_EXTENSION))
	echo $(ASCII_OR_DOCBOOK)
	echo $(SOURCE_FILES_DBK)

# -----------------------------------------------------------------
#     pattern rule to make DocBook refentry from asciidoc source
# -----------------------------------------------------------------
%.1$(DOCBOOK_FILE_EXTENSION): %.1.txt
	$(ASCIIDOC) $(ASCIIDOCFLAGS) -d manpage -b docbook $<

%.2$(DOCBOOK_FILE_EXTENSION): %.2.txt
	$(ASCIIDOC) $(ASCIIDOCFLAGS) -d manpage -b docbook $<

%.3$(DOCBOOK_FILE_EXTENSION): %.3.txt
	$(ASCIIDOC) $(ASCIIDOCFLAGS) -d manpage -b docbook $<

%.4$(DOCBOOK_FILE_EXTENSION): %.4.txt
	$(ASCIIDOC) $(ASCIIDOCFLAGS) -d manpage -b docbook $<

%.5$(DOCBOOK_FILE_EXTENSION): %.5.txt
	$(ASCIIDOC) $(ASCIIDOCFLAGS) -d manpage -b docbook $<

%.6$(DOCBOOK_FILE_EXTENSION): %.6.txt
	$(ASCIIDOC) $(ASCIIDOCFLAGS) -d manpage -b docbook $<

%.7$(DOCBOOK_FILE_EXTENSION): %.7.txt
	$(ASCIIDOC) $(ASCIIDOCFLAGS) -d manpage -b docbook $<

%.8$(DOCBOOK_FILE_EXTENSION): %.8.txt
	$(ASCIIDOC) $(ASCIIDOCFLAGS) -d manpage -b docbook $<

%.9$(DOCBOOK_FILE_EXTENSION): %.9.txt
	$(ASCIIDOC) $(ASCIIDOCFLAGS) -d manpage -b docbook $<

# -----------------------------------------------------------------
#     pattern rule to make DocBook article from asciidoc source
# -----------------------------------------------------------------
%$(DOCBOOK_FILE_EXTENSION): %.txt
	export LINECOUNT1=$$(cat $< | $(DOS2UNIX) $(DOS2UNIXFLAGS) | egrep "^=+$$" | wc -l); \
	export LINECOUNT2=$$(cat $< | $(DOS2UNIX) $(DOS2UNIXFLAGS) | egrep "^= $$" | wc -l); \
	if [[ $$LINECOUNT1 > 1 || $$LINECOUNT2 > 1 ]]; then \
	$(ASCIIDOC) $(ASCIIDOCFLAGS) -d book -b docbook $<; \
	else \
	$(ASCIIDOC) $(ASCIIDOCFLAGS) -b docbook $<; \
	fi

# -----------------------------------------------------------------
#     pattern rule for making (X)HTML and plain-text output
# -----------------------------------------------------------------
%.html: %$(DOCBOOK_FILE_EXTENSION)
	@echo '$(HTML_CUSTOM)' | $(XSLT) $(XSLT_FLAGS) $(HTML_PARAMS) - $< > $@

%.out.txt: %.html
	$(TXT_MAKER) $(TXT_MAKER_FLAGS) ./$< \
	  | sed "s/^\(\s\+[0-9]\+\. \)file:\/\/.\+$$/\\1(local)/g" \
	  | egrep -v '^	file:///.+$$' \
	  > $@
# if DOCBOOK_OUTPUT_FORMATS does not contain "html", then we need
# to remove the "intermediate" HTML files we used for generating
# plain-text output
ifeq ($(findstring html,$(DOCBOOK_OUTPUT_FORMATS)),)
	$(RM) $<
endif

# -----------------------------------------------------------------
#     pattern rule for making chunked (X)HTML pages
# -----------------------------------------------------------------
%.$(HTML_MANIFEST_EXT): %$(DOCBOOK_FILE_EXTENSION)
	@echo '$(CHNK_CUSTOM)' | $(XSLT) $(XSLT_FLAGS) $(HTML_PARAMS) \
	--stringparam manifest $@  \
	--stringparam base.dir $(basename $@)$(BASEDIR_SUFFIX)/  \
	- $< 

# -----------------------------------------------------------------
#     pattern rules for making FO and PDF stuff
# -----------------------------------------------------------------
%.fo: %$(DOCBOOK_FILE_EXTENSION)
	@echo '$(FO_CUSTOM)' \
	  | $(XSLT) $(XSLT_FLAGS) $(FO_PARAMS) - $< > $@

ifeq ($(PDF_MAKER),dblatex)
%.pdf: %$(DOCBOOK_FILE_EXTENSION)
	mkdir -p $(DOCBOOK_TMP)
	echo '$(DBX_CUSTOM)' > $(DOCBOOK_TMP)/dblatex.xsl
	-$(DBLATEX) $(DBLATEX_FLAGS)\
	  -p $(DOCBOOK_TMP)/dblatex.xsl \
	  -o $@ \
	  $<
	$(RM) -r $(DOCBOOK_TMP)
endif

%.pdf: %.fo
ifeq ($(PDF_MAKER),)
	$(error No PDF_MAKER specified. Cannot make pdf)
else
ifeq ($(PDF_MAKER),xep)
	$(XEP) $(XEP_FLAGS) $< $@
else
ifeq ($(PDF_MAKER),fop)
	$(FOP) $(FOP_FLAGS) $< $@
else
ifeq ($(PDF_MAKER),xmlroff)
	$(XMLROFF) $(XMLROFF_FLAGS) $< -o $@
else
ifeq ($(PDF_MAKER),passivetex)
	$(PDFTEX) $(PDFTEX_FLAGS) &$(PDFXMLTEX) $<
	@if [ `egrep Rerun $(basename $@).log | wc -l` -gt 0 ]; then \
		$(PDFTEX) $(PDFTEX_FLAGS) &$(PDFXMLTEX) $< ; \
	fi
	@if [ `egrep Rerun $(basename $@).log | wc -l` -gt 0 ]; then \
		$(PDFTEX) $(PDFTEX_FLAGS) &$(PDFXMLTEX) $< ; \
	fi
	$(RM) $(basename $@).log
	$(RM) $(basename $@).aux
	$(RM) $(basename $@).out
else
	$(error I do not know how to make a PDF using "$(PDF_MAKER)")
endif
endif
endif
endif
endif

# -----------------------------------------------------------------
#     pattern rules for making TeXinfo stuff
# -----------------------------------------------------------------
%.txml: %$(DOCBOOK_FILE_EXTENSION)
	$(DB2X_XSLTPROC) $(DB2X_XSLTPROC_FLAGS) -s texi -o $@ $<

%.texi: %.txml
	$(DB2X_TEXIXML) $(DB2X_TEXIXML_FLAGS) $<

# the following is actually a built-in rule, but it's redefined
# here just for the sake of clarity
%.info: %.texi
	$(MAKEINFO) $(MAKEINFO_FLAGS) $< -o $@

# -----------------------------------------------------------------
#     pattern rule for making man pages
# -----------------------------------------------------------------
%.$(MAN_MANIFEST_EXT): %$(DOCBOOK_FILE_EXTENSION)
	@if [ "$(strip $(shell echo '$(REFENTRY_CHECK)' | $(XSLT) $(XSLT_FLAGS) - $<))" != "true" ]; then \
	  touch $@; \
	else \
	  echo '$(MAN_CUSTOM)' \
	  | $(XSLT) $(XSLT_FLAGS) $(MAN_PARAMS) \
	    --stringparam man.output.manifest.filename $@ \
	    - $<; \
	fi

# -----------------------------------------------------------------
#  pattern rule for enabling direct "make foo.1" to work
# -----------------------------------------------------------------

%.1 %.2 %.3 %.4 %.5 %.6 %.7: %.xml
	$(MAKE) $(basename $<).$(MAN_MANIFEST_EXT)

# -----------------------------------------------------------------
#  pattern rules for making Postscript/PDF output from man pages
# -----------------------------------------------------------------
%.1.man.ps: %.1
	$(MAN) -l $(MAN_FLAGS) -Tps $< > $@

%.2.man.ps: %.2
	$(MAN) -l $(MAN_FLAGS) -Tps $< > $@

%.3.man.ps: %.3
	$(MAN) -l $(MAN_FLAGS) -Tps $< > $@

%.4.man.ps: %.4
	$(MAN) -l $(MAN_FLAGS) -Tps $< > $@

%.5.man.ps: %.5
	$(MAN) -l $(MAN_FLAGS) -Tps $< > $@

%.6.man.ps: %.6
	$(MAN) -l $(MAN_FLAGS) -Tps $< > $@

%.7.man.ps: %.7
	$(MAN) -l $(MAN_FLAGS) -Tps $< > $@

%.8.man.ps: %.8
	$(MAN) -l $(MAN_FLAGS) -Tps $< > $@

%.9.man.ps: %.9
	$(MAN) -l $(MAN_FLAGS) -Tps $< > $@

# -----------------------------------------------------------------
#  pattern rule for converting Postscript to PDF
# -----------------------------------------------------------------
%.pdf: %.ps
	$(PS2PDF) $(PS2PDF_FLAGS) $<

# -----------------------------------------------------------------
#  pattern rules for making plain-text output from man pages
# -----------------------------------------------------------------
%.1.out.txt: %.1
	$(MAN) -l $(MAN_FLAGS) -Tascii $< | $(COL) -b $(COL_FLAGS) | $(EXPAND) $(EXPAND_FLAGS) > $@

%.2.out.txt: %.2
	$(MAN) -l $(MAN_FLAGS) -Tascii $< | $(COL) -b $(COL_FLAGS) | $(EXPAND) $(EXPAND_FLAGS) > $@

%.3.out.txt: %.3
	$(MAN) -l $(MAN_FLAGS) -Tascii $< | $(COL) -b $(COL_FLAGS) | $(EXPAND) $(EXPAND_FLAGS) > $@

%.4.out.txt: %.4
	$(MAN) -l $(MAN_FLAGS) -Tascii $< | $(COL) -b $(COL_FLAGS) | $(EXPAND) $(EXPAND_FLAGS) > $@

%.5.out.txt: %.5
	$(MAN) -l $(MAN_FLAGS) -Tascii $< | $(COL) -b $(COL_FLAGS) | $(EXPAND) $(EXPAND_FLAGS) > $@

%.6.out.txt: %.6
	$(MAN) -l $(MAN_FLAGS) -Tascii $< | $(COL) -b $(COL_FLAGS) | $(EXPAND) $(EXPAND_FLAGS) > $@

%.7.out.txt: %.7
	$(MAN) -l $(MAN_FLAGS) -Tascii $< | $(COL) -b $(COL_FLAGS) | $(EXPAND) $(EXPAND_FLAGS) > $@

%.8.out.txt: %.8
	$(MAN) -l $(MAN_FLAGS) -Tascii $< | $(COL) -b $(COL_FLAGS) | $(EXPAND) $(EXPAND_FLAGS) > $@

%.9.out.txt: %.9
	$(MAN) -l $(MAN_FLAGS) -Tascii $< | $(COL) -b $(COL_FLAGS) | $(EXPAND) $(EXPAND_FLAGS) > $@

# -----------------------------------------------------------------
#   target(s) for cleaning up the mess
# -----------------------------------------------------------------
clean:
ifneq ($(FILES_TXT),)
	$(RM) $(FILES_TXT)
endif
ifneq ($(FILES_PDF),)
	$(RM) $(FILES_PDF)
endif
ifneq ($(FILES_FO),)
	$(RM) $(FILES_FO)
endif
ifneq ($(FILES_LOG),)
	$(RM) $(FILES_LOG)
endif
ifneq ($(FILES_OUT),)
	$(RM) $(FILES_OUT)
endif
ifneq ($(FILES_AUX),)
	$(RM) $(FILES_AUX)
endif
ifneq ($(FILES_HTML),)
	$(RM) $(FILES_HTML)
endif
ifneq ($(FILES_CHNK),)
	$(RM) $(FILES_CHNK)
endif
ifneq ($(FILES_MAN),)
	$(RM) $(FILES_MAN)
endif
ifneq ($(FILES_MANT),)
	$(RM) $(FILES_MANT)
endif
ifneq ($(FILES_MANP),)
	$(RM) $(FILES_MANP)
endif
ifneq ($(FILES_INFO),)
	$(RM) $(FILES_INFO)
endif
ifneq ($(DIRS_CHUNK),)
	for dir in $(DIRS_CHUNK); do \
	  if [ -d "$$dir" ]; then \
	    $(RMDIR) $(RMDIR_FLAGS) $$dir; \
	  fi \
	done
endif
ifneq ($(DIRS_MAN),)
ifneq ($(DIRS_MAN),.)
	for dir in $(DIRS_MAN); do \
	  if [ -d "$$dir" ]; then \
	    $(RMDIR) $(RMDIR_FLAGS) $$dir; \
	  fi \
	done
endif
endif
ifneq ($(LISTS_MAN),)
	$(RM) $(LISTS_MAN)
endif
ifneq ($(LISTS_HTML),)
	$(RM) $(LISTS_HTML)
endif
ifneq ($(ASCII_OR_DOCBOOK),docbook)
	$(RM) -i $(SOURCE_FILES_DBK)
endif