#!/bin/sh

#
# test if test is available.
#
if [ "$path" = "" ]
then
  path="`echo $PATH | sed -e 's/:/ /g'`"
fi

ecc="echo"
ecs="\c"
if [ "`(echo "test\c";echo "test") | wc | awk '{print $1}'`" != "1" ]
then
        ecc="echo -n"
        ecs=""
fi
searchstr="bdftopcf bdftosnf dxfc xtbdftosnf convertfont"
convertstr=""
for file in $searchstr
do
  whicharg="$file"
  whichfnd="F"
  for dir in $path
  do
    if [ -x $dir/$whicharg ]
    then
      whichfnd="T"
      whicharg="$dir/$whicharg"
      break
    fi
  done
  if [ "$whichfnd" = "T" ]
  then
    convertstr="$convertstr $file"
  fi
done
searchstr="mkfontdir dxmkfontdir xtmkfontdir bldfamily"
dirstr=""
for file in $searchstr
do
  whicharg="$file"
  whichfnd="F"
  for dir in $path
  do
    if [ -x $dir/$whicharg ]
    then
      whichfnd="T"
      whicharg="$dir/$whicharg"
      break
    fi
  done
  if [ "$whichfnd" = "T" ]
  then
    dirstr="$dirstr $file"
  fi
done
#
echo "SHELL=/bin/sh" > Makefile
echo "all: fontfiles indexfiles" >> Makefile
echo "fontfiles: $convertstr" >> Makefile
echo "indexfiles: $dirstr" >> Makefile
cat Makefile.def >> Makefile
cat fs.config.def | sed -e 's#FONTDIRECTORY#'$FONTDIR'#g' -e 's#ERRORFILE#'$FONTDIR'/error.log#g' > fs.config
