dnl
dnl autoconf source file for objc-2.x.x configure script
dnl $Id: configure.in,v 1.31 1999/08/27 18:32:50 stes Exp $
dnl
dnl note: we're in the process of converting the old configure script
dnl (configure.orig) to an autoconf script

AC_INIT()

dnl normally we check for _objcInit() (to see if it's not in the syslibs)
dnl if it is, we should be using some other prefixed name (oc_objcInit)

AC_ARG_WITH(prefixed-names,
  [  --with-prefixed-names        use oc_objcInit as initialization function],
  [ac_cv_prefixed_names=$withval]
)

dnl runtime initialization options are import
dnl see documentation (manual) for more info on postlink init vs. automatic
dnl initialization

AC_ARG_WITH(postlink,
  [  --with-postlink              use postlink runtime initialization],
  [ac_cv_postlink=$withval]
)

dnl the cplus stuff is not terribly important, allow to disable it
dnl (it works with a couple of compilers, such as g++, mwcc -cplus, SGI CC)

AC_ARG_WITH(cplus,
  [  --with-cplus                 find a c++ compiler (to make -cplus work)],
  [ac_cv_cplus=$withval],
  [ac_cv_cplus=no]
)

AC_CONFIG_AUX_DIR(util)
AC_CANONICAL_SYSTEM

TARGET=$target;AC_SUBST(TARGET)
NAME=objc-2.3.16;AC_SUBST(NAME)
WARNING="DO NOT EDIT -- configure ${NAME} ${TARGET}";AC_SUBST(WARNING)

dnl the following is for compatibility with the old configure script

case "x$prefix" in
  xNONE) INSTALLDIR=$ac_default_prefix;;
  *) INSTALLDIR="$prefix"
esac
AC_SUBST(INSTALLDIR)
INSTALLDIRC="$INSTALLDIR";AC_SUBST(INSTALLDIRC)
GCPREFIX="$INSTALLDIR";AC_SUBST(GCPREFIX)
GCPREFIXC="$INSTALLDIR";AC_SUBST(GCPREFIXC)

PATHSEP=/;AC_SUBST(PATHSEP)
PATHSEPC=/;AC_SUBST(PATHSEPC)

AC_PROG_MAKE_SET

if test -f BOOTSTRAP
then
btrap=1
else
btrap=0
fi

AC_CHECK_PROG(OBJC,objc,objc -q)
case $btrap in
0)	if test -z "$OBJC"
	then
	  AC_MSG_ERROR(Can't find bootstrap compiler)
	fi
	;;
1)	;;
esac

dnl for compiling in src/objc, must specify full path
AC_PATH_PROG(XOBJC,objc,objc -q)

AC_PROG_CC
AC_PROG_CPP

case $ac_cv_prog_gcc in
 yes) CPPWANTSDOTC=0;;
 *) CPPWANTSDOTC=1;;
esac
AC_SUBST(CPPWANTSDOTC)

case $ac_cv_cplus in
yes)
AC_PROG_CXX
;;
no)
;;
esac

CCPLUS=$CXX;AC_SUBST(CCPLUS)
IISUFFIX=cc;AC_SUBST(IISUFFIX)
CCMINUSDFLAG='-D';AC_SUBST(CCMINUSDFLAG)
CCMINUSIFLAG='-I';AC_SUBST(CCMINUSIFLAG)
CCMINUSCFLAG='-c ';AC_SUBST(CCMINUSCFLAG)
CCMINUSOFLAG='-o ';AC_SUBST(CCMINUSOFLAG)
CPPMINUSOFLAG='> ';AC_SUBST(CPPMINUSOFLAG)
CPPSUFFIX='P';AC_SUBST(CPPSUFFIX)
CPPFILTER='';AC_SUBST(CPPFILTER)
OBJC1FILTER='';AC_SUBST(OBJC1FILTER)

CPPIMPORTFLAG="";
CCDOLLARFLAG="";

case $ac_cv_prog_gcc in
 yes) 
  CPPIMPORTFLAG="-x objective-c -Wno-import";
  CCDOLLARFLAG="-fdollars-in-identifiers";
  ;;
 *)
  case $target in
   *irix*)
    CPPIMPORTFLAG="-acpp -Wp,-+";
    CCDOLLARFLAG="-dollar";
    ;; 
   *sco*|*unixware*|*svrv*uw*)
    CCDOLLARFLAG="-Kdollar";
    ;; 
  esac
  ;;
