## (C) 1998 Stephan Kulow
## Modified by Tero Pulkkinen
## Modified by Karl Nelson

AC_INIT(sigc++)

define(AC_PUSH_LIB,[dnl
ifdef([__LIB__],,[define([__LIB__],0)])dnl
ac_save_LIBS[]__LIB__="$LIBS"
define([__LIB__],builtin(eval,(__LIB__ + 1)))dnl
LIBS="$1"])
define(AC_POP_LIB,[dnl
define([__LIB__],builtin(eval,(__LIB__ - 1)))dnl
LIBS="$ac_save_LIBS[]__LIB__"])


dnl
dnl Source packaging numbers
SIGC_MAJOR_VERSION=1
SIGC_MINOR_VERSION=2
SIGC_MICRO_VERSION=5

SIGC_VERSION=$SIGC_MAJOR_VERSION.$SIGC_MINOR_VERSION.$SIGC_MICRO_VERSION

#
# +1 : ? : +1  == new interface that does not break old one
# +1 : ? : 0   == new interface that breaks old one
#  ? : ? : 0   == no new interfaces, but breaks apps
#  ? :+1 : ?   == just some internal changes, nothing breaks but might work 
#                 better
# CURRENT : REVISION : AGE
LIBSIGC_SO_VERSION=5:5:0
AC_SUBST(LIBSIGC_SO_VERSION, $LIBSIGC_SO_VERSION)

dnl AC_SUBST(SIGC_RELEASE, $SIGC_RELEASE)
AC_SUBST(SIGC_VERSION)

AC_DEFINE_UNQUOTED(SIGC_MAJOR_VERSION, $SIGC_MAJOR_VERSION)
AC_DEFINE_UNQUOTED(SIGC_MINOR_VERSION, $SIGC_MINOR_VERSION)
AC_DEFINE_UNQUOTED(SIGC_MICRO_VERSION, $SIGC_MICRO_VERSION)

AC_CONFIG_AUX_DIR(scripts)

dnl For automake.
VERSION=$SIGC_VERSION
PACKAGE=libsigc++

dnl Initialize automake stuff
AM_INIT_AUTOMAKE($PACKAGE, $VERSION)

dnl Specify a configuration file
AM_CONFIG_HEADER(sigc++/config/sigcconfig.h)

AM_MAINTAINER_MODE

# echo $USE_MAINTAINER_MODE
# if test ! $USE_MAINTAINER_MODE = yes; then
# cat << EOF
# [
# *********************************************************************
#  WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING 
# This version is a developement versions intended only for developers
# associated with libsigc++ to port to various architectures, discussion
# piece for C++ experts and tool to verify compatiblity of features.  
# Unless you meet this description stick with 1.0.x
# 
# This version should NOT be shipped with any binary distribution 
# and source compatiblity from version to version will not be maintained.
# NEVER ship a binary against this code.
#  WARNING * WARNING * WARNING * WARNING * WARNING * WARNING * WARNING 
# *********************************************************************
# If you were a real developer you would be using maintainer mode.
# ]
# EOF
#   exit
# fi

AC_ARG_ENABLE(threads,
[  --disable-threads       disables support threading.],
enable_threads=$enableval,enable_threads="yes")
AC_ARG_ENABLE(checks,
[  --disable-checks        disables unnecessary tests needed for bug reports.],
enable_checks=$enableval,enable_checks="yes"
)

AC_PROG_CC
AC_PROG_CPP

dnl Used for enabling the "-no-undefined" flag while generating DLLs
dnl Copied from the official gtk+-2 configure.in
AC_CANONICAL_HOST
AC_MSG_CHECKING([for some Win32 platform])
case "$host" in
  *-*-mingw*|*-*-cygwin*)
    platform_win32=yes
    LIBSTDCPP_LIBS=-lstdc++
    ;;
  *)
    platform_win32=no
    LIBSTDCPP_LIBS=
    ;;
esac
AC_SUBST(LIBSTDCPP_LIBS)
AC_MSG_RESULT([$platform_win32])
AM_CONDITIONAL(PLATFORM_WIN32, test "$platform_win32" = "yes")

AC_MSG_CHECKING([for native Win32])
case "$host" in
  *-*-mingw*)
    os_win32=yes
    MATH_LIB=
    ;;
  *)
    os_win32=no
    ;;
