]> git.ipfire.org Git - thirdparty/lldpd.git/blobdiff - configure.ac
travis: disable integration tests
[thirdparty/lldpd.git] / configure.ac
index 0878ca06481c8406d9a70e3d2b9c2443b2540ad0..814251473e8f1813ab1432cdffdc30201abca305 100644 (file)
@@ -15,18 +15,19 @@ AC_INIT([lldpd],
 
 AC_CONFIG_SRCDIR([src/log.c])
 AC_CONFIG_HEADER([config.h])
-AC_CONFIG_FILES([Makefile src/Makefile src/compat/Makefile src/daemon/Makefile
-                         src/lib/Makefile src/lib/lldpctl.pc src/client/Makefile
-                         tests/Makefile])
-AC_CONFIG_FILES([osx/Makefile osx/distribution.xml osx/im.bernat.lldpd.plist])
-AC_CONFIG_FILES([osx/scripts/preinstall], [chmod +x osx/scripts/preinstall])
-AC_CONFIG_FILES([osx/scripts/postinstall], [chmod +x osx/scripts/postinstall])
-AC_CONFIG_FILES([src/daemon/lldpd.service])
+AC_CONFIG_FILES([Makefile
+                 src/Makefile
+                 src/compat/Makefile
+                 src/daemon/Makefile
+                src/lib/Makefile
+                 src/client/Makefile
+                tests/Makefile
+                 osx/Makefile])
 AC_CONFIG_MACRO_DIR([m4])
 AC_SUBST([CONFIGURE_ARGS], [$ac_configure_args])
 
 # Configure automake
-AM_INIT_AUTOMAKE([foreign -Wall -Werror])
+AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror tar-ustar])
 AM_MAINTAINER_MODE
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES(yes)])
 
@@ -36,6 +37,7 @@ AM_PROG_AR
 
 # Configure libtool
 LT_INIT
+gl_LD_VERSION_SCRIPT
 
 #######################
 ### Checks
@@ -43,6 +45,9 @@ LT_INIT
 # Checks for programs.
 AC_PROG_CC
 AC_PROG_CC_C99
+if test x"$ac_cv_prog_cc_c99" = x"no"; then
+  AC_MSG_FAILURE([*** C99 support is mandatory])
+fi
 AC_PROG_CXX
 AM_PROG_CC_C_O
 AC_PROG_LIBTOOL
@@ -63,26 +68,52 @@ DX_PS_FEATURE(OFF)
 DX_INIT_DOXYGEN([lldpd], [doxygen.cfg], [doxygen])
 
 # Check some compiler flags
