#!/bin/bash

if [ -z $2 ]
then
echo "Usage: $0 <file to convert> <resulted file>"
exit 0
fi

cat $1 | sed -e s/\#include.*// > $1.h

cat glcpp2m3d.cpp | sed -e s/INCLUDE_FILE/\#include\ \"$1\.h\"/ > convert.cpp

g++ -I../src/FileFormats/m3dme -I../src/utils ../src/FileFormats/.libs/libfileformats.so -o convert convert.cpp

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../src/FileFormats/.libs/ ./convert $2
if [ "$?" != "0" ] 
then 
    exit 1
fi
rm -f ./convert
rm -f convert.cpp
rm -f $1.h