From d3c09984d0d831983fd2102e22a84f1922cc9e6b Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Thu, 19 Jan 2012 20:30:26 +0000 Subject: [PATCH] Fixed some preprocessor directives for MinGW The purpose of these changes is to make the distinction between compiling under Windows (in which case _WIN32 is defined) and compiling with the Microsoft compiler (in which case _MSC_VER is defined). These changes are from the patch submitted by David Fronczek. --- Cantera/clib/src/clib_defs.h | 3 +-- Cantera/clib/src/ct.cpp | 4 ++-- Cantera/cxx/demos/rankine/rankine.cpp | 7 ------- Cantera/cxx/include/Cantera.h | 5 ----- Cantera/fortran/src/flib_defs.h | 2 +- Cantera/src/base/checkFinite.cpp | 6 +++--- Cantera/src/base/config.h.in | 4 ---- Cantera/src/base/ct2ctml.cpp | 8 ++++---- Cantera/src/base/misc.cpp | 15 +++++++++------ Cantera/src/base/stringUtils.cpp | 2 +- SConstruct | 4 ---- ext/cvode/include/cvode.h | 3 --- ext/f2c_libs/dtime_.c | 2 +- ext/f2c_libs/etime_.c | 2 +- ext/f2c_libs/fio.h | 4 +++- ext/f2c_libs/lread.c | 2 +- ext/f2c_libs/rsne.c | 2 +- ext/f2c_libs/s_paus.c | 6 ++++-- tools/testtools/tok_input_util.cpp | 4 ++-- 19 files changed, 34 insertions(+), 51 deletions(-) diff --git a/Cantera/clib/src/clib_defs.h b/Cantera/clib/src/clib_defs.h index ddd54c88f..f8a2d9b9d 100755 --- a/Cantera/clib/src/clib_defs.h +++ b/Cantera/clib/src/clib_defs.h @@ -6,7 +6,7 @@ #include "kernel/ct_defs.h" -#ifdef WIN32 +#ifdef _WIN32 // Either build as a DLL under Windows or not. // the decision relies upon whether the NO_DLL_BUILD define is // set or not. @@ -17,7 +17,6 @@ #define DLL_IMPORT __declspec(dllimport) #define DLL_EXPORT __declspec(dllexport) #endif - #else // On other platforms, we turn off the DLL macros. #define DLL_EXPORT diff --git a/Cantera/clib/src/ct.cpp b/Cantera/clib/src/ct.cpp index 4575f3553..2a0320196 100755 --- a/Cantera/clib/src/ct.cpp +++ b/Cantera/clib/src/ct.cpp @@ -28,7 +28,7 @@ using namespace std; using namespace Cantera; -#ifdef WIN32 +#ifdef _WIN32 #include "windows.h" #endif @@ -97,7 +97,7 @@ namespace Cantera { */ extern "C" { -#ifdef WIN32 +#ifdef _WIN32 #ifndef NO_DLL_BUILD /* * The microsoft docs says we may need this in some diff --git a/Cantera/cxx/demos/rankine/rankine.cpp b/Cantera/cxx/demos/rankine/rankine.cpp index 91f2f059d..13fd0c51b 100644 --- a/Cantera/cxx/demos/rankine/rankine.cpp +++ b/Cantera/cxx/demos/rankine/rankine.cpp @@ -74,13 +74,6 @@ int openRankine(int np, void* p) { double efficiency = work/heat_in; cout << "efficiency = " << efficiency << endl; -#ifdef WIN32 -#ifndef CXX_DEMO - cout << "press any key to end" << endl; - char ch; - cin >> ch; -#endif -#endif return 0; } diff --git a/Cantera/cxx/include/Cantera.h b/Cantera/cxx/include/Cantera.h index 33249dd2e..30fe8901b 100755 --- a/Cantera/cxx/include/Cantera.h +++ b/Cantera/cxx/include/Cantera.h @@ -8,11 +8,6 @@ #ifndef CANTERA_H_INCL #define CANTERA_H_INCL -// definitions -#ifndef CANTERA_APP -#define CANTERA_APP -#endif - namespace Cantera_CXX{ } using namespace Cantera_CXX; diff --git a/Cantera/fortran/src/flib_defs.h b/Cantera/fortran/src/flib_defs.h index b3a9455c1..5ece2576a 100644 --- a/Cantera/fortran/src/flib_defs.h +++ b/Cantera/fortran/src/flib_defs.h @@ -2,7 +2,7 @@ #define FCTC_DEFS_H // Build as a DLL under Windows -#ifdef WIN32 +#ifdef _WIN32 #define DLL_IMPORT __declspec(dllimport) #define DLL_EXPORT __declspec(dllexport) #else diff --git a/Cantera/src/base/checkFinite.cpp b/Cantera/src/base/checkFinite.cpp index 8747268e1..06715fa19 100644 --- a/Cantera/src/base/checkFinite.cpp +++ b/Cantera/src/base/checkFinite.cpp @@ -27,7 +27,7 @@ #include #endif -#ifdef WIN32 +#ifdef _WIN32 #include #endif @@ -39,7 +39,7 @@ namespace mdp { /* * @param tmp number to be checked */ -#ifdef WIN32 +#ifdef _WIN32 void checkFinite(const double tmp) { if (_finite(tmp)) { if(_isnan(tmp)) { @@ -108,7 +108,7 @@ namespace mdp { * * @param tmp number to be checked */ -#ifdef WIN32 +#ifdef _WIN32 void checkZeroFinite(const double tmp) { if ((tmp == 0.0) || (! _finite(tmp))) { if (tmp == 0.0) { diff --git a/Cantera/src/base/config.h.in b/Cantera/src/base/config.h.in index 248f8ec2d..919ac2c2c 100644 --- a/Cantera/src/base/config.h.in +++ b/Cantera/src/base/config.h.in @@ -86,10 +86,6 @@ typedef int ftnlen; // Fortran hidden string length type // microsoft vc++ being used as the compiler %(WINMSVC)s -// Despite the name, this variable is expected to be defined -// on both 32 and 64 bit Windows -%(WIN32)s - // Identify whether the operating system is solaris // with a native compiler %(SOLARIS)s diff --git a/Cantera/src/base/ct2ctml.cpp b/Cantera/src/base/ct2ctml.cpp index c132fde26..7710a1067 100644 --- a/Cantera/src/base/ct2ctml.cpp +++ b/Cantera/src/base/ct2ctml.cpp @@ -19,7 +19,7 @@ // These defines are needed for the windows Sleep() function // - comment them out if you don't want the Sleep function. -//#ifdef WIN32 +//#ifdef _WIN32 //#include "Windows.h" //#include "Winbase.h" //#endif @@ -114,7 +114,7 @@ namespace ctml { << "write()\n"; f.close(); string logfile = tmpDir()+"/ct2ctml.log"; -#ifdef WIN32 +#ifdef _WIN32 string cmd = pypath() + " " + "\"" + path + "\"" + "> " + logfile + " 2>&1"; #else string cmd = "sleep " + sleep() + "; " + "\"" + pypath() + "\"" + @@ -156,7 +156,7 @@ namespace ctml { * It probably has to do with NFS syncing problems. * 3/3/06 */ -#ifndef WIN32 +#ifndef _WIN32 string sss = sleep(); if (debug > 0) { writelog("sleeping for " + sss + " secs+\n"); @@ -209,7 +209,7 @@ namespace ctml { // if the conversion succeeded and DEBUG_PATHS is not defined, // then clean up by deleting the temporary Python file. #ifndef DEBUG_PATHS - //#ifdef WIN32 + //#ifdef _WIN32 //cmd = "cmd /C rm " + path; if (debug == 0) remove(path.c_str()); diff --git a/Cantera/src/base/misc.cpp b/Cantera/src/base/misc.cpp index 0634d511b..fb84a504c 100644 --- a/Cantera/src/base/misc.cpp +++ b/Cantera/src/base/misc.cpp @@ -26,11 +26,14 @@ #include #include -#ifdef WIN32 +#ifdef _WIN32 #include #include #include #include +#endif + +#ifdef _MSC_VER #pragma comment(lib, "advapi32") #endif @@ -757,7 +760,7 @@ namespace Cantera { * @param msg c++ string to be written to the screen * @ingroup textlogs */ -#ifdef WIN32 +#ifdef _WIN32 long int readStringRegistryKey(const std::string& keyName, const std::string& valueName, std::string& value, const std::string& defaultValue); #endif @@ -1027,7 +1030,7 @@ protected: // file is not found. But I (dgg) don't think it makes much sense, // so it is replaced by: path = findInputFile(file); -#ifdef WIN32 +#ifdef _WIN32 // RFB: For Windows make the path POSIX compliant so code looking for directory // separators is simpler. Just look for '/' not both '/' and '\\' replace_if( path.begin(), path.end(), bind2nd( equal_to(), '\\'), '/' ) ; @@ -1145,7 +1148,7 @@ protected: } } -#ifdef WIN32 +#ifdef _WIN32 long int Application::readStringRegistryKey(const std::string& keyName, const std::string& valueName, std::string& value, const std::string& defaultValue) { @@ -1359,7 +1362,7 @@ protected: dirs.push_back("."); -#ifdef WIN32 +#ifdef _WIN32 // Under Windows, the Cantera setup utility records the installation // directory in the registry. Data files are stored in the 'data' and // 'templates' subdirectories of the main installation directory. @@ -1618,7 +1621,7 @@ protected: va_start( args, fmt ) ; -#if defined(WIN32) && defined(MSC_VER) +#ifdef _MSC_VER _vsnprintf( sbuf, BUFSIZE, fmt, args ) ; #else vsprintf( sbuf, fmt, args ) ; diff --git a/Cantera/src/base/stringUtils.cpp b/Cantera/src/base/stringUtils.cpp index 9cffd410a..0ec63e8ca 100644 --- a/Cantera/src/base/stringUtils.cpp +++ b/Cantera/src/base/stringUtils.cpp @@ -8,7 +8,7 @@ //@{ #include "ct_defs.h" -#ifdef WIN32 +#ifdef _MSC_VER #define SNPRINTF _snprintf #else #define SNPRINTF snprintf diff --git a/SConstruct b/SConstruct index df5e9b022..0b8a5e1a7 100644 --- a/SConstruct +++ b/SConstruct @@ -549,14 +549,11 @@ elif env['F90'] == 'ifort': env['FORTRANMODDIR'] = '${TARGET.dir}' if env['CC'] == 'cl': - env['WIN32'] = True # embed manifest file env['LINKCOM'] = [env['LINKCOM'], 'if exist ${TARGET}.manifest mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;1'] env['SHLINKCOM'] = [env['SHLINKCOM'], 'if exist ${TARGET}.manifest mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;2'] -else: - env['WIN32'] = False if env['boost_inc_dir']: env.Append(CPPPATH=env['boost_inc_dir']) @@ -739,7 +736,6 @@ def cdefine(definevar, configvar, comp=True, value=1): configh[definevar] = None cdefine('DEBUG_MODE', 'debug') -cdefine('WIN32', 'WIN32') # Need to test all of these to see what platform.system() returns configh['SOLARIS'] = 1 if env['OS'] == 'Solaris' else None diff --git a/ext/cvode/include/cvode.h b/ext/cvode/include/cvode.h index 95ea01747..7c5500161 100755 --- a/ext/cvode/include/cvode.h +++ b/ext/cvode/include/cvode.h @@ -16,10 +16,7 @@ extern "C" { #ifndef _cvode_h #define _cvode_h -#ifdef WIN32 #include -#endif - #include #include "llnltyps.h" #include "nvector.h" diff --git a/ext/f2c_libs/dtime_.c b/ext/f2c_libs/dtime_.c index f7694247b..ccf681e0a 100644 --- a/ext/f2c_libs/dtime_.c +++ b/ext/f2c_libs/dtime_.c @@ -1,6 +1,6 @@ #include "time.h" -#ifdef MSDOS +#if defined(MSDOS) || defined (__MINGW32__) #undef USE_CLOCK #define USE_CLOCK #endif diff --git a/ext/f2c_libs/etime_.c b/ext/f2c_libs/etime_.c index 3602e3ded..6f559a686 100644 --- a/ext/f2c_libs/etime_.c +++ b/ext/f2c_libs/etime_.c @@ -1,6 +1,6 @@ #include "time.h" -#ifdef MSDOS +#if defined(MSDOS) || defined (__MINGW32__) #undef USE_CLOCK #define USE_CLOCK #endif diff --git a/ext/f2c_libs/fio.h b/ext/f2c_libs/fio.h index 4595187af..e7c18bffc 100644 --- a/ext/f2c_libs/fio.h +++ b/ext/f2c_libs/fio.h @@ -108,12 +108,14 @@ extern void f_init(void); extern int (*f__donewrec)(void), t_putc(int), x_wSL(void); extern void b_char(char*,char*,ftnlen), g_char(char*,ftnlen,char*); extern int c_sfe(cilist*), z_rnew(void); +#ifndef _WIN32 +extern int isatty(int); +#endif #ifdef _MSC_VER #define ISATTY _isatty #define FILENO _fileno #define ACCESS _access #else -extern int isatty(int); #define ISATTY isatty #define FILENO fileno #define ACCESS access diff --git a/ext/f2c_libs/lread.c b/ext/f2c_libs/lread.c index abd5a9cce..0e317dd69 100644 --- a/ext/f2c_libs/lread.c +++ b/ext/f2c_libs/lread.c @@ -75,7 +75,7 @@ un_getc(int x, FILE *f__cf) #ifdef KR_headers extern int ungetc(); #else -#ifndef _MSC_VER +#ifndef _WIN32 extern int ungetc(int, FILE*); /* for systems with a buggy stdio.h */ #endif #endif diff --git a/ext/f2c_libs/rsne.c b/ext/f2c_libs/rsne.c index 190f6c461..9dc18846e 100644 --- a/ext/f2c_libs/rsne.c +++ b/ext/f2c_libs/rsne.c @@ -66,7 +66,7 @@ un_getc(int x, FILE *f__cf) { return ungetc(x,f__cf); } #else #define un_getc ungetc -#ifndef _MSC_VER +#ifndef _WIN32 extern int ungetc(int, FILE*); /* for systems with a buggy stdio.h */ #endif #endif diff --git a/ext/f2c_libs/s_paus.c b/ext/f2c_libs/s_paus.c index 426b2c62a..c2217b7b2 100644 --- a/ext/f2c_libs/s_paus.c +++ b/ext/f2c_libs/s_paus.c @@ -19,12 +19,14 @@ extern "C" { #ifdef __cplusplus extern "C" { #endif -extern int getpid(void); +extern int getpid(void); +#ifndef _WIN32 +extern int isatty(int); +#endif #ifdef _MSC_VER #define ISATTY _isatty #define FILENO _fileno #else -extern int isatty(int); #define ISATTY isatty #define FILENO fileno #endif diff --git a/tools/testtools/tok_input_util.cpp b/tools/testtools/tok_input_util.cpp index 9c358165b..c1c6d83ce 100644 --- a/tools/testtools/tok_input_util.cpp +++ b/tools/testtools/tok_input_util.cpp @@ -1526,13 +1526,13 @@ void strip_item_from_token(int iword, TOKEN *tok) { if (!tok) return; if (iword < 0 || iword > tok->ntokes) return; -#ifdef WIN32 +#ifdef _MSC_VER __w64 int ioffset = tok->tok_ptr[iword] - tok->tok_str; #else size_t ioffset = tok->tok_ptr[iword] - tok->tok_str; #endif size_t ilength = strlen(tok->tok_ptr[iword]); -#ifdef WIN32 +#ifdef _MSC_VER __w64 int i = ioffset; __w64 int j = ioffset + ilength; #else