2021-03-09 01:16:23 +01:00
|
|
|
#!/bin/bash
|
2021-05-10 23:56:26 +02:00
|
|
|
#
|
|
|
|
# This script tangles all the org-mode files in the src directory of QMCkl.
|
|
|
|
# It needs to be run from in the src directory. It uses the config_tangle.el
|
|
|
|
# Emacs configuration file, which contains information required to compute the
|
|
|
|
# current file names using for example ~(eval c)~ to get the name of the
|
|
|
|
# produced C file. The org-mode file is not tangled if the last modification
|
|
|
|
# date of the org file is older than one of the tangled files.
|
|
|
|
# The =missing= script is used to check if emacs is present on the system.
|
2021-03-09 01:16:23 +01:00
|
|
|
|
2021-05-11 11:45:49 +02:00
|
|
|
if [[ -z ${srcdir} ]] ; then
|
2021-10-28 17:52:03 +02:00
|
|
|
echo "Error: srcdir environment variable is not defined"
|
2021-05-11 11:45:49 +02:00
|
|
|
exit 1
|
2021-05-10 23:56:26 +02:00
|
|
|
fi
|
2021-03-09 01:16:23 +01:00
|
|
|
|
2021-10-28 17:52:03 +02:00
|
|
|
if [[ -z ${top_builddir} ]] ; then
|
2021-11-17 17:06:30 +01:00
|
|
|
echo "Error: top_builddir environment variable is not defined"
|
2021-10-28 17:52:03 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2023-06-14 11:44:00 +02:00
|
|
|
EMACS="${VARIABLE:=emacs}"
|
|
|
|
|
2023-03-31 15:10:30 +02:00
|
|
|
EXTENSIONS="_f.F90 _fh_func.F90 _fh_type.F90 .c _func.h _type.h _private_type.h _private_func.h"
|
|
|
|
|
2021-03-09 01:16:23 +01:00
|
|
|
function tangle()
|
|
|
|
{
|
2023-03-31 15:10:30 +02:00
|
|
|
local backup_dir=$(mktemp -d)
|
2021-03-19 13:47:50 +01:00
|
|
|
local org_file=$1
|
|
|
|
local c_file=${org_file%.org}.c
|
2022-02-11 16:07:25 +01:00
|
|
|
local f_file=${org_file%.org}.F90
|
2021-03-19 13:47:50 +01:00
|
|
|
|
|
|
|
if [[ ${org_file} -ot ${c_file} ]] ; then
|
|
|
|
return
|
|
|
|
elif [[ ${org_file} -ot ${f_file} ]] ; then
|
|
|
|
return
|
2021-03-09 01:16:23 +01:00
|
|
|
fi
|
2023-03-31 15:10:30 +02:00
|
|
|
|
|
|
|
local prefix=${top_builddir}/src/$(basename ${org_file})
|
|
|
|
prefix=${prefix%.org}
|
|
|
|
for ext in $EXTENSIONS ; do
|
|
|
|
if [[ -f ${prefix}${ext} ]] ; then
|
|
|
|
mv ${prefix}${ext} ${backup_dir}
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2021-10-28 17:52:03 +02:00
|
|
|
${srcdir}/tools/missing \
|
2023-06-14 11:44:00 +02:00
|
|
|
$EMACS --no-init-file --no-site-lisp --quick --batch ${org_file} \
|
2021-11-17 17:06:30 +01:00
|
|
|
--load=${srcdir}/tools/config_tangle.el \
|
2021-05-10 23:56:26 +02:00
|
|
|
-f org-babel-tangle
|
2023-03-31 15:10:30 +02:00
|
|
|
|
|
|
|
for ext in $EXTENSIONS ; do
|
|
|
|
local new_file=${prefix}${ext}
|
|
|
|
local old_file=${backup_dir}/$(basename ${new_file})
|
|
|
|
diff $new_file $old_file &> /dev/null
|
|
|
|
if [[ $? -eq 0 ]] ; then
|
|
|
|
echo "${old_file} unchanged"
|
|
|
|
mv $old_file $new_file
|
|
|
|
else
|
|
|
|
echo "${old_file} changed"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
rm -rf ${backup_dir}
|
2021-03-09 01:16:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for i in $@
|
|
|
|
do
|
2021-05-11 12:15:08 +02:00
|
|
|
tangled=${i%.org}.tangled
|
2021-11-17 17:06:30 +01:00
|
|
|
tangled=${top_builddir}/src/$(basename $tangled)
|
2021-05-11 12:15:08 +02:00
|
|
|
NOW=$(date +"%m%d%H%M.%S")
|
2021-10-14 18:57:40 +02:00
|
|
|
tangle ${i} &> $tangled
|
|
|
|
rc=$?
|
2021-10-14 21:39:08 +02:00
|
|
|
# Make log file older than the tangled files
|
|
|
|
touch -t ${NOW} $tangled
|
|
|
|
# Fail if tangling failed
|
2021-10-14 18:57:40 +02:00
|
|
|
if [[ $rc -ne 0 ]] ; then
|
|
|
|
cat $tangled
|
2022-12-08 18:34:09 +01:00
|
|
|
rm $tangled
|
2021-11-17 17:06:30 +01:00
|
|
|
exit $rc
|
2021-10-14 18:57:40 +02:00
|
|
|
fi
|
2021-03-09 01:16:23 +01:00
|
|
|
done
|