Commit 8928ac54 authored by Mark Olesen's avatar Mark Olesen Committed by Andrew Heather
Browse files

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)
parent 8d827f99
......@@ -20,7 +20,7 @@ POSIX.C
*/
fileMonitor.C
#ifdef SunOS64
#ifdef __sun__
dummyPrintStack.C
#else
printStack.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));
......
......@@ -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
(
isValid_
?
#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)
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 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
{
......
......@@ -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
// ************************************************************************* //
......@@ -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)
......
......@@ -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) 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";
......
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd |
\\ / A nd | Copyright (C) 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";
......
......@@ -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
......
......@@ -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) \
......
......@@ -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
......
......@@ -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));
......
......@@ -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
......
......@@ -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);
......
......@@ -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
......
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
# -----------------------------------------------------------------------------
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment