From: oetiker Date: Wed, 21 Nov 2007 06:57:22 +0000 (+0000) Subject: * improve portability of compile environment to netbsd and solaris X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=887e52ad0ab3f742cbfcee05b6f44c66decebe40;p=rrdtool.git * improve portability of compile environment to netbsd and solaris git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@1242 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/bindings/perl-shared/Makefile.PL b/bindings/perl-shared/Makefile.PL index 863444c..c31f3b9 100644 --- a/bindings/perl-shared/Makefile.PL +++ b/bindings/perl-shared/Makefile.PL @@ -30,8 +30,11 @@ WriteMakefile( 'VERSION_FROM' => 'RRDs.pm', # finds $VERSION 'DEFINE' => "-DPERLPATCHLEVEL=$Config{PATCHLEVEL}", 'INC' => '-I../../src', + 'LIBS' => '-lm -lpng -lz -lfreetype', # Perl will figure out which one is valid - 'dynamic_lib' => {'OTHERLDFLAGS' => "$librrd -lm"}, + #'dynamic_lib' => {'OTHERLDFLAGS' => "$librrd -lm"}, + 'depend' => {'RRDs.c' => "../../src/librrd.la"}, + 'LDFROM' => '$(OBJECT) '.$librrd, 'realclean' => {FILES => 't/demo?.rrd t/demo?.png' } ); diff --git a/configure.ac b/configure.ac index e09c051..0977c8a 100644 --- a/configure.ac +++ b/configure.ac @@ -49,15 +49,105 @@ AH_TOP([ /* realloc does not support NULL as argument */ #undef NO_NULL_REALLOC +/* lets enable madvise defines in netbsd */ +#if defined(__NetBSD__) +# if !defined(_NETBSD_SOURCE) +# define _NETBSD_SOURCE +# endif +#endif + ]) AH_BOTTOM([ -/* enable posix_fadvise on linux */ -#if defined(HAVE_POSIX_FADVISE) && defined(HAVE_FCNTL_H) -#define _XOPEN_SOURCE 600 +#ifdef HAVE_FEATURES_H +#define _XOPEN_SOURCE 600 +#define _BSD_SOURCE 1 +# include +#endif + +#ifdef HAVE_ERRNO_H +# include +#endif + +#if defined(HAVE_SYS_MMAN_H) +#include +#endif + +#ifdef HAVE_SYS_TYPES_H +# include +#endif + +#ifdef HAVE_SYS_PARAM_H +# include +#endif +#ifndef MAXPATH +# ifdef PATH_MAX +# define MAXPATH PATH_MAX +# endif +#endif +#ifndef MAXPATH +/* else try the BSD variant */ +# ifdef MAXPATHLEN +# define MAXPATH MAXPATHLEN +# endif +#endif + +#if !defined HAVE_MADVISE && defined HAVE_POSIX_MADVISE +/* use posix_madvise family */ +# define madvise posix_madvise +# define MADV_NORMAL POSIX_MADV_NORMAL +# define MADV_RANDOM POSIX_MADV_RANDOM +# define MADV_SEQUENTIAL POSIX_MADV_SEQUENTIAL +# define MADV_WILLNEED POSIX_MADV_WILLNEED +# define MADV_DONTNEED POSIX_MADV_DONTNEED +#endif + +#if defined POSIX_MADV_RANDOM && !defined MADV_RANDOM +#define MADV_RANDOM POSIX_MADV_RANDOM +#endif + + + +#if defined HAVE_MADVISE || defined HAVE_POSIX_MADVISE +# define USE_MADVISE 1 +#endif + +#ifdef HAVE_SYS_STAT_H +# include +#endif + +#ifdef HAVE_FCNTL_H #include #endif +#ifdef HAVE_UNISTD_H +# include +#endif + +#ifdef TIME_WITH_SYS_TIME +# include +# include +#else +# ifdef HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif + +#ifdef HAVE_SYS_TIMES_H +# include +#endif + +#ifdef HAVE_SYS_RESOURCE_H +# include +#if (defined(__svr4__) && defined(__sun__)) +/* Solaris headers (pre 2.6) don't have a getrusage prototype. + Use this instead. */ +extern int getrusage(int, struct rusage *); +#endif /* __svr4__ && __sun__ */ +#endif + /* define strrchr, strchr and memcpy, memmove in terms of bsd funcs make sure you are NOT using bcopy, index or rindex in the code */ @@ -109,7 +199,7 @@ char *strchr (), *strrchr (); /* solaris 10 it defines isnan such that only forte can compile it ... bad bad */ #if (defined(HAVE_ISNAN) && defined(isnan) && defined(HAVE_FPCLASS)) -# undef isnan +# undefine isnan # define isnan(a) (fpclass(a) == FP_SNAN || fpclass(a) == FP_QNAN) #endif @@ -222,7 +312,7 @@ CONFIGURE_PART(Checking for Header Files) dnl Checks for header files. AC_HEADER_STDC AC_HEADER_DIRENT -AC_CHECK_HEADERS(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 float.h strings.h) +AC_CHECK_HEADERS( 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 float.h strings.h) dnl Checks for typedefs, structures, and compiler characteristics. AC_C_CONST @@ -250,9 +340,46 @@ dnl of the form HAVE_FUNCTION AC_CHECK_FUNCS(tzset mbstowcs opendir readdir chdir chroot getuid setlocale strerror strerror_r snprintf vsnprintf fpclass class fp_class isnan memmove strchr mktime getrusage gettimeofday posix_fadvise madvise) AC_CHECK_DECLS(fdatasync, [], [], [#include ]) + +dnl XXX: dunno about windows.. add AC_CHECK_FUNCS(munmap) there too? +if test "x$enable_mmap" = "xyes"; then + case "$host" in + *cygwin*) + # the normal mmap test does not work in cygwin + AC_CHECK_FUNCS(mmap) + if test "x$ac_cv_func_mmap" = "xyes"; then + ac_cv_func_mmap_fixed_mapped=yes + fi + ;; + *) + AC_CHECK_HEADERS(sys/mman.h) + AC_FUNC_MMAP + AC_CHECK_FUNCS(mmap munmap msync) + AC_CHECK_DECLS(madvise, [], [], [#ifdef HAVE_SYS_MMAN_H + # include + #endif]) + if test "x$ac_cv_have_decl_madvise" = "xyes"; + then + AC_CHECK_FUNCS(madvise) + else + AC_CHECK_FUNCS(posix_madvise) + if test "x$ac_cv_func_posix_madvise" != "xyes"; then + AC_MSG_WARN([madvise() nor posix_madvise() found.]) + fi + fi + ;; + esac + if test "x$ac_cv_func_mmap" != "xyes"; + then + AC_MSG_ERROR([--enable-mmap requested but mmap() was not detected]) +dnl enable_mmap="no" + fi +fi + +dnl can we use posix_fadvise AC_CHECK_DECLS(posix_fadvise, [], [], [#define _XOPEN_SOURCE 600 #include ]) -AC_CHECK_DECLS(madvise, [], [], [#include ]) +AC_CHECK_FUNCS(posix_fadvise) if test "x$enable_mmap" = xyes; then case "$host" in diff --git a/src/rrd_tool.h b/src/rrd_tool.h index 852bfec..84ffc0a 100644 --- a/src/rrd_tool.h +++ b/src/rrd_tool.h @@ -71,39 +71,10 @@ extern "C" { # include #endif -#if HAVE_UNISTD_H -# include -#endif - #if HAVE_STRINGS_H # include #endif -#if TIME_WITH_SYS_TIME -# include -# include -#else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif - -#if HAVE_SYS_TIMES_H -# include -#endif - - -#if HAVE_SYS_RESOURCE_H -# include -#if (defined(__svr4__) && defined(__sun__)) -/* Solaris headers (pre 2.6) don't have a getrusage prototype. - Use this instead. */ -extern int getrusage(int, struct rusage *); -#endif /* __svr4__ && __sun__ */ -#endif - #include "rrd.h" #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) diff --git a/src/rrd_update.c b/src/rrd_update.c index 08a2ce2..9225fb0 100644 --- a/src/rrd_update.c +++ b/src/rrd_update.c @@ -9,9 +9,6 @@ #include "rrd_tool.h" #include #include -#ifdef HAVE_MMAP -# include -#endif #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) #include @@ -427,10 +424,10 @@ _rrd_update(const char *filename, const char *tmplt, int argc, const char **argv fclose(rrd_file); return(-1); } -#ifdef HAVE_MADVISE +#ifdef USE_MADVISE /* when we use mmaping we tell the kernel the mmap equivalent of POSIX_FADV_RANDOM */ - madvise(rrd_mmaped_file,rrd_filesize,POSIX_MADV_RANDOM); + madvise(rrd_mmaped_file,rrd_filesize,MADV_RANDOM); #endif #endif /* loop through the arguments. */