Don't compile getopt*.c if the system provides getopt_long().
authorGuus Sliepen <guus@tinc-vpn.org>
Fri, 8 Apr 2016 15:49:49 +0000 (17:49 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Fri, 8 Apr 2016 16:03:32 +0000 (18:03 +0200)
configure.ac
src/Makefile.am
src/tincd.c

index 5cdd642..3b781ba 100644 (file)
@@ -160,7 +160,7 @@ dnl Checks for header files.
 dnl We do this in multiple stages, because unlike Linux all the other operating systems really suck and don't include their own dependencies.
 
 AC_HEADER_STDC
 dnl We do this in multiple stages, because unlike Linux all the other operating systems really suck and don't include their own dependencies.
 
 AC_HEADER_STDC
-AC_CHECK_HEADERS([stdbool.h syslog.h sys/file.h sys/ioctl.h sys/mman.h sys/param.h sys/resource.h sys/socket.h sys/time.h time.h sys/uio.h sys/wait.h netdb.h arpa/inet.h arpa/nameser.h dirent.h])
+AC_CHECK_HEADERS([stdbool.h syslog.h sys/file.h sys/ioctl.h sys/mman.h sys/param.h sys/resource.h sys/socket.h sys/time.h time.h sys/uio.h sys/wait.h netdb.h arpa/inet.h arpa/nameser.h dirent.h getopt.h])
 AC_CHECK_HEADERS([net/if.h net/if_types.h linux/if_tun.h net/if_tun.h net/tun/if_tun.h net/if_tap.h net/tap/if_tap.h net/ethernet.h net/if_arp.h netinet/in_systm.h netinet/in.h netinet/in6.h netpacket/packet.h],
   [], [], [#include "src/have.h"]
 )
 AC_CHECK_HEADERS([net/if.h net/if_types.h linux/if_tun.h net/if_tun.h net/tun/if_tun.h net/if_tap.h net/tap/if_tap.h net/ethernet.h net/if_arp.h netinet/in_systm.h netinet/in.h netinet/in6.h netpacket/packet.h],
   [], [], [#include "src/have.h"]
 )
@@ -191,6 +191,9 @@ AC_CHECK_FUNCS([asprintf daemon fchmod flock ftime fork get_current_dir_name get
   [], [], [#include "src/have.h"]
 )
 
   [], [], [#include "src/have.h"]
 )
 
+AC_CHECK_FUNC(getopt_long, [getopt=true; AC_DEFINE(HAVE_GETOPT_LONG, 1, [getopt_long()])], [getopt=false])
+AM_CONDITIONAL(GETOPT, test "$getopt" = true)
+
 dnl Support for SunOS
 
 AC_CHECK_FUNC(socket, [], [
 dnl Support for SunOS
 
 AC_CHECK_FUNC(socket, [], [
index ebd52ab..a5a9692 100644 (file)
@@ -17,8 +17,6 @@ tincd_SOURCES = \
        fake-gai-errnos.h \
        fake-getaddrinfo.c fake-getaddrinfo.h \
        fake-getnameinfo.c fake-getnameinfo.h \
        fake-gai-errnos.h \
        fake-getaddrinfo.c fake-getaddrinfo.h \
        fake-getnameinfo.c fake-getnameinfo.h \
-       getopt.c getopt.h \
-       getopt1.c \
        graph.c graph.h \
        ipv4.h \
        ipv6.h \
        graph.c graph.h \
        ipv4.h \
        ipv6.h \
@@ -49,6 +47,12 @@ tincd_SOURCES = \
        xalloc.h \
        xmalloc.c
 
        xalloc.h \
        xmalloc.c
 
+if !GETOPT
+tincd_SOURCES += \
+       getopt.c getopt.h \
+       getopt1.c
+endif
+
 if LINUX
 tincd_SOURCES += linux/device.c
 endif
 if LINUX
 tincd_SOURCES += linux/device.c
 endif
index ed0cee9..db18dc5 100644 (file)
 #include <time.h>
 #endif
 
 #include <time.h>
 #endif
 
+#ifdef HAVE_GETOPT_LONG
 #include <getopt.h>
 #include <getopt.h>
+#else
+#include "getopt.h"
+#endif
+
 #include "pidfile.h"
 
 #include "conf.h"
 #include "pidfile.h"
 
 #include "conf.h"