#! /bin/sh

# Values from c-auto.h

mk_NOTOOL=
mk_GREY=
mk_BUTTONS=
mk_PS_GS=
mk_GS_PATH='gs'
mk_PS_DPS=
mk_PS_NEWS=
mk_A4=

# HyperTeX: There appears to be no (easy) way to disable this
mk_HTEX=1

# Kpathsea defaults, they are #if'ed in the source but there is no
# config option to disable them.
mk_SELFILE=1
mk_KPATHSEA=1

# Optional values from CFLAGS

mk_MFMODE='unspecified'
mk_BDPI=600
mk_DEFAULT_FONT_SIZES='m0:m0.5:m1:m2:m3:m4:m5'
mk_SHRINK=8

# Get arguments from CFLAGS

for mk_arg
do
  case "$mk_arg" in
    -D*=*)
      eval "`echo \"$mk_arg\" | sed 's/^-D/mk_/'`"
      ;;
    -D*)
      eval "`echo \"$mk_arg\" | sed 's/^-D/mk_/'`=1"
      ;;
  esac
done

# Get arguments from c-auto.h

eval "`awk '/^#define/ { print "mk_"$2"="$3 }' c-auto.h`"

# eval "`cat c-auto.h \
#   | grep '^[ 	]*#[ 	]*define[ 	]' \
#   | sed 's/^[ 	]*#[ 	]*define[ 	][ 	]*/mk_/' \
#   | sed 's/[ 	][ 	]*/=/'`"

# Process simple boolean arguments.  Their values are empty or nonempty

if test -n "$mk_NOTOOL";	then mk_BUTTONS=;			fi
if test -z "$mk_GREY";		then echo '/^#ifgrey/,/^#/d';		fi
if test -z "$mk_BUTTONS";	then echo '/^#ifbuttons/,/^#/d';	fi
if test -z "$mk_PS_DPS";	then echo '/^#ifdps/,/^#/d';		fi
if test -z "$mk_PS_NEWS";	then echo '/^#ifnews/,/^#/d';		fi
if test -z "$mk_HTEX";		then echo '/^#ifhyper/,/^#/d';		fi
if test -n "$mk_NOGRID";	then echo '/^#ifgrid/,/^#/d';		fi

if test -z "$mk_KPATHSEA"; then	echo	'/^#ifkpathsea/,/^#/d';
			   else echo	'/^#ifnokpathsea/,/^#/d';	fi

# -DNOSELFILE is supposed to override everything
case $mk_SELFILE:$mk_NOSELFILE in
    *:1)	echo '/^#ifselfile/,/^#/d';;
    1:*)	echo '/^#ifnoselfile/,/^#/d';
esac

# See HTEX comment above    
# if test -z "$mk_HAVE_LIBWWW" || test -z "$mk_HAVE_WWWLIB_H";
# 				then echo '/^#ifhyper/,/^#/d';		fi

# Process remaining PostScript emulation arguments

if test -z "$mk_PS_GS"; then
  echo '/^#ifghost/,/^#/d'
else
  echo "s^@GS_PATH@^$mk_GS_PATH^"
fi

if test -n "$mk_PS_GS" || test -n "$mk_PS_DPS" || test -n "$mk_PS_NEWS"; then
  mk_PS=y
  echo '/^#ifnops/,/^#/d'
else
  mk_PS=
  echo '/^#ifps/,/^#/d'
fi

# Miscellaneous args

if test -n "$mk_A4"; then
  echo 's/@DEFAULT_PAGE_SIZE@/21 x 29.7 cm (A4 size)/'
  echo 's/@DEFAULT_UNIT@/cm " (centimeters)"/'
else
  echo 's/@DEFAULT_PAGE_SIZE@/8.5 x 11 inches/'
  echo 's/@DEFAULT_UNIT@/in " (inches)"/'
fi

echo "s^@MFMODE@^$mk_MFMODE^"
echo "s/@BDPI@/$mk_BDPI/"
echo "s/@SHRINK@/$mk_SHRINK/"

echo "s/@DEFAULT_FONT_SIZES@/$mk_DEFAULT_FONT_SIZES/" | sed -e "s/:/ :\\\\\\
/g"

# Remove all remaining '#' lines

echo	'/^#/d'

# Done

exit 0
