From 40426850a309657f6535f107c302d45d47b6425b Mon Sep 17 00:00:00 2001
From: Mark Olesen <Mark.Olesen@esi-group.com>
Date: Fri, 12 Apr 2019 18:42:30 +0200
Subject: [PATCH] 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)
---
 src/OSspecific/POSIX/Make/files                 |  2 +-
 src/OSspecific/POSIX/POSIX.C                    | 11 ++++++-----
 src/OSspecific/POSIX/fileStat.C                 |  4 ++--
 src/OSspecific/POSIX/printStack.C               |  6 +++---
 src/OSspecific/POSIX/signals/feexceptErsatz.H   |  4 ++--
 src/OSspecific/POSIX/signals/sigFpe.C           | 10 +++++-----
 .../db/dynamicLibrary/dynamicCode/dynamicCode.C |  4 ++--
 .../db/dynamicLibrary/dynamicCode/dynamicCode.H |  4 ++--
 .../Scalar/doubleScalar/doubleScalar.H          | 13 +++++++++++++
 .../primitives/Scalar/floatScalar/floatScalar.H | 17 ++++++++++++++---
 src/OpenFOAM/primitives/ints/int64/int64.H      |  8 ++++----
 src/OpenFOAM/primitives/ints/int64/int64IO.C    |  4 ++--
 src/OpenFOAM/primitives/ints/uint64/uint64.H    |  7 ++++---
 src/OpenFOAM/primitives/ints/uint64/uint64IO.C  |  4 ++--
 wmake/rules/General/general                     |  2 +-
 wmake/rules/darwin64Clang/general               |  5 +----
 16 files changed, 64 insertions(+), 41 deletions(-)

diff --git a/src/OSspecific/POSIX/Make/files b/src/OSspecific/POSIX/Make/files
index 44ba1ec1bf..ce684dc46b 100644
--- a/src/OSspecific/POSIX/Make/files
+++ b/src/OSspecific/POSIX/Make/files
@@ -20,7 +20,7 @@ POSIX.C
  */
 fileMonitor.C
 
-#ifdef SunOS64
+#ifdef __sun__
 dummyPrintStack.C
 #else
 printStack.C
diff --git a/src/OSspecific/POSIX/POSIX.C b/src/OSspecific/POSIX/POSIX.C
index 811eafe7e5..33d9a61679 100644
--- a/src/OSspecific/POSIX/POSIX.C
+++ b/src/OSspecific/POSIX/POSIX.C
@@ -28,7 +28,8 @@ Description
 
 \*---------------------------------------------------------------------------*/
 
-#ifdef solarisGcc
+#if defined(__sun__) && defined(__GNUC__)
+    // Not certain if this is still required
     #define _SYS_VNODE_H
 #endif
 
@@ -59,7 +60,7 @@ Description
 #include <netinet/in.h>
 #include <dlfcn.h>
 
-#ifdef darwin
+#ifdef __APPLE__
     #include <mach-o/dyld.h>
 #else
 
