Commit 297570de authored by Mark Olesen's avatar Mark Olesen
Browse files

COMP: some low-level darwin-related patches

- a partial selection from https://github.com/mrklein/openfoam-os-x
  with adjustments. The primary purpose is to reduce header-level
  incompatibilities and to provide a common set of make rules to allow
  easier patching (or re-integration).
parent d2b1b1cd
......@@ -103,6 +103,11 @@ case Linux:
endsw
breaksw
case Darwin: # Presumably x86_64
if (! $?WM_ARCH_OPTION ) setenv WM_ARCH_OPTION 64 # Default to 64-bit
setenv WM_ARCH darwin64
breaksw
case SunOS:
setenv WM_ARCH SunOS64
setenv WM_MPLIB FJMPI
......
......@@ -97,6 +97,11 @@ Linux)
esac
;;
Darwin) # Presumably x86_64
: ${WM_ARCH_OPTION:=64}; export WM_ARCH_OPTION # Default to 64-bit
WM_ARCH=darwin64
;;
SunOS)
WM_ARCH=SunOS64
WM_MPLIB=FJMPI
......
......@@ -1547,6 +1547,15 @@ void* Foam::dlOpen(const fileName& lib, const bool check)
}
void* handle = ::dlopen(lib.c_str(), RTLD_LAZY|RTLD_GLOBAL);
#ifdef darwin
// Re-try "libXX.so" as "libXX.dylib"
if (!handle && lib.hasExt("so"))
{
const fileName dylib(lib.lessExt().ext("dylib"));
handle = ::dlopen(dylib.c_str(), RTLD_LAZY|RTLD_GLOBAL);
}
#endif
if (!handle && check)
{
WarningInFunction
......@@ -1631,6 +1640,7 @@ bool Foam::dlSymFound(void* handle, const std::string& symbol)
}
#ifndef darwin
static int collectLibsCallback
(
struct dl_phdr_info *info,
......@@ -1643,12 +1653,21 @@ static int collectLibsCallback
ptr->append(info->dlpi_name);
return 0;
}
#endif
Foam::fileNameList Foam::dlLoaded()
{
DynamicList<fileName> libs;
#ifdef darwin
for (uint32_t i=0; i < _dyld_image_count(); ++i)
{
libs.append(_dyld_get_image_name(i));
}
#else
dl_iterate_phdr(collectLibsCallback, &libs);
#endif
if (POSIX::debug)
{
std::cout
......
......@@ -37,6 +37,9 @@ SourceFiles
#define clockValue_H
#include <sys/types.h>
#ifdef darwin
#include <sys/time.h>
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -40,7 +40,9 @@ SourceFiles
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef __GNUC__
#ifdef darwin
#include <machine/endian.h>
#elif defined __GNUC__
#include <endian.h>
#elif defined __mips
#include <standards.h>
......
......@@ -87,7 +87,11 @@ string pOpen(const string& cmd, label line=0)
inline word addressToWord(const uintptr_t addr)
{
OStringStream os;
#ifdef darwin
os << "0x" << hex << uint64_t(addr);
#else
os << "0x" << hex << addr;
#endif
return os.str();
}
......
......@@ -315,7 +315,11 @@ Foam::fileName Foam::dynamicCode::codeRelPath() const
Foam::fileName Foam::dynamicCode::libRelPath() const
{
#ifdef darwin
return codeRelPath()/libSubDir_/"lib" + codeName_ + ".dylib";
#else
return codeRelPath()/libSubDir_/"lib" + codeName_ + ".so";
#endif
}
......
......@@ -44,7 +44,7 @@ SourceFiles
namespace Foam
{
// Forward declaration of classes
// Forward declarations
class dynamicCodeContext;
class ISstream;
class OSstream;
......@@ -92,11 +92,11 @@ private:
// Private Member Functions
//- Disallow default bitwise copy construct
dynamicCode(const dynamicCode&);
//- No copy construct
dynamicCode(const dynamicCode&) = delete;
//- Disallow default bitwise assignment
void operator=(const dynamicCode&);
//- No copy assignment
void operator=(const dynamicCode&) = delete;
protected:
......@@ -221,7 +221,11 @@ public:
// Corresponds to codeRoot()/libSubDir()/lib\<codeName\>.so
fileName libPath() const
{
#ifdef darwin
return codeRoot_/libSubDir_/"lib" + codeName_ + ".dylib";
#else
return codeRoot_/libSubDir_/"lib" + codeName_ + ".so";
#endif
}
//- Path for specified code name relative to \$FOAM_CASE
......
......@@ -166,11 +166,10 @@ transFunc(erfc)
transFunc(lgamma)
transFunc(tgamma)
transFunc(j0)
transFunc(j1)
transFunc(y0)
transFunc(y1)
besselFunc(j0)
besselFunc(j1)
besselFunc(y0)
besselFunc(y1)
inline Scalar& setComponent(Scalar& s, const direction)
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......
......@@ -100,6 +100,15 @@ inline Scalar func(const Scalar s) \
return ::func(s); \
}
// Double-precision bessel functions
#define besselFunc(func) \
inline Scalar func(const Scalar s) \
{ \
return ::func(s); \
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
......@@ -115,6 +124,7 @@ inline Scalar func(const Scalar s) \
#undef ScalarROOTVSMALL
#undef ScalarRead
#undef transFunc
#undef besselFunc
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
......@@ -83,23 +83,54 @@ inline Scalar atan2(const Scalar y, const Scalar x)
return ::atan2f(y, x);
}
// Single-precision transcendental functions (with 'f' appended to the name)
#define transFunc(func) \
inline Scalar func(const Scalar s) \
{ \
return ::func##f(s); \
}
#ifdef darwin
// Single-precision bessel functions. (No float version for darwin).
#define besselFunc(func) \
inline Scalar func(const Scalar s) \
{ \
return ::func(s); \
}
inline Scalar jn(const int n, const Scalar s)
{
return ::jnf(n, s);
return Scalar(::jn(n, double(s)));
}
inline Scalar yn(const int n, const Scalar s)
{
return ::ynf(n, s);
return Scalar(::yn(n, double(s)));
}
// Single-precision transcendental functions (with 'f' appended to the name)
#define transFunc(func) \
#else
// Single-precision bessel functions (with 'f' appended to the name)
#define besselFunc(func) \
inline Scalar func(const Scalar s) \
{ \
return ::func##f(s); \
}
inline Scalar jn(const int n, const Scalar s)
{
return ::jnf(n, s);
}
inline Scalar yn(const int n, const Scalar s)
{
return ::ynf(n, s);
}
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
......@@ -115,6 +146,7 @@ inline Scalar func(const Scalar s) \
#undef ScalarROOTVSMALL
#undef ScalarRead
#undef transFunc
#undef besselFunc
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
SUFFIXES += .c
cc = clang -m64 -Ddarwin
cWARN = -Wall
include $(DEFAULT_RULES)/c$(WM_COMPILE_OPTION)
cFLAGS = $(GFLAGS) $(cWARN) $(cOPT) $(cDBUG) $(LIB_HEADER_DIRS) -fPIC
ctoo = $(WM_SCHEDULER) $(cc) $(cFLAGS) -c $< -o $@
LINK_LIBS = $(cDBUG)
LINKLIBSO = $(cc) -Wl,-dylib,-undefined,dynamic_lookup
LINKEXE = $(cc) -Wl,-execute,-undefined,dynamic_lookup
include $(GENERAL_RULES)/Clang/c++
CC = clang++ -std=c++11 -m64 -Ddarwin
include $(DEFAULT_RULES)/c++$(WM_COMPILE_OPTION)
c++FLAGS = $(GFLAGS) $(c++WARN) $(c++OPT) $(c++DBUG) $(ptFLAGS) $(LIB_HEADER_DIRS) -fPIC
Ctoo = $(WM_SCHEDULER) $(CC) $(c++FLAGS) -c $< -o $@
cxxtoo = $(Ctoo)
cctoo = $(Ctoo)
cpptoo = $(Ctoo)
LINK_LIBS = $(c++DBUG)
LINKLIBSO = $(CC) $(c++FLAGS) -Wl,-dylib,-undefined,dynamic_lookup
LINKEXE = $(CC) $(c++FLAGS) -Wl,-execute,-undefined,dynamic_lookup
c++DBUG = -g -DFULLDEBUG
c++OPT = -O0
c++DBUG = -pg
c++OPT = -O2
cDBUG = -g -DFULLDEBUG
cOPT = -O0
cDBUG = -pg
cOPT = -O2
Markdown is supported
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