#!/bin/sh
##############################################################################
# charmc: Compiler for Converse/Charm/Charm++ programs
#
# Converted to Bourne Shell by Orion Sky Lawlor, 10/21/1999
#
# Initialize the main controlling variables, setup error handler
# ALL variables used by this script should be initialized here.
#
##############################################################################

#Prepare aliases for the external commands we use--
# Note that adding /bin/ to everything breaks Cygwin32.
RM="rm -f"
CP="cp"
MV="mv"
LN="ln"
WC="wc"
SED="sed"

MACHTYPE=""
SEQUENTIAL=""
LANGUAGE=""
BALANCE=""
MEMORY=""
TRACEMODE=""
VERBOSE=""
DEBUG_SCRIPT=""
SAVE=""
PURIFY=""
OVERRIDE_CC=""
OVERRIDE_CXX=""
OVERRIDE_LD=""
OVERRIDE_LDXX=""
OPTS_CPP=""
OPTS_LDRO="" 
OPTS_CC=""
OPTS_CXX="" 
OPTS_LD=""  
OPTS_LDXX=""  
OBJECT=""
POST_LANGUAGE=""
POST_LIBRARIES=""    
PRE_LIBRARIES=""    
COPIES=""        
FILES=""       
OBJECTFILES=""  
DELETE=""    
MAINOBJ=""   
GENCPM=""     
DEBUG_MODE=""
OPTIMIZE_MODE=""
USE_RELIABLE_CC=""
USE_FASTEST_CC=""
IS_WINDOWS=""

####################################################################
#
#  Utility routines used below
#
###################################################################

# PrintUsage: prints a helpful command-line usage message and quits
# Args: any additional messages
printUsage() {
    echo "Usage: charmc [ flags ] <files>"
    echo
    echo "  flags:"
    echo "        -o <target> -g -O"
    echo "        -D<define> -I<include path> -L<lib path> -l<library> -s"
    echo "        -machine <mach> -seq -langage <lang> -balance"
    echo "        -tracemode <mode> -verbose -save -purify -cp"
    echo "        -use-reliable-cc -use-fastest-cc -gen-cpm <new gen>"
    echo "        -cc <new cc> -c++ <new CC>  -ld <new ld> -ld++ <new LD>"
    echo "        -cpp-option <opt> -ldro-option <opt> -cc-option <opt>"
    echo "        -c++-option <opt> -ld-option <opt> -ld++-option <opt>"
    echo "        -pg <opt>"
    echo
    echo "  Charmc compiles C, C++, f77, f90, Converse, Converse++, Charm, "
    echo "and Charm++ programs.  The flags generally match those of cc or f77."
    echo "Version 5.0, Parallel Programming Lab, UIUC, 1999"
    echo $*
    exit 1
}

# End blows away the temporary files (unless SAVE is true) and exits
# Args: <exit code>
End() {
    if [ -z "$SAVE" ]
	then
        for FILE in `echo $FILES`
        do
			BASE=`stripExtention $FILE`
			TMP=`basename $FILE`".TMP"
            $RM $TMP.P.C $TMP.cpp $TMP.space $TMP.xlat $TMP.o
            $RM $TMP.c $TMP.c.0.h $TMP.c.1.h $TMP.c.2.h
            $RM $TMP.i $TMP.$CMK_CPP_SUFFIX
        done
        $RM core $DELETE
    fi
    exit $1
}

# This procedure prints an error message and exits.
# ("1>&2" redirects the echo output to stderr).
# Args: written to stderr
Abort() {
	echo "Fatal Error by charmc in directory "`pwd` 1>&2
	echo "   $*" 1>&2
	echo "charmc exiting..." 1>&2
	End 1
}

# Instead of an ECHO_CMD variable, I define a procedure Do,
# which (possibly) echos, runs, and tests the errors of the given command.
# Args: executed as given
DoNoErrCheck() {
	[ -n "$VERBOSE" ] && echo "charmc: Executing $*" 1>&2
	$*
}
Do() {
	DoNoErrCheck $*
	Do_res=$?
# The UNIX result code better be zero, or we die
	[ $Do_res -eq 0 ] || Abort "Command $* returned error code $Do_res"
}