esac
AC_MSG_RESULT([$os_win32])
AM_CONDITIONAL(OS_WIN32, test "$os_win32" = "yes")

dnl AM_DISABLE_STATIC

dnl Instruct build of dll for cygwin and mingw32 (libtool 1.4)
dnl Exports screw up badly on libtool 1.3, backing off to 1.2f
dnl Seems to be working again with libtool 1.4 
AC_LIBTOOL_WIN32_DLL  

dnl libtool does all checks with $CC, not with $CXX
dnl maybe this should be fixed in libtool, not here
AM_PROG_LIBTOOL

dnl On FreeBSD 3.0 (and perhaps some other systems) GNU m4 is
dnl called `gm4' where `m4' is the system's own m4.
AC_CHECK_PROGS(M4, gm4 m4, m4)
AC_MSG_CHECKING(if m4 is gnu m4 (required))
if "$M4" --version 2>&1 < /dev/null | egrep 'GNU' > /dev/null; then
  AC_MSG_RESULT([yes])
else
  config_error=yes
  AC_MSG_RESULT([no (fail)])
  AC_MSG_ERROR([you must use GNU m4 to build libsigc++])
fi

AC_PROG_CXX
AC_PROG_CXX_SUN
AC_LANG_CPLUSPLUS

dnl Checking if linker supports global constructors
dnl This is largely information for me if someone files a bug report
if test "X$enable_checks" = "Xyes"; then
AC_MSG_CHECKING([if linker supports global constructors])
cat > mylib.$ac_ext <<EOF
#include <stdio.h>

struct A
{
  A() { printf("PASS\n"); }
};

A a;

int foo()
  { return 1; }

EOF
cat > mytest.$ac_ext <<EOF
#include <stdio.h>

extern int foo();

int main(int, char**)
{
  int i = foo();
  if(i != 1) printf("FAIL\n");
  return 0;
}

EOF
sh libtool --mode=compile $CXX -c mylib.$ac_ext >&5
sh libtool --mode=link $CXX -o libtest.la -rpath / -version-info 0 mylib.lo  >&5
$CXX -c $CFLAGS $CPPFLAGS mytest.$ac_ext >&5
sh libtool --mode=link $CXX -o mytest mytest.o libtest.la >&5 2>/dev/null
if test -x mytest; then
myresult=`./mytest`
if test "X$myresult" = "XPASS"; then
AC_MSG_RESULT(yes)
else
AC_MSG_RESULT(no)
AC_MSG_WARN([
===================================================================
WARNING: This platform lacks support of construction of global 
objects in shared librarys.  Although not required by this library, 
this is a serious problem for building C++ libraries.  You will not 
be able to use any shared libraries that contain global objects with 
contructors.

See ftp://rtfm.mit.edu/pub/usenet/news.answers/g++-FAQ/plain
for details about this problem.  Also for possible solutions
http://www.informatik.uni-frankfurt.de/~fp/Tcl/tcl-c++/tcl-c++.html
===================================================================
])
fi
else
AC_MSG_RESULT(unknown)
fi
rm -f mylib.* mytest.* libtest.la .libs/libtest* mytest .libs/mytest .libs/lt-mytest >&5
rmdir .libs >&5
fi

AC_MSG_CHECKING(if C++ compiler uses std namespace )
AC_TRY_COMPILE(
[
#include <iostream>
namespace std{ void kludge(); }
using namespace std;
],[
cout << "test" << endl;
],[
 ac_std_namespace=yes
 AC_MSG_RESULT([yes])
],[
 ac_std_namespace=maybe
])
if test "x$ac_std_namespace" = xmaybe ; then
AC_TRY_COMPILE(
[
#include <iostream.h>
namespace std{ void kludge(); }
using namespace std;
],[
cout << "test" << endl;
],[
 ac_std_namespace=yes
 AC_MSG_RESULT([yes])
 AC_MSG_WARN([
===================================================================
WARNING: This compiler platform does not have the iostream library
in the std namespace.  This presents a problem for writing portable
STL code.  To run the demos, you will need to place a file with the
following in a file called "iostream" in your include directory.

---------------------------iostream--------------------------------
#ifndef IOSTREAM_KLUDGE
#define IOSTREAM_KLUDGE
#include <iostream.h>
namespace std { void iostream_kludge(); };
#endif
===================================================================
])
],[
 ac_std_namespace=no
 AC_MSG_RESULT([no])
 AC_MSG_WARN([
===================================================================
WARNING: This compiler platform does not support iostream 
or namespaces.  You will not be able to run the demos as they
use STL.  This does not affect use of the library, only the demos.
===================================================================
])
])
fi