-AX_CFLAGS_GCC_OPTION([-fdiagnostics-show-option])
-AX_CFLAGS_GCC_OPTION([-fdiagnostics-color=auto])
-AX_CFLAGS_GCC_OPTION([-pipe])
-AX_CFLAGS_GCC_OPTION([-Wall])
-AX_CFLAGS_GCC_OPTION([-W])
-AX_CFLAGS_GCC_OPTION([-Wextra])
-AX_CFLAGS_GCC_OPTION([-Wformat])
-AX_CFLAGS_GCC_OPTION([-Wformat-security])
-AX_CFLAGS_GCC_OPTION([-Wfatal-errors])
-AX_CFLAGS_GCC_OPTION([-Wcast-align])
-AX_CFLAGS_GCC_OPTION([-Winline])
-AX_CFLAGS_GCC_OPTION([-fstack-protector])
-AX_CFLAGS_GCC_OPTION([-fstack-protector-strong])
-AX_CFLAGS_GCC_OPTION([-fno-omit-frame-pointer])
-AX_CFLAGS_GCC_OPTION([-D_FORTIFY_SOURCE=2])
-AX_CFLAGS_GCC_OPTION([-Wno-unused-parameter])
-AX_CFLAGS_GCC_OPTION([-Wno-missing-field-initializers])
-AX_CFLAGS_GCC_OPTION([-Wno-sign-compare]) dnl Should be fixed later
-AX_LDFLAGS_OPTION([-Wl,-z,relro])
-AX_LDFLAGS_OPTION([-Wl,-z,now])
+AX_CFLAGS_GCC_OPTION([-Wunknown-warning-option], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-fdiagnostics-show-option], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-fdiagnostics-color=auto], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-pipe], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-Wall], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-W], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-Wextra], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-Wformat], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-Wformat-security], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-Wfatal-errors], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-Wcast-align], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-Wheader-guard], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-Wdocumentation], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-Winline], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-Wpointer-arith], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-fno-omit-frame-pointer], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-Wno-unused-parameter], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-Wno-missing-field-initializers], [LLDP_CFLAGS])
+AX_CFLAGS_GCC_OPTION([-Wno-sign-compare], [LLDP_CFLAGS]) dnl Should be fixed later
+AX_LDFLAGS_OPTION([-Wl,-z,relro], [LLDP_LDFLAGS])
+AX_LDFLAGS_OPTION([-Wl,-z,now], [LLDP_LDFLAGS])
+lldp_CHECK_CTORS
+
+# Hardening
+AC_ARG_ENABLE([hardening],
+  [AS_HELP_STRING([--enable-hardening],
+    [Enable compiler and linker options to frustrate memory corruption exploits @<:@default=yes@:>@])],
+  [hardening="$enableval"],
+  [hardening="yes"])
+AC_ARG_ENABLE([pie],
+  [AS_HELP_STRING([--enable-pie],
+    [Enable PIE (position independant executable) @<:@default=no@:>@])],
+  [pie="$enableval"],
+  [pie="no"])
+
+if test x"$hardening" != x"no"; then
+  AX_CFLAGS_GCC_OPTION([-fstack-protector], [LLDP_CFLAGS])
+  AX_CFLAGS_GCC_OPTION([-fstack-protector-all], [LLDP_CFLAGS])
+  AX_CFLAGS_GCC_OPTION([-fstack-protector-strong], [LLDP_CFLAGS])
+  AX_CFLAGS_GCC_OPTION([-D_FORTIFY_SOURCE=2], [LLDP_CPPFLAGS])
+fi
+if test x"$pie" = x"yes"; then
+  AX_CFLAGS_GCC_OPTION([-fPIE], [LLDP_CFLAGS])
+  AX_LDFLAGS_OPTION([-fPIE -pie], [LLDP_BIN_LDFLAGS],
+    [AX_LDFLAGS_OPTION([-fPIE -Wl,-pie], [LLDP_BIN_LDFLAGS])])
+fi
 
 # OS
 lldp_CHECK_OS
@@ -106,26 +137,42 @@ AC_CONFIG_LIBOBJ_DIR([src/compat])
 AC_FUNC_MALLOC
 AC_FUNC_REALLOC
 AC_FUNC_FORK
-# setproctitle (maybe through libbsd)
-AC_SEARCH_LIBS([setproctitle], [util bsd])
+
+# Some functions can be in libbsd
+PKG_CHECK_MODULES([libbsd], [libbsd-overlay], [
+  _save_CFLAGS="$CFLAGS"
+  _save_LIBS="$LIBS"
+  CFLAGS="$CFLAGS $libbsd_CFLAGS"
+  LIBS="$LIBS $libbsd_LIBS"
+  AC_MSG_CHECKING([if libbsd can be linked correctly])
+  AC_LINK_IFELSE([AC_LANG_SOURCE([[int main() { return 0; }]])],
+    [
+      AC_MSG_RESULT(yes)
+      LLDP_CFLAGS="$LLDP_CFLAGS $libbsd_CFLAGS"
+      LLDP_LDFLAGS="$LLDP_LDFLAGS $libbsd_LIBS"
+    ],[
+      AC_MSG_RESULT(no)
+      CFLAGS="$_save_CFLAGS"
+      LIBS="$_save_LIBS"
+    ])
+], [:])
+
+# setproctitle may have an _init function
 AC_REPLACE_FUNCS([setproctitle])
 AC_CHECK_FUNCS([setproctitle_init])
 # Other functions
 AC_REPLACE_FUNCS([strlcpy
                   strnlen
                   strndup
-                  fgetln
+                  getline
                   asprintf
                   vsyslog
                   daemon])
 # Optional functions
 AC_CHECK_FUNCS([setresuid setresgid])
 
-case " $LIBS " in
-     *\ -lbsd\ *)
-        AC_DEFINE(HAVE_LIBBSD, 1, [Define if libbsd is used])
-        ;;
-esac
+CFLAGS="$_save_CFLAGS"
+LIBS="$_save_LIBS"
 
 # Check for res_init. On OSX, res_init is a symbol in libsystem_info
 # and a macro in resolv.h. We need to ensure we test with resolv.h.