# This procedure removes the extention (the ".c" in "./main.c") from
# its first argument, and prints the result. Unlike the builtin command
# basename, it keeps the directory path.
# Args: <name to strip>
stripExtention() {
	se_base=`echo $1 | awk -F/ '{print $NF}'`
	se_strip=`echo $se_base | awk -F. '{ORS="";print $1;for (i=2;i<NF;i++) print "."$i}'`
	se_ret=`echo $1 | awk -F/ '{ORS="";for (i=1;i<NF;i++) print $i"/"}'`"$se_strip"
	echo $se_ret
}

# GetExtention returns the extention on the given file name
# or "" if none.  (e.g. "./bob/snack.c" returns ".c")
# Args: <name to find extention of>
getExtention() {
	se_base=`echo $1 | awk -F/ '{print $NF}'`
        se_ret=`echo $se_base | awk -F. '{if (NF<=1) print ""; else print "."$NF}'`
	echo $se_ret
}

Debug() {
    if [ -n "$DEBUG_SCRIPT" ]
    then
	echo 
	echo "------- Charmc Debugging info: $* -------"
#	echo "CHARMBIN=$CHARMBIN"
#	echo "CHARMINC=$CHARMINC"
#	echo "CHARMLIB=$CHARMLIB"
#	echo "FILES=$FILES"
#	echo "DELETE=$DELETE"
#	echo "OBJECT=$OBJECT"
#	echo "LANGUAGE=$LANGUAGE"
#	echo "Working directory="`pwd`
    fi
}

# TEMP_BASE is appended with this script's process ID (PID),
# so multiple charmcs can run in parallel without overwriting
# each other's temporary files.
TEMP_BASE="/tmp/charmc_tmp.$$"

##############################################################################
#
# Parse the arguments
#
# Don't do any analysis in here, just the parsing.
#
##############################################################################

[ $# -eq 0 ] && printUsage "Error: No arguments given."

while [ ! $# -eq 0 ]
do
	arg="$1"
	shift

	case "$arg" in
	"-machine")
		MACHTYPE="$1"
		shift
		;;

	"-seq")
		SEQUENTIAL=true
		;;

	"-language")
		LANGUAGE="$1"
		POST_LANGUAGE=1
		shift
		;;

	"-balance")
		BALANCE="$1"
		shift
		;;

	"-queue")
		echo "Warning: -queue currently being ignored."
		shift
		;;

	"-memory")
		echo "Warning: -memory currently being ignored."
		shift
		;;

	"-tracemode")
		TRACEMODE="$1"
		shift
		;;

	"-verbose")
		echo "Verbose mode set"
		VERBOSE=true
		;;

	"-debug-script")
	        echo "Will give excessive charmc debugging output..."
		DEBUG_SCRIPT=true
		;;

	"-save")
		SAVE=true
		;;

	"-purify")
		PURIFY=true
		;;

	"-use-reliable-cc")
		USE_RELIABLE_CC=1
		;;

	"-use-fastest-cc")
		USE_FASTEST_CC=1
		;;

	"-cc")
		OVERRIDE_CC="$1"
		shift
		;;

	"-c++")
		OVERRIDE_CXX="$1"
		shift
		;;

	"-ld")
		OVERRIDE_LD="$1"
		shift
		;;

	"-ld++")
		OVERRIDE_LDXX="$1"
		shift
		;;

	"-cpp-option")
		OPTS_CPP="$OPTS_CPP $1"
		shift
		;;

	"-ldro-option")
		OPTS_LDRO="$OPTS_LDRO $1"
		shift
		;;

	"-cc-option")
		OPTS_CC="$OPTS_CC $1"
		shift
		;;

	"-c++-option")
		OPTS_CXX="$OPTS_CXX $1"
		shift
		;;

	"-ld-option")
		OPTS_LD="$OPTS_LD $1"
		shift
		;;

	"-ld++-option")
		OPTS_LDXX="$OPTS_LDXX $1"
		shift
		;;

	"-rpath")
		OPTS_LDXX="$OPTS_LDXX -rpath $1"
		shift
		;;

	"-c")
