69 lines
2.3 KiB
Bash
Executable File
69 lines
2.3 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
|
|
shift
|
|
echo "Building Linux release inside Ubuntu 20.04 Docker container..."
|
|
sudo docker build -t hush-builder -f Dockerfile.build .
|
|
sudo docker run --rm -v "$SCRIPT_DIR:/hush3" hush-builder "$@"
|
|
echo "Docker build complete. Release is in release-linux/"
|
|
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
|