Skip to content

Commit

Permalink
Auto merge of #4030 - str4d:freebsd-build, r=str4d
Browse files Browse the repository at this point in the history
Add FreeBSD build support

Usage on FreeBSD:

> $ pkg install autoconf automake bash cmake gcc gmake libtool pkgconf
> $ MAKE=gmake ./zcutil/build.sh

Closes #4023.
  • Loading branch information
zkbot committed Sep 12, 2019
2 parents 0650772 + ae6cee2 commit a722aa6
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 5 deletions.
2 changes: 2 additions & 0 deletions depends/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ build_vendor=$(word 2,$(subst -, ,$(build)))
full_build_os:=$(subst $(build_arch)-$(build_vendor)-,,$(build))
build_os:=$(findstring linux,$(full_build_os))
build_os+=$(findstring darwin,$(full_build_os))
build_os+=$(findstring freebsd,$(full_build_os))
build_os:=$(strip $(build_os))
ifeq ($(build_os),)
build_os=$(full_build_os)
Expand All @@ -48,6 +49,7 @@ host_vendor=$(word 2,$(subst -, ,$(canonical_host)))
full_host_os:=$(subst $(host_arch)-$(host_vendor)-,,$(canonical_host))
host_os:=$(findstring linux,$(full_host_os))
host_os+=$(findstring darwin,$(full_host_os))
host_os+=$(findstring freebsd,$(full_host_os))
host_os+=$(findstring mingw32,$(full_host_os))
host_os:=$(strip $(host_os))
ifeq ($(host_os),)
Expand Down
2 changes: 2 additions & 0 deletions depends/builders/freebsd.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build_freebsd_SHA256SUM = shasum -a 256
build_freebsd_DOWNLOAD = curl --location --fail --connect-timeout $(DOWNLOAD_CONNECT_TIMEOUT) --retry $(DOWNLOAD_RETRIES) -o
31 changes: 31 additions & 0 deletions depends/hosts/freebsd.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
freebsd_CFLAGS=-pipe
freebsd_CXXFLAGS=$(freebsd_CFLAGS)

freebsd_release_CFLAGS=-O1
freebsd_release_CXXFLAGS=$(freebsd_release_CFLAGS)

freebsd_debug_CFLAGS=-O1
freebsd_debug_CXXFLAGS=$(freebsd_debug_CFLAGS)

freebsd_debug_CPPFLAGS=-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC

ifeq (86,$(findstring 86,$(build_arch)))
i686_freebsd_CC=gcc -m32
i686_freebsd_CXX=g++ -m32
i686_freebsd_AR=ar
i686_freebsd_RANLIB=ranlib
i686_freebsd_NM=nm
i686_freebsd_STRIP=strip

x86_64_freebsd_CC=gcc -m64
x86_64_freebsd_CXX=g++ -m64
x86_64_freebsd_AR=ar
x86_64_freebsd_RANLIB=ranlib
x86_64_freebsd_NM=nm
x86_64_freebsd_STRIP=strip
else
i686_freebsd_CC=$(default_host_CC) -m32
i686_freebsd_CXX=$(default_host_CXX) -m32
x86_64_freebsd_CC=$(default_host_CC) -m64
x86_64_freebsd_CXX=$(default_host_CXX) -m64
endif
1 change: 1 addition & 0 deletions depends/packages/bdb.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ define $(package)_set_vars
$(package)_config_opts=--disable-shared --enable-cxx --disable-replication
$(package)_config_opts_mingw32=--enable-mingw
$(package)_config_opts_linux=--with-pic
$(package)_config_opts_freebsd=--with-pic
$(package)_config_opts_aarch64=--disable-atomicsupport
$(package)_cxxflags=-std=c++11
endef
Expand Down
7 changes: 4 additions & 3 deletions depends/packages/boost.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ $(package)_sha256_hash=430ae8354789de4fd19ee52f3b1f739e1fba576f0aded0897c3c2bc00
define $(package)_set_vars
$(package)_config_opts_release=variant=release
$(package)_config_opts_debug=variant=debug
$(package)_config_opts=--layout=system --user-config=user-config.jam
$(package)_config_opts=--layout=system
$(package)_config_opts+=threading=multi link=static -sNO_BZIP2=1 -sNO_ZLIB=1
$(package)_config_opts_linux=threadapi=pthread runtime-link=shared
$(package)_config_opts_darwin=--toolset=darwin-4.2.1 runtime-link=shared
Expand All @@ -22,14 +22,15 @@ $(package)_archiver_darwin=$($(package)_libtool)
$(package)_config_libraries=chrono,filesystem,program_options,system,thread,test
$(package)_cxxflags=-std=c++11 -fvisibility=hidden
$(package)_cxxflags_linux=-fPIC
$(package)_cxxflags_freebsd=-fPIC
endef

