#!/bin/sh
#
# Erlang compiler shell script
# Compiles a module (-shared)
#
# To execute need to invoke execution stub
# We also need a program to make an executable (ie. include stub)
#

#   if [ `echo $1 | cut -c1`='-' ] ; then
#       switch $1
#       case '-static'):
#       prog=$2
#       flags= 
#       case *):
#   else
#       prog=$1
#       flags= 
#   fi

ERL=$HOME/gerl
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ERL/erlib/:$ERL/lib/:./
export LD_LIBRARY_PATH
#echo $LD_LIBRARY_PATH
OS=`uname`
if [ ! -f $1 ] ; then
    echo Unable to find $1
    exit 1
fi

outname=`echo $1 | cut -f1 -d'.'`

if [ $OS = 'Linux' ] ; then
	gcc -g -rdynamic -I$ERL/lib/ -shared -Wl,-soname,$outname.so.t -o $outname.so $1 -Llib/

else
	gcc -fPIC -g -c -I$ERL/lib/ $1
#	gcc -shared -o $outname.so $outname.o -Llib/liberl.a
	gcc -g -I$ERL/lib/ -shared -o $outname.so $1 -Llib/ 
    rm $1.$$.o

fi

#ar crs $1.so $1.$$.o
# 'ar' the .o now?

