s3:smbd: add a nfs backend for sysquotas.
[amitay/samba.git] / source3 / configure.in
index c7ad8e7d27f1b0933d05b0ff487876f964f2efad..d8bf5543876a6f06b3943f70e1ba4fbe3fb5a0df 100644 (file)
@@ -23,6 +23,7 @@ m4_include(m4/check_path.m4)
 m4_include(pkg.m4)
 
 AC_LIBREPLACE_CC_CHECKS
+AC_LIBREPLACE_RUNTIME_LIB_PATH_VAR
 
 m4_include(../lib/tevent/libtevent.m4)
 
@@ -120,14 +121,17 @@ fi
 
 m4_include(../lib/socket_wrapper/config.m4)
 m4_include(../lib/nss_wrapper/config.m4)
+m4_include(../lib/util/time.m4)
 
 m4_include(m4/swat.m4)
 
+DEVELOPER_CFLAGS="-DDEBUG_PASSWORD -DDEVELOPER"
+
 # Probe the gcc version for extra CFLAGS. We always stash these in
 # DEVELOPER_CFLAGS, so that you can turn them on and off with a simple
 # Makefile edit, avoiding the need to re-run configure.
 if test x"$ac_cv_prog_gcc" = x"yes" ; then
-       DEVELOPER_CFLAGS="-g -Wall -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -DDEBUG_PASSWORD -DDEVELOPER"
+       DEVELOPER_CFLAGS="${DEVELOPER_CFLAGS} -g -Wall -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings"
        # Add -Wdeclaration-after-statement if compiler supports it
        AC_CACHE_CHECK(
           [that the C compiler understands -Wdeclaration-after-statement],
@@ -200,23 +204,26 @@ AC_PROG_INSTALL
 AC_PROG_AWK
 # Check for GNU make
 m4_include(../m4/check_make.m4)
-AC_SAMBA_GNU_MAKE([true], [merged_build_possible=no])
+AC_SAMBA_GNU_MAKE([true], [true])
 
 # Check for perl
 m4_include(../m4/check_perl.m4)
 AC_SAMBA_PERL([true], [merged_build_possible=no])
 
+# Check for python
+m4_include(../m4/check_python.m4)
+AC_SAMBA_PYTHON_DEVEL([true], [merged_build_possible=no])
+
 AC_CHECK_TOOL(AR, ar)
 
-dnl Check if we use GNU ld
-LD=ld
+dnl Check if we (actually our C compiler!) use GNU ld
 AC_PROG_LD_GNU
 
 dnl Certain versions of GNU ld the default is not to have the
 dnl --allow-shlib-undefined flag defined.  This causes a stackload of
 dnl warnings when building modules.
 if test "$ac_cv_prog_gnu_ld" = "yes"; then
-       ac_cv_gnu_ld_version=`$LD -v 2>/dev/null | head -1`
+       ac_cv_gnu_ld_version=`$CC -Wl,-v /dev/null 2>/dev/null | head -1`
        AC_MSG_CHECKING(GNU ld release date)
        changequote(,)dnl
        ac_cv_gnu_ld_date=`echo $ac_cv_gnu_ld_version | sed -n 's,^.*\([2-9][0-9][0-9][0-9]\)[-]*\([01][0-9]\)[-]*\([0-3][0-9]\).*$,\1\2\3,p'`
@@ -232,7 +239,7 @@ if test "$ac_cv_prog_gnu_ld" = "yes"; then
         else
            AC_MSG_CHECKING(GNU ld release version)
            changequote(,)dnl
-           ac_cv_gnu_ld_vernr=`echo $ac_cv_gnu_ld_version | sed -n 's,^[^0-9]*\([1-9][0-9]*\.[0-9][0-9]*\).*$,\1,p'`
+           ac_cv_gnu_ld_vernr=`echo $ac_cv_gnu_ld_version | awk '{print $NF}' | sed -n 's,\([1-9][0-9]*\.[0-9][0-9]*\).*$,\1,p'`
            ac_cv_gnu_ld_vernr_major=`echo $ac_cv_gnu_ld_vernr | cut -d '.' -f 1`
            ac_cv_gnu_ld_vernr_minor=`echo $ac_cv_gnu_ld_vernr | cut -d '.' -f 2`
            changequote([,])dnl
@@ -262,7 +269,7 @@ else
 fi
 AC_SUBST(BROKEN_CC)
 
-dnl Check if the C compiler understands -Werror
+dnl Check if the C compiler understands -Werror (GNU)
 AC_CACHE_CHECK([that the C compiler understands -Werror],samba_cv_HAVE_Werror, [
  AC_TRY_RUN_STRICT([
   int main(void)
@@ -284,7 +291,7 @@ AC_CACHE_CHECK([that the C compiler understands -w2],samba_cv_HAVE_w2, [
 if test x"$samba_cv_HAVE_w2" = x"yes"; then
    Werror_FLAGS="-w2"
 else
-dnl Check if the C compiler understands -errwarn
+dnl Check if the C compiler understands -errwarn (Sun)
 AC_CACHE_CHECK([that the C compiler understands -errwarn],samba_cv_HAVE_errwarn, [
   AC_TRY_RUN_STRICT([
    int main(void)
@@ -294,6 +301,18 @@ AC_CACHE_CHECK([that the C compiler understands -errwarn],samba_cv_HAVE_errwarn,
    samba_cv_HAVE_errwarn=yes,samba_cv_HAVE_errwarn=no,samba_cv_HAVE_errwarn=cross)])
 if test x"$samba_cv_HAVE_errwarn" = x"yes"; then
    Werror_FLAGS="-errwarn=%all"
+else
+dnl Check if the C compiler understands -qhalt (IBM)
+AC_CACHE_CHECK([that the C compiler understands -qhalt],samba_cv_HAVE_qhalt, [
+  AC_TRY_RUN_STRICT([
+   int main(void)
+   {
+       return 0;
+   }],[$CFLAGS -qhalt=w],[$CPPFLAGS],[$LDFLAGS],
+   samba_cv_HAVE_qhalt=yes,samba_cv_HAVE_qhalt=no,samba_cv_HAVE_qhalt=cross)])
+if test x"$samba_cv_HAVE_qhalt" = x"yes"; then
+   Werror_FLAGS="-qhalt=w"
+fi
 fi
 fi
 fi
@@ -324,7 +343,7 @@ AC_CACHE_CHECK([that the C compiler understands negative enum values],samba_cv_C
                return 0;
        }
 ],
-       samba_cv_CC_NEGATIVE_ENUM_VALUES=yes,samba_cv__CC_NEGATIVE_ENUM_VALUES=no)])
+       samba_cv_CC_NEGATIVE_ENUM_VALUES=yes,samba_cv_CC_NEGATIVE_ENUM_VALUES=no)])
 if test x"$samba_cv_CC_NEGATIVE_ENUM_VALUES" != x"yes"; then
        AC_MSG_WARN([using --uint-enums for pidl])
        PIDL_ARGS="$PIDL_ARGS --uint-enums"
@@ -438,6 +457,9 @@ default_shared_modules="$default_shared_modules vfs_acl_tdb"
 default_shared_modules="$default_shared_modules vfs_smb_traffic_analyzer"
 default_shared_modules="$default_shared_modules vfs_preopen"
 default_shared_modules="$default_shared_modules vfs_catia"
+default_shared_modules="$default_shared_modules vfs_scannedonly"
+default_shared_modules="$default_shared_modules vfs_crossrename"
+default_shared_modules="$default_shared_modules vfs_linux_xfs_sgid"
 
 if test "x$developer" = xyes; then
    default_static_modules="$default_static_modules rpc_rpcecho pdb_ads"
@@ -707,7 +729,7 @@ AUTH_LIBS="${AUTH_LIBS} ${CRYPT_LIBS}"
 
 AC_CHECK_HEADERS(aio.h sys/fcntl.h sys/select.h fcntl.h sys/time.h sys/unistd.h rpc/nettype.h)
 AC_CHECK_HEADERS(unistd.h grp.h sys/id.h memory.h alloca.h)
-AC_CHECK_HEADERS(limits.h float.h pthread.h libintl.h)
+AC_CHECK_HEADERS(limits.h float.h libintl.h)
 AC_CHECK_HEADERS(rpc/rpc.h rpcsvc/nis.h rpcsvc/ypclnt.h)
 AC_CHECK_HEADERS(sys/param.h ctype.h sys/wait.h sys/resource.h sys/ioctl.h sys/ipc.h sys/prctl.h sys/sysctl.h)
 AC_CHECK_HEADERS(sys/mman.h sys/filio.h sys/priv.h sys/shm.h string.h strings.h stdlib.h)
@@ -795,15 +817,21 @@ if test x$enable_cups != xno; then
 
         if test "x$CUPS_CONFIG" != x; then
 
-               ac_save_CFLAGS=$CFLAGS
                ac_save_LDFLAGS=$LDFLAGS
                ac_save_PRINT_LIBS=$PRINT_LIBS
-               CFLAGS="$CFLAGS `$CUPS_CONFIG --cflags`"
-               LDFLAGS="$LDFLAGS `$CUPS_CONFIG --ldflags`"
-               PRINT_LIBS="$PRINT_LIBS -lcups"
                AC_CHECK_HEADERS(cups/cups.h cups/language.h)
+
                if test x"$ac_cv_header_cups_cups_h" = xyes -a \
                        x"$ac_cv_header_cups_language_h" = xyes; then
+                       # try linking with -lcups alone first. That should work unless libcups is
+                       # underlinked. With cups-config --libs we pull in unwanted and unneeded
+                       # dendencies including thread libraries - use cups-config only if really
+                       # required. 
+                       AC_CHECK_LIB_EXT(cups, ac_save_PRINT_LIBS , httpConnect,
+                               [PRINT_LIBS"$ac_save_PRINT_LIBS -lcups"],
+                               [AC_MSG_WARN([your cups library doesn't link with -lcups alone, it might be underlinked.]) ;
+                                PRINT_LIBS="$ac_save_PRINT_LIBS `$CUPS_CONFIG --libs`"])
+
                        AC_DEFINE(HAVE_CUPS,1,[Whether we have CUPS])
                        samba_cv_HAVE_CUPS=yes
                        AC_CHECK_LIB_EXT(cups, PRINT_LIBS, httpConnectEncrypt)
@@ -1052,7 +1080,8 @@ fi
 AC_CHECK_FUNCS(getcwd fchown chmod fchmod mknod mknod64)
 AC_CHECK_FUNCS(strtol)
 AC_CHECK_FUNCS(strchr chflags)
-AC_CHECK_FUNCS(getrlimit fsync fdatasync setpgid)
+AC_CHECK_FUNCS(getrlimit fsync setpgid)
+AC_CHECK_FUNCS(fdatasync,,[AC_CHECK_LIB_EXT(rt, LIBS, fdatasync)])
 AC_CHECK_FUNCS(setsid glob strpbrk crypt16 getauthuid)
 AC_CHECK_FUNCS(sigprocmask sigblock sigaction sigset innetgr setnetgrent getnetgrent endnetgrent)
 AC_CHECK_FUNCS(initgroups select poll rdchk getgrnam getgrent pathconf)
@@ -1066,7 +1095,7 @@ AC_CHECK_FUNCS(setenv strcasecmp fcvt fcvtl)
 AC_CHECK_FUNCS(syslog vsyslog timegm)
 AC_CHECK_FUNCS(setlocale nl_langinfo)
 AC_CHECK_FUNCS(nanosleep,,[AC_CHECK_LIB_EXT(rt, LIBS, nanosleep)])
-AC_CHECK_FUNCS(utimensat)
+AC_CHECK_FUNCS(lutimes futimes utimensat futimens)
 AC_CHECK_FUNCS(mlock munlock mlockall munlockall)
 AC_CHECK_FUNCS(memalign posix_memalign hstrerror)
 AC_CHECK_HEADERS(sys/mman.h)
@@ -1086,6 +1115,15 @@ AC_CHECK_LIB(exc, trace_back_stack)
 # check for sysctlbyname for BSD systems
 AC_CHECK_FUNCS(sysctlbyname)
 
+#################################################
+# Check to see if core dump directory is defined in linux
+# with /proc/sys/kernel/core_pattern
+
+AC_CHECK_FILE([/proc/sys/kernel/core_pattern],
+       AC_DEFINE(HAVE_SYS_KERNEL_PROC_CORE_PATTERN, 1,
+       [Whether Linux kernel uses core_pattern for core files]),
+        [])
+
 #############################
 # check if building with gpfs
 AC_CHECK_HEADERS(gpfs_gpl.h)
@@ -1244,7 +1282,7 @@ AC_DEFINE(HAVE_PRCTL, 1, [Whether prctl is available]),[])
 case "$host_os" in
     *linux* | gnu* | k*bsd*-gnu | kopensolaris*-gnu)
        # glibc <= 2.3.2 has a broken getgrouplist
-       AC_TRY_RUN([
+       AC_CACHE_CHECK([for good getgrouplist],samba_cv_linux_getgrouplist_ok,[AC_TRY_RUN([
 #include <unistd.h>
 #include <sys/utsname.h>
 main() {
@@ -1260,8 +1298,10 @@ main() {
 #endif
        exit(0);
 }
-], [linux_getgrouplist_ok=yes], [linux_getgrouplist_ok=no])
-       if test x"$linux_getgrouplist_ok" = x"yes"; then
+], [samba_cv_linux_getgrouplist_ok=yes],
+   [samba_cv_linux_getgrouplist_ok=no],
+   [samba_cv_linux_getgrouplist_ok=cross])])
+       if test x"$samba_cv_linux_getgrouplist_ok" = x"yes"; then
           AC_DEFINE(HAVE_GETGROUPLIST, 1, [Have good getgrouplist])
        fi
        ;;
@@ -1361,6 +1401,22 @@ if test x"$samba_cv_stat_dos_flags" = x"yes" ; then
     AC_DEFINE(HAVE_STAT_DOS_FLAGS, 1, [whether there is DOS flags support in the stat struct])
 fi
 
+AC_CACHE_CHECK([whether we can compile with __attribute__((destructor))],
+              samba_cv_function_attribute_destructor,
+              [
+                AC_COMPILE_IFELSE(
+                       [
+                               __attribute__((destructor))
+                               static void cleanup(void) { }
+                       ],
+                       samba_cv_function_attribute_destructor=yes)
+               ])
+
+if test x"$samba_cv_function_attribute_destructor" = xyes ; then
+   AC_DEFINE(HAVE_FUNCTION_ATTRIBUTE_DESTRUCTOR, 1,
+            [whether we can compile with __attribute__((destructor))])
+fi
+
 #####################################
 # needed for SRV lookups
 AC_CHECK_LIB(resolv, dn_expand)
@@ -1394,7 +1450,7 @@ AC_LIBTESTFUNC(sec, getprpwnam)
 AC_CHECK_FUNCS(strsignal)
 
 ############################################
-# Check if we have libattr
+# Check for EA implementations
 case "$host_os" in
   *osf*)
        AC_SEARCH_LIBS(getproplist, [proplist])
@@ -1402,24 +1458,27 @@ case "$host_os" in
        AC_CHECK_FUNCS(delproplist fdelproplist add_proplist_entry get_proplist_entry)
        AC_CHECK_FUNCS(sizeof_proplist_entry)
   ;;
-  *)
-       AC_SEARCH_LIBS(getxattr, [attr])
-       AC_CHECK_FUNCS(getxattr lgetxattr fgetxattr listxattr llistxattr)
-       AC_CHECK_FUNCS(getea fgetea lgetea listea flistea llistea)
-       AC_CHECK_FUNCS(removeea fremoveea lremoveea setea fsetea lsetea)
-       AC_CHECK_FUNCS(flistxattr removexattr lremovexattr fremovexattr)
-       AC_CHECK_FUNCS(setxattr lsetxattr fsetxattr)
-       AC_CHECK_FUNCS(attr_get attr_list attr_set attr_remove)
-       AC_CHECK_FUNCS(attr_getf attr_listf attr_setf attr_removef)
+  *freebsd4* | *dragonfly* )
+       AC_DEFINE(BROKEN_EXTATTR, 1, [Does extattr API work])
   ;;
