#! /bin/sh

export CFLAGS=-O3
export CXXFLAGS=-O3
export builddir=`pwd | sed -e 's,[a-z][:],,g'`
export srcdir=`cd ..; pwd | sed -e 's,[a-z][:],,g'`
export CONFIG_SHELL=bash
inst_prefix=`( cd ..; pwd; ) | sed -e 's,[a-z][:][/],/,g'`/install.djg
dft_target=i586-pc-msdosdjgpp

case $1 in \
	config) 
	        echo "BASH_VERSION: ${BASH_VERSION}" >con
		case ${BASH_VERSION} in 
			1.*.*) 	export PATH_SEPARATOR=:
				# The following is needed, to get not the // syntax, when
				# the configure script or the makefile calls pwd
				current_drive=`pwd | sed 's,//\(.\).*,\1,'`
				export SYSROOT=$current_drive:/
			       	;;
			2.*.*)  ;;
			*) exit 1 ;;
		esac

		# give now the configure script some hints
		topdir=`(cd $srcdir/..; pwd;)`
		AS=`test -f $DJDIR/bin/as.exe && echo $DJDIR/bin/as.exe`
		export AS=${AS-as}
		export PATH_SEPARATOR=:
		export CC=gcc
		export CXX=gpp
		export LD=ld
		export DEFAULT_LEX=flex
		export LEX=flex
		export RANLIB=ranlib
		export ac_cv_path_install="ginstall -c"
                $srcdir/configure --srcdir=$srcdir --disable-shared --verbose \
		  --with-gxx-include-dir=\\\${prefix}/lang/cxx \
		  --with-gnu-ld	--target=${target-${dft_target}} \
		  --host=${target-${dft_target}}  \
		  --prefix=\\\$\$DJDIR
		exit $?
		;;

	gcc)
            make all-gcc CFLAGS=-O3 && \
            exit $?
		;;

      pas)
            make languages=pascal CFLAGS=-O3 && \
            exit $?
            ;;

	libs1)
            make      configure-target-libiberty \
			    configure-target-libio \
			    configure-target-libstdcxx \
                      configure-target-libgpp \
			    all-target-libio \
			    all-target-libiberty \
			    all-target-libstdcxx \
			    all-target-libgpp
		exit $?
		;;

	libs2)
		make configure-target-libf2c
		make all-target-libf2c
		exit $?
		;;

	libs3)
		make all-target-libobjc all-target-libchill
		exit $?
		;;

	install)
		make install prefix=${inst_prefix}
		rc=$?
		make info
		make install-info prefix=${inst_prefix}
                exit ${rc}
		;;

	mkdist)
		cd ${inst_prefix} && ./mkdist.sh
		exit $?	
		;;

	*)	;;

esac;
