#! /bin/bash

DOXYGEN_PATH="${DOXYGEN_PATH:-/user/did/not/set/DOXYGEN_PATH}"
# EYEWALL_DAKOTA is doxygen-1.8.13
EYEWALL_DAKOTA_PATH=/usr/local/doxygen/bin/doxygen
JET_PATH=/contrib/doxygen/1.8.10/bin/doxygen
LUNA_PATH=/gpfs/hps/emc/hwrf/noscrub/soft/doxygen-1.8.10/bin/doxygen
TIDE_PATH=/hwrf/noscrub/soft/doxygen-1.8.10/bin/doxygen

rm -f doxyloc

found=''
for exe in $DOXYGEN_PATH $EYEWALL_DAKOTA_PATH $JET_PATH $TIDE_PATH $LUNA_PATH ; do
    if [[ -x "$exe" && -s "$exe" ]] ; then
        if ( $exe --version ) ; then
            found="$exe"
            echo "Found doxygen at $found"
            echo "You can now run ./compile"
            break
        fi
    fi
done

if [[ -n "$found" ]] ; then
    echo "doxygen='$found'" > doxygenloc
else
    echo "Cannot find doxygen 1.8.9.1 or later.  Please compile and install it." 1>&2
    echo "It is already pre-installed on the NOAA Jet and Zeus clusters," 1>&2
    echo "and this script knows where to find it there." 1>&2
    echo 1>&2
    echo "If you have compiled doxygen, set this environment variable to" 1>&2
    echo "the path to the bin/doxygen program inside the installation" 1>&2
    echo "directory:" 1>&2
    echo "  export DOXYGEN_PATH=/path/to/doxygen-1.8.9.1/bin/doxygen" 1>&2
    exit 1
fi

### Below was code to append version info to the  doxygenloc file for HWRF
# For now just manually edit the file ... until we port the logic below
# to METPlus and git. Example of doxygenloc file, but no # in front of lines.
#doxygen='/usr/bin/doxygen'
#version="trunk@5501"

metplus_ver='METplusV3.0'
echo "version='$metplus_ver'" >> doxygenloc

# ----
#svn info ../..|perl -ne '
#   /^Revision: (\d+)/ and $r=$1;
#   m(^URL: https://[^/]*/(\S+)) and $b=$1;
#   END {
#      if($r && $b) {
#         $version="$b\@$r";
#         $version=~s/[;,]/./g; # remove sed metacharacters
#         print "version=\"$version\"\n";
#      } else {
#         print "version=\"9.0.0\"\n";
#      }
#   }' >> doxygenloc


