Skip to content

Instantly share code, notes, and snippets.

@denkspuren
Last active April 26, 2023 16:39
Show Gist options
  • Save denkspuren/2d23f11de27e3d4e6ad62d21b2d57650 to your computer and use it in GitHub Desktop.
Save denkspuren/2d23f11de27e3d4e6ad62d21b2d57650 to your computer and use it in GitHub Desktop.
A simple build system as a bash script

README

Frustrated with using make for generating pdf and html files from asciidoc documents (I use asciidoctor a lot), I wrote a simple shell script doing the job.

The problem with make is that it cannot work with files having spaces in their file names. Gradle, bazel, ninja and other build tools seemed like overkill for such a tiny task. And bash runs anywhere.

#!/bin/bash
all() {
build "html"
build "pdf"
}
clean() {
echo "Cleaning up ..."
rm -f *.html
rm -f *.pdf
}
build() {
echo "Building $1 files ..."
for file in *.adoc; do
target_file="$(basename "$file" .adoc).$1"
if ! [[ "$file" -nt "$target_file" ]]; then
continue # skip files, which are not outdated
fi
case $1 in
html)
asciidoctor -o "$target_file" "$file";;
pdf)
asciidoctor -r asciidoctor-pdf -b pdf -o "$target_file" "$file";;
*)
echo "unmatched file type";
exit 1;;
esac
echo "success: $target_file";
done
}
if [[ "$1" == "all" ]]; then
all
elif [[ "$1" == "clean" ]]; then
clean
else
build $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment