#!/bin/sh

EXTERNAL="/afs/nd.edu/user37/ccl/software/external"

# Our external packages are installed in $EXTERNAL/packagename-version/$SYS
# Where $SYS is the output of the AFS `sys` command, usually something
# like amd64_linux26 or i686_darwin_100.  In some cases, the AFS sys
# does not sufficiently discriminate, so we add a subtype like
# redhat5 or redhat6.

function detect_packages()
{
    unset GLOBUS_LOCATION
    export GLOBUS_LOCATION
    
    echo "platform is `sys`"

    if [ -f /etc/redhat-release ]
    then
        major=`cat /etc/redhat-release | awk '{print $7'} | awk -F. '{print $1}'`
	subtype=redhat$major
	echo "subtype is $subtype"
    fi

    echo "$0: Detecting packages ..."

    PACKAGES_CONFIG=""
    for package in fuse irods mysql python globus openmpi swig xrootd cvmfs
    do
	packagepath=$EXTERNAL/$package/`sys`_$subtype

	if [ ! -d $packagepath ]
	then
		packagepath=$EXTERNAL/$package/`sys`
	fi

	if [ -d $packagepath ]
        then
            echo "$package -> $packagepath"
            if [ $package = openmpi ]
            then
                PACKAGES_CONFIG="$PACKAGES_CONFIG --with-mpi-path $packagepath"
            else
                PACKAGES_CONFIG="$PACKAGES_CONFIG --with-$package-path $packagepath"
            fi
	else
            echo "$package -> NOTFOUND"
        fi
    done

    echo ""
}

detect_packages

./configure --strict --tcp-low-port 9000 $PACKAGES_CONFIG $@

# vim: set sts=4 sw=4 ts=8 expandtab ft=sh:
