10bbfda8aSnia#
20bbfda8aSnia# Find and setup asciidoc[tor] bits
30bbfda8aSnia#
40bbfda8aSnia
50bbfda8aSnia
60bbfda8aSnia# First see if we can find the programs
70bbfda8aSniafind_program(ASCIIDOCTOR asciidoctor)
80bbfda8aSniafind_program(ASCIIDOC asciidoc)
90bbfda8aSniafind_program(A2X a2x)
100bbfda8aSniafind_program(DBLATEX dblatex)
110bbfda8aSniafind_program(XMLTO xmlto)
120bbfda8aSnia
130bbfda8aSnia
140bbfda8aSnia# If we have asciidoctor, we need to figure out the version, as manpage
150bbfda8aSnia# output is relatively new.
160bbfda8aSniaif(ASCIIDOCTOR)
170bbfda8aSnia	execute_process(
180bbfda8aSnia		COMMAND ${ASCIIDOCTOR} --version
190bbfda8aSnia		RESULT_VARIABLE _adoctor_result
200bbfda8aSnia		OUTPUT_VARIABLE _adoctor_verout
210bbfda8aSnia		ERROR_QUIET
220bbfda8aSnia	)
230bbfda8aSnia	if(NOT ${_adoctor_result} EQUAL "0")
240bbfda8aSnia		# Err...
250bbfda8aSnia		message(WARNING "Unexpected result trying asciidoctor --version.")
260bbfda8aSnia		set(_adoctor_verout "Asciidoctor 0.0.0 FAKE")
270bbfda8aSnia	endif()
280bbfda8aSnia	unset(_adoctor_result)
290bbfda8aSnia
300bbfda8aSnia	# Break out the version.
310bbfda8aSnia	set(_adoctor_veregex "Asciidoctor ([0-9]+\\.[0-9]+\\.[0-9]+).*")
320bbfda8aSnia	string(REGEX REPLACE ${_adoctor_veregex} "\\1"
330bbfda8aSnia		ASCIIDOCTOR_VERSION ${_adoctor_verout})
340bbfda8aSnia	unset(_adoctor_verout)
350bbfda8aSnia	unset(_adoctor_veregex)
360bbfda8aSnia	message(STATUS "Found asciidoctor (${ASCIIDOCTOR}) version ${ASCIIDOCTOR_VERSION}")
370bbfda8aSnia
380bbfda8aSnia	# 1.5.3 is the first release that can write manpages natively.  This
390bbfda8aSnia	# means 1.5.3 dev versions after a certain point can as well; assume
400bbfda8aSnia	# anybody running a 1.5.3 dev is keeping up well enough that it can
410bbfda8aSnia	# DTRT too.  We assume any version can do HTML.
420bbfda8aSnia	set(ASCIIDOCTOR_CAN_MAN  0)
430bbfda8aSnia	set(ASCIIDOCTOR_CAN_HTML 1)
440bbfda8aSnia	set(ASCIIDOCTOR_CAN_DBXML 1)
450bbfda8aSnia	if(${ASCIIDOCTOR_VERSION} VERSION_GREATER "1.5.2")
460bbfda8aSnia		set(ASCIIDOCTOR_CAN_MAN 1)
470bbfda8aSnia	elseif(${ASCIIDOCTOR_VERSION} VERSION_LESS "0.0.1")
480bbfda8aSnia		set(ASCIIDOCTOR_CAN_HTML 0)
490bbfda8aSnia		set(ASCIIDOCTOR_CAN_DBXML 0)
500bbfda8aSnia	endif()
510bbfda8aSnia
520bbfda8aSnia	# dblatex PDF output works fine with docbook5.  xmlto/docbook XSL
530bbfda8aSnia	# manpage generation doesn't, so it has to override this.
540bbfda8aSnia	set(ASCIIDOCTOR_DB_VER 5)
550bbfda8aSniaendif(ASCIIDOCTOR)
560bbfda8aSnia
570bbfda8aSnia
580bbfda8aSnia# For asciidoc, it doesn't really matter, but look up the version for
590bbfda8aSnia# cosmetics anyway
600bbfda8aSniaif(ASCIIDOC)
610bbfda8aSnia	execute_process(
620bbfda8aSnia		COMMAND ${ASCIIDOC} --version
630bbfda8aSnia		RESULT_VARIABLE _adoc_result
640bbfda8aSnia		OUTPUT_VARIABLE _adoc_verout
650bbfda8aSnia		ERROR_QUIET
660bbfda8aSnia	)
670bbfda8aSnia	if(NOT ${_adoc_result} EQUAL "0")
680bbfda8aSnia		# Err...
690bbfda8aSnia		message(WARNING "Unexpected result trying asciidoc --version.")
700bbfda8aSnia		set(_adoc_verout "asciidoc 0.0.0")
710bbfda8aSnia	endif()
720bbfda8aSnia	unset(_adoc_result)
730bbfda8aSnia
740bbfda8aSnia	# Break out the version.
750bbfda8aSnia	set(_adoc_veregex "asciidoc ([0-9]+\\.[0-9]+\\.[0-9]+).*")
760bbfda8aSnia	string(REGEX REPLACE ${_adoc_veregex} "\\1"
770bbfda8aSnia		ASCIIDOC_VERSION ${_adoc_verout})
780bbfda8aSnia	unset(_adoc_verout)
790bbfda8aSnia	unset(_adoc_veregex)
800bbfda8aSnia	message(STATUS "Found asciidoc (${ASCIIDOC}) version ${ASCIIDOC_VERSION}")
810bbfda8aSnia
820bbfda8aSnia	# Can always do both, unless horked
830bbfda8aSnia	if(${ASCIIDOC_VERSION} VERSION_GREATER "0.0.0")
840bbfda8aSnia		set(ASCIIDOC_CAN_MAN  1)
850bbfda8aSnia		set(ASCIIDOC_CAN_HTML 1)
860bbfda8aSnia		set(ASCIIDOC_CAN_DBXML 1)
870bbfda8aSnia	endif()
880bbfda8aSnia
890bbfda8aSnia	# This is an example of 'horked'...
900bbfda8aSnia	if(NOT A2X)
910bbfda8aSnia		set(ASCIIDOC_CAN_MAN 0)
920bbfda8aSnia	endif()
930bbfda8aSnia
940bbfda8aSnia	# Only docbook version python asciidoc supports
950bbfda8aSnia	set(ASCIIDOC_DB_VER 45)
960bbfda8aSniaendif(ASCIIDOC)
970bbfda8aSnia
980bbfda8aSnia
990bbfda8aSnia# dblatex lets us build PDF's from the DocBook XML.  This is pretty
1000bbfda8aSnia# fringe and not part of normal builds, so try to minimize the impact of
1010bbfda8aSnia# the checks.
1020bbfda8aSniaif(DBLATEX)
1030bbfda8aSnia	# Don't really care about the version, so save the extra checks
1040bbfda8aSnia	if(0)
1050bbfda8aSnia		execute_process(
1060bbfda8aSnia			COMMAND ${DBLATEX} --version
1070bbfda8aSnia			RESULT_VARIABLE _dblatex_result
1080bbfda8aSnia			OUTPUT_VARIABLE _dblatex_verout
1090bbfda8aSnia			ERROR_QUIET
1100bbfda8aSnia		)
1110bbfda8aSnia		if(NOT ${_dblatex_result} EQUAL "0")
1120bbfda8aSnia			# Err...
1130bbfda8aSnia			message(WARNING "Unexpected result trying dblatex --version.")
1140bbfda8aSnia			set(_dblatex_verout "dblatex 0.0.0 FAKE")
1150bbfda8aSnia		endif()
1160bbfda8aSnia		unset(_dblatex_result)
1170bbfda8aSnia
1180bbfda8aSnia		# Break out the version.
1190bbfda8aSnia		set(_dblatex_veregex "dblatex version ([0-9]+\\.[0-9]+\\.[0-9]+).*")
1200bbfda8aSnia		string(REGEX REPLACE ${_dblatex_veregex} "\\1"
1210bbfda8aSnia			DBLATEX_VERSION ${_dblatex_verout})
1220bbfda8aSnia		unset(_dblatex_verout)
1230bbfda8aSnia		unset(_dblatex_veregex)
1240bbfda8aSnia		message(STATUS "Found dblatex (${DBLATEX}) version ${DBLATEX_VERSION}")
1250bbfda8aSnia	else()
1260bbfda8aSnia		message(STATUS "Found dblatex (${DBLATEX})")
1270bbfda8aSnia	endif()
1280bbfda8aSnia
1290bbfda8aSnia	# I guess it works...
1300bbfda8aSnia	set(DBLATEX_CAN_PDF 1)
1310bbfda8aSniaendif(DBLATEX)
1320bbfda8aSnia
1330bbfda8aSnia
1340bbfda8aSnia# xmlto is another frontend for DocBook XML -> stuff.  It can indirect
1350bbfda8aSnia# through dblatex (like we just do manually above) or through fop for PDF
1360bbfda8aSnia# output, but also knows how to invoke xsltproc to generate manpage
1370bbfda8aSnia# output, which gives us another route from adoc -> XML -> manpage.  And
1380bbfda8aSnia# potentially other formats, if we start caring.
1390bbfda8aSniaif(XMLTO)
1400bbfda8aSnia	# Don't really care about the version, so save the extra checks
1410bbfda8aSnia	if(0)
1420bbfda8aSnia		execute_process(
1430bbfda8aSnia			COMMAND ${XMLTO} --version
1440bbfda8aSnia			RESULT_VARIABLE _xmlto_result
1450bbfda8aSnia			OUTPUT_VARIABLE _xmlto_verout
1460bbfda8aSnia			ERROR_QUIET
1470bbfda8aSnia		)
1480bbfda8aSnia		if(NOT ${_xmlto_result} EQUAL "0")
1490bbfda8aSnia			# Err...
1500bbfda8aSnia			message(WARNING "Unexpected result trying xmlto --version.")
1510bbfda8aSnia			set(_xmlto_verout "xmlto 0.0.0 FAKE")
1520bbfda8aSnia		endif()
1530bbfda8aSnia		unset(_xmlto_result)
1540bbfda8aSnia
1550bbfda8aSnia		# Break out the version.
1560bbfda8aSnia		set(_xmlto_veregex "xmlto version ([0-9]+\\.[0-9]+\\.[0-9]+).*")
1570bbfda8aSnia		string(REGEX REPLACE ${_xmlto_veregex} "\\1"
1580bbfda8aSnia			XMLTO_VERSION ${_xmlto_verout})
1590bbfda8aSnia		unset(_xmlto_verout)
1600bbfda8aSnia		unset(_xmlto_veregex)
1610bbfda8aSnia		message(STATUS "Found xmlto (${XMLTO}) version ${XMLTO_VERSION}")
1620bbfda8aSnia	else()
1630bbfda8aSnia		message(STATUS "Found xmlto (${XMLTO})")
1640bbfda8aSnia	endif()
1650bbfda8aSnia
1660bbfda8aSnia	# I guess it can do whatever...
1670bbfda8aSnia	set(XMLTO_CAN_STUFF 1)
1680bbfda8aSniaendif(XMLTO)
1690bbfda8aSnia
1700bbfda8aSnia
1710bbfda8aSnia
1720bbfda8aSnia
1730bbfda8aSnia#
1740bbfda8aSnia# Generator functions for creating targets for the various
1750bbfda8aSnia# transformations.
1760bbfda8aSnia#
1770bbfda8aSnia
1780bbfda8aSnia# Lot of boilerplate in all of them
1790bbfda8aSniamacro(_ad_mk_boilerplate PROG OUT)
1800bbfda8aSnia	# Minimal seatbelt
1810bbfda8aSnia	set(my_usage "${PROG}_mk_${OUT}(<output> <input> [DEPENDS <deps>] [COMMENT <comment>])")
1820bbfda8aSnia	cmake_parse_arguments(
1830bbfda8aSnia		_ARGS
1840bbfda8aSnia		""
1850bbfda8aSnia		"COMMENT"
1860bbfda8aSnia		"DEPENDS"
1870bbfda8aSnia		${ARGN}
1880bbfda8aSnia	)
1890bbfda8aSnia	if(_ARGS_UNPARSED_ARGUMENTS)
1900bbfda8aSnia		message(FATAL_ERROR ${my_usage})
1910bbfda8aSnia	endif()
1920bbfda8aSnia
1930bbfda8aSnia	# Always depend on the input file, maybe on more
1940bbfda8aSnia	set(dependancies ${ADFILE})
1950bbfda8aSnia	if(_ARGS_DEPENDS)
1960bbfda8aSnia		list(APPEND dependancies ${_ARGS_DEPENDS})
1970bbfda8aSnia	endif()
1980bbfda8aSnia
1990bbfda8aSnia	# Come up with some comment or other
2000bbfda8aSnia	if(NOT _ARGS_COMMENT)
2010bbfda8aSnia		get_filename_component(basename ${OUTFILE} NAME)
2020bbfda8aSnia		set(_ARGS_COMMENT "Generating ${basename} with ${PROG}")
2030bbfda8aSnia	endif()
2040bbfda8aSniaendmacro(_ad_mk_boilerplate)
2050bbfda8aSnia
2060bbfda8aSnia
2070bbfda8aSnia# Build a manpage via asciidoctor
2080bbfda8aSniafunction(asciidoctor_mk_manpage OUTFILE ADFILE)
2090bbfda8aSnia	# Guard
2100bbfda8aSnia	if(NOT ASCIIDOCTOR_CAN_MAN)
2110bbfda8aSnia		message(FATAL_ERROR "asciidoctor can't do man")
2120bbfda8aSnia	endif()
2130bbfda8aSnia
2140bbfda8aSnia	_ad_mk_boilerplate(asciidoctor manpage ${ARGN})
2150bbfda8aSnia
2160bbfda8aSnia	# Setup the rule
2170bbfda8aSnia	add_custom_command(OUTPUT ${OUTFILE}
2180bbfda8aSnia		DEPENDS ${dependancies}
2190bbfda8aSnia		COMMAND ${ASCIIDOCTOR} -b manpage -o ${OUTFILE} ${ADFILE}
2200bbfda8aSnia		COMMENT ${_ARGS_COMMENT}
2210bbfda8aSnia	)
2220bbfda8aSniaendfunction(asciidoctor_mk_manpage)
2230bbfda8aSnia
2240bbfda8aSnia
2250bbfda8aSnia# Build a manpage via asciidoc (technically, a2x)
2260bbfda8aSniafunction(a2x_mk_manpage OUTFILE ADFILE)
2270bbfda8aSnia	# Guard
2280bbfda8aSnia	if(NOT A2X OR NOT ASCIIDOC_CAN_MAN)
2290bbfda8aSnia		message(FATAL_ERROR "asciidoc/a2x can't do man")
2300bbfda8aSnia	endif()
2310bbfda8aSnia
2320bbfda8aSnia	_ad_mk_boilerplate(a2x manpage ${ARGN})
2330bbfda8aSnia
2340bbfda8aSnia	# a2x gives us very little control over input/output files, so we
2350bbfda8aSnia	# have to do some vaguely stupid dances.  In theory, -D works for the
2360bbfda8aSnia	# manpage output, but it's doc'd not to and will warn, so don't even
2370bbfda8aSnia	# try.  The result is that it always puts the outfile file next to
2380bbfda8aSnia	# the input.  So we make a temporary dir (with a hopefully unique
2390bbfda8aSnia	# name) and do all our stuff in there.
2400bbfda8aSnia	get_filename_component(basedir ${ADFILE} DIRECTORY)
2410bbfda8aSnia	while(1)
2420bbfda8aSnia		string(RANDOM rndstr)
2430bbfda8aSnia		set(a2x_tmpdir "${basedir}/a2x.${rndstr}")
2440bbfda8aSnia		if(NOT IS_DIRECTORY ${a2x_tmpdir})
2450bbfda8aSnia			break()
2460bbfda8aSnia		endif()
2470bbfda8aSnia	endwhile()
2480bbfda8aSnia	file(MAKE_DIRECTORY ${a2x_tmpdir})
2490bbfda8aSnia
2500bbfda8aSnia	# This had better already be named "someprog.somesection.adoc",
2510bbfda8aSnia	# because a2x is going to magically figure the program and section
2520bbfda8aSnia	# name from the contents and make that output file.
2530bbfda8aSnia	get_filename_component(inbasename ${ADFILE} NAME)
2540bbfda8aSnia	string(REGEX REPLACE "(.*)\\.adoc$" "\\1" outbasename ${inbasename})
2550bbfda8aSnia	if(NOT outbasename)
2560bbfda8aSnia		message(FATAL_ERROR "Can't figure output for ${inbasename}")
2570bbfda8aSnia	endif()
2580bbfda8aSnia
2590bbfda8aSnia	# In/out tmpfile names
2600bbfda8aSnia	set(a2x_intmp  "${a2x_tmpdir}/${inbasename}")
2610bbfda8aSnia	set(a2x_outtmp "${a2x_tmpdir}/${outbasename}")
2620bbfda8aSnia
2630bbfda8aSnia	add_custom_command(OUTPUT ${OUTFILE}
2640bbfda8aSnia		DEPENDS ${dependancies}
2650bbfda8aSnia		COMMAND cp ${ADFILE} ${a2x_intmp}
2660bbfda8aSnia		COMMAND ${A2X} --doctype manpage --format manpage ${a2x_intmp}
2670bbfda8aSnia		COMMAND mv ${a2x_outtmp} ${OUTFILE}
2680bbfda8aSnia		COMMAND rm ${a2x_intmp}
2690bbfda8aSnia		COMMENT ${_ARGS_COMMENT}
2700bbfda8aSnia	)
2710bbfda8aSniaendfunction(a2x_mk_manpage)
2720bbfda8aSnia
2730bbfda8aSnia
2740bbfda8aSnia# Build a manpage via xmlto
2750bbfda8aSniafunction(xmlto_mk_manpage OUTFILE XMLFILE)
2760bbfda8aSnia	# Guard
2770bbfda8aSnia	if(NOT XMLTO)
2780bbfda8aSnia		message(FATAL_ERROR "xmlto can't do man")
2790bbfda8aSnia	endif()
2800bbfda8aSnia
2810bbfda8aSnia	_ad_mk_boilerplate(xmlto manpage ${ARGN})
2820bbfda8aSnia
2830bbfda8aSnia	# As with a2x, this had better already be named
2840bbfda8aSnia	# "someprog.somesection.xml" because we have so little control over
2850bbfda8aSnia	# the output location.
2860bbfda8aSnia	get_filename_component(inbasename ${XMLFILE} NAME)
2870bbfda8aSnia	string(REGEX REPLACE "(.*)\\.xml$" "\\1" outbasename ${inbasename})
2880bbfda8aSnia	if(NOT outbasename)
2890bbfda8aSnia		message(FATAL_ERROR "Can't figure output for ${inbasename}")
2900bbfda8aSnia	endif()
2910bbfda8aSnia
2920bbfda8aSnia	get_filename_component(basedir ${XMLFILE} DIRECTORY)
2930bbfda8aSnia	add_custom_command(OUTPUT ${OUTFILE}
2940bbfda8aSnia		DEPENDS ${XMLFILE} ${dependancies}
2950bbfda8aSnia		COMMAND ${XMLTO}
2960bbfda8aSnia			--skip-validation
2970bbfda8aSnia			-o ${basedir}
2980bbfda8aSnia			# This apparently doesn't work right...
2990bbfda8aSnia			--stringparam 'man.endnotes.list.enabled=0'
3000bbfda8aSnia			man ${XMLFILE}
3010bbfda8aSnia		COMMENT ${_ARGS_COMMENT}
3020bbfda8aSnia	)
3030bbfda8aSnia
3040bbfda8aSnia	# Set various overrides.  Note that this leads to rather worse PDF
3050bbfda8aSnia	# output.  If we ever decide to make xmlto a more likely part of the
3060bbfda8aSnia	# process, we probably need to rework things so we generate a
3070bbfda8aSnia	# different XML for the manpage path vs. the PDF path...
3080bbfda8aSnia	set(OVERRIDE_DTYPE manpage PARENT_SCOPE)
3090bbfda8aSnia
3100bbfda8aSnia	# This does _very_ poorly [currently?] with DocBook 5 output.
3110bbfda8aSnia	if(ASCIIDOCTOR_CAN_DBXML)
3120bbfda8aSnia		set(_addg "; downgrading asciidoctor output to docbook45")
3130bbfda8aSnia		set(ASCIIDOCTOR_DB_VER 45 PARENT_SCOPE)
3140bbfda8aSnia	endif()
3150bbfda8aSnia
3160bbfda8aSnia	message(WARNING "Using xmlto manpage generation${_addg}.  This "
3170bbfda8aSnia		"will compromise the quality of PDF output.")
3180bbfda8aSniaendfunction(xmlto_mk_manpage)
3190bbfda8aSnia
3200bbfda8aSnia
3210bbfda8aSnia
3220bbfda8aSnia# Build HTML output with asciidoctor
3230bbfda8aSniafunction(asciidoctor_mk_html OUTFILE ADFILE)
3240bbfda8aSnia	# Guard
3250bbfda8aSnia	if(NOT ASCIIDOCTOR_CAN_HTML)
3260bbfda8aSnia		message(FATAL_ERROR "asciidoctor can't do html")
3270bbfda8aSnia	endif()
3280bbfda8aSnia
3290bbfda8aSnia	_ad_mk_boilerplate(asciidoctor html ${ARGN})
3300bbfda8aSnia
3310bbfda8aSnia	# Setup the rule
3320bbfda8aSnia	add_custom_command(OUTPUT ${OUTFILE}
3330bbfda8aSnia		DEPENDS ${dependancies}
3340bbfda8aSnia		COMMAND ${ASCIIDOCTOR} -atoc -anumbered -o ${OUTFILE} ${ADFILE}
3350bbfda8aSnia		COMMENT ${_ARGS_COMMENT}
3360bbfda8aSnia	)
3370bbfda8aSniaendfunction(asciidoctor_mk_html)
3380bbfda8aSnia
3390bbfda8aSnia
3400bbfda8aSnia# And the asciidoc HTML
3410bbfda8aSniafunction(asciidoc_mk_html OUTFILE ADFILE)
3420bbfda8aSnia	# Guard
3430bbfda8aSnia	if(NOT ASCIIDOC_CAN_HTML)
3440bbfda8aSnia		message(FATAL_ERROR "asciidoc can't do html")
3450bbfda8aSnia	endif()
3460bbfda8aSnia
3470bbfda8aSnia	_ad_mk_boilerplate(asciidoc html ${ARGN})
3480bbfda8aSnia
3490bbfda8aSnia	# Setup the rule
3500bbfda8aSnia	add_custom_command(OUTPUT ${OUTFILE}
3510bbfda8aSnia		DEPENDS ${dependancies}
3520bbfda8aSnia		COMMAND ${ASCIIDOC} -atoc -anumbered -o ${OUTFILE} ${ADFILE}
3530bbfda8aSnia		COMMENT ${_ARGS_COMMENT}
3540bbfda8aSnia	)
3550bbfda8aSniaendfunction(asciidoc_mk_html)
3560bbfda8aSnia
3570bbfda8aSnia
3580bbfda8aSnia# Building DocBook XML
3590bbfda8aSniafunction(asciidoctor_mk_docbook OUTFILE ADFILE)
3600bbfda8aSnia	# Guard
3610bbfda8aSnia	if(NOT ASCIIDOCTOR_CAN_DBXML)
3620bbfda8aSnia		message(FATAL_ERROR "asciidoctor can't do DocBook")
3630bbfda8aSnia	endif()
3640bbfda8aSnia
3650bbfda8aSnia	_ad_mk_boilerplate(asciidoctor docbook ${ARGN})
3660bbfda8aSnia
3670bbfda8aSnia	set(DTYPE article)
3680bbfda8aSnia	if(OVERRIDE_DTYPE)
3690bbfda8aSnia		set(DTYPE ${OVERRIDE_DTYPE})
3700bbfda8aSnia	endif()
3710bbfda8aSnia
3720bbfda8aSnia	add_custom_command(OUTPUT ${OUTFILE}
3730bbfda8aSnia		DEPENDS ${dependancies}
3740bbfda8aSnia		COMMAND ${ASCIIDOCTOR} -b docbook${ASCIIDOCTOR_DB_VER}
3750bbfda8aSnia			-d ${DTYPE} -o ${OUTFILE} ${ADFILE}
3760bbfda8aSnia		COMMENT "${_ARGS_COMMENT} (docbook${ASCIIDOCTOR_DB_VER},${DTYPE})"
3770bbfda8aSnia	)
3780bbfda8aSniaendfunction(asciidoctor_mk_docbook)
3790bbfda8aSnia
3800bbfda8aSniafunction(asciidoc_mk_docbook OUTFILE ADFILE)
3810bbfda8aSnia	# Guard
3820bbfda8aSnia	if(NOT ASCIIDOC_CAN_DBXML)
3830bbfda8aSnia		message(FATAL_ERROR "asciidoc can't do DocBook")
3840bbfda8aSnia	endif()
3850bbfda8aSnia
3860bbfda8aSnia	_ad_mk_boilerplate(asciidoc docbook ${ARGN})
3870bbfda8aSnia
3880bbfda8aSnia	set(DTYPE article)
3890bbfda8aSnia	if(OVERRIDE_DTYPE)
3900bbfda8aSnia		set(DTYPE ${OVERRIDE_DTYPE})
3910bbfda8aSnia	endif()
3920bbfda8aSnia
3930bbfda8aSnia	add_custom_command(OUTPUT ${OUTFILE}
3940bbfda8aSnia		DEPENDS ${dependancies}
3950bbfda8aSnia		COMMAND ${ASCIIDOC} -b docbook${ASCIIDOC_DB_VER}
3960bbfda8aSnia			-d ${DTYPE} -o ${OUTFILE} ${ADFILE}
3970bbfda8aSnia		COMMENT "${_ARGS_COMMENT} (docbook${ASCIIDOC_DB_VER},${DTYPE})"
3980bbfda8aSnia	)
3990bbfda8aSniaendfunction(asciidoc_mk_docbook)
4000bbfda8aSnia
4010bbfda8aSnia
4020bbfda8aSnia# PDF via dblatex
4030bbfda8aSniafunction(dblatex_mk_pdf OUTFILE XMLFILE)
4040bbfda8aSnia	if(NOT DBLATEX_CAN_PDF)
4050bbfda8aSnia		message(FATAL_ERROR "dblatex can't do PDF")
4060bbfda8aSnia	endif()
4070bbfda8aSnia
4080bbfda8aSnia	_ad_mk_boilerplate(dblatex pdf ${ARGN})
4090bbfda8aSnia
4100bbfda8aSnia	# Passes through to LaTeX geometry.
4110bbfda8aSnia	# Likely choices: letterpaper, a4paper
4120bbfda8aSnia	if(NOT DBLATEX_PAPERSIZE)
4130bbfda8aSnia		set(DBLATEX_PAPERSIZE "a4paper")
4140bbfda8aSnia	endif()
4150bbfda8aSnia
4160bbfda8aSnia	add_custom_command(OUTPUT ${OUTFILE}
4170bbfda8aSnia		DEPENDS ${XMLFILE} ${dependancies}
4180bbfda8aSnia		COMMAND ${DBLATEX}
4190bbfda8aSnia			-tpdf
4200bbfda8aSnia			-Pdoc.collab.show=0
4210bbfda8aSnia			-Platex.output.revhistory=0
4220bbfda8aSnia			-Ppaper.type=${DBLATEX_PAPERSIZE}
4230bbfda8aSnia			-Ppage.margin.top=2cm
4240bbfda8aSnia			-Ppage.margin.bottom=2cm
4250bbfda8aSnia			-o ${OUTFILE} ${XMLFILE}
4260bbfda8aSnia		COMMENT ${_ARGS_COMMENT}
4270bbfda8aSnia	)
4280bbfda8aSniaendfunction(dblatex_mk_pdf)
429