]> git.ipfire.org Git - thirdparty/lldpd.git/blob - configure.ac
build: try -Wl,-pie before trying -pie for clang
[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])
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
41 #######################
42 ### Checks
43
44 # Checks for programs.
45 AC_PROG_CC
46 AC_PROG_CC_C99
47 if test x"$ac_cv_prog_cc_c99" = x"no"; then
48 AC_MSG_FAILURE([*** C99 support is mandatory])
49 fi
50 AC_PROG_CXX
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([-fdiagnostics-show-option], [LLDP_CFLAGS])
71 AX_CFLAGS_GCC_OPTION([-fdiagnostics-color=auto], [LLDP_CFLAGS])
72 AX_CFLAGS_GCC_OPTION([-pipe], [LLDP_CFLAGS])
73 AX_CFLAGS_GCC_OPTION([-Wall], [LLDP_CFLAGS])
74 AX_CFLAGS_GCC_OPTION([-W], [LLDP_CFLAGS])
75 AX_CFLAGS_GCC_OPTION([-Wextra], [LLDP_CFLAGS])
76 AX_CFLAGS_GCC_OPTION([-Wformat], [LLDP_CFLAGS])
77 AX_CFLAGS_GCC_OPTION([-Wformat-security], [LLDP_CFLAGS])
78 AX_CFLAGS_GCC_OPTION([-Wfatal-errors], [LLDP_CFLAGS])
79 AX_CFLAGS_GCC_OPTION([-Wcast-align], [LLDP_CFLAGS])
80 AX_CFLAGS_GCC_OPTION([-Winline], [LLDP_CFLAGS])
81 AX_CFLAGS_GCC_OPTION([-fno-omit-frame-pointer], [LLDP_CFLAGS])
82 AX_CFLAGS_GCC_OPTION([-Wno-unused-parameter], [LLDP_CFLAGS])
83 AX_CFLAGS_GCC_OPTION([-Wno-missing-field-initializers], [LLDP_CFLAGS])
84 AX_CFLAGS_GCC_OPTION([-Wno-sign-compare], [LLDP_CFLAGS]) dnl Should be fixed later
85 AX_LDFLAGS_OPTION([-Wl,-z,relro], [LLDP_LDFLAGS])
86 AX_LDFLAGS_OPTION([-Wl,-z,now], [LLDP_LDFLAGS])
87
88 # OS
89 lldp_CHECK_OS
90 lldp_CFLAGS_OS
91
92 AC_CACHE_SAVE
93
94 # Checks for header files.
95 AC_HEADER_RESOLV
96 AC_CHECK_HEADERS([valgrind/valgrind.h])
97 lldp_CHECK_STDINT
98
99 AC_CACHE_SAVE
100
101 # Checks for typedefs, structures, and compiler characteristics.
102 lldp_CHECK___PROGNAME
103 lldp_CHECK_ALIGNOF
104
105 # Checks for library functions.
106 AC_CONFIG_LIBOBJ_DIR([src/compat])
107 AC_FUNC_MALLOC
108 AC_FUNC_REALLOC
109 AC_FUNC_FORK
110 # setproctitle (maybe through libbsd)
111 AC_SEARCH_LIBS([setproctitle], [util bsd])
112 AC_REPLACE_FUNCS([setproctitle])
113 AC_CHECK_FUNCS([setproctitle_init])
114 # Other functions
115 AC_REPLACE_FUNCS([strlcpy
116 strnlen
117 strndup
118 fgetln
119 asprintf
120 vsyslog
121 daemon])
122 # Optional functions
123 AC_CHECK_FUNCS([setresuid setresgid])
124
125 case " $LIBS " in
126 *\ -lbsd\ *)
127 AC_DEFINE(HAVE_LIBBSD, 1, [Define if libbsd is used])
128 ;;
129 esac
130
131 # Check for res_init. On OSX, res_init is a symbol in libsystem_info
132 # and a macro in resolv.h. We need to ensure we test with resolv.h.
133 m4_pushdef([AC_LANG_CALL(C)], [
134 AC_LANG_PROGRAM([$1
135 @%:@include <resolv.h>], [return $2 ();])])
136 AC_SEARCH_LIBS([res_init], resolv bind,
137 AC_DEFINE([HAVE_RES_INIT], 1,
138 [Define to indicate that res_init() exists]))
139 m4_popdef([AC_LANG_CALL(C)])
140
141 AC_CACHE_SAVE
142
143 ## Unit tests wich check
144 PKG_CHECK_MODULES([CHECK], [check >= 0.9.4], [have_check=yes], [have_check=no])
145
146 # Libevent
147 lldp_CHECK_LIBEVENT
148
149 # Compatibility with pkg.m4 < 0.27
150 m4_ifdef([PKG_INSTALLDIR], [PKG_INSTALLDIR],
151 [AC_ARG_WITH([pkgconfigdir],
152 [AS_HELP_STRING([--with-pkgconfigdir],
153 [install directory for *.pc pkg-config file])],
154 [],[with_pkgconfigdir='$(libdir)/pkgconfig'])
155 AC_SUBST([pkgconfigdir], [${with_pkgconfigdir}])])
156
157 #######################
158 ### Options
159
160 # Readline
161 AC_ARG_WITH([readline],
162 AS_HELP_STRING(
163 [--with-readline],
164 [Enable the use of readline-like library @<:@default=auto@:>@]),
165 [],
166 [with_readline=auto])
167 if test x"$with_readline" != x"no"; then
168 AX_LIB_READLINE
169 if test x"$with_readline" != x"check" -a x"$with_readline" != x"auto"; then
170 if test x"$ax_cv_lib_readline" = x"no"; then
171 AC_MSG_FAILURE([*** no readline support found])
172 fi
173 fi
174 else
175 ax_cv_lib_readline="no"
176 fi
177
178 # SNMP
179 AC_ARG_WITH([snmp],
180 AS_HELP_STRING(
181 [--with-snmp],
182 [Enable the use of SNMP @<:@default=no@:>@]),
183 [],
184 [with_snmp=no])
185 lldp_CHECK_SNMP
186
187 # XML
188 AC_ARG_WITH([xml],
189 AS_HELP_STRING(
190 [--with-xml],
191 [Enable XML output via libxml2 @<:@default=auto@:>@]),
192 [],
193 [with_xml=auto])
194 lldp_CHECK_XML2
195
196 # JSON
197 AC_ARG_WITH([json],
198 AS_HELP_STRING(
199 [--with-json],
200 [Enable JSON output via janson or json-c @<:@default=auto@:>@]),
201 [],
202 [with_json=auto])
203 if test x"$with_json" = x"yes" -o x"$with_json" = x"auto"; then
204 _with_json="$with_json"
205 with_json=auto
206 lldp_CHECK_JANSSON
207 if test x"$with_json" = x"no"; then
208 with_json=auto
209 lldp_CHECK_JSONC
210 fi
211 if test x"$with_json" = x"no" -a x"$_with_json" = x"yes"; then
212 AC_MSG_FAILURE([*** no JSON support found])
213 fi
214 else
215 lldp_CHECK_JANSSON
216 lldp_CHECK_JSONC
217 fi
218
219 # Seccomp
220 AC_ARG_WITH([seccomp],
221 AS_HELP_STRING(
222 [--with-seccomp],
223 [Enable seccomp support (with libseccomp) @<:@default=no@:>@]),
224 [],
225 [with_seccomp=no])
226 lldp_CHECK_SECCOMP
227
228 # OS X launchd support
229 lldp_ARG_WITH([launchddaemonsdir], [Directory for launchd configuration file (OSX)],
230 [/Library/LaunchDaemons])
231 AC_SUBST([launchddaemonsdir], [$with_launchddaemonsdir])
232 AM_CONDITIONAL(HAVE_LAUNCHDDAEMONSDIR,
233 [test -n "$with_launchddaemonsdir" -a "x$with_launchddaemonsdir" != xno ])
234
235 # Systemd
236 lldp_ARG_WITH([systemdsystemunitdir], [Directory for systemd service files],
237 [$($PKG_CONFIG --variable=systemdsystemunitdir systemd 2> /dev/null)])
238 AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])
239 AM_CONDITIONAL(HAVE_SYSTEMDSYSTEMUNITDIR,
240 [test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ])
241
242 # sysusers
243 lldp_ARG_WITH([sysusersdir], [Directory for sysusers files],
244 [$($PKG_CONFIG --variable=sysusersdir systemd 2> /dev/null)])
245 AC_SUBST([sysusersdir], [$with_sysusersdir])
246 AM_CONDITIONAL(HAVE_SYSUSERSDIR,
247 [test -n "$with_sysusersdir" -a "x$with_sysusersdir" != xno ])
248
249 # Systemtap/DTrace
250 lldp_SYSTEMTAP
251
252 # Privsep settings
253 lldp_ARG_ENABLE([privsep], [Privilege separation], [yes])
254 lldp_ARG_WITH([privsep-user], [Which user to use for privilege separation], [_lldpd])
255 lldp_ARG_WITH([privsep-group], [Which group to use for privilege separation], [_lldpd])
256
257 # Directories
258 dnl On autoconf 2.69 and before, runstatedir is not configurable, let be able to use it anyway
259 if test "x$runstatedir" = x; then
260 AC_SUBST([runstatedir], ['${localstatedir}/run'])
261 fi
262 lldp_ARG_WITH([privsep-chroot], [Which directory to use to chroot lldpd], [${runstatedir}/lldpd])
263 lldp_ARG_WITH([lldpd-ctl-socket], [Path to socket for communication with lldpd], [${runstatedir}/lldpd.socket])
264 lldp_ARG_WITH([lldpd-pid-file], [Path to lldpd PID file], [${runstatedir}/lldpd.pid])
265
266 # CDP/FDP/EDP/SONMP
267 lldp_ARG_ENABLE([cdp], [Cisco Discovery Protocol], [yes])
268 lldp_ARG_ENABLE([fdp], [Foundry Discovery Protocol], [yes])
269 lldp_ARG_ENABLE([edp], [Extreme Discovery Protocol], [yes])
270 lldp_ARG_ENABLE([sonmp], [SynOptics Network Management Protocol], [yes])
271
272 # LLDPMED/Dot1/Dot3
273 lldp_ARG_ENABLE([lldpmed], [LLDP-MED extension], [yes])
274 lldp_ARG_ENABLE([dot1], [Dot1 extension (VLAN stuff)], [yes])
275 lldp_ARG_ENABLE([dot3], [Dot3 extension (PHY stuff)], [yes])
276
277 # Oldies
278 lldp_ARG_ENABLE([oldies], [compatibility with Linux kernel older than 2.6.18], [no])
279
280
281 # Hardening
282 AC_ARG_ENABLE([hardening],
283 [AS_HELP_STRING([--enable-hardening],
284 [Enable compiler and linker options to frustrate memory corruption exploits @<:@yes@:>@])],
285 [hardening="$enableval"],
286 [hardening="yes"])
287
288 if test x"$hardening" != x"no"; then
289 AX_CFLAGS_GCC_OPTION([-fstack-protector], [LLDP_CFLAGS])
290 AX_CFLAGS_GCC_OPTION([-fstack-protector-all], [LLDP_CFLAGS])
291 AX_CFLAGS_GCC_OPTION([-fstack-protector-strong], [LLDP_CFLAGS])
292 AX_CFLAGS_GCC_OPTION([-D_FORTIFY_SOURCE=2], [LLDP_CPPFLAGS])
293 if test x"$LIBEVENT_EMBEDDED" = x; then
294 AX_CFLAGS_GCC_OPTION([-fPIE], [LLDP_CFLAGS])
295 AX_LDFLAGS_OPTION([-fPIE -Wl,-pie], [LLDP_LDFLAGS],
296 [AX_LDFLAGS_OPTION([-fPIE -pie], [LLDP_LDFLAGS])])
297 fi
298 fi
299
300 #######################
301 # Output results
302 AC_SUBST([LLDP_CFLAGS])
303 AC_SUBST([LLDP_CPPFLAGS])
304 AC_SUBST([LLDP_LDFLAGS])
305 AM_CONDITIONAL([HAVE_CHECK], [test x"$have_check" = x"yes"])
306 AM_CONDITIONAL([USE_SNMP], [test x"$with_snmp" = x"yes"])
307 AM_CONDITIONAL([USE_XML], [test x"$with_xml" = x"yes"])
308 AM_CONDITIONAL([USE_JSON], [test x"$with_json" = x"json-c" || test -x"$with_json" = x"jansson"])
309 AM_CONDITIONAL([USE_JANSSON], [test x"$with_json" = x"jansson"])
310 AM_CONDITIONAL([USE_JSONC], [test x"$with_json" = x"json-c"])
311 AM_CONDITIONAL([USE_SECCOMP], [test x"$with_seccomp" = x"yes"])
312 AC_OUTPUT
313
314 if test x"$LIBEVENT_EMBEDDED" = x; then
315 libevent=system
316 else
317 libevent=embedded
318 fi
319
320 cat <<EOF
321
322 ------------------ Summary ------------------
323 $PACKAGE_NAME version $PACKAGE_VERSION
324 OS.............: $os
325 Prefix.........: $prefix
326 C Compiler.....: $CC $LLDP_CFLAGS $LLDP_CPPFLAGS $CFLAGS $CPPFLAGS
327 Linker.........: $LD $LLDP_LDFLAGS $LDFLAGS $LIBS
328 Libevent.......: $libevent
329 Readline.......: ${ax_cv_lib_readline}
330 Optional features:
331 SNMP support...: ${with_snmp-no}
332 CDP............: $enable_cdp
333 FDP............: $enable_fdp
334 EDP............: $enable_edp
335 SONMP..........: $enable_sonmp
336 LLDPMED........: $enable_lldpmed
337 DOT1...........: $enable_dot1
338 DOT3...........: $enable_dot3
339 XML output.....: ${with_xml-no}
340 JSON output....: ${with_json-no}
341 Oldies support.: $enable_oldies
342 seccomp........: ${with_seccomp-no}
343 Privilege separation:
344 Enabled........: $enable_privsep
345 User/group.....: ${with_privsep_user}/${with_privsep_group}
346 Chroot.........: ${with_privsep_chroot}
347 ---------------------------------------------
348
349 Check the above options and compile with:
350 ${MAKE-make}
351
352 EOF