-esac
-
-########################################################
-# Check if attropen() is present if this is Solaris
-case "$host_os" in
   *solaris*)
        AC_CHECK_FUNCS(attropen)
   ;;
+  *)
+       AC_SEARCH_LIBS(getxattr, [attr])
+       AC_CHECK_FUNCS(getxattr,[
+               AC_CHECK_FUNCS(lgetxattr fgetxattr listxattr llistxattr flistxattr removexattr lremovexattr fremovexattr setxattr lsetxattr fsetxattr)
+               ])
+       AC_CHECK_FUNCS(getea,[
+               AC_CHECK_FUNCS(fgetea lgetea listea flistea llistea removeea fremoveea lremoveea setea fsetea lsetea)
+               ])
+       AC_CHECK_FUNCS(attr_get,[
+               AC_CHECK_FUNCS(attr_list attr_set attr_remove attr_getf attr_listf attr_setf attr_removef)
+               ])
+       AC_CHECK_FUNCS(extattr_delete_file,[
+               AC_CHECK_FUNCS(extattr_delete_fd extattr_delete_link extattr_get_fd extattr_get_file extattr_get_link extattr_list_fd extattr_list_file extattr_list_link extattr_set_fd extattr_set_file extattr_set_link)
+               ])
+  ;;
 esac
 
 ########################################################
@@ -1446,19 +1505,6 @@ if test x"$ac_cv_func_getxattr" = x"yes" ; then
        fi
 fi
 
-# Check if we have extattr
-case "$host_os" in
-  *freebsd4* | *dragonfly* )
-    AC_DEFINE(BROKEN_EXTATTR, 1, [Does extattr API work])
-    ;;
-  *)
-    AC_CHECK_FUNCS(extattr_delete_fd extattr_delete_file extattr_delete_link)
-    AC_CHECK_FUNCS(extattr_get_fd extattr_get_file extattr_get_link)
-    AC_CHECK_FUNCS(extattr_list_fd extattr_list_file extattr_list_link)
-    AC_CHECK_FUNCS(extattr_set_fd extattr_set_file extattr_set_link)
-    ;;
-esac
-
 AC_DISABLE_STATIC
 AC_ENABLE_SHARED
 
