r19227: - add a AC_CACHE_CHECK() around the net/if.h test
[ira/wip.git] / source4 / lib / replace / libreplace.m4
index 8b1486c5c1fb3f158e9219608683556f7cf05a02..662993cb79b4788e6cbcb7f25fdeb2b8800705a6 100644 (file)
@@ -1,3 +1,36 @@
+AC_DEFUN_ONCE(AC_LIBREPLACE_LOCATION_CHECKS,
+[
+echo "LIBREPLACE_LOCATION_CHECKS: START"
+
+dnl find the libreplace sources. This is meant to work both for 
+dnl libreplace standalone builds, and builds of packages using libreplace
+libreplacedir=""
+libreplacepaths="$srcdir $srcdir/lib/replace $srcdir/libreplace $srcdir/../libreplace $srcdir/../replace"
+for d in $libreplacepaths; do
+       if test -f "$d/replace.c"; then
+               libreplacedir="$d"              
+               AC_SUBST(libreplacedir)
+               break;
+       fi
+done
+if test x"$libreplacedir" = "x"; then
+       AC_MSG_ERROR([cannot find libreplace in $libreplacepaths])
+fi
+LIBREPLACEOBJ="replace.o"
+AC_SUBST(LIBREPLACEOBJ)
+
+AC_CANONICAL_BUILD
+AC_CANONICAL_HOST
+AC_CANONICAL_TARGET
+
+echo "LIBREPLACE_LOCATION_CHECKS: END"
+]) dnl end AC_LIBREPLACE_LOCATION_CHECKS
+
+
+AC_DEFUN_ONCE(AC_LIBREPLACE_BROKEN_CHECKS,
+[
+echo "LIBREPLACE_BROKEN_CHECKS: START"
+
 dnl find the libreplace sources. This is meant to work both for 
 dnl libreplace standalone builds, and builds of packages using libreplace
 libreplacedir=""
@@ -8,80 +41,10 @@ for d in "$srcdir" "$srcdir/lib/replace" "$srcdir/libreplace" "$srcdir/../librep
                break;
        fi
 done
-LIBREPLACEOBJ="dlfcn.o getpass.o replace.o snprintf.o timegm.o"
+LIBREPLACEOBJ="replace.o"
 AC_SUBST(LIBREPLACEOBJ)
 
-dnl stop the C89 attempt by autoconf - if autoconf detects -Ae it will enable it
-dnl which conflicts with C99 on HPUX
-ac_cv_prog_cc_Ae=no
-
-savedCFLAGS=$CFLAGS
-AC_PROG_CC
-CFLAGS=$savedCFLAGS
-AC_ISC_POSIX
-AC_USE_SYSTEM_EXTENSIONS
-AC_PROG_CC_C99
-AC_C_INLINE
-AC_PROG_INSTALL
-
-AH_VERBATIM([_XOPEN_SOURCE],
-[/* Enable XOPEN on systems that have them.  */
-#ifndef _XOPEN_SOURCE
-# define _XOPEN_SOURCE 1
-#endif])
-
-AH_VERBATIM([_XOPEN_SOURCE_EXTENDED],
-[/* Enable XOPEN extensions on systems that have them.  */
-#ifndef _XOPEN_SOURCE_EXTENDED
-# define _XOPEN_SOURCE_EXTENDED 1
-#endif])
-
-AH_VERBATIM([_OSF_SOURCE],
-[/* Enable OSF extensions on systems that have them.  */
-#ifndef _OSF_SOURCE
-# define _OSF_SOURCE 1
-#endif])
-
-LIBREPLACE_C99_STRUCT_INIT([],[])
-
-AC_SYS_LARGEFILE
-
-dnl Add #include for broken IRIX header files
-case "$host_os" in
-       *irix6*) AC_ADD_INCLUDE(<standards.h>)
-               ;;
-esac
-
-AC_C_BIGENDIAN
-AC_HEADER_STDC
-
-
-AC_CHECK_SIZEOF(off_t,cross)
-AC_CHECK_SIZEOF(size_t,cross)
-AC_CHECK_SIZEOF(ssize_t,cross)
-
-AC_CHECK_HEADERS([stdint.h inttypes.h])
-AC_CHECK_TYPE(uint_t, unsigned int)
-AC_CHECK_TYPE(uint8_t, unsigned char)
-AC_CHECK_TYPE(int8_t, char)
-AC_CHECK_TYPE(int16_t, short)
-AC_CHECK_TYPE(uint16_t, unsigned short)
-AC_CHECK_TYPE(int32_t, long)
-AC_CHECK_TYPE(intptr_t, unsigned long long)
-AC_CHECK_TYPE(uint32_t, unsigned long)
-AC_CHECK_TYPE(ssize_t, int)
-AC_CHECK_TYPE(ptrdiff_t, unsigned long long)
-
-dnl these are needed for heimdal roken.h
-AC_CHECK_TYPE(struct sockaddr, [], [], [
-AC_INCLUDES_DEFAULT
-#include <sys/socket.h>])
-AC_CHECK_TYPE(struct sockaddr_storage, [], [], [
-AC_INCLUDES_DEFAULT
-#include <sys/socket.h>])
-AC_CHECK_TYPE(struct addrinfo, [], [], [
-AC_INCLUDES_DEFAULT
-#include <netdb.h>])
+LIBREPLACEOBJ="${LIBREPLACEOBJ} snprintf.o"
 
 AC_TYPE_SIGNAL
 AC_TYPE_UID_T
@@ -93,13 +56,15 @@ AC_STRUCT_ST_RDEV
 AC_CHECK_TYPE(ino_t,unsigned)
 AC_CHECK_TYPE(loff_t,off_t)
 AC_CHECK_TYPE(offset_t,loff_t)
-AC_CHECK_TYPES(long long)
 
 AC_FUNC_MEMCMP
 
 AC_CHECK_FUNCS(pipe strftime srandom random srand rand usleep setbuffer lstat getpgrp)
 
-AC_CHECK_HEADERS(stdbool.h stddef.h)
+AC_CHECK_HEADERS(stdbool.h sys/select.h)
+
+AC_CHECK_HEADERS(sys/epoll.h)
+AC_CHECK_FUNCS(epoll_create)
 
 AC_CHECK_TYPE(bool, 
 [AC_DEFINE(HAVE_BOOL, 1, [Whether the bool type is available])],,
@@ -127,6 +92,32 @@ if test x"$samba_cv_HAVE_MMAP" = x"yes"; then
 fi
 
 
+AC_CHECK_HEADERS(sys/syslog.h syslog.h)
+AC_CHECK_HEADERS(sys/time.h time.h)
+AC_CHECK_HEADERS(stdarg.h vararg.h)
+AC_CHECK_HEADERS(sys/socket.h netinet/in.h netdb.h arpa/inet.h)
+AC_CHECK_HEADERS(netinet/ip.h netinet/tcp.h netinet/in_systm.h netinet/in_ip.h)
+AC_CHECK_HEADERS(sys/sockio.h sys/un.h)
+
+
+dnl we need to check that net/if.h really can be used, to cope with hpux
+dnl where including it always fails
+AC_CACHE_CHECK([for usable net/if.h],libreplace_cv_USABLE_NET_IF_H,[
+       AC_COMPILE_IFELSE([
+               AC_INCLUDES_DEFAULT
+               #if HAVE_SYS_SOCKET_H
+               # include <sys/socket.h>
+               #endif
+               #include <net/if.h>
+               int main(void) {return 0;}],
+               [libreplace_cv_USABLE_NET_IF_H=yes],
+               [libreplace_cv_USABLE_NET_IF_H=no]
+       )
+])
+if test x"$libreplace_cv_USABLE_NET_IF_H" = x"yes";then
+       AC_DEFINE(HAVE_NET_IF_H, 1, usability of net/if.h)
+fi
+
 AC_CACHE_CHECK([for broken inet_ntoa],samba_cv_REPLACE_INET_NTOA,[
 AC_TRY_RUN([
 #include <stdio.h>
@@ -156,10 +147,6 @@ AC_TRY_COMPILE([
 [socklen_t foo;],,
 [AC_DEFINE(socklen_t, int,[Socket length type])])
 
-AC_CHECK_HEADERS(sys/syslog.h syslog.h)
-AC_CHECK_HEADERS(sys/time.h time.h)
-AC_CHECK_HEADERS(sys/socket.h netinet/in.h)
-AC_CHECK_HEADERS(stdarg.h vararg.h)
 AC_CHECK_FUNCS(seteuid setresuid setegid setresgid chroot bzero strerror)
 AC_CHECK_FUNCS(vsyslog setlinebuf mktime ftruncate chsize rename)
 AC_CHECK_FUNCS(waitpid strlcpy strlcat innetgr initgroups memmove strdup)
@@ -234,24 +221,6 @@ if test x"$samba_cv_HAVE_C99_VSNPRINTF" = x"yes"; then
     AC_DEFINE(HAVE_C99_VSNPRINTF,1,[Whether there is a C99 compliant vsnprintf])
 fi
 
-dnl dummies provided by dlfcn.c if not available
-save_LIBS="$LIBS"
-LIBS=""
-AC_SEARCH_LIBS(dlopen, dl)
-AC_CHECK_HEADERS(dlfcn.h)
-AC_CHECK_FUNCS(dlopen dlsym dlerror dlclose)
-LIBDL="$LIBS"
-AC_SUBST(LIBDL)
-LIBS="$save_LIBS"
-
-AC_CHECK_FUNCS([syslog memset setnetgrent getnetgrent endnetgrent memcpy],,
-                          [AC_MSG_ERROR([Required function not found])])
-
-m4_include(getpass.m4)
-m4_include(system/config.m4)
-
-LIBREPLACE_C99_STRUCT_INIT(c99_struct_initialization=yes,
-                       c99_struct_initialization=no)
 
 dnl VA_COPY
 AC_CACHE_CHECK([for va_copy],samba_cv_HAVE_VA_COPY,[
@@ -293,14 +262,14 @@ AC_CHECK_HEADERS([sys/param.h limits.h])
 AC_CHECK_TYPE(comparison_fn_t, 
 [AC_DEFINE(HAVE_COMPARISON_FN_T, 1,[Whether or not we have comparison_fn_t])])
 
-AC_CHECK_FUNCS(timegm strnlen setenv)
+AC_CHECK_FUNCS(strnlen setenv)
 AC_CHECK_FUNCS(strtoull __strtoull strtouq strtoll __strtoll strtoq)
 
 # this test disabled as we don't actually need __VA_ARGS__ yet
-AC_TRY_CPP([
-# #define eprintf(...) fprintf(stderr, __VA_ARGS__)
-eprintf("bla", "bar");
-# ], [], [AC_MSG_ERROR([__VA_ARGS__ is required])])
+AC_TRY_CPP([
+#define eprintf(...) fprintf(stderr, __VA_ARGS__)
+eprintf("bla", "bar");
+], AC_DEFINE(HAVE__VA_ARGS__MACRO, 1, [Whether the __VA_ARGS__ macro is available]))
 
 # Check prerequisites
 AC_CHECK_FUNCS([memset printf syslog], [], 
@@ -351,3 +320,38 @@ AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [
 if test x"$samba_cv_volatile" = x"yes"; then
        AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
 fi
+
+m4_include(system/config.m4)
+
+m4_include(dlfcn.m4)
+m4_include(getpass.m4)
+m4_include(win32.m4)
+m4_include(timegm.m4)
+m4_include(repdir.m4)
+
+AC_CHECK_FUNCS([syslog memset setnetgrent getnetgrent endnetgrent memcpy],,
+                          [AC_MSG_ERROR([Required function not found])])
+
+echo "LIBREPLACE_BROKEN_CHECKS: END"
+]) dnl end AC_LIBREPLACE_BROKEN_CHECKS
+
+AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_START,
+[
+#LIBREPLACE_ALL_CHECKS: START"
+])
+AC_DEFUN_ONCE(AC__LIBREPLACE_ALL_CHECKS_END,
+[
+#LIBREPLACE_ALL_CHECKS: END"
+])
+m4_define(AC_LIBREPLACE_ALL_CHECKS,
+[
+AC__LIBREPLACE_ALL_CHECKS_START
+AC_LIBREPLACE_LOCATION_CHECKS
+AC_LIBREPLACE_CC_CHECKS
+AC_LIBREPLACE_BROKEN_CHECKS
+AC__LIBREPLACE_ALL_CHECKS_END
+])
+
+m4_include(libreplace_cc.m4)
+m4_include(libreplace_macros.m4)
+m4_include(autoconf-2.60.m4)