#!/usr/bin/env bash
# LEGAL: COPYRIGHT (C) 2010 JIM E. BROOKS WWW.PALOMINO3D.ORG

# Need to know root dir of project to find cmake-produced lib/ directory.
ROOT_DIR=$1
if [ "$ROOT_DIR" = "" ]; then
    echo "Usage: if-debug-build.sh rootDirOfProject"
    echo "Returns 0 (success) if project was compiled for DEBUG."
    echo "Returns 1 if compiled but not for DEBUG."
    echo "Returns 2 if error."
    exit 2
fi

if [ ! -d $ROOT_DIR ]; then
    echo "[if-debug-build] ROOT_DIR='${ROOT_DIR}' doesn't exist as a directory"
    exit 2
fi

if [ ! -d $ROOT_DIR/lib ]; then
    # Wasn't even compiled.
    exit 1
fi

if ( nm $ROOT_DIR/lib/libbase.a 2>/dev/null | grep -q BASE_DEBUG_BUILD  ); then
    # Yes, it is a DEBUG compile.
    # Found the special C++ variable BASE_DEBUG_BUILD.
    exit 0
fi

# Nope.
exit 1
