Expand PMF_FN_* macros.
[netbsd-mini2440.git] / external / bsd / atf / dist / doc / build-xml.sh
blob4b50a1720baf78739b3712529a83b51131c3a302
1 #! /bin/sh
3 # Automated Testing Framework (atf)
5 # Copyright (c) 2009 The NetBSD Foundation, Inc.
6 # All rights reserved.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
18 # CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19 # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 # IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26 # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
28 # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 set -e
33 # -------------------------------------------------------------------------
34 # Variables expected in the environment.
35 # -------------------------------------------------------------------------
37 : ${DOC_BUILD:=UNSET}
38 : ${LINKS:=UNSET}
39 : ${TIDY:=UNSET}
40 : ${XML_CATALOG_FILE:=UNSET}
41 : ${XMLLINT:=UNSET}
42 : ${XSLTPROC:=UNSET}
44 # -------------------------------------------------------------------------
45 # Global variables.
46 # -------------------------------------------------------------------------
48 Prog_Name=${0##*/}
50 # -------------------------------------------------------------------------
51 # Auxiliary functions.
52 # -------------------------------------------------------------------------
55 # err message
57 err() {
58 for line in "${@}"; do
59 echo "${Prog_Name}: ${line}" 1>&2
60 done
61 exit 1
65 # validate_xml xml_file
67 validate_xml() {
68 echo "XML_CATALOG_FILES=${XML_CATALOG_FILE} ${XMLLINT}" \
69 "--nonet --valid --path doc ${1}"
70 XML_CATALOG_FILES=${XML_CATALOG_FILE} \
71 ${XMLLINT} --nonet --valid --path doc ${1} >/dev/null
72 [ ${?} -eq 0 ] || err "XML validation of ${1} failed"
76 # run_xsltproc input stylesheet output [args]
78 run_xsltproc() {
79 input=${1}; shift
80 stylesheet=${1}; shift
81 output=${1}; shift
82 echo "${XSLTPROC} --path doc ${*} ${stylesheet} ${input} >${output}"
83 if ${XSLTPROC} --path doc "${@}" ${stylesheet} ${input} >${output}; then
85 else
86 err "XSLT processing of ${input} with ${stylesheet} failed"
91 # tidy_xml input output
93 tidy_xml() {
94 echo "${TIDY} -quiet -xml ${1} >${2}"
95 if ${TIDY} -quiet -xml ${1} >${2}; then
97 else
98 err "Tidying of ${1} failed"
103 # xml_to_html xml_input xslt_file html_output
105 xml_to_html() {
106 xml_input=${1}
107 xslt_file=${2}
108 html_output=${3}
110 tmp1=$(mktemp -t build-xml.XXXXXX)
111 tmp2=$(mktemp -t build-xml.XXXXXX)
113 mkdir -p ${html_output%/*}
114 validate_xml ${xml_input}
115 run_xsltproc ${xml_input} ${xslt_file} ${tmp1}
116 tidy_xml ${tmp1} ${tmp2}
118 echo "rm -f ${tmp1}"
119 rm -f ${tmp1}
120 echo "mv -f ${tmp2} ${html_output}"
121 mv -f ${tmp2} ${html_output}
125 # format_txt input output
127 format_txt() {
128 echo "${LINKS} -dump ${1} >${2}"
129 if ${LINKS} -dump ${1} >${2}; then
131 else
132 err "Formatting of ${1} failed"
137 # xml_to_txt xml_input xslt_file txt_output
139 xml_to_txt() {
140 xml_input=${1}
141 xslt_file=${2}
142 txt_output=${3}
144 tmp1=$(mktemp -t build-xml.XXXXXX)
145 tmp2=$(mktemp -t build-xml.XXXXXX)
147 mkdir -p ${txt_output%/*}
148 validate_xml ${xml_input}
149 run_xsltproc ${xml_input} ${xslt_file} ${tmp1}
150 format_txt ${tmp1} ${tmp2}
152 echo "rm -f ${tmp1}"
153 rm -f ${tmp1}
154 echo "mv -f ${tmp2} ${txt_output}"
155 mv -f ${tmp2} ${txt_output}
159 # xml_to_anything xml_input xslt_file output
161 xml_to_anything() {
162 xml_input=${1}
163 xslt_file=${2}
164 format=$(echo ${3} | cut -d : -f 1)
165 output=$(echo ${3} | cut -d : -f 2)
167 case ${format} in
168 txt|html)
169 xml_to_${format} ${xml_input} ${xslt_file} ${output}
172 err "Unknown format ${format}"
174 esac
177 # -------------------------------------------------------------------------
178 # Main program.
179 # -------------------------------------------------------------------------
181 main() {
182 [ ${#} -eq 3 ] || usage
184 xml_input=${1}
185 xslt_file=${2}
186 output=${3}
188 if [ ${DOC_BUILD} = yes ]; then
189 xml_to_anything ${1} ${2} ${3}
190 true
191 else
192 err "Cannot regenerate ${output}" \
193 "Reconfigure the package using --enable-doc-build"
197 usage() {
198 cat 1>&2 <<EOF
199 Usage: ${Prog_Name} <xml-input> <xslt-file> <format>:<output>
201 exit 1
204 main "${@}"
206 # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4