#!/bin/bash

rm -f model.c
rm -f $2

echo "Creating model.c file from $1 ..."
mod $1

shopt -s extglob

if test $2; 
 then target=$2;
 else target=mcsim.${1%.mod?('el')};
fi;

if test -f model.c; then \

	echo; \
	echo "Compiling and linking standalone model ..."; \
	@CC@ -O3 -I@prefix@/include @CPPFLAGS@ @CFLAGS@ @LDFLAGS@ model.c @prefix@/share/mcsim/sim/*.c -o $target @LIBS@ -Wall; \

fi;

if test -f $target; then \

	echo "Cleaning up ..."; \
	rm -f model.c; \

	echo "Created standalone executable $target"; \
	echo; \

fi;
