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