From d189d95d46c576c7541d36a7eec026a2cbbaf85a Mon Sep 17 00:00:00 2001 From: Chris Dams Date: Mon, 31 Jul 2006 16:46:27 +0000 Subject: [PATCH] Patch from Alexei to make it possible to compile on MinGW. --- acinclude.m4 | 25 +++++++++++++++++++++++ check/Makefile.am | 1 + check/exam_archive.cpp | 4 ++-- check/run_checks | 2 +- check/run_exams | 2 +- check/run_times | 2 +- check/timer.cpp | 45 ++++++++++++++++++++++++++++++++++-------- check/timer.h | 11 +++++++++++ configure.ac | 4 ++++ ginsh/ginsh_parser.yy | 29 +++++++++++++++++++-------- 10 files changed, 104 insertions(+), 21 deletions(-) diff --git a/acinclude.m4 b/acinclude.m4 index 09d71cb3..4ab13878 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -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 ], +ac_cv_have_rusage, + [AC_TRY_COMPILE([#include + #include ], + [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 ]) +fi +AC_SUBST(CONFIG_RUSAGE) +]) diff --git a/check/Makefile.am b/check/Makefile.am index 48e7a999..b7c9d0fb 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -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 diff --git a/check/exam_archive.cpp b/check/exam_archive.cpp index 303192d0..e2e62615 100644 --- a/check/exam_archive.cpp +++ b/check/exam_archive.cpp @@ -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"); diff --git a/check/run_checks b/check/run_checks index 6304d18f..93b77065 100755 --- a/check/run_checks +++ b/check/run_checks @@ -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 diff --git a/check/run_exams b/check/run_exams index 8c8efa59..1e7ba463 100755 --- a/check/run_exams +++ b/check/run_exams @@ -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 diff --git a/check/run_times b/check/run_times index 3687f1ef..eb2380bd 100755 --- a/check/run_times +++ b/check/run_times @@ -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 diff --git a/check/timer.cpp b/check/timer.cpp index 0b978a7d..1ac07c9d 100644 --- a/check/timer.cpp +++ b/check/timer.cpp @@ -20,51 +20,80 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#ifdef HAVE_RUSAGE #include #include +#include +#else +#include +#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() diff --git a/check/timer.h b/check/timer.h index 2e76a6e1..48e884ac 100644 --- a/check/timer.h +++ b/check/timer.h @@ -23,7 +23,14 @@ #ifndef TIMER_H #define TIMER_H +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +#ifdef HAVE_RUSAGE #include +#else +#include +#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 diff --git a/configure.ac b/configure.ac index 96230c63..7900873d 100644 --- a/configure.ac +++ b/configure.ac @@ -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 header file cou AC_CHECK_HEADER(stdexcept, , GINAC_ERROR([The standard header file could not be found.])) AC_CHECK_HEADER(algorithm, , GINAC_ERROR([The standard header file could not be found.])) AC_CHECK_HEADER(limits, , GINAC_ERROR([The standard header file could not be found.])) +if test "x$CONFIG_RUSAGE" = "xno"; then + AC_CHECK_HEADER(ctime, , GINAC_ERROR([The standard 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, diff --git a/ginsh/ginsh_parser.yy b/ginsh/ginsh_parser.yy index 1242d894..cdd5cb2a 100644 --- a/ginsh/ginsh_parser.yy +++ b/ginsh/ginsh_parser.yy @@ -28,8 +28,11 @@ %{ #include "config.h" - +#ifdef HAVE_RUSAGE #include +#else +#include +#endif #if HAVE_UNISTD_H #include @@ -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;} ; -- 2.47.0