@@ -1473,9 +1519,9 @@ then
        [
                cat > conftest.c <<EOF
 int foo;
-main () { return 0;}
+int main () { return 0;}
 EOF
-               if AC_TRY_COMMAND([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -pie -fPIE -o conftest conftest.c 1>&AS_MESSAGE_LOG_FD])
+               if AC_TRY_COMMAND_NO_STDERR([${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS -pie -fPIE -o conftest conftest.c])
                then
                        samba_cv_fpie=yes
                else
@@ -1558,19 +1604,21 @@ DSO_EXPORTS=""
                        ;;
                *solaris*) AC_DEFINE(SUNOS5,1,[Whether the host os is solaris])
                        BLDSHARED="true"
-                       LDSHFLAGS="-G"
-                       SONAMEFLAG="-h "
                        if test "${GCC}" = "yes"; then
                                PICFLAG="-fPIC"
                                SONAMEFLAG="-Wl,-soname="
                                if test "${ac_cv_prog_gnu_ld}" = "yes"; then
                                        DYNEXP="-Wl,-E"
                                fi
+                               LDSHFLAGS="-shared"
                        else
                                PICFLAG="-KPIC"
-                               ## ${CFLAGS} added for building 64-bit shared
-                               ## libs using Sun's Compiler
-                               LDSHFLAGS="-G \${CFLAGS}"
+                               LDSHFLAGS="-G"
+                       fi
+                       if test "$ac_cv_prog_gnu_ld" = "yes"; then
+                               SONAMEFLAG="-Wl,-soname="
+                       else
+                               SONAMEFLAG="-Wl,-h,"
                        fi
                        AC_DEFINE(STAT_ST_BLOCKSIZE,512,[The size of a block])
                        AC_DEFINE(BROKEN_GETGRNAM,1,[Does getgrnam work correctly])
@@ -1606,9 +1654,8 @@ DSO_EXPORTS=""
                        ;;
                        esac
                        BLDSHARED="true"
-                       LDSHFLAGS="-set_version sgi1.0 -shared"
-                       SONAMEFLAG="-soname "
-                       SHLD="\${LD}"
+                       LDSHFLAGS="-Wl,-set_version,sgi1.0 -shared"
+                       SONAMEFLAG="-Wl,-soname,"
                        if test "${GCC}" = "yes"; then
                                PICFLAG="-fPIC"
                        else
@@ -1627,7 +1674,7 @@ DSO_EXPORTS=""
                        # .po will just create compile warnings, use po.o:
                        if test "${GCC}" != "yes"; then
                                ## for funky AIX compiler using strncpy()
-                               CFLAGS="$CFLAGS -D_LINUX_SOURCE_COMPAT -qmaxmem=32000"
+                               CFLAGS="$CFLAGS -D_LINUX_SOURCE_COMPAT -qmaxmem=32000 -qhalt=e"
                        fi
 
                        AC_DEFINE(STAT_ST_BLOCKSIZE,DEV_BSIZE,[The size of a block])
@@ -1635,25 +1682,45 @@ DSO_EXPORTS=""
                        AC_DEFINE(BROKEN_STRNDUP,1,[Does strndup work correctly])
                        ;;
                *hpux*) AC_DEFINE(HPUX,1,[Whether the host os is HPUX])
-                       # Use special PIC flags for the native HP-UX compiler.
-                               BLDSHARED="true"
-                               SHLD="cc"
-                               LDSHFLAGS="-b -Wl,-B,symbolic,-b,-z"
-                               SONAMEFLAG="-Wl,+h "
-                               PICFLAG="+z"
+                       # ia64: 64bit build using gcc with CFLAGS="-mpl64"
+                       #       64bit build using HP's cc with CFLAGS="+DD64"
+                       # hppa: 64bit build unsupported by gcc
+                       #       64bit build using HP's cc with CFLAGS="+DA2.0w"
+                       # HP-UX 11.00 ld needs PHSS_33034
+                       BLDSHARED="true"
                        if test "${GCC}" = "yes"; then
                                PICFLAG="-fPIC"
+                               LDSHFLAGS="-shared"
                        else
-                               PICFLAG="+z +ESnolit"
+                               PICFLAG="+z"
+                               LDSHFLAGS="-b"
+                               # "Uses depth-first symbol resolution"
+                               LDSHFLAGS="$LDSHFLAGS -Wl,-B,symbolic,-b"
+                               if test "$host_cpu" != "ia64"; then
+                                       # "don't store literals in read-only memory" (?):
+                                       PICFLAG="$PICFLAG +ESnolit"
+                               fi
                        fi
                        if test "$host_cpu" = "ia64"; then
                                SHLIBEXT="so"
-                             PICFLAG="+z"
-                               DYNEXP="-Wl,-E,+b/usr/local/lib/hpux32:/usr/lib/hpux32"
+                               # TODO: does the linker find the right 32/64 bit version of the libs? :
+                               DYNEXP="-Wl,-E,+b/usr/local/lib/hpux32:/usr/lib/hpux32:/usr/local/lib/hpux64:/usr/lib/hpux64"
                        else
                                SHLIBEXT="sl"
                                DYNEXP="-Wl,-E,+b/usr/local/lib:/usr/lib"
                        fi
+                       if test "$ac_cv_prog_gnu_ld" = "yes"; then
+                               SONAMEFLAG="-Wl,-soname="
+                       else
+                               SONAMEFLAG="-Wl,+h,"
+                       fi
+                       # PIE/PIC flags at link time are required on HP-UX because
+                       # linking requires a temporary source file, which is being
+                       # compiled with the indicated flags - which need to contain
+                       # PIC flags when we don't support PIE flags:
+                       if test "$PIE_LDFLAGS" = "" ; then
+                               PIE_LDFLAGS=\${PICFLAG}
+                       fi
                        AC_DEFINE(STAT_ST_BLOCKSIZE,8192,[The size of a block])
                        AC_DEFINE(POSIX_ACL_NEEDS_MASK,1,[Does a POSIX ACL need a mask element])
                        ;;
@@ -1664,6 +1731,17 @@ DSO_EXPORTS=""
                        PICFLAG="-fPIC"
                        AC_DEFINE(STAT_ST_BLOCKSIZE,512)
                        AC_DEFINE(BROKEN_GETGRNAM,1,[Does getgrnam work correctly])
+                       for flags in "-expect_unresolved '*'" "-Wl,-expect_unresolved,'*'" ; do
+                               saved_ldflags="$LDFLAGS"
+                               AC_MSG_CHECKING([if $flags works])
+                               LDFLAGS="$flags $saved_ldflags"
+                               AC_TRY_LINK([],[],
+                                       [AC_MSG_RESULT([yes])
+                                       LDSHFLAGS_Z_NODEFS=$flags],
+                                       AC_MSG_RESULT([no]))
+                               LDFLAGS="$saved_ldflags"
+                               test x"$LDSHFLAGS_Z_NODEFS" != x && break
+                       done
                        ;;
                *sco*) AC_DEFINE(SCO,1,[Whether the host os is sco unix])
                        AC_DEFINE(STAT_ST_BLOCKSIZE,512)
@@ -1741,7 +1819,19 @@ fi
 
 AC_MSG_RESULT($BLDSHARED)
 
-for flags in "-Wl,--as-needed" "-Wl,-z,ignore" "-z ignore" ; do
+if test x"$enable_developer" = x"yes" ; then
+       default_as_needed=auto
+else
+       default_as_needed=no
+fi
+AC_ARG_ENABLE(as-needed,
+       AS_HELP_STRING([--enable-as-needed],
+       [Turn on as-needed support if available (default=no)]),
+       [enable_as_needed=$enableval],
+       [enable_as_needed=$default_as_needed])
+if test "x$enable_as_needed" != xno; then
+    saved_before_as_needed_ldflags="$LDFLAGS"
+    for flags in "-Wl,--as-needed" "-Wl,-z,ignore" "-z ignore" ; do
        saved_ldflags="$LDFLAGS"
        AC_MSG_CHECKING([if $flags works])
        LDFLAGS="$flags $saved_ldflags"
@@ -1752,7 +1842,65 @@ for flags in "-Wl,--as-needed" "-Wl,-z,ignore" "-z ignore" ; do
                AC_MSG_RESULT([no]))
        LDFLAGS="$LD_AS_NEEDED_FLAG $saved_ldflags"
        test x"$ld_as_needed_flag_found" = xyes && break
