#!/bin/sh
#
# This script make a new METAFONT cm*.mf or dc*.mf or fc*.mf file
# because one wasn't found.  Usage
#
# MakeTeXMF name
#
# `name' is the name of the font file, such as `cmr10'
#
# This file need the sauter font system and the dc fonts
#
# 940726, FL: customized for NTeX

MFDIR=/usr/lib/texmf/mf
DESTDIR=/usr/lib/texmf/fonts/tmp/src
SAUTERDIR=/usr/lib/texmf/fonts/cm/sauter21
DCDIR=/usr/lib/texmf/fonts/dc
FCDIR=/usr/lib/texmf/fonts/language/fc

NAME=`echo $1 | sed 's/\.mf$//'`

echo "Running MakeTeXMF $*" 1>&2

umask 0

MFNAME=$NAME.mf

# Which type of font is this?
case $NAME in
  cm*) font=cm;;
  dc*) font=dc;;
  fc*) font=fc;;
  *) font=other;;
esac

if test -r $DESTDIR/$MFNAME
then
   echo "$DESTDIR/$MFNAME already exists!" 1>&2
   echo $DESTDIR/$MFNAME
   exit 0
fi

if test $font = cm; then
  # The font is CM.  Try Sauter's scripts.
  echo "Trying interpolated/extrapolated (Sauter) CM source." 1>&2
  if test -d $SAUTERDIR; then
   	cd $SAUTERDIR
   	rootfont=`echo $NAME | sed 's/[0-9]*$//'`
   	pointsize=`echo $NAME | sed 's/cm[a-z]*//'`
	if test -e $SAUTERDIR"/src/bases/b-"$rootfont".mf"; then
   	  make-mf $rootfont $pointsize 1>&2
   	  echo 1>&2
   	  # Install the MF file carefully, since others may be doing the same
   	  # as us simultaneously.
   	  chmod 644 src/$MFNAME 1>&2
   	  mv src/$MFNAME $DESTDIR/mftmp.$$ 1>&2
   	  cd $DESTDIR
   	  mv mftmp.$$ $MFNAME 1>&2
   	  echo $DESTDIR/$MFNAME
	else
	  echo "Sauter base for the font does not exist" 1>&2
	fi
  else
   	echo "Could not find the sauter font directory" 1>&2
  fi
elif test $font = dc; then
  # The font is DC. 
  echo "Trying interpolated/extrapolated DC source." 1>&2
  if test -d $DCDIR; then
  	cd $DESTDIR
  	rootfont=`echo $NAME | sed 's/[0-9]*$//'`
  	pointsize=`echo $NAME | sed 's/dc[a-z]*//'` 
	if test -e $DCDIR/make-dc-mf; then
		if test-e $DCDIR"/src/bases/"$rootfont".mf"; then
  		  $DCDIR/make-dc-mf $rootfont $pointsize >/dev/null
  		  chmod 644 $MFNAME >/dev/null
  		  echo $DESTDIR/$MFNAME
		else
		  echo "DC basefile for the font does not exist" 1>&2
		fi
	else
		echo "Could not find make-dc-mf" 1>&2
	fi
   else
	echo "Could not find the dc font directory" 1>&2
   fi
elif test $font = fc; then
  # The font is FC. 
  echo "Trying interpolated/extrapolated FC source." 1>&2
  if test -d $FCDIR; then
  	cd $DESTDIR
  	rootfont=`echo $NAME | sed 's/[0-9]*$//'`
  	pointsize=`echo $NAME | sed 's/fc[a-z]*//'` 
	if test -e $FCDIR/make-fc; then
		if test-e $FCDIR"/make-fc/src/bases/b-"$rootfont".mf";then
  		  $FCDIR/make-fc $rootfont $pointsize $pointsize >/dev/null
  		  chmod 644 $MFNAME >/dev/null
  		  echo $DESTDIR/$MFNAME
		else
		  echo "FC basefile for the font does not exist" 1>&2
		fi
	else
		echo "Could not find make-fc" 1>&2
	fi
   else
	echo "Could not find the fc font directory" 1>&2
   fi
else
  echo "MakeTeXMF is not implemented for this font" 1>&2
fi
