From d361be13eb92757969ecea06d4fb1ab4fa4a6114 Mon Sep 17 00:00:00 2001
From: Christian Engwer <christi@dune-project.org>
Date: Wed, 10 Nov 2004 15:10:14 +0000
Subject: [PATCH] added pagesize test

[[Imported from SVN: r1046]]
---
 m4/dune_all.m4      |   1 +
 m4/dune_pagesize.m4 | 116 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 117 insertions(+)
 create mode 100644 m4/dune_pagesize.m4

diff --git a/m4/dune_all.m4 b/m4/dune_all.m4
index 02126585e..ced712b4c 100644
--- a/m4/dune_all.m4
+++ b/m4/dune_all.m4
@@ -52,6 +52,7 @@ dnl check all components
   AC_REQUIRE([DUNE_PATH_F5])
   AC_REQUIRE([DUNE_PATH_AMIRAMESH])
   AC_REQUIRE([DUNE_MPI])
+  AC_REQUIRE([DUNE_GETPAGESIZE])
 
   if test x$HAVE_DUNE != x1 ; then
     AC_MSG_ERROR([Can't work without the DUNE-library. Maybe you have to supply your DUNE-directory as --with-dune=dir])
diff --git a/m4/dune_pagesize.m4 b/m4/dune_pagesize.m4
new file mode 100644
index 000000000..620b05fd0
--- /dev/null
+++ b/m4/dune_pagesize.m4
@@ -0,0 +1,116 @@
+# $Id$
+
+#################################
+# getpagesize 
+# -----------
+# On some systems, the page size is available as the macro
+# PAGE_SIZE in the header file `sys/param.h'. On others, the page size
+# is available via the sysconf function. If none of those work, you
+# must generally simply guess a value such as 4096. 
+#################################
+
+AC_DEFUN([DUNE_GETPAGESIZE],[
+AC_REQUIRE([AC_PROG_CC])
+AC_MSG_NOTICE([Checking how to determine PAGESIZE])
+
+#################################
+# user defined pagesize
+#################################
+AC_ARG_WITH(pagesize,
+  AC_HELP_STRING([--with-pagesize=PAGESIZE],[pagesize of this system]))
+
+if test x$with_pagesize != x ; then
+  DUNE_PAGESIZE=$with_pagesize
+  AC_MSG_NOTICE([using user defined value])
+fi
+
+#################################
+# test int getpagesize(void);
+#################################
+cat >conftest.c <<_ACEOF
+#include <unistd.h>
+#include <stdio.h>
+int main() { printf("%i", getpagesize()); }
+_ACEOF
+
+if test x$DUNE_PAGESIZE == x ; then
+  AC_MSG_CHECKING([for int getpagesize(void)])
+  if $CC $CFLAGS conftest.c -o conftest.$ac_exeext >&5; then
+	DUNE_PAGESIZE=`./conftest.$ac_exeext`
+    rm -f conftest.$ac_exeext
+  fi
+  AC_MSG_RESULT(yes)
+fi
+
+#################################
+# test int getpagesize(void);
+#################################
+cat >conftest.c <<_ACEOF
+#include <unistd.h>
+#include <stdio.h>
+int main() { printf("%i", sysconf(_SC_PAGESIZE)); }
+_ACEOF
+
+if test x$DUNE_PAGESIZE == x ; then
+  AC_MSG_CHECKING([for int sysconf(_SC_PAGESIZE)])
+  if $CC $CFLAGS conftest.c -o conftest.$ac_exeext >&5; then
+	DUNE_PAGESIZE=`./conftest.$ac_exeext`
+    rm -f conftest.$ac_exeext
+  fi
+  AC_MSG_RESULT(yes)
+fi
+
+#################################
+# test int getpagesize(void);
+#################################
+cat >conftest.c <<_ACEOF
+#include <unistd.h>
+#include <stdio.h>
+int main() { printf("%i", sysconf(_SC_PAGE_SIZE)); }
+_ACEOF
+
+if test x$DUNE_PAGESIZE == x ; then
+  AC_MSG_CHECKING([for int sysconf(_SC_PAGE_SIZE)])
+  if $CC $CFLAGS conftest.c -o conftest.$ac_exeext >&5; then
+	DUNE_PAGESIZE=`./conftest.$ac_exeext`
+    rm -f conftest.$ac_exeext
+  fi
+  AC_MSG_RESULT(yes)
+fi
+
+#################################
+# test int getpagesize(void);
+#################################
+cat >conftest.c <<_ACEOF
+#include <sys/param.h>
+#include <stdio.h>
+int main() { printf("%i", PAGE_SIZE); }
+_ACEOF
+
+if test x$DUNE_PAGESIZE == x ; then
+  AC_MSG_CHECKING([for definition of PAGE_SIZE in sys/param.h])
+  if $CC $CFLAGS conftest.c -o conftest.$ac_exeext >&5; then
+	DUNE_PAGESIZE=`./conftest.$ac_exeext`
+    rm -f conftest.$ac_exeext
+  fi
+  AC_MSG_RESULT(yes)
+fi
+
+#################################
+# fall back to default
+#################################
+if test x$DUNE_PAGESIZE == x ; then
+  DUNE_PAGESIZE=4096
+  AC_MSG_WARN([failed to determine PAGE_SIZE, falling back to default 4096])
+fi
+
+#################################
+# store pagesize & clean up
+#################################
+AC_DEFINE_UNQUOTED(DUNE_PAGESIZE, $DUNE_PAGESIZE, [Pagesize of this system])
+
+AC_MSG_NOTICE([setting DUNE_PAGESIZE to $DUNE_PAGESIZE])
+
+rm -f conftest.c
+
+])
-- 
GitLab