-done
+    done
+fi
+
+if test x$ld_as_needed_flag_found = xyes -a x$enable_as_needed = xauto ; then
+# check if ld has bug described in https://bugzilla.samba.org/show_bug.cgi?id=7209#c17
+       AC_MSG_CHECKING([if $LD_AS_NEEDED_FLAG has explicit external libs bug])
+cat > conftest_shb.c <<END
+void b() {}
+END
+cat > conftest_sha.c <<END
+extern void b();
+void a() {
+       b();
+}
+END
+cat > conftest.c <<END
+extern void a();
+int main() {
+       a();
+       return 0;
+}
+END
+
+       rm -fr conftest
+       AC_TRY_COMMAND([$CC $CPPFLAGS $CFLAGS $PICFLAG -c -o conftest_sha.o conftest_sha.c 1>&AS_MESSAGE_LOG_FD 2>&1])
+       AC_TRY_COMMAND([$CC $CPPFLAGS $CFLAGS $PICFLAG -c -o conftest_shb.o conftest_shb.c 1>&AS_MESSAGE_LOG_FD 2>&1])
+       TESTCMD="`eval echo \"$SHLD $LDSHFLAGS $PICFLAG\"`"
+       AC_TRY_COMMAND([$TESTCMD -o libconftest_shb.$SHLIBEXT conftest_shb.o 1>&AS_MESSAGE_LOG_FD 2>&1])
+       AC_TRY_COMMAND([$TESTCMD -o libconftest_sha.$SHLIBEXT conftest_sha.o 1>&AS_MESSAGE_LOG_FD 2>&1])
+       AC_TRY_COMMAND([$CC -o conftest conftest.c $LDFLAGS -L. -lconftest_sha -lconftest_shb 1>&AS_MESSAGE_LOG_FD 2>&1])
+       if AC_TRY_COMMAND([eval "$LIB_PATH_VAR=. ./conftest 1>&AS_MESSAGE_LOG_FD 2>&1"])
+       then
+               AC_MSG_RESULT([no])
+       else
+               ld_as_needed_flag_found=no
+               LDFLAGS="$saved_before_as_needed_ldflags"
+               AC_MSG_RESULT([yes])
+       fi
+       rm conftest* libconftest*
+fi
+
+# check if we have to disable LD_AS_NEEDED_FLAG:
+# On some systems for a veriety of reasons linking with
+# -Wl,--as-needed -lreadline -lncurses fails
+# we have to retest, if these combination is detected before.
+# Bugzilla #7209
+
+if test x$ac_cv_lib_readline_rl_callback_handler_install = xyes ; then
+       if test x$ld_as_needed_flag_found = xyes ; then
+               AC_MSG_CHECKING([if $LD_AS_NEEDED_FLAG works with readline])
+               # try if check no fails
+               save_LIBS=$LIBS
+               LIBS="$LIBS $TERMLIBS"
+               AC_TRY_LINK([], [rl_callback_handler_install();], [AC_MSG_RESULT([yes])],[ AC_MSG_RESULT([no]); LDFLAGS="$saved_before_as_needed_ldflags"])
+               LIBS="$save_LIBS"
+        fi
+fi
+
+
 
 # for historical reasons almost all linkers don't complain about unresolved
 # symbols in shared libs. Except for the internal samba modules we want to get
@@ -1806,10 +1954,15 @@ AC_CACHE_CHECK([whether building shared libraries actually works],
    ac_cv_shlib_works=no
    # The $SHLD and $LDSHFLAGS variables may contain references to other
    # variables so they need to be eval'ed.
-   $CC $CPPFLAGS $CFLAGS $PICFLAG -c -o \
-       shlib.o ${srcdir-.}/../tests/shlib.c && \
-   `eval echo $SHLD` `eval echo $LDSHFLAGS` -o "shlib.$SHLIBEXT" \
-        shlib.o && ac_cv_shlib_works=yes
+   if AC_TRY_COMMAND([$CC $CPPFLAGS $CFLAGS $PICFLAG -c -o shlib.o ${srcdir-.}/../tests/shlib.c 1>&AS_MESSAGE_LOG_FD])
+   then
+     TESTCMD="`eval echo \"$SHLD $LDSHFLAGS $PICFLAG\"`"
+     TESTCMD="$TESTCMD -o \"shlib.$SHLIBEXT\" shlib.o"
+     if AC_TRY_COMMAND([eval $TESTCMD 1>&AS_MESSAGE_LOG_FD 2>&1])
+     then
+       ac_cv_shlib_works=yes
+     fi
+   fi
    rm -f "shlib.$SHLIBEXT" shlib.o
 
 ])
@@ -1833,7 +1986,6 @@ AC_MSG_RESULT([$PICFLAG])
 
 AC_DEFINE_UNQUOTED(SHLIBEXT, "$SHLIBEXT", [Shared library extension])
 
-AC_LIBREPLACE_RUNTIME_LIB_PATH_VAR
 
 
 ###########################################################
