#!/bin/sh
#
# Configuration Program for Portable Objective C Compiler
# Copyright (c) 1997,98. All Rights Reserved.
#
# Revision: $Id: configure.orig,v 1.3 1999/05/15 12:36:34 stes Exp $

#
# Error diagnostics
#
# Descriptor usage:
# 1: ???
# 2: errors that should be seen even if we're in the background.
# 3: [stdout from test runs]
# 4: verbose-style messages (Using ...)
# 5: compiler stderr when running tests
#

Note()
{
    case $VERBOSE in
     1) echo "$@" 1>&2;;
     *) ;;
    esac
}

Error()
{
    echo "configure: $@" 1>&2
}

FatalError()
{
    Error $*
    Error "Fatal!  Once you've corrected the problem rerun this script."
    # use kill so a trap handler could be called
    kill -1 $$
}

CheckIncDir()
{
  if [ ! -f "$GNUOBJCDIR/Object.h" ]; then
    Error      "Set the env. variable GNUOBJCDIR to the Object.h directory"
    Error      " "
    Error      "	setenv GNUOBJCDIR /usr/include/objc"
    FatalError " "
  fi
}

#
# Remove junk when interrupted, remove junk when starting
#
# do not deposit these files in '.' (problem when . is not in $PATH for
# sourcing the file)
#

CMDFILE=/tmp/cmdfile.$$
CONFSED=/tmp/confsed.$$

JUNK="$CONFSED $CMDFILE"
trap "rm -f $JUNK; exit 1" 1 2 15

rm -f $JUNK

#
# help option

Usage()
{
    cat<<'EOF'
Usage: configure [options] [targethost]
Options:
  -v|--verbose   	  verbose
  -h|--help               print this message
  -e PARAM=ARG		  set configuration PARAM 
  -e CC=lcc		  (example) use CC=lcc
  -nextstep               configure for compiling with nextstep gcc compiler
  -stepstone              configure for compiling with stepstone compiler
  -gnu                    configure for compiling with plain gcc compiler
  -f file		  source configuration PARAMs in file
  --prefix=DIR            set prefix to DIR instead of /usr/local
  --gcprefix=DIR          set prefix for gc.h and gc.a, default is /usr/local
EOF
}

#
# Arguments of the script
# Append all to '$CMDFILE' and then source that file
#

touch $CMDFILE
STEPALLC=n
MAKEONLY=0
VERBOSE=0

while :
do
	case $# in
	0)  break ;;
	esac
	
	arg="$1"
	case ${arg} in
		--prefix=*)	INSTALLDIR=`expr $arg : '--prefix=\(.*\)'` ;;
		--gcprefix=*)	GCPREFIX=`expr $arg : '--gcprefix=\(.*\)'` ;;
		-v|--verbose)	VERBOSE=1;;
		-f)		shift;cat "$1" >> $CMDFILE;;
		-e)		shift;echo "$1" >> $CMDFILE;;
		-M)             MAKEONLY=1;;
		-stepstone)
			OBJCC=objcc;
			OTHER_MFLAGS="-q";
			STEPALLC=n;
			;;
		-stepstoneAllC)
			OBJCC=objcc;
			OTHER_MFLAGS="-q";
			STEPALLC=y;
			;;
	        -gnu)
			OBJCC="gcc";
			CheckIncDir;
			OTHER_MFLAGS="-Wall -DIOD='FILE*' -I$GNUOBJCDIR";
			mv include/objcrt/Object.h include/objcrt/Object.bak
			mv src/objcrt/Object.h src/objcrt/Object.bak
			;;
		-nextstep)
			OBJCC="cc";
			CheckIncDir;
			OTHER_MFLAGS="-Wall -DIOD='FILE*' -I$GNUOBJCDIR";
			mv include/objcrt/Object.h include/objcrt/Object.bak
			mv src/objcrt/Object.h src/objcrt/Object.bak
			;;
		-Wall)
			OTHER_MFLAGS="-q -Wall";
			;;
		-watcom)
			TARGET=i586-watcom-win32;
			OBJCC='objc';
			XOBJCC='\\objc\\bin\\objc';
			OTHER_MFLAGS="-q";
			;;
		-msvc)
			TARGET=i586-msvc-win32;
			OBJCC='objc';
			XOBJCC='\\objc\\bin\\objc';
			OTHER_MFLAGS="-q";
			;;
		-mwcppc)
			TARGET=powerpc-mwcppc-system7;
			OBJCC='objc';
			XOBJCC='stes:ObjectiveC:bin:objc';
			OTHER_MFLAGS="-q";
			;;
		-mwc68k)
			TARGET=m68k-mwc68k-system7;
			OBJCC='objc';
			XOBJCC='stes:ObjectiveC:bin:objc';
			OTHER_MFLAGS="-q";
			;;
		-lccwin32)
			TARGET=i586-lcc-win32;
			OBJCC='objc';
			XOBJCC='\\objc\\bin\\objc';
			OTHER_MFLAGS="-q";
			;;
		-djgpp)
			TARGET=i586-djgpp-win32;
			OBJCC='objc';
			# for GNU make need double slash
			XOBJCC='\\\\objc\\\\bin\\\\objc';
			OTHER_MFLAGS="-q";
			;;
		-cygwin32)
			TARGET=i586-cygwin32-win32;
			OBJCC='objc';
			XOBJCC='/objc/bin/objc';
			OTHER_MFLAGS="-q";
			;;
		-ibmvac)
			TARGET=i586-ibmvac-os2;
			OBJCC='objc';
			XOBJCC='\\objc\\bin\\objc';
			OTHER_MFLAGS="-q";
			;;
		-*) Usage;kill -1 $$;;
		*) TARGET=$arg;;
	esac
shift
done

. $CMDFILE

#
# Find the full pathname of a file
# using the specified test operation.
#