# This is ignored.
		;;

	"-o")
		OBJECT=$1
		shift
		;;

	"-cp")
		COPIES="$1 $COPIES"
		shift
		;;

	"-gen-cpm")
		GENCPM="$GENCPM $1"
		shift
		;;

	-D*)
		OPTS_CPP="$OPTS_CPP $arg"
		OPTS_CC="$OPTS_CC  $arg"
		OPTS_CXX="$OPTS_CXX $arg"
		;;

	-I*)
		OPTS_CPP="$OPTS_CPP $arg"
		OPTS_CC="$OPTS_CC  $arg"
		OPTS_CXX="$OPTS_CXX $arg"
		;;

	-LANG*)
		echo "passing unrecognized option $arg to all compilers and linkers"
		OPTS_CPP="$OPTS_CPP  $arg"
		OPTS_CC="$OPTS_CC   $arg"
		OPTS_CXX="$OPTS_CXX  $arg"
		;;
	-L*)
		OPTS_LDRO="$OPTS_LDRO $arg"
		OPTS_LD="$OPTS_LD   $arg"
		OPTS_LDXX="$OPTS_LDXX $arg"
		;;

	"-g")
		DEBUG_MODE=true
		;;

	"-O")
		OPTIMIZE_MODE=true
		;;

	"-NO")
		OPTIMIZE_MODE=false
		;;

	"-pg")
		OPTS_CC="$OPTS_CC $arg"
		OPTS_CXX="$OPTS_CXX $arg"
		OPTS_LD="$OPTS_LD $arg"
		OPTS_LDXX="$OPTS_LDXX $arg"
		;;

	-O*)
		OPTS_CC="$OPTS_CC $arg"
		OPTS_CXX="$OPTS_CXX $arg"
		;;

	-l*)
		if [ -n "$POST_LANGUAGE" ]
		then
			POST_LIBRARIES="$POST_LIBRARIES $arg"
		else
			PRE_LIBRARIES="$PRE_LIBRARIES $arg"
		fi
		;;

	-s)
		OPTS_LD="$OPTS_LD   $arg"
		OPTS_LDXX="$OPTS_LDXX $arg"
		;;

        -h|--help)
	        printUsage
		;;
	-*|+*)
		echo "passing unrecognized option $arg to all compilers and linkers"
		OPTS_CPP="$OPTS_CPP  $arg"
		OPTS_CC="$OPTS_CC   $arg"
		OPTS_CXX="$OPTS_CXX  $arg"
		OPTS_LD="$OPTS_LD   $arg"
		OPTS_LDXX="$OPTS_LDXX $arg"
		OPTS_LDRO="$OPTS_LDRO $arg"
		;;
	*.*)
		[ -n "$VERBOSE" ] && echo "Adding file $arg..."
		FILES="$FILES $arg"
		;;
# Default
	*)
		printUsage  "Error: Unrecognized argument $arg"
		;;
	esac
done

##############################################################################
#
# The following section identifies CHARMBIN, the charm binary-directory.
#
##############################################################################

ORIGDIR=`pwd`

# Try to find CHARMBIN by looking in directory where charmc is

if [ -z "$CHARMBIN" ]
then
	SCRIPT=$0
	CHARMBIN=`dirname $SCRIPT`
	cd $CHARMBIN
	CHARMBIN=`pwd`