@@ -1971,7 +2123,7 @@ AC_ARG_ENABLE(external_libtdb,
 
 if test "x$enable_external_libtdb" != xno
 then
-       PKG_CHECK_MODULES(LIBTDB, tdb >= 1.1.4,
+       PKG_CHECK_MODULES(LIBTDB, tdb >= 1.2.2,
                [ enable_external_libtdb=yes ],
                [
                if test x$enable_external_libtdb = xyes; then
@@ -1989,6 +2141,7 @@ then
        LINK_LIBTDB=STATIC
        SMB_LIBRARY(tdb, 1)
        LIBTDB_OBJ0=""
+       LIBTDB_LIBS="$LIBTDB_LIBS $TDB_DEPS"
        for obj in ${TDB_OBJ}; do
                LIBTDB_OBJ0="${LIBTDB_OBJ0} ${tdbdir}/${obj}"
        done
@@ -2216,15 +2369,6 @@ if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
     AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
 fi
 
-AC_CACHE_CHECK([if gettimeofday takes tz argument],samba_cv_HAVE_GETTIMEOFDAY_TZ,[
-AC_TRY_LINK([
-#include <sys/time.h>
-#include <unistd.h>], [struct timeval tv; return gettimeofday(&tv, NULL);],
-           samba_cv_HAVE_GETTIMEOFDAY_TZ=yes,
-          samba_cv_HAVE_GETTIMEOFDAY_TZ=no)])
-if test x"$samba_cv_HAVE_GETTIMEOFDAY_TZ" = x"yes"; then
-    AC_DEFINE(HAVE_GETTIMEOFDAY_TZ,1,[Whether gettimeofday takes a tz argument])
-fi
 
 if test x"$samba_cv_WITH_PROFILE" = x"yes"; then
 
@@ -2272,7 +2416,7 @@ dnl  We need to check for many of them
 dnl  But we don't need to do each and every one, because our code uses
 dnl  mostly just the utmp (not utmpx) fields.
 
-AC_CHECK_FUNCS(pututline pututxline updwtmp updwtmpx getutmpx)
+AC_CHECK_FUNCS(pututline pututxline updwtmp updwtmpx getutmpx getutxent)
 
 AC_CACHE_CHECK([for ut_name in utmp],samba_cv_HAVE_UT_UT_NAME,[
 AC_TRY_COMPILE([#include <sys/types.h>
@@ -2647,18 +2791,19 @@ if test x$enable_fam != xno; then
         # On IRIX, libfam requires libC, but other FAM implementations
        # might not need it.
         AC_CHECK_LIB(fam, FAMOpen2,
-            [samba_cv_HAVE_LIBFAM=yes; SMB_FAM_LIBS="-lfam"],
-            [samba_cv_HAVE_LIBFAM=no])
+           [samba_cv_HAVE_LIBFAM=yes; SMB_FAM_LIBS="-lfam";
+           AC_DEFINE(HAVE_FAMOPEN2, 1, Define to 1 if there is support for FAMOpen2)],
+           [samba_cv_HAVE_LIBFAM=no])
 
         if test x"$samba_cv_HAVE_LIBFAM" = x"no" ; then
             samba_fam_xtra=-lC
             AC_CHECK_LIB_EXT(fam, samba_fam_xtra, FAMOpen2,
-                [samba_cv_HAVE_LIBFAM=yes; SMB_FAM_LIBS="-lfam -lC"],
-                [samba_cv_HAVE_LIBFAM=no])
+               [samba_cv_HAVE_LIBFAM=yes; SMB_FAM_LIBS="-lfam -lC";
+               AC_DEFINE(HAVE_FAMOPEN2, 1, Define to 1 if there is support for FAMOpen2)],
+               [samba_cv_HAVE_LIBFAM=no])
             unset samba_fam_xtra
         fi
     fi
-
     if test x"$samba_cv_HAVE_LIBFAM" = x"yes" ; then
         default_shared_modules="$default_shared_modules vfs_notify_fam"
         AC_TRY_COMPILE([#include <fam.h>],
@@ -2668,6 +2813,11 @@ if test x$enable_fam != xno; then
                     [])
     fi
 
+    if test x"$samba_cv_HAVE_LIBFAM" = x"yes" ; then
+       AC_CHECK_LIB(fam, FAMNoExists,
+           [AC_DEFINE(HAVE_FAMNOEXISTS, 1, Define to 1 if there is support for FAMNoExists)])
+    fi
+
     if test x$enable_fam = xyes && test x"$samba_cv_HAVE_LIBFAM" != xyes ; then
         AC_MSG_ERROR(FAM support requested but FAM library not available )
     fi
@@ -2678,11 +2828,32 @@ AC_SUBST(SMB_FAM_LIBS)
 #################################################
 # Check for DMAPI interfaces in libdm/libjfsdm/libxsdm
 
-SMB_CHECK_DMAPI([], AC_MSG_NOTICE(DMAPI support not present) )
+
+with_dmapi_support=auto
+AC_MSG_CHECKING(whether to use DMAPI support)
+AC_ARG_WITH(dmapi,
+[AS_HELP_STRING([--with-dmapi], [Include DMAPI/XDSM support (default=auto)])],
+[ case "$withval" in
+  yes|no)
+    with_dmapi_support=$withval
+    ;;
+  esac ]
+)
+AC_MSG_RESULT([$with_dmapi_support])
+
+if test x"$with_dmapi_support" != xno ; then
+       SMB_CHECK_DMAPI([], [
+               AC_MSG_NOTICE(DMAPI support not present)
+               if test x"$with_dmapi_support" = xyes ; then
+                       AC_MSG_ERROR(no DMAPI support found but requested!)
+               fi
+               ]
+       )
+fi
 
 # Add TSM SM VFS module only if there are both GPFS and DMAPI support
 # Theoretically it should work with AIX JFS2 too but this needs testing
-if test x"$samba_cv_HAVE_GPFS" = x"yes" && test x"$samba_dmapi_libs" != x"" ; then
+if test x"$ac_cv_header_gpfs_gpl_h" = x"yes" && test x"$samba_dmapi_libs" != x"" ; then
     default_shared_modules="$default_shared_modules vfs_tsmsm"
 fi
 
@@ -2977,6 +3148,22 @@ exit(1);
   fi
 fi
 
+# glibc up to 2.3.6 had dangerously broken posix_fallocate(). DON'T USE IT.
+AC_CACHE_CHECK([for broken posix_fallocate],samba_cv_HAVE_BROKEN_POSIX_FALLOCATE,[
+AC_TRY_COMPILE([
+  #define _XOPEN_SOURCE 600
+  #include <stdlib.h>
+  #if defined(__GLIBC__) && ((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 4))
+    probably broken posix_fallocate
+  #endif
+], [
+], 
+samba_cv_HAVE_BROKEN_POSIX_FALLOCATE=no,samba_cv_HAVE_BROKEN_POSIX_FALLOCATE=yes)])
+if test x"$samba_cv_HAVE_BROKEN_POSIX_FALLOCATE" = xyes; then
+       AC_DEFINE(HAVE_BROKEN_POSIX_FALLOCATE,, Whether we have a broken posix_fallocate)
+fi
+
+
 AC_CACHE_CHECK([for st_blocks in struct stat],samba_cv_HAVE_STAT_ST_BLOCKS,[
 AC_TRY_COMPILE([#include <sys/types.h>
 #include <sys/stat.h>
@@ -3175,7 +3362,7 @@ with_ldap_support=auto
 AC_MSG_CHECKING([for LDAP support])
 
 AC_ARG_WITH(ldap,
-[AS_HELP_STRING([--with-ldap], [LDAP support (default yes)])],
+[AS_HELP_STRING([--with-ldap], [LDAP support (default=auto)])],
 [ case "$withval" in
     yes|no)
        with_ldap_support=$withval
@@ -3188,8 +3375,6 @@ SMBLDAP=""
 AC_SUBST(SMBLDAP)
 SMBLDAPUTIL=""
 AC_SUBST(SMBLDAPUTIL)
-LDBLDAP=""
-AC_SUBST(LDBLDAP)
 
 if test x"$with_ldap_support" != x"no"; then
 
@@ -3325,7 +3510,7 @@ with_ads_support=auto
 AC_MSG_CHECKING([for Active Directory and krb5 support])
 
 AC_ARG_WITH(ads,
-[AS_HELP_STRING([--with-ads], [Active Directory support (default auto)])],
+[AS_HELP_STRING([--with-ads], [Active Directory support (default=auto)])],
 [ case "$withval" in
     yes|no)
        with_ads_support="$withval"
@@ -3575,7 +3760,7 @@ if test x"$with_ads_support" != x"no"; then
 
   # now check for gssapi headers.  This is also done here to allow for
   # different kerberos include paths
-  AC_CHECK_HEADERS(gssapi.h gssapi/gssapi_generic.h gssapi/gssapi.h com_err.h)
+  AC_CHECK_HEADERS(gssapi.h gssapi/gssapi_generic.h gssapi/gssapi.h gssapi/gssapi_ext.h com_err.h)
 
   ##################################################################
   # we might need the k5crypto and com_err libraries on some systems
@@ -3600,6 +3785,7 @@ if test x"$with_ads_support" != x"no"; then
   # now see if we can find the gssapi libs in standard paths
   if test x"$have_gssapi" != x"yes"; then
      AC_CHECK_LIB_EXT(gssapi_krb5, KRB5_LIBS,gss_display_status,[],[],have_gssapi=yes)
+     AC_CHECK_FUNC_EXT(gss_wrap_iov, $KRB5_LIBS)
   fi
 
   AC_CHECK_FUNC_EXT(krb5_set_real_time, $KRB5_LIBS)
@@ -3649,6 +3835,9 @@ if test x"$with_ads_support" != x"no"; then
   AC_CHECK_FUNC_EXT(krb5_get_creds_opt_set_impersonate, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_get_creds, $KRB5_LIBS)
   AC_CHECK_FUNC_EXT(krb5_get_credentials_for_user, $KRB5_LIBS)
+  AC_CHECK_FUNC_EXT(krb5_get_host_realm, $KRB5_LIBS)
+  AC_CHECK_FUNC_EXT(krb5_free_host_realm, $KRB5_LIBS)
+
   # MIT krb5 1.8 does not expose this call (yet)
   AC_CHECK_DECLS(krb5_get_credentials_for_user, [], [], [#include <krb5.h>])
 
@@ -3855,6 +4044,7 @@ if test x"$with_ads_support" != x"no"; then
               [Whether the krb5_keyblock struct has a keyvalue property])
   fi
 
+  found_arcfour_hmac=no
   AC_CACHE_CHECK([for ENCTYPE_ARCFOUR_HMAC_MD5],
                  samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5,[
     AC_TRY_COMPILE([#include <krb5.h>],
@@ -3872,7 +4062,19 @@ if test x"$with_ads_support" != x"no"; then
   if test x"$samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC_MD5" = x"yes" -a\
           x"$samba_cv_HAVE_KEYTYPE_ARCFOUR_56" = x"yes"; then
     AC_DEFINE(HAVE_ENCTYPE_ARCFOUR_HMAC_MD5,1,
-              [Whether the ENCTYPE_ARCFOUR_HMAC_MD5 key type is available])
+              [Whether the ENCTYPE_ARCFOUR_HMAC_MD5 key type definition is available])
+    found_arcfour_hmac=yes
+  fi
+  AC_CACHE_CHECK([for ENCTYPE_ARCFOUR_HMAC],
+                 samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC,[
+    AC_TRY_COMPILE([#include <krb5.h>],
+      [krb5_enctype enctype; enctype = ENCTYPE_ARCFOUR_HMAC;],
+      samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC=yes,
+      samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC=no)])
+  if test x"$samba_cv_HAVE_ENCTYPE_ARCFOUR_HMAC" = x"yes"; then
+    AC_DEFINE(HAVE_ENCTYPE_ARCFOUR_HMAC,1,
+              [Whether the ENCTYPE_ARCFOUR_HMAC key type definition is available])
+    found_arcfour_hmac=yes
   fi
 
   AC_CACHE_CHECK([for AP_OPTS_USE_SUBKEY],
@@ -3991,6 +4193,18 @@ if test x"$with_ads_support" != x"no"; then
                [Whether the WRFILE:-keytab is supported])
   fi
 
+  AC_CACHE_CHECK([for krb5_realm type],
+                samba_cv_HAVE_KRB5_REALM_TYPE,[
+    AC_TRY_COMPILE([#include <krb5.h>],
+      [krb5_realm realm;],
+      samba_cv_HAVE_KRB5_REALM_TYPE=yes,
+      samba_cv_HAVE_KRB5_REALM_TYPE=no)])
+
+  if test x"$samba_cv_HAVE_KRB5_REALM_TYPE" = x"yes"; then
+    AC_DEFINE(HAVE_KRB5_REALM_TYPE,1,
+               [Whether the type krb5_realm exists])
+  fi
+
   AC_CACHE_CHECK([for krb5_princ_realm returns krb5_realm or krb5_data],
                samba_cv_KRB5_PRINC_REALM_RETURNS_REALM,[
     AC_TRY_COMPILE([#include <krb5.h>],
@@ -4103,6 +4317,11 @@ if test x"$with_ads_support" != x"no"; then
   # NOTE: all tests should be done before this block!
   #
   #
+  if test x"$found_arcfour_hmac" != x"yes"; then
+    AC_MSG_WARN(arcfour-hmac-md5 encryption type not found in -lkrb5)
+    use_ads=no
+  fi
+
   if test x"$ac_cv_lib_ext_krb5_krb5_mk_req_extended" != x"yes"; then
     AC_MSG_WARN(krb5_mk_req_extended not found in -lkrb5)
     use_ads=no
@@ -4191,11 +4410,11 @@ PASSDB_LIBS="$PASSDB_LIBS $NSCD_LIBS"
 ########################################################
 # Compile with DNS Updates support?
 
-with_dnsupdate_support=no
+with_dnsupdate_support=auto
 AC_MSG_CHECKING([whether to enable DNS Updates support])
 
 AC_ARG_WITH(dnsupdate,
-[AS_HELP_STRING([--with-dnsupdate], [Enable DNS Updates support (default no)])],
+[AS_HELP_STRING([--with-dnsupdate], [Enable DNS Updates support (default=auto)])],
 [ case "$withval" in
     yes|no)
        with_dnsupdate_support=$withval
@@ -4207,24 +4426,29 @@ AC_MSG_RESULT($with_dnsupdate_support)
 if test x"$with_dnsupdate_support" != x"no"; then
 
   ################################################################
-  # first test for Active Directory support being enabled
-  #if test x"$with_ads_support" = x"no"; then
-  #            AC_MSG_ERROR(Active Directory support is required to enable DNS Update support)
-  #            with_dnsupdate_support=no
-  #fi          
+  # first test for AD / GSSAPI support being enabled
+       if test x"$have_gssapi" != xyes ; then
+               if test x"$with_dnsupdate_support" = x"yes" ; then
+                       AC_MSG_ERROR(DNS Updates support only possible with AD and GSSAPI support)
+               else
+                       AC_MSG_NOTICE(DNS Updates support only possible with AD and GSSAPI support)
+                       with_dnsupdate_support=no
+               fi
+       fi
   ##################################################################
   # then test for uuid.h (necessary to generate unique DNS keynames
   # (uuid.h is required for this test)
-  AC_CHECK_HEADERS(uuid/uuid.h)
+       AC_CHECK_HEADERS(uuid/uuid.h)
 
-  if test x"$ac_cv_header_uuid_uuid_h" != x"yes"; then
-       if test x"$with_dnsupdate_support" = x"yes"; then
-        AC_MSG_ERROR(uuid.h is needed to enable DNS Updates support)
-       else
-        AC_MSG_WARN(uuid.h is needed to enable DNS Updates support)
+       
+       if test x"$ac_cv_header_uuid_uuid_h" != x"yes"; then
+               if test x"$with_dnsupdate_support" = x"yes"; then
+                       AC_MSG_ERROR(uuid.h is needed to enable DNS Updates support)
+               else
+                       AC_MSG_NOTICE(uuid.h is needed to enable DNS Updates support)
+               fi
+               with_dnsupdate_support=no
        fi
-       with_dnsupdate_support=no
-  fi
 fi
 
 if test x"$with_dnsupdate_support" != x"no"; then
@@ -4256,6 +4480,10 @@ if test x"$with_dnsupdate_support" != x"no"; then
            with_dnsupdate_support=no
        ])
 fi
+  # finally print out the result:
+AC_MSG_CHECKING(whether DNS Updates support is used)
+AC_MSG_RESULT([$with_dnsupdate_support])
+
 
 #################################################
 # check for automount support
@@ -4274,130 +4502,6 @@ AC_ARG_WITH(automount,
   AC_MSG_RESULT(no)
 )
 
-#################################################
-# check for mount- and umount.cifs support
-CIFSMOUNT_PROGS=""
-INSTALL_CIFSMOUNT=""
-UNINSTALL_CIFSMOUNT=""
-AC_MSG_CHECKING(whether to build mount.cifs)
-AC_ARG_WITH(cifsmount,
-[AS_HELP_STRING([--with-cifsmount], [Include mount.cifs (Linux only) support (default=yes)])],
-[ case "$withval" in
-  no)
-       AC_MSG_RESULT(no)
-       ;;
-  *)
-       case "$host_os" in
-       *linux*)
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(WITH_CIFSMOUNT,1,[Whether to build mount.cifs])
-               CIFSMOUNT_PROGS="bin/mount.cifs"
-               INSTALL_CIFSMOUNT="installcifsmount"
-               UNINSTALL_CIFSMOUNT="uninstallcifsmount"
-               ;;
-       *)
-               AC_MSG_ERROR(not on a linux system!)
-               ;;
-       esac
-    ;;
-  esac ],
-[ case "$host_os" in
-  *linux*)
-       AC_MSG_RESULT(yes)
-       AC_DEFINE(WITH_CIFSMOUNT,1,[Whether to build mount.cifs])
-       CIFSMOUNT_PROGS="bin/mount.cifs"
-       INSTALL_CIFSMOUNT="installcifsmount"
-       UNINSTALL_CIFSMOUNT="uninstallcifsmount"
-       ;;
-  *)
-       AC_MSG_RESULT(no)
-       ;;
-  esac ]
-)
-
-CIFSUMOUNT_PROGS=""
-INSTALL_CIFSUMOUNT=""
-UNINSTALL_CIFSUMOUNT=""
-AC_MSG_CHECKING(whether to build umount.cifs)
-AC_ARG_WITH(cifsumount,
-[AS_HELP_STRING([--with-cifsumount], [Include umount.cifs (Linux only) support (default=no)])],
-[ case "$withval" in
-  yes)
-       case "$host_os" in
-       *linux*)
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(WITH_CIFSUMOUNT,1,[Whether to build umount.cifs])
-               CIFSUMOUNT_PROGS="bin/umount.cifs"
-               INSTALL_CIFSUMOUNT="installcifsumount"
-               UNINSTALL_CIFSUMOUNT="uninstallcifsumount"
-               ;;
-       *)
-               AC_MSG_ERROR(not on a linux system!)
-               ;;
-       esac
-       ;;
-  *)
-       AC_MSG_RESULT(no)
-       ;;
-  esac ],
-  AC_MSG_RESULT(no)
-)
-
-#################################################
-# check for cifs.upcall support
-AC_CHECK_HEADERS([keyutils.h], [HAVE_KEYUTILS_H=1], [HAVE_KEYUTILS_H=0])
-CIFSUPCALL_PROGS=""
-INSTALL_CIFSUPCALL=""
-UNINSTALL_CIFSUPCALL=""
-AC_MSG_CHECKING(whether to build cifs.upcall)
-AC_ARG_WITH(cifsupcall,
-[AS_HELP_STRING([--with-cifsupcall], [Include cifs.upcall (Linux only) support (default=yes)])],
-[ case "$withval" in
-  no)
-       AC_MSG_RESULT(no)
-       ;;
-  *)
-       case "$host_os" in
-       *linux*)
-               if test x"$use_ads" != x"yes"; then
-                       AC_MSG_ERROR(ADS support should be enabled for building cifs.upcall)
-               elif test x"$HAVE_KEYUTILS_H" != "x1"; then
-                       AC_MSG_ERROR(keyutils package is required for cifs.upcall)
-               else
-                       AC_MSG_RESULT(yes)
-                       AC_DEFINE(WITH_CIFSUPCALL,1,[whether to build cifs.upcall])
-                       CIFSUPCALL_PROGS="bin/cifs.upcall"
-                       INSTALL_CIFSUPCALL="installcifsupcall"
-                       UNINSTALL_CIFSUPCALL="uninstallcifsupcall"
-               fi
-               ;;
-       *)
-               AC_MSG_ERROR(not on a linux system!)
-               ;;
-       esac
-    ;;
-  esac ],
-[ case "$host_os" in
-  *linux*)
-       if test x"$use_ads" != x"yes"; then
-               AC_MSG_WARN(ADS support should be enabled for building cifs.upcall)
-       elif test x"$HAVE_KEYUTILS_H" != "x1"; then
-               AC_MSG_WARN(keyutils package is required for cifs.upcall)
-       else
-               AC_MSG_RESULT(yes)
-               AC_DEFINE(WITH_CIFSUPCALL,1,[whether to build cifs.upcall])
-               CIFSUPCALL_PROGS="bin/cifs.upcall"
-               INSTALL_CIFSUPCALL="installcifsupcall"
-               UNINSTALL_CIFSUPCALL="uninstallcifsupcall"
-       fi
-       ;;
-  *)
-       AC_MSG_RESULT(no)
-       ;;
-  esac ]
-)
-
-
 #################################################
 # Check for a PAM clear-text auth, accounts, password
 # and session support. Most PAM implementations keep their
@@ -4482,8 +4586,64 @@ if test x"${try_pam}" != x"no";then
 
        AC_MSG_CHECKING(whether to have PAM MODULES support)
        AC_MSG_RESULT([$create_pam_modules])
+
+       AC_TRY_COMPILE([
+               #if defined(HAVE_SECURITY_PAM_APPL_H)
+               #include <security/pam_appl.h>
+               #elif defined(HAVE_PAM_PAM_APPL_H)
+               #include <pam/pam_appl.h>
+               #endif],[
+               pam_set_item(0, PAM_RHOST, 0);
+               ],
+               AC_DEFINE(HAVE_PAM_RHOST, 1,
+                         [Define to 1 if PAM_RHOST is available]),[])
+
+       AC_TRY_COMPILE([
+               #if defined(HAVE_SECURITY_PAM_APPL_H)
+               #include <security/pam_appl.h>
+               #elif defined(HAVE_PAM_PAM_APPL_H)
+               #include <pam/pam_appl.h>
+               #endif],[
+               pam_set_item(0, PAM_TTY, 0);
+               ],
+               AC_DEFINE(HAVE_PAM_TTY, 1,
+                         [Define to 1 if PAM_TTY is available]),[])
+
 fi # try_pam != no
 
+#################################################
+# check for PAM_RADIO_TYPE
+AC_TRY_COMPILE([
+#if (!defined(LINUX))
+
+#define PAM_EXTERN extern
+#if defined(HAVE_SECURITY_PAM_APPL_H)
+#include <security/pam_appl.h>
+#elif defined(HAVE_PAM_PAM_APPL_H)
+#include <pam/pam_appl.h>
+#endif
+
+#endif
+
+#if defined(HAVE_SECURITY_PAM_MODULES_H)
+#include <security/pam_modules.h>
+#elif defined(HAVE_PAM_PAM_MODULES_H)
+#include <pam/pam_modules.h>
+#endif
+
+#if defined(HAVE_SECURITY__PAM_MACROS_H)
+#include <security/_pam_macros.h>
+#elif defined(HAVE_PAM__PAM_MACROS_H)
+#include <pam/_pam_macros.h>
+#endif
+
+#ifdef HAVE_SECURITY_PAM_EXT_H
+#include <security/pam_ext.h>
+#endif
+],
+[int i; i = PAM_RADIO_TYPE; ],
+AC_DEFINE(HAVE_PAM_RADIO_TYPE, 1, [Define to 1 if PAM_RADIO_TYPE is available]),[])
+
 #################################################
 # check for pam_smbpass support
 PAM_MODULES=""
@@ -4865,6 +5025,27 @@ AC_MSG_CHECKING(whether to use the new lib/sysquotas.c interface)
 fi
 fi
 
+if test x"$samba_cv_SYSQUOTA_FOUND" != x"no"; then
+AC_CACHE_CHECK([whether the sys_quota interface works with NFS],samba_cv_SYSQUOTA_WORKS_NFS,[
+SAVE_CPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS ${SAMBA_CONFIGURE_CPPFLAGS}"
+AC_TRY_COMPILE([
+#include "confdefs.h"
+#define NO_PROTO_H 1
+#define NO_CONFIG_H 1
+#define HAVE_SYS_QUOTAS 1
+#define HAVE_NFS_QUOTAS 1
+#include "${srcdir-.}/lib/sysquotas_nfs.c"
+],[],samba_cv_SYSQUOTA_WORKS_NFS=yes,samba_cv_SYSQUOTA_WORKS_NFS=no)
+CPPFLAGS="$SAVE_CPPFLAGS"
+])
+if test x"$samba_cv_SYSQUOTA_WORKS_NFS" = x"yes"; then
+    if test x"$samba_cv_WE_USE_SYS_QUOTAS" = x"yes"; then
+       AC_DEFINE(HAVE_NFS_QUOTAS,1,[Whether nfs quota support is available])
+    fi
+fi
+fi
+
 if test x"$samba_cv_SYSQUOTA_FOUND" != x"no" -a x"$samba_cv_found_xfs_header" = x"yes"; then
 AC_CACHE_CHECK([whether the sys_quota interface works with XFS],samba_cv_SYSQUOTA_WORKS_XFS,[
 SAVE_CPPFLAGS="$CPPFLAGS"
@@ -5227,24 +5408,7 @@ AC_CHECK_HEADERS(ctdb.h ctdb_private.h,,,[
 #include <ctdb.h>
 ])
 
-AC_HAVE_DECL(CTDB_CONTROL_TRANS2_COMMIT_RETRY,[
-#include "confdefs.h"
-#define NO_CONFIG_H
-#include "replace.h"
-#include "system/wait.h"
-#include "system/network.h"
-#include <talloc.h>
-#include <tdb.h>
-#include <ctdb.h>
-#include <ctdb_private.h>
-])
-if test x"$ac_cv_have_CTDB_CONTROL_TRANS2_COMMIT_RETRY_decl" = x"yes"; then
-       ctdb_broken=no
-else
-       ctdb_broken="missing transaction support"
-fi
-
-AC_HAVE_DECL(CTDB_CONTROL_TRANS2_ACTIVE,[
+AC_HAVE_DECL(CTDB_CONTROL_TRANS3_COMMIT,[
 #include "confdefs.h"
 #define NO_CONFIG_H
 #include "replace.h"
@@ -5255,10 +5419,10 @@ AC_HAVE_DECL(CTDB_CONTROL_TRANS2_ACTIVE,[
 #include <ctdb.h>
 #include <ctdb_private.h>
 ])
-if test x"$ac_cv_have_CTDB_CONTROL_TRANS2_ACTIVE_decl" = x"yes"; then
+if test x"$ac_cv_have_CTDB_CONTROL_TRANS3_COMMIT_decl" = x"yes"; then
        ctdb_broken=no
 else
-       ctdb_broken="transaction support too old"
+       ctdb_broken="ctdb transaction support missing or too old"
 fi
 
 # in ctdb 1.0.57 ctdb_control_tcp was temparary renamed to ctdb_tcp_client
@@ -5465,7 +5629,9 @@ AC_ARG_WITH(aio-support,
        case "$host_os" in
        *)
                AIO_LIBS=$LIBS
+               no_rt_LIBS=$LIBS
                AC_CHECK_LIB(rt,aio_read,[AIO_LIBS="$LIBS -lrt"])
+               LIBS=$no_rt_LIBS
                AC_CHECK_LIB(aio,aio_read,[AIO_LIBS="$LIBS -laio"])
                AC_CACHE_CHECK([for asynchronous io support],samba_cv_HAVE_AIO,[
                aio_LIBS=$LIBS
@@ -5979,7 +6145,6 @@ WINBIND_NSS="../nsswitch/libnss_winbind.$SHLIBEXT"
 WINBIND_WINS_NSS="../nsswitch/libnss_wins.$SHLIBEXT"
 WINBIND_NSS_LDSHFLAGS=$LDSHFLAGS
 NSSSONAMEVERSIONSUFFIX=""
-WINBIND_NSS_PTHREAD=""
 
 case "$host_os" in
        *linux* | gnu* | k*bsd*-gnu | kopensolaris*-gnu)
@@ -6121,12 +6286,6 @@ else
         AC_MSG_RESULT(no$winbind_no_reason)
 fi
 
-AC_CHECK_LIB(pthread, pthread_mutex_lock, [WINBIND_NSS_PTHREAD="-lpthread"
-                       AC_DEFINE(HAVE_PTHREAD, 1, [whether pthread exists])
-                       samba_cv_HAVE_PTHREAD=yes],
-                       samba_cv_HAVE_PTHREAD=no)
-
-AC_SUBST(WINBIND_NSS_PTHREAD)
 AC_SUBST(WINBIND_NSS)
 AC_SUBST(WINBIND_WINS_NSS)
 AC_SUBST(WINBIND_NSS_LDSHFLAGS)
@@ -6282,16 +6441,77 @@ if test x"$enable_avahi" != x"no"; then
     fi
 fi
 
+
+#################################################
+# Set pthread stuff
+
+PTHREAD_CFLAGS=error
+PTHREAD_LDFLAGS=error
+
+# If it's error, then the user didn't 
+# define it.
+if test "x$PTHREAD_LDFLAGS" = xerror; then
+  AC_CHECK_LIB(pthread, pthread_attr_init, [
+            PTHREAD_CFLAGS="-D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS"
+            PTHREAD_LDFLAGS="-lpthread" ])
+fi
+
+if test "x$PTHREAD_LDFLAGS" = xerror; then
+  AC_CHECK_LIB(pthreads, pthread_attr_init, [
+            PTHREAD_CFLAGS="-D_THREAD_SAFE"
+            PTHREAD_LDFLAGS="-lpthreads" ])
+fi
+
+if test "x$PTHREAD_LDFLAGS" = xerror; then
+   AC_CHECK_LIB(c_r, pthread_attr_init, [
+               PTHREAD_CFLAGS="-D_THREAD_SAFE -pthread"
+               PTHREAD_LDFLAGS="-pthread" ])
+fi
+
+if test "x$PTHREAD_LDFLAGS" = xerror; then
+   AC_CHECK_FUNC(pthread_attr_init, [
+                PTHREAD_CFLAGS="-D_REENTRANT"
+                PTHREAD_LDFLAGS="-lpthread" ])
+fi
+
+# especially for HP-UX, where the AC_CHECK_FUNC macro fails to test for
+# pthread_attr_init. On pthread_mutex_lock it works there...
+if test "x$PTHREAD_LDFLAGS" = xerror; then
+   AC_CHECK_LIB(pthread, pthread_mutex_lock, [
+               PTHREAD_CFLAGS="-D_REENTRANT"
+               PTHREAD_LDFLAGS="-lpthread" ])
+fi
+
+AC_SUBST(PTHREAD_CFLAGS)
+AC_SUBST(PTHREAD_LDFLAGS)
+
+samba_cv_HAVE_PTHREAD=no
+if test x"$PTHREAD_CFLAGS" != xerror -a x"$PTHREAD_LDFLAGS" != xerror; then
+       samba_cv_HAVE_PTHREAD=yes
+       # now check for pthread.h with pthread-correct CFLAGS and LDFLAGS:
+       ac_save_CFLAGS=$CFLAGS
+       CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+       ac_save_LDFLAGS=$LDFLAGS
+       LDFLAGS="$LDFLAGS $PTHREAD_LDFLAGS"
+       AC_CHECK_HEADERS(pthread.h)
+       CFLAGS=$ac_save_CFLAGS
+       LDFLAGS=$ac_save_LDFLAGS
+       AC_DEFINE(HAVE_PTHREAD, 1, [Do we have pthreads around?])
+fi
+
 #################################################
 # Check if user wants pthreadpool support
 
 AC_ARG_ENABLE(pthreadpool,
-[AS_HELP_STRING([--enable-pthreadpool], [Enable pthreads pool helper support (default=auto)])])
+[AS_HELP_STRING([--enable-pthreadpool], [Enable pthreads pool helper support (default=no)])])
+
+if test x"$enable_pthreadpool" = xyes -a x"$samba_cv_HAVE_PTHREAD" != x"yes"; then
+       AC_MSG_ERROR([pthreadpool support cannot be enabled when pthread support was not found])
+fi
 
-if test x"$enable_pthreadpool" != x"no" -a x"$samba_cv_HAVE_PTHREAD" = x"yes"; then
-    AC_TRY_LINK([#include "pthread.h"],
-    [pthread_create(NULL, NULL, NULL, NULL)],
-                   ,LIBS="$LIBS -lpthread")
+if test x"$enable_pthreadpool" = x"yes" -a x"$samba_cv_HAVE_PTHREAD" = x"yes"; then
+    LIBS="$LIBS $PTHREAD_LDFLAGS"
+    CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
     AC_DEFINE(WITH_PTHREADPOOL, 1, [Whether to include pthreadpool helpers])
     AC_SUBST(PTHREADPOOL_OBJ, "lib/pthreadpool.o")
 fi
@@ -6321,7 +6541,7 @@ if test x"$INCLUDED_INIPARSER" = x"yes"; then
     AC_MSG_RESULT(yes)
     BUILD_INIPARSER='$(INIPARSER_OBJ)'
        INIPARSERLIBS=""
-    FLAGS1="$FLAGS1 -I\$(srcdir)/iniparser/src"
+    FLAGS1="$FLAGS1 -I\$(srcdir)/../lib/iniparser/src"
 else
     AC_MSG_RESULT(no)
        BUILD_INIPARSER=""
@@ -6331,7 +6551,41 @@ AC_SUBST(BUILD_INIPARSER)
 AC_SUBST(INIPARSERLIBS)
 AC_SUBST(FLAGS1)
 
-
+###################################################
+# Check for different/missing (set|get|end)netgrent prototypes
+CFLAGS_SAVE=$CFLAGS
+if test x"$samba_cv_HAVE_Wdeclaration_after_statement" = x"yes"; then
+       CFLAGS="$CFLAGS -Werror-implicit-function-declaration"
+fi
+AC_CACHE_CHECK([for setnetgrent prototype],samba_cv_setnetgrent_prototype, [
+    AC_TRY_COMPILE([#include<netdb.h>
+                    #ifdef HAVE_NETGROUP_H
+                    #include<netgroup.h>
+                    #endif],[setnetgrent("foo")],
+                    samba_cv_setnetgrent_prototype=yes, samba_cv_setnetgrent_prototype=no)])
+if test x"$samba_cv_setnetgrent_prototype" = x"yes"; then
+    AC_DEFINE(HAVE_SETNETGRENT_PROTOTYPE, 1, [If setnetgrent prototype is defined])
+fi
+AC_CACHE_CHECK([for getnetgrent prototype],samba_cv_getnetgrent_prototype, [
+    AC_TRY_COMPILE([#include<netdb.h>
+                    #ifdef HAVE_NETGROUP_H
+                    #include<netgroup.h>
+                    #endif],[char *dom, *user,*host; getnetgrent(&dom,&user,&host)],
+                    samba_cv_getnetgrent_prototype=yes, samba_cv_getnetgrent_prototype=no)])
+if test x"$samba_cv_getnetgrent_prototype" = x"yes"; then
+    AC_DEFINE(HAVE_GETNETGRENT_PROTOTYPE, 1, [If getnetgrent prototype is defined])
+fi
+AC_CACHE_CHECK([for endnetgrent prototype],samba_cv_endnetgrent_prototype, [
+    AC_TRY_COMPILE([#include<netdb.h>
+                    #ifdef HAVE_NETGROUP_H
+                    #include<netgroup.h>
+                    #endif],[endnetgrent()],
+                    samba_cv_endnetgrent_prototype=yes, samba_cv_endnetgrent_prototype=no)])
+if test x"$samba_cv_endnetgrent_prototype" = x"yes"; then
+    AC_DEFINE(HAVE_ENDNETGRENT_PROTOTYPE, 1, [If endnetgrent prototype is defined])
+fi
+
+CFLAGS=$CFLAGS_SAVE
 
 # Checks for the vfs_fileid module
 # Start
@@ -6511,6 +6765,9 @@ SMB_MODULE(vfs_smb_traffic_analyzer, \$(VFS_SMB_TRAFFIC_ANALYZER_OBJ), "bin/smb_
 SMB_MODULE(vfs_onefs, \$(VFS_ONEFS), "bin/onefs.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_onefs_shadow_copy, \$(VFS_ONEFS_SHADOW_COPY), "bin/onefs_shadow_copy.$SHLIBEXT", VFS)
 SMB_MODULE(vfs_dirsort, \$(VFS_DIRSORT_OBJ), "bin/dirsort.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_scannedonly, \$(VFS_SCANNEDONLY_OBJ), "bin/scannedonly.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_crossrename, \$(VFS_CROSSRENAME_OBJ), "bin/crossrename.$SHLIBEXT", VFS)
+SMB_MODULE(vfs_linux_xfs_sgid, \$(VFS_LINUX_XFS_SGID_OBJ), "bin/linux_xfs_sgid.$SHLIBEXT", VFS)
 
 SMB_SUBSYSTEM(VFS,smbd/vfs.o)
 
@@ -6627,9 +6884,6 @@ fi
 m4_include(../lib/zlib/zlib.m4)
 
 if test x$enable_merged_build = xauto; then
-       # Check for python
-       m4_include(../m4/check_python.m4)
-       AC_SAMBA_PYTHON_DEVEL([true], [merged_build_possible=no])
 
        AC_MSG_CHECKING([whether it would be possible to do a merged build])
        AC_MSG_RESULT([$merged_build_possible])
@@ -6644,8 +6898,13 @@ if test x$enable_merged_build = xyes; then
        MERGED_BUILD=1
        saved_USESHARED="$USESHARED"
        USESHARED="false"
-       m4_include(samba4.m4)
+       smbtorture4_path="bin/smbtorture4"
+       smbtorture4_option="-t bin/smbtorture4"
+       AC_SUBST(smbtorture4_path)
+       AC_SUBST(smbtorture4_option)
        USESHARED="$saved_USESHARED"
+       SMBTORTURE4="bin/smbtorture4"
+       AC_SUBST(SMBTORTURE4)
 fi
 
 AC_SUBST(ZLIB_LIBS)
@@ -6719,26 +6978,16 @@ SMBD_LIBS="$samba_dmapi_libs"
 AC_SUBST(SMBD_LIBS)
 
 CFLAGS="${CFLAGS} \$(FLAGS)"
+CFLAGS="${CFLAGS} -D_SAMBA_BUILD_=3"
 
-if test x$MERGED_BUILD != x1; then
-       CFLAGS="${CFLAGS} -D_SAMBA_BUILD_=3"
-else
-       if test x"$BLDSHARED" = x"true" ; then
-               LDFLAGS="$LDFLAGS -L./bin"
-       fi
+# If we had to expand the includes, make tsure the output file is moved back
+AC_OUTPUT_COMMANDS([
+if test -f Makefile-noincludes -a ! -f Makefile -a ! -h Makefile ; then
+       ln -s Makefile-noincludes Makefile
 fi
+])
 
-AC_SUBST(MAKEFILE)
-if test x$samba_cv_gnu_make = xyes; then
-       MAKEFILE=Makefile
-else
-       # When we don't have GNU Make, generate a copy of Makefile.in 
-       # that doesn't have the "include " statements but just includes 
-       # the files verbatim.
-       MAKEFILE=Makefile-noincludes
-       $PERL ./script/expand-includes.pl Makefile.in > $MAKEFILE.in
-fi
-AC_OUTPUT($MAKEFILE
+AC_OUTPUT(Makefile
          script/findsmb smbadduser script/gen-8bit-gap.sh script/installbin.sh script/uninstallbin.sh
          lib/netapi/examples/Makefile
          lib/netapi/tests/Makefile
@@ -6748,12 +6997,6 @@ AC_OUTPUT($MAKEFILE
          pkgconfig/smbsharemodes.pc
          ../examples/libsmbclient/Makefile.internal
          )
-dnl If we had to expand the includes, make tsure the output file is moved back
-AC_OUTPUT_COMMANDS([
-if test x$MAKEFILE != Makefile; then
-       mv $MAKEFILE Makefile
-fi
-])
 
 #################################################
 # Print very concise instructions on building/use