#!/bin/sh
# PROJECT: MusixTeX PreProcessor
# FILE   : configure
# AUTHOR : JCNieuwenhuizen
#
# copyright (c) FlowerSoft 1995, 1997
# ---------------------------------------------------------------------------
# ABSTRACT: script to configure mpp and to determine specifics of C++ release
# --
# Guess values for system-dependent variables and create Makefiles.
# Generated automatically using autoconf version 2.1 
# Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
#
# This configure script is free software; the Free Software Foundation
# gives unlimited permission to copy, distribute and modify it.

# constants
#
USAGE=\
'Usage: configure [options] [PLATFORM]
       PLATFORM is one of unix, msdos, msvc, gnu'

OPTIONS=\
'Options:
  --help                  print this message
  --name=NAME             configure from NAME.in [mpp]
  --platform=PLATFORM     configure for platform PLATFORM [gnu]
  --version               print version number and exit'
#

# defaults:
#
ac_help=
compile=g++
name=mpp
nonopt=NONE
platform=gnu
srcdir=.
#

# determine type of echo
#
if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then
  # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu.
  # IRIX 5.3 lacks -e, tnnvjn@asterix.urc.tue.nl
  if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then
    ac_n= ac_c='
' ac_t='        '
  else
    ac_n=-n ac_c= ac_t=
  fi
else
  ac_n= ac_c='\c' ac_t=
fi
#

# parse command line
#
ac_prev=
for ac_option
do

  # If the previous option needs an argument, assign it.
  if test -n "$ac_prev"; then
    eval "$ac_prev=\$ac_option"
    ac_prev=
    continue
  fi

  case "$ac_option" in
  -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
  *) ac_optarg= ;;
  esac

  case "$ac_option" in

  -h | -help | --help | --hel | --he | --h)
#    # Omit some internal or obsolete options to make the list less imposing.
#    # This message is too long to be a string in the A/UX 3.1 sh.
#    echo "$USAGE"
#    cat << EOF
#Options:
#  --help                  print this message
#  --name=NAME             configure from NAME.in
#  --platform=PLATFORM     configure for platform PLATFORM
#  --version               print version number and exit
#EOF
#  --version               print version number and exit
    echo "$USAGE"
    echo
    echo "$OPTIONS"
    exit 0 ;;

  -n | -name | --name | --nam | --na | --n )
    ac_prev=name;;
  -n=* | -name=* | --name=* | --nam=* | --na=* | --n=* )
    name="$ac_optarg" ;;

  -p | -platform | --platform | --platfor | --platfo | --platf \
    | --plat | --pla | --pl | --p )
    ac_prev=platform ;;
  -p=* | -platform=* | --platform=* | --platfor=* | --platfo=* | --platf=* \
    | --plat=* | --pla=* | --pl=* | --p=* )
    platform="$ac_optarg" ;;
 
#  -q | -quiet | --quiet | --quie | --qui | --qu | --q \
#  | -silent | --silent | --silen | --sile | --sil)
#    silent=yes ;;

  -v | -version | --version | --versio | --versi | --vers | --ver | --ve | --v)
    echo "configure for mpp v0.1, manually hacked"
    exit 0 ;;

  -*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; }
    ;;

  *) 
    if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then
      echo "configure: warning: $ac_option: invalid host type" 1>&2
    fi
    if test "x$nonopt" != xNONE; then
      { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; }
    fi
    nonopt="$ac_option"
    ;;

  esac
done

if test -n "$ac_prev"; then
  { echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; }
fi
#

# set platform
#
if test "$nonopt" != NONE; then
	platform=$nonopt
fi
#

# check for sources
#
# A filename unique to this package, relative to the directory that
# configure is in, which we can look for to find out if srcdir is correct.
ac_unique_file=$name.in

if test ! -r $srcdir/$ac_uniue_file; then
    echo "configure: error: cannot find sources in $srcdir" 1>&2; 
    exit 1;
fi
#

echo $ac_n "configuring [$name] for: $ac_c"

# check platform and set compiler
#
config=src/config.hh
echo "/* Generated automatically by configure */" > $config
echo "#ifndef __CONFIG_HH" >> $config
echo "#define __CONFIG_HH" >> $config

echo "PLATFORM = $platform" > Makefile
cat config/Makefile.0 >> Makefile

case $platform in
#NONE)   echo "$USAGE"
#	exit 2 
#	;;
gnu)	echo gnu
	compile=g++
	g++ -v
	echo "#ifndef __unix__ " >> $config
	echo "#define __unix__ " >> $config
	echo "#endif " >> $config
	echo "#define PATHSEP '/'">>$config
	;;
unix)	echo unix
	compile=CC
	echo "#define __unix__ " >> $config
	echo "#define PATHSEP '/'">>$config
	;;
msvc)	echo msvc
	;;
msdos)	echo msdos
	echo "#define PATHSEP '\\\\'">>$config
	;;
mac)	echo mac
	echo "#define PATHSEP ':'">$config
	;;
*)	echo none
	echo "$USAGE"
	exit 2
	;;
esac
#

# determine release specifics
#
echo "determining C++ release"

# rm comma*, hwn 26/10

if $compile -o testbool.o -c testbool.cc
then
	echo compiler has boolean type. Good.
else
	echo error compiling testbool.cc, compiler has no builtin boolean
	echo "#define HAVE_NO_BOOL" >> $config
fi
rm -rf testbool.o

$compile -DTEST -o assign assign.cc;
if test ! -x assign 
then
	echo "configure: error compiling assign.cc"
	exit 1
fi

$compile -DTEST -o postfix postfix.cc;
if test ! -x postfix
then
	echo "configure: error compiling postfix.cc"
	exit 1
fi
#$compile -DTEST -o nest.cc

if ./assign                   # true if exit status == 0
then
	echo $ac_n "$ac_c"    # do nothing
else
    echo "configure: warning: assignment operator has left to right associativity";
    echo '#define ASSIGN_LEFT_TO_RIGHT' >> $config
fi

#if ./postfix                  # true if exit status == 0
#then
    echo "#define POSTFIX_INT int" >> $config;
    echo '#define DELETE_ARRAY( size ) delete[]' >> $config
    echo '#define NESTED_IN( Class ) Class::' >> $config
#else
#    echo "configure: warning: old C++ release; please upgrade"
#    echo "#define POSTFIX_INT" >> $config;
#    echo "#define DELETE_ARRAY( size ) delete[ size ]" >> $config
#    echo "#define NESTED_IN( Class )" >> $config
#fi

#if ./nested
#then
#    echo "#define NESTED_IN( Class ) Class::" >> $config
#else
#    echo "configure: warning: old C++ release; please upgrade"
#    echo "#define NESTED_IN( Class )" >> $config
#fi

rm assign postfix 

echo "#endif /* __CONFIG_HH */" >> $config

# rm -f src/systemna.hh
# echo "\"`uname`\"" > src/systemna.hh

echo configured for $platform

echo \"make\" for compiling
echo \"make INSTALLDIR=PATH install\" for installing in \"PATH\"



