From 75f715bfe47f835639d811971515cc289f284ec0 Mon Sep 17 00:00:00 2001 From: Peter Surda Date: Sat, 18 Feb 2017 17:20:09 +0100 Subject: [PATCH] BSD compatibility - separate Makefile for BSD make - auto-compile will detect BSD and pass the correct parameters to make - C PoW builds on OpenBSD and detects number of cores --- src/bitmsghash/Makefile.bsd | 14 ++++++++++++++ src/bitmsghash/bitmsghash.cpp | 10 ++++++++++ src/proofofwork.py | 7 ++++++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/bitmsghash/Makefile.bsd diff --git a/src/bitmsghash/Makefile.bsd b/src/bitmsghash/Makefile.bsd new file mode 100644 index 00000000..6e680c86 --- /dev/null +++ b/src/bitmsghash/Makefile.bsd @@ -0,0 +1,14 @@ +all: bitmsghash.so + +powtest: + ./testpow.py + +bitmsghash.so: bitmsghash.o + ${CXX} bitmsghash.o -shared -fPIC -lpthread -lcrypto $(LDFLAGS) -o bitmsghash.so + +bitmsghash.o: + ${CXX} -Wall -O3 -march=native -fPIC $(CCFLAGS) -c bitmsghash.cpp + +clean: + rm -f bitmsghash.o bitmsghash.so + diff --git a/src/bitmsghash/bitmsghash.cpp b/src/bitmsghash/bitmsghash.cpp index f4979702..3c06b218 100644 --- a/src/bitmsghash/bitmsghash.cpp +++ b/src/bitmsghash/bitmsghash.cpp @@ -75,6 +75,10 @@ void getnumthreads() DWORD_PTR dwProcessAffinity, dwSystemAffinity; #elif __linux__ cpu_set_t dwProcessAffinity; +#elif __OpenBSD__ + int mib[2], core_count = 0; + int dwProcessAffinity = 0; + size_t len2; #else int dwProcessAffinity = 0; int32_t core_count = 0; @@ -86,6 +90,12 @@ void getnumthreads() GetProcessAffinityMask(GetCurrentProcess(), &dwProcessAffinity, &dwSystemAffinity); #elif __linux__ sched_getaffinity(0, len, &dwProcessAffinity); +#elif __OpenBSD__ + len2 = sizeof(core_count); + mib[0] = CTL_HW; + mib[1] = HW_NCPU; + if (sysctl(mib, 2, &core_count, &len2, 0, 0) == 0) + numthreads = core_count; #else if (sysctlbyname("hw.logicalcpu", &core_count, &len, 0, 0) == 0) numthreads = core_count; diff --git a/src/proofofwork.py b/src/proofofwork.py index 6ad790c0..dfae42fe 100644 --- a/src/proofofwork.py +++ b/src/proofofwork.py @@ -174,7 +174,12 @@ def buildCPoW(): notifyBuild(False) return try: - call(["make", "-C", os.path.join(paths.codePath(), "bitmsghash")]) + if "bsd" in sys.platform: + # BSD make + call(["make", "-C", os.path.join(paths.codePath(), "bitmsghash"), '-f', 'Makefile.bsd']) + else: + # GNU make + call(["make", "-C", os.path.join(paths.codePath(), "bitmsghash")]) if os.path.exists(os.path.join(paths.codePath(), "bitmsghash", "bitmsghash.so")): init() notifyBuild(True)