#!/bin/sh
set -eu

if [ ! "${CPP_HOME:-}" ]
then
    echo You must set CPP_HOME to the directory where the materials are >&2
    exit 1
fi
if [ ! -f ${CPP_HOME:-}/Includes/std_lib_facilities.h ]
then
    echo ${CPP_HOME:-}/Includes/std_lib_facilities.h does not exist >&2
    exit 1
fi
if [ ! -d ${CPP_HOME:-}/Includes/FL -o \
        ! -f ${CPP_HOME:-}/Libs/libbookgui.a -o \
        ! -f ${CPP_HOME:-}/Libs/libfltk.a ]
then
    echo The graphics libraries have not been installed properly >&2
    exit 1
fi

# Regrettably, enabling warnings for GUI code is a lost cause
g++ -g -O3 $@ -I${CPP_HOME:-}/Includes -L${CPP_HOME:-}/Libs \
-lbookgui -lfltk -lfltk_forms -lfltk_images -lXt -lX11 -ljpeg
./a.out
