Skip to content

Commit

Permalink
Another bunch of FreeBSD related portability fixes (#571)
Browse files Browse the repository at this point in the history
* Provide CGlobalRNG::result_type

Allows to use CGlobalRNG in std::shuffle, similar to fc61592

* Make bash shebang portable

* Make version fetch failure message more verbose

Let the package maintainer know which file is actually missing

* Implement gettid() on FreeBSD

* Fix rts/System/Platform/Misc.cpp on FreeBSD

* Make manpages optional
  • Loading branch information
AMDmi3 authored Jun 2, 2022
1 parent 60cc0c5 commit 11bdb17
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 4 deletions.
3 changes: 2 additions & 1 deletion doc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
option(ENABLE_MANPAGES "Enable manpages" TRUE)

### make and install the man pages
if (UNIX)
if (UNIX AND ENABLE_MANPAGES)
find_package(SevenZip)
set(AsciiDoc_FIND_QUIETLY TRUE)
find_package(AsciiDoc)
Expand Down
2 changes: 1 addition & 1 deletion doc/manpages/make_manpages.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

ORIG_DIR=$(pwd)

Expand Down
2 changes: 2 additions & 0 deletions rts/System/GlobalRNG.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ template<typename RNG, bool synced> class CGlobalRNG {
typedef typename RNG::val_type rng_val_type;
typedef typename RNG::res_type rng_res_type;

using result_type = rng_res_type;

static_assert(std::numeric_limits<float>::digits == 24, "sign plus mantissa bits should be 24");

void Seed(rng_val_type seed) { SetSeed(seed); }
Expand Down
8 changes: 8 additions & 0 deletions rts/System/Platform/Linux/ThreadSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#include <fstream>
#include <sys/syscall.h>

#if defined(__FreeBSD__)
#include <pthread_np.h> // for pthread_getthreadid_np
#endif

#include "System/Log/ILog.h"
#include "System/Platform/Threading.h"

Expand Down Expand Up @@ -42,7 +46,11 @@ enum LinuxThreadState {
* There is no glibc wrapper for this system call, so you have to write one:
*/
static int gettid() {
#if defined(__FreeBSD__)
return pthread_getthreadid_np();
#else
return syscall(SYS_gettid);
#endif
}

/**
Expand Down
4 changes: 3 additions & 1 deletion rts/System/Platform/Misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
#include <mach-o/dyld.h>

#elif defined( __FreeBSD__)
#include <sys/types.h>
#include <sys/sysctl.h>
#include <ifaddrs.h>

#else

Expand Down Expand Up @@ -714,7 +716,7 @@ namespace Platform
return (GetMacType(macAddr, 0), macAddr);
}

#elif defined(__APPLE__)
#elif defined(__APPLE__) || defined (__FreeBSD__)

std::array<uint8_t, 6> GetRawMacAddr() {
// TODO: http://lists.freebsd.org/pipermail/freebsd-hackers/2004-June/007415.html
Expand Down
2 changes: 1 addition & 1 deletion rts/build/cmake/UtilVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ macro (fetch_spring_version dir prefix)
# Try to fetch version through VERSION file
get_version_from_file(${prefix}_VERSION "${dir}/VERSION")
if (${${prefix}_VERSION-NOTFOUND})
message (FATAL_ERROR "Failed to fetch ${prefix} version.")
message (FATAL_ERROR "Failed to fetch ${prefix} version from ${dir}/VERSION.")
else ()
message (STATUS "${prefix} version fetched from VERSION file: ${${prefix}_VERSION}")
endif ()
Expand Down

0 comments on commit 11bdb17

Please sign in to comment.