#
# $Id: configure.in,v 1.2 1997/08/18 13:32:42 grubba Exp $
#
# Configure-script for zlib.
#
# Adapted from the original configure-script to autoconf by
# Henrik Grubbström <grubba@infovav.se>
#

AC_REVISION("$Id: configure.in,v 1.2 1997/08/18 13:32:42 grubba Exp $")
AC_INIT(zlib.h)

AC_PROG_CC
AC_PROG_RANLIB

# We need some special hacks when running slowaris
AC_PATH_PROG(uname_prog,uname,no)
AC_MSG_CHECKING(operating system)
AC_CACHE_VAL(zlib_cv_sys_os,
[
if test "$uname_prog" != "no"; then
  zlib_cv_sys_os="`uname`"

  case "$zlib_cv_sys_os" in
    SunOS)
      case "`uname -r`" in
        5.*) zlib_cv_sys_os="Solaris";
      esac
    ;;
  esac
else
  zlib_cv_sys_os="Not Solaris"
fi
])
AC_MSG_RESULT($zlib_cv_sys_os)

case "$zlib_cv_sys_os" in
  SCO*)
     case "$CC" in
       *-belf*) ;;
       *)
          CC="$CC -belf"
       ;;
     esac
  ;;
esac

if test "x${CFLAGS-}" = x ; then
  cflags_is_set=no
else
  cflags_is_set=yes
fi

if test "x${CPPFLAGS-}" = x ; then
  cppflags_is_set=no
else
  cppflags_is_set=yes
fi

if test "x${LDFLAGS-}" = x ; then
  ldflags_is_set=no
else
  ldflags_is_set=yes
fi

#############################################################################


AC_DEFUN(AC_SYS_COMPILER_FLAG,
[
  AC_MSG_CHECKING($1)
  OLD_CFLAGS="[$]CFLAGS"
  AC_CACHE_VAL(zlib_cv_option_$2,
  [
    CFLAGS="[$]OLD_CFLAGS $1"
    AC_TRY_RUN([int main(){exit(0);}],zlib_cv_option_$2=yes,zlib_cv_option_$2=no)
  ])
  
  CFLAGS="[$]OLD_CFLAGS"
  
  if test x"[$]zlib_cv_option_$2" = "xyes" ; then
    OPTIMIZE="[$]OPTIMIZE $1"
    AC_MSG_RESULT(yes)
  else
    AC_MSG_RESULT(no)
  fi
])

AC_DEFUN(AC_SYS_CPU_COMPILER_FLAG,
[
 if test "`uname -m 2>/dev/null`" = "$1" ; then
    AC_SYS_COMPILER_FLAG($2,$3)
 fi
])

WARN=""
OPTIMIZE=""

AC_SUBST(WARN)
AC_SUBST(OPTIMIZE)

if test \! "$cflags_is_set" = "yes"; then
 if test "x${GCC-}" = xyes ; then
  WARN="-W -Wall -Wpointer-arith -Wno-unused"
### Optimize for different SUN machines. If there is no working 'uname'
### no extra optimization will be done, but nothing should break either.
  AC_SYS_CPU_COMPILER_FLAG(sun4c,-msparclite,sparclite)
  AC_SYS_CPU_COMPILER_FLAG(sun4m,-mv8,microsparc)
  AC_SYS_CPU_COMPILER_FLAG(sun4d,-msupersparc,supersparc)
  AC_SYS_CPU_COMPILER_FLAG(sun4u,-msupersparc,ultrasparc)
 else

### Non-gcc thingies. This should probably be enhanced...
  AC_SYS_COMPILER_FLAG(-fast,fast)

dnl
dnl This does not work with Digital UNIX cc/ld (cc thinks it is ok, ld does not)
dnl  
dnl AC_SYS_COMPILER_FLAG(-native,native)
dnl