esac

AC_SUBST(CCDOLLARFLAG)
AC_SUBST(CPPIMPORTFLAG)

dnl BeOS for PowerPC has a weird linker (on Intel they use something else)
case $target in
  *beos*)
    AC_CHECK_PROG(LD,mwld,mwld,[$CC])
    ;;
  *) 
    LD=$CC
    AC_SUBST(LD)
    ;;
esac
RUNXSTR=n;AC_SUBST(RUNXSTR)
LDMINUSOFLAG='-o ';AC_SUBST(LDMINUSOFLAG)
case $target in
# cpp broken on nextstep
 *nextstep*|*rhapsody*) OC_CPARGS="-traditional-cpp";;
 *) OC_CPARGS='';;
esac

OC_CPARGS="-D__PORTABLE_OBJC__ $OC_CPARGS"
AC_SUBST(OC_CPARGS)

OC_CCARGS=''
AC_SUBST(OC_CCARGS)

dnl again some old stuff
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";;
# since -gnu extensions are enabled by default, we'd better remove this switch
	*) OC_OCARGS="-gnu";;
esac
AC_SUBST(OC_OCARGS)
OC_LDARGS='';
AC_SUBST(OC_LDARGS)
case $LD in
  mwld) PLLDARGS='-map postlink.map';;
  *) PLLDARGS='';;
esac
AC_SUBST(PLLDARGS)

AC_CHECK_PROG(RM,rm,rm -f,del)
AC_CHECK_PROG(CP,cp,cp -p,copy)
AC_CHECK_PROG(CAT,cat,cat,Catenate)
AC_CHECK_PROG(MKDIR,mkdir,mkdir,mkdir)
AC_CHECK_PROG(TAR,tar,tar)
TARARGS='';AC_SUBST(TARARGS)
AC_CHECK_PROG(AR,ar,ar cr,:)
dnl BeOS for PPC has a mwld -xml which is not a real 'ar'
case $target in
 *beos*)
   AC_CHECK_PROG(FINAL_AR,mwld,mwld -xml -o,:)
   ;;
 *)
   FINAL_AR='echo'
   AC_SUBST(FINAL_AR)
   ;;
esac
AC_PROG_RANLIB

dnl stuff from the days we were using configure on win95 too
LIBSUFFIX=a;AC_SUBST(LIBSUFFIX)
OBJSUFFIX=o;AC_SUBST(OBJSUFFIX)
AOUTNAME=a.out;AC_SUBST(AOUTNAME)
BINDOTSUFFIX='';AC_SUBST(BINDOTSUFFIX)
USELFLAG=1;AC_SUBST(USELFLAG)

dnl flags for compiling the compiler
MFLAGS=OPT_MFLAGS;AC_SUBST(MFLAGS)
case $ac_cv_prog_gcc in
  yes) OPT_MFLAGS='-DNDEBUG -O2';;
  *) OPT_MFLAGS='-DNDEBUG';;
esac
AC_SUBST(OPT_MFLAGS)
DBG_MFLAGS='-DDEBUG -g';AC_SUBST(DBG_MFLAGS)

UP="..$PATHSEP"
case $OBJC 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"

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"

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}"

AC_SUBST(OBJCRT_IFLAGS)
AC_SUBST(OBJPAK_IFLAGS)
AC_SUBST(OCLIB_IFLAGS)
AC_SUBST(OBJC_IFLAGS)
AC_SUBST(CAKIT_IFLAGS)
AC_SUBST(OBJC_BOOTLIBS)

dnl Since the quality of the POC depends on lex/yacc, we require flex/byacc
dnl Most lexes, yaccs and bison also work (but: byacc is required for -refcnt)
AC_CHECK_PROG(LEX,flex,flex)
if test -z "$LEX"
then
  AC_MSG_ERROR(Can't find flex)
fi
AC_CHECK_PROG(YACC,byacc,byacc -d)
if test -z "$YACC"
then
  AC_MSG_ERROR(Can't find Berkeley yacc (byacc))
fi
LEXYYC=lex.yy.c; AC_SUBST(LEXYYC)
YTABH=y.tab.h; AC_SUBST(YTABH)
YTABC=y.tab.c; AC_SUBST(YTABC)

dnl this should be cleaned up
dnl a general test for bsd format of 'nm' would be nice
case $target in
	*hpux*) 
NM='nm -p';AC_SUBST(NM)
;;
	*)
