]> git.ipfire.org Git - thirdparty/lldpd.git/blob - configure.ac
daemon: cleanup remote ports for permanent interfaces too
[thirdparty/lldpd.git] / configure.ac
1 # -*- Autoconf -*-
2 # Process this file with autoconf to produce a configure script.
3
4 #######################
5 ### Base configuration
6
7 # Configure autoconf
8 AC_PREREQ([2.69])
9
10 AC_INIT([lldpd],
11 [m4_esyscmd_s([./get-version])],
12 [https://github.com/lldpd/lldpd/issues],
13 [lldpd],
14 [https://lldpd.github.io/])
15
16 AC_CONFIG_SRCDIR([src/log.c])
17 AC_CONFIG_HEADERS([config.h])
18 AC_CONFIG_FILES([Makefile
19 src/Makefile
20 src/compat/Makefile
21 src/daemon/Makefile
22 src/lib/Makefile
23 src/client/Makefile
24 tests/Makefile
25 osx/Makefile])
26 AC_CONFIG_MACRO_DIR([m4])
27 AC_SUBST([CONFIGURE_ARGS], [$ac_configure_args])
28
29 # Configure automake
30 AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror tar-ustar])
31 AM_MAINTAINER_MODE
32 m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES(yes)])
33
34 # Automake 1.12...
35 m4_pattern_allow([AM_PROG_AR])
36 AM_PROG_AR
37
38 # Configure libtool
39 LT_INIT
40 gl_LD_VERSION_SCRIPT
41
42 #######################
43 ### Checks
44
45 # Checks for programs.
46 AC_PROG_CC
47 AC_PROG_CC_C99
48 if test x"$ac_cv_prog_cc_c99" = x"no"; then
49 AC_MSG_FAILURE([*** C99 support is mandatory])
50 fi
51 AC_PROG_CPP
52 AM_PROG_CC_C_O
53 LT_INIT
54 AC_PROG_LN_S
55 AC_PROG_EGREP
56 AC_PROG_AWK
57 AC_PROG_SED
58
59 # Check for pkg-config
60 m4_ifndef([PKG_CHECK_MODULES], [
61 AC_MSG_ERROR([PKG_CHECK_MODULES not found. Please install pkg-config and re-run autogen.sh])])
62
63 # Doxygen
64 DX_HTML_FEATURE(ON)
65 DX_DOT_FEATURE(OFF)
66 DX_CHM_FEATURE(OFF)
67 DX_CHI_FEATURE(OFF)
68 DX_MAN_FEATURE(OFF)
69 DX_RTF_FEATURE(OFF)
70 DX_XML_FEATURE(OFF)
71 DX_PDF_FEATURE(ON)
72 DX_PS_FEATURE(OFF)
73 DX_INIT_DOXYGEN([lldpd], [doxygen.cfg], [doxygen])
74
75 # Check some compiler flags
76 AX_CFLAGS_GCC_OPTION([-Wunknown-warning-option], [LLDP_CFLAGS])
77 AX_CFLAGS_GCC_OPTION([-fdiagnostics-show-option], [LLDP_CFLAGS])
78 AX_CFLAGS_GCC_OPTION([-fdiagnostics-color=auto], [LLDP_CFLAGS])
79 AX_CFLAGS_GCC_OPTION([-pipe], [LLDP_CFLAGS])
80 AX_CFLAGS_GCC_OPTION([-Wall], [LLDP_CFLAGS])
81 AX_CFLAGS_GCC_OPTION([-W], [LLDP_CFLAGS])
82 AX_CFLAGS_GCC_OPTION([-Wextra], [LLDP_CFLAGS])
83 AX_CFLAGS_GCC_OPTION([-Wformat], [LLDP_CFLAGS])
84 AX_CFLAGS_GCC_OPTION([-Wformat-security], [LLDP_CFLAGS])
85 AX_CFLAGS_GCC_OPTION([-Wimplicit-fallthrough], [LLDP_CFLAGS])
86 AX_CFLAGS_GCC_OPTION([-Wfatal-errors], [LLDP_CFLAGS])
87 AX_CFLAGS_GCC_OPTION([-Wheader-guard], [LLDP_CFLAGS])
88 AX_CFLAGS_GCC_OPTION([-Wdocumentation], [LLDP_CFLAGS])
89 AX_CFLAGS_GCC_OPTION([-Winline], [LLDP_CFLAGS])
90 AX_CFLAGS_GCC_OPTION([-Wpointer-arith], [LLDP_CFLAGS])
91 AX_CFLAGS_GCC_OPTION([-fno-omit-frame-pointer], [LLDP_CFLAGS])
92 AX_CFLAGS_GCC_OPTION([-Wno-cast-align], [LLDP_CFLAGS]) dnl clang is bad at this
93 AX_CFLAGS_GCC_OPTION([-Wno-unused-parameter], [LLDP_CFLAGS])
94 AX_CFLAGS_GCC_OPTION([-Wno-missing-field-initializers], [LLDP_CFLAGS])
95 AX_CFLAGS_GCC_OPTION([-Wno-sign-compare], [LLDP_CFLAGS]) dnl Should be fixed later
96 AX_LDFLAGS_OPTION([-Wl,-z,relro], [LLDP_LDFLAGS])
97 AX_LDFLAGS_OPTION([-Wl,-z,now], [LLDP_LDFLAGS])
98
99 AC_C_TYPEOF
100
101 # Hardening
102 AC_ARG_ENABLE([hardening],
103 [AS_HELP_STRING([--enable-hardening],
104 [Enable compiler and linker options to frustrate memory corruption exploits @<:@default=yes@:>@])],
105 [hardening="$enableval"],
106 [hardening="yes"])
107 AC_ARG_ENABLE([pie],
108 [AS_HELP_STRING([--enable-pie],
109 [Enable PIE (position independant executable) @<:@default=no@:>@])],
110 [pie="$enableval"],
111 [pie="no"])
112
113 if test x"$hardening" != x"no"; then
114 AX_CFLAGS_GCC_OPTION([-fstack-protector], [LLDP_CFLAGS])
115 AX_CFLAGS_GCC_OPTION([-fstack-protector-all], [LLDP_CFLAGS])
116 AX_CFLAGS_GCC_OPTION([-fstack-protector-strong], [LLDP_CFLAGS])
117 AX_CFLAGS_GCC_OPTION([-fstack-protector-strong], [LLDP_CFLAGS])
118 AX_CFLAGS_GCC_OPTION([-fstack-clash-protection], [LLDP_CFLAGS])
119 AX_CFLAGS_GCC_OPTION([-D_FORTIFY_SOURCE=2], [LLDP_CPPFLAGS])
120 fi
121 if test x"$pie" = x"yes"; then
122 AX_CFLAGS_GCC_OPTION([-fPIE], [LLDP_CFLAGS])
123 AX_LDFLAGS_OPTION([-fPIE -pie], [LLDP_BIN_LDFLAGS],
124 [AX_LDFLAGS_OPTION([-fPIE -Wl,-pie], [LLDP_BIN_LDFLAGS])])
125 fi
126
127 # Sanitizers
128 AC_ARG_ENABLE([sanitizers],
129 AS_HELP_STRING([--enable-sanitizers],
130 [Enable code instrumentation with selected sanitizers @<:@default=no@:>@]),
131 [
132 case "$enableval" in
133 no) sanitizers= ;;
134 yes) sanitizers="-fsanitize=address,undefined" ;;
135 *) sanitizers="-fsanitize=$enableval" ;;
136 esac
137 if test x"$sanitizers" != x; then
138 LLDP_CFLAGS="$LLDP_CFLAGS $sanitizers"
139 LLDP_LDFLAGS="$LLDP_LDFLAGS $sanitizers"
140 AC_DEFINE([HAVE_ADDRESS_SANITIZER], 1, [Define if have both address and leak sanitizer])
141 elif test x"$hardening" != x"no"; then
142 AX_LDFLAGS_OPTION([-fsanitize=safe-stack], [LLDP_BIN_LDFLAGS])
143 if test x"$ax_cv_ld_check_flag__fsanitize_safe_stack" != x"no"; then
144 AX_CFLAGS_GCC_OPTION([-fsanitize=safe-stack], [LLDP_CFLAGS])
145 fi
146 fi
147 ])
148
149 # Code coverage
150 AC_ARG_ENABLE([gcov],
151 AS_HELP_STRING([--enable-gcov],
152 [Enable coverage instrumentation @<:@default=no@:>@]),
153 [gcov="$enableval"],
154 [gcov="no"])
155 if test x"$gcov" != x"no"; then
156 LLDP_CFLAGS="$LLDP_CFLAGS --coverage"
157 LLDP_LDFLAGS="$LLDP_LDFLAGS --coverage"
158 fi
159
160 # OS
161 lldp_CHECK_OS
162 lldp_CFLAGS_OS
163
164 AC_CACHE_SAVE
165
166 # Checks for header files.
167 AC_HEADER_RESOLV
168 AC_CHECK_HEADERS([valgrind/valgrind.h])
169 lldp_CHECK_STDINT
170
171 AC_CACHE_SAVE
172
173 # Checks for typedefs, structures, and compiler characteristics.
174 lldp_CHECK___PROGNAME
175 lldp_CHECK_ALIGNOF
176
177 # Checks for library functions.
178 AC_CONFIG_LIBOBJ_DIR([src/compat])
179 AC_FUNC_MALLOC
180 AC_FUNC_REALLOC
181 AC_FUNC_FORK
182
183 # Some functions can be in libbsd
184 AC_ARG_WITH([libbsd],
185 AS_HELP_STRING(
186 [--with-libbsd],
187 [Use libbsd @<:@default=auto@:>@]),
188 [],
189 [with_libbsd=auto])
190 if test x"$with_libbsd" != x"no"; then
191 PKG_CHECK_MODULES([libbsd], [libbsd-overlay], [
192 _save_CFLAGS="$CFLAGS"
193 _save_LIBS="$LIBS"
194 CFLAGS="$CFLAGS $libbsd_CFLAGS"
195 LIBS="$LIBS $libbsd_LIBS"
196 AC_MSG_CHECKING([if libbsd can be linked correctly])
197 AC_LINK_IFELSE([AC_LANG_PROGRAM([[
198 @%:@include <sys/time.h>
199 @%:@include <sys/types.h>
200 ]], [[]])],[
201 AC_MSG_RESULT(yes)
202 LLDP_CFLAGS="$LLDP_CFLAGS $libbsd_CFLAGS"
203 LLDP_LDFLAGS="$LLDP_LDFLAGS $libbsd_LIBS"
204 with_libbsd=yes
205 ],[
206 AC_MSG_RESULT(no)
207 CFLAGS="$_save_CFLAGS"
208 LIBS="$_save_LIBS"
209 if test x"$with_libbsd" = x"yes"; then
210 AC_MSG_FAILURE([*** no libbsd support found])
211 fi
212 with_libbsd=no
213 ])
214 ], [
215 if test x"$with_libbsd" = x"yes"; then
216 AC_MSG_FAILURE([*** no libbsd support found])
217 fi
218 with_libbsd=no
219 ])
220 fi
221
222 # setproctitle may have an _init function
223 AC_REPLACE_FUNCS([setproctitle])
224 AC_CHECK_FUNCS([setproctitle_init])
225 # Other functions
226 AC_REPLACE_FUNCS([strlcpy
227 strnlen
228 strndup
229 strtonum
230 getline
231 asprintf
232 vsyslog
233 daemon])
234 # Optional functions
235 AC_CHECK_FUNCS([setresuid setresgid])
236
237 # Check for res_init. On OSX, res_init is a symbol in libsystem_info
238 # and a macro in resolv.h. We need to ensure we test with resolv.h.
239 m4_pushdef([AC_LANG_CALL(C)], [
240 AC_LANG_PROGRAM([$1
241 @%:@include <resolv.h>], [return $2 ();])])
242 AC_SEARCH_LIBS([res_init], resolv bind,
243 AC_DEFINE([HAVE_RES_INIT], 1,
244 [Define to indicate that res_init() exists]))
245 m4_popdef([AC_LANG_CALL(C)])
246
247 AC_CACHE_SAVE
248
249 ## Unit tests wich check
250 PKG_CHECK_MODULES([check], [check >= 0.9.4], [have_check=yes], [have_check=no])
251
252 # Third-party libraries
253 lldp_CHECK_LIBEVENT
254 lldp_CHECK_LIBCAP
255
256 # Compatibility with pkg.m4 < 0.27
257 m4_ifdef([PKG_INSTALLDIR], [PKG_INSTALLDIR],
258 [AC_ARG_WITH([pkgconfigdir],
259 [AS_HELP_STRING([--with-pkgconfigdir],
260 [install directory for *.pc pkg-config file])],
261 [],[with_pkgconfigdir='$(libdir)/pkgconfig'])
262 AC_SUBST([pkgconfigdir], [${with_pkgconfigdir}])])
263
264 #######################
265 ### Options
266
267 # Readline
268 AC_ARG_WITH([readline],
269 AS_HELP_STRING(
270 [--with-readline],
271 [Enable the use of readline-like library @<:@default=auto@:>@]),
272 [],
273 [with_readline=auto])
274 if test x"$with_readline" != x"no"; then
275 AX_LIB_READLINE_LLDPD
276 if test x"$with_readline" != x"check" -a x"$with_readline" != x"auto"; then
277 if test x"$ax_cv_lib_readline" = x"no"; then
278 AC_MSG_FAILURE([*** no readline support found])
279 fi
280 fi
281 else
282 ax_cv_lib_readline="no"
283 fi
284
285 # SNMP
286 AC_ARG_WITH([snmp],
287 AS_HELP_STRING(
288 [--with-snmp],
289 [Enable the use of SNMP @<:@default=no@:>@]),
290 [],
291 [with_snmp=no])
292 lldp_CHECK_SNMP
293
294 # XML
295 AC_ARG_WITH([xml],
296 AS_HELP_STRING(
297 [--with-xml],
298 [Enable XML output via libxml2 @<:@default=auto@:>@]),
299 [],
300 [with_xml=auto])
301 lldp_CHECK_XML2
302
303 # JSON (built-in)
304 lldp_ARG_ENABLE([json0], [use of pre-0.9.2 JSON/json-c format], [no])
305
306 # Seccomp
307 AC_ARG_WITH([seccomp],
308 AS_HELP_STRING(
309 [--with-seccomp],
310 [Enable seccomp support (with libseccomp, experimental) @<:@default=no@:>@]),
311 [],
312 [with_seccomp=no])
313 lldp_CHECK_SECCOMP
314
315 # OS X launchd support
316 lldp_ARG_WITH([launchddaemonsdir], [Directory for launchd configuration file (OSX)],
317 [/Library/LaunchDaemons])
318 AC_SUBST([launchddaemonsdir], [$with_launchddaemonsdir])
319 AM_CONDITIONAL(HAVE_LAUNCHDDAEMONSDIR,
320 [test -n "$with_launchddaemonsdir" -a "x$with_launchddaemonsdir" != xno ])
321
322 # Systemd
323 lldp_ARG_WITH([systemdsystemunitdir], [Directory for systemd service files],
324 [$($PKG_CONFIG --variable=systemdsystemunitdir systemd 2> /dev/null)])
325 AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
326 AM_CONDITIONAL(HAVE_SYSTEMDSYSTEMUNITDIR,
327 [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ])
328
329 # sysusers
330 lldp_ARG_WITH([sysusersdir], [Directory for sysusers files],
331 [$($PKG_CONFIG --variable=sysusersdir systemd 2> /dev/null)])
332 AC_SUBST([sysusersdir], [$with_sysusersdir])
333 AM_CONDITIONAL(HAVE_SYSUSERSDIR,
334 [test -n "$with_sysusersdir" -a "x$with_sysusersdir" != xno ])
335
336 # AppArmor
337 lldp_ARG_WITH([apparmordir], [Directory for AppArmor profiles (Linux)],
338 [no])
339 AC_SUBST([apparmordir], [$with_apparmordir])
340 AM_CONDITIONAL(HAVE_APPARMORDIR,
341 [test -n "$with_apparmordir" -a "x$with_apparmordir" != xno ])
342
343 # Systemtap/DTrace
344 lldp_SYSTEMTAP
345
346 # Privsep settings
347 lldp_ARG_ENABLE([privsep], [Privilege separation], [yes])
348 lldp_ARG_WITH([privsep-user], [Which user to use for privilege separation], [_lldpd])
349 lldp_ARG_WITH([privsep-group], [Which group to use for privilege separation], [_lldpd])
350
351 # Directories
352 dnl On autoconf 2.69 and before, runstatedir is not configurable, let be able to use it anyway
353 if test "x$runstatedir" = x; then
354 AC_SUBST([runstatedir], ['${localstatedir}/run'])
355 fi
356 lldp_ARG_WITH([privsep-chroot], [Which directory to use to chroot lldpd], [${runstatedir}/lldpd])
357 lldp_ARG_WITH([lldpd-ctl-socket], [Path to socket for communication with lldpd], [${runstatedir}/lldpd.socket])
358 lldp_ARG_WITH([lldpd-pid-file], [Path to lldpd PID file], [${runstatedir}/lldpd.pid])
359
360 # Netlink
361 lldp_ARG_WITH_UNQUOTED([netlink-max-receive-bufsize], [Netlink maximum receive buffer size], [1024*1024])
362 lldp_ARG_WITH_UNQUOTED([netlink-receive-bufsize], [Netlink initial receive buffer size], [0])
363 lldp_ARG_WITH_UNQUOTED([netlink-send-bufsize], [Netlink send buffer size], [0])
364
365 # CDP/FDP/EDP/SONMP
366 lldp_ARG_ENABLE([cdp], [Cisco Discovery Protocol], [yes])
367 lldp_ARG_ENABLE([fdp], [Foundry Discovery Protocol], [yes])
368 lldp_ARG_ENABLE([edp], [Extreme Discovery Protocol], [yes])
369 lldp_ARG_ENABLE([sonmp], [SynOptics Network Management Protocol], [yes])
370
371 # LLDPMED/Dot1/Dot3
372 lldp_ARG_ENABLE([lldpmed], [LLDP-MED extension], [yes])
373 lldp_ARG_ENABLE([dot1], [Dot1 extension (VLAN stuff)], [yes])
374 lldp_ARG_ENABLE([dot3], [Dot3 extension (PHY stuff)], [yes])
375 lldp_ARG_ENABLE([custom], [Custom TLV support], [yes])
376
377 # Oldies
378 MIN_LINUX_KERNEL_VERSION=2.6.39
379 lldp_ARG_ENABLE([oldies], [compatibility with Linux kernel older than 2.6.39], [no])
380 if test x"$os" = x"Linux"; then
381 if test x"$enable_oldies" = x"no"; then
382 AC_DEFINE_UNQUOTED(MIN_LINUX_KERNEL_VERSION, "[$MIN_LINUX_KERNEL_VERSION]", [Minimal Linux kernel version required])
383 else
384 AC_DEFINE(MIN_LINUX_KERNEL_VERSION, "2.6.11", [Minimal kernel version required])
385 fi
386 fi
387
388 AX_BUILD_DATE_EPOCH(BUILD_DATE, "%FT%TZ", [BUILD_DATE="(unknown)"])
389 AC_DEFINE_UNQUOTED(BUILD_DATE, "[$BUILD_DATE]", [Build date and time])
390
391 dnl per reproducible-builds.org check SOURCE_DATE_EPOCH
392 dnl
393 if test -z "${SOURCE_DATE_EPOCH+set}" ; then
394 AC_DEFINE_UNQUOTED(LLDP_CC, "[$CC $LLDP_CFLAGS $LLDP_CPPFLAGS $CFLAGS $CPPFLAGS]", [C compiler command])
395 AC_DEFINE_UNQUOTED(LLDP_LD, "[$LD $LLDP_LDFLAGS $LLDP_BIN_LDFLAGS $LDFLAGS $LIBS]", [Linker compiler command])
396 else
397 AC_DEFINE_UNQUOTED(LLDP_CC, "[C compiler command is not available for reproducible builds]", [C compiler command])
398 AC_DEFINE_UNQUOTED(LLDP_LD, "[Linker compiler command is not available for reproducible builds]", [Linker compiler command])
399 fi
400
401 #######################
402 # Output results
403 AC_SUBST([LLDP_CFLAGS])
404 AC_SUBST([LLDP_CPPFLAGS])
405 AC_SUBST([LLDP_LDFLAGS])
406 AC_SUBST([LLDP_BIN_LDFLAGS])
407 AM_CONDITIONAL([HAVE_CHECK], [test x"$have_check" = x"yes"])
408 AM_CONDITIONAL([USE_SNMP], [test x"$with_snmp" = x"yes"])
409 AM_CONDITIONAL([USE_XML], [test x"$with_xml" = x"yes"])
410 AM_CONDITIONAL([USE_SECCOMP], [test x"$with_seccomp" = x"yes"])
411 dnl If old default of AR_FLAGS is otherwise being used (because of older automake),
412 dnl replace it with one without 'u'
413 if test "x$AR_FLAGS" = "xcru" ; then
414 AR_FLAGS="cr"
415 fi
416 AC_OUTPUT
417
418 if test x"$LIBEVENT_EMBEDDED" = x; then
419 libevent=system
420 else
421 libevent=embedded
422 fi
423
424 cat <<EOF
425
426 ------------------ Summary ------------------
427 $PACKAGE_NAME version $PACKAGE_VERSION
428 OS.............: $os
429 Prefix.........: $prefix
430 C Compiler.....: $CC $LLDP_CFLAGS $LLDP_CPPFLAGS $CFLAGS $CPPFLAGS
431 Linker.........: $LD $LLDP_LDFLAGS $LLDP_BIN_LDFLAGS $LDFLAGS $LIBS
432 Libevent.......: $libevent
433 Readline.......: ${ax_cv_lib_readline}
434
435 Optional features:
436 SNMP support...: ${with_snmp-no}
437 CDP............: $enable_cdp
438 FDP............: $enable_fdp
439 EDP............: $enable_edp
440 SONMP..........: $enable_sonmp
441 LLDPMED........: $enable_lldpmed
442 DOT1...........: $enable_dot1
443 DOT3...........: $enable_dot3
444 CUSTOM.........: $enable_custom
445 XML output.....: ${with_xml-no}
446 Oldies support.: $enable_oldies
447 seccomp........: ${with_seccomp-no}
448 libbsd.........: ${with_libbsd-no}
449
450 Privilege separation:
451 Enabled........: $enable_privsep
452 User/group.....: ${with_privsep_user}/${with_privsep_group}
453 Chroot.........: ${with_privsep_chroot}
454
455 Instrumentation (for devs only):
456 Sanitizers.....: ${sanitizers:-none}
457 Coverage.......: ${gcov}
458 ------------- Compiler version --------------
459 $($CC --version || true)
460 -------------- Linker version ---------------
461 $($LD --version || true)
462 ---------------------------------------------
463
464 Check the above options and compile with:
465 ${MAKE-make}
466
467 EOF