@@ -142,9 +189,17 @@ AC_CACHE_SAVE
 ## Unit tests wich check
 PKG_CHECK_MODULES([CHECK], [check >= 0.9.4], [have_check=yes], [have_check=no])
 
-# Libevent
+# Third-party libraries
 lldp_CHECK_LIBEVENT
 
+# Compatibility with pkg.m4 < 0.27
+m4_ifdef([PKG_INSTALLDIR], [PKG_INSTALLDIR],
+         [AC_ARG_WITH([pkgconfigdir],
+                      [AS_HELP_STRING([--with-pkgconfigdir],
+                      [install directory for *.pc pkg-config file])],
+                      [],[with_pkgconfigdir='$(libdir)/pkgconfig'])
+          AC_SUBST([pkgconfigdir], [${with_pkgconfigdir}])])
+
 #######################
 ### Options
 
@@ -152,12 +207,12 @@ lldp_CHECK_LIBEVENT
 AC_ARG_WITH([readline],
   AS_HELP_STRING(
     [--with-readline],
-    [Enable the use of readline-like library @<:@default=check@:>@]),
+    [Enable the use of readline-like library @<:@default=auto@:>@]),
   [],
-  [with_readline=check])
+  [with_readline=auto])
 if test x"$with_readline" != x"no"; then
    AX_LIB_READLINE
-   if test x"$with_readline" != x"check"; then
+   if test x"$with_readline" != x"check" -a x"$with_readline" != x"auto"; then
      if test x"$ax_cv_lib_readline" = x"no"; then
        AC_MSG_FAILURE([*** no readline support found])
      fi
@@ -170,37 +225,48 @@ fi
 AC_ARG_WITH([snmp],
   AS_HELP_STRING(
     [--with-snmp],
-    [Enable the use of SNMP @<:@default=no@:>@]
-  ))
-if test x"$with_snmp" = x"yes"; then
-   lldp_CHECK_SNMP
-fi
+    [Enable the use of SNMP @<:@default=no@:>@]),
+  [],
+  [with_snmp=no])
+lldp_CHECK_SNMP
 
 # XML
 AC_ARG_WITH([xml],
   AS_HELP_STRING(
     [--with-xml],
-    [Enable XML output via libxml2 @<:@default=no@:>@]
-  ))
-if test x"$with_xml" = x"yes"; then
-   lldp_CHECK_XML2
-fi
+    [Enable XML output via libxml2 @<:@default=auto@:>@]),
+  [],
+  [with_xml=auto])
+lldp_CHECK_XML2
 
 # JSON
 AC_ARG_WITH([json],
   AS_HELP_STRING(
     [--with-json],
-    [Enable JSON output via Jansson @<:@default=no@:>@]
-  ))
-if test x"$with_json" = x"yes"; then
+    [Enable JSON output via janson or json-c @<:@default=auto@:>@]),
+  [],
+  [with_json=auto])
+if test x"$with_json" = x"yes" -o x"$with_json" = x"auto"; then
+   _with_json="$with_json"
+   with_json=auto
+   lldp_CHECK_JANSSON
+   if test x"$with_json" = x"no"; then
+     with_json=auto
+     lldp_CHECK_JSONC
+   fi
+   if test x"$with_json" = x"no" -a x"$_with_json" = x"yes"; then
+     AC_MSG_FAILURE([*** no JSON support found])
+   fi
+else
    lldp_CHECK_JANSSON
+   lldp_CHECK_JSONC
 fi
 
 # Seccomp
 AC_ARG_WITH([seccomp],
   AS_HELP_STRING(
     [--with-seccomp],
-    [Enable seccomp support (with libseccomp) @<:@default=no@:>@]),
+    [Enable seccomp support (with libseccomp, experimental) @<:@default=no@:>@]),
   [],
   [with_seccomp=no])
 lldp_CHECK_SECCOMP
@@ -219,6 +285,20 @@ AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
 AM_CONDITIONAL(HAVE_SYSTEMDSYSTEMUNITDIR,
     [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ])
 