AC_CHECK_PROG(NM,nm,nm)
;;
esac

dnl
dnl the shared library stuff is messy
dnl it doesn't depend on tests, but rather checks the $target variable
dnl (enumeration of supported platforms as opposed to trying to figure out
dnl automagically how to build shlibs on the target)
dnl
DLXLDARGS=""
DLXCCARGS=""
DLARGS="-bogus"
DLFILE="objcdlso.ld";
PICFLAG="-fpic"
STATICFLAG="-static"
PICOCARGS=""
OBJCRTEXPORT=""
case $target in
	*watcom* | *lcc* | *msvc* | *ibmvac* )
		DOTSHLIBSUFFIX="_s.lib";;
	*mwc*)
		DOTSHLIBSUFFIX=".o";;
	*freebsd*)
		DOTSHLIBSUFFIX=".so.2.1";;
	*hpux*)
		DOTSHLIBSUFFIX=".sl";;
	*)
		DOTSHLIBSUFFIX=".so";;
esac
case $target in
	*freebsd*) DLARGS="-Bshareable";
		   ;;
	*netbsd*)  DLARGS="-Bshareable";
		   ;;
	*sysv*uw*|*sco*)
            case $ac_cv_prog_gcc in
               yes)
                   DLARGS="-shared";
	           DLXLDARGS="-Xlinker --export-dynamic -ldl";
		   ;;
               no)
                   DLARGS="-G";
                   PICFLAG="-KPIC"
                   STATICFLAG="-Bstatic"
                   ;;
            esac
            ;;
	*linux*)   DLARGS="-shared -lc"; # add -lc for debian per Marcel
	           DLXLDARGS="-rdynamic -ldl";
		   ;;
	*hpux*)
            case $ac_cv_prog_gcc in
	       yes)
	           DLARGS="-shared";
	           DLXLDARGS="-Wl,-E -ldld";
		   ;;
               no)
	           PICFLAG="+z";
	           DLARGS="-b +I _init";
		   DLXLDARGS="-Wl,-E -ldld";
		   STATICFLAG="-Wl,-a,archive";
	       ;;
            esac
	    ;;
	*osf*)
            case $ac_cv_prog_gcc in
	       yes)
	           DLARGS="-shared";
		   ;;
               no)
	           PICFLAG="";
	           DLARGS="-shared -init _init";
		   DLXLDARGS="";
		   STATICFLAG="-non_shared";
	           ;;
            esac
            ;;
        *irix*)
            case $ac_cv_prog_gcc in
	       yes)
	           DLARGS="-shared";
		   ;;
              no)
                   DLXLDARGS="-lc";
	           DLARGS="-shared -init _init";
		   PICFLAG="-KPIC";
		   ;;
            esac
            ;;
	*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

AC_SUBST(DOTSHLIBSUFFIX)
AC_SUBST(DLARGS)
AC_SUBST(DLXCCARGS)
AC_SUBST(DLXLDARGS)
AC_SUBST(PICFLAG)
AC_SUBST(PICOCARGS)
AC_SUBST(STATICFLAG)
AC_SUBST(DLFILE)
AC_SUBST(OBJCRTEXPORT)

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

AC_SUBST(LINKFORMAT)

AC_HEADER_STDC
AC_CHECK_HEADERS(string.h stdarg.h)

AC_PROG_CC_C_O
AC_C_CONST

AC_CHECK_FUNCS(memcpy memset snprintf)

dnl some old crap

OBJCRT_USE_YYLESS=1
AC_SUBST(OBJCRT_USE_YYLESS)
PRINTSYSTEM=0
AC_SUBST(PRINTFSYSTEM)
SHORTCMDLINE=0
AC_SUBST(SHORTCMDLINE)
OBJCRT_PROTOTYPE_MESSENGER=1
AC_SUBST(OBJCRT_PROTOTYPE_MESSENGER)
case $ac_cv_header_stdarg_h in
  yes) OBJCRT_USE_STDARG=1;;
  *) OBJCRT_USE_STDARG=0;;