@@ -1660,7 +1661,7 @@ void* Foam::dlOpen(const fileName& libName, const bool check)
     }
     void* handle = ::dlopen(libName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
 
-    #ifdef darwin
+    #ifdef __APPLE__
     // Re-try "libXX.so" as "libXX.dylib"
     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
 (
     struct dl_phdr_info *info,
@@ -1772,7 +1773,7 @@ static int collectLibsCallback
 Foam::fileNameList Foam::dlLoaded()
 {
     DynamicList<fileName> libs;
-    #ifdef darwin
+    #ifdef __APPLE__
     for (uint32_t i=0; i < _dyld_image_count(); ++i)
     {
        libs.append(_dyld_get_image_name(i));
diff --git a/src/OSspecific/POSIX/fileStat.C b/src/OSspecific/POSIX/fileStat.C
index c3a118ba5b..4337d1dac4 100644
--- a/src/OSspecific/POSIX/fileStat.C
+++ b/src/OSspecific/POSIX/fileStat.C
@@ -30,7 +30,7 @@ License
 #include "timer.H"
 
 #include <unistd.h>
-#ifndef darwin
+#ifndef __APPLE__
     #include <sys/sysmacros.h>
 #endif
 
@@ -115,7 +115,7 @@ double Foam::fileStat::dmodTime() const
     (
         valid_
       ?
-        #ifdef darwin
+        #ifdef __APPLE__
         (status_.st_mtime + 1e-9*status_.st_mtimespec.tv_nsec)
         #else
         (status_.st_mtime + 1e-9*status_.st_mtim.tv_nsec)
diff --git a/src/OSspecific/POSIX/printStack.C b/src/OSspecific/POSIX/printStack.C
index 48850442ee..a6dea3d621 100644
--- a/src/OSspecific/POSIX/printStack.C
+++ b/src/OSspecific/POSIX/printStack.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2004-2010 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2004-2010, 2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | 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)
 {
     OStringStream os;
-    #ifdef darwin
+    #ifdef __APPLE__
     os << "0x" << hex << uint64_t(addr);
     #else
     os << "0x" << hex << addr;
@@ -121,7 +121,7 @@ void printSourceFileAndLine
     // Darwin addr2line implementation.
     // On other systems (Linux), only use relative addresses for libraries.
 
-    #ifndef darwin
+    #ifndef __APPLE__
     if (filename.hasExt("so"))
     #endif
     {
diff --git a/src/OSspecific/POSIX/signals/feexceptErsatz.H b/src/OSspecific/POSIX/signals/feexceptErsatz.H
index 1b866242f2..ee6548b773 100644
--- a/src/OSspecific/POSIX/signals/feexceptErsatz.H
+++ b/src/OSspecific/POSIX/signals/feexceptErsatz.H
@@ -20,8 +20,8 @@
 
 #ifndef feexceptErsatz_H
 #define feexceptErsatz_H
-#ifdef darwin
 
+#ifdef __APPLE__
 #include <fenv.h>
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -68,7 +68,7 @@ inline int fedisableexcept(unsigned int excepts)
 
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
-#endif  // darwin
+#endif  // __APPLE__
 #endif
 
 // ************************************************************************* //
diff --git a/src/OSspecific/POSIX/signals/sigFpe.C b/src/OSspecific/POSIX/signals/sigFpe.C
index 048805307e..c2c54d65ab 100644
--- a/src/OSspecific/POSIX/signals/sigFpe.C
+++ b/src/OSspecific/POSIX/signals/sigFpe.C
@@ -43,7 +43,7 @@ License
     #include <malloc.h>
 #endif
 
-#ifdef darwin
+#ifdef __APPLE__
     #include "feexceptErsatz.H"
 #endif
 
@@ -121,7 +121,7 @@ void* Foam::sigFpe::mallocNan(size_t size)
 
 void Foam::sigFpe::sigHandler(int)
 {
-    #if (defined(__linux__) && defined(__GNUC__)) || defined(darwin)
+    #if (defined(__linux__) && defined(__GNUC__)) || defined(__APPLE__)
 
     resetHandler("SIGFPE", SIGFPE);
 
@@ -129,7 +129,7 @@ void Foam::sigFpe::sigHandler(int)
     error::printStack(Perr);
     ::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 (defined(__linux__) && defined(__GNUC__)) || defined(darwin)
+        #if (defined(__linux__) && defined(__GNUC__)) || defined(__APPLE__)
 
         feenableexcept
         (
@@ -244,7 +244,7 @@ void Foam::sigFpe::set(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 (verbose)
diff --git a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C
index c8e4ceaa31..7e63d8d298 100644
--- a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C
+++ b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2011, 2016-2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2011-2011, 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011-2016 OpenFOAM Foundation
@@ -319,7 +319,7 @@ Foam::fileName Foam::dynamicCode::codeRelPath() const
 
 Foam::fileName Foam::dynamicCode::libRelPath() const
 {
-    #ifdef darwin
+    #ifdef __APPLE__
     return codeRelPath()/libSubDir_/"lib" + codeName_ + ".dylib";
     #else
     return codeRelPath()/libSubDir_/"lib" + codeName_ + ".so";
diff --git a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.H b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.H
index ded00d6562..4ed7ffaf3c 100644
--- a/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.H
+++ b/src/OpenFOAM/db/dynamicLibrary/dynamicCode/dynamicCode.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2011-2011 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2011, 2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2011 OpenFOAM Foundation
@@ -223,7 +223,7 @@ public:
         //  Corresponds to codeRoot()/libSubDir()/lib\<codeName\>.so
         fileName libPath() const
         {
-            #ifdef darwin
+            #ifdef __APPLE__
             return codeRoot_/libSubDir_/"lib" + codeName_ + ".dylib";
             #else
             return codeRoot_/libSubDir_/"lib" + codeName_ + ".so";
diff --git a/src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.H b/src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.H
index dca0fc152d..bc90a1c7df 100644
--- a/src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.H
+++ b/src/OpenFOAM/primitives/Scalar/doubleScalar/doubleScalar.H
@@ -109,6 +109,18 @@ inline Scalar func(const Scalar s)                              \
         std::cerr<< "No '" << #func << "' function\n";          \
         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
     #define besselFunc(func)                                    \
     inline Scalar func(const Scalar s)                          \
@@ -122,6 +134,7 @@ inline Scalar func(const Scalar s)                              \
     }
 #endif
 
+
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 } // End namespace Foam
diff --git a/src/OpenFOAM/primitives/Scalar/floatScalar/floatScalar.H b/src/OpenFOAM/primitives/Scalar/floatScalar/floatScalar.H
index 0304106021..5e09ae9516 100644
--- a/src/OpenFOAM/primitives/Scalar/floatScalar/floatScalar.H
+++ b/src/OpenFOAM/primitives/Scalar/floatScalar/floatScalar.H
@@ -109,8 +109,8 @@ inline Scalar func(const Scalar s)                              \
         std::cerr<< "No '" << #func << "' function\n";          \
         return 0;                                               \
     }
-#elif defined(darwin)
-    // No float version for darwin - use a cast.
+#elif defined(__APPLE__)
+    // Darwin: no float version (use a cast)
     #define besselFunc(func)                                    \
     inline Scalar func(const Scalar s)                          \
     {                                                           \
@@ -121,7 +121,18 @@ inline Scalar func(const Scalar 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
     // With 'f' (float) appended to the name
     #define besselFunc(func)                                    \
diff --git a/src/OpenFOAM/primitives/ints/int64/int64.H b/src/OpenFOAM/primitives/ints/int64/int64.H
index 4027f86328..b0e075b634 100644
--- a/src/OpenFOAM/primitives/ints/int64/int64.H
+++ b/src/OpenFOAM/primitives/ints/int64/int64.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2016-2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | Copyright (C) 2014-2016 OpenFOAM Foundation
@@ -46,7 +46,6 @@ SourceFiles
 #include "pTraits.H"
 #include "direction.H"
 
-
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
 
 namespace Foam
@@ -120,9 +119,10 @@ inline bool read(const std::string& str, int64_t& val)
 Istream& operator>>(Istream& is, 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
-#ifdef darwin
+#if defined(__APPLE__) || defined(_WIN32)
     Istream& operator>>(Istream& is, long& val);
     Ostream& operator<<(Ostream& os, const long val);
 #endif
diff --git a/src/OpenFOAM/primitives/ints/int64/int64IO.C b/src/OpenFOAM/primitives/ints/int64/int64IO.C
index 47e7a97ab6..add4abb455 100644
--- a/src/OpenFOAM/primitives/ints/int64/int64IO.C
+++ b/src/OpenFOAM/primitives/ints/int64/int64IO.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2017-2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2017-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | 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)
 {
     return operator>>(is, reinterpret_cast<int64_t&>(val));
diff --git a/src/OpenFOAM/primitives/ints/uint64/uint64.H b/src/OpenFOAM/primitives/ints/uint64/uint64.H
index 694e9f1158..7b2da34766 100644
--- a/src/OpenFOAM/primitives/ints/uint64/uint64.H
+++ b/src/OpenFOAM/primitives/ints/uint64/uint64.H
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2016-2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2016-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | 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);
 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
-#ifdef darwin
+#ifdef __APPLE__
     Ostream& operator<<(Ostream& os, const unsigned long val);
 #endif
 
diff --git a/src/OpenFOAM/primitives/ints/uint64/uint64IO.C b/src/OpenFOAM/primitives/ints/uint64/uint64IO.C
index e6e8369025..38b4e0c9db 100644
--- a/src/OpenFOAM/primitives/ints/uint64/uint64IO.C
+++ b/src/OpenFOAM/primitives/ints/uint64/uint64IO.C
@@ -2,7 +2,7 @@
   =========                 |
   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
    \\    /   O peration     |
-    \\  /    A nd           | Copyright (C) 2017-2018 OpenCFD Ltd.
+    \\  /    A nd           | Copyright (C) 2017-2019 OpenCFD Ltd.
      \\/     M anipulation  |
 -------------------------------------------------------------------------------
                             | 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)
 {
     os << uint64_t(val);
diff --git a/wmake/rules/General/general b/wmake/rules/General/general
index ec52419e9d..4eb70d6c45 100644
--- a/wmake/rules/General/general
+++ b/wmake/rules/General/general
@@ -7,7 +7,7 @@ RANLIB     = ranlib
 CPP        = cpp
 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)
 GINC       =
 GLIBS      = -lm
diff --git a/wmake/rules/darwin64Clang/general b/wmake/rules/darwin64Clang/general
index 37bf4f300e..1409ef1e6e 100644
--- a/wmake/rules/darwin64Clang/general
+++ b/wmake/rules/darwin64Clang/general
@@ -1,4 +1,4 @@
-CPP        = cpp -traditional-cpp $(GFLAGS) -Ddarwin
+CPP        = cpp -traditional-cpp $(GFLAGS)
 
 PROJECT_LIBS = -l$(WM_PROJECT) -ldl
 
@@ -11,7 +11,4 @@ include $(DEFAULT_RULES)/c++
 # Shared library extension (with '.' separator)
 EXT_SO  = .dylib
 
-# Define general os-type
-GFLAGS  += -Ddarwin
-
 # -----------------------------------------------------------------------------
-- 
GitLab