only link build and use rrd_getopt if there is no getopt_long provided by
[rrdtool.git] / configure.ac
1 dnl RRDtool AutoConf script ... 
2 dnl ---------------------------
3 dnl
4 dnl Created by Jeff Allen, Tobi Oetiker, Blair Zajac
5 dnl
6 dnl Inspiration from http://autoconf-archive.cryp.to
7  
8 dnl tell automake the this script is for rrdtool
9
10 dnl the official version number is
11 dnl a.b.c
12 AC_INIT([rrdtool],[1.3.2])
13
14 dnl for testing a numberical version number comes handy
15 dnl the released version are
16 dnl a.bccc
17 dnl the devel versions will be something like
18 dnl a.b999yymmddhh 
19 NUMVERS=1.3002
20 AC_SUBST(NUMVERS)
21
22 dnl for the linker to understand which versions the library are compatible with
23 dnl each other we must keep a separate library version cout of the format c:r:a.
24 dnl - if only implementation changed but all interfaces are kept, do r++
25 dnl - if only functionality was added do c++,r=0,a++
26 dnl - if any functionality was removed do c++,r=0,a=0.
27 dnl
28 dnl see http://sourceware.org/autobook/autobook/autobook_91.html
29 dnl 
30 LIBVERS=4:1:0
31 AC_SUBST(LIBVERS)
32
33 AC_CANONICAL_TARGET
34 AM_INIT_AUTOMAKE
35 AM_MAINTAINER_MODE
36
37 AC_CONFIG_HEADERS([rrd_config.h])
38
39 dnl all our local stuff like install scripts and include files
40 dnl is in there
41
42
43 dnl determine the type of system we are running on
44
45 AC_SUBST(VERSION)
46
47 AC_PREFIX_DEFAULT( /usr/local/rrdtool-$PACKAGE_VERSION )
48
49 dnl Minimum Autoconf version required.
50 AC_PREREQ(2.59)
51
52 dnl At the TOP of the HEADER
53
54 AH_TOP([
55
56 #ifndef RRD_CONFIG_H
57 #define RRD_CONFIG_H
58 /* IEEE can be prevented from raising signals with fpsetmask(0) */
59 #undef MUST_DISABLE_FPMASK
60
61 /* IEEE math only works if SIGFPE gets actively set to IGNORE */
62
63 #undef MUST_DISABLE_SIGFPE
64
65 /* realloc does not support NULL as argument */
66 #undef NO_NULL_REALLOC
67
68 /* lets enable madvise defines in NetBSD */ 
69 #if defined(__NetBSD__)
70 # if !defined(_NETBSD_SOURCE)
71 #  define _NETBSD_SOURCE
72 # endif
73 #endif
74
75  ])
76
77 AH_BOTTOM([
78 /* make sure that we pickup the correct stuff from all headers */
79 #ifdef HAVE_FEATURES_H
80 #undef _XOPEN_SOURCE /* keep unmodified */
81 #undef _BSD_SOURCE /* keep unmodified */
82 #define _XOPEN_SOURCE 600
83 #define _BSD_SOURCE 1
84 # include <features.h>
85 #endif
86
87 /* FreeBSD 4.8 wants this included BEFORE sys/types.h */
88 #ifdef HAVE_SYS_MMAN_H
89 # include <sys/mman.h>
90 #endif
91
92 #ifdef HAVE_SYS_TYPES_H
93 # include <sys/types.h>
94 #endif
95
96 #ifdef HAVE_SYS_PARAM_H
97 # include <sys/param.h>
98 #endif
99 #ifndef MAXPATH
100 # ifdef PATH_MAX
101 #  define MAXPATH PATH_MAX
102 # endif
103 #endif
104 #ifndef MAXPATH
105 /* else try the BSD variant */
106 # ifdef MAXPATHLEN
107 #  define MAXPATH MAXPATHLEN
108 # endif
109 #endif
110
111 #ifdef HAVE_ERRNO_H
112 # include <errno.h>
113 #endif
114
115 #if !defined HAVE_MADVISE && defined HAVE_POSIX_MADVISE
116 /* use posix_madvise family */
117 # define madvise posix_madvise
118 # define MADV_NORMAL POSIX_MADV_NORMAL
119 # define MADV_RANDOM POSIX_MADV_RANDOM
120 # define MADV_SEQUENTIAL POSIX_MADV_SEQUENTIAL
121 # define MADV_WILLNEED POSIX_MADV_WILLNEED
122 # define MADV_DONTNEED POSIX_MADV_DONTNEED
123 #endif
124 #if defined HAVE_MADVISE || defined HAVE_POSIX_MADVISE
125 # define USE_MADVISE 1
126 #endif
127
128 #ifdef HAVE_SYS_STAT_H
129 # include <sys/stat.h>
130 #endif
131
132 #ifdef HAVE_FCNTL_H
133 #include <fcntl.h>
134 #endif
135
136 #ifdef HAVE_UNISTD_H
137 # include <unistd.h>
138 #endif
139
140 #ifdef TIME_WITH_SYS_TIME
141 # include <sys/time.h>
142 # include <time.h>
143 #else
144 # ifdef HAVE_SYS_TIME_H
145 #  include <sys/time.h>
146 # else
147 #  include <time.h>
148 # endif
149 #endif
150
151 #ifdef HAVE_SYS_TIMES_H
152 # include <sys/times.h>
153 #endif
154
155 #ifdef HAVE_SYS_RESOURCE_H
156 # include <sys/resource.h>
157 #if (defined(__svr4__) && defined(__sun__))
158 /* Solaris headers (pre 2.6) do not have a getrusage prototype. 
159    Use this instead. */
160 extern int getrusage(int, struct rusage *);
161 #endif /* __svr4__ && __sun__ */
162 #endif
163
164
165 /* define strrchr, strchr and memcpy, memmove in terms of bsd funcs
166    make sure you are NOT using bcopy, index or rindex in the code */
167       
168 #ifdef STDC_HEADERS
169 # include <string.h>
170 #else
171 # ifndef HAVE_STRCHR
172 #  define strchr index
173 #  define strrchr rindex
174 # endif
175 char *strchr (), *strrchr ();
176 # ifndef HAVE_MEMMOVE
177 #  define memcpy(d, s, n) bcopy ((s), (d), (n))
178 #  define memmove(d, s, n) bcopy ((s), (d), (n))
179 # endif
180 #endif
181
182 #ifdef NO_NULL_REALLOC
183 # define rrd_realloc(a,b) ( (a) == NULL ? malloc( (b) ) : realloc( (a) , (b) ))
184 #else
185 # define rrd_realloc(a,b) realloc((a), (b))
186 #endif
187
188 #ifdef NEED_MALLOC_MALLOC_H
189 #  include <malloc/malloc.h>
190 #endif
191
192 #ifdef HAVE_STDIO_H
193 # include <stdio.h>
194 #endif
195
196 #ifdef HAVE_STDLIB_H
197 # include <stdlib.h>
198 #endif
199
200 #ifdef HAVE_CTYPE_H
201 # include <ctype.h>
202 #endif
203
204 #ifdef HAVE_DIRENT_H
205 # include <dirent.h>
206 # define NAMLEN(dirent) strlen((dirent)->d_name)
207 #else
208 # define dirent direct
209 # define NAMLEN(dirent) (dirent)->d_namlen
210 # ifdef HAVE_SYS_NDIR_H
211 #  include <sys/ndir.h>
212 # endif
213 # ifdef HAVE_SYS_DIR_H
214 #  include <sys/dir.h>
215 # endif
216 # ifdef HAVE_NDIR_H
217 #  include <ndir.h>
218 # endif
219 #endif
220
221 #ifdef MUST_DISABLE_SIGFPE
222 # include <signal.h>
223 #endif
224
225 #ifdef MUST_DISABLE_FPMASK
226 # include <floatingpoint.h>
227 #endif
228
229
230 #ifdef HAVE_MATH_H
231 # include <math.h>
232 #endif
233
234 #ifdef HAVE_FLOAT_H
235 # include <float.h>
236 #endif
237
238 #ifdef HAVE_IEEEFP_H
239 # include <ieeefp.h>
240 #endif
241
242 #ifdef HAVE_FP_CLASS_H
243 # include <fp_class.h>
244 #endif
245
246 /* for Solaris */
247 #if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASS))
248 #  define HAVE_ISINF 1
249 #  ifdef isinf
250 #  undef isinf /* confuse autoconf */
251 #  endif
252 #  define isinf(a) (fpclass(a) == FP_NINF || fpclass(a) == FP_PINF)
253 #endif
254
255 /* solaris 10 it defines isnan such that only forte can compile it ... bad bad  */
256 #if (defined(HAVE_ISNAN) && defined(isnan) && defined(HAVE_FPCLASS))
257 #  undef isnan /* confuse autoconf to NOT remove this */
258 #  define isnan(a) (fpclass(a) == FP_SNAN || fpclass(a) == FP_QNAN)
259 #endif
260
261 /* for OSF1 Digital Unix */
262 #if (! defined(HAVE_ISINF) && defined(HAVE_FP_CLASS) && defined(HAVE_FP_CLASS_H))
263 #  define HAVE_ISINF 1
264 #  define isinf(a) (fp_class(a) == FP_NEG_INF || fp_class(a) == FP_POS_INF)
265 #endif
266
267 #if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASSIFY) && defined(FP_PLUS_INF) && defined(FP_MINUS_INF))
268 #  define HAVE_ISINF 1
269 #  define isinf(a) (fpclassify(a) == FP_MINUS_INF || fpclassify(a) == FP_PLUS_INF)
270 #endif
271
272 #if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASSIFY) && defined(FP_INFINITE))
273 #  define HAVE_ISINF 1
274 #  define isinf(a) (fpclassify(a) == FP_INFINITE)
275 #endif
276
277 /* for AIX */
278 #if (! defined(HAVE_ISINF) && defined(HAVE_CLASS))
279 #  define HAVE_ISINF 1
280 #  define isinf(a) (class(a) == FP_MINUS_INF || class(a) == FP_PLUS_INF)
281 #endif
282
283 #if (! defined (HAVE_FINITE) && defined (HAVE_ISFINITE))
284 #  define HAVE_FINITE 1
285 #  define finite(a) isfinite(a)
286 #endif
287
288 #if (! defined(HAVE_FINITE) && defined(HAVE_ISNAN) && defined(HAVE_ISINF))
289 #  define HAVE_FINITE 1
290 #  define finite(a) (! isnan(a) && ! isinf(a))
291 #endif
292
293 #ifndef HAVE_FINITE
294 #error "Can't compile without finite function"
295 #endif
296
297 #ifndef HAVE_ISINF
298 #error "Can't compile without isinf function"
299 #endif
300
301 #if (! defined(HAVE_FDATASYNC) && defined(HAVE_FSYNC))
302 #define fdatasync fsync
303 #endif
304
305 #if (!defined(HAVE_FDATASYNC) && !defined(HAVE_FSYNC))
306 #error "Can't compile with without fsync and fdatasync"
307 #endif
308
309 #endif /* RRD_CONFIG_H */
310 ])
311
312 dnl Process Special Options
313 dnl -----------------------------------
314
315 dnl How the vertical axis label is printed
316 AC_ARG_VAR(RRDGRAPH_YLEGEND_ANGLE, 
317  [Vertical label angle: -90.0 (default) or 90.0])
318 AC_DEFINE_UNQUOTED(RRDGRAPH_YLEGEND_ANGLE,${RRDGRAPH_YLEGEND_ANGLE:-90.0},
319  [Vertical label angle: -90.0 (default) or 90.0])
320
321 AC_ARG_ENABLE(rrdcgi,[  --disable-rrdcgi        disable building of rrdcgi],
322 [],[enable_rrdcgi=yes])
323
324 dnl Check if we run on a system that has fonts
325 AC_ARG_WITH(rrd-default-font,
326 [  --with-rrd-default-font=[OPTIONS]  set the full path to your default font.],
327 [RRD_DEFAULT_FONT=$withval],[
328   if test -d ${WINDIR:-nodir}/cour.ttf ; then
329         RRD_DEFAULT_FONT=`cd $WINDIR;pwd`/cour.ttf
330   else
331         RRD_DEFAULT_FONT='"DejaVu Sans Mono,Bitstream Vera Sans Mono,monospace,Courier"'
332   fi
333 ])
334
335 dnl Use mmap in rrd_update instead of seek+write
336 AC_ARG_ENABLE([mmap],
337 [  --disable-mmap          disable mmap in rrd_update, use seek+write instead],
338 [],
339 [enable_mmap=yes])
340
341 AC_ARG_ENABLE(pthread,[  --disable-pthread       disable multithread support],
342 [],[enable_pthread=yes])
343
344 AC_ARG_ENABLE(static-programs,
345      [  --enable-static-programs  Build static programs],
346      [case "${enableval}" in
347        yes) staticprogs=yes ;;
348        no)  staticprogs=no ;;
349        *) AC_MSG_ERROR(bad value ${enableval} for --enable-static-programs) ;;
350      esac],[staticprogs=no])
351 AM_CONDITIONAL(STATIC_PROGRAMS,[test "x$staticprogs" = "xyes"])
352
353
354 CONFIGURE_PART(Audit Compilation Environment)
355
356
357 dnl Check for the compiler and static/shared library creation.
358 AC_PROG_CC
359 AC_PROG_CPP
360 AC_PROG_LIBTOOL
361
362 dnl Try to detect/use GNU features
363 CFLAGS="$CFLAGS -D_GNU_SOURCE"
364
365 dnl which flags does the compiler support?
366 if test "x$GCC" = "xyes"; then
367   for flag in -fno-strict-aliasing -Wall -std=c99 -pedantic -Wundef -Wshadow -Wpointer-arith -Wcast-align -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline -Wold-style-definition -W; do
368     oCFLAGS="$CFLAGS"
369     CFLAGS="$CFLAGS $flag"
370     cachename=rd_cv_gcc_flag_`echo $flag|sed 's/[[^A-Za-z]]/_/g'`
371     AC_CACHE_CHECK([if gcc likes the $flag flag], $cachename,
372        [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[return 0 ]])],[eval $cachename=yes],[eval $cachename=no])])
373     if eval test \$$cachename = no; then
374          CFLAGS="$oCFLAGS"
375     fi
376   done
377 fi
378
379
380
381 AC_SUBST(RRD_DEFAULT_FONT)
382
383 CONFIGURE_PART(Checking for Header Files)
384  
385 dnl Checks for header files.
386 AC_HEADER_STDC
387 AC_HEADER_DIRENT
388 AC_CHECK_HEADERS(features.h sys/stat.h sys/types.h fcntl.h locale.h fp_class.h malloc.h unistd.h ieeefp.h math.h sys/times.h sys/param.h sys/resource.h signal.h float.h stdio.h stdlib.h errno.h string.h ctype.h)
389
390 dnl Checks for typedefs, structures, and compiler characteristics.
391 AC_C_CONST
392 AC_HEADER_TIME
393 AC_STRUCT_TM
394
395 CONFIGURE_PART(Test Library Functions)
396
397 dnl Checks for libraries.
398 AC_CHECK_FUNC(acos, , AC_CHECK_LIB(m, acos))
399
400
401 dnl add pic flag in any case this makes sure all our code is relocatable
402 eval `./libtool --config | grep pic_flag`
403 CFLAGS="$CFLAGS $pic_flag"
404
405
406 dnl Checks for library functions.
407 AC_FUNC_STRFTIME
408 AC_FUNC_VPRINTF
409
410 AC_C_BIGENDIAN
411
412 dnl for each function found we get a definition in config.h 
413 dnl of the form HAVE_FUNCTION
414
415 AC_CHECK_FUNCS(tzset fsync mbstowcs opendir readdir chdir chroot getuid setlocale strerror strerror_r snprintf vsnprintf fpclass class fp_class isnan memmove strchr mktime getrusage gettimeofday)
416
417 CONFIGURE_PART(Map/Fadvis/Madvise checking)
418
419 dnl Could use these to know if we need to provide a prototype
420 dnl AC_CHECK_DECLS(fdatasync, [], [], [#include <unistd.h>])
421
422 dnl check for fdatasync. Solaris has fdatasync in the librt
423
424 AC_CHECK_FUNCS(fdatasync, [],  AC_CHECK_LIB(rt, fdatasync, [LIBS="${LIBS} -lrt"; AC_DEFINE(HAVE_FDATASYNC)],[]))
425 dnl if there is no fdatasync we may get lucky with fsync
426 AC_CHECK_FUNCS(fsync)
427
428
429 dnl XXX: dunno about windows.. add AC_CHECK_FUNCS(munmap) there too?
430 if test "x$enable_mmap" = "xyes"; then
431   case "$host" in
432   *cygwin*)
433     # the normal mmap test does not work in cygwin
434     AC_CHECK_FUNCS(mmap)
435     if test "x$ac_cv_func_mmap" = "xyes"; then
436       ac_cv_func_mmap_fixed_mapped=yes
437     fi
438   ;;
439   *)
440     AC_CHECK_HEADERS(sys/mman.h)
441     AC_FUNC_MMAP
442     AC_CHECK_FUNCS(mmap munmap msync)
443     AC_CHECK_DECLS(madvise, [], [], [#ifdef HAVE_SYS_MMAN_H
444                                      # include <sys/mman.h>
445                                      #endif])
446     if test "x$ac_cv_have_decl_madvise" = "xyes";
447     then
448       AC_CHECK_FUNCS(madvise)
449     else
450       AC_CHECK_FUNCS(posix_madvise)
451       if test "x$ac_cv_func_posix_madvise" != "xyes"; then
452         AC_MSG_WARN([madvise() nor posix_madvise() found.])
453       fi
454     fi
455   ;;
456   esac
457   if test "x$ac_cv_func_mmap" != "xyes";
458   then
459     AC_MSG_ERROR([--enable-mmap requested but mmap() was not detected])
460 dnl enable_mmap="no"
461   fi
462 fi
463
464 dnl can we use posix_fadvise
465 AC_CHECK_DECLS(posix_fadvise, [], [], [#define _XOPEN_SOURCE 600
466 #include <fcntl.h>])
467 AC_CHECK_FUNCS(posix_fadvise)
468
469 CONFIGURE_PART(Libintl Processing)
470
471
472 dnl gettext
473 GETTEXT_PACKAGE=rrdtool
474 AC_SUBST(GETTEXT_PACKAGE)
475 AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE",[Gettext package])
476
477 AM_GLIB_GNU_GETTEXT()
478
479 AC_ARG_ENABLE(libintl,[  --disable-libintl        i18n support (libintl)],
480 [],[enable_libintl=yes])
481
482 if test x$enable_libintl = xyes; then
483   IT_PROG_INTLTOOL([0.35.0],[no-xml])
484 fi
485
486 if test x$enable_libintl = xyes -a x$MSGFMT = xno; then
487   AC_MSG_WARN(I could not find msgfmt. Diabeling libintl build.)
488   enable_libintl=no
489 fi
490
491 if test x$enable_libintl = xyes; then
492   AC_CHECK_HEADERS(libintl.h,[],[AC_MSG_RESULT(disabeling libintl build); enable_libintl=no])
493 fi
494
495 if test x$enable_libintl = xyes ; then
496   dnl it seems bsd synstems need to link against libintl
497   dnl when compiling rrdupdate. lets check        
498   AC_CHECK_LIB(intl, libintl_gettext,[LIB_LIBINTL="-lintl"])
499 fi
500
501 dnl use for linking rrdupdate
502 AC_SUBST(LIB_LIBINTL)
503
504 dnl do not touch the po stuff if we are not going to build intl
505 AM_CONDITIONAL(BUILD_LIBINTL,[test x$enable_libintl = xyes])
506
507 if test x$enable_libintl = xyes; then
508    AC_DEFINE([BUILD_LIBINTL], [], [Use this in code sections to mark them for libintl build])
509 fi
510
511 CONFIGURE_PART(IEEE Math Checks)
512  
513
514 dnl actual code to check if this works
515 AC_CHECK_FUNCS(fpclassify, ,
516   [AC_MSG_CHECKING(for fpclassify with <math.h>)
517     AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <math.h>
518 volatile int x;volatile float f; ]], [[x = fpclassify(f)]])],[AC_MSG_RESULT(yes)
519       AC_DEFINE(HAVE_FPCLASSIFY)],[AC_MSG_RESULT(no)])])
520
521 AC_CHECK_FUNCS(isinf, ,
522   [AC_MSG_CHECKING(for isinf with <math.h>)
523     AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <math.h>
524 volatile int x;volatile float f;  ]], [[x = isinf(f)]])],[AC_MSG_RESULT(yes)
525       AC_DEFINE(HAVE_ISINF)],[AC_MSG_RESULT(no)])])
526
527 dnl finite is BSD, isfinite is C99, so prefer the latter
528 AC_CACHE_CHECK([whether isfinite is broken],[have_broken_isfinite],[
529 AC_TRY_RUN([
530 #ifdef HAVE_MATH_H
531 #include <math.h>
532 #endif
533 #ifdef HAVE_FLOAT_H
534 #include <float.h>
535 #endif
536 int main ()
537 {
538 #ifdef isfinite
539 #ifdef LDBL_MAX
540   if (!isfinite(LDBL_MAX)) return 1;
541 #endif
542 #ifdef DBL_MAX
543   if (!isfinite(DBL_MAX)) return 1;
544 #endif
545 #endif
546 return 0;
547 }],[
548 have_broken_isfinite=no],have_broken_isfinite=yes,[
549 case "${target}" in
550   hppa*-*-hpux*) have_broken_isfinite=yes ;;
551   *-sun-solaris2.8) have_broken_isfinite=yes ;;
552   *) have_broken_isfinite=no ;;
553 esac])
554 ])
555 if test "x$have_broken_isfinite" = "xno"; then
556   AC_DEFINE(HAVE_ISFINITE)
557 else
558 AC_CHECK_FUNCS(finite,[],
559   [AC_CHECK_FUNCS(isfinite,[],
560       [AC_MSG_CHECKING(for isfinite with <math.h>)
561        AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <math.h>
562 volatile int x;volatile float f;  ]],[[x = isfinite(f)]])],[AC_MSG_RESULT(yes)
563                 AC_DEFINE(HAVE_ISFINITE)],[AC_MSG_RESULT(no)])])])
564 fi
565
566 AC_FULL_IEEE
567
568 CONFIGURE_PART(Resolve Portability Issues)
569
570 dnl Do we need getopt_long
571
572 build_getopt=no
573 RRD_GETOPT_LONG="#"
574 AC_CHECK_FUNC(getopt_long,[],[
575 RRD_GETOPT_LONG="getopt_long"
576 build_getopt=yes
577 ])
578 AC_SUBST(RRD_GETOPT_LONG)
579 AM_CONDITIONAL(BUILD_GETOPT,[test $build_getopt = yes])
580
581 dnl what does realloc do if it gets called with a NULL pointer
582
583 AC_CACHE_CHECK([if realloc can deal with NULL], rd_cv_null_realloc,
584 [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdlib.h>
585               int main(void){
586               char *x = NULL;
587               x = realloc (x,10);
588               if (x==NULL) return 1;
589               return 0;
590              }]])],[rd_cv_null_realloc=yes],[rd_cv_null_realloc=nope],[:])])
591
592 if test x"$rd_cv_null_realloc" = xnope; then
593 AC_DEFINE(NO_NULL_REALLOC)
594 fi
595
596 AC_LANG_PUSH(C)
597 dnl solaris has some odd defines it needs in order to propperly compile ctime_r
598 AC_MSG_CHECKING([if ctime_r need special care to act posixly correct])
599 AC_LINK_IFELSE(
600     AC_LANG_PROGRAM(
601            [[#include <time.h>]],
602            [[ctime_r(NULL,NULL,0)]]
603                    ),
604     [ CPPFLAGS="$CPPFLAGS -D_POSIX_PTHREAD_SEMANTICS"
605       AC_LINK_IFELSE(
606           AC_LANG_PROGRAM(
607                 [[#include <time.h>]],
608                 [[ctime_r(NULL,NULL)]]
609                          ),
610           [AC_MSG_RESULT([yes, this seems to be solaris style])],
611           [AC_MSG_ERROR([Can't figure how to compile ctime_r])]
612       )
613     ],  
614     [ AC_LINK_IFELSE(
615           AC_LANG_PROGRAM(
616                 [[#include <time.h>]],
617                 [[ctime_r(NULL,NULL)]]
618                          ),
619           [AC_MSG_RESULT(no)],
620           [AC_MSG_ERROR([Can't figure how to compile ctime_r])]
621       )
622     ]  
623 )
624 AC_LANG_POP(C)
625
626 dnl Check for pthreads
627 dnl http://autoconf-archive.cryp.to/acx_pthread.m4
628  
629 AC_SUBST(MULTITHREAD_CFLAGS)
630 AC_SUBST(MULTITHREAD_LDFLAGS)
631
632 if test $enable_pthread != no; then 
633  ACX_PTHREAD([
634     MULTITHREAD_CFLAGS=$PTHREAD_CFLAGS
635     MULTITHREAD_LDFLAGS=$PTHREAD_LIBS
636              ],
637              [])
638 fi
639
640 dnl since we use lots of *_r functions all over the code we better
641 dnl make sure they are known
642
643 if test  "x$x_rflag" != "xno"; then
644    CPPFLAGS="$CPPFLAGS $x_rflag"
645 fi
646
647 AM_CONDITIONAL(BUILD_MULTITHREAD,[test $enable_pthread != no])
648
649 AC_LANG_PUSH(C)
650 dnl see if we have to include malloc/malloc.h
651 AC_MSG_CHECKING([do we need malloc/malloc.h])
652 AC_LINK_IFELSE(
653     AC_LANG_PROGRAM(
654            [[#include <stdlib.h>]],
655            [[malloc(1)]]
656                    ),
657     [ AC_MSG_RESULT([nope, works out of the box]) ],
658     [ AC_LINK_IFELSE(
659           AC_LANG_PROGRAM(
660                 [[#include <stdlib.h>
661                   #include <malloc/malloc.h>]],
662                 [[malloc(1)]]
663                          ),
664           [AC_DEFINE(NEED_MALLOC_MALLOC_H)
665            AC_MSG_RESULT([yes we do])],
666           [AC_MSG_ERROR([Can not figure how to compile malloc])]
667       )
668     ]  
669 )
670 AC_LANG_POP(C)
671
672 CONFIGURE_PART(Find 3rd-Party Libraries)
673
674
675 AM_CONDITIONAL(BUILD_RRDCGI,[test $enable_rrdcgi != no])
676
677
678 CORE_LIBS="$LIBS"
679
680 dnl EX_CHECK_ALL(z,          zlibVersion,               zlib.h,                 zlib,        1.2.3,  http://www.gzip.org/zlib/, "")
681 dnl EX_CHECK_ALL(png,        png_access_version_number, png.h,                  libpng,      1.2.10,  http://prdownloads.sourceforge.net/libpng/, "")
682 dnl EX_CHECK_ALL(freetype,   FT_Init_FreeType,          ft2build.h,             freetype2,   2.1.10,  http://prdownloads.sourceforge.net/freetype/, /usr/include/freetype2)
683 dnl EX_CHECK_ALL(fontconfig, FcInit,                    fontconfig.h,           fontconfig,  2.3.1,  http://fontconfig.org/release/, /usr/include)
684 EX_CHECK_ALL(cairo,      cairo_font_options_create,     cairo.h,                cairo-png,   1.4.6,  http://cairographics.org/releases/, "")
685 EX_CHECK_ALL(cairo,      cairo_svg_surface_create,      cairo-svg.h,            cairo-svg,   1.4.6,  http://cairographics.org/releases/, "")
686 EX_CHECK_ALL(cairo,      cairo_pdf_surface_create,      cairo-pdf.h,            cairo-pdf,   1.4.6,  http://cairographics.org/releases/, "")
687 EX_CHECK_ALL(cairo,      cairo_ps_surface_create,       cairo-ps.h,             cairo-ps,    1.4.6,  http://cairographics.org/releases/, "")
688 dnl EX_CHECK_ALL(glib-2.0,   glib_check_version,        glib.h,                 glib-2.0,    2.12.12, ftp://ftp.gtk.org/pub/glib/2.12/, "")
689 EX_CHECK_ALL(pango-1.0,  pango_cairo_context_set_font_options,  pango/pango.h,  pangocairo,  1.17,    http://ftp.gnome.org/pub/GNOME/sources/pango/1.17, "")
690 EX_CHECK_ALL(xml2,       xmlParseFile,                  libxml/parser.h,        libxml-2.0,        2.6.31,  http://xmlsoft.org/downloads.html, /usr/include/libxml2)
691
692 if test "$EX_CHECK_ALL_ERR" = "YES"; then
693   AC_MSG_ERROR([Please fix the library issues listed above and try again.])
694 fi
695
696 ALL_LIBS="$LIBS"
697 LIBS=
698
699 AC_SUBST(CORE_LIBS)
700 AC_SUBST(ALL_LIBS)
701
702 CONFIGURE_PART(Prep for Building Language Bindings)
703   
704 dnl Check for Perl and friends
705 PATH=$PATH:/usr/perl5/bin
706 export PATH
707 AC_PATH_PROG(PERL, perl, no)
708 AC_PATH_PROG(POD2MAN, pod2man, no)
709 AC_PATH_PROG(POD2HTML, pod2html, no)
710
711
712 AC_ARG_ENABLE(perl,[  --disable-perl          do not build the perl modules],
713 [],[enable_perl=yes])
714
715
716 AC_ARG_VAR(PERLCC, [[] C compiler for Perl modules])
717 AC_ARG_VAR(PERLCCFLAGS, [[] CC flags for Perl modules])
718 AC_ARG_VAR(PERLLD, [[same as PERLCC] Linker for Perl modules])
719 AC_ARG_VAR(PERLLDFLAGS, [[] LD flags for Perl modules])
720
721 if test "x$PERL" = "xno" -o  x$enable_perl = xno; then
722         COMP_PERL=
723 else
724         COMP_PERL="perl_piped perl_shared"
725         AC_MSG_CHECKING(for the perl version you are running)
726         PERL_VERSION=`$PERL -MConfig -e 'print $Config{version}'`
727         AC_MSG_RESULT($PERL_VERSION)
728         if test -z "$PERLCC"; then
729             AC_MSG_CHECKING(for the C compiler perl wants to use to build its modules)
730             perlcc=`$PERL -MConfig -e 'print $Config{cc}'`
731             AC_MSG_RESULT($perlcc)
732             if test ! -x "$perlcc"; then
733                 AC_PATH_PROG(PERL_CC, ${perlcc}, no)
734                 if test "$PERL_CC" = "no"; then
735                     AC_MSG_WARN([
736 I would not find the Compiler ($perlcc) that was originally used to compile
737 your perl binary. You should either make sure that this compiler is
738 available on your system, pick an other compiler and set PERLCC
739 appropriately, or use a different perl setup that was compiled locally.
740
741 I will disable the compilation of the RRDs perl module for now.
742 ])
743                     COMP_PERL="perl_piped"
744                 fi
745             fi    
746         fi
747 fi
748
749 AC_MSG_CHECKING(Perl Modules to build)
750 AC_MSG_RESULT(${COMP_PERL:-No Perl Modules will be built})
751
752 # Options to pass when configuring perl module
753 ppref=$prefix
754 test "$ppref" = "NONE" && ppref=$ac_default_prefix
755
756 PERL_MAKE_OPTIONS="PREFIX=$ppref LIB=$ppref/lib/perl/$PERL_VERSION"
757
758 dnl pass additional perl options when generating Makefile from Makefile.PL
759 AC_ARG_ENABLE(perl-site-install,
760 [  --enable-perl-site-install   by default the rrdtool perl modules are installed
761                           together with rrdtool in $prefix/lib/perl. You have to
762                           put a 'use lib qw($prefix/lib/perl)' into your scripts
763                           when you want to use them. When you set this option
764                           the perl modules will get installed wherever
765                           your perl setup thinks it is best.],
766 [PERL_MAKE_OPTIONS=],[])
767
768 if test ! -z "$PERLCC"; then
769    PERL_MAKE_OPTIONS="$PERL_MAKE_OPTIONS CC=$PERLCC"
770
771    if test ! -z "$PERLCCFLAGS"; then
772        PERL_MAKE_OPTIONS="$PERL_MAKE_OPTIONS CCFLAGS=$PERLCCFLAGS"
773    fi
774    
775    if test -z "$PERLLD"; then
776        PERLLD=$PERLCC
777    fi
778    PERL_MAKE_OPTIONS="$PERL_MAKE_OPTIONS LD=$PERLLD"
779   
780    if test ! -z "$PERLLDFLAGS"; then
781        PERL_MAKE_OPTIONS="$PERL_MAKE_OPTIONS LDFLAGS=$PERLLDFLAGS"
782    fi
783 fi
784         
785 AC_ARG_WITH(perl-options,
786 [  --with-perl-options=[OPTIONS]  options to pass on command-line when
787                           generating Makefile from Makefile.PL. If you set this
788                           option, interesting things may happen unless you know
789                           what you are doing!],
790 [PERL_MAKE_OPTIONS=$withval])
791
792 AC_SUBST(PERL_MAKE_OPTIONS)
793 AC_SUBST(PERL)
794 AC_SUBST(COMP_PERL)
795 AC_SUBST(PERL_VERSION)
796
797 dnl Check for Ruby.
798 AC_PATH_PROG(RUBY, ruby, no)
799
800 AC_ARG_ENABLE(ruby,[  --disable-ruby          do not build the ruby modules],
801 [],[enable_ruby=yes])
802
803 AC_MSG_CHECKING(if ruby modules can be built)
804
805 if test "x$RUBY" = "xno" -o  x$enable_ruby = xno; then
806         COMP_RUBY=
807         AC_MSG_RESULT(No .. Ruby not found or disabled)
808 else
809         if $RUBY -e 'require "mkmf"' >/dev/null 2>&1; then
810                 COMP_RUBY="ruby"
811                 AC_MSG_RESULT(YES)
812         else
813                 COMP_RUBY=
814                 AC_MSG_RESULT(Ruby found but mkmf is missing! Install the -dev package)         
815         fi                              
816 fi
817
818
819 dnl pass additional ruby options when generating Makefile from Makefile.PL
820 AC_ARG_ENABLE(ruby-site-install,
821 [  --enable-ruby-site-install   by default the rrdtool ruby modules are installed
822                           together with rrdtool in $prefix/lib/ruby. You have to
823                           add $prefix/lib/ruby/$ruby_version/$sitearch to you $: variable
824                           for ruby to find the RRD.so file.],
825 [RUBY_MAKE_OPTIONS=],[RUBY_MAKE_OPTIONS="sitedir="'$(DESTDIR)'"$prefix/lib/ruby"])
826
827     
828 AC_ARG_WITH(ruby-options,
829 [  --with-ruby-options=[OPTIONS]  options to pass on command-line when
830                           generating Makefile from extconf.rb. If you set this
831                           option, interesting things may happen unless you know
832                           what you are doing!],
833 [RUBY_MAKE_OPTIONS=$withval])
834
835 AC_SUBST(RUBY_MAKE_OPTIONS)
836 AC_SUBST(RUBY)
837 AC_SUBST(COMP_RUBY)
838
839
840 enable_tcl_site=no
841
842 AC_ARG_ENABLE(tcl,[  --disable-tcl           do not build the tcl modules],
843 [],[enable_tcl=yes])
844
845 if test  "$enable_tcl" = "yes"; then
846   dnl Check for Tcl.
847   withval=""
848   AC_ARG_WITH(tcllib,[  --with-tcllib=DIR       location of the tclConfig.sh])
849   enable_tcl=no
850   for dir in $withval /usr/lib /usr/local/lib /usr/lib/tcl8.4 /usr/lib/tcl8.3 ; do
851     AC_MSG_CHECKING(for tclConfig.sh in $dir)
852     if test -f "$dir/tclConfig.sh" ; then
853         tcl_config=$dir/tclConfig.sh
854         enable_tcl=yes
855         AC_MSG_RESULT(yes)
856         break
857     else
858         AC_MSG_RESULT(no)
859     fi
860   done
861
862   if test "$enable_tcl" = "no"; then
863         AC_MSG_WARN([tclConfig.sh not found - Tcl interface will not be built])
864   else
865         . $tcl_config
866         TCL_PACKAGE_DIR="$TCL_PACKAGE_PATH/tclrrd$VERSION"
867         if test -n "$TCL_INC_DIR"; then
868           TCL_INCLUDE_SPEC="$TCL_INCLUDE_SPEC -I$TCL_INC_DIR"
869         fi
870   fi
871   AC_ARG_ENABLE(tcl,[  --enable-tcl-site        install the tcl extension in the tcl tree],
872   [],[enable_tcl_site=yes])
873
874 fi
875
876 AM_CONDITIONAL(BUILD_TCL, test "$enable_tcl" = "yes" )
877 AM_CONDITIONAL(BUILD_TCL_SITE, test "$enable_tcl_site" = "yes" )
878
879
880 AC_SUBST(TCL_PREFIX)
881 AC_SUBST(TCL_SHLIB_CFLAGS)
882 AC_SUBST(TCL_SHLIB_LD)
883 AC_SUBST(TCL_SHLIB_SUFFIX)
884 AC_SUBST(TCL_PACKAGE_PATH)
885 AC_SUBST(TCL_LD_SEARCH_FLAGS)
886 AC_SUBST(TCL_STUB_LIB_SPEC)
887 AC_SUBST(TCL_VERSION)
888 AC_SUBST(TCL_PACKAGE_DIR)
889 AC_SUBST(TCL_INCLUDE_SPEC)
890
891 AC_ARG_ENABLE(python,[  --disable-python        do not build the python modules],
892 [],[enable_python=yes])
893
894 if test  "$enable_python" = "yes"; then
895 dnl Check for python
896 AM_PATH_PYTHON(2.3,[],[enable_python=no])
897 AM_CHECK_PYTHON_HEADERS(,[enable_python=no;AC_MSG_WARN(could not find Python headers)])
898 fi
899
900 if test  x$enable_python = xno; then
901         COMP_PYTHON=
902 else
903         COMP_PYTHON="python"
904 fi
905
906 AC_SUBST(COMP_PYTHON)
907
908 dnl Check for nroff
909 AC_PATH_PROGS(NROFF, gnroff nroff)
910 AC_PATH_PROGS(TROFF, groff troff)
911
912 AC_ARG_VAR(RRDDOCDIR, [[DATADIR/doc/PACKAGE-VERSION] Documentation directory])
913 if test -z "$RRDDOCDIR"; then
914    RRDDOCDIR='${datadir}/doc/${PACKAGE}-${VERSION}'; fi
915
916
917 CONFIGURE_PART(Apply Configuration Information)
918  
919 AC_CONFIG_FILES([examples/shared-demo.pl])
920 AC_CONFIG_FILES([examples/piped-demo.pl])
921 AC_CONFIG_FILES([examples/stripes.pl])
922 AC_CONFIG_FILES([examples/bigtops.pl])
923 AC_CONFIG_FILES([examples/minmax.pl])
924 AC_CONFIG_FILES([examples/4charts.pl])
925 AC_CONFIG_FILES([examples/perftest.pl])
926 AC_CONFIG_FILES([examples/Makefile])
927 AC_CONFIG_FILES([doc/Makefile])
928 AC_CONFIG_FILES([po/Makefile.in])
929 AC_CONFIG_FILES([src/Makefile])
930 AC_CONFIG_FILES([src/librrd.sym])
931 AC_CONFIG_FILES([bindings/Makefile])
932 AC_CONFIG_FILES([bindings/tcl/Makefile])
933 AC_CONFIG_FILES([bindings/tcl/ifOctets.tcl])
934 AC_CONFIG_FILES([Makefile])          
935
936 AC_CONFIG_COMMANDS([default],[[ chmod +x examples/*.pl]],[[]])
937 AC_OUTPUT
938
939 AC_MSG_CHECKING(in)
940 AC_MSG_RESULT(and out again)
941
942 echo $ECHO_N "ordering CD from http://tobi.oetiker.ch/wish $ECHO_C" 1>&6
943 sleep 1
944 echo $ECHO_N ".$ECHO_C" 1>&6
945 sleep 1
946 echo $ECHO_N ".$ECHO_C" 1>&6
947 sleep 1
948 echo $ECHO_N ".$ECHO_C" 1>&6
949 sleep 1
950 echo $ECHO_N ".$ECHO_C" 1>&6
951 sleep 1
952 AC_MSG_RESULT([ just kidding ;-)])
953 echo
954 echo "----------------------------------------------------------------"
955 echo "Config is DONE!"
956 echo
957 echo "          With MMAP IO: $enable_mmap"
958 echo "      Build rrd_getopt: $build_getopt"
959 echo "       Static programs: $staticprogs"
960 echo "          Perl Modules: $COMP_PERL"
961 echo "           Perl Binary: $PERL"
962 echo "          Perl Version: $PERL_VERSION"
963 echo "          Perl Options: $PERL_MAKE_OPTIONS"
964 echo "          Ruby Modules: $COMP_RUBY"
965 echo "           Ruby Binary: $RUBY"
966 echo "          Ruby Options: $RUBY_MAKE_OPTIONS"
967 echo "    Build Tcl Bindings: $enable_tcl"
968 echo " Build Python Bindings: $enable_python"
969 echo "          Build rrdcgi: $enable_rrdcgi"
970 echo "       Build librrd MT: $enable_pthread"
971 echo "     Link with libintl: $enable_libintl"
972 echo
973 echo "             Libraries: $ALL_LIBS"
974 echo
975 echo "Type 'make' to compile the software and use 'make install' to "
976 echo "install everything to: $prefix."
977 echo 
978 echo "       ... that wishlist is NO JOKE. If you find RRDtool useful"
979 echo "make me happy. Go to http://tobi.oetiker.ch/wish and"
980 echo "place an order."
981 echo 
982 echo "                               -- Tobi Oetiker <tobi@oetiker.ch>"
983 echo "----------------------------------------------------------------"