define $(package)_preprocess_cmds
echo "using $(boost_toolset_$(host_os)) : : $($(package)_cxx) : <cxxflags>\"$($(package)_cxxflags) $($(package)_cppflags)\" <linkflags>\"$($(package)_ldflags)\" <archiver>\"$(boost_archiver_$(host_os))\" <striper>\"$(host_STRIP)\" <ranlib>\"$(host_RANLIB)\" <rc>\"$(host_WINDRES)\" : ;" > user-config.jam
endef

define $(package)_config_cmds
./bootstrap.sh --without-icu --with-libraries=$(boost_config_libraries)
./bootstrap.sh --without-icu --with-toolset=$($(package)_toolset_$(host_os)) --with-libraries=$($(package)_config_libraries) && \
sed -i -e "s|using gcc ;|using $(boost_toolset_$(host_os)) : : $($(package)_cxx) : <cxxflags>\"$($(package)_cxxflags) $($(package)_cppflags)\" <linkflags>\"$($(package)_ldflags)\" <archiver>\"$(boost_archiver_$(host_os))\" <striper>\"$(host_STRIP)\" <ranlib>\"$(host_RANLIB)\" <rc>\"$(host_WINDRES)\" : ;|" project-config.jam
endef

define $(package)_build_cmds
Expand Down
1 change: 1 addition & 0 deletions depends/packages/googletest.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ $(package)_sha256_hash=58a6f4277ca2bc8565222b3bbd58a177609e9c488e8a72649359ba514
define $(package)_set_vars
$(package)_cxxflags+=-std=c++11
$(package)_cxxflags_linux=-fPIC
$(package)_cxxflags_freebsd=-fPIC
endef

define $(package)_build_cmds
Expand Down
4 changes: 4 additions & 0 deletions depends/packages/libevent.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ $(package)_download_path=https://github.com/libevent/libevent/archive/
$(package)_file_name=$(package)-$($(package)_version).tar.gz
$(package)_download_file=release-$($(package)_version)-stable.tar.gz
$(package)_sha256_hash=316ddb401745ac5d222d7c529ef1eada12f58f6376a66c1118eee803cb70f83d
$(package)_patches=detect-arch4random_addrandom.patch detect-arch4random_addrandom-fix.patch

define $(package)_preprocess_cmds
patch -p1 <$($(package)_patch_dir)/detect-arch4random_addrandom.patch && \
patch -p1 <$($(package)_patch_dir)/detect-arch4random_addrandom-fix.patch && \
./autogen.sh
endef

define $(package)_set_vars
$(package)_config_opts=--disable-shared --disable-openssl --disable-libevent-regress
$(package)_config_opts_release=--disable-debug-mode
$(package)_config_opts_linux=--with-pic
$(package)_config_opts_freebsd=--with-pic
endef

