#!/bin/sh

#
# bpmake
#

# Set USE_ENV to -e if you want to override the variables in
# the Makefile.

makefile=$NNTOOLS/migraines/bp/$MACHTYPE.bp.mk

# see if there is a user initialization file
if test -s user_init.c
then
	uinit='INIT=user_init.o INIT_CONST=-DUSER_INIT ' ;
else
	uinit="";
fi


if test "$*"
then

#   are you asking for a particular .aspirin file?
  if test -s $1.aspirin
  then
    make $USE_ENV -f $makefile NETWORK=$1 $uinit "$@"  
  else    
    make $USE_ENV -f $makefile $uinit "$@"  
  fi

else

  # default, look for .aspirin files
  nfiles=`ls | grep '\.aspirin$' | wc -l`
  if test $nfiles -ge 1
  then
	if test $nfiles -gt 1
	then
		echo Warning: There are $nfiles Aspirin files \(files \
			with .aspirin suffix\) in this directory.
		file=`ls *.aspirin | head -1`
		net=`echo $file | sed s/\.aspirin$//`
		echo \  \  \  \  \ Will compile the first:  $file
		echo
	else
		file=`ls *.aspirin`
		net=`echo $file | sed s/\.aspirin$//`
	fi

	make $USE_ENV -f $makefile NETWORK=$net $uinit  

  else
	echo
	echo "Error: Unable to find an Aspirin file(*.aspirin) to make!"
	echo
  fi

fi

echo ""
echo "bpmake finished."

exit

