]> www.ginac.de Git - ginac.git/commitdiff
Patch from Alexei to make it possible to compile on MinGW.
authorChris Dams <Chris.Dams@mi.infn.it>
Mon, 31 Jul 2006 16:46:27 +0000 (16:46 +0000)
committerChris Dams <Chris.Dams@mi.infn.it>
Mon, 31 Jul 2006 16:46:27 +0000 (16:46 +0000)
acinclude.m4
check/Makefile.am
check/exam_archive.cpp
check/run_checks
check/run_exams
check/run_times
check/timer.cpp
check/timer.h
configure.ac
ginsh/ginsh_parser.yy

index 09d71cb3b2fa84fe7c49ba3e5d1e7c63c8e68748..4ab138787626c52d056f02959f489f5ab822c7bc 100644 (file)
@@ -43,6 +43,10 @@ dnl When both libtermcap and libncurses exist, we prefer the latter, because
 dnl libtermcap is being phased out.
 AC_DEFUN([GINAC_TERMCAP],
 [LIBTERMCAP=
+case $host_os in
+*mingw32*) dnl termcap library is not necessary on this platform
+;;
+*)
 AC_CHECK_FUNCS(tgetent)
 if test "x$ac_cv_func_tgetent" = "xyes"; then
     :
@@ -52,6 +56,8 @@ else
         AC_CHECK_LIB(termcap, tgetent, LIBTERMCAP="-ltermcap")
     fi
 fi
+;;
+esac
 AC_SUBST(LIBTERMCAP)
 ])
 
@@ -100,3 +106,22 @@ else
     fi
     echo "Configuration of GiNaC $VERSION done. Now type \"make\"."
 fi])