findThing()
{
    t="$1"; app="$2"; path="$3";
    case "$app" in
    /*) eval "$t" "$app" && { echo "$app"; return; };;
    esac
    (IFS=:
    for i in $path; do
	eval "$t" "$i/$app" && { echo "$i/$app"; return 0; }
    done
    return 1
    )
}

#
# Find the full pathname of a plain file.
#

findFile()
{
    findThing "test -f" "$1" "$2"
}

#
# Find the full pathname of an executable.
#

findApp()
{
    findThing "test -x" $1 $2
}

#
# Name of this version EXCLUDING the Target Platform
#

NAME=objc-2.3.3
Note NAME = "$NAME"

#
# Locate top directory by looking for the License file.
# If file BOOTSTRAP is found, then we assume we're working as bootstrap script
#

if [ -z "$TOPDIR" ]; then
  TOPDIR=.
fi

if [ -f $TOPDIR/BOOTSTRAP ]; then
  BOOTSTRAP=1;
else
  BOOTSTRAP=0;
  if [ ! -f $TOPDIR/License.txt ]; then
    FatalError "Cannot locate sources in $TOPDIR"
  fi
fi

#
# Guess - or standarize format of - the target architecture.
# We use GNU scripts for doing that, because these are being kept up to
# date for many UNIX platforms.
#

CONFGUESS=$TOPDIR/util/config.guess
CONFSUB=$TOPDIR/util/config.sub

if [ -z "$TARGET" ]; then
	TARGET=`sh $CONFGUESS`
	Note "My guess is that we're on a $TARGET."
else
	TARGET=`sh $CONFSUB "$TARGET"`
	if [ $? = 0 ]; then
		Note "Setting TARGET platform to $TARGET"
	else
		FatalError "Need processor-vendor-operatingsystem format"
	fi
fi

###############################################################################
#
#                              M A K E F I L E
#
###############################################################################

#
# Directory for "make install"
# (Moved Note to the end of the configure script)
#
# about backslashes : don't use "" here since it will eat a \\
# we have to double once, because the "sed" will reduce a \\ to \
# for paths to be used in C source (in objc.exe for example) we need
# to generate a \\ instead of \ (which we have to do for paths in makefiles)
#

if [ -z "$INSTALLDIR" ]; then
	case $TARGET in
		*watcom*) INSTALLDIR='\\objc';;
		*lcc*) INSTALLDIR='\\objc';;
		*msvc*) INSTALLDIR='\\objc';;
		*djgpp*) INSTALLDIR='\\\\objc';;
		*cygwin*) INSTALLDIR='/objc';;
		*mwc*) INSTALLDIR='stes:ObjectiveC';;
		*ibmvac*) INSTALLDIR='\\objc';;
		*beos*) INSTALLDIR="/boot/apps/GeekGadgets";;
		*) INSTALLDIR='/usr/local';;
	esac
fi

if [ -z "$INSTALLDIRC" ]; then
	case $TARGET in
		*djgpp*) INSTALLDIRC='\\\\objc';;
		*watcom*) INSTALLDIRC='\\\\objc';;
		*lcc*) INSTALLDIRC='\\\\objc';;
		*msvc*) INSTALLDIRC='\\\\objc';;
		*cygwin*) INSTALLDIRC='/objc';;
		*mwc*) INSTALLDIRC='stes:ObjectiveC';;
		*ibmvac*) INSTALLDIRC='\\\\objc';;
		*beos*) INSTALLDIRC="$INSTALLDIR";;
		*) INSTALLDIRC="$INSTALLDIR";;
	esac
fi

if [ -z "$GCPREFIX" ]; then
  GCPREFIX="$INSTALLDIR";
fi

if [ -z "$GCPREFIXC" ]; then
  GCPREFIXC="$INSTALLDIRC";
fi

# this is used in WATCOM Makefiles.
# In C strings or GNU make we'd need \\\\

if [ -z "$PATHSEP" ]; then
	case $TARGET in
		*watcom*) PATHSEP='\\';;
		*lcc*) PATHSEP='\\';;
		*msvc*) PATHSEP='\\';;
		*djgpp*) PATHSEP='\\\\';;
		*mwc*) PATHSEP='/';; # for UNIX makefiles
		*ibmvac*) PATHSEP='\\\\';;
		*) PATHSEP='/';;
	esac
fi

if [ -z "$PATHSEPC" ]; then
	case $TARGET in
		*watcom*) PATHSEPC='\\\\';;
		*lcc*) PATHSEPC='\\\\';;
		*msvc*) PATHSEPC='\\\\';;
		*djgpp*) PATHSEPC='\\\\';;
		*mwc*) PATHSEPC=':';; # for source
		*ibmvac*) PATHSEPC='\\\\';;
		*) PATHSEPC='/';;
	esac
fi

#
# Little hack to generate source from LEX and YACC files for
# platforms that don't have this normally (Windows)
#
# Also, do prefix substitutions as in the Makefiles (cakit/Makefile)
#
# It's also possible to use the WIN32 flex/bison
#

genLex()
{
	(
		cd $1
		file=$2
		prefix=$3
		Note Creating $1 / $file.m from $file.lm
		flex -Cem $file.lm
		sed s/yy/$prefix/g < lex.yy.c > $file.m
		rm lex.yy.c
	);
}

genYacc()
{
	(
		cd $1
		file=$2
		prefix=$3
		Note Creating $1 / $file.m from $file.ym
		byacc -d $file.ym;
		sed s/yy/$prefix/g < y.tab.c > $file.m
		sed s/yy/$prefix/g < y.tab.h > $file.h
		rm y.tab.c
		rm y.tab.h
	);
}

genParser()
{
	genYacc src/objc yacc yy
	genLex src/objc lex yy
	genLex words token yy
}

#
# Finding Objective C compiler
# Don't use -Wall by default as many cc have a different interface
#
# XOBJCC is for cross compiles when the current directory contains a ./objc
#

if [ -z "$OTHER_MFLAGS" ]; then
	OTHER_MFLAGS="-q"
fi

case $BOOTSTRAP in
1)
;;
0)
if [ -z "$OBJCC" ]; then
	OBJCC="objc";
	XOBJCC=`findApp objc $PATH`
	if [ -z "$XOBJCC" ]; then FatalError "no objc bootstrap compiler found"; fi
	XOBJC1=`findApp objc1 $PATH`
	if [ -z "$XOBJC1" ]; then FatalError "no objc1 (stage 1) found"; fi
fi
;;
esac

if [ -z "$XOBJCC" ]; then
	XOBJCC="$OBJCC"
fi

Note OBJCC = $OBJCC
Note XOBJCC = $XOBJCC
Note XOBJC1 = $XOBJC1

#
# C compiler
# On SunOS 4.1.1 cc is not ANSI.  Good test perhaps to support K&R.
# I once compiled with acc on a machine where acc was installed.
#
# On Solaris using gcc because don't have access to other machine.
#

if [ -z "$CC" ]; then

# gcc is by default safer choice then native cc
CC="gcc"
CCPLUS="g++"

case $TARGET in
	*aix*) CC=cc;;
	*irix*) CC="cc";CCPLUS="CC";;
	*hpux*) CC="cc";CCPLUS="CC";;
	*osf*) CC="cc";CCPLUS="CC";;
	*unicos*) CC="cc";CCPLUS="CC";;
	*watcom*) CC=wcc386;CCPLUS="$CC";;
	*msvc*) CC="cl /TC";CCPLUS="cl /TP";;
	*lcc*) CC=lcc;;
# suppress warnings about unused functions.
# note : can't do this OC_CCARGS since MWLinkPPC does not impl. -w
	*mwcppc*) CC="MWCPPC -w nopossible -w nounusedarg";CCPLUS="$CC";;
	*mwc68k*) CC="MWC68K -w nopossible -w nounusedarg";CCPLUS="$CC";;
# pentium, turn off logo
	*ibmvac*) CC="icc";CCPLUS="$CC";;
	*nextstep*) CC="cc";CCPLUS="c++";;
	*rhapsody*) CC="cc";CCPLUS="c++";;
	*netbsd*) CC="cc";CCPLUS="c++";;
	*beos*) CC="mwcc";CCPLUS="mwcc -dialect cplus";;
	*) ;;
esac

fi

Note CC = $CC


# flags to place output in file, to add path to include path,
# to prevent a link

IISUFFIX="cc"
CCMINUSCFLAG="-c "
CCMINUSDFLAG="-D"
CCMINUSOFLAG="-o "
CCMINUSIFLAG="-I"

case $TARGET in
	*watcom*) CCMINUSCFLAG="";CCMINUSOFLAG="-fo=";CCMINUSIFLAG="-i=";;
	*lcc*) CCMINUSOFLAG="";CCMINUSCFLAG=" ";;
	*msvc*) CCMINUSCFLAG="/c";CCMINUSOFLAG="/Fo";CCMINUSIFLAG="/I";;
	*mwc*) CCMINUSCFLAG="";CCMINUSIFLAG="-i ";CCMINUSDFLAG="-d ";;
	*ibmvac*) CCMINUSCFLAG="-C ";CCMINUSOFLAG="-Fo";;
	*linux*|*bsd*|*sunos*) IISUFFIX="ii";;
	*hpux*) IISUFFIX="C";;
	*) ;;
esac

Note CCMINUSCFLAG = $CCMINUSCFLAG
Note CCMINUSOFLAG = $CCMINUSOFLAG
Note CCMINUSIFLAG = $CCMINUSIFLAG
Note CCMINUSDFLAG = $CCMINUSDFLAG

# watcom -pl = precompile + emit #line  (-plc preserves comments too)
# mw 68k needs the -d flags to strip out 68k assembly from string.h

case $TARGET in
	*watcom*) CPP="$CC -pl";;
	*msvc*) CPP="$CC /E";;
	*mwcppc*) CPP="MWCPPC -e";;
	*mwc68k*) CPP="MWCPPC -e -d _No_BlockMove -d _NoString_Inlines";;
	*ibmvac*) CPP="$CC -Pd";;
	*) CPP="$CC -E";;
esac

Note CPP = $CPP

# flag for cpp to accept #import and // comments (if supported at all)
# flag to allow $ in identifier (if supported at all)

CPPIMPORTFLAG=""
CCDOLLARFLAG=""

case $CC in
	cc)
	    case $TARGET in
		*irix*)
			CPPIMPORTFLAG="-acpp -Wp,-+";
                        CCDOLLARFLAG="-dollar";
			;; 
		*sco*|*unixware*|*svrv*uw*)
                        CCDOLLARFLAG="-Kdollar";
			;; 
		*linux*|*bsd*)
			CPPIMPORTFLAG="-x objective-c -Wno-import";
                        CCDOLLARFLAG="-fdollars-in-identifiers";
			;;
	    esac;;
	gcc) 
			CPPIMPORTFLAG="-x objective-c -Wno-import";
                        CCDOLLARFLAG="-fdollars-in-identifiers";
			;;
	tcc|lcc) ;;
esac

# filters to remove line continuation backslash emitted by WATCOM cpp

CPPFILTER=""
OBJC1FILTER=""

case $TARGET in
	*watcom*) CPPFILTER=fixwcpp;;
	*) ;;
esac

Note CPPFILTER = $CPPFILTER
Note OBJC1FILTER = $OBJC1FILTER

# flag to place output in a file
# if it's empty ("") the invocation is without outputfile

case $TARGET in
	*watcom*) CPPMINUSOFLAG="-fo=";;
	*lcc*) CPPMINUSOFLAG="-Fo";;
	*) CPPMINUSOFLAG="> ";;
esac

case $TARGET in
	*watcom*) CPPSUFFIX="P1";; # filter produces .P
	*) CPPSUFFIX="P";;
esac

#
# Linker and Suffices
# for objfiles and regular static libs
#

case $TARGET in
	*linux*) LD="gcc";;
	*sysv*uw*) LD="gcc";;
	*sco*) LD="gcc";;
	*sunos*) LD="gcc";;
	*solaris*) LD="gcc";;
	*aix*) LD="cc";;
	*watcom*) LD="wlink";;
	*msvc*) LD="link";;
	*lcc*) LD="lcclnk";;
	*djgpp*) LD="gcc";;
	*cygwin*) LD="gcc";;
	*mwcppc*) LD="MWLinkPPC";;
	*mwc68k*) LD="MWLink68K";;
	*ibmvac*) LD="icc";;
	*amigaos*) LD="gcc";;
	*beos*) LD="mwld";;
	*) LD="$CC";;
esac

Note LD = $LD

#
# Flags to be used with -dl (dynamic loading stuff)
#
# on HP-UX have to specify (with +I) list of initializers to call 
# also have to make all symbols exported to loaded modules (ld -E)
#
# on IRIX could set PICFLAG="" because manpage says PIC is default
# also use -init to add _init() to .init section
# (note that the IRIX dlopen() doesn't look in current dir for .so files)
#
# on WATCOM, we configure -dl for building WIN32 (NT) DLL's.
#

DLXLDARGS=""
DLXCCARGS=""
DLARGS="-bogus"
DLFILE="objcdlso.ld";
PICFLAG="-fpic"
STATICFLAG="-static"
PICOCARGS=""
OBJCRTEXPORT=""

# BROS's Comment
# please explain me meaning of all these flags so i could write right ones
#
case $TARGET in
	*freebsd*) DLARGS="-Bshareable";
		   ;;
	*netbsd*)  DLARGS="-Bshareable";
		   ;;
	*sysv*uw*|*sco*)
            case $CC in
               gcc)
                   DLARGS="-shared";
	           DLXLDARGS="-Xlinker --export-dynamic -ldl";
		   ;;
               cc)
                   DLARGS="-G";
                   PICFLAG="-KPIC"
                   STATICFLAG="-Bstatic"
                   ;;
            esac
            ;;
	*linux*)   DLARGS="-shared -lc"; # add -lc for debian per Marcel
	           DLXLDARGS="-rdynamic -ldl";
		   ;;
	*hpux*)    PICFLAG="+z";
	           DLARGS="-b +I _init";
		   DLXLDARGS="-Wl,-E -ldld";
		   STATICFLAG="-Wl,-a,archive";
	           ;;
	*osf*)     PICFLAG="";
	           DLARGS="-shared -init _init";
		   DLXLDARGS="";
		   STATICFLAG="-non_shared";
	           ;;
        *irix*)    DLXLDARGS="-lc";
	           DLARGS="-shared -init _init";
		   PICFLAG="-KPIC";
		   ;;
	*watcom*) PICFLAG="-bd -br";
		  PICOCARGS="-dllexport";
		  OBJCRTEXPORT="__declspec(dllexport)";
	          DLARGS="system nt_dll initinstance terminstance";
		  DLXCCARGS="-br";
		  DLFILE="objcdlnt.wat";
		  ;;
	*msvc*) PICFLAG="/LD";
		PICOCARGS="-dllexport";
		OBJCRTEXPORT="__declspec(dllexport)";
	        DLARGS="/DLL";
		DLXCCARGS="";
                DLFILE="objcdlnt.msv";
		;;
	*lcc*) PICFLAG="";
		PICOCARGS="-dllexport";
		OBJCRTEXPORT="__declspec(dllexport)";
	        DLARGS="-dll";
		DLXCCARGS="";
                DLFILE="objcdlnt.lcc";
		;;
	*) ;;
esac

Note DLARGS = $DLARGS
Note DLXCCARGS = $DLXCCARGS
Note DLXLDARGS = $DLXLDARGS
Note PICFLAG = $PICFLAG
Note PICOCARGS = $PICOCARGS

#
# default argument of -linkFormat of objc.exe and postlink.exe

case $TARGET in
	*watcom*) LINKFORMAT="watcom";;
	*msvc*) LINKFORMAT="msvc";;
	*lcc*) LINKFORMAT="msvc";;
	*mwc*) LINKFORMAT="mpw";;
	*beos*) LINKFORMAT="metrowerks";;
	*ibmvac*) LINKFORMAT="ibmvac";;
	*) LINKFORMAT="unix";; # bsdnm
esac

Note LINKFORMAT = $LINKFORMAT

case $TARGET in
	*watcom* | *lcc* | *msvc* | *ibmvac* )
                OBJSUFFIX="obj";
		LIBSUFFIX="lib";
                BINDOTSUFFIX=".exe";
	        AOUTNAME="a.exe";
		USELFLAG="0";;
	*cygwin*)
                OBJSUFFIX="o";
		LIBSUFFIX="a";
	        BINDOTSUFFIX=".exe";
	        AOUTNAME="a.exe";
		USELFLAG="1";;
	*mwc*)
                OBJSUFFIX="o";
		LIBSUFFIX="o";
	        BINDOTSUFFIX="";
	        AOUTNAME="a.out";
		USELFLAG="0";;
	*)
                OBJSUFFIX="o";
		LIBSUFFIX="a";
	        BINDOTSUFFIX="";
	        AOUTNAME="a.out";
		USELFLAG="1";;
esac

case $TARGET in
	*watcom* | *lcc* | *msvc* | *ibmvac* )
		DOTSHLIBSUFFIX="_s.lib";;
	*mwc*)
		DOTSHLIBSUFFIX=".o";;
	*freebsd*)
		DOTSHLIBSUFFIX=".so.2.1";;
	*hpux*)
		DOTSHLIBSUFFIX=".sl";;
	*)
		DOTSHLIBSUFFIX=".so";;
esac

Note OBJSUFFIX = $OBJSUFFIX
Note LIBSUFFIX = $LIBSUFFIX
Note DOTSHLIBSUFFIX = $DOTSHLIBSUFFIX
Note BINDOTSUFFIX = $BINDOTSUFFIX
Note AOUTNAME = $AOUTNAME

#
# C Flags.
# make debug uses DBG_MFLAGS and make optimized uses OPT_MFLAGS
# WEAKOPT_MFLAGS is used for *big* files like parse.m
#

if [ -z "$DBG_MFLAGS" ]; then
	case $CC in
		wcc*)	DBG_MFLAGS="$OTHER_MFLAGS -d2 -od";;
		icc*)	DBG_MFLAGS="$OTHER_MFLAGS -Ti";;
		*)	DBG_MFLAGS="$OTHER_MFLAGS -g";;
	esac
fi

Note DBG_MFLAGS = "$DBG_MFLAGS"

if [ -z "$OPT_MFLAGS" ]; then
	case $CC in
		gcc)	OPT_MFLAGS="$OTHER_MFLAGS -O2 -DNDEBUG";;
		wcc*)	OPT_MFLAGS="$OTHER_MFLAGS -DNDEBUG";;
		lcc*)	OPT_MFLAGS="$OTHER_MFLAGS -DNDEBUG";;
		mwcc)   OPT_MFLAGS="$OTHER_MFLAGS -O4 -DNDEBUG";;
		*)	OPT_MFLAGS="$OTHER_MFLAGS -O -DNDEBUG";;
	esac
fi

Note OPT_MFLAGS = $OPT_MFLAGS

# WEAKOPT_MFLAGS is used for *big* files like parse.m

if [ -z "$WEAKOPT_MFLAGS" ]; then
	WEAKOPT_MFLAGS="-DNDEBUG $OTHER_MFLAGS"
fi

Note WEAKOPT_MFLAGS = $WEAKOPT_MFLAGS

# MFLAGS can be OPT_MFLAGS or DBG_MFLAGS
# cheap way to do debug/non-debug builds (doing this in a
# portable way at the Makefile level is tricky)

if [ -z "$MFLAGS" ]; then
	MFLAGS="OPT_MFLAGS"
fi

Note MFLAGS = $MFLAGS	

#
# IFLAGS for the different components.  Useful to declare here
# because of DOS/UNIX issues and because of crosscompiles with
# other objc compilers.
#

UP="..$PATHSEP"

# when recompiling with objc itself, use new objcrt
# the portions that are incompatible with other rt's should be
# inside __PORTABLE_OBJC__

case $OBJCC in
        objc)   NOI="-noI";
		NOLIBS="-noLibs";
                OBJCRT_INC="-noI -I${UP}${UP}include${PATHSEP}objcrt";
		;;
	*)      NOI=""; 
		NOLIBS="";
		OBJCRT_INC="-I${UP}${UP}include${PATHSEP}objcrt";
		;;
esac 

OBJPAK_INC="-I${UP}${UP}include${PATHSEP}objpak"

#
#
# this pretty much summarizes dependencies between the components
# for instance : objcrt,objpak and cakit depend on nothing
# (except for objpak and cakit depending on an arbitrary
# Objective C runtime; objcrt expands to nothing if compiled with
# a different compiler than ours since it's #ifdef __PORTABLE_OBJC__)
#
# oclib depends on objpak and objc/objc1 depend on objpak
#

OBJCRT_IFLAGS="$NOI"
OBJPAK_IFLAGS="$OBJCRT_INC"
 OCLIB_IFLAGS="$OBJCRT_INC $OBJPAK_INC"
  OBJC_IFLAGS="-I. $OBJCRT_INC $OBJPAK_INC -I${UP}oclib"
 CAKIT_IFLAGS="-I. $OBJCRT_INC"

# objcrt.lib expands to empty if compiled with compiler != objc

OBJC_BOOTLIBS="${NOLIBS} ${UP}oclib${PATHSEP}oclib.${LIBSUFFIX}"
OBJC_BOOTLIBS="$OBJC_BOOTLIBS ${UP}objpak${PATHSEP}objpak.${LIBSUFFIX}"
OBJC_BOOTLIBS="$OBJC_BOOTLIBS ${UP}objcrt${PATHSEP}objcrt.${LIBSUFFIX}"

Note OBJCRT_IFLAGS = $OBJCRT_IFLAGS
Note OBJPAK_IFLAGS = $OBJPAK_IFLAGS
Note OCLIB_IFLAGS  = $OCLIB_IFLAGS
Note OBJC_IFLAGS   = $OBJC_IFLAGS
Note CAKIT_IFLAGS  = $CAKIT_IFLAGS
Note OBJC_BOOTLIBS = $OBJC_BOOTLIBS

#
# RANLIB and AR
#
# the way we do this (mostly because of the watcom wlib) is
# compile a file, replace it in the archive (assume that the archive is
# going to be created if not existing). then at the end, run RANLIB
#
# for BeOS (but other platforms also might want to use this)
# set FINAL_AR to be a 'ar' that archives all obj files, and set AR=echo
#
# if your platform doesn't fit any of these styles of ar/ranlib usage,
# consider writing a shell script or .bat file (such as arwat.bat)
#

if [ -z "$FINAL_AR" ]; then FINAL_AR='echo';fi

if [ -z "$RANLIB" ]; then
case $TARGET in
	*solaris*) RANLIB='ar -ts';AR='ar cr';;
	*irix*)    RANLIB='echo';AR='ar clr';;
	*sco*)    RANLIB='echo';AR='ar cr';;
	*sysv*uw*) RANLIB='echo';AR='ar cr';;
	*watcom*)  RANLIB='echo';AR='arwat';;
	*lcc*)     RANLIB='echo';AR='lcclib';;
	*msvc*)    RANLIB='echo';AR='lib /NOLOGO';;
	*mwc*)     RANLIB='echo';AR='echo';;
	*ibmvac*)  RANLIB='echo';AR='arvac';;
	*beos*)    RANLIB='echo';FINAL_AR='mwld -xml -o';AR='echo';;
	*)         RANLIB=ranlib;AR='ar cr';;
esac
fi

Note AR = $AR
Note FINAL_AR = $FINAL_AR
Note RANLIB = $RANLIB

#
# LEX
# There seems to be a problem with AIX lex and scan.l
# I haven't figured this out yet.
#
# stes 3/98: our lexical analyzer seems to have grown to big for DEC
# and HP-UX lex : use flex.
#
#
# YACC
#
# On SunOS4.1.1, yacc is emitting an "extern char *malloc()"
# Clashes with the GNU cc stdlib.h's malloc() definition.
# (it's possible to run "sed" on the generated file and remove the decl).
#
# Abraxas PCYACC : myacc -v -Dy.tab.h -Cy.tab.c
#
# On WATCOM, I'm using flex/bison (as found on http://www.winsite.com)
#
# Special flag added for yyless().  (for c++ gram) DEC lex doesn't have this
# (and presumably other lex'es as well - I think old flexes don't have this)
#

LEXYYC="lex.yy.c"

if [ -z "$LEX" ]; then
case $TARGET in
	*djgpp* | *watcom* | *msvc* | *lcc* )
		LEX=flex;
                # depends on which flex port you use
		LEXYYC="lexyy.c";
	;;
	*mwc*) genParser;LEX=echo;;
	*ibmvac*) LEX=flex;LEXYYC="lexyy.c";;
	*) LEX=flex;;
esac
fi

if [ -z "$OBJCRT_USE_YYLESS" ]; then
case $TARGET in
	*) OBJCRT_USE_YYLESS=1
esac
fi

YTABH="y.tab.h"
YTABC="y.tab.c"

if [ -z "$YACC" ]; then
case $TARGET in
	*watcom* | *djgpp* | *msvc* | *lcc* )
		YACC="bison -y -d";
                # depends on which bison port you use
		YTABH="y_tab.h";
		YTABC="y_tab.c";
	;;
	*mwc*) YACC="echo";;
# I advise to use 'byacc' as found e.g. on the Linux Slackware CD-ROM
# You can use 'bison', but expect problems with their use of alloca().
# In fact, there is one occasion where bison will not work, namely when
# you use -refcnt, in which case byacc works fine (because it fills an
# array with zeroes) while bison uses a alloca() allocated array filled
# with garbage bits ...
	*) YACC="byacc -d";;
esac
fi

Note LEX = $LEX
Note LEXYYC = $LEXYYC
Note YACC = $YACC
Note OBJCRT_USE_YYLESS= $OBJCRT_USE_YYLESS
Note YTABH = $YTABH
Note YTABC = $YTABC

#
# NM
# This is relevant to the postlink option where we need to process
# the output of "nm".  Unfortunately there's quite some difference in output.
#

case $TARGET in
	*hpux*) NM="nm -p";; # names are sometimes delimited by '|' otherwise
	*) NM=nm;;
esac

Note NM = $NM

#
# RM & CP
# This is called "del" on DOS.  Currently used in objc.m
# Use -p on UNIX to preserve time when copying libraries
#

case $TARGET in
	*watcom*) RM="del";;
	*lcc*) RM="del";;
	*msvc*) RM="del";;
	*djgpp*) RM="del";;
	*cygwin*) RM="rm -f";;
	*mwc*) RM="Delete";;
	*ibmvac*) RM="del";;
	*) RM="rm -f";;
esac

Note RM = $RM

case $TARGET in
	*mwc*) CAT="Catenate";;
	*) CAT="cat";;
esac

Note CAT = $CAT

case $TARGET in
	*watcom*) CP="copy";;
	*lcc*) CP="copy";;
	*msvc*) CP="copy";;
	*djgpp*) CP="copy";;
	*cygwin*) CP="cp -p";;
	*mwc*) CP="Duplicate";;
	*ibmvac*) CP="copy";;
	*) CP="cp -p";;
esac

Note CP = $CP

TAR="tar"

Note TAR = $TAR

case $TARGET in
	*linux*|*beos*) TARARGS="--exclude CVS";;
	*) TARARGS="";;
esac

Note TARARGS = $TARARGS

#
# MAKE
# I do my best to make it work with as many variants...
# (you should NOT have to install gmake for instance, on UNIX, although
# that it works of course)
# WATCOM : -u for UNIX, -c for not checking target built after cmds.
# (stes: removed -u and -c since it got messy trying to keep wmake
# makefiles the same as for unix)
#

# BROS's Comment
# We need to do something with makefiles format - nmake doesn't support UNIX-like
if [ -z "$MAKE" ]; then
case $TARGET in
	*watcom*) MAKE="wmake";;
	*lcc*) MAKE="make";; # lcc make is nmake compatible
	*msvc*) MAKE="nmake";;
	*ibmvac*) MAKE="gmake";;
	*) MAKE="make";;
esac
fi

Note MAKE = $MAKE

###############################################################################
#
#                              C O N F I G . H
#
###############################################################################

#
# define if #import <stdarg.h> instead of #import <varargs.h>
# SunOS4.1.1 has no stdarg.h 
#

case $TARGET in
*sunos*) OBJCRT_USE_STDARG="0";;
*) OBJCRT_USE_STDARG="1";;
esac
Note OBJCRT_USE_STDARG = $OBJCRT_USE_STDARG

#
# this is if we want to use fast clearing (memset)
# or copying (memcpy) of object instance memory 
# risk is that this pulls in some ugly asm() that breaks a compile
#

case $TARGET in
*freebsd*) OBJCRT_USE_MEMSET="1";;
*) OBJCRT_USE_MEMSET="0";;
esac
Note OBJCRT_USE_MEMSET = $OBJCRT_USE_MEMSET

#
# this is for a safe implementation of the String +sprintf: method
#

case $TARGET in
*) OBJCRT_USE_SNPRINTF="0";;
esac
Note OBJCRT_USE_SNPRINTF = $OBJCRT_USE_SNPRINTF

#
# whether the runtime vectors remap _alloc to oc_alloc etc.
# have to avoid name clash with NeXT libsys.a
# since they use the same names (_objcInit, _error etc.) as Stepstone
# if this is the case, then the driver should probably also set an init func.
#

if [ -z "$PREFIXEDNAMES" ]; then
  case $TARGET in
  *nextstep*) PREFIXEDNAMES=1;;
  *rhapsody*) PREFIXEDNAMES=1;;
  *)          PREFIXEDNAMES=0;;
  esac
fi

case $PREFIXEDNAMES in
0) OBJCRT_USE_PREFIXED_NAMES="0";INITCALL="_objcInit";;
1) OBJCRT_USE_PREFIXED_NAMES="1";INITCALL="oc_objcInit";;
esac

Note INITCALL = "$INITCALL"
Note OBJCRT_USE_PREFIXED_NAMES = $OBJCRT_USE_PREFIXED_NAMES

#
# always trouble with GNU extensions.
#

OBJCRT_LINUX="0"
OBJC_HAVE_SYSTEM_CALL="1"

case $TARGET in
*linux*) OBJCRT_LINUX="1";;
*mwc*)   OBJC_HAVE_SYSTEM_CALL="0";;
esac

Note OBJCRT_LINUX = $OBJCRT_LINUX
Note OBJC_HAVE_SYSTEM_CALL = $OBJC_HAVE_SYSTEM_CALL

#
# For cross-compiles with some Stepstone compilers we have
# OBJCRT_PROTOTYPE_MESSENGER=0, in order to use _their_ _imp().
#

case $STEPALLC in
y) OBJCRT_PROTOTYPE_MESSENGER="0";;
*) OBJCRT_PROTOTYPE_MESSENGER="1";;
esac
Note OBJCRT_PROTOTYPE_MESSENGER = $OBJCRT_PROTOTYPE_MESSENGER

###############################################################################
#
#                          D R I V E R   S C R I P T
#
###############################################################################

# Linux doesn't seem to have an xstr
# I turned it off anyhow, for the problem of libraries and duplicate xs.o

case $TARGET in
*linux*)	RUNXSTR=n;;
*)		RUNXSTR=n;;
esac

#
# OC_OCARGS flags passed to objc1
#
# -postlink: don't generate OCU entries 
# (note: -postlink is now added to OCARGS by the driver if POSTLINK=1)
#
# -shortTag : use # (a la gcc) instead of #line 
#  (NOTE: this was originally -longlinetag, the default changed)
#
# -inlinecache : enable the inline cache messenger
# -linemax x : break long strings (such as pragmas)
#
# on HPUX have to emit #line instead of #
# for the IRIX 6.2 MIPSpro 7.0.1 have to emit #line instead of #
# on UNIXWARE with USL cc have to emit # and not #line
#
# -watcom : __int64 (we could actually do this better now with -builtintype)
#
# Metrowerks : -refBind force a reference to OBJCBIND in each module 
# (this reference causes a warning on some compilers, e.g. lcc, so we don't
# do this everywhere)
# -msdos : for pascal keyword (this is a quick work-around)
#
# DEC Alpha: has a header which defines an asm() function.
#

# BROS's Comment
# VC has __int64 type; dunno what to write here for MSVC ;-)
#
case $TARGET in
	*watcom* | *msvc* | *lcc*) 
	          OC_OCARGS="-gnu -msdos -watcom -linemax 127";
		  ;;
	*mwc*) OC_OCARGS="-msdos -refBind";;
# USL cc requires short tag
	*unixware*|*sco*|*sysv*uw*) OC_OCARGS="-shortTags";;
	*hpux*) OC_OCARGS="-gnu";;
	*unicos*) OC_OCARGS="-gnu";;
	*irix*) OC_OCARGS="-gnu";;
	*osf*) OC_OCARGS="-noasm -gnu";;
	*ibmvac*) OC_OCARGS="-ibmvac";;
	*beos*) OC_OCARGS="-msdos -watcom -refBind";;
	*) OC_OCARGS="-gnu";;
esac

Note OC_OCARGS = "$OC_OCARGS"

# all UNIX compilers support -postlink, but are configured
# by default for auto-initialization.  not possibly on WATCOM
# since it has no flag for common global storage.
#
# djgpp COULD be made to work I think with auto-init but currently
# it's crashing (haven't looked into it yet).  Works with postlink
# (using the gawk port).
# PS: this got fixed in objc1.3.18 - djgpp (correctly) was not zero'ing
# some malloc'ed memory
#

# MSVC port
# BROS's Comment (MSVC)
# In your porting doc some check procedure is written.
# I tried it and it works.
# So, maybe we don't need to make postlink.

#
# We'd probaby want to migrate the SGI cc also to POSTLINK '1'.
#

if [ -z "$POSTLINK" ]; then
  POSTLINK=0;
  case $TARGET in
	  *watcom*) POSTLINK=1;;
	  *mwc*) POSTLINK=1;;
	  *beos*) POSTLINK=1;;
	  *) ;;
  esac
fi

Note POSTLINK = "$POSTLINK"

case $POSTLINK in
1) OBJCRT_SCOPE_OBJCMODULES_EXTERN="1";;
0) OBJCRT_SCOPE_OBJCMODULES_EXTERN="0";;
esac

Note OBJCRT_SCOPE_OBJCMODULES_EXTERN = $OBJCRT_SCOPE_OBJCMODULES_EXTERN

case $TARGET in
	*mwc*) PRINTFSYSTEM=1;;
	*) PRINTFSYSTEM=0;;
esac

Note PRINTFSYSTEM = "$PRINTFSYSTEM"

case $TARGET in
	*watcom*) SHORTCMDLINE=1;;
	*djgpp*)  SHORTCMDLINE=1;;
	*) SHORTCMDLINE=0;;
esac

Note SHORTCMDLINE = "$SHORTCMDLINE"

#
# WATCOM linker is pretty weird.
# We need to give it a "map" option to generate a "nm" file for use
# in postlink.
# We presumably also depend on lower/upper case differentation...
#
# mwcppc linker likes to strip dead code, in particular OBJCBIND.
# can be solved with -exportBind and -export pragma, but there is a
# smarter trick inplace now which causes a reference to OBJCBIND in 
# _selTransTbl.

case $TARGET in
        *watcom*) OC_LDARGS="option quiet option caseexact";;
	*msvc*) OC_LDARGS="/machine:IX86 /subsystem:console";;
	*) OC_LDARGS="";;
esac

case $TARGET in
	*watcom*) PLLDARGS="option map=postlink.map";;
	*lcc*) PLLDARGS="-map postlink.map";;
	*mwc*) PLLDARGS="-map postlink.map";;
	*msvc*) PLLDARGS="/MAP:postlink.map";;
	*beos*) PLLDARGS="-map postlink.map";;
	*ibmvac*) PLLDARGS="-Fmpostlink.map";;
	*) PLLDARGS="";;
esac

case $TARGET in
	*watcom*) LDMINUSOFLAG="-fo=";;
	*msvc*) LDMINUSOFLAG="/OUT:";;
	*ibmvac*) LDMINUSOFLAG="-Fe";;
	*) LDMINUSOFLAG="-o ";;
esac

Note OC_LDARGS = "$OC_LDARGS"
Note PLLDARGS = "$PLLDARGS"

#
# OC_CCARGS flags for $CC as invoked from objc
# cc -E is invoked with CCARGS and in addtion to that, with CPARGS
#

case $TARGET in

# the IRIX compiler ABSOLUTELY needs -common for the relaxed ansi
# linker model, where uninitialized variables are not immediately placed
# in the bss segment.  If you, for some reason, do not want this, you
# have to configure the driver for POSTLINK=1 instead.
#
# removed -ansi flag for warning about LONGLONG on 64bit MIPSpro cc
*irix*) OC_CCARGS="-common -ansi";;
#*irix6*) OC_CCARGS="-common -64";;

# ansi mode is absolutely needed for the HP-UX (doesn't know about const etc.)
*hpux*)	OC_CCARGS="-Aa";;

# -std is "popular ansi".  we presumably don't want -std1 for OCU entries.
*osf*)	OC_CCARGS="-std";;

# this obscure flag needed for defining alloca and compiling bison output
*unixware*|*sco*|*sysv*uw*) 
   case $CC in
      cc*) OC_CCARGS="-W0,-2A1";;
      gcc*) ;;
   esac
   ;;

# -ansi : Robey had a header file type problem and had to add -ansi.
# on 2.1.7 everything seems to go okay.
# (robey reports the problem was some occurence of __signed)
*freebsd*)	OC_CCARGS="";;
*netbsd*)	OC_CCARGS="";;

# suppress copyright with -zq
*watcom*)   OC_CCARGS="-zq";;

# BROS comment
# suppress copyright and choose Blend code generation
*msvc*)   OC_CCARGS="/nologo /GB";;

# suppress copyright choose Pentium Code generation
*ibmvac*)   OC_CCARGS="-G5 -Q";;

*)	OC_CCARGS="";;
esac

Note OC_CCARGS = "$OC_CCARGS"

#
# OC_CPARGS should be the flags that are needed so that objc can compile
# regular C programs (#include's of system headers)
#

case $TARGET in
*nextstep* | *rhapsody* )
# the -D__STRICT_ANSI__ is necessary to parse string.h
# -traditional-cpp is needed for the cc -E interface
OC_CPARGS="-D__STDC__ -D__STRICT_ANSI__ -traditional-cpp" 
;;
# flag to make <> includes work
*mwc*)
OC_CPARGS="-nosyspath"
;;
*)
OC_CPARGS=""
;;
esac


#if we're configuring for gcc, can as well support import and line comments
#don't do this on djgpp
#in addition we can't do this for C++ (don't wnt an -x flag)
#case $CC in
#	gcc)	OC_CPARGS="$CPPIMPORTFLAG $OC_CPARGS";;
#	*)	;;
#esac

#always include the POC define
#and we can use this define as the "official" OC switch

case $TARGET in
	*mwc*) OC_CPARGS="-d __PORTABLE_OBJC__ $OC_CPARGS";;
	*) OC_CPARGS="-D__PORTABLE_OBJC__ $OC_CPARGS";;
esac

Note OC_CPARGS = "$OC_CPARGS"

###############################################################################
#
#                                  S E D
#
###############################################################################

#
# Parameters to rewrite in files like Makefile.in.
#
# stes 11/97 : use Makefile.wmk as input for watcom, use Makefile.nmk
# as input for Microsoft nmake.
#

DATE=`date`

cat>>$CONFSED<<EOF
/@AR@/s;;${AR};g
/@AOUTNAME@/s;;${AOUTNAME};g
/@MFLAGS@/s;;${MFLAGS};g
/@DBG_MFLAGS@/s;;${DBG_MFLAGS};g
/@OPT_MFLAGS@/s;;${OPT_MFLAGS};g
/@WEAKOPT_MFLAGS@/s;;${WEAKOPT_MFLAGS};g
/@OBJCRT_IFLAGS@/s;;${OBJCRT_IFLAGS};g
/@OBJPAK_IFLAGS@/s;;${OBJPAK_IFLAGS};g
/@OCLIB_IFLAGS@/s;;${OCLIB_IFLAGS};g
/@OBJC_IFLAGS@/s;;${OBJC_IFLAGS};g
/@CAKIT_IFLAGS@/s;;${CAKIT_IFLAGS};g
/@OBJC_BOOTLIBS@/s;;${OBJC_BOOTLIBS};g
/@OC_CPARGS@/s;;${OC_CPARGS};g
/@OC_OCARGS@/s;;${OC_OCARGS};g
/@OC_CCARGS@/s;;${OC_CCARGS};g
/@OC_LDARGS@/s;;${OC_LDARGS};g
/@PLLDARGS@/s;;${PLLDARGS};g
/@LD@/s;;${LD};g
/@DLARGS@/s;;${DLARGS};g
/@DLFILE@/s;;${DLFILE};g
/@PICFLAG@/s;;${PICFLAG};g
/@STATICFLAG@/s;;${STATICFLAG};g
/@PICOCARGS@/s;;${PICOCARGS};g
/@DLXCCARGS@/s;;${DLXCCARGS};g
/@DLXLDARGS@/s;;${DLXLDARGS};g
/@CC@/s;;${CC};g
/@CCPLUS@/s;;${CCPLUS};g
/@CPP@/s;;${CPP};g
/@NM@/s;;${NM};g
/@CP@/s;;${CP};g
/@TAR@/s;;${TAR};g
/@TARARGS@/s;;${TARARGS};g
/@RM@/s;;${RM};g
/@CAT@/s;;${CAT};g
/@LEX@/s;;${LEX};g
/@LEXYYC@/s;;${LEXYYC};g
/@YACC@/s;;${YACC};g
/@YTABH@/s;;${YTABH};g
/@YTABC@/s;;${YTABC};g
/@MAKE@/s;;${MAKE};g
/@SET_MAKE@/s;;MAKE=${MAKE};g
/@OBJC@/s;;${OBJCC};g
/@XOBJC@/s;;${XOBJCC};g
/@RANLIB@/s;;${RANLIB};g
/@FINAL_AR@/s;;${FINAL_AR};g
/@TARGET@/s;;${TARGET};g
/@RUNXSTR@/s;;${RUNXSTR};g
/@POSTLINK@/s;;${POSTLINK};g
/@SHORTCMDLINE@/s;;${SHORTCMDLINE};g
/@CPPFILTER@/s;;${CPPFILTER};g
/@OBJC1FILTER@/s;;${OBJC1FILTER};g
/@NAME@/s;;${NAME};g
/@TARGET@/s;;${TARGET};g
/@INITCALL@/s;;${INITCALL};g
/@IISUFFIX@/s;;${IISUFFIX};g
/@OBJSUFFIX@/s;;${OBJSUFFIX};g
/@CPPSUFFIX@/s;;${CPPSUFFIX};g
/@LIBSUFFIX@/s;;${LIBSUFFIX};g
/@USELFLAG@/s;;${USELFLAG};g
/@DOTSHLIBSUFFIX@/s;;${DOTSHLIBSUFFIX};g
/@BINDOTSUFFIX@/s;;${BINDOTSUFFIX};g
/@PATHSEP@/s;;${PATHSEP};g
/@PATHSEPC@/s;;${PATHSEPC};g
/@GCPREFIX@/s;;${GCPREFIX};g
/@GCPREFIXC@/s;;${GCPREFIXC};g
/@INSTALLDIR@/s;;${INSTALLDIR};g
/@INSTALLDIRC@/s;;${INSTALLDIRC};g
/@WARNING@/s;;DO NOT EDIT -- configure ${NAME} ${TARGET};g
/@OBJCRTEXPORT@/s;;${OBJCRTEXPORT};g
/@OBJCRT_LINUX@/s;;${OBJCRT_LINUX};g
/@OBJC_HAVE_SYSTEM_CALL@/s;;${OBJC_HAVE_SYSTEM_CALL};g
/@OBJCRT_USE_STDARG@/s;;${OBJCRT_USE_STDARG};g
/@OBJCRT_USE_MEMSET@/s;;${OBJCRT_USE_MEMSET};g
/@OBJCRT_USE_SNPRINTF@/s;;${OBJCRT_USE_SNPRINTF};g
/@OBJCRT_USE_PREFIXED_NAMES@/s;;${OBJCRT_USE_PREFIXED_NAMES};g
/@OBJCRT_USE_YYLESS@/s;;${OBJCRT_USE_YYLESS};g
/@OBJCRT_PROTOTYPE_MESSENGER@/s;;${OBJCRT_PROTOTYPE_MESSENGER};g
/@OBJCRT_SCOPE_OBJCMODULES_EXTERN@/s;;${OBJCRT_SCOPE_OBJCMODULES_EXTERN};g
/@LINKFORMAT@/s;;${LINKFORMAT};g
/@PRINTFSYSTEM@/s;;${PRINTFSYSTEM};g
/@CPPMINUSOFLAG@/s;;${CPPMINUSOFLAG};g
/@CCDOLLARFLAG@/s;;${CCDOLLARFLAG};g
/@CPPIMPORTFLAG@/s;;${CPPIMPORTFLAG};g
/@CCMINUSCFLAG@/s;;${CCMINUSCFLAG};g
/@CCMINUSOFLAG@/s;;${CCMINUSOFLAG};g
/@LDMINUSOFLAG@/s;;${LDMINUSOFLAG};g
/@CCMINUSIFLAG@/s;;${CCMINUSIFLAG};g
/@CCMINUSDFLAG@/s;;${CCMINUSDFLAG};g
EOF

#
# Rewrite files.
#

SedConfigFiles()
{
    SUF=$1;
    shift
    for F do
	G=$F.$SUF
	if [ -f $G ]; then
		Note "Creating $F from $G"
		if sed -f $CONFSED $G >$F; then
			if [ -x $G ]; then
				chmod 755 $F;
				Note "Making $F executable"
			else
				chmod 644 $F
			fi
		else
			Error "Problem running sed -f $CONFSED $G"
			exit 1 # don't remove $JUNK
		fi
	else
		Error "$TOPDIR/$G is missing"
	fi
    done
}

if [ $MAKEONLY = 0 ]; then
case $BOOTSTRAP in
0)
SedConfigFiles in Makefile makeLibs src/objc/objc src/objc/objc.mpw src/objc/objc.m config.h
;;
1)
SedConfigFiles in objc
;;
esac
fi

case $TARGET in
*watcom*) SUF=wmk;; # WATCOM wmake
*lcc*) SUF=lcc;; # LCC make (a la nmake)
*msvc*) SUF=nmk;; # Microsoft nmake
*mwc*) SUF=mpw;; # MPW make
*ibmvac*) SUF=vac;; # IBM VisualAge nmake
*) SUF=in;; # UNIX make
esac

case $BOOTSTRAP in
0)
SedConfigFiles $SUF src/objc/Makefile src/oclib/Makefile src/objpak/Makefile src/objcrt/Makefile src/cakit/Makefile words/Makefile examples/Makefile
cp config.h src/objcrt
cp config.h src/objpak
cp config.h src/oclib
cp config.h src/objc
cp config.h src/cakit 
touch src/objc/objc1.m
# let's put this here to avoid "make install" catastrophes
Note PATHSEP = "$PATHSEP"
Note PATHSEPC = "$PATHSEPC"
Note INSTALLDIR = "$INSTALLDIR"
;;
1)
SedConfigFiles $SUF Makefile 
;;
esac

#
# clean exit
#

rm -f $JUNK
exit 0
