#!/bin/sh

# cccl 
# Wrapper around MS's cl.exe and link.exe to make them act more like
# Unix cc and ld
#
# Copyright (C) 2000-2003 Geoffrey Wossum (gwossum@acm.org)
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your optsion) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

usage()
{
    cat <<EOF
Usage: cccl [OPTIONS]

cccl is a wrapper around Microsoft's cl.exe and link.exe.  It translates
parameters that Unix cc's and ld's understand to parameters that cl and link
understand.
EOF
    exit $1
}

prog=cl

### Run through every optsion and convert it to the proper MS one
while test $# -gt 0; do

    case "$1" in
    --version)
	cat <<EOF
cccl 0.03

Copyright 2000-2003 Geoffrey Wossum
This is free software; see the source for copying conditions.  There is NO
waranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
EOF
	exit 1;
	;;

    -o)
	# specifying output file, is it an object or an executable
	shift
	case "$1" in
			
		*.exe)
			opts="$opts /Fe$1";
		;;


		*.mex*)
			opts="$opts /Fe$1"
		;;

		*.o | *.obj)
			opts="$opts /Fo$1"
		;;

		*)
			opts="$opts /Fo$1"
		;;
    esac
	;;
	-fPIC)
	#do nothing
	;;
	-g)
	#do nothing
	;;
	-pthread)
	#do nothing
	;;
	-fno-omit-frame-pointer)
	#do nothing
	;;
	-L*)
		library=`echo $1 | sed 's/-L//g'`
		string="/link -/IBPATH:\"$library\""
		opts="$opts $string"
	;;
	*)
		#do nothing
		opts="$opts $1"
	;;

	
    esac
    shift
done
			
#Some default options:
opts="$opts /nologo"

#echo "$prog $opts"
exec $prog $opts
exit 0

    
