-which gmqcc >> /dev/null || (echo "error gmqcc not installed" && exit 1)
-pushd ~/.gmqcc/testsuite/projects >> /dev/null
-find . -maxdepth 1 -mindepth 1 -type d -printf "%f\n" | while read -r line
+gmqcc_bin="gmqcc"
+env -i type gmqcc 1>/dev/null 2>&1 || {
+ if [ -f ../gmqcc ]; then
+ echo "previous build of gmqcc exists, using it"
+ gmqcc_bin="$(pwd)/../gmqcc"
+ elif [ -f ./gmqcc ]; then
+ echo "previous build of gmqcc exists, using it"
+ gmqcc_bin="$(pwd)/gmqcc"
+ else
+ echo "gmqcc not installed and previous build doesn't exist"
+ echo "please run make, or make install"
+ exit 1
+ fi
+}
+
+end_dir="$PWD"
+cd ~/.gmqcc/testsuite/projects
+start="$PWD"
+find . -maxdepth 1 -mindepth 1 -type d | while read -r line