2021-03-23 22:23:49 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# Script to build the documentation
|
|
|
|
# :PROPERTIES:
|
|
|
|
# :header-args:bash: :tangle build_doc.sh :noweb yes :shebang #!/bin/bash :comments org
|
|
|
|
# :END:
|
2021-03-10 12:58:38 +01:00
|
|
|
|
2021-03-23 22:23:49 +01:00
|
|
|
# First define readonly global variables.
|
2021-04-21 13:17:33 +02:00
|
|
|
|
2021-03-10 12:58:38 +01:00
|
|
|
|
2021-04-30 01:26:19 +02:00
|
|
|
readonly DOCS=${QMCKL_ROOT}/share/doc/qmckl/
|
2021-03-23 22:23:49 +01:00
|
|
|
readonly SRC=${QMCKL_ROOT}/src/
|
2021-04-30 01:26:19 +02:00
|
|
|
readonly HTMLIZE=${DOCS}/html/htmlize.el
|
2021-04-21 13:17:33 +02:00
|
|
|
readonly CONFIG_DOC=${QMCKL_ROOT}/tools/config_doc.el
|
2021-03-23 22:23:49 +01:00
|
|
|
readonly CONFIG_TANGLE=${QMCKL_ROOT}/tools/config_tangle.el
|
2021-03-10 12:58:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-23 22:23:49 +01:00
|
|
|
# Check that all the defined global variables correspond to files.
|
|
|
|
|
|
|
|
|
|
|
|
function check_preconditions()
|
|
|
|
{
|
|
|
|
if [[ -z ${QMCKL_ROOT} ]]
|
|
|
|
then
|
|
|
|
print "QMCKL_ROOT is not defined"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-04-30 01:26:19 +02:00
|
|
|
for dir in ${DOCS}/html ${DOCS}/text ${SRC}
|
2021-03-23 22:23:49 +01:00
|
|
|
do
|
|
|
|
if [[ ! -d ${dir} ]]
|
|
|
|
then
|
|
|
|
print "${dir} not found"
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
done
|
2021-04-21 13:17:33 +02:00
|
|
|
|
2021-03-23 22:23:49 +01:00
|
|
|
for file in ${CONFIG_DOC} ${CONFIG_TANGLE}
|
|
|
|
do
|
|
|
|
if [[ ! -f ${file} ]]
|
|
|
|
then
|
|
|
|
print "${file} not found"
|
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ~install_htmlize~ installs the htmlize Emacs plugin if the
|
|
|
|
# =htmlize.el= file is not present.
|
|
|
|
|
|
|
|
|
|
|
|
function install_htmlize()
|
|
|
|
{
|
|
|
|
local url="https://github.com/hniksic/emacs-htmlize"
|
|
|
|
local repo="emacs-htmlize"
|
2021-04-21 13:17:33 +02:00
|
|
|
|
2021-03-23 22:23:49 +01:00
|
|
|
[[ -f ${HTMLIZE} ]] || (
|
2021-04-30 01:26:19 +02:00
|
|
|
cd ${DOCS}/html
|
2021-03-23 22:23:49 +01:00
|
|
|
git clone ${url} \
|
|
|
|
&& cp ${repo}/htmlize.el ${HTMLIZE} \
|
|
|
|
&& rm -rf ${repo}
|
|
|
|
cd -
|
|
|
|
)
|
|
|
|
|
|
|
|
# Assert htmlize is installed
|
|
|
|
[[ -f ${HTMLIZE} ]] \
|
|
|
|
|| exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Extract documentation from an org-mode file.
|
2021-03-10 12:58:38 +01:00
|
|
|
|
|
|
|
|
|
|
|
function extract_doc()
|
|
|
|
{
|
2021-03-23 22:23:49 +01:00
|
|
|
local org=$1
|
2021-04-21 13:17:33 +02:00
|
|
|
local local_html=${SRC}/${org%.org}.html
|
2021-04-21 13:26:11 +02:00
|
|
|
local local_text=${SRC}/${org%.org}.txt
|
2021-04-30 01:26:19 +02:00
|
|
|
local html=${DOCS}/html/${org%.org}.html
|
|
|
|
local text=${DOCS}/text/${org%.org}.txt
|
2021-03-23 22:23:49 +01:00
|
|
|
|
|
|
|
if [[ -f ${html} && ${org} -ot ${html} ]]
|
|
|
|
then
|
|
|
|
return
|
2021-03-10 12:58:38 +01:00
|
|
|
fi
|
2021-03-23 22:23:49 +01:00
|
|
|
emacs --batch \
|
|
|
|
--load ${HTMLIZE} \
|
|
|
|
--load ${CONFIG_DOC} \
|
|
|
|
${org} \
|
|
|
|
--load ${CONFIG_TANGLE} \
|
2021-04-21 13:26:11 +02:00
|
|
|
-f org-html-export-to-html \
|
|
|
|
-f org-ascii-export-to-ascii
|
2021-04-30 01:26:19 +02:00
|
|
|
mv ${local_html} ${DOCS}/html
|
|
|
|
mv ${local_text} ${DOCS}/text
|
2021-03-23 22:23:49 +01:00
|
|
|
|
2021-03-10 12:58:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-03-23 22:23:49 +01:00
|
|
|
# The main function of the script.
|
2021-03-10 12:58:38 +01:00
|
|
|
|
2021-03-23 22:23:49 +01:00
|
|
|
|
|
|
|
function main() {
|
2021-04-21 13:17:33 +02:00
|
|
|
|
|
|
|
check_preconditions || exit 1
|
|
|
|
|
2021-03-23 22:23:49 +01:00
|
|
|
# Install htmlize if needed
|
2021-04-21 13:17:33 +02:00
|
|
|
install_htmlize || exit 2
|
2021-03-23 22:23:49 +01:00
|
|
|
|
|
|
|
# Create documentation
|
|
|
|
cd ${SRC} \
|
|
|
|
|| exit 3
|
|
|
|
|
|
|
|
for i in *.org
|
|
|
|
do
|
|
|
|
echo
|
|
|
|
echo "======= ${i} ======="
|
|
|
|
extract_doc ${i}
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ $? -eq 0 ]]
|
|
|
|
then
|
2021-04-30 01:26:19 +02:00
|
|
|
cd ${DOCS}/html
|
2021-03-23 22:23:49 +01:00
|
|
|
rm -f index.html
|
|
|
|
ln README.html index.html
|
|
|
|
exit 0
|
|
|
|
else
|
|
|
|
exit 3
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
main
|