# NOTE: this script no longer tries to follow soft links
# to find the "original" charmc-- if this is bad, 
# translate these lines to Bourne shell from C shell:
# -------------------- Begin C Shell ------------------------->
#    if ($SCRIPT:h != $SCRIPT:t) then
#        cd $SCRIPT:h
#        set SCRIPT=$SCRIPT:t
#    else
#        foreach dir ($path)
#            if (-x $dir/$SCRIPT && ! -d $dir/$SCRIPT) then
#                cd $dir
#                break
#            endif
#        end
#    endif
#    while (x`find $SCRIPT -type l -print` == x$SCRIPT)
#        set SCRIPT=`ls -al ./$SCRIPT:t | sed -e "s@.*-> @@"`
#        if ($SCRIPT:h != $SCRIPT:t) then
#            cd $SCRIPT:h
#            set SCRIPT=$SCRIPT:t
#        endif
#    end
#    set CHARMBIN=`pwd`
# <------------------ End C Shell -----------------------------
fi

FIRST_THREE=`uname -s | awk '{print substr($1,1,3)}' `
if [ "$FIRST_THREE" = "CYG" ]
then
	IS_WINDOWS="true"
fi

if [ -n "$MACHTYPE" ]
then
    if [ -d $CHARMBIN/../../$MACHTYPE/bin ]
    then
		cd $CHARMBIN/../../$MACHTYPE/bin
		CHARMBIN=`pwd`
    else
        Abort "there is no installed charm for $MACHTYPE in $CHARMBIN"
    fi
fi

if [ -z "$CHARMLIB" ]
then
	cd $CHARMBIN/../lib
	CHARMLIB=`pwd`
fi
if [ -z "$CHARMINC" ]
then
	cd $CHARMBIN/../include
	CHARMINC=`pwd`
fi

cd $ORIGDIR

##############################################################################
#
# Load machine-specific configuration data, then handle overrides to it.
#
##############################################################################

if [ ! -r $CHARMINC/conv-mach.sh ]
then
	Abort "Can't find conv-mach.sh in $CHARMINC directory."
fi

Debug "About to read machine config script"
. $CHARMINC/conv-mach.sh

Debug "Read config script, setting vars..."

if [ -n "$USE_RELIABLE_CC" ]
then
	CMK_CC="$CMK_CC_RELIABLE"
fi

if [ -n "$USE_FASTEST_CC" ]
then
    CMK_CC="$CMK_CC_FASTEST"
fi

if [ -n "$SEQUENTIAL" ]
then
    CMK_CC="$CMK_SEQ_CC"
    CMK_LD="$CMK_SEQ_LD"
    CMK_CXX="$CMK_SEQ_CXX" 
    CMK_LDXX="$CMK_SEQ_LDXX" 
fi

if [ -n "$OVERRIDE_CC" ]
then
    CMK_CC="$OVERRIDE_CC $CMK_CC "
fi
Debug "set 2"
if [ -n "$OVERRIDE_CXX" ]
then
    CMK_CXX="$OVERRIDE_CXX $CMK_CXX "
fi

if [ -n "$OVERRIDE_LD" ]
then
    CMK_LD="$OVERRIDE_LD $CMK_LD"
fi

if [ -n "$PURIFY" ]
then
    CMK_LD="purify $CMK_LD"
    CMK_LDXX="purify $CMK_LDXX"
fi

if [ -n "$OVERRIDE_LDXX" ]
then
    CMK_LDXX="$OVERRIDE_LDXX $CMK_LDXX"
fi
Debug "set 3"
if [ -n "$DEBUG_MODE" ]
then
    OPTS_CC="$CMK_C_DEBUG $OPTS_CC"
    OPTS_CXX="$CMK_CXX_DEBUG $OPTS_CXX"
    OPTS_LD="$CMK_C_DEBUG $OPTS_LD"
    OPTS_LDXX="$CMK_CXX_DEBUG $OPTS_LDXX"
fi
Debug "set 4"
if [ -n "$OPTIMIZE_MODE" ]
then
    OPTS_CC="$CMK_C_OPTIMIZE $OPTS_CC"
    OPTS_CXX="$CMK_CXX_OPTIMIZE $OPTS_CXX"
    OPTS_LD="$CMK_C_OPTIMIZE $OPTS_LD"
    OPTS_LDXX="$CMK_CXX_OPTIMIZE $OPTS_LDXX"
