dnl Hey Emacs, I want this in -*- sh -*- mode, please.
dnl ---
dnl Copyright 1988-92, 1994-95, 1999, 2000 Free Software Foundation, Inc.
dnl Please see COPYING for a description your rights and responsibilities
dnl with this software.
dnl Process this file with autoconf to produce a configure script.

AC_REVISION($Revision: 1.7.5$)
AC_INIT(main.c)
AC_PREREQ(2.12)
AC_CONFIG_HEADER(gstconf.h:gstconf.hin)

VERSION=1.7.5
MAINTAINER="bonzini@gnu.org"
echo "GNU Smalltalk Version $VERSION"

# Make srcdir an *absolute* path -- e.g. not . but /home/bonz/gst/src
# this is not very orthodox, but it makes directories be represented the same
# way in all subtrees: otherwise, for example, if srcdir is ., ac_aux_dir
# is . too and $ac_aux_dir/missing would be invalid when processing
# lib/Makefile!
currentdir=`pwd`
cd $srcdir
srcdir=`pwd`
cd $currentdir
currentdir=

dnl ------------------------------- VERSION -------------------

# Split the version number
[
  ST_MAJOR_VERSION=`echo $VERSION| sed "s%\\..*%%g"`
  if test `echo $VERSION| sed "s%[^.]%%g"` = ".."; then
    ST_MINOR_VERSION=`echo $VERSION| sed "s%.*\\.\\(.*\\)\\..*%\\1%g"`
    ST_EDIT_VERSION=`echo $VERSION| sed "s%.*\\.%%g"`
  else
    ST_MINOR_VERSION=`echo $VERSION| sed "s%.*\\.%%g"`
    ST_EDIT_VERSION=0
  fi
]

AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [The current version of GNU Smalltalk.])
AC_DEFINE_UNQUOTED(ST_MAJOR_VERSION, $ST_MAJOR_VERSION, [Major version of GNU Smalltalk.])
AC_DEFINE_UNQUOTED(ST_MINOR_VERSION, $ST_MINOR_VERSION, [Minor version of GNU Smalltalk.])
AC_DEFINE_UNQUOTED(ST_EDIT_VERSION, $ST_EDIT_VERSION, [Patch level of GNU Smalltalk.])
AC_DEFINE_UNQUOTED(MAINTAINER, "$MAINTAINER", [E-mail address of GNU Smalltalk's maintainer.])

dnl 
dnl ------------------------------- PROGRAMS ------------------

test -z "$CDEBUG" && CDEBUG=-g 
test -z "$CFLAGS" && CFLAGS= 
test -z "$LDFLAGS" && LDFLAGS= 
test -z "$RM" && RM='rm -f'

AC_PROG_CC
AC_PROG_CPP
AC_AIX
AC_ISC_POSIX
AC_PROG_GCC_TRADITIONAL
AC_PROG_INSTALL
AC_PROG_RANLIB
AC_PROG_MAKE_SET
GST_CHECK_PROG(INSTALL_INFO, install-info, :)
GST_CHECK_PROG(MAKEINFO, makeinfo)
GST_CHECK_PROG(AUTOCONF, autoconf)
GST_CHECK_PROG(AUTOHEADER, autoheader)
GST_CHECK_PROG(BISON, bison)

if test "$GCC" = yes; then
  GCC_OPT_CFLAGS='-fno-inline-functions -fomit-frame-pointer -fno-unroll-loops'
fi

dnl 
dnl -------------------------- HARDWARE ARCHITECTURE ----------

AC_C_BIGENDIAN
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)
AC_CHECK_SIZEOF(char *, $ac_cv_sizeof_long)
GST_DOUBLE_ALIGNMENT

dnl 
dnl ------------------------------ C COMPILER / OS ------------

AC_C_INLINE
AC_C_CONST
AC_EXEEXT
GST_C_SIGNED
GST_C_GOTO_VOID_P
GST_C_OLDCC
GST_C_SYMBOLSET
GST_C_VARARGS

AC_CACHE_CHECK([for bison output filename], gst_cv_bison_output,
[cat >foo.y <<ACEOF
%%
conftest:
%%
ACEOF
if $BISON foo.y; then
  if test -f foo_tab.c; then
    gst_cv_bison_output=_tab
  else
    gst_cv_bison_output=.tab
  fi
fi
rm -f foo.y foo$gst_cv_bison_output.*])
GST_TAB=gst$gst_cv_bison_output
AC_DEFINE_UNQUOTED(GRAMMAR_HEADER, "gst$gst_cv_bison_output.h",
  [Name of the header file generated by bison.])

PLATFORM=unix
case "$gst_cv_machine_defines" in
    *WIN32*)
	PLATFORM=win32
	ICON=gsticon.o
	;;
    *\"MSDOS\",*)
	PLATFORM=msdos