dnl ### Ok. This is for apcc...
case "$CC" in
  *apcc)
    AC_SYS_COMPILER_FLAG(-XO=5,apcc_opt)
    AC_SYS_COMPILER_FLAG(-Xcallmod=2,apcc_opt_2)
  ;;
esac


  AC_SYS_CPU_COMPILER_FLAG(sun4m,-Xpipe=micro,microsparc)
  AC_SYS_CPU_COMPILER_FLAG(sun4d,-Xpipe=super,supersparc)
  AC_SYS_CPU_COMPILER_FLAG(sun4u,-Xpipe=super,ultrasparc)

  case "${CFLAGS-}" in
     *-O*) ;;
     *)
      AC_SYS_COMPILER_FLAG(-O,O)
     ;;
  esac
 fi
fi



if test "$GCC" = "yes"; then
  if test \! "$cflags_is_set" = "yes"; then
    AC_SYS_COMPILER_FLAG(-pipe, pipe)
  fi
else
#
# Special hack for HP-UX stupid cc
#
  if test "$zlib_cv_sys_os" = "HP-UX"; then
    AC_TRY_COMPILE([int foo(int bar);],[],[],
    [
      OLD_CC="${CC-cc}"
      if test "$CC" = "$BINDIR/smartlink cc" -a -x /usr/bin/cc ; then
        CC="$BINDIR/smartlink /usr/bin/cc"
      fi
      CC="$CC -Aa -D_HPUX_SOURCE +Olibcalls"
      AC_TRY_COMPILE([int foo(int bar);],[],[],[CC="$OLD_CC"])
    ])
  fi
fi

##########################################################################

# LDSHARED is the ld *command* used to create shared library
# -- "ld" on SunOS 4.x.x, "ld -G" on SunOS 5.x, "ld -shared" on IRIX 5
AC_SUBST(LDSHARED)
AC_MSG_CHECKING(LDSHARED)
if test -z "$LDSHARED"
then
	case "$pike_cv_sys_os" in
	AIX*)
	  # LDSHARED="ld_so_aix \$(CC)"
	  LDSHARED="ld -G -bnogc -bnox"
	;;
	IRIX*) LDSHARED="ld -shared";;
	SunOS*) LDSHARED="ld";;
	Solaris) LDSHARED="/usr/ccs/bin/ld -G";;
	hp*|HP*) LDSHARED="ld -b";;
	OSF*)
           LDSHARED="ld -expect_unresolved '*' -shared -msym -O3"
        ;;
	DYNIX/ptx*) LDSHARED="ld -G";;
	next) LDSHARED='$(CC) $(CFLAGS) -nostdlib -r';;
	Linux*) LDSHARED="gcc -shared";;
	FreeBSD*) LDSHARED="ld -Bshareable";;
	NetBSD) LDSHARED="ld -Bshareable";;
	OpenBSD*) LDSHARED="ld -Bshareable";;
	SCO_SV*) LDSHARED="cc -G -KPIC -Wl,-Bexport";;
	UNIX_SV) LDSHARED="ld -G";;
	*) LDSHARED="ld";;
	esac
fi
AC_MSG_RESULT($LDSHARED)

# CCSHARED are the C *flags* used to create objects to go into a shared
# library -- this is only needed for a few systems
AC_SUBST(CCSHARED)
AC_MSG_CHECKING(CCSHARED)
if test -z "$CCSHARED" ; then
  if test "$GCC" = yes ; then
    CCSHARED="-fpic"
  else
    case $pike_cv_sys_os in
	hp*|HP*) CCSHARED="+z"; ;;
	FreeBSD*) CCSHARED="-fpic";;
	SCO_SV*) CCSHARED="-KPIC -dy -Bdynamic";;
	Solaris) CCSHARED="-KPIC";;
	SunOS*) CCSHARED="-PIC";;
    esac
  fi
fi
AC_MSG_RESULT($CCSHARED)

AC_OUTPUT(Makefile, echo foo >stamp-h)
