COMP: use standard compiler macros when distinguishing the OS

- replace (darwin) with (__APPLE__)
- replace (solarisGcc) with (__sun__ && __GNUC__)
- instead of 'darwin' -> '__APPLE'

- cease with passing a -D$(WM_ARCH) define since this adds no useful
  additional information and isn't used anywhere.

Reference
http://nadeausoftware.com/articles/2012/01/c_c_tip_how_use_compiler_predefined_macros_detect_operating_system

--

COMP: Extend size disambiguation on long (#1238)
This commit is contained in:
Mark Olesen
2019-04-12 18:42:30 +02:00
committed by Andrew Heather
parent 8d827f99a9
commit 8928ac54bd
16 changed files with 64 additions and 41 deletions

View File

@ -20,7 +20,7 @@ POSIX.C
*/ */
fileMonitor.C fileMonitor.C
#ifdef SunOS64 #ifdef __sun__
dummyPrintStack.C dummyPrintStack.C
#else #else
printStack.C printStack.C

View File

@ -28,7 +28,8 @@ Description
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifdef solarisGcc #if defined(__sun__) && defined(__GNUC__)
// Not certain if this is still required
#define _SYS_VNODE_H #define _SYS_VNODE_H
#endif #endif
@ -59,7 +60,7 @@ Description
#include <netinet/in.h> #include <netinet/in.h>
#include <dlfcn.h> #include <dlfcn.h>
#ifdef darwin #ifdef __APPLE__
#include <mach-o/dyld.h> #include <mach-o/dyld.h>
#else #else
@ -1660,7 +1661,7 @@ void* Foam::dlOpen(const fileName& libName, const bool check)
} }
void* handle = ::dlopen(libName.c_str(), RTLD_LAZY|RTLD_GLOBAL); void* handle = ::dlopen(libName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
#ifdef darwin #ifdef __APPLE__
// Re-try "libXX.so" as "libXX.dylib" // Re-try "libXX.so" as "libXX.dylib"
if (!handle && libName.hasExt("so")) if (!handle && libName.hasExt("so"))
{ {
@ -1753,7 +1754,7 @@ bool Foam::dlSymFound(void* handle, const std::string& symbol)
} }
#ifndef darwin #ifndef __APPLE__
static int collectLibsCallback static int collectLibsCallback
( (
struct dl_phdr_info *info, struct dl_phdr_info *info,
@ -1772,7 +1773,7 @@ static int collectLibsCallback
Foam::fileNameList Foam::dlLoaded() Foam::fileNameList Foam::dlLoaded()
{ {
DynamicList<fileName> libs; DynamicList<fileName> libs;
#ifdef darwin #ifdef __APPLE__
for (uint32_t i=0; i < _dyld_image_count(); ++i) for (uint32_t i=0; i < _dyld_image_count(); ++i)
{ {
libs.append(_dyld_get_image_name(i)); libs.append(_dyld_get_image_name(i));

View File

@ -30,7 +30,7 @@ License
#include "timer.H" #include "timer.H"
#include <unistd.h> #include <unistd.h>
#ifndef darwin #ifndef __APPLE__
#include <sys/sysmacros.h> #include <sys/sysmacros.h>
#endif #endif
@ -115,7 +115,7 @@ double Foam::fileStat::dmodTime() const
( (
isValid_ isValid_
? ?
#ifdef darwin #ifdef __APPLE__
(status_.st_mtime + 1e-9*status_.st_mtimespec.tv_nsec) (status_.st_mtime + 1e-9*status_.st_mtimespec.tv_nsec)
#else #else
(status_.st_mtime + 1e-9*status_.st_mtim.tv_nsec) (status_.st_mtime + 1e-9*status_.st_mtim.tv_nsec)

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -89,7 +89,7 @@ string pOpen(const string& cmd, label line=0)
inline word addressToWord(const uintptr_t addr) inline word addressToWord(const uintptr_t addr)
{ {
OStringStream os; OStringStream os;
#ifdef darwin #ifdef __APPLE__
os << "0x" << hex << uint64_t(addr); os << "0x" << hex << uint64_t(addr);
#else #else
os << "0x" << hex << addr; os << "0x" << hex << addr;
@ -121,7 +121,7 @@ void printSourceFileAndLine
// Darwin addr2line implementation. // Darwin addr2line implementation.
// On other systems (Linux), only use relative addresses for libraries. // On other systems (Linux), only use relative addresses for libraries.
#ifndef darwin #ifndef __APPLE__
if (filename.hasExt("so")) if (filename.hasExt("so"))
#endif #endif
{ {

View File

@ -20,8 +20,8 @@
#ifndef feexceptErsatz_H #ifndef feexceptErsatz_H
#define feexceptErsatz_H #define feexceptErsatz_H
#ifdef darwin
#ifdef __APPLE__
#include <fenv.h> #include <fenv.h>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -68,7 +68,7 @@ inline int fedisableexcept(unsigned int excepts)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif // darwin #endif // __APPLE__
#endif #endif
// ************************************************************************* // // ************************************************************************* //

View File

@ -43,7 +43,7 @@ License
#include <malloc.h> #include <malloc.h>
#endif #endif
#ifdef darwin #ifdef __APPLE__
#include "feexceptErsatz.H" #include "feexceptErsatz.H"
#endif #endif
@ -121,7 +121,7 @@ void* Foam::sigFpe::mallocNan(size_t size)
void Foam::sigFpe::sigHandler(int) void Foam::sigFpe::sigHandler(int)
{ {
#if (defined(__linux__) && defined(__GNUC__)) || defined(darwin) #if (defined(__linux__) && defined(__GNUC__)) || defined(__APPLE__)
resetHandler("SIGFPE", SIGFPE); resetHandler("SIGFPE", SIGFPE);
@ -129,7 +129,7 @@ void Foam::sigFpe::sigHandler(int)
error::printStack(Perr); error::printStack(Perr);
::raise(SIGFPE); // Throw signal (to old handler) ::raise(SIGFPE); // Throw signal (to old handler)
#endif // (__linux__ && __GNUC__) || darwin #endif // (__linux__ && __GNUC__) || __APPLE__
} }
@ -188,7 +188,7 @@ void Foam::sigFpe::set(bool verbose)
{ {
if (!sigActive_ && requested()) if (!sigActive_ && requested())
{ {
#if (defined(__linux__) && defined(__GNUC__)) || defined(darwin) #if (defined(__linux__) && defined(__GNUC__)) || defined(__APPLE__)
feenableexcept feenableexcept
( (
@ -244,7 +244,7 @@ void Foam::sigFpe::set(bool verbose)
void Foam::sigFpe::unset(bool verbose) void Foam::sigFpe::unset(bool verbose)
{ {
#if (defined(__linux__) && defined(__GNUC__)) || defined(darwin) #if (defined(__linux__) && defined(__GNUC__)) || defined(__APPLE__)
if (sigActive_) if (sigActive_)
{ {
if (verbose) if (verbose)

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011-2016 OpenFOAM Foundation | Copyright (C) 2011-2016 OpenFOAM Foundation
@ -319,7 +319,7 @@ Foam::fileName Foam::dynamicCode::codeRelPath() const
Foam::fileName Foam::dynamicCode::libRelPath() const Foam::fileName Foam::dynamicCode::libRelPath() const
{ {
#ifdef darwin #ifdef __APPLE__
return codeRelPath()/libSubDir_/"lib" + codeName_ + ".dylib"; return codeRelPath()/libSubDir_/"lib" + codeName_ + ".dylib";
#else #else
return codeRelPath()/libSubDir_/"lib" + codeName_ + ".so"; return codeRelPath()/libSubDir_/"lib" + codeName_ + ".so";

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2011 OpenFOAM Foundation | Copyright (C) 2011 OpenFOAM Foundation
@ -223,7 +223,7 @@ public:
// Corresponds to codeRoot()/libSubDir()/lib\<codeName\>.so // Corresponds to codeRoot()/libSubDir()/lib\<codeName\>.so
fileName libPath() const fileName libPath() const
{ {
#ifdef darwin #ifdef __APPLE__
return codeRoot_/libSubDir_/"lib" + codeName_ + ".dylib"; return codeRoot_/libSubDir_/"lib" + codeName_ + ".dylib";
#else #else
return codeRoot_/libSubDir_/"lib" + codeName_ + ".so"; return codeRoot_/libSubDir_/"lib" + codeName_ + ".so";

View File

@ -109,6 +109,18 @@ inline Scalar func(const Scalar s) \
std::cerr<< "No '" << #func << "' function\n"; \ std::cerr<< "No '" << #func << "' function\n"; \
return 0; \ return 0; \
} }
#elif defined(__MINGW32__)
// Mingw: with '_' prefix
#define besselFunc(func) \
inline Scalar func(const Scalar s) \
{ \
return _##func(s); \
}
#define besselFunc2(func) \
inline Scalar func(const int n, const Scalar s) \
{ \
return _##func(n, s); \
}
#else #else
#define besselFunc(func) \ #define besselFunc(func) \
inline Scalar func(const Scalar s) \ inline Scalar func(const Scalar s) \
@ -122,6 +134,7 @@ inline Scalar func(const Scalar s) \
} }
#endif #endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam

View File

@ -109,8 +109,8 @@ inline Scalar func(const Scalar s) \
std::cerr<< "No '" << #func << "' function\n"; \ std::cerr<< "No '" << #func << "' function\n"; \
return 0; \ return 0; \
} }
#elif defined(darwin) #elif defined(__APPLE__)
// No float version for darwin - use a cast. // Darwin: no float version (use a cast)
#define besselFunc(func) \ #define besselFunc(func) \
inline Scalar func(const Scalar s) \ inline Scalar func(const Scalar s) \
{ \ { \
@ -121,7 +121,18 @@ inline Scalar func(const Scalar s) \
{ \ { \
return Scalar(::func(n, double(s))); \ return Scalar(::func(n, double(s))); \
} }
#elif defined(__MINGW32__)
// Mingw: with '_' prefix, no float version (use a cast)
#define besselFunc(func) \
inline Scalar func(const Scalar s) \
{ \
return _##func(s); \
}
#define besselFunc2(func) \
inline Scalar func(const int n, const Scalar s) \
{ \
return Scalar(_##func(n, double(s))); \
}
#else #else
// With 'f' (float) appended to the name // With 'f' (float) appended to the name
#define besselFunc(func) \ #define besselFunc(func) \

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2014-2016 OpenFOAM Foundation | Copyright (C) 2014-2016 OpenFOAM Foundation
@ -46,7 +46,6 @@ SourceFiles
#include "pTraits.H" #include "pTraits.H"
#include "direction.H" #include "direction.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam namespace Foam
@ -120,9 +119,10 @@ inline bool read(const std::string& str, int64_t& val)
Istream& operator>>(Istream& is, int64_t& val); Istream& operator>>(Istream& is, int64_t& val);
Ostream& operator<<(Ostream& os, const int64_t val); Ostream& operator<<(Ostream& os, const int64_t val);
// On Darwin: long is not unambiguously (int32_t | int64_t) // On Darwin and Windows (mingw):
// long is not unambiguously (int32_t | int64_t)
// - explicitly resolve for input and output // - explicitly resolve for input and output
#ifdef darwin #if defined(__APPLE__) || defined(_WIN32)
Istream& operator>>(Istream& is, long& val); Istream& operator>>(Istream& is, long& val);
Ostream& operator<<(Ostream& os, const long val); Ostream& operator<<(Ostream& os, const long val);
#endif #endif

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2014-2016 OpenFOAM Foundation | Copyright (C) 2014-2016 OpenFOAM Foundation
@ -125,7 +125,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const int64_t val)
} }
#ifdef darwin #if defined(__APPLE__) || defined(_WIN32)
Foam::Istream& Foam::operator>>(Istream& is, long& val) Foam::Istream& Foam::operator>>(Istream& is, long& val)
{ {
return operator>>(is, reinterpret_cast<int64_t&>(val)); return operator>>(is, reinterpret_cast<int64_t&>(val));

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2014-2016 OpenFOAM Foundation | Copyright (C) 2014-2016 OpenFOAM Foundation
@ -119,9 +119,10 @@ inline bool read(const std::string& str, uint64_t& val)
Istream& operator>>(Istream& is, uint64_t& val); Istream& operator>>(Istream& is, uint64_t& val);
Ostream& operator<<(Ostream& os, const uint64_t val); Ostream& operator<<(Ostream& os, const uint64_t val);
// On Darwin: unsigned long is not unambiguously (uint32_t | uint64_t) // On Darwin:
// unsigned long is not unambiguously (uint32_t | uint64_t)
// - explicitly resolve for output // - explicitly resolve for output
#ifdef darwin #ifdef __APPLE__
Ostream& operator<<(Ostream& os, const unsigned long val); Ostream& operator<<(Ostream& os, const unsigned long val);
#endif #endif

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2017-2018 OpenCFD Ltd. \\ / A nd | Copyright (C) 2017-2019 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
| Copyright (C) 2014-2016 OpenFOAM Foundation | Copyright (C) 2014-2016 OpenFOAM Foundation
@ -124,7 +124,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const uint64_t val)
} }
#ifdef darwin #ifdef __APPLE__
Foam::Ostream& Foam::operator<<(Ostream& os, const unsigned long val) Foam::Ostream& Foam::operator<<(Ostream& os, const unsigned long val)
{ {
os << uint64_t(val); os << uint64_t(val);

View File

@ -7,7 +7,7 @@ RANLIB = ranlib
CPP = cpp CPP = cpp
LD = ld LD = ld
GFLAGS = -D$(WM_VERSION) -D$(WM_ARCH) -DWM_ARCH_OPTION=$(WM_ARCH_OPTION) \ GFLAGS = -D$(WM_VERSION) -DWM_ARCH_OPTION=$(WM_ARCH_OPTION) \
-DWM_$(WM_PRECISION_OPTION) -DWM_LABEL_SIZE=$(WM_LABEL_SIZE) -DWM_$(WM_PRECISION_OPTION) -DWM_LABEL_SIZE=$(WM_LABEL_SIZE)
GINC = GINC =
GLIBS = -lm GLIBS = -lm

View File

@ -1,4 +1,4 @@
CPP = cpp -traditional-cpp $(GFLAGS) -Ddarwin CPP = cpp -traditional-cpp $(GFLAGS)
PROJECT_LIBS = -l$(WM_PROJECT) -ldl PROJECT_LIBS = -l$(WM_PROJECT) -ldl
@ -11,7 +11,4 @@ include $(DEFAULT_RULES)/c++
# Shared library extension (with '.' separator) # Shared library extension (with '.' separator)
EXT_SO = .dylib EXT_SO = .dylib
# Define general os-type
GFLAGS += -Ddarwin
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------