dnl configure.in
dnl   IIRC autoconf input script
dnl
dnl $Id: configure.in,v 1.1.1.1 2002/01/24 20:18:42 sembera Exp $

dnl IIRC - IIRC Is a Real Client (Modular IRC Client)
dnl Copyright (C) 2001,2002  Jan Sembera <fis@ji.cz>
dnl Copyright (C) 2001,2002  Petr Baudis <pasky@ji.cz>
dnl
dnl This program is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 2 of the License, or
dnl (at your option) any later version.
dnl
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with this program; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

AC_REVISION($Revision: 1.1.1.1 $)
AC_INIT(src/core/main.c)
AC_CONFIG_HEADER(include/config.h)

dnl ,-------------------
dnl | Get version number

VERSION=`cat VERSION`
echo This is iirc version $VERSION
echo
AC_SUBST(VERSION)
AC_DEFINE_UNQUOTED(IIRC_VERSION, "$VERSION")

dnl ,---------------------------------
dnl | Get these once, check them later

unamer=`uname -r 2> /dev/null`
unames=`uname -s 2> /dev/null`

LIBS=" "
CFLAGS=" "

dnl ,----------------
dnl | Programs checks

AC_CANONICAL_SYSTEM
AC_PROG_CC
AC_PROG_CC_C_O
AC_PROG_CPP
AC_PROG_GCC_TRADITIONAL
AC_PROG_INSTALL
AC_PROG_LN_S
AC_PROG_RANLIB

CFLAGS="$CFLAGS -Wall -g -ggdb  " 

dnl ,---------------------
dnl | UNIX variants checks

AC_ISC_POSIX
AC_MINIX
AC_AIX

dnl ,---------------------------------
dnl | Checking for svr4's /usr/ccs/lib
dnl

