]> arthur.barton.de Git - netdata.git/blob - configure.ac
Merge pull request #1968 from ktsaou/master
[netdata.git] / configure.ac
1 #
2 # Copyright (C) 2015 Alon Bar-Lev <alon.barlev@gmail.com>
3 #
4 AC_PREREQ(2.60)
5
6 define([VERSION_MAJOR], [1])
7 define([VERSION_MINOR], [5])
8 define([VERSION_FIX], [1])
9 define([VERSION_NUMBER], VERSION_MAJOR[.]VERSION_MINOR[.]VERSION_FIX)
10 define([VERSION_SUFFIX], [_rolling])
11
12 dnl Set to "1" for a first RPM release of a new version
13 PACKAGE_RPM_RELEASE="0.0.$(echo VERSION_SUFFIX | sed s/^_//)"
14
15 # We do not use m4_esyscmd_s to support older autoconf.
16 define([VERSION_STRING], m4_esyscmd(git describe 2>/dev/null | sed 's/^v//' | tr -d '\n'))
17 m4_ifval(VERSION_STRING, [], [define([VERSION_STRING], VERSION_NUMBER)])
18
19 AC_INIT([netdata], VERSION_STRING[]VERSION_SUFFIX)
20
21 AM_MAINTAINER_MODE([disable])
22 if test x"$USE_MAINTAINER_MODE" = xyes; then
23 AC_MSG_NOTICE(***************** MAINTAINER MODE *****************)
24 PACKAGE_BUILT_DATE=$(date '+%d %b %Y')
25 fi
26
27 PACKAGE_RPM_VERSION="VERSION_NUMBER"
28 AC_SUBST([PACKAGE_RPM_VERSION])
29 AC_SUBST([PACKAGE_RPM_RELEASE])
30
31
32 # -----------------------------------------------------------------------------
33 # autoconf initialization
34
35 AC_CONFIG_AUX_DIR([.])
36 AC_CONFIG_HEADERS([config.h])
37 AC_CONFIG_MACRO_DIR([m4])
38 AC_CONFIG_SRCDIR([src/main.c])
39 AM_INIT_AUTOMAKE
40 AC_CANONICAL_HOST
41 AC_PROG_CC
42 AC_PROG_INSTALL
43 PKG_PROG_PKG_CONFIG
44 AC_USE_SYSTEM_EXTENSIONS
45
46
47 # -----------------------------------------------------------------------------
48 # configurable options
49
50 AC_ARG_ENABLE(
51     [plugin-nfacct],
52     [AS_HELP_STRING([--enable-plugin-nfacct], [enable nfacct plugin, requires root])],
53     ,
54     [enable_plugin_nfacct="no"]
55 )
56 AC_ARG_ENABLE(
57     [plugin-freeipmi],
58     [AS_HELP_STRING([--enable-plugin-freeipmi], [enable freeipmi plugin])],
59     ,
60     [enable_plugin_freeipmi="detect"]
61 )
62 AC_ARG_ENABLE(
63     [pedantic],
64     [AS_HELP_STRING([--enable-pedantic], [enable pedantic compiler warnings])],
65     ,
66     [enable_pedantic="no"]
67 )
68 AC_ARG_WITH(
69     [webdir],
70     [AS_HELP_STRING([--with-webdir], [location of webdir @<:@PKGDATADIR/web@:>@])],
71     [webdir="${withval}"],
72     [webdir="\$(pkgdatadir)/web"]
73 )
74 AC_ARG_WITH(
75     [libcap],
76     [AS_HELP_STRING([--with-libcap], [build with libcap])],
77     ,
78     [with_libcap="detect"]
79 )
80 AC_ARG_WITH(
81     [zlib],
82     [AS_HELP_STRING([--with-zlib], [build with zlib])],
83     ,
84     [with_zlib="yes"]
85 )
86 AC_ARG_WITH(
87     [math],
88     [AS_HELP_STRING([--with-math], [build with math])],
89     ,
90     [with_math="yes"]
91 )
92 AC_ARG_WITH(
93     [user],
94     [AS_HELP_STRING([--with-user], [use this user to drop privilege])],
95     ,
96     [with_user="nobody"]
97 )
98 AC_ARG_ENABLE(
99     [x86-sse],
100     [AS_HELP_STRING([--disable-x86-sse], [SSE/SS2 optimizations on x86 @<:@default enabled@:>@])],
101     ,
102     [enable_x86_sse="yes"]
103 )
104 AC_ARG_ENABLE(
105     [lto],
106     [AS_HELP_STRING([--disable-lto], [Link Time Optimizations @<:@default enabled@:>@])],
107     ,
108     [enable_lto="detect"]
109 )
110
111
112 # -----------------------------------------------------------------------------
113 # netdata required checks
114
115 # fails on centos6
116 #AX_CHECK_ENABLE_DEBUG()
117
118 AX_GCC_FUNC_ATTRIBUTE([returns_nonnull])
119 AX_GCC_FUNC_ATTRIBUTE([malloc])
120 AX_GCC_FUNC_ATTRIBUTE([noreturn])
121 AX_GCC_FUNC_ATTRIBUTE([format])
122 AX_GCC_FUNC_ATTRIBUTE([warn_unused_result])
123
124 AC_CHECK_FUNCS_ONCE(accept4)
125 AC_CHECK_TYPES([struct timespec, clockid_t], [], [], [[#include <time.h>]])
126 AC_SEARCH_LIBS([clock_gettime], [rt posix4])
127 AC_CHECK_FUNCS([clock_gettime])
128 AC_CHECK_FUNCS([sched_setscheduler sched_get_priority_min sched_get_priority_max nice])
129
130 AC_TYPE_INT8_T
131 AC_TYPE_INT16_T
132 AC_TYPE_INT32_T
133 AC_TYPE_INT64_T
134 AC_TYPE_UINT8_T
135 AC_TYPE_UINT16_T
136 AC_TYPE_UINT32_T
137 AC_TYPE_UINT64_T
138 AC_C_INLINE
139 AC_FUNC_STRERROR_R
140 AC_C__GENERIC
141 AC_C___ATOMIC
142 # AC_C_STMT_EXPR
143 AC_CHECK_SIZEOF([void *])
144 AC_CANONICAL_HOST
145 AC_HEADER_MAJOR
146 AC_HEADER_RESOLV
147
148 AC_CHECK_HEADERS_ONCE([sys/prctl.h])
149
150
151 # -----------------------------------------------------------------------------
152 # operating system detection
153
154 AC_MSG_CHECKING([operating system])
155 case "$host_os" in
156 freebsd*)
157     build_target=freebsd
158     ;;
159 darwin*)
160     build_target=macos
161     LDFLAGS="${LDFLAGS} -framework CoreFoundation -framework IOKit"
162     ;;
163 *)
164     build_target=linux
165     ;;
166 esac
167
168 AM_CONDITIONAL([FREEBSD], [test "${build_target}" = "freebsd"])
169 AM_CONDITIONAL([MACOS], [test "${build_target}" = "macos"])
170 AM_CONDITIONAL([LINUX], [test "${build_target}" = "linux"])
171 AC_MSG_RESULT([${build_target}])
172
173
174 # -----------------------------------------------------------------------------
175 # pthreads
176
177 ACX_PTHREAD(, [AC_MSG_ERROR([Cannot initialize pthread environment])])
178 LIBS="${PTHREAD_LIBS} ${LIBS}"
179 CFLAGS="${CFLAGS} ${PTHREAD_CFLAGS}"
180 CC="${PTHREAD_CC}"
181
182
183 # -----------------------------------------------------------------------------
184 # libm
185
186 AC_ARG_VAR([MATH_CFLAGS], [C compiler flags for math])
187 AC_ARG_VAR([MATH_LIBS], [linker flags for math])
188 if test -z "${MATH_LIBS}"; then
189     AC_CHECK_LIB(
190         [m],
191         [sin],
192         [MATH_LIBS="-lm"]
193     )
194 fi
195 test "${with_math}" = "yes" -a -z "${MATH_LIBS}" && AC_MSG_ERROR([math required but not found])
196
197 AC_MSG_CHECKING([if libm should be used])
198 if test "${with_math}" != "no" -a ! -z "${MATH_LIBS}"; then
199     with_math="yes"
200     AC_DEFINE([STORAGE_WITH_MATH], [1], [math usability])
201     OPTIONAL_MATH_CFLAGS="${MATH_CFLAGS}"
202     OPTIONAL_MATH_LIBS="${MATH_LIBS}"
203 else
204     with_math="no"
205 fi
206 AC_MSG_RESULT([${with_math}])
207
208
209 # -----------------------------------------------------------------------------
210 # zlib
211
212 PKG_CHECK_MODULES(
213     [ZLIB],
214     [zlib],
215     [have_zlib=yes],
216     [have_zlib=no]
217 )
218 test "${with_zlib}" = "yes" -a "${have_zlib}" != "yes" && AC_MSG_ERROR([zlib required but not found. Try installing 'zlib1g-dev' or 'zlib-devel'.])
219
220 AC_MSG_CHECKING([if zlib should be used])
221 if test "${with_zlib}" != "no" -a "${have_zlib}" = "yes"; then
222     with_zlib="yes"
223     AC_DEFINE([NETDATA_WITH_ZLIB], [1], [zlib usability])
224     OPTIONAL_ZLIB_CLFAGS="${ZLIB_CFLAGS}"
225     OPTIONAL_ZLIB_LIBS="${ZLIB_LIBS}"
226 else
227     with_zlib="no"
228 fi
229 AC_MSG_RESULT([${with_zlib}])
230
231
232 # -----------------------------------------------------------------------------
233 # libuuid
234
235 PKG_CHECK_MODULES(
236     [UUID],
237     [uuid],
238     [have_uuid=yes],
239     [AC_MSG_ERROR([libuuid required but not found. Try installing 'uuid-dev' or 'libuuid-devel'.])]
240 )
241 AC_DEFINE([NETDATA_WITH_UUID], [1], [uuid usability])
242 OPTIONAL_UUID_CLFAGS="${UUID_CFLAGS}"
243 OPTIONAL_UUID_LIBS="${UUID_LIBS}"
244
245
246 # -----------------------------------------------------------------------------
247 # compiler options
248
249 AC_ARG_VAR([SSE_CANDIDATE], [C compiler flags for SSE])
250 AS_CASE([$host_cpu],
251     [i?86], [SSE_CANDIDATE="yes"]
252 )
253 AC_SUBST([SSE_CANDIDATE])
254 if test "${SSE_CANDIDATE}" = "yes" -a "${enable_x86_sse}" = "yes"; then
255     opt="-msse2 -mfpmath=sse"
256     AX_CHECK_COMPILE_FLAG(${opt}, [CFLAGS="${CFLAGS} ${opt}"], [])
257 fi
258
259 if test "${GCC}" = "yes"; then
260     AC_DEFINE_UNQUOTED([likely(x)], [__builtin_expect(!!(x), 1)], [gcc branch optimization])
261     AC_DEFINE_UNQUOTED([unlikely(x)], [__builtin_expect(!!(x), 0)], [gcc branch optimization])
262 else
263     AC_DEFINE_UNQUOTED([likely(x)], [(x)], [gcc branch optimization])
264     AC_DEFINE_UNQUOTED([unlikely(x)], [(x)], [gcc branch optimization])
265 fi
266
267 if test "${enable_pedantic}" = "yes"; then
268     enable_strict="yes"
269     CFLAGS="${CFLAGS} -pedantic -Wall -Wextra -Wno-long-long"
270 fi
271
272
273 # -----------------------------------------------------------------------------
274 # memory allocation library
275
276 AC_MSG_CHECKING([for memory allocator])
277 TS_CHECK_JEMALLOC
278 if test "$has_jemalloc" = "1"; then
279     AC_DEFINE([ENABLE_JEMALLOC], [1], [compile and link with jemalloc])
280     AC_MSG_RESULT([jemalloc])
281 else
282     TS_CHECK_TCMALLOC
283     if test "$has_tcmalloc" = "1"; then
284         AC_DEFINE([ENABLE_TCMALLOC], [1], [compile and link with tcmalloc])
285         AC_MSG_RESULT([tcmalloc])
286     else
287         AC_MSG_RESULT([system])
288         AC_C_MALLOPT
289         AC_C_MALLINFO
290     fi
291 fi
292
293
294 # -----------------------------------------------------------------------------
295 # libcap
296
297 PKG_CHECK_MODULES(
298     [LIBCAP],
299     [libcap],
300     [AC_CHECK_LIB([cap], [cap_get_proc, cap_set_proc],
301         [AC_CHECK_HEADER(
302             [sys/capability.h],
303             [have_libcap=yes],
304             [have_libcap=no]
305         )],
306         [have_libcap=no]
307     )],
308     [have_libcap=no]
309 )
310 test "${with_libcap}" = "yes" -a "${have_libcap}" != "yes" && AC_MSG_ERROR([libcap required but not found.])
311
312 AC_MSG_CHECKING([if libcap should be used])
313 if test "${with_libcap}" != "no" -a "${have_libcap}" = "yes"; then
314     with_libcap="yes"
315     AC_DEFINE([HAVE_CAPABILITY], [1], [libcap usability])
316     OPTIONAL_LIBCAP_CLFAGS="${LIBCAP_CFLAGS}"
317     OPTIONAL_LIBCAP_LIBS="${LIBCAP_LIBS}"
318 else
319     with_libcap="no"
320 fi
321 AC_MSG_RESULT([${with_libcap}])
322 AM_CONDITIONAL([ENABLE_CAPABILITY], [test "${with_libcap}" = "yes"])
323
324
325 # -----------------------------------------------------------------------------
326 # apps.plugin
327
328 AC_MSG_CHECKING([if apps.plugin should be enabled])
329 if test "${build_target}" != "macos"; then
330     enable_plugin_apps="yes"
331 else
332     enable_plugin_apps="no"
333 fi
334 AC_MSG_RESULT([${enable_plugin_apps}])
335 AM_CONDITIONAL([ENABLE_PLUGIN_APPS], [test "${enable_plugin_apps}" = "yes"])
336
337
338 # -----------------------------------------------------------------------------
339 # freeipmi.plugin - libipmimonitoring
340
341 PKG_CHECK_MODULES(
342     [IPMIMONITORING],
343     [libipmimonitoring],
344     [have_ipmimonitoring=yes],
345     [have_ipmimonitoring=no]
346 )
347 test "${enable_plugin_freeipmi}" = "yes" -a "${have_ipmimonitoring}" != "yes" && \
348     AC_MSG_ERROR([ipmimonitoring required but not found. Try installing 'libipmimonitoring-dev' or 'libipmimonitoring-devel'])
349
350 AC_MSG_CHECKING([if freeipmi.plugin should be enabled])
351 if test "${enable_plugin_freeipmi}" != "no" -a "${have_ipmimonitoring}" = "yes"; then
352     enable_plugin_freeipmi="yes"
353     AC_DEFINE([HAVE_FREEIPMI], [1], [ipmimonitoring usability])
354     OPTIONAL_IPMIMONITORING_CLFAGS="${IPMIMONITORING_CFLAGS}"
355     OPTIONAL_IPMIMONITORING_LIBS="${IPMIMONITORING_LIBS}"
356 else
357     enable_plugin_freeipmi="no"
358 fi
359 AC_MSG_RESULT([${enable_plugin_freeipmi}])
360 AM_CONDITIONAL([ENABLE_PLUGIN_FREEIPMI], [test "${enable_plugin_freeipmi}" = "yes"])
361
362
363 # -----------------------------------------------------------------------------
364 # nfacct.plugin - libmnl, libnetfilter_acct
365
366 AC_CHECK_HEADERS_ONCE([linux/netfilter/nfnetlink_conntrack.h])
367
368 PKG_CHECK_MODULES(
369     [NFACCT],
370     [libnetfilter_acct],
371     [have_libnetfilter_acct=yes],
372     [have_libnetfilter_acct=no]
373 )
374
375 PKG_CHECK_MODULES(
376     [LIBMNL],
377     [libmnl],
378     [have_libmnl=yes],
379     [have_libmnl=no]
380 )
381
382 test "${enable_plugin_nfacct}" = "yes" -a "${have_libnetfilter_acct}" != "yes" && \
383     AC_MSG_ERROR([netfilter_acct required but not found])
384
385 test "${enable_plugin_nfacct}" = "yes" -a "${have_libmnl}" != "yes" && \
386     AC_MSG_ERROR([libmnl required but not found. Try installing 'libmnl-dev' or 'libmnl-devel'])
387
388 AC_MSG_CHECKING([if nfacct.plugin should be enabled])
389 if test "${enable_plugin_nfacct}" != "no" -a "${have_libnetfilter_acct}" = "yes" -a "${have_libmnl}" = "yes"; then
390     enable_plugin_nfacct="yes"
391     AC_DEFINE([HAVE_LIBMNL], [1], [libmnl usability])
392     AC_DEFINE([HAVE_LIBNETFILTER_ACCT], [1], [libnetfilter_acct usability])
393     AC_DEFINE([INTERNAL_PLUGIN_NFACCT], [1], [nfacct plugin usability])
394     OPTIONAL_NFACCT_CLFAGS="${NFACCT_CFLAGS} ${LIBMNL_CFLAGS}"
395     OPTIONAL_NFACCT_LIBS="${NFACCT_LIBS} ${LIBMNL_LIBS}"
396 else
397     enable_plugin_nfacct="no"
398 fi
399 AC_MSG_RESULT([${enable_plugin_nfacct}])
400 AM_CONDITIONAL([ENABLE_PLUGIN_NFACCT], [test "${enable_plugin_nfacct}" = "yes"])
401
402
403 # -----------------------------------------------------------------------------
404 # Link-Time-Optimization
405
406 if test "${enable_lto}" != "no"; then
407     opt="-flto"
408     AX_CHECK_COMPILE_FLAG(${opt}, [have_lto=yes], [have_lto=no])
409 fi
410 if test "${have_lto}" = "yes"; then
411     oCFLAGS="${CFLAGS}"
412     CFLAGS="${CFLAGS} -flto ${OPTIONAL_MATH_CLFAGS} ${OPTIONAL_NFACCT_CLFAGS} ${OPTIONAL_ZLIB_CLFAGS} ${OPTIONAL_UUID_CLFAGS} ${OPTIONAL_LIBCAP_CFLAGS} ${OPTIONAL_IPMIMONITORING_CFLAGS}"
413     ac_cv_c_lto_cross_compile="${enable_lto}"
414     test "${ac_cv_c_lto_cross_compile}" != "yes" && ac_cv_c_lto_cross_compile="no"
415     AC_C_LTO
416     CFLAGS="${oCFLAGS}"
417     test "${ac_cv_c_lto}" != "yes" && have_lto="no"
418 fi
419 test "${enable_lto}" = "yes" -a "${have_lto}" != "yes" && \
420     AC_MSG_ERROR([LTO is required but is not available.])
421 AC_MSG_CHECKING([if LTO should be enabled])
422 if test "${enable_lto}" != "no" -a "${have_lto}" = "yes"; then
423     enable_lto="yes"
424     CFLAGS="${CFLAGS} -flto"
425 else
426     enable_lto="no"
427 fi
428 AC_MSG_RESULT([${enable_lto}])
429
430
431 # -----------------------------------------------------------------------------
432
433 AC_DEFINE_UNQUOTED([NETDATA_USER], ["${with_user}"], [use this user to drop privileged])
434
435 AC_SUBST([varlibdir], ["\$(localstatedir)/lib/netdata"])
436 AC_SUBST([registrydir], ["\$(localstatedir)/lib/netdata/registry"])
437 AC_SUBST([cachedir], ["\$(localstatedir)/cache/netdata"])
438 AC_SUBST([chartsdir], ["\$(libexecdir)/netdata/charts.d"])
439 AC_SUBST([nodedir], ["\$(libexecdir)/netdata/node.d"])
440 AC_SUBST([pythondir], ["\$(libexecdir)/netdata/python.d"])
441 AC_SUBST([configdir], ["\$(sysconfdir)/netdata"])
442 AC_SUBST([logdir], ["\$(localstatedir)/log/netdata"])
443 AC_SUBST([pluginsdir], ["\$(libexecdir)/netdata/plugins.d"])
444 AC_SUBST([webdir])
445
446 AC_SUBST([OPTIONAL_MATH_CLFAGS])
447 AC_SUBST([OPTIONAL_MATH_LIBS])
448 AC_SUBST([OPTIONAL_NFACCT_CLFAGS])
449 AC_SUBST([OPTIONAL_NFACCT_LIBS])
450 AC_SUBST([OPTIONAL_ZLIB_CLFAGS])
451 AC_SUBST([OPTIONAL_ZLIB_LIBS])
452 AC_SUBST([OPTIONAL_UUID_CLFAGS])
453 AC_SUBST([OPTIONAL_UUID_LIBS])
454 AC_SUBST([OPTIONAL_LIBCAP_CFLAGS])
455 AC_SUBST([OPTIONAL_LIBCAP_LIBS])
456 AC_SUBST([OPTIONAL_IPMIMONITORING_CFLAGS])
457 AC_SUBST([OPTIONAL_IPMIMONITORING_LIBS])
458
459 AC_CONFIG_FILES([
460     Makefile
461     charts.d/Makefile
462     conf.d/Makefile
463     netdata.spec
464     python.d/Makefile
465     node.d/Makefile
466     plugins.d/Makefile
467     src/Makefile
468     system/Makefile
469     web/Makefile
470     contrib/Makefile
471 ])
472 AC_OUTPUT
473
474 test "${with_math}" != "yes" && AC_MSG_WARN([You are building without math. math allows accurate calculations. It should be enabled.]) || :
475 test "${with_zlib}" != "yes" && AC_MSG_WARN([You are building without zlib. zlib allows netdata to transfer a lot less data with web clients. It should be enabled.]) || :