commit efc609d0875d9fe21881182351b735d6b4ea2e75 Author: Jörn-Michael Miehe Date: Thu Sep 19 18:11:47 2019 +0200 initial commit diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3c05757 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM ldericher/pandocker:latest + +RUN apt-get update && apt-get -y install \ + inotify-tools \ + lsof \ +&& rm -rf /var/lib/apt/lists/* + +COPY autodoc.sh /usr/local/bin/autodoc +RUN chmod +x /usr/local/bin/autodoc diff --git a/autodoc.sh b/autodoc.sh new file mode 100755 index 0000000..b047274 --- /dev/null +++ b/autodoc.sh @@ -0,0 +1,86 @@ +#!/bin/bash + +# $1:WATCHROOT (default: ".") +g_watchroot="$(readlink -f "${1:-.}")" + +# compile using bare make command +do_make() { # $1:DIR $2:OBJECT + # extract params + local dir="$1" + local object="$2" + + # enter build directory + local olddir="$(pwd)" + cd "${dir}" + + # extract Makefile 'source pattern' + local srcpat="$(grep -E "^#@SRCPAT" Makefile | sed -r "s/^#@SRCPAT\s+//")" + + if [ -z "${srcpat}" ]; then + echo "Empty source pattern! Make sure Makefile has '#@SRCPAT' annotation!" + elif [[ "${object}" =~ ${srcpat} ]]; then + make -j # source pattern matched + else + echo "'${object}' does not match source pattern '${srcpat}'!" + fi + + cd "${olddir}" +} + +# compile a directory +do_compile() { # $1:DIR $2:OBJECT + # extract params + local dir="$1" + local object="$2" + + # compile using Makefile + if [ -e "${dir}/Makefile" ]; then + echo "Using '${dir}/Makefile'." + do_make "${dir}" "${object}" + + # compile parent dir if not in g_watchroot +elif [ "${dir}" != "${g_watchroot}" ]; then + do_compile "$(dirname "${dir}")" "${object}" + + # stop otherwise + else + echo "No compile description found!" + fi +} + +# process an inotify event +do_handle() { # $1:FLAGS $2:OBJECT + # extract params + local flags="$1" + shift 1 + local dir="$(dirname "$*")" + local object="$(basename "$*")" + + # object refers to directory + if [[ "${flags}" =~ "ISDIR" ]]; then + local dir="${dir}/${object}" + local object="." + fi + + # use toolchain + echo -n "Flags '${flags}' for '${dir}/${object}' ... " + do_compile "${dir}" "${object}" +} + +# +# MAIN +# + +echo "watching '${g_watchroot}' ..." +# setup inotify: +# -mrq monitor, recursive, quiet +# -e events +# --format %e eventlist csv, %w workdir, %f filename +inotifywait -mrq \ + -e create -e delete -e moved_to -e close_write \ + --format '%e %w%f' \ + "${g_watchroot}" | \ +\ +while read FILE; do + do_handle ${FILE} +done