AC_MSG_CHECKING(for SVR4's /usr/ccs/lib)

if test -d /usr/ccs/lib; then
  LIBS="-L/usr/ccs/lib $LIBS"
  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT(no)
fi

dnl ,-------------------
dnl | Which make to use?

AC_MSG_CHECKING(which make to use...)

found=

for prog in gmake make; do
  ver=`$prog -v 2> /dev/null`
  if test -n "$ver"; then
    MAKE="$prog"
    AC_SUBST(MAKE)
    AC_MSG_RESULT($prog)
    found=1;
    break;
  fi
done

if test -z "$found"; then
  AC_MSG_RESULT(none usable)
  echo I have no other mean of life :\| I\'m so sad depressed and just going to die.
  AC_MSG_ERROR(I have not found any make for you anywhere.)
fi


dnl ,---------------------------------------------------------------------
dnl | Checking for headers, functions, environment and a type declarations

AC_CYGWIN
AC_EXEEXT
AC_OBJEXT
AC_SYS_LONG_FILE_NAMES
AC_C_CONST
AC_C_INLINE
AC_FUNC_VPRINTF
AC_HEADER_STDC
AC_HEADER_TIME
AC_STRUCT_TM
AC_STRUCT_TIMEZONE
AC_CHECK_HEADERS(sys/ioctl.h memory.h unistd.h)
AC_CHECK_FUNCS(strchr memcpy strerror strdup socket)
AC_TYPE_SIGNAL

dnl ,---------------------------------------------------
dnl | Glib - find configuration program, then get output

AC_MSG_CHECKING(for glib)

found=

for prog in glib-config glib12-config glib-config-2.0; do
  location=`which ${prog} 2> /dev/null`
  dnl XXX - this is not portable :(
  
  if test -n "$location"; then
    LIBS="$LIBS `$location --libs`"
    CFLAGS="$CFLAGS `$location --cflags`"
    AC_MSG_RESULT(found)
    AC_DEFINE(HAVE_GLIB)
    found=1
    break;
  fi
done

if test -z "$found"; then
  AC_MSG_RESULT(not found in PATH)
  echo I have no other mean of life :\| I\'m so sad depressed and just going to die.
  AC_MSG_ERROR(I have not found glib configuration script anywhere.)
fi

dnl I don't see any reason why we should use this - if there is any 
dnl glib-config available, there will be glib.h somewhere. -- fis

dnl That's true, but you never know... :-)
dnl You won't lose anything but 26 bytes on disk by having this :-) --pasky 

AC_CHECK_HEADERS(glib.h)


dnl ,------------------------------------------------------
dnl | Checking for select() [will be useful in near future]

dnl FIXME Make this work

olibs="$LIBS"
AC_CHECK_FUNC(select, ,
  AC_CHECK_LIB(socket, select, LIBS="$LIBS -lsocket",
    AC_CHECK_LIB(nsl, select, LIBS="$LIBS -lnsl",
      AC_CHECK_LIB(inet, select, LIBS="$LIBS -linet",
        AC_CHECK_LIB(cposix, select, LIBS="$LIBS -lcposix",
          AC_CHECK_LIB(net, select, LIBS="$LIBS -lnet",
            AC_MSG_WARN(I can not find select.  you might need to help me)))))))

dnl ,------------------------------------------------------------
dnl | Checking for termcap/curses [will be useful in near future]

dnl FIXME Make this work

if test x$hpux = x1 -o x$aix = x1; then
  LIBS="-lcurses $LIBS"
  AC_DEFINE(USING_CURSES)
else
  olibs="$LIBS"
  AC_CHECK_LIB(ncurses, tgetent, LIBS="-lncurses $olibs",
    AC_CHECK_LIB(termcap, tgetent, LIBS="-ltermcap $olibs",
      AC_CHECK_LIB(termlib, tgetent, LIBS="-ltermlib $olibs",
        AC_CHECK_LIB(xtermcap, tgetent, LIBS="-lxtermcap $olibs",
          AC_MSG_WARN(I can not find tgetent.  you might need to help me)))))
fi

dnl ,----------
dnl | Misc libs

if test -z "$libsocket"; then
  AC_CHECK_LIB(socket, socket, LIBS="$LIBS -lsocket",)
fi

dnl ISC
if test -z "$libinet"; then
  AC_CHECK_LIB(inet, socket, libnsl=1; LIBS="$LIBS -linet -lnsl_s",)
fi

if test -z "$libnsl"; then
  AC_CHECK_LIB(nsl, gethostname, LIBS="$LIBS -lnsl",)
fi

AC_CHECK_LIB(sun, getpwnam, LIBS="$LIBS -lsun",)
AC_CHECK_LIB(dgc, inet_addr, LIBS="$LIBS -ldgc",)
AC_CHECK_LIB(resolv, gethostbyname, LIBS="$LIBS -lresolv",)
AC_CHECK_LIB(crypt, crypt, LIBS="$LIBS -lcrypt",)
AC_CHECK_LIB(gnumalloc, malloc, LIBS="$LIBS -lgnumalloc",
AC_CHECK_LIB(bsdmalloc, malloc, LIBS="$LIBS -lbsdmalloc",))

dnl ,------------------
dnl | Last minute stuff

if test -z "$CFLAGS"; then CFLAGS= ; fi
if test -z "$LDFLAGS"; then LDFLAGS= ; fi

AC_SUBST(CFLAGS)
AC_SUBST(LDFLAGS)
AC_SUBST(INSTALL)
AC_SUBST(DEFS)
AC_SUBST(LIBS)
AC_SUBST(bindir)
AC_SUBST(prefix)
AC_SUBST(exec_prefix)
AC_SUBST(sysconfdir)
AC_SUBST(libdir)
AC_SUBST(datadir)
AC_SUBST(includedir)

AC_OUTPUT(Makefile src/Makefile src/back/Makefile src/core/Makefile src/front/Makefile src/libiirc/Makefile src/libmod/Makefile src/libaio/Makefile doc/Makefile include/Makefile)

dnl ,--------
dnl | Bye bye

echo
echo Well, there we are. We hope everything passed OK, so now just go
echo and type make, and silently watch all the famous compilation.
echo Good luck!
echo