define $(package)_config_cmds
Expand Down
3 changes: 3 additions & 0 deletions depends/packages/openssl.mk
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ $(package)_config_opts+=no-zlib-dynamic
$(package)_config_opts+=$($(package)_cflags) $($(package)_cppflags)
$(package)_config_opts+=-DPURIFY
$(package)_config_opts_linux=-fPIC -Wa,--noexecstack
$(package)_config_opts_freebsd=-fPIC -Wa,--noexecstack
$(package)_config_opts_x86_64_linux=linux-x86_64
$(package)_config_opts_i686_linux=linux-generic32
$(package)_config_opts_arm_linux=linux-generic32
Expand All @@ -87,6 +88,8 @@ $(package)_config_opts_mipsel_linux=linux-generic32
$(package)_config_opts_mips_linux=linux-generic32
$(package)_config_opts_powerpc_linux=linux-generic32
$(package)_config_opts_x86_64_darwin=darwin64-x86_64-cc
$(package)_config_opts_x86_64_freebsd=BSD-x86_64
$(package)_config_opts_i686_freebsd=BSD-generic32
$(package)_config_opts_x86_64_mingw32=mingw64
$(package)_config_opts_i686_mingw32=mingw
endef
Expand Down
6 changes: 4 additions & 2 deletions depends/packages/rust.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ $(package)_file_name_linux=rust-$($(package)_version)-x86_64-unknown-linux-gnu.t
$(package)_sha256_hash_linux=e024698320d76b74daf0e6e71be3681a1e7923122e3ebd03673fcac3ecc23810
$(package)_file_name_darwin=rust-$($(package)_version)-x86_64-apple-darwin.tar.gz
$(package)_sha256_hash_darwin=f0dfba507192f9b5c330b5984ba71d57d434475f3d62bd44a39201e36fa76304
$(package)_file_name_freebsd=rust-$($(package)_version)-x86_64-unknown-freebsd.tar.gz
$(package)_sha256_hash_freebsd=20d062493d01f1816014fe9dbe883bda06f1828a6ddbfb7ee5e4f1df20eb1c3a

# Mapping from GCC canonical hosts to Rust targets
# If a mapping is not present, we assume they are identical
Expand Down Expand Up @@ -38,12 +40,12 @@ define $(package)_extract_cmds
endef

define $(package)_stage_cmds
./install.sh --destdir=$($(package)_staging_dir) --prefix=$(host_prefix)/native --disable-ldconfig && \
bash ./install.sh --destdir=$($(package)_staging_dir) --prefix=$(host_prefix)/native --disable-ldconfig && \
../$(canonical_host)/install.sh --destdir=$($(package)_staging_dir) --prefix=$(host_prefix)/native --disable-ldconfig
endef
else

define $(package)_stage_cmds
./install.sh --destdir=$($(package)_staging_dir) --prefix=$(host_prefix)/native --disable-ldconfig
bash ./install.sh --destdir=$($(package)_staging_dir) --prefix=$(host_prefix)/native --disable-ldconfig
endef
endif
1 change: 1 addition & 0 deletions depends/packages/zeromq.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ $(package)_sha256_hash=bcbabe1e2c7d0eec4ed612e10b94b112dd5f06fcefa994a0c79a45d83
define $(package)_set_vars
$(package)_config_opts=--without-documentation --disable-shared --disable-curve
$(package)_config_opts_linux=--with-pic
$(package)_config_opts_freebsd=--with-pic
$(package)_cxxflags=-std=c++11
endef

Expand Down
43 changes: 43 additions & 0 deletions depends/patches/libevent/detect-arch4random_addrandom-fix.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
From 266f43af7798befa3d27bfabaa9ae699259c3924 Mon Sep 17 00:00:00 2001
From: Azat Khuzhin <a3at.mail@gmail.com>
Date: Mon, 27 Mar 2017 15:50:23 +0300
Subject: [PATCH] Fix arc4random_addrandom() detecting and fallback
(regression)

But this is kind of hot-fix, we definitelly need more sane arc4random
compat layer.

Fixes: #488
Introduced-in: 6541168 ("Detect arch4random_addrandom() existence")
---
event-config.h.cmake | 3 +++
include/event2/util.h | 2 +-
2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/event-config.h.cmake b/event-config.h.cmake
index b7f0be57c..5c233a3d9 100644
--- a/event-config.h.cmake
+++ b/event-config.h.cmake
@@ -53,6 +53,9 @@
/* Define to 1 if you have the `arc4random_buf' function. */
#cmakedefine EVENT__HAVE_ARC4RANDOM_BUF 1

+/* Define to 1 if you have the `arc4random_addrandom' function. */
+#cmakedefine EVENT__HAVE_ARC4RANDOM_ADDRANDOM 1
+
/* Define if clock_gettime is available in libc */
#cmakedefine EVENT__DNS_USE_CPU_CLOCK_FOR_ID 1

