#!/bin/sh

missing() {
    echo "'$1' is missing - please install it and try again"
    exit 1
}

executables() {
    for i in $* ; do
        j=$(echo $i | cut -d "/" -f1)
        k=$(echo $i | cut -d "/" -f2)
        which $j 1>/dev/null 2>/dev/null || which $k 1>/dev/null 2>/dev/null || missing $i
    done
}

python_modules() {
    for i in $* ; do
        python -c "import $i" 1>/dev/null 2>/dev/null || missing "python module '$i'"
    done
}

executables autoreconf libtool autopoint make

if test -d docsrc; then
    # we need to check these if the docsrc directory is present
    executables magick/convert
    python_modules pygments
fi

echo "remaking missing files in build environment"

# the docsrc directory exists in git source only
if test -d docsrc; then
    cd docsrc
    make && make doc
    cd ..
fi

autoreconf -ifs