fi


# There's really no analog for this in the Bourne shell: 
#  -------- C Shell ------> onintr failure
# Luckily, it's irrelevant as long as nobody sends us a ^Z.

##############################################################################
#
# Check for valid choice of LANGUAGE
#
##############################################################################
Debug "Checking language..."

if [ -z "$LANGUAGE" ]
then
    LANGUAGE="charm++"
    [ -n "$SEQUENTIAL" ] && LANGUAGE=c
fi

case "$LANGUAGE" in
"c"|"C"|"c++"|"C++")
	[ -z "$SEQUENTIAL" ] && Abort "Language $LANGUAGE is for sequential programs"
	;;
"charm"|"charm++"|"converse"|"converse++"|"idl"|"ampi"|"ampif"|"f90charm")
	[ -z "$SEQUENTIAL" ] || Abort "Language $LANGUAGE is for parallel programs"
	;;
*)
	Abort "Unrecognized choice of language $LANGUAGE"
	;;
esac

########################################################################
#
# We've parsed and verified the command-line parameters.
# Now we prepare routines to clean up and exit.
# None of these routines ever returns-- they all just exit.
#
########################################################################


Copyobj() {
	for COPY in `echo $COPIES`
	do
		if [ "a$COPY" != "a$OBJECT" ] 
		then
			[ -d $COPY ] && COPY="$COPY/$OBJECT"
			if [ -n "$IS_WINDOWS" ] ; then
				if [ -r "$OBJECT.exe" ] ; then
# Object is (probably) an executable-- append
				echo "Appending .exe to object file name"
				OBJECT="$OBJECT.exe"
				COPY="$COPY.exe"
				fi
			fi
			DoNoErrCheck $RM $COPY 
			Do $CP $OBJECT $COPY
		fi
	done
	Success
}

Success() {
	End 0
}


##############################################################################
#
# Preprocess the GEN-CPM files
#
##############################################################################

Debug "Preprocessing GEN-CPM files"

for FILE in `echo $GENCPM`
do
# This used to be "$FILE:r", which strips the extention
	BASE=`stripExtention $FILE`
	TMP=`basename $FILE`".TMP"
	DELETE="$DELETE $TMP.c $TMP.i"
	DoNoErrCheck $RM $BASE.cpm.h $TMP.c
	Do touch $BASE.cpm.h
	Do $LN -s $FILE $TMP.c
	Do $CMK_CPP_C $OPTS_CPP -I$CHARMINC $TMP.c > $TMP.i
	Do $CHARMBIN/conv-cpm $TMP.i $BASE.cpm.h
done

##############################################################################
#
# Compile all specified files
#
# All temporary files named *.TMP.* for easy cleanup.
#
##############################################################################

Debug "About to compile..."

