#!/bin/bash
#
# A library file for detecting dmd versions and setting up variables.  Now that
# Tango supports DMD 2, we must setup variables properly
#

# Various common build and install functionality

dmdversion() {
    echo ">> Checking compiler version DMD"

    DMDVERSION=`dmd | head -1 | cut -c 26-`
    DMDVERSIONMAJ="${DMDVERSION:0:1}" #`echo $DMDVERSION | cut -d . -f 1`
    DMDVERSIONMIN="${DMDVERSION:2}" #`echo $DMDVERSIOM | cut -c 3-`
    echo ">> Compiler version is $DMDVERSIONMAJ.$DMDVERSIONMIN"
    while [ "${DMDVERSIONMIN:0:1}" = "0" ]
    do
        DMDVERSIONMIN="${DMDVERSIONMIN:1}"
    done
}

dmdsettings() {
    dmdversion

    if [ ! "$DMDVERSIONMAJ" -gt "1" ]
    then
	if [ "$DMDVERSIONMIN" -lt "40" ]
	then
            POSIXFLAG="-version=Posix"		
            echo ">> Enabling -version=Posix for DMD older than 1.040."
	fi
    fi
}

dmdbugs() {
    dmdversion

    if [ ! "$DMDVERSIONMAJ" -gt "1" ]
    then
        if [ ! "$DMDVERSIONMIN" -gt "21" ]
        then
            INLINE=""
            echo ">> Removing -inline due to bugzilla 668"
        fi

        if [ "$DMDVERSIONMIN" -lt "31" ]
        then
            echo ">> DMD 1.031 introduced several fixes for usage of implicit"
            echo " >> template functions in particular, so you should consider an"
            echo " >> upgrade if you experience problems."
        fi

        if [ "$DMDVERSIONMIN" = "32" ]
        then
            echo ">> DMD 1.032 is not supported by Tango. You are most likely going"
            echo " >> to experience problems."
        fi

        if [ "$DMDVERSIONMIN" -gt "47" -a "$DMDVERSIONMIN" -lt "51" ]
        then
            echo ">> This version of DMD is broken and is not supported by Tango."
            echo " >> Aborting."
            exit 1
        fi

        if [ "$DMDVERSIONMIN" -gt "51" ]
        then
            echo ">> This version has not been tested with Tango prior to this release,"
            echo " >> so if you experience any problems, try reverting to DMD 1.041"
            echo " >> or earlier."
        fi
    else
        echo ">> D 2.0 not supported in this code base"
        exit 1
    fi
}