diff --git a/include/event2/util.h b/include/event2/util.h
index c4af2bd60..ca4048944 100644
--- a/include/event2/util.h
+++ b/include/event2/util.h
@@ -842,7 +842,7 @@ int evutil_secure_rng_init(void);
EVENT2_EXPORT_SYMBOL
int evutil_secure_rng_set_urandom_device_file(char *fname);

-#ifdef EVENT__HAVE_ARC4RANDOM_ADDRANDOM
+#if !defined(EVENT__HAVE_ARC4RANDOM) || defined(EVENT__HAVE_ARC4RANDOM_ADDRANDOM)
/** Seed the random number generator with extra random bytes.

You should almost never need to call this function; it should be
77 changes: 77 additions & 0 deletions depends/patches/libevent/detect-arch4random_addrandom.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
From 6541168d7037457b8e5c51cc354f11bd94e618b6 Mon Sep 17 00:00:00 2001
From: Marek Sebera <marek.sebera@gmail.com>
Date: Mon, 6 Mar 2017 00:55:16 +0300
Subject: [PATCH] Detect arch4random_addrandom() existence

Refs: #370
Refs: #475
---
CMakeLists.txt | 1 +
configure.ac | 1 +
evutil_rand.c | 2 ++
include/event2/util.h | 2 ++
4 files changed, 6 insertions(+)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index a861e7d96..f609d02d0 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -338,6 +338,7 @@ CHECK_FUNCTION_EXISTS_EX(sysctl EVENT__HAVE_SYSCTL)
CHECK_FUNCTION_EXISTS_EX(accept4 EVENT__HAVE_ACCEPT4)
CHECK_FUNCTION_EXISTS_EX(arc4random EVENT__HAVE_ARC4RANDOM)
CHECK_FUNCTION_EXISTS_EX(arc4random_buf EVENT__HAVE_ARC4RANDOM_BUF)
+CHECK_FUNCTION_EXISTS_EX(arc4random_addrandom EVENT__HAVE_ARC4RANDOM_ADDRANDOM)
CHECK_FUNCTION_EXISTS_EX(epoll_create1 EVENT__HAVE_EPOLL_CREATE1)
CHECK_FUNCTION_EXISTS_EX(getegid EVENT__HAVE_GETEGID)
CHECK_FUNCTION_EXISTS_EX(geteuid EVENT__HAVE_GETEUID)
diff --git a/configure.ac b/configure.ac
index a127bbc91..e73c29b14 100644
--- a/configure.ac
+++ b/configure.ac
@@ -342,6 +342,7 @@ AC_CHECK_FUNCS([ \
accept4 \
arc4random \
arc4random_buf \
+ arc4random_addrandom \
eventfd \
epoll_create1 \
fcntl \
diff --git a/evutil_rand.c b/evutil_rand.c
index 046a14b07..4be0b1c5e 100644
--- a/evutil_rand.c
+++ b/evutil_rand.c
@@ -192,12 +192,14 @@ evutil_secure_rng_get_bytes(void *buf, size_t n)
ev_arc4random_buf(buf, n);
}

+#if !defined(EVENT__HAVE_ARC4RANDOM) || defined(EVENT__HAVE_ARC4RANDOM_ADDRANDOM)
void
evutil_secure_rng_add_bytes(const char *buf, size_t n)
{
arc4random_addrandom((unsigned char*)buf,
n>(size_t)INT_MAX ? INT_MAX : (int)n);
}
+#endif

void
evutil_free_secure_rng_globals_(void)
diff --git a/include/event2/util.h b/include/event2/util.h
index dd4bbb69d..c4af2bd60 100644
--- a/include/event2/util.h
+++ b/include/event2/util.h
@@ -842,6 +842,7 @@ int evutil_secure_rng_init(void);
EVENT2_EXPORT_SYMBOL
int evutil_secure_rng_set_urandom_device_file(char *fname);

+#ifdef EVENT__HAVE_ARC4RANDOM_ADDRANDOM
/** Seed the random number generator with extra random bytes.

You should almost never need to call this function; it should be
@@ -858,6 +859,7 @@ int evutil_secure_rng_set_urandom_device_file(char *fname);
*/
EVENT2_EXPORT_SYMBOL
void evutil_secure_rng_add_bytes(const char *dat, size_t datlen);
+#endif

#ifdef __cplusplus
}

0 comments on commit a722aa6

Please sign in to comment.