for FILE in `echo $FILES`
do
	BASE=`stripExtention $FILE`
	TMP=`basename $FILE`".TMP"
	FILE_EXT=`getExtention $FILE`
	if [ "$FILE_EXT" != ".o" ]
	then
		[ $VERBOSE ] && echo "Compiling $FILE"
		DoNoErrCheck $RM $BASE.o $BASE.f.o
	fi
	NU_OBJ=""
	case "$FILE" in
	*.ci)
		if [ "$LANGUAGE" = "f90charm" ]
		then
		    Do $CHARMBIN/charmxi -f90 $CMK_XIOPTS $BASE.ci
		else
		    Do $CHARMBIN/charmxi $CMK_XIOPTS $BASE.ci
		fi
		;;
	*.idl)
		Do $CHARMBIN/charmidl $BASE.idl
		;;
	*.sdag)
		Do $CHARMBIN/sdagx $BASE.sdag
		;;
	*.c|*.s)
		Do $CMK_CC $OPTS_CC -I$CHARMINC -c $FILE -o $BASE.o
		NU_OBJ=$BASE.o
		;;
	*.C|*.cc|*.cxx|*.cpp|*.c++)
		Do $CMK_CXX $OPTS_CXX -I$CHARMINC -c $FILE -o $BASE.o
		NU_OBJ=$BASE.o
		;;
	*.f|*.F)
		Do $CMK_CF77 -I$CHARMINC -c $FILE -o $BASE.o
		NU_OBJ=$BASE.o
		;;
	*.f90)
		Do $CMK_CF90 -I$CHARMINC -c $BASE.f90 -o $BASE.o
		;;
	*.F90)
		Do $CMK_CF90 -I$CHARMINC -c $BASE.F90 -o $BASE.o
		;;
	*.fc|*.FC)
		Abort "I'm not yet smart enough to compile $FILE"
		;;
	*.o|*.a)
		OBJECTFILES="$OBJECTFILES $FILE"
		;;
	*)
		Abort "file with unrecognized extension $FILE"
	esac
# Handle new object files
	if [ -n "$NU_OBJ" -a -n "$OBJECT" ] 
	then
		if [ "$OBJECT" != "$BASE.o" ]
		then
			DELETE="$DELETE $NU_OBJ"
		fi
		OBJECTFILES="$OBJECTFILES $NU_OBJ"
	fi
done

##############################################################################
#
#                        POSSIBLY, SKIP LINK-STEP
#
# 1. No $OBJECT may be specified at all --- its just a compilation.
# 2. If $OBJECT is a ".a" file, a library is created from $OBJECTFILES.
# 3. If $OBJECT is a ".o" file, then an "LDRO" is created from $OBJECTFILES.
# 4. Language may be sequential.  Do a quick and easy linkage.
#
#               in any of these cases, the full link step is skipped.
#
##############################################################################

if [ -z "$OBJECT" ] 
then
# We have no target object-- just end
	Success
fi

Debug "About to link..."

case "$OBJECT" in
*.o)
	nFiles=`echo $FILES | wc -w`
	nObj=`echo $OBJECTFILES | wc -w`
	if [ $nFiles -eq 1 -a $nObj -eq 1 ] 
	then
		if [ $OBJECT != $OBJECTFILES ]
		then
			DoNoErrCheck $RM $OBJECT
			Do $MV $OBJECTFILES $OBJECT
		fi
	else
		DoNoErrCheck $RM $OBJECT
		Do $CMK_LDRO $OBJECT $OPTS_LDRO $OBJECTFILES
	fi
	Copyobj
	;;
*.a)
	DoNoErrCheck $RM $OBJECT
	Do $CMK_AR $OBJECT $OBJECTFILES
	Do $CMK_RANLIB $OBJECT
	Copyobj
	;;
esac
# If the above case returns, we're not creating a .o or .a file--
# check if we're linking a sequential object

case "$LANGUAGE" in
"c"|"C"|"f90"|"f77")
	Do $CMK_SEQ_LD $OPTS_LD -o $OBJECT $OBJECTFILES -L$CHARMLIB $PRE_LIBRARIES $CMK_SEQ_LIBS $POST_LIBRARIES
	Copyobj
	;;
"c++"|"C++")
	Do $CMK_SEQ_LDXX $OPTS_LD -o $OBJECT $OBJECTFILES -L$CHARMLIB $PRE_LIBRARIES $CMK_SEQ_LIBS $POST_LIBRARIES
	Copyobj
	;;
esac

##############################################################################
#
# Some quick consistency checks prior to full link-step
#
# Check for valid choice of TRACEMODE
# Check for valid choice of BALANCE
# Check for compatibility among BALANCE and TRACEMODE
#
##############################################################################

Debug "About to check TRACEMODE=$TRACEMODE and BALANCE=$BALANCE..."

# Check for valid choice of TRACEMODE

[ -r $CHARMLIB/libtrace-none.a ] || Abort "trace libraries not installed."

