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).
This commit is contained in:
Mark Olesen
2018-04-09 12:48:55 +02:00
parent d2b1b1cdc0
commit 297570de53
31 changed files with 218 additions and 19 deletions

View File

@ -103,6 +103,11 @@ case Linux:
endsw endsw
breaksw 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: case SunOS:
setenv WM_ARCH SunOS64 setenv WM_ARCH SunOS64
setenv WM_MPLIB FJMPI setenv WM_MPLIB FJMPI

View File

@ -97,6 +97,11 @@ Linux)
esac esac
;; ;;
Darwin) # Presumably x86_64
: ${WM_ARCH_OPTION:=64}; export WM_ARCH_OPTION # Default to 64-bit
WM_ARCH=darwin64
;;
SunOS) SunOS)
WM_ARCH=SunOS64 WM_ARCH=SunOS64
WM_MPLIB=FJMPI WM_MPLIB=FJMPI

View File

@ -1547,6 +1547,15 @@ void* Foam::dlOpen(const fileName& lib, const bool check)
} }
void* handle = ::dlopen(lib.c_str(), RTLD_LAZY|RTLD_GLOBAL); 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) if (!handle && check)
{ {
WarningInFunction WarningInFunction
@ -1631,6 +1640,7 @@ bool Foam::dlSymFound(void* handle, const std::string& symbol)
} }
#ifndef darwin
static int collectLibsCallback static int collectLibsCallback
( (
struct dl_phdr_info *info, struct dl_phdr_info *info,
@ -1643,12 +1653,21 @@ static int collectLibsCallback
ptr->append(info->dlpi_name); ptr->append(info->dlpi_name);
return 0; return 0;
} }
#endif
Foam::fileNameList Foam::dlLoaded() Foam::fileNameList Foam::dlLoaded()
{ {
DynamicList<fileName> libs; 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); dl_iterate_phdr(collectLibsCallback, &libs);
#endif
if (POSIX::debug) if (POSIX::debug)
{ {
std::cout std::cout

View File

@ -37,6 +37,9 @@ SourceFiles
#define clockValue_H #define clockValue_H
#include <sys/types.h> #include <sys/types.h>
#ifdef darwin
#include <sys/time.h>
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -40,7 +40,9 @@ SourceFiles
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef __GNUC__ #ifdef darwin
#include <machine/endian.h>
#elif defined __GNUC__
#include <endian.h> #include <endian.h>
#elif defined __mips #elif defined __mips
#include <standards.h> #include <standards.h>

View File

@ -87,7 +87,11 @@ 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
os << "0x" << hex << uint64_t(addr);
#else
os << "0x" << hex << addr; os << "0x" << hex << addr;
#endif
return os.str(); return os.str();
} }

View File

@ -315,7 +315,11 @@ Foam::fileName Foam::dynamicCode::codeRelPath() const
Foam::fileName Foam::dynamicCode::libRelPath() const Foam::fileName Foam::dynamicCode::libRelPath() const
{ {
#ifdef darwin
return codeRelPath()/libSubDir_/"lib" + codeName_ + ".dylib";
#else
return codeRelPath()/libSubDir_/"lib" + codeName_ + ".so"; return codeRelPath()/libSubDir_/"lib" + codeName_ + ".so";
#endif
} }

View File

@ -44,7 +44,7 @@ SourceFiles
namespace Foam namespace Foam
{ {
// Forward declaration of classes // Forward declarations
class dynamicCodeContext; class dynamicCodeContext;
class ISstream; class ISstream;
class OSstream; class OSstream;
@ -92,11 +92,11 @@ private:
// Private Member Functions // Private Member Functions
//- Disallow default bitwise copy construct //- No copy construct
dynamicCode(const dynamicCode&); dynamicCode(const dynamicCode&) = delete;
//- Disallow default bitwise assignment //- No copy assignment
void operator=(const dynamicCode&); void operator=(const dynamicCode&) = delete;
protected: protected:
@ -221,7 +221,11 @@ public:
// Corresponds to codeRoot()/libSubDir()/lib\<codeName\>.so // Corresponds to codeRoot()/libSubDir()/lib\<codeName\>.so
fileName libPath() const fileName libPath() const
{ {
#ifdef darwin
return codeRoot_/libSubDir_/"lib" + codeName_ + ".dylib";
#else
return codeRoot_/libSubDir_/"lib" + codeName_ + ".so"; return codeRoot_/libSubDir_/"lib" + codeName_ + ".so";
#endif
} }
//- Path for specified code name relative to \$FOAM_CASE //- Path for specified code name relative to \$FOAM_CASE

View File

@ -166,11 +166,10 @@ transFunc(erfc)
transFunc(lgamma) transFunc(lgamma)
transFunc(tgamma) transFunc(tgamma)
transFunc(j0) besselFunc(j0)
transFunc(j1) besselFunc(j1)
besselFunc(y0)
transFunc(y0) besselFunc(y1)
transFunc(y1)
inline Scalar& setComponent(Scalar& s, const direction) inline Scalar& setComponent(Scalar& s, const direction)

View File

@ -3,7 +3,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) 2011 OpenFOAM Foundation \\ / A nd | Copyright (C) 2011 OpenFOAM Foundation
\\/ M anipulation | \\/ M anipulation | Copyright (C) 2018 OpenCFD Ltd.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
This file is part of OpenFOAM. This file is part of OpenFOAM.

View File

@ -100,6 +100,15 @@ inline Scalar func(const Scalar s) \
return ::func(s); \ return ::func(s); \
} }
// Double-precision bessel functions
#define besselFunc(func) \
inline Scalar func(const Scalar s) \
{ \
return ::func(s); \
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam } // End namespace Foam
@ -115,6 +124,7 @@ inline Scalar func(const Scalar s) \
#undef ScalarROOTVSMALL #undef ScalarROOTVSMALL
#undef ScalarRead #undef ScalarRead
#undef transFunc #undef transFunc
#undef besselFunc
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -83,6 +83,41 @@ inline Scalar atan2(const Scalar y, const Scalar x)
return ::atan2f(y, 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 Scalar(::jn(n, double(s)));
}
inline Scalar yn(const int n, const Scalar s)
{
return Scalar(::yn(n, double(s)));
}
#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) inline Scalar jn(const int n, const Scalar s)
{ {
return ::jnf(n, s); return ::jnf(n, s);
@ -93,12 +128,8 @@ inline Scalar yn(const int n, const Scalar s)
return ::ynf(n, s); return ::ynf(n, s);
} }
// Single-precision transcendental functions (with 'f' appended to the name) #endif
#define transFunc(func) \
inline Scalar func(const Scalar s) \
{ \
return ::func##f(s); \
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -115,6 +146,7 @@ inline Scalar func(const Scalar s) \
#undef ScalarROOTVSMALL #undef ScalarROOTVSMALL
#undef ScalarRead #undef ScalarRead
#undef transFunc #undef transFunc
#undef besselFunc
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View File

@ -0,0 +1,16 @@
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

View File

@ -0,0 +1,17 @@
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

View File

@ -0,0 +1,2 @@
c++DBUG = -g -DFULLDEBUG
c++OPT = -O0

View File

@ -0,0 +1,2 @@
c++DBUG =
c++OPT = -O3

View File

@ -0,0 +1,2 @@
c++DBUG = -pg
c++OPT = -O2

View File

@ -0,0 +1,2 @@
cDBUG = -g -DFULLDEBUG
cOPT = -O0

View File

@ -0,0 +1,2 @@
cDBUG =
cOPT = -O3

View File

@ -0,0 +1,2 @@
cDBUG = -pg
cOPT = -O2

View File

@ -0,0 +1,9 @@
CPP = cpp -traditional-cpp $(GFLAGS) -Ddarwin
PROJECT_LIBS = -l$(WM_PROJECT) -ldl
include $(GENERAL_RULES)/standard
include $(GENERAL_RULES)/Clang/openmp
include $(DEFAULT_RULES)/c
include $(DEFAULT_RULES)/c++

16
wmake/rules/darwin64Gcc/c Normal file
View File

@ -0,0 +1,16 @@
SUFFIXES += .c
cc = gcc -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

View File

@ -0,0 +1,17 @@
include $(GENERAL_RULES)/Gcc/c++
CC = g++ -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

View File

@ -0,0 +1,2 @@
c++DBUG = -ggdb3 -DFULLDEBUG
c++OPT = -O0 -fdefault-inline

View File

@ -0,0 +1,4 @@
c++DBUG =
c++OPT = -O3
ROUNDING_MATH = -frounding-math

View File

@ -0,0 +1,2 @@
c++DBUG = -pg
c++OPT = -O2

View File

@ -0,0 +1,2 @@
cDBUG = -ggdb -DFULLDEBUG
cOPT = -O1 -fdefault-inline -finline-functions

View File

@ -0,0 +1,2 @@
cDBUG =
cOPT = -O3

View File

@ -0,0 +1,2 @@
cDBUG = -pg
cOPT = -O2

View File

@ -0,0 +1,9 @@
CPP = cpp -traditional-cpp $(GFLAGS) -Ddarwin
PROJECT_LIBS = -l$(WM_PROJECT) -ldl
include $(GENERAL_RULES)/standard
include $(GENERAL_RULES)/Gcc/openmp
include $(DEFAULT_RULES)/c
include $(DEFAULT_RULES)/c++

View File

@ -110,7 +110,9 @@ make="make"
nCores=0 nCores=0
allCores() allCores()
{ {
nCores=$(egrep -c "^processor" /proc/cpuinfo 2>/dev/null) || nCores=1 nCores=$(egrep -c "^processor" /proc/cpuinfo 2>/dev/null) || \
nCores=$(getconf _NPROCESSORS_ONLN 2>/dev/null) || \
nCores=1
: ${nCores:=1} : ${nCores:=1}
} }