navid/veins / commit
8a4cd0cbcde1
Navid M <navidmomtahen@gmail.com> · 2026-11-27
parents: b5cb4a0403bd
Browse files at this commit · Download source
--- a/veins/build-native.sh+++ b/veins/build-native.sh@@ -9,6 +9,31 @@ crypto="src/crypto" b3="$crypto/blake3"++# Locate OpenSSL. Homebrew installs it keg-only on macOS, so neither the+# headers nor the static archives are in the default compiler search paths.+# An explicit OPENSSL_PREFIX always wins; otherwise ask brew/pkg-config.+openssl_prefix="${OPENSSL_PREFIX:-}"+if [ -z "$openssl_prefix" ] && [ "$(uname -s)" = "Darwin" ] &&+ command -v brew >/dev/null 2>&1; then+ for formula in openssl@3 openssl; do+ candidate=$(brew --prefix "$formula" 2>/dev/null || true)+ if [ -n "$candidate" ] && [ -d "$candidate/include/openssl" ]; then+ openssl_prefix=$candidate+ break+ fi+ done+fi+if [ -z "$openssl_prefix" ] && command -v pkg-config >/dev/null 2>&1; then+ candidate=$(pkg-config --variable=prefix openssl 2>/dev/null || true)+ if [ -n "$candidate" ] && [ -d "$candidate/include/openssl" ]; then+ openssl_prefix=$candidate+ fi+fi+openssl_cflags=""+if [ -n "$openssl_prefix" ] && [ -d "$openssl_prefix/include" ]; then+ openssl_cflags="-I$openssl_prefix/include"+fi # sx.mod passes the target architecture; fall back to the compiler's target so # the script also works standalone.@@ -24,7 +49,8 @@ esac "$cc" -O3 -c "$crypto/blake3_c.c" -o "$out/blake3_c.o"-"$cc" -O3 -c "$crypto/openssl_c.c" -o "$out/openssl_c.o"+# shellcheck disable=SC2086+"$cc" -O3 $openssl_cflags -c "$crypto/openssl_c.c" -o "$out/openssl_c.o" "$cc" -O3 -c "$b3/blake3.c" -o "$out/blake3_impl.o" "$cc" -O3 -c "$b3/blake3_dispatch.c" -o "$out/blake3_dispatch.o" "$cc" -O3 -c "$b3/blake3_portable.c" -o "$out/blake3_portable.o"@@ -45,8 +71,22 @@ # source is searched too early (and is dropped under --as-needed). Embed the # jitter archive into the relocatable object instead, where ordering no longer # matters.-ssl_a=$("$cc" -print-file-name=libssl.a)-crypto_a=$("$cc" -print-file-name=libcrypto.a)+ssl_a=""+crypto_a=""+if [ -n "$openssl_prefix" ]; then+ if [ -f "$openssl_prefix/lib/libssl.a" ]; then+ ssl_a="$openssl_prefix/lib/libssl.a"+ fi+ if [ -f "$openssl_prefix/lib/libcrypto.a" ]; then+ crypto_a="$openssl_prefix/lib/libcrypto.a"+ fi+fi+if [ -z "$ssl_a" ]; then+ ssl_a=$("$cc" -print-file-name=libssl.a)+fi+if [ -z "$crypto_a" ]; then+ crypto_a=$("$cc" -print-file-name=libcrypto.a)+fi jit_a=$("$cc" -print-file-name=libjitterentropy.a) if [ ! -f "$jit_a" ]; then for cand in /usr/lib/*/libjitterentropy.a /usr/lib/libjitterentropy.a \@@ -59,17 +99,24 @@ done fi if [ -f "$ssl_a" ] && [ -f "$crypto_a" ]; then- if [ -f "$jit_a" ]; then- "$cc" -r "$out/openssl_c.o" -Wl,--whole-archive \- "$ssl_a" "$crypto_a" "$jit_a" -Wl,--no-whole-archive \+ if [ "$(uname -s)" = "Darwin" ]; then+ # ld64 has no --start-group/--whole-archive. A plain relocatable link+ # pulls only the archive members needed by openssl_c.o, which keeps the+ # binary independent of the keg-only Homebrew dylibs.+ "$cc" -r "$out/openssl_c.o" "$ssl_a" "$crypto_a" \ -o "$out/openssl_embed.o" else- # Pull only the OpenSSL members that the wrapper actually needs. This- # often avoids the optional jitter seed source entirely; if it does- # not, report the dependency instead of failing later at the final- # link with an opaque symbol error.- "$cc" -r "$out/openssl_c.o" -Wl,--start-group \- "$ssl_a" "$crypto_a" -Wl,--end-group -o "$out/openssl_embed.o"+ # GNU ld: resolve the OpenSSL archive dependencies in one group. This+ # pulls only referenced members instead of every object in libcrypto.a.+ if [ -f "$jit_a" ]; then+ "$cc" -r "$out/openssl_c.o" -Wl,--start-group \+ "$ssl_a" "$crypto_a" "$jit_a" -Wl,--end-group \+ -o "$out/openssl_embed.o"+ else+ "$cc" -r "$out/openssl_c.o" -Wl,--start-group \+ "$ssl_a" "$crypto_a" -Wl,--end-group \+ -o "$out/openssl_embed.o"+ fi if command -v nm >/dev/null 2>&1 && nm -u "$out/openssl_embed.o" 2>/dev/null | grep -q 'jent_'; then echo "build-native.sh: libcrypto.a needs libjitterentropy; install libjitterentropy3-dev (Debian/Ubuntu) or libjitterentropy-devel (Fedora)" >&2@@ -78,7 +125,7 @@ fi objects="$objects $out/openssl_embed.o" else- echo "build-native.sh: OpenSSL static libraries not found; TLS will fail to link" >&2+ echo "build-native.sh: OpenSSL static libraries not found under ${openssl_prefix:-the compiler search path}; TLS will fail to link" >&2 objects="$objects $out/openssl_c.o" fi