#! /bin/sh
## makeam,v 1.20 1998/05/13 03:48:00 bjg Exp
## Usage: 'makeam [Makefile.ami] > Makefile.am'
## makes the 'Makefile.am' file from the template 'Makefile.ami'

ami=Makefile.ami
if [ $# -gt 0 ]; then
    ami=$1
fi

list=`egrep '^ALLRAN=' $ami | sed s/ALLRAN=//`

##################################################
## Start writing the Makefile.am
##
## First line is to get a $_Id_$ string without having
## RCS expand it here!
#echo '### $xIxdx:x$' | sed s/x//g
cat Makefile.ami   | egrep -v '^### '
    
auxbin="test-switch"

progs=""
for i in $list; do
    progs="$progs $i"
done
progs="$progs $auxbin"
echo "bin_PROGRAMS=$progs"
echo ""
echo ""

tests=""
for i in $list; do
    tests="$tests test-$i bench-$i"
done
progs="$progs $auxbin"
echo "check_PROGRAMS=$tests"
echo ""
echo ""

libs=""
for i in $list; do
    libs="$libs libgslran$i.a"
done
echo "lib_LIBRARIES= libgslrandom.a $libs"
echo ""
echo ""
for i in $list; do
    echo "libgslran${i}_a_SOURCES= $i.c $i-gen.c "
done
echo ""

sources="switch.c "
for i in $list; do
    sources="$sources $i.c"
done
echo "libgslrandom_a_SOURCES=$sources"
echo ""
echo ""

tests=""
for i in $list; do
    tests="$tests test-$i"
done
echo "TESTS=$tests"
echo ""
echo ""

deps="gsl_ran_switch.h"
for i in $list; do
    deps="$deps $i.h $i.o"
done
echo "test_switch_DEPENDENCIES=$deps"
echo ""

obj=""
for i in $list; do
    obj="$obj $i.o"
done
obj="$obj ../utils/libutils.a "
echo "test_switch_LDADD=$obj"
echo ""
    
    for i in $list; do
    echo "${i}_SOURCES=             ran.c $i.c $i.h"
    echo "EXTRA_${i}_SOURCES=       $i-state.c"
    echo "${i}_DEPENDENCIES=        $i-state.c $i-gen.o"
    echo "${i}_LDADD=               $i-gen.o"
    echo "test_${i}_SOURCES=        testran.c"
    echo "test_${i}_DEPENDENCIES=   $i.o $i-gen.o $i.h"
    echo "test_${i}_LDADD=          $i.o $i-gen.o ../err/libgsltest.a ../utils/libutils.a"
    echo "bench_${i}_SOURCES=       benchran.c"
    echo "bench_${i}_DEPENDENCIES=  $i.o $i-gen.o $i.h"
    echo "bench_${i}_LDADD=         $i.o $i-gen.o"
done
echo ""


echo "## Note, BUILT_SOURCES has special meaning to automake"
echo "## I'm deliberately trying to avoid having the casual user"
echo "## build sources.  If you want to build THE_BUILT_SOURCESS"
echo "## then run the program './makesrc'"
built_src=""
for i in $list; do
    built_src="$built_src $i.h $i-state.c $i-gen.c"
done
built_src="$built_src gsl_ran_switch.h switch.c"
echo "## THE_BUILT_SOURCES=$built_src"
echo ""
echo "## If you need to build these sources, use the 'makesrc' script"
echo "# These are commented out now that the files are under CVS "
echo "# The relative dates seem to cause a problem for make distcheck"
for i in $list; do
    echo "# $i.h $i-state.c $i-gen.c: makesrc"
    echo "#	\$(srcdir)/makesrc $i"
    echo ""
done


echo "## This target is kind of like 'distclean'"
echo "tooclean:"
echo "	/bin/rm -rf .deps"
for i in $list; do
    echo "	/bin/rm -f $i.h $i-state.c $i-gen.c"
done
echo "	/bin/rm -f switch.c gsl_ran_switch.h"
echo ""
     
##