+
+AC_DEFUN([GINAC_HAVE_RUSAGE],
+[AC_CACHE_CHECK([whether struct rusage is declared in <sys/resource.h>],
+ac_cv_have_rusage,
+ [AC_TRY_COMPILE([#include <sys/times.h>
+                  #include <sys/resource.h>],
+                  [struct rusage resUsage;
+                   getrusage(RUSAGE_SELF, &resUsage);
+                   return 0;],
+                 [ac_cv_have_rusage=yes],
+                 [ac_cv_have_rusage=no])
+])
+CONFIG_RUSAGE="no"
+if test "$ac_cv_have_rusage" = yes; then
+  CONFIG_RUSAGE="yes"
+  AC_DEFINE(HAVE_RUSAGE,,[define if struct rusage declared in <sys/resource.h>])
+fi
+AC_SUBST(CONFIG_RUSAGE)
+])
index 48e7a999e2a20b3bc79fcc04d5fe28a4a9495721..b7c9d0fbf0972e3010c13771828f88c6530171d9 100644 (file)
@@ -2,6 +2,7 @@
 
 TESTS = run_exams run_checks run_times
 check_PROGRAMS = exams checks times
+TESTS_ENVIRONMENT = EXEEXT=$(EXEEXT) srcdir=$(srcdir)
 
 checks_SOURCES =  check_numeric.cpp check_inifcns.cpp check_matrices.cpp \
   check_lsolve.cpp genex.cpp checks.cpp checks.h
index 303192d0fbd90c949fa6ec14fb85e5a91bed2c52..e2e62615f662a3227a65eb850b86e8e3ffbcf236 100644 (file)
@@ -54,12 +54,12 @@ unsigned exam_archive()
        archive ar;
        ar.archive_ex(e, "expr 1");
        {
-               std::ofstream fout("exam.gar");
+               std::ofstream fout("exam.gar", std::ios_base::binary);
                fout << ar;
        }
        ar.clear();
        {
-               std::ifstream fin("exam.gar");
+               std::ifstream fin("exam.gar", std::ios_base::binary);
                fin >> ar;
        }
        f = ar.unarchive_ex(lst(x, y, mu, dim), "expr 1");
index 6304d18f5b66b09086d9a690a36071bdd9058e9e..93b77065d1b0ca0acbe93fa685c12d1cf6051fc9 100755 (executable)
@@ -1,4 +1,4 @@
 #! /bin/sh
 echo "GiNaC will now run through some rather costly random consistency checks:"
-./checks 2>checks.out
+./checks${EXEEXT} 2>checks.out
 cmp ${srcdir}/checks.ref checks.out
index 8c8efa59408cb3c109cb78c0f5abbdc9e5a5ebea..1e7ba46325edb0fb2a661aa5b0206b63ca7ceb28 100755 (executable)
@@ -1,4 +1,4 @@
 #! /bin/sh
 echo "GiNaC will now take an exam with specific input (like a pupils' exam):"
-./exams 2>exams.out
+./exams${EXEEXT} 2>exams.out
 cmp ${srcdir}/exams.ref exams.out
index 3687f1ef59dfb7fe0ba142be3acb24875475d606..eb2380bd7aea8dafb26a40a5aac854039a7b8f56 100755 (executable)
@@ -1,4 +1,4 @@
 #! /bin/sh
 echo "GiNaC will now run through some basic timings:"
-./times 2>times.out
+./times${EXEEXT} 2>times.out
 cmp ${srcdir}/times.ref times.out
index 0b978a7ded82aadb3cea7a1ed4d68eda84c45d8e..1ac07c9d9cc492a1806424da201dbe15e380833e 100644 (file)
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <sys/time.h>
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#ifdef HAVE_RUSAGE
 #include <sys/resource.h>
 #include <unistd.h>
+#include <sys/time.h>
+#else
+#include <ctime>
+#endif
 
 #include "timer.h"
 
 timer::timer() : on(false)
 {
+#ifdef HAVE_RUSAGE
        getrusage(RUSAGE_SELF, &used1);
        used2.ru_utime = used1.ru_utime;
        used2.ru_stime = used1.ru_stime;
+#else
+       used1 = clock();
+       used2 = used1;
+#endif
 }
 
 void timer::start()
 {
        on = true;
+#ifdef HAVE_RUSAGE
        getrusage(RUSAGE_SELF, &used1);
        used2.ru_utime = used1.ru_utime;
        used2.ru_stime = used1.ru_stime;
+#else
+       used1 = clock();
+       used2 = used1;
+#endif
 }
 
 void timer::stop()
 {
        on = false;
+#ifdef HAVE_RUSAGE
        getrusage(RUSAGE_SELF, &used2);
+#else
+       used2 = clock();
+#endif
 }
 
 void timer::reset()
 {
+#ifdef HAVE_RUSAGE
        getrusage(RUSAGE_SELF, &used1);
        used2.ru_utime = used1.ru_utime;
        used2.ru_stime = used1.ru_stime;
+#else
+       used1 = clock();
+       used2 = used1;
+#endif
 }
 
 double timer::read()
 {
-       double elapsed;
+#ifdef HAVE_RUSAGE
        if (running())
                getrusage(RUSAGE_SELF, &used2);
-       elapsed = ((used2.ru_utime.tv_sec - used1.ru_utime.tv_sec) +
-                  (used2.ru_stime.tv_sec - used1.ru_stime.tv_sec) +
-                  (used2.ru_utime.tv_usec - used1.ru_utime.tv_usec) * 1e-6 +
-                  (used2.ru_stime.tv_usec - used1.ru_stime.tv_usec) * 1e-6);
-       // Results more accurate than 10ms are pointless:
-       return 0.01*int(elapsed*100+0.5);
+       return ((used2.ru_utime.tv_sec - used1.ru_utime.tv_sec) +
+               (used2.ru_stime.tv_sec - used1.ru_stime.tv_sec) +
+               (used2.ru_utime.tv_usec - used1.ru_utime.tv_usec) * 1e-6 +
+               (used2.ru_stime.tv_usec - used1.ru_stime.tv_usec) * 1e-6);
+#else
+       if (running())
+               used2 = clock();
+       return double(used2 - used1)/CLOCKS_PER_SEC;
+#endif
 }
 
 bool timer::running()
index 2e76a6e1a6e8926095770815266d3172d96ccfe6..48e884acb521a5cb32deb0ae8259c139c8dcf48a 100644 (file)
 #ifndef TIMER_H
 #define TIMER_H
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+#ifdef HAVE_RUSAGE
 #include <sys/resource.h>
+#else
+#include <ctime>
+#endif
 
 class timer {
 public:
@@ -35,7 +42,11 @@ public:
        bool running();
 private:
        bool on;
+#ifdef HAVE_RUSAGE
        struct rusage used1, used2;
+#else
+       std::clock_t used1, used2;
+#endif
 };
 
 #endif // ndef TIMER_H
index 96230c63a33211df75cf0501ac5bc10c6e8a0665..7900873d216e6ec27d402e22ec04913acff4216a 100644 (file)
@@ -82,6 +82,7 @@ AC_LANG([C++])
 
 dnl Check for stuff needed for building the GiNaC interactive shell (ginsh).
 AC_CHECK_HEADERS(unistd.h)
+GINAC_HAVE_RUSAGE
 AC_CHECK_HEADERS(readline/readline.h readline/history.h)
 if test "x${ac_cv_header_readline_readline_h}" != "xyes" -o "x${ac_cv_header_readline_history_h}" != "xyes"; then
   GINAC_WARNING([I could not find the headers for libreadline (needed for building ginsh).])
@@ -111,6 +112,9 @@ AC_CHECK_HEADER(typeinfo, , GINAC_ERROR([The standard <typeinfo> header file cou
 AC_CHECK_HEADER(stdexcept, , GINAC_ERROR([The standard <stdexcept> header file could not be found.]))
 AC_CHECK_HEADER(algorithm, , GINAC_ERROR([The standard <algorithm> header file could not be found.]))
 AC_CHECK_HEADER(limits, , GINAC_ERROR([The standard <limits> header file could not be found.]))
+if test "x$CONFIG_RUSAGE" = "xno"; then
+    AC_CHECK_HEADER(ctime, , GINAC_ERROR([The standard <ctime> header file could not be found.]))
+fi
 
 dnl We need to have Bruno Haible's CLN installed.
 dnl (CLN versions >= 1.1.0 must have installed cln.m4 at a visible place,
index 1242d8941f3fc675939c0f42ba7aa0d4ac1a7d67..cdd5cb2a91b2c106aff3ea6139b5c496923e2c83 100644 (file)
 
 %{
 #include "config.h"
-
+#ifdef HAVE_RUSAGE
 #include <sys/resource.h>
+#else
+#include <ctime>
+#endif
 
 #if HAVE_UNISTD_H
 #include <sys/types.h>
@@ -61,7 +64,23 @@ static void push(const ex &e);
 static ex exstack[3];
 
 // Start and end time for the time() function
+#ifdef HAVE_RUSAGE
 static struct rusage start_time, end_time;
+#define START_TIMER getrusage(RUSAGE_SELF, &start_time);
+#define STOP_TIMER getrusage(RUSAGE_SELF, &end_time);
+#define PRINT_TIME_USED cout << \
+   (end_time.ru_utime.tv_sec - start_time.ru_utime.tv_sec) + \
+       (end_time.ru_stime.tv_sec - start_time.ru_stime.tv_sec) + \
+       double(end_time.ru_utime.tv_usec - start_time.ru_utime.tv_usec) / 1e6 + \
+       double(end_time.ru_stime.tv_usec - start_time.ru_stime.tv_usec) / 1e6 \
+                       << 's' << endl;
+#else
+static std::clock_t start_time, end_time;
+#define START_TIMER start_time = std::clock();
+#define STOP_TIMER end_time = std::clock();
+#define PRINT_TIME_USED \
+  cout << double(end_time - start_time)/CLOCKS_PER_SEC << 's' << endl;
+#endif
 
 // Table of functions (a multimap, because one function may appear with different
 // numbers of parameters)
@@ -210,13 +229,7 @@ line       : ';'
        }
        | T_REAL_SYMBOLS { symboltype = domain::real; }
        | T_COMPLEX_SYMBOLS { symboltype = domain::complex; }
-       | T_TIME {getrusage(RUSAGE_SELF, &start_time);} '(' exp ')' {
-               getrusage(RUSAGE_SELF, &end_time);
-               cout << (end_time.ru_utime.tv_sec - start_time.ru_utime.tv_sec) +
-                       (end_time.ru_stime.tv_sec - start_time.ru_stime.tv_sec) +
-                        double(end_time.ru_utime.tv_usec - start_time.ru_utime.tv_usec) / 1e6 +
-                        double(end_time.ru_stime.tv_usec - start_time.ru_stime.tv_usec) / 1e6 << 's' << endl;
-       }
+       | T_TIME { START_TIMER } '(' exp ')' { STOP_TIMER PRINT_TIME_USED }
        | error ';'             {yyclearin; yyerrok;}
        | error ':'             {yyclearin; yyerrok;}
        ;