dnl
dnl C++ compiler feature check start here

AC_MSG_CHECKING(if C++ compiler supports bool (required))
AC_TRY_COMPILE(
[
],[
   bool b=true;
   bool b1=false;
],[
  ac_bool=yes
  AC_MSG_RESULT([$ac_bool])
],[
  config_error=yes
  AC_MSG_RESULT([$ac_bool])
  AC_WARN(bool type is not supported by your compiler)
]) 

AC_MSG_CHECKING([if C++ compiler supports explicit])
AC_TRY_COMPILE(
[
  class T {
    public:
      explicit T(int) {}
  };
],[
],
  AC_DEFINE(SIGC_CXX_EXPLICIT,explicit)
  ac_cxx_explicit=yes
,
  AC_DEFINE(SIGC_CXX_EXPLICIT,)
  ac_cxx_explicit=no
)
AC_MSG_RESULT([$ac_cxx_explicit])

AC_MSG_CHECKING([if C++ compiler supports explicit copy ctor])
AC_TRY_COMPILE(
[
  class T {
    public:
      explicit T(const T&) {}
  };
],[
],
  AC_DEFINE(SIGC_CXX_EXPLICIT_COPY,explicit)
  ac_cxx_explicit_copy_ctor=yes
,
  AC_DEFINE(SIGC_CXX_EXPLICIT_COPY,)
  ac_cxx_explicit_copy_ctor=no
)
AC_MSG_RESULT([$ac_cxx_explicit_copy_ctor])



AC_MSG_CHECKING([if C++ compiler supports const_cast<> (required)])
AC_TRY_COMPILE(
[
   class foo;
],[
   const foo *c=0;
   foo *c1=const_cast<foo*>(c);
],[
  ac_const_cast=yes
  AC_MSG_RESULT([$ac_const_cast])
],[
  AC_MSG_RESULT([$ac_const_cast])
  AC_WARN(C++ compiler const_cast<> does not work)
  config_error=yes
]) 


# Member function templates
#AC_MSG_CHECKING(if C++ compiler supports member function templates)
#AC_TRY_COMPILE(
#[
#class foo
#{
#public:
  #template <class T> void method(T t);
#};
#
#template <class T> void foo::method(T t) {t = 0;}
#],[
#],[
   #ac_member_func_templates=yes
   #AC_DEFINE(SIGC_CXX_MEMBER_FUNC_TEMPLATES)
   #AC_MSG_RESULT([$ac_member_func_templates])
#],[
  #ac_member_func_templates=no
  #AC_MSG_RESULT([$ac_member_func_templates])
  #config_error=yes
  #AC_MSG_WARN([Test for member templates failed. This disables some methods that requires member template support. If your compiler should support member templates, see config.log to figure out why the test failed.])
#])



# Member class templates
#AC_MSG_CHECKING(if C++ compiler supports member class templates)
#AC_TRY_COMPILE(
#[
#struct S
#{
  #template <class T> struct A {};
  #template <class T> struct B {};
#};
#],[
#],[
   #ac_member_class_templates=yes
   #AC_DEFINE(SIGC_CXX_MEMBER_CLASS_TEMPLATES)
   #AC_MSG_RESULT([$ac_member_class_templates])
#],[
  #ac_member_class_templates=no
  #AC_MSG_RESULT([$ac_member_class_templates])
  #AC_MSG_WARN([Test for member templates failed. This disables some methods that requires member template support. If your compiler should support member templates, see config.log to figure out why the test failed.])
#])



# Mutable
AC_MSG_CHECKING(if C++ compiler supports mutable (required))
AC_TRY_COMPILE(
[
class k { 	
	mutable char *c;
public:
   void foo() const { c=0; }
};
],[
],[
  ac_cxx_mutable=yes
#  AC_DEFINE(SIGC_CXX_MUTABLE)
],[
  config_error=yes
  ac_cxx_mutable=no
]) 
AC_MSG_RESULT([$ac_cxx_mutable])


