Files
hush3/build.sh
2026-02-25 13:33:52 -06:00

85 lines
2.8 KiB
Bash
Executable File

#!/usr/bin/env bash
# Copyright (c) 2016-2024 The Hush developers
# Distributed under the GPLv3 software license, see the accompanying
# file COPYING or https://www.gnu.org/licenses/gpl-3.0.en.html
set -eu -o pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_TARGET_FILE="$SCRIPT_DIR/src/.build_target"
# Function to check and clean if target changed
check_and_clean_target() {
local new_target="$1"
local current_target=""
if [[ -f "$BUILD_TARGET_FILE" ]]; then
current_target=$(cat "$BUILD_TARGET_FILE")
fi
if [[ -n "$current_target" && "$current_target" != "$new_target" ]]; then
echo "Build target changed from '$current_target' to '$new_target'"
echo "Cleaning old build artifacts to prevent cross-compilation contamination..."
cd "$SCRIPT_DIR"
make distclean 2>/dev/null || true
# Clean leveldb separately as it often causes issues
if [[ -d src/leveldb ]]; then
make -C src/leveldb clean 2>/dev/null || true
fi
echo "Clean complete."
fi
# Record the new target
echo "$new_target" > "$BUILD_TARGET_FILE"
}
# Check for --win-release flag for cross-compilation
if [[ "${1:-}" == "--win-release" ]]; then
check_and_clean_target "windows"
shift
./util/build-win.sh "$@"
exit $?
fi
# Check for --linux-release flag (builds inside Ubuntu 20.04 container for max compatibility)
if [[ "${1:-}" == "--linux-release" ]]; then
check_and_clean_target "linux-docker"
shift
echo "Building Linux release inside Ubuntu 20.04 Docker container..."
sudo docker build -t hush-builder -f Dockerfile.build .
sudo docker run --rm -e HOST_UID=$(id -u) -e HOST_GID=$(id -g) -v "$SCRIPT_DIR:/hush3" hush-builder "$@"
echo "Docker build complete. Release is in release-linux/"
exit $?
fi
# Check for --mac-release flag for macOS release build (must be run on macOS)
if [[ "${1:-}" == "--mac-release" ]]; then
check_and_clean_target "macos-release"
shift
if [[ "$OSTYPE" != "darwin"* ]]; then
echo "ERROR: --mac-release must be run on a native macOS system."
echo " Copy this repo to a Mac and run: ./build.sh --mac-release $*"
exit 1
fi
echo "Building macOS release natively..."
./util/build-mac.sh "$@"
echo "macOS release build complete."
exit $?
fi
# run correct build script for detected OS
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
check_and_clean_target "linux"
./util/build.sh --disable-tests "$@"
elif [[ "$OSTYPE" == "darwin"* ]]; then
check_and_clean_target "macos"
./util/build-mac.sh --disable-tests "$@"
elif [[ "$OSTYPE" == "msys"* ]]; then
check_and_clean_target "windows"
./util/build-win.sh --disable-tests "$@"
#elif [[ "$OSTYPE" == "freebsd"* ]]; then
# placeholder
else
echo "Unable to detect your OS. What are you using?"
fi