make MakeMaker work on debian and fix some leftovers from the library rip-out transition
[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
7
8 dnl tell automake the this script is for rrdtool
9 AC_INIT([rrdtool],[1.1.0])
10 AM_INIT_AUTOMAKE
11 AC_CANONICAL_TARGET
12 AM_CONFIG_HEADER(config.h)
13 # AC_CONFIG_AUX_DIR(config)
14
15 dnl all our local stuff like install scripts and include files
16 dnl is in there
17
18
19 dnl determine the type of system we are running on
20
21
22 AC_SUBST(VERSION)
23
24 dnl where we install our stuff ...
25 AC_PREFIX_DEFAULT( /usr/local/rrdtool-1.1.0 )
26
27 dnl Minimum Autoconf version required.
28 AC_PREREQ(2.58)
29
30 dnl At the TOP of the HEADER
31
32 AH_TOP([
33
34 #ifndef CONFIG_H
35 #define CONFIG_H
36 /* IEEE can be prevented from raising signals with fpsetmask(0) */
37 #undef MUST_DISABLE_FPMASK
38
39 /* IEEE math only works if SIGFPE gets actively set to IGNORE */
40
41 #undef MUST_DISABLE_SIGFPE
42
43 /* realloc does not support NULL as argument */
44 #undef NO_NULL_REALLOC
45  ])
46
47 AH_BOTTOM([
48
49 /* define strrchr, strchr and memcpy, memmove in terms of bsd funcs
50    make sure you are NOT using bcopy, index or rindex in the code */
51       
52 #if STDC_HEADERS
53 # include <string.h>
54 #else
55 # ifndef HAVE_STRCHR
56 #  define strchr index
57 #  define strrchr rindex
58 # endif
59 char *strchr (), *strrchr ();
60 # ifndef HAVE_MEMMOVE
61 #  define memcpy(d, s, n) bcopy ((s), (d), (n))
62 #  define memmove(d, s, n) bcopy ((s), (d), (n))
63 # endif
64 #endif
65
66
67 #if NO_NULL_REALLOC
68 # define rrd_realloc(a,b) ( (a) == NULL ? malloc( (b) ) : realloc( (a) , (b) ))
69 #else
70 # define rrd_realloc(a,b) realloc((a), (b))
71 #endif      
72
73 #if HAVE_MATH_H
74 #  include <math.h>
75 #endif
76
77 #if HAVE_FLOAT_H
78 #  include <float.h>
79 #endif
80
81 #if HAVE_IEEEFP_H
82 #  include <ieeefp.h>
83 #endif
84
85 #if HAVE_FP_CLASS_H
86 #  include <fp_class.h>
87 #endif
88
89 /* for Solaris */
90 #if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASS))
91 #  define HAVE_ISINF 1
92 #  define isinf(a) (fpclass(a) == FP_NINF || fpclass(a) == FP_PINF)
93 #endif
94
95 /* for OSF1 Digital Unix */
96 #if (! defined(HAVE_ISINF) && defined(HAVE_FP_CLASS) && defined(HAVE_FP_CLASS_H))
97 #  define HAVE_ISINF 1
98 #  define isinf(a) (fp_class(a) == FP_NEG_INF || fp_class(a) == FP_POS_INF)
99 #endif
100
101 #if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASSIFY) && defined(FP_PLUS_INF) && defined(FP_MINUS_INF))
102 #  define HAVE_ISINF 1
103 #  define isinf(a) (fpclassify(a) == FP_MINUS_INF || fpclassify(a) == FP_PLUS_INF)
104 #endif
105
106 #if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASSIFY) && defined(FP_INFINITE))
107 #  define HAVE_ISINF 1
108 #  define isinf(a) (fpclassify(a) == FP_INFINITE)
109 #endif
110
111 /* for AIX */
112 #if (! defined(HAVE_ISINF) && defined(HAVE_CLASS))
113 #  define HAVE_ISINF 1
114 #  define isinf(a) (class(a) == FP_MINUS_INF || class(a) == FP_PLUS_INF)
115 #endif
116
117 #if (! defined (HAVE_FINITE) && defined (HAVE_ISFINITE))
118 #  define HAVE_FINITE 1
119 #  define finite(a) isfinite(a)
120 #endif
121
122 #if (! defined(HAVE_FINITE) && defined(HAVE_ISNAN) && defined(HAVE_ISINF))
123 #  define HAVE_FINITE 1
124 #  define finite(a) (! isnan(a) && ! isinf(a))
125 #endif
126
127 #ifndef HAVE_FINITE
128 #error "Can't compile without finite function"
129 #endif
130
131 #ifndef HAVE_ISINF
132 #error "Can't compile without isinf function"
133 #endif
134
135 #endif /* CONFIG_H */
136 ])
137
138
139
140 dnl Check for the compiler and static/shared library creation.
141 AC_PROG_CC
142 AC_PROG_CPP
143 AC_PROG_LIBTOOL
144
145 dnl Checks for header files.
146 AC_HEADER_STDC
147 AC_HEADER_DIRENT
148 AC_CHECK_HEADERS(sys/stat.h sys/types.h fcntl.h time.h locale.h fp_class.h malloc.h unistd.h ieeefp.h math.h sys/time.h sys/times.h sys/param.h sys/resource.h float.h)
149
150 dnl Checks for typedefs, structures, and compiler characteristics.
151 AC_C_CONST
152 AC_HEADER_TIME
153 AC_STRUCT_TM
154
155 dnl substitute them in all the files listed in AC_OUTPUT
156 AC_SUBST(PERLFLAGS)
157
158 dnl Checks for libraries.
159 AC_CHECK_FUNC(acos, , AC_CHECK_LIB(m, acos))
160
161 AC_DEFUN([EX_CHECK_ALL],
162 [ AC_CHECK_LIB($1,$2,
163   [ AC_CHECK_HEADER($3,[LIBS="-l$1 ${LIBS}"],[
164      [ $echo "#include <$3>" | $CC -E - > /dev/null ] 
165      AC_MSG_ERROR([Adjust CPPFLAGS so that the $4 header $3 AND its dependencies gets found])
166   ] ) ],
167   [ AC_MSG_ERROR([
168 ############################################################################
169 I could not find a working copy of $4. Check config.log for hints on why
170 this is the case. Maybe you need to set LDFLAGS appropriately so that the
171 linker can find lib$1. If you have not installed $4, you can get it
172 either from its original home on
173
174    $6
175
176 Or you can find an archive copy on
177
178    http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/pub/libs
179
180 The last tested version of $4 is $5.
181 ############################################################################
182 ])] )
183 ]
184 )
185  
186 EX_CHECK_ALL(cgi,        cgiInit,                   cgi.h,                  cgilib,      0.5,    http://www.infodrom.org/projects/cgilib)
187 EX_CHECK_ALL(art_lgpl_2, art_vpath_add_point,       libart_lgpl/libart.h,   libart_lgpl, 2.3.16, ftp://ftp.gnome.org/pub/GNOME/sources/libart_lgpl/2.3/)
188 EX_CHECK_ALL(z,          zlibVersion,               zlib.h,                 zlib,        1.2.1,  http://www.gzip.org/zlib/)
189 EX_CHECK_ALL(png,        png_access_version_number, png.h,                  libpng,      1.2.5,  http://prdownloads.sourceforge.net/libpng/)
190 EX_CHECK_ALL(freetype,   FT_Init_FreeType,          ft2build.h,             freetype,    2.1.5,  http://prdownloads.sourceforge.net/freetype/)
191
192 dnl Check for Perl.
193 AC_PATH_PROG(PERL, perl, no)
194 if test "x$PERL" = "xno"; then
195         COMP_PERL=
196 else
197         COMP_PERL="perl_piped perl_shared"
198         AC_MSG_CHECKING(for shared library extension)
199         SO_EXT=`$PERL -e 'use Config; if (defined $Config{so} and $Config{so} ne 'a') {print "$Config{so}\n"} else {print "so\n"};'`
200         AC_MSG_RESULT($SO_EXT)
201         AC_MSG_CHECKING(for the C compiler perl wants to use to build its modules)
202         PROBLEMCC=`$PERL -e 'use Config; ($cc = $Config{cc}) =~ s/\s.*//; exit 0 if -x $cc; map {if (-x "$_/$cc"){exit 0}} split /:/, $ENV{PATH};print $Config{cc}'`
203         if test x$PROBLEMCC != x; then
204                 AC_MSG_RESULT(no)
205                 echo Could not find the Compiler: '"'$PROBLEMCC'"'
206                 echo which has been used to build perl. You may have to compile
207                 echo your own copy of perl to make this work. Binary perls often
208                 echo exhibit this problem
209                 exit 1
210         else
211                 AC_MSG_RESULT(found)
212         fi
213 fi
214 AC_SUBST(COMP_PERL)
215 AC_SUBST(SO_EXT)
216
217 dnl Check for Tcl.
218 withval=""
219 AC_ARG_WITH(tcllib,[  --with-tcllib=DIR       location of the tclConfig.sh])
220 found=0
221 AC_MSG_CHECKING(for tclConfig.sh in $withval)
222 if test -f "$withval/tclConfig.sh" ; then
223         tcl_config=$withval/tclConfig.sh
224         found=1
225         AC_MSG_RESULT(yes)
226         break
227 else
228         AC_MSG_RESULT(no)
229 fi
230
231 if test $found -eq 0 ; then
232         AC_MSG_WARN([tclConfig.sh not found - Tcl interface won't be built])
233 else
234         . $tcl_config
235 fi
236
237 dnl Pass additional perl options when generating Makefile from Makefile.PL
238 # Options to pass when configuring perl module
239 AC_ARG_WITH(perl-options,
240 [  --with-perl-options=[OPTIONS]  options to pass on command-line when
241                           generating Makefile from Makefile.PL],
242 [PERL_MAKE_OPTIONS=$withval])
243 AC_SUBST(PERL_MAKE_OPTIONS)
244
245 AM_CONDITIONAL(COMP_TCL, test x$found = x1 )
246
247 AC_SUBST(TCL_PREFIX)
248 AC_SUBST(TCL_SHLIB_CFLAGS)
249 AC_SUBST(TCL_SHLIB_LD)
250 AC_SUBST(TCL_SHLIB_SUFFIX)
251 AC_SUBST(TCL_PACKAGE_PATH)
252 AC_SUBST(TCL_LD_SEARCH_FLAGS)
253
254
255
256 dnl Check for nroff
257 AC_PATH_PROGS(NROFF, gnroff nroff)
258 AC_PATH_PROGS(TROFF, groff troff)
259
260 dnl Does the compiler like -Wall and -pedantic?
261 if test "x$GCC" = "xyes"; then
262   oCFLAGS=$CFLAGS
263   CFLAGS="$CFLAGS -Wall -pedantic -Wshadow -Wpointer-arith -Wcast-align -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline -W"
264   AC_CACHE_CHECK(if we can use GCC-specific compiler options, rd_cv_gcc_opt,
265                 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[return 0 ]])],[rd_cv_gcc_opt=yes],[rd_cv_gcc_opt=no ])
266                ]
267         )
268   if test $rd_cv_gcc_opt = no; then
269          CFLAGS=$oCFLAGS
270   fi
271 fi
272
273 dnl add pic flag in any case this makes sure all our code is relocatable
274 CFLAGS="$CFLAGS "`grep pic_flag= libtool | head -1|sed -e 's/.*pic_flag=//' -e 's/"//g'`
275
276 ZLIB_CFLAGS=$CFLAGS
277 dnl it seems that hpux chockes on -fPIC for some reason
278 case $target_os in
279 *hpux*)
280         ZLIB_CFLAGS=`echo $CFLAGS|sed -e 's/-fPIC/-fpic/g'`
281 ;;
282 esac
283 AC_SUBST(ZLIB_CFLAGS)
284
285 dnl Checks for library functions.
286 AC_FUNC_STRFTIME
287 AC_FUNC_VPRINTF
288
289 dnl for each function found we get a definition in config.h 
290 dnl of the form HAVE_FUNCTION
291
292 AC_CHECK_FUNCS(tzset opendir readdir chdir chroot getuid setlocale strerror strerror_r snprintf vsnprintf fpclass class fp_class isnan memmove strchr mktime getrusage gettimeofday)
293
294 dnl HP-UX 11.00 does not have finite but does have isfinite as a macro
295 AC_CHECK_FUNCS(fpclassify, ,
296   [AC_MSG_CHECKING(for fpclassify with <math.h>)
297     AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <math.h>]], [[float f = 0.0; fpclassify(f)]])],[AC_MSG_RESULT(yes)
298       AC_DEFINE(HAVE_FPCLASSIFY)],[AC_MSG_RESULT(no)])])
299 AC_CHECK_FUNCS(finite, ,
300   [AC_CHECK_FUNCS(isfinite, ,
301     [AC_MSG_CHECKING(for isfinite with <math.h>)
302     AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <math.h>]], [[float f = 0.0; isfinite(f)]])],[AC_MSG_RESULT(yes)
303       AC_DEFINE(HAVE_ISFINITE)],[AC_MSG_RESULT(no)])])])
304 AC_CHECK_FUNCS(isinf, ,
305   [AC_MSG_CHECKING(for isinf with <math.h>)
306     AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <math.h>]], [[float f = 0.0; isinf(f)]])],[AC_MSG_RESULT(yes)
307       AC_DEFINE(HAVE_ISINF)],[AC_MSG_RESULT(no)])])
308
309 dnl what does realloc do if it gets called with a NULL pointer
310
311 AC_CACHE_CHECK([if realloc can deal with NULL], rd_cv_null_realloc,
312 [AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <stdlib.h>
313               int main(void){
314               char *x = NULL;
315               x = realloc (x,10);
316               if (x==NULL) return 1;
317               return 0;
318              }]])],[rd_cv_null_realloc=yes],[rd_cv_null_realloc=nope],[:])])
319
320 if test x"$rd_cv_null_realloc" = xnope; then
321 AC_DEFINE(NO_NULL_REALLOC)
322 fi
323
324 dnl determine how to get IEEE math working
325 dnl AC_IEEE(MESSAGE, set rd_cv_ieee_[var] variable, INCLUDES,
326 dnl   FUNCTION-BODY, [ACTION-IF-FOUND [,ACTION-IF-NOT-FOUND]])
327
328 AC_C_BIGENDIAN
329
330 AC_DEFUN([AC_IEEE], 
331 AC_MSG_CHECKING([if IEEE math works $1])
332 AC_CACHE_VAL([rd_cv_ieee_$2],
333 [AC_RUN_IFELSE([AC_LANG_SOURCE([[$3
334
335 #if HAVE_MATH_H
336 #  include <math.h>
337 #endif
338
339 #if HAVE_FLOAT_H
340 #  include <float.h>  
341 #endif
342
343 #if HAVE_IEEEFP_H
344 #  include <ieeefp.h>
345 #endif
346
347 #if HAVE_FP_CLASS_H
348 #  include <fp_class.h>
349 #endif
350
351 /* Solaris */
352 #if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASS))
353 #  define HAVE_ISINF 1
354 #  define isinf(a) (fpclass(a) == FP_NINF || fpclass(a) == FP_PINF)
355 #endif
356
357 /* Digital UNIX */
358 #if (! defined(HAVE_ISINF) && defined(HAVE_FP_CLASS) && defined(HAVE_FP_CLASS_H))
359 #  define HAVE_ISINF 1
360 #  define isinf(a) (fp_class(a) == FP_NEG_INF || fp_class(a) == FP_POS_INF)
361 #endif 
362
363 /* AIX */
364 #if (! defined(HAVE_ISINF) && defined(HAVE_CLASS))
365 #  define HAVE_ISINF 1
366 #  define isinf(a) (class(a) == FP_MINUS_INF || class(a) == FP_PLUS_INF)
367 #endif
368
369 #if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASSIFY) && defined(FP_PLUS_INF) && defined(FP_MINUS_INF))
370 #  define HAVE_ISINF 1
371 #  define isinf(a) (fpclassify(a) == FP_MINUS_INF || fpclassify(a) == FP_PLUS_INF)
372 #endif
373
374 #if (! defined(HAVE_ISINF) && defined(HAVE_FPCLASSIFY) && defined(FP_INFINITE))
375 #  define HAVE_ISINF 1
376 #  define isinf(a) (fpclassify(a) == FP_INFINITE)
377 #endif
378
379 #include <stdio.h>
380 int main(void){
381     double nan,inf,c,zero;
382     $4;
383     /* some math to see if we get a floating point exception */
384     zero=sin(0.0); /* don't let the compiler optimize us away */
385     nan=0.0/zero; /* especially here */
386     inf=1.0/zero; /* and here. I want to know if it can do the magic */
387                   /* at run time without sig fpe */
388     c = inf + nan;
389     c = inf / nan;
390     if (! isnan(nan)) {printf ("not isnan(NaN) ... "); return 1;}
391     if (nan == nan) {printf ("nan == nan ... "); return 1;}
392     if (! isinf(inf)) {printf ("not isinf(oo) ... "); return 1;}
393     if (! isinf(-inf)) {printf ("not isinf(-oo) ... "); return 1;}
394     if (! inf > 0) {printf ("not inf > 0 ... "); return 1;}
395     if (! -inf < 0) {printf ("not -inf < 0 ... "); return 1;}
396     return 0;
397  }]])],[rd_cv_ieee_$2=yes],[rd_cv_ieee_$2=no],[:])])
398 dnl these we run regardles is cached or not
399 if test x${rd_cv_ieee_$2} = "xyes"; then
400  AC_MSG_RESULT(yes)
401  $5
402 else
403  AC_MSG_RESULT(no)
404  $6
405 fi
406
407 )
408
409 _cflags=${CFLAGS}
410 AC_IEEE([out of the box], works, , , ,
411   [CFLAGS="$_cflags -ieee"
412   AC_IEEE([with the -ieee switch], switch, , , ,
413     [CFLAGS="$_cflags -qfloat=nofold"
414     AC_IEEE([with the -qfloat=nofold switch], nofold, , , ,
415       [CFLAGS="$_cflags -w -qflttrap=enable:zerodivide"
416       AC_IEEE([with the -w -qflttrap=enable:zerodivide], flttrap, , , ,
417        [CFLAGS="$_cflags -mieee"
418        AC_IEEE([with the -mieee switch], mswitch, , , ,
419          [CFLAGS="$_cflags -q float=rndsngl"
420          AC_IEEE([with the -q float=rndsngl switch], qswitch, , , ,
421            [CFLAGS="$_cflags -OPT:IEEE_NaN_inf=ON"
422            AC_IEEE([with the -OPT:IEEE_NaN_inf=ON switch], ieeenaninfswitch, , , ,
423              [CFLAGS="$_cflags -OPT:IEEE_comparisons=ON"
424              AC_IEEE([with the -OPT:IEEE_comparisons=ON switch], ieeecmpswitch, , , ,
425                [CFLAGS=$_cflags
426                AC_IEEE([with fpsetmask(0)], mask,
427                  [#include <floatingpoint.h>], [fpsetmask(0)],
428                  [AC_DEFINE(MUST_DISABLE_FPMASK)
429                  PERLFLAGS="CCFLAGS=-DMUST_DISABLE_FPMASK"],
430                  [AC_IEEE([with signal(SIGFPE,SIG_IGN)], sigfpe,
431                    [#include <signal.h>], [signal(SIGFPE,SIG_IGN)],
432                    [AC_DEFINE(MUST_DISABLE_SIGFPE)
433                    PERLFLAGS="CCFLAGS=-DMUST_DISABLE_SIGFPE"],          
434                    AC_MSG_ERROR([
435 Your Compiler does not do propper IEEE math ... Please find out how to
436 make IEEE math work with your compiler and let me know (oetiker@ee.ethz.ch).
437 Check config.log to see what went wrong ...
438 ]))])])])])])])])])])
439
440
441 AC_CONFIG_FILES([examples/shared-demo.pl                        \
442           examples/piped-demo.pl                        \
443           examples/stripes.pl                           \
444           examples/bigtops.pl                           \
445           examples/minmax.pl                            \
446           examples/cgi-demo.cgi                         \
447           examples/Makefile                             \
448           doc/Makefile                                  \
449           src/Makefile                                  \
450           bindings/Makefile                             \
451           bindings/tcl/Makefile                         \
452           Makefile])
453 AC_CONFIG_COMMANDS([default],[[\
454           chmod +x examples/*.cgi examples/*.pl]],[[]])
455 AC_OUTPUT
456
457 AC_MSG_CHECKING(in)
458 AC_MSG_RESULT(and out again)
459
460 echo $ECHO_N "ordering CD from http://people.ee.ethz.ch/~oetiker/wish $ECHO_C" 1>&6
461 sleep 1
462 echo $ECHO_N ".$ECHO_C" 1>&6
463 sleep 1
464 echo $ECHO_N ".$ECHO_C" 1>&6
465 sleep 1
466 echo $ECHO_N ".$ECHO_C" 1>&6
467 sleep 1
468 echo $ECHO_N ".$ECHO_C" 1>&6
469 sleep 1
470 AC_MSG_RESULT([ just kidding ;-)])
471 echo
472 echo "----------------------------------------------------------------"
473 echo "Config is DONE!"
474 echo
475 echo "Type 'make' to compile the software and use 'make install' to "
476 echo "install everything to: $prefix."
477 echo
478 echo "If you want to install the perl"
479 echo "modules in site-perl, try 'make site-perl-install'."
480 echo 
481 echo "       ... that wishlist is NO JOKE. If you find RRDtool useful"
482 echo "make me happy. Go to http://people.ee.ethz.ch/~oetiker/wish and"
483 echo "place an order."
484 echo 
485 echo "                               -- Tobi Oetiker <tobi@oetiker.ch>"
486 echo "----------------------------------------------------------------"