[ -z "$TRACEMODE" ] && TRACEMODE="none"

[ ! -r $CHARMLIB/libtrace-$TRACEMODE.a ] && Abort "charmc : No such tracemode $TRACEMODE"


# Check for valid choice of BALANCE

[ -z "$BALANCE" ] && BALANCE=rand

if [ "$TRACEMODE" = replay ]
then
	[ "$BALANCE" != replay ] && echo "Ignoring -balance $BALANCE, incompatible with -tracemode replay"
    BALANCE=replay
fi

BAL_EXT=`getExtention $BALANCE`
if [ -z "$BAL_EXT" ]
then
# Balance has no extention-- is a library reference
    BAL_OBJ="$CHARMLIB/libldb-$BALANCE.o"
else
# Balance has some extention-- must be a .o or .a file
    BAL_OBJ="$BALANCE"
fi

Debug "Finished with BAL_OBJ=$BAL_OBJ, TRACEMODE=$TRACEMODE..."

if [ ! -r "$BAL_OBJ" ]
then
	if [ "$BALANCE" = "$BAL_OBJ" ]
	then
		Abort "Could not find load balancer object $BAL_OBJ"
	else
		(cd $CHARMLIB ; ls -al libldb-*)
		Abort "Unknown load balancer $BALANCE / $BAL_OBJ"
	fi
fi

###############################################################################
#
#                               Finally, LINK
#
###############################################################################

Debug "About to perform final link..."

case "$LANGUAGE" in
"ampi")
        PRE_LIBRARIES="$PRE_LIBRARIES -lampi"
	;;
"f90charm")
        PRE_LIBRARIES="$PRE_LIBRARIES lib/libmain.a"
        POST_LIBRARIES="$POST_LIBRARIES -lfsu -lsunmath"
	;;
esac

LANG_LIBS="-L$CHARMLIB -I$CHARMINC $BAL_OBJ $OBJECTFILES $PRE_LIBRARIES -lck $POST_LIBRARIES"
CORE_LIBS="-lconv-core -ltrace-$TRACEMODE"

case "$LANGUAGE" in
"charm"|"charm++")
	Do $CMK_LDXX $OPTS_LDXX -o $OBJECT \
		$LANG_LIBS -lconv-cplus-y $CORE_LIBS -lm $CMK_LIBS
	;;
"f90charm")
	Do $CMK_LDXX $OPTS_LDXX -o $OBJECT \
		$LANG_LIBS -lconv-cplus-y $CORE_LIBS -lm $CMK_LIBS
	;;
"idl")
	Do $CMK_LDXX $OPTS_LDXX -o $OBJECT \
		$LANG_LIBS -lconv-cplus-y $CORE_LIBS -lidl -lm $CMK_LIBS
	;;
"ampi")
        echo language: $LANG_LIBS
	echo objects: $OBJECT
	Do $CMK_LDXX $OPTS_LDXX -o $OBJECT \
		$LANG_LIBS -lconv-cplus-y $CORE_LIBS -lm $CMK_LIBS
	;;
"ampif")
	Do $CMK_LDXX $OPTS_LDXX -o $OBJECT \
		$LANG_LIBS -lconv-cplus-y $CORE_LIBS -lampif -lm $CMK_LIBS
	;;
"converse")
	Do $CMK_LD $OPTS_LD -o $OBJECT \
		$LANG_LIBS -lconv-cplus-n $CORE_LIBS -lm $CMK_LIBS
	;;
"converse++")
	Do $CMK_LDXX $OPTS_LDXX -o $OBJECT \
		$LANG_LIBS -lconv-cplus-y $CORE_LIBS -lm $CMK_LIBS
	;;
esac

########################################################################
#
# Copy conv-host to user directory if it is present in installation.
#
########################################################################

if [ -x $CHARMBIN/conv-host ]
then
	DoNoErrCheck $RM conv-host
	Do $CP $CHARMBIN/conv-host conv-host
fi

Copyobj