dnl Note: This is overridden by a runtime check on DJGPP
        AC_DEFINE(NAMES83, 1, [Define if your system is a loser one with 8.3 filenames.])
	;;
    *\"NeXT\",*)
	SPECIAL_INTERP='				\
# Hack around NeXTs CPP bugs/limitations		\
interp.o: interp.c					\
	$(GENERIC_CC) -traditional-cpp interp.c		\
'
	;;
esac

dnl 
dnl ------------------------------- C LIBRARY -----------------

AC_TYPE_SIGNAL
AC_HEADER_STDC
AC_HEADER_DIRENT
AC_CHECK_HEADERS(io.h stdlib.h unistd.h sys/time.h sys/utsname.h)
AC_EGREP_HEADER([ *ioctl[[^A-Za-z0-9_]]], unistd.h,
AC_DEFINE(IOCTL_IN_UNISTD_H, 1, [Define if you have unistd.h and it defines ioctl (like IRIX 5.3's does).]))

AC_FUNC_ALLOCA
AC_CHECK_LIB(m, atan)
AC_REPLACE_FUNCS(putenv qsort strdup strerror)
AC_CHECK_FUNCS(gethostname memcpy sighold ldexp uname ioctl pipe \
	popen getdtablesize getrusage gettimeofday getcwd fork	 \
	sigsetmask alarm select)

GST_FUNC_WAITPID
GST_FUNC_OBSTACK
GST_INET_SOCKETS
GST_FUNC_STRTOUL
GST_FUNC_LOCALTIME


dnl ------------------------- OTHER LIBRARIES -------------------

GST_KIND_DLD
GST_HAVE_TCLTK
GST_HAVE_READLINE

AC_ARG_ENABLE(warnings, 
[  --enable-warnings       enable compiler warnings], [
   GCC_CFLAGS='-Wall -Wno-parentheses -Wno-switch'
])

dnl 
dnl ------------------------------- FILE GENERATION -----------

### HACK!
test "x$prefix" = xNONE && prefix=$ac_default_prefix
KERNEL_PATH=`eval echo $datadir`/gnu-smalltalk/kernel
IMAGE_PATH=`eval echo $datadir`/gnu-smalltalk
AC_DEFINE_UNQUOTED(KERNEL_PATH, "$KERNEL_PATH", [Define to the path in which the kernel files will be looked for.])
AC_DEFINE_UNQUOTED(IMAGE_PATH, "$IMAGE_PATH", [Define to the path in which an image will be looked for.])

AC_SUBST(CDEBUG)
AC_SUBST(CFLAGS)
AC_SUBST(GCC_CFLAGS)
AC_SUBST(GCC_OPT_CFLAGS)
AC_SUBST(GST_TAB)
AC_SUBST(ICON)
AC_SUBST(IMAGE_PATH)
AC_SUBST(KERNEL_PATH)
AC_SUBST(LDFLAGS)
AC_SUBST(LDPATH)
AC_SUBST(LIBOBJS)
AC_SUBST(MAINTAINER)
AC_SUBST(PLATFORM)
AC_SUBST(RM)
AC_SUBST(SPECIAL_INTERP)
AC_SUBST(ST_EDIT_VERSION)
AC_SUBST(ST_MAJOR_VERSION)
AC_SUBST(ST_MINOR_VERSION)
AC_SUBST(VERSION)

AC_OUTPUT(Makefile.defs:MakeDefs.in lib/Makefile,  [
  echo timestamp > stamp-h
  test ! -f Makefile && ./modules
])