esac
AC_SUBST(OBJCRT_USE_STDARG)
case $ac_cv_func_memset in
  yes) OBJCRT_USE_MEMSET=1;;
  *) OBJCRT_USE_MEMSET=0;;
esac
AC_SUBST(OBJCRT_USE_MEMSET)
case $ac_cv_func_snprintf in
  yes) OBJCRT_USE_SNPRINTF=1;;
  *) OBJCRT_USE_SNPRINTF=0;;
esac
AC_SUBST(OBJCRT_USE_SNPRINTF)
case $target in
  *linux*) OBJCRT_LINUX=1;;
  *) OBJCRT_LINUX=0;;
esac
AC_SUBST(OBJCRT_LINUX)
OBJC_HAVE_SYSTEM_CALL=1;AC_SUBST(OBJC_HAVE_SYSTEM_CALL)


dnl
dnl Testing for public storage model of C compiler 
dnl (common storage or strict definition reference)
dnl

AC_MSG_CHECKING(whether to use postlink)
AC_CACHE_VAL(ac_cv_postlink,[
t1="x$$.c"
t2="y$$.c"
e1="x$$"
e2="y$$"
ac_clean_files="$e1 $e2 $t1 $t2"

cat >$t1 <<EOF
int a = 7;
EOF

cat >$t2 <<EOF
#include <stdio.h>
int a;
int main() { exit(a);return a; }
EOF

echo "$CC $t1 $t2 -o $e1" >&5
($CC $t1 $t2 -o $e1) 2>&5 1>&5
echo "$CC $t2 $t1 -o $e2" >&5
($CC $t2 $t1 -o $e2) 2>&5 1>&5

if test -x $e1 -a -x $e2
then
  echo -n "check whether $e1 returns '7'" >&5
  if $srcdir/$e1 != 7
  then
    echo " (no)" >&5
    ac_cv_postlink=yes;
  else
    echo " (yes)" >&5
    echo -n "check whether $e2 returns '7'" >&5
    if $srcdir/$e2 != 7
    then
     echo " (no)" >&5
     ac_cv_postlink=yes
    else
     echo " (yes)" >&5
     ac_cv_postlink=no;
    fi
  fi
else
  ac_cv_postlink=yes;
fi
],ac_cv_postlink=yes,ac_cv_postlink=no)
AC_MSG_RESULT($ac_cv_postlink)

case $ac_cv_postlink in
  no) POSTLINK=0;OBJCRT_SCOPE_OBJCMODULES_EXTERN=0;;
  yes) POSTLINK=1;OBJCRT_SCOPE_OBJCMODULES_EXTERN=1;;
  *) AC_MSG_ERROR(you must use --with-postlink or --without-postlink);;
esac
AC_SUBST(POSTLINK)
AC_SUBST(OBJCRT_SCOPE_OBJCMODULES_EXTERN)

dnl
dnl Testing for system libs that contain _objcInit
dnl _objcInit is the name that Stepstone used to use for the runtime init
dnl and we use the same name.
dnl this is fine, except for the case where some vendors compile _objcInit
dnl into their system libs, so that we have to be careful to use *our* init
dnl

if test -z "$ac_cv_prefixed_names"
then
AC_CHECK_FUNC(_objcInit,ac_cv_prefixed_names=yes,ac_cv_prefixed_names=no)
else
AC_MSG_CHECKING(for _objcInit)
AC_MSG_RESULT((cached) $ac_cv_prefixed_names)
fi

case $ac_cv_prefixed_names in
yes) OBJCRT_USE_PREFIXED_NAMES="1";INITCALL="oc_objcInit";;
no) OBJCRT_USE_PREFIXED_NAMES="0";INITCALL="_objcInit";;
esac
AC_SUBST(OBJCRT_USE_PREFIXED_NAMES)
AC_SUBST(INITCALL)

case $btrap in
1)	list='Makefile objc'
	;;
0)	list='config.h Makefile makeLibs src/objcrt/config.h src/objcrt/Makefile src/objpak/config.h src/objpak/Makefile src/oclib/config.h src/oclib/Makefile src/objc/config.h src/objc/Makefile src/objc/objc src/objc/objc.m src/cakit/config.h src/cakit/Makefile examples/Makefile words/Makefile'
	;;
esac

AC_OUTPUT($list)

if test -f BOOTSTRAP
then
chmod a+x objc
else
chmod a+x makeLibs src/objc/objc
fi

