1
0
mirror of https://github.com/TREX-CoE/qmckl.git synced 2025-01-03 10:06:09 +01:00

Nicer bash script

This commit is contained in:
Anthony Scemama 2021-03-23 22:23:49 +01:00
parent 27b9fdab22
commit 271c4cfe84
3 changed files with 248 additions and 44 deletions

View File

@ -411,4 +411,132 @@ EOF
#+end_src
* Script to build the documentation
* Script to build the documentation
:PROPERTIES:
:header-args:bash: :tangle build_doc.sh :noweb yes :shebang #!/bin/bash :comments org
:END:
First define readonly global variables.
#+begin_src bash :noweb yes
readonly DOCS=${QMCKL_ROOT}/docs/
readonly SRC=${QMCKL_ROOT}/src/
readonly HTMLIZE=${DOCS}/htmlize.el
readonly CONFIG_DOC=${QMCKL_ROOT}/tools/config_doc.el
readonly CONFIG_TANGLE=${QMCKL_ROOT}/tools/config_tangle.el
#+end_src
Check that all the defined global variables correspond to files.
#+begin_src bash :noweb yes
function check_preconditions()
{
if [[ -z ${QMCKL_ROOT} ]]
then
print "QMCKL_ROOT is not defined"
exit 1
fi
for dir in ${DOCS} ${SRC}
do
if [[ ! -d ${dir} ]]
then
print "${dir} not found"
exit 2
fi
done
for file in ${CONFIG_DOC} ${CONFIG_TANGLE}
do
if [[ ! -f ${file} ]]
then
print "${file} not found"
exit 3
fi
done
}
#+end_src
~install_htmlize~ installs the htmlize Emacs plugin if the
=htmlize.el= file is not present.
#+begin_src bash :noweb yes
function install_htmlize()
{
local url="https://github.com/hniksic/emacs-htmlize"
local repo="emacs-htmlize"
[[ -f ${HTMLIZE} ]] || (
cd ${DOCS}
git clone ${url} \
&& cp ${repo}/htmlize.el ${HTMLIZE} \
&& rm -rf ${repo}
cd -
)
# Assert htmlize is installed
[[ -f ${HTMLIZE} ]] \
|| exit 1
}
#+end_src
Extract documentation from an org-mode file.
#+begin_src bash :noweb yes
function extract_doc()
{
local org=$1
local local_html=${SRC}/${org%.org}.html
local html=${DOCS}/${org%.org}.html
if [[ -f ${html} && ${org} -ot ${html} ]]
then
return
fi
emacs --batch \
--load ${HTMLIZE} \
--load ${CONFIG_DOC} \
${org} \
--load ${CONFIG_TANGLE} \
-f org-html-export-to-html
mv ${local_html} ${DOCS}
}
#+end_src
The main function of the script.
#+begin_src bash :noweb yes
function main() {
[[ check_preconditions ]] \
|| exit 1
# Install htmlize if needed
[[ install_htmlize ]] \
|| exit 2
# Create documentation
cd ${SRC} \
|| exit 3
for i in *.org
do
echo
echo "======= ${i} ======="
extract_doc ${i}
done
if [[ $? -eq 0 ]]
then
cd ${DOCS}
rm -f index.html
ln README.html index.html
exit 0
else
exit 3
fi
}
main
#+end_src

View File

@ -1,57 +1,132 @@
#!/bin/bash
# Script to build the documentation
# :PROPERTIES:
# :header-args:bash: :tangle build_doc.sh :noweb yes :shebang #!/bin/bash :comments org
# :END:
if [[ -z $QMCKL_ROOT ]]
then
print "QMCKL_ROOT is not defined"
exit 1
fi
# First define readonly global variables.
# Install htmlize if needed
[[ -f ${QMCKL_ROOT}/docs/htmlize.el ]] || (
cd ${QMCKL_ROOT}/docs/
git clone https://github.com/hniksic/emacs-htmlize
cp emacs-htmlize/htmlize.el .
rm -rf emacs-htmlize
cd -
)
[[ -f ${QMCKL_ROOT}/docs/htmlize.el ]] || exit 1
readonly DOCS=${QMCKL_ROOT}/docs/
readonly SRC=${QMCKL_ROOT}/src/
readonly HTMLIZE=${DOCS}/htmlize.el
readonly CONFIG_DOC=${QMCKL_ROOT}/tools/config_doc.el
readonly CONFIG_TANGLE=${QMCKL_ROOT}/tools/config_tangle.el
# Create documentation
cd ${QMCKL_ROOT}/src
# 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
for dir in ${DOCS} ${SRC}
do
if [[ ! -d ${dir} ]]
then
print "${dir} not found"
exit 2
fi
done
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"
[[ -f ${HTMLIZE} ]] || (
cd ${DOCS}
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.
function extract_doc()
{
HTML=${1%.org}.html
if [[ -f ${QMCKL_ROOT}/docs/$HTML && $1 -ot ${QMCKL_ROOT}/docs/$HTML ]]
then return
local org=$1
local local_html=${SRC}/${org%.org}.html
local html=${DOCS}/${org%.org}.html
if [[ -f ${html} && ${org} -ot ${html} ]]
then
return
fi
emacs --batch \
--load ${QMCKL_ROOT}/docs/htmlize.el \
--load ${QMCKL_ROOT}/tools/config_doc.el \
$i \
--load ${QMCKL_ROOT}/tools/config_tangle.el \
-f org-html-export-to-html || break
mv $HTML ${QMCKL_ROOT}/docs
emacs --batch \
--load ${HTMLIZE} \
--load ${CONFIG_DOC} \
${org} \
--load ${CONFIG_TANGLE} \
-f org-html-export-to-html
mv ${local_html} ${DOCS}
}
for i in *.org
do
echo
echo "======= $i ======="
extract_doc $i
done
if [[ $? -eq 0 ]]
then
cd ${QMCKL_ROOT}/docs
rm -f index.html
ln README.html index.html
exit 0
else
exit 2
fi
# The main function of the script.
function main() {
[[ check_preconditions ]] \
|| exit 1
# Install htmlize if needed
[[ install_htmlize ]] \
|| exit 2
# Create documentation
cd ${SRC} \
|| exit 3
for i in *.org
do
echo
echo "======= ${i} ======="
extract_doc ${i}
done
if [[ $? -eq 0 ]]
then
cd ${DOCS}
rm -f index.html
ln README.html index.html
exit 0
else
exit 3
fi
}
main

View File

@ -42,4 +42,5 @@
(setq h_private (concat name "_private.h"))
(setq c_test (concat pwd "test_" name ".c"))
(setq f_test (concat pwd "test_" name "_f.f90"))
(org-babel-lob-ingest "../tools/lib.org")