#!/bin/bash
#
# $Id: build-non-gnu-makefiles,v 1.1 2008/11/22 14:00:57 cepek Exp $

CXX=g++

if test "$1" != "gnu" -a "$1" != "win32-borland" -a "$1" != "win32-msvc"; 
then
cat <<EOF

usage: 

cd working-directory
$0 gnu | win32-borland | win32-msvc


The script (with the helper program gnu_gama_dep.cpp) is run from a
working directory with GNU gama source codes.  Resulting makefiles are
written to the 'lib' subdirectory. Before using makefile you need to
rename file lib/config.h-"platform" to lib/config.h.

EOF
exit;
fi

if pwd | grep /scripts$; then cd ..; fi

DEP=scripts/gnu_gama_dep

if ! test -f $DEP;
then
        echo $CXX -o $DEP $DEP.cpp        
        $CXX -o $DEP $DEP.cpp
fi

echo
echo "Building makefiles"
echo

VER=$(awk '/AC_INIT/{print $2}'  configure.ac | sed s/\\[//g | sed s/\\],//)
echo "#define VERSION \""$VER\"  > lib/config.h-$1

find lib -name "*.cpp" | sed s/lib\\/// | \
$DEP lib        "$1" > lib/Makefile-lib-$1
$DEP expat      "$1" > lib/Makefile-expat-$1
$DEP gama-local "$1" > lib/Makefile-gama-local-$1
$DEP gama-g3    "$1" > lib/Makefile-gama-g3-$1

MAKE=make
if test "$1" == "win32-msvc";
then
        MAKE=nmake
fi

echo all: > lib/Makefile-all-$1
echo -e "\t$MAKE -f Makefile-lib-$1"        >> lib/Makefile-all-$1
echo -e "\t$MAKE -f Makefile-expat-$1"      >> lib/Makefile-all-$1
echo -e "\t$MAKE -f Makefile-gama-local-$1" >> lib/Makefile-all-$1
echo -e "\t$MAKE -f Makefile-gama-g3-$1"    >> lib/Makefile-all-$1

# ------------------------------------------------------------------------
