# run buildapi.sh from the IA2 directory

# make sure we have Cygwin
if [ ! -d /cygdrive/c ]; then
    echo 'Expected to find Cygwin'
    exit 1
fi

# make sure we have the proper directory structure
if [ ! -d api ]; then
    echo 'Expected to find ./api'
    exit 1
fi

# make sure we have Doxygen
if [ ! -x /cygdrive/c/program\ files/doxygen/bin/doxygen.exe ]; then
    echo 'Expected to find c:/program files/doxygen/bin/doxygen.exe'
    exit 1
fi

# make sure we have a Doxygen configuration file
if [ ! -f doxygen.conf ]; then
    echo 'Expected to find doxygen.conf'
    exit 1
fi

# clean up test dir
if [ -f IDL-Test/dlldata.c ]; then
    rm IDL-Test/*.c
    rm IDL-Test/*.h
fi

cp IDL-Test/StdAfxSave/*.* IDL-Test

# remove previous autogenerated Doxygen files
if [ -d docs ]; then
    rm -rf docs
fi

# generate IDL documentation with Doxygen
cd api
/cygdrive/c/program\ files/doxygen/bin/doxygen ../doxygen.conf
cd ..

./concatidl.sh

# remove previous autogenerated zip file
if [ -f ia2-api-`date +%Y%m%d`.zip ]; then
    rm ia2-api-`date +%Y%m%d`.zip
fi

# package merged IDL file and documentation
zip -9r ia2-api-`date +%Y%m%d`.zip ia2_api_all.idl api/*.idl docs

# list packaged file for visual confirmation
echo ''
ls -l ia2-api-`date +%Y%m%d`.zip