+# sysusers
+lldp_ARG_WITH([sysusersdir], [Directory for sysusers files],
+              [$($PKG_CONFIG --variable=sysusersdir systemd 2> /dev/null)])
+AC_SUBST([sysusersdir], [$with_sysusersdir])
+AM_CONDITIONAL(HAVE_SYSUSERSDIR,
+    [test -n "$with_sysusersdir" -a "x$with_sysusersdir" != xno ])
+
+# AppArmor
+lldp_ARG_WITH([apparmordir], [Directory for AppArmor profiles (Linux)],
+                             [no])
+AC_SUBST([apparmordir], [$with_apparmordir])
+AM_CONDITIONAL(HAVE_APPARMORDIR,
+    [test -n "$with_apparmordir" -a "x$with_apprmordir" != xno ])
+
 # Systemtap/DTrace
 lldp_SYSTEMTAP
 
@@ -246,16 +326,31 @@ lldp_ARG_ENABLE([sonmp], [SynOptics Network Management Protocol], [yes])
 lldp_ARG_ENABLE([lldpmed], [LLDP-MED extension], [yes])
 lldp_ARG_ENABLE([dot1], [Dot1 extension (VLAN stuff)], [yes])
 lldp_ARG_ENABLE([dot3], [Dot3 extension (PHY stuff)], [yes])
+lldp_ARG_ENABLE([custom], [Custom TLV support], [yes])
 
 # Oldies
-lldp_ARG_ENABLE([oldies], [compatibility with Linux kernel older than 2.6.18], [no])
+MIN_LINUX_KERNEL_VERSION=2.6.39
+lldp_ARG_ENABLE([oldies], [compatibility with Linux kernel older than 2.6.39], [no])
+if test x"$os" = x"Linux"; then
+    if test x"$enable_oldies" = x"no"; then
+      AC_DEFINE_UNQUOTED(MIN_LINUX_KERNEL_VERSION, "[$MIN_LINUX_KERNEL_VERSION]", [Minimal Linux kernel version required])
+    else
+      AC_DEFINE(MIN_LINUX_KERNEL_VERSION, "2.6.11", [Minimal kernel version required])
+    fi
+fi
 
 #######################
 # Output results
+AC_SUBST([LLDP_CFLAGS])
+AC_SUBST([LLDP_CPPFLAGS])
+AC_SUBST([LLDP_LDFLAGS])
+AC_SUBST([LLDP_BIN_LDFLAGS])
 AM_CONDITIONAL([HAVE_CHECK], [test x"$have_check" = x"yes"])
 AM_CONDITIONAL([USE_SNMP], [test x"$with_snmp" = x"yes"])
 AM_CONDITIONAL([USE_XML], [test x"$with_xml" = x"yes"])
-AM_CONDITIONAL([USE_JSON], [test x"$with_json" = x"yes"])
+AM_CONDITIONAL([USE_JSON], [test x"$with_json" = x"json-c" || test -x"$with_json" = x"jansson"])
+AM_CONDITIONAL([USE_JANSSON], [test x"$with_json" = x"jansson"])
+AM_CONDITIONAL([USE_JSONC], [test x"$with_json" = x"json-c"])
 AM_CONDITIONAL([USE_SECCOMP], [test x"$with_seccomp" = x"yes"])
 AC_OUTPUT
 
@@ -271,8 +366,8 @@ cat <<EOF
  $PACKAGE_NAME version $PACKAGE_VERSION
   OS.............: $os
   Prefix.........: $prefix
-  C Compiler.....: $CC $CFLAGS $CPPFLAGS
-  Linker.........: $LD $LDFLAGS $LIBS
+  C Compiler.....: $CC $LLDP_CFLAGS $LLDP_CPPFLAGS $CFLAGS $CPPFLAGS
+  Linker.........: $LD $LLDP_LDFLAGS $LLDP_BIN_LDFLAGS $LDFLAGS $LIBS
   Libevent.......: $libevent
   Readline.......: ${ax_cv_lib_readline}
  Optional features:
@@ -284,6 +379,7 @@ cat <<EOF
   LLDPMED........: $enable_lldpmed
   DOT1...........: $enable_dot1
   DOT3...........: $enable_dot3
+  CUSTOM.........: $enable_custom
   XML output.....: ${with_xml-no}
   JSON output....: ${with_json-no}
   Oldies support.: $enable_oldies