]> git.ipfire.org Git - thirdparty/lldpd.git/blobdiff - configure.ac
lib: don't rely on constructors
[thirdparty/lldpd.git] / configure.ac
index 66821f4441bbcf3a26a2ececf8cb076deef8e70b..b7ff5d79e78dc72390badf0687aa50bb3e569404 100644 (file)
@@ -27,7 +27,7 @@ AC_CONFIG_MACRO_DIR([m4])
 AC_SUBST([CONFIGURE_ARGS], [$ac_configure_args])
 
 # Configure automake
-AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror])
+AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror tar-ustar])
 AM_MAINTAINER_MODE
 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES(yes)])
 
@@ -82,6 +82,7 @@ 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])
@@ -92,20 +93,45 @@ AX_LDFLAGS_OPTION([-Wl,-z,now], [LLDP_LDFLAGS])
 # Hardening
 AC_ARG_ENABLE([hardening],
   [AS_HELP_STRING([--enable-hardening],
-    [Enable compiler and linker options to frustrate memory corruption exploits @<:@yes@:>@])],
+    [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
 
+# Sanitizers
+AC_ARG_ENABLE([sanitizers],
+  AS_HELP_STRING(
+    [--enable-sanitizers],
+    [Enable code instrumentation with selected sanitizers @<:@default=no@:>@]),
+  [
+case "$enableval" in
+    no) sanitizers= ;;
+    yes) sanitizers="-fsanitize=address,undefined" ;;
+    *) sanitizers="-fsanitize=$enableval" ;;
+esac
+if test x"$sanitizers" != x; then
+  LLDP_CFLAGS="$LLDP_CFLAGS $sanitizers"
+  LLDP_LDFLAGS="$LLDP_LDFLAGS $sanitizers"
+  AC_DEFINE([HAVE_ADDRESS_SANITIZER], 1, [Define if have both address and leak sanitizer])
+fi
+  ])
+
 # OS
 lldp_CHECK_OS
 lldp_CFLAGS_OS
@@ -128,27 +154,40 @@ 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
-
 # 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.
 m4_pushdef([AC_LANG_CALL(C)], [
@@ -164,7 +203,7 @@ 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
@@ -241,7 +280,7 @@ fi
 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
@@ -267,6 +306,13 @@ 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
 
@@ -297,7 +343,22 @@ 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
+
+# Build date
+if test x"$SOURCE_DATE_EPOCH" != x; then
+   AC_DEFINE_UNQUOTED(BUILD_DATE, "[$SOURCE_DATE_EPOCH]", [Build date and time])
+fi
+AC_DEFINE_UNQUOTED(LLDP_CC, "[$CC $LLDP_CFLAGS $LLDP_CPPFLAGS $CFLAGS $CPPFLAGS]", [C compiler command])
+AC_DEFINE_UNQUOTED(LLDP_LD, "[$LD $LLDP_LDFLAGS $LLDP_BIN_LDFLAGS $LDFLAGS $LIBS]", [Linker compiler command])
 
 #######################
 # Output results
@@ -330,6 +391,7 @@ cat <<EOF
   Linker.........: $LD $LLDP_LDFLAGS $LLDP_BIN_LDFLAGS $LDFLAGS $LIBS
   Libevent.......: $libevent
   Readline.......: ${ax_cv_lib_readline}
+
  Optional features:
   SNMP support...: ${with_snmp-no}
   CDP............: $enable_cdp
@@ -344,10 +406,15 @@ cat <<EOF
   JSON output....: ${with_json-no}
   Oldies support.: $enable_oldies
   seccomp........: ${with_seccomp-no}
+
  Privilege separation:
   Enabled........: $enable_privsep
   User/group.....: ${with_privsep_user}/${with_privsep_group}
   Chroot.........: ${with_privsep_chroot}
+------------- Compiler version --------------
+$($CC --version || true)
+-------------- Linker version ---------------
+$($LD --version || true)
 ---------------------------------------------
 
 Check the above options and compile with: