]> git.ipfire.org Git - thirdparty/lldpd.git/blame - configure.ac
lib: use C preprocessor to build list of init functions
[thirdparty/lldpd.git] / configure.ac
CommitLineData
43c02e7b
VB
1# -*- Autoconf -*-
2# Process this file with autoconf to produce a configure script.
3
d38eae28
VB
4#######################
5### Base configuration
6
7# Configure autoconf
8AC_PREREQ([2.64])
4593c0dc 9
4593c0dc 10AC_INIT([lldpd],
a888bea6 11 [m4_esyscmd_s([./get-version])],
493b0d42
VB
12 [https://github.com/vincentbernat/lldpd/issues],
13 [lldpd],
14 [http://vincentbernat.github.io/lldpd/])
4593c0dc 15
4b292b55 16AC_CONFIG_SRCDIR([src/log.c])
43c02e7b 17AC_CONFIG_HEADER([config.h])
95493844
VB
18AC_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])
2acc1418 26AC_CONFIG_MACRO_DIR([m4])
fa71a00c 27AC_SUBST([CONFIGURE_ARGS], [$ac_configure_args])
43c02e7b 28
d38eae28 29# Configure automake
4a0791a4 30AM_INIT_AUTOMAKE([foreign subdir-objects -Wall -Werror tar-ustar])
33aa26d0 31AM_MAINTAINER_MODE
44cd2bed 32m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES(yes)])
d38eae28 33
0339b9a2
VB
34# Automake 1.12...
35m4_pattern_allow([AM_PROG_AR])
36AM_PROG_AR
37
d38eae28 38# Configure libtool
d38eae28 39LT_INIT
f571f2db 40gl_LD_VERSION_SCRIPT
d38eae28
VB
41
42#######################
43### Checks
44
43c02e7b
VB
45# Checks for programs.
46AC_PROG_CC
6c586123 47AC_PROG_CC_C99
630cc035
VB
48if test x"$ac_cv_prog_cc_c99" = x"no"; then
49 AC_MSG_FAILURE([*** C99 support is mandatory])
50fi
223227c8 51AC_PROG_CXX
d38eae28 52AM_PROG_CC_C_O
f5bc67ee 53AC_PROG_LIBTOOL
fe80711e 54AC_PROG_LN_S
7ba4a183 55AC_PROG_EGREP
140e34f0 56AC_PROG_AWK
2acc1418 57
4b292b55
VB
58# Doxygen
59DX_HTML_FEATURE(ON)
60DX_DOT_FEATURE(OFF)
61DX_CHM_FEATURE(OFF)
62DX_CHI_FEATURE(OFF)
63DX_MAN_FEATURE(OFF)
64DX_RTF_FEATURE(OFF)
65DX_XML_FEATURE(OFF)
66DX_PDF_FEATURE(ON)
67DX_PS_FEATURE(OFF)
68DX_INIT_DOXYGEN([lldpd], [doxygen.cfg], [doxygen])
69
45e89c8c 70# Check some compiler flags
f42b8214 71AX_CFLAGS_GCC_OPTION([-Wunknown-warning-option], [LLDP_CFLAGS])
8d92800b
VB
72AX_CFLAGS_GCC_OPTION([-fdiagnostics-show-option], [LLDP_CFLAGS])
73AX_CFLAGS_GCC_OPTION([-fdiagnostics-color=auto], [LLDP_CFLAGS])
74AX_CFLAGS_GCC_OPTION([-pipe], [LLDP_CFLAGS])
75AX_CFLAGS_GCC_OPTION([-Wall], [LLDP_CFLAGS])
76AX_CFLAGS_GCC_OPTION([-W], [LLDP_CFLAGS])
77AX_CFLAGS_GCC_OPTION([-Wextra], [LLDP_CFLAGS])
78AX_CFLAGS_GCC_OPTION([-Wformat], [LLDP_CFLAGS])
79AX_CFLAGS_GCC_OPTION([-Wformat-security], [LLDP_CFLAGS])
80AX_CFLAGS_GCC_OPTION([-Wfatal-errors], [LLDP_CFLAGS])
81AX_CFLAGS_GCC_OPTION([-Wcast-align], [LLDP_CFLAGS])
09f0af1d
ALG
82AX_CFLAGS_GCC_OPTION([-Wheader-guard], [LLDP_CFLAGS])
83AX_CFLAGS_GCC_OPTION([-Wdocumentation], [LLDP_CFLAGS])
8d92800b 84AX_CFLAGS_GCC_OPTION([-Winline], [LLDP_CFLAGS])
dff59172 85AX_CFLAGS_GCC_OPTION([-Wpointer-arith], [LLDP_CFLAGS])
8d92800b 86AX_CFLAGS_GCC_OPTION([-fno-omit-frame-pointer], [LLDP_CFLAGS])
8d92800b
VB
87AX_CFLAGS_GCC_OPTION([-Wno-unused-parameter], [LLDP_CFLAGS])
88AX_CFLAGS_GCC_OPTION([-Wno-missing-field-initializers], [LLDP_CFLAGS])
89AX_CFLAGS_GCC_OPTION([-Wno-sign-compare], [LLDP_CFLAGS]) dnl Should be fixed later
90AX_LDFLAGS_OPTION([-Wl,-z,relro], [LLDP_LDFLAGS])
91AX_LDFLAGS_OPTION([-Wl,-z,now], [LLDP_LDFLAGS])
19a5c9b6 92
56663327
VB
93# Hardening
94AC_ARG_ENABLE([hardening],
95 [AS_HELP_STRING([--enable-hardening],
d2a01934 96 [Enable compiler and linker options to frustrate memory corruption exploits @<:@default=yes@:>@])],
56663327
VB
97 [hardening="$enableval"],
98 [hardening="yes"])
a8add742
VB
99AC_ARG_ENABLE([pie],
100 [AS_HELP_STRING([--enable-pie],
101 [Enable PIE (position independant executable) @<:@default=no@:>@])],
102 [pie="$enableval"],
103 [pie="no"])
56663327
VB
104
105if test x"$hardening" != x"no"; then
106 AX_CFLAGS_GCC_OPTION([-fstack-protector], [LLDP_CFLAGS])
107 AX_CFLAGS_GCC_OPTION([-fstack-protector-all], [LLDP_CFLAGS])
108 AX_CFLAGS_GCC_OPTION([-fstack-protector-strong], [LLDP_CFLAGS])
109 AX_CFLAGS_GCC_OPTION([-D_FORTIFY_SOURCE=2], [LLDP_CPPFLAGS])
a8add742
VB
110fi
111if test x"$pie" = x"yes"; then
56663327 112 AX_CFLAGS_GCC_OPTION([-fPIE], [LLDP_CFLAGS])
f42b8214
VB
113 AX_LDFLAGS_OPTION([-fPIE -pie], [LLDP_BIN_LDFLAGS],
114 [AX_LDFLAGS_OPTION([-fPIE -Wl,-pie], [LLDP_BIN_LDFLAGS])])
56663327
VB
115fi
116
33fd6231
VB
117# Sanitizers
118AC_ARG_ENABLE([sanitizers],
119 AS_HELP_STRING(
120 [--enable-sanitizers],
121 [Enable code instrumentation with selected sanitizers @<:@default=no@:>@]),
122 [
123case "$enableval" in
124 no) sanitizers= ;;
2315d097 125 yes) sanitizers="-fsanitize=address,undefined" ;;
33fd6231
VB
126 *) sanitizers="-fsanitize=$enableval" ;;
127esac
dc37bc8d
VB
128if test x"$sanitizers" != x; then
129 LLDP_CFLAGS="$LLDP_CFLAGS $sanitizers"
130 LLDP_LDFLAGS="$LLDP_LDFLAGS $sanitizers"
131 AC_DEFINE([HAVE_ADDRESS_SANITIZER], 1, [Define if have both address and leak sanitizer])
132fi
33fd6231
VB
133 ])
134
e12c2365
VB
135# OS
136lldp_CHECK_OS
3dc1eb8c 137lldp_CFLAGS_OS
24b8d79f 138
8e4b9031
VB
139AC_CACHE_SAVE
140
d38eae28
VB
141# Checks for header files.
142AC_HEADER_RESOLV
396cfdfe 143AC_CHECK_HEADERS([valgrind/valgrind.h])
c3e340b6 144lldp_CHECK_STDINT
43c02e7b 145
8e4b9031
VB
146AC_CACHE_SAVE
147
43c02e7b 148# Checks for typedefs, structures, and compiler characteristics.
6bb9c4e0 149lldp_CHECK___PROGNAME
dd1d33cf 150lldp_CHECK_ALIGNOF
43c02e7b
VB
151
152# Checks for library functions.
4b292b55 153AC_CONFIG_LIBOBJ_DIR([src/compat])
d38eae28
VB
154AC_FUNC_MALLOC
155AC_FUNC_REALLOC
45bf0bd0 156AC_FUNC_FORK
47bbc5f3
VB
157
158# Some functions can be in libbsd
cbe8bbd6
VB
159PKG_CHECK_MODULES([libbsd], [libbsd-overlay], [
160 _save_CFLAGS="$CFLAGS"
161 _save_LIBS="$LIBS"
162 CFLAGS="$CFLAGS $libbsd_CFLAGS"
163 LIBS="$LIBS $libbsd_LIBS"
164 AC_MSG_CHECKING([if libbsd can be linked correctly])
165 AC_LINK_IFELSE([AC_LANG_SOURCE([[int main() { return 0; }]])],
166 [
167 AC_MSG_RESULT(yes)
168 LLDP_CFLAGS="$LLDP_CFLAGS $libbsd_CFLAGS"
169 LLDP_LDFLAGS="$LLDP_LDFLAGS $libbsd_LIBS"
170 ],[
171 AC_MSG_RESULT(no)
172 CFLAGS="$_save_CFLAGS"
173 LIBS="$_save_LIBS"
174 ])
175], [:])
e01aeb55 176
47bbc5f3 177# setproctitle may have an _init function
1e0d651f
VB
178AC_REPLACE_FUNCS([setproctitle])
179AC_CHECK_FUNCS([setproctitle_init])
554d650d
VB
180# Other functions
181AC_REPLACE_FUNCS([strlcpy
182 strnlen
183 strndup
af828c47 184 getline
554d650d
VB
185 asprintf
186 vsyslog
187 daemon])
188# Optional functions
8dab5698 189AC_CHECK_FUNCS([setresuid setresgid])
e66b7f34 190
d0a03372
VB
191# Check for res_init. On OSX, res_init is a symbol in libsystem_info
192# and a macro in resolv.h. We need to ensure we test with resolv.h.
193m4_pushdef([AC_LANG_CALL(C)], [
194 AC_LANG_PROGRAM([$1
195@%:@include <resolv.h>], [return $2 ();])])
196AC_SEARCH_LIBS([res_init], resolv bind,
197 AC_DEFINE([HAVE_RES_INIT], 1,
198 [Define to indicate that res_init() exists]))
199m4_popdef([AC_LANG_CALL(C)])
e66b7f34 200
8e4b9031
VB
201AC_CACHE_SAVE
202
d38eae28
VB
203## Unit tests wich check
204PKG_CHECK_MODULES([CHECK], [check >= 0.9.4], [have_check=yes], [have_check=no])
43c02e7b 205
13181ede 206# Third-party libraries
c461e5da 207lldp_CHECK_LIBEVENT
e5c94652 208
135ff0f7
VB
209# Compatibility with pkg.m4 < 0.27
210m4_ifdef([PKG_INSTALLDIR], [PKG_INSTALLDIR],
211 [AC_ARG_WITH([pkgconfigdir],
212 [AS_HELP_STRING([--with-pkgconfigdir],
213 [install directory for *.pc pkg-config file])],
214 [],[with_pkgconfigdir='$(libdir)/pkgconfig'])
215 AC_SUBST([pkgconfigdir], [${with_pkgconfigdir}])])
216
d38eae28
VB
217#######################
218### Options
43c02e7b 219
35f6f4fb
VB
220# Readline
221AC_ARG_WITH([readline],
222 AS_HELP_STRING(
223 [--with-readline],
fa9b12c5 224 [Enable the use of readline-like library @<:@default=auto@:>@]),
35f6f4fb 225 [],
fa9b12c5 226 [with_readline=auto])
35f6f4fb
VB
227if test x"$with_readline" != x"no"; then
228 AX_LIB_READLINE
fa9b12c5 229 if test x"$with_readline" != x"check" -a x"$with_readline" != x"auto"; then
35f6f4fb
VB
230 if test x"$ax_cv_lib_readline" = x"no"; then
231 AC_MSG_FAILURE([*** no readline support found])
232 fi
233 fi
234else
235 ax_cv_lib_readline="no"
236fi
237
d38eae28
VB
238# SNMP
239AC_ARG_WITH([snmp],
240 AS_HELP_STRING(
241 [--with-snmp],
fa9b12c5
VB
242 [Enable the use of SNMP @<:@default=no@:>@]),
243 [],
244 [with_snmp=no])
245lldp_CHECK_SNMP
315587ef 246
8beb9a73 247# XML
1480ce74 248AC_ARG_WITH([xml],
00e40dba 249 AS_HELP_STRING(
1480ce74 250 [--with-xml],
dd8c9fe3 251 [Enable XML output via libxml2 @<:@default=auto@:>@]),
fa9b12c5 252 [],
dd8c9fe3 253 [with_xml=auto])
fa9b12c5 254lldp_CHECK_XML2
1480ce74 255
8b7150e4
VB
256# JSON
257AC_ARG_WITH([json],
00e40dba 258 AS_HELP_STRING(
8b7150e4 259 [--with-json],
dd8c9fe3 260 [Enable JSON output via janson or json-c @<:@default=auto@:>@]),
fa9b12c5 261 [],
dd8c9fe3 262 [with_json=auto])
fa9b12c5
VB
263if test x"$with_json" = x"yes" -o x"$with_json" = x"auto"; then
264 _with_json="$with_json"
265 with_json=auto
266 lldp_CHECK_JANSSON
267 if test x"$with_json" = x"no"; then
268 with_json=auto
269 lldp_CHECK_JSONC
270 fi
271 if test x"$with_json" = x"no" -a x"$_with_json" = x"yes"; then
272 AC_MSG_FAILURE([*** no JSON support found])
273 fi
274else
8b7150e4 275 lldp_CHECK_JANSSON
8ff14a6d 276 lldp_CHECK_JSONC
8b7150e4
VB
277fi
278
00e40dba
VB
279# Seccomp
280AC_ARG_WITH([seccomp],
281 AS_HELP_STRING(
282 [--with-seccomp],
5472ac18 283 [Enable seccomp support (with libseccomp, experimental) @<:@default=no@:>@]),
00e40dba
VB
284 [],
285 [with_seccomp=no])
286lldp_CHECK_SECCOMP
287
c3f85560 288# OS X launchd support
4dfe31fd
VB
289lldp_ARG_WITH([launchddaemonsdir], [Directory for launchd configuration file (OSX)],
290 [/Library/LaunchDaemons])
291AC_SUBST([launchddaemonsdir], [$with_launchddaemonsdir])
292AM_CONDITIONAL(HAVE_LAUNCHDDAEMONSDIR,
293 [test -n "$with_launchddaemonsdir" -a "x$with_launchddaemonsdir" != xno ])
9d1524b7
VB
294
295# Systemd
296lldp_ARG_WITH([systemdsystemunitdir], [Directory for systemd service files],
29760896 297 [$($PKG_CONFIG --variable=systemdsystemunitdir systemd 2> /dev/null)])
4dfe31fd
VB
298AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
299AM_CONDITIONAL(HAVE_SYSTEMDSYSTEMUNITDIR,
300 [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ])
c3f85560 301
a9f77488
VB
302# sysusers
303lldp_ARG_WITH([sysusersdir], [Directory for sysusers files],
304 [$($PKG_CONFIG --variable=sysusersdir systemd 2> /dev/null)])
305AC_SUBST([sysusersdir], [$with_sysusersdir])
306AM_CONDITIONAL(HAVE_SYSUSERSDIR,
307 [test -n "$with_sysusersdir" -a "x$with_sysusersdir" != xno ])
308
cd7ee899
VB
309# AppArmor
310lldp_ARG_WITH([apparmordir], [Directory for AppArmor profiles (Linux)],
311 [no])
312AC_SUBST([apparmordir], [$with_apparmordir])
313AM_CONDITIONAL(HAVE_APPARMORDIR,
314 [test -n "$with_apparmordir" -a "x$with_apprmordir" != xno ])
315
bdfe4193
VB
316# Systemtap/DTrace
317lldp_SYSTEMTAP
318
d38eae28 319# Privsep settings
71a7dbb3 320lldp_ARG_ENABLE([privsep], [Privilege separation], [yes])
d38eae28
VB
321lldp_ARG_WITH([privsep-user], [Which user to use for privilege separation], [_lldpd])
322lldp_ARG_WITH([privsep-group], [Which group to use for privilege separation], [_lldpd])
9a4ed64a
VB
323
324# Directories
325dnl On autoconf 2.69 and before, runstatedir is not configurable, let be able to use it anyway
326if test "x$runstatedir" = x; then
327 AC_SUBST([runstatedir], ['${localstatedir}/run'])
328fi
329lldp_ARG_WITH([privsep-chroot], [Which directory to use to chroot lldpd], [${runstatedir}/lldpd])
3a3a3623 330lldp_ARG_WITH([lldpd-ctl-socket], [Path to socket for communication with lldpd], [${runstatedir}/lldpd.socket])
5133ce2f 331lldp_ARG_WITH([lldpd-pid-file], [Path to lldpd PID file], [${runstatedir}/lldpd.pid])
89840df0 332
d38eae28
VB
333# CDP/FDP/EDP/SONMP
334lldp_ARG_ENABLE([cdp], [Cisco Discovery Protocol], [yes])
335lldp_ARG_ENABLE([fdp], [Foundry Discovery Protocol], [yes])
336lldp_ARG_ENABLE([edp], [Extreme Discovery Protocol], [yes])
337lldp_ARG_ENABLE([sonmp], [SynOptics Network Management Protocol], [yes])
a1347cd8 338
d38eae28
VB
339# LLDPMED/Dot1/Dot3
340lldp_ARG_ENABLE([lldpmed], [LLDP-MED extension], [yes])
341lldp_ARG_ENABLE([dot1], [Dot1 extension (VLAN stuff)], [yes])
342lldp_ARG_ENABLE([dot3], [Dot3 extension (PHY stuff)], [yes])
fb1b78bb 343lldp_ARG_ENABLE([custom], [Custom TLV support], [yes])
a1347cd8 344
184bd199 345# Oldies
2472bfda 346MIN_LINUX_KERNEL_VERSION=2.6.39
d9fdc886 347lldp_ARG_ENABLE([oldies], [compatibility with Linux kernel older than 2.6.39], [no])
2472bfda
VB
348if test x"$os" = x"Linux"; then
349 if test x"$enable_oldies" = x"no"; then
350 AC_DEFINE_UNQUOTED(MIN_LINUX_KERNEL_VERSION, "[$MIN_LINUX_KERNEL_VERSION]", [Minimal Linux kernel version required])
351 else
352 AC_DEFINE(MIN_LINUX_KERNEL_VERSION, "2.6.11", [Minimal kernel version required])
353 fi
354fi
184bd199 355
efa6a7a3
VB
356# Build date
357if test x"$SOURCE_DATE_EPOCH" != x; then
358 AC_DEFINE_UNQUOTED(BUILD_DATE, "[$SOURCE_DATE_EPOCH]", [Build date and time])
359fi
360AC_DEFINE_UNQUOTED(LLDP_CC, "[$CC $LLDP_CFLAGS $LLDP_CPPFLAGS $CFLAGS $CPPFLAGS]", [C compiler command])
361AC_DEFINE_UNQUOTED(LLDP_LD, "[$LD $LLDP_LDFLAGS $LLDP_BIN_LDFLAGS $LDFLAGS $LIBS]", [Linker compiler command])
362
d38eae28
VB
363#######################
364# Output results
8d92800b
VB
365AC_SUBST([LLDP_CFLAGS])
366AC_SUBST([LLDP_CPPFLAGS])
367AC_SUBST([LLDP_LDFLAGS])
f42b8214 368AC_SUBST([LLDP_BIN_LDFLAGS])
d38eae28
VB
369AM_CONDITIONAL([HAVE_CHECK], [test x"$have_check" = x"yes"])
370AM_CONDITIONAL([USE_SNMP], [test x"$with_snmp" = x"yes"])
1480ce74 371AM_CONDITIONAL([USE_XML], [test x"$with_xml" = x"yes"])
8ff14a6d
MS
372AM_CONDITIONAL([USE_JSON], [test x"$with_json" = x"json-c" || test -x"$with_json" = x"jansson"])
373AM_CONDITIONAL([USE_JANSSON], [test x"$with_json" = x"jansson"])
374AM_CONDITIONAL([USE_JSONC], [test x"$with_json" = x"json-c"])
00e40dba 375AM_CONDITIONAL([USE_SECCOMP], [test x"$with_seccomp" = x"yes"])
43c02e7b 376AC_OUTPUT
d38eae28 377
4c1a8c61 378if test x"$LIBEVENT_EMBEDDED" = x; then
e5c94652
VB
379 libevent=system
380else
381 libevent=embedded
382fi
383
d38eae28
VB
384cat <<EOF
385
386------------------ Summary ------------------
387 $PACKAGE_NAME version $PACKAGE_VERSION
91e0280a 388 OS.............: $os
d38eae28 389 Prefix.........: $prefix
8d92800b 390 C Compiler.....: $CC $LLDP_CFLAGS $LLDP_CPPFLAGS $CFLAGS $CPPFLAGS
f42b8214 391 Linker.........: $LD $LLDP_LDFLAGS $LLDP_BIN_LDFLAGS $LDFLAGS $LIBS
e5c94652 392 Libevent.......: $libevent
35f6f4fb 393 Readline.......: ${ax_cv_lib_readline}
457d06aa 394
d38eae28
VB
395 Optional features:
396 SNMP support...: ${with_snmp-no}
397 CDP............: $enable_cdp
398 FDP............: $enable_fdp
399 EDP............: $enable_edp
400 SONMP..........: $enable_sonmp
401 LLDPMED........: $enable_lldpmed
402 DOT1...........: $enable_dot1
403 DOT3...........: $enable_dot3
fb1b78bb 404 CUSTOM.........: $enable_custom
1480ce74 405 XML output.....: ${with_xml-no}
8b7150e4 406 JSON output....: ${with_json-no}
184bd199 407 Oldies support.: $enable_oldies
00e40dba 408 seccomp........: ${with_seccomp-no}
457d06aa 409
71a7dbb3
VB
410 Privilege separation:
411 Enabled........: $enable_privsep
08841844
VB
412 User/group.....: ${with_privsep_user}/${with_privsep_group}
413 Chroot.........: ${with_privsep_chroot}
457d06aa
VB
414------------- Compiler version --------------
415$($CC --version || true)
416-------------- Linker version ---------------
417$($LD --version || true)
d38eae28
VB
418---------------------------------------------
419
420Check the above options and compile with:
421 ${MAKE-make}
422
423EOF