# Partial Specialization
AC_MSG_CHECKING([if C++ compiler supports partial specialization ])
AC_TRY_COMPILE(
[
template<class T, class K>
class k { 	
public:
};
template<class T> class k<void,T> { };
],[
  k<float, float> b;
  k<void,void> a;
],[
  ac_cxx_partial_specialization=yes
  AC_DEFINE(SIGC_CXX_PARTIAL_SPEC)
],[
#  config_error=yes
  ac_cxx_partial_specialization=no
#  AC_MSG_WARN([Partial specialization is needed for signal templates.])
]) 
AC_MSG_RESULT([$ac_cxx_partial_specialization])


AC_MSG_CHECKING(if C++ compiler supports name spaces)
AC_TRY_COMPILE(
[
namespace Check
  {
   int i;
  }
],[
  Check::i=1;
],[
  ac_cxx_namespaces=yes
  AC_MSG_RESULT([$ac_cxx_namespaces])
  AC_DEFINE(SIGC_CXX_NAMESPACES)
],[
  ac_cxx_namespaces=no
  AC_MSG_RESULT([$ac_cxx_namespaces])
  AC_MSG_WARN([Without namespaces all classes will be global.])
]) 


#AC_MSG_CHECKING(if C++ compiler supports friend template)
#AC_TRY_COMPILE(
#[
#struct A
  #{
   #template <class T>
     #friend T* gen();
  #};
#],[
#],[
  #ac_cxx_friend_templates=yes
  #AC_MSG_RESULT([$ac_cxx_friend_templates])
  #AC_DEFINE(SIGC_CXX_FRIEND_TEMPLATES)
#],[
  #ac_cxx_friend_templates=no
  #AC_MSG_RESULT([$ac_cxx_friend_templates])
  #AC_MSG_WARN([Access to dynamic will not be controlled.])
#]) 


AC_MSG_CHECKING(if C++ compiler has intrinsic constructors)
AC_TRY_COMPILE(
[
template<class T>
  struct A
    { T t;
     A(): t() {}
    };

A<int> i;
],[
],[
  AC_DEFINE(SIGC_CXX_INT_CTOR)
  ac_cxx_tmpl_intctor=yes
],[
  ac_cxx_tmpl_intctor=no
])
AC_MSG_RESULT([$ac_cxx_tmpl_intctor])


#AC_MSG_CHECKING(if C++ compiler uses template copy ctor)
#AC_TRY_COMPILE(
#[
#template <class T>
#struct A
  #{
   #A(const A&) {}
   #template <class T1>
   #A(const T1&) {}  
  #};
#],[
#],[
#  ac_cxx_template_cctor=no
#],[
#  AC_DEFINE(SIGC_CXX_TEMPLATE_CCTOR)
#  ac_cxx_template_cctor=yes
#])
#AC_MSG_RESULT([$ac_cxx_template_cctor])


AC_MSG_CHECKING(if C++ compiler allows void returns)
AC_TRY_COMPILE(
[

void g(int *p)
  {}

void h(int *p)
  {return g(p);}

],[
],[
  ac_cxx_void_return=yes
  AC_DEFINE(SIGC_CXX_VOID_RETURN)
],[
  ac_cxx_void_return=no
])
AC_MSG_RESULT([$ac_cxx_void_return])


AC_MSG_CHECKING([if C++ compiler supports void cast return])
AC_TRY_COMPILE(
[
  int g() {return 1;}
  void f() {return void(g()); }
],[
],[
  ac_cxx_void_cast_return=yes
  AC_DEFINE(SIGC_CXX_VOID_CAST_RETURN)
],[
  ac_cxx_void_cast_return=no
])
AC_MSG_RESULT([$ac_cxx_void_cast_return])


AC_MSG_CHECKING(if C++ compiler allows specialization of references)
AC_TRY_COMPILE(
[
struct A {};
struct B {};

template <class T>
struct P
  {
   typedef A* ptr;
   typedef T* type;
  };

template <class T>
struct P<T&>
  {
   typedef B* ptr;
   typedef T* type;
  };

],[
    typedef P<int&>::type r;
    A* a=0;
    B* b=0;
    P<int>::ptr p=a;
    P<int&>::ptr q=b;
],[
  ac_cxx_specialize_references=yes
  AC_DEFINE(SIGC_CXX_SPECIALIZE_REFERENCES)
],[
  ac_cxx_specialize_references=no
])
AC_MSG_RESULT([$ac_cxx_specialize_references])

AC_MSG_CHECKING(if C++ compiler allows default template types (required))
AC_TRY_COMPILE(
[

template <class R>
struct Trait {
   typedef R type;
};

template <class R, class R2=Trait<R> >
struct Class {
  typename R2::type foo() {};
};
],[
],[
  ac_cxx_default_template_types=yes
],[
  ac_cxx_default_template_types=no
  config_error=yes
])
AC_MSG_RESULT([$ac_cxx_default_template_types])


dnl unused at the moment, disabled
dnl mirko, 99/1/15
dnl AC_MSG_CHECKING(if C++ compiler supports qualification of return types with templates)
dnl AC_TRY_COMPILE(
dnl [
dnl template<class T>
dnl class foo {
dnl public:
dnl   typedef int iterator;
dnl   iterator begin();
dnl };
dnl template<class T> foo<T>::iterator foo<T>::begin() { }
dnl ],[
dnl   foo<int> f;
dnl   f.begin();
dnl ],[
dnl   ac_template_qualification=yes
dnl ],[
dnl   AC_DEFINE(SIGC_CXX_NO_TEMPLATE_QUALIFICATION)
dnl   ac_template_qualification=no
dnl ]) 
dnl AC_MSG_RESULT([$ac_template_qualification])

dnl unused at the moment, disabled
dnl mirko, 99/1/15
dnl AC_MSG_CHECKING(if C++ compiler supports static data inside templates)
dnl AC_TRY_LINK(
dnl [
dnl template<class T>
dnl class foo { public: static T a; };
dnl template<class T>
dnl static T foo<T>::a=0;
dnl ],[
dnl   foo<int> b;
dnl ],[
dnl   ac_static_templates=yes
dnl ],[
dnl   AC_DEFINE(SIGC_CXX_NO_STATIC_TEMPLATES)
dnl   ac_static_templates=no
dnl ]) 
dnl AC_MSG_RESULT([$ac_static_templates])

AC_MSG_CHECKING(if C++ environment provides all required features)
if test "x$config_error" = xyes ; then
  AC_MSG_RESULT([no])
  AC_MSG_ERROR([Your compiler is not powerful enough to compile libsigc++. If it should be, see config.log for more information of why it failed.])
fi
AC_MSG_RESULT([yes])

# Dummy conditional just to make automake-1.4 happy.
# We need an always-false condition in docs/Makefile.am.
AM_CONDITIONAL(LIBSIGC_FALSE,[false])

# HACK:  Assign a dummy in order to prevent execution of autoheader by the
# maintainer-mode rules.  That would fail since we aren't using autoheader.
AUTOHEADER=':'


AC_OUTPUT([Makefile 
	sigc++-1.2.pc
        libsigc++.spec 
        sigc++/Makefile  
        sigc++/macros/Makefile  
        sigc++/config/Makefile  
        scripts/Makefile
        examples/Makefile
        tests/Makefile
        MSVC_6/Makefile
        MSVC_Net2003/Makefile
          MSVC_Net2003/tests/Makefile
            MSVC_Net2003/tests/bind_return_test/Makefile
            MSVC_Net2003/tests/bind_test/Makefile
            MSVC_Net2003/tests/class_slot_test/Makefile
            MSVC_Net2003/tests/connection_test/Makefile
            MSVC_Net2003/tests/hide_test/Makefile
            MSVC_Net2003/tests/method_slot_test/Makefile
            MSVC_Net2003/tests/object_slot_test/Makefile
            MSVC_Net2003/tests/object_test/Makefile
            MSVC_Net2003/tests/retype_return_test/Makefile
            MSVC_Net2003/tests/retype_test/Makefile
            MSVC_Net2003/tests/size_test/Makefile
            MSVC_Net2003/tests/slot_test/Makefile
                                                                                                              
        doc/Makefile
          doc/manual/Makefile
          doc/reference/Makefile
])
