265 lines
7.0 KiB
Bash
Executable File
265 lines
7.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# sovereign_browser - Build Script
|
|
# Builds the WebKitGTK + C99 browser for the current (or specified) architecture.
|
|
#
|
|
# This mirrors the workflow from nostr_core_lib/build.sh: colored output,
|
|
# architecture auto-detection, verbose mode, and a clean help screen. The
|
|
# actual compilation is delegated to the Makefile, which uses pkg-config
|
|
# for WebKitGTK 4.1.
|
|
|
|
set -e # Exit on error
|
|
|
|
# Color constants
|
|
RED='\033[31m'
|
|
GREEN='\033[32m'
|
|
YELLOW='\033[33m'
|
|
BLUE='\033[34m'
|
|
BOLD='\033[1m'
|
|
RESET='\033[0m'
|
|
|
|
# Detect if we should use colors (terminal output and not piped)
|
|
USE_COLORS=true
|
|
if [ ! -t 1 ] || [ "$NO_COLOR" = "1" ]; then
|
|
USE_COLORS=false
|
|
fi
|
|
|
|
# Function to print output with colors
|
|
print_info() {
|
|
if [ "$USE_COLORS" = true ]; then
|
|
echo -e "${BLUE}[INFO]${RESET} $1"
|
|
else
|
|
echo "[INFO] $1"
|
|
fi
|
|
}
|
|
|
|
print_success() {
|
|
if [ "$USE_COLORS" = true ]; then
|
|
echo -e "${GREEN}${BOLD}[SUCCESS]${RESET} $1"
|
|
else
|
|
echo "[SUCCESS] $1"
|
|
fi
|
|
}
|
|
|
|
print_warning() {
|
|
if [ "$USE_COLORS" = true ]; then
|
|
echo -e "${YELLOW}[WARNING]${RESET} $1"
|
|
else
|
|
echo "[WARNING] $1"
|
|
fi
|
|
}
|
|
|
|
print_error() {
|
|
if [ "$USE_COLORS" = true ]; then
|
|
echo -e "${RED}${BOLD}[ERROR]${RESET} $1"
|
|
else
|
|
echo "[ERROR] $1"
|
|
fi
|
|
}
|
|
|
|
# Default values
|
|
ARCHITECTURE=""
|
|
VERBOSE=false
|
|
HELP=false
|
|
RUN_AFTER=false
|
|
NO_COLOR_FLAG=false
|
|
|
|
# Parse command line arguments
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
x64|x86_64|amd64)
|
|
ARCHITECTURE="x64"
|
|
shift
|
|
;;
|
|
arm64|aarch64)
|
|
ARCHITECTURE="arm64"
|
|
shift
|
|
;;
|
|
--verbose|-v)
|
|
VERBOSE=true
|
|
shift
|
|
;;
|
|
--run|-r)
|
|
RUN_AFTER=true
|
|
shift
|
|
;;
|
|
--no-color)
|
|
NO_COLOR_FLAG=true
|
|
shift
|
|
;;
|
|
--help|-h)
|
|
HELP=true
|
|
shift
|
|
;;
|
|
*)
|
|
print_error "Unknown argument: $1"
|
|
HELP=true
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
# Apply no-color flag
|
|
if [ "$NO_COLOR_FLAG" = true ]; then
|
|
USE_COLORS=false
|
|
fi
|
|
|
|
# Show help
|
|
if [ "$HELP" = true ]; then
|
|
echo "sovereign_browser - Build Script"
|
|
echo ""
|
|
echo "Usage: $0 [architecture] [options]"
|
|
echo ""
|
|
echo "Architectures:"
|
|
echo " x64, x86_64, amd64 Build for x86-64 architecture (native)"
|
|
echo " arm64, aarch64 Build for ARM64 architecture (cross-compile)"
|
|
echo " (default) Build for current architecture"
|
|
echo ""
|
|
echo "Options:"
|
|
echo " --run, -r Run the browser after a successful build"
|
|
echo " --verbose, -v Verbose output (pass V=1 to make)"
|
|
echo " --no-color Disable colored output"
|
|
echo " --help, -h Show this help"
|
|
echo ""
|
|
echo "Requirements:"
|
|
echo " Debian 13 (trixie) or similar with WebKitGTK 4.1 dev headers:"
|
|
echo " sudo apt install libwebkit2gtk-4.1-dev"
|
|
echo ""
|
|
echo "Examples:"
|
|
echo " $0 # Build for current architecture"
|
|
echo " $0 x64 # Build for x64"
|
|
echo " $0 -r # Build and run"
|
|
echo " $0 arm64 -v # Cross-compile for ARM64, verbose"
|
|
exit 0
|
|
fi
|
|
|
|
print_info "sovereign_browser - Build Script"
|
|
|
|
# Check if we're running from the correct directory
|
|
CURRENT_DIR=$(basename "$(pwd)")
|
|
if [ "$CURRENT_DIR" != "sovereign_browser" ]; then
|
|
print_error "Build script must be run from the sovereign_browser directory"
|
|
echo ""
|
|
echo "Current directory: $CURRENT_DIR"
|
|
echo "Expected directory: sovereign_browser"
|
|
echo ""
|
|
echo "Please change to the sovereign_browser directory first, then run the build script."
|
|
echo ""
|
|
echo "Correct usage:"
|
|
echo " cd sovereign_browser"
|
|
echo " ./build.sh"
|
|
echo ""
|
|
exit 1
|
|
fi
|
|
|
|
# Check that the source tree is present
|
|
if [ ! -f "src/main.c" ] || [ ! -f "Makefile" ]; then
|
|
print_error "src/main.c or Makefile not found in the current directory"
|
|
echo ""
|
|
echo "This script must be run from the root of the sovereign_browser project."
|
|
exit 1
|
|
fi
|
|
|
|
###########################################################################################
|
|
############ AUTODETECT SYSTEM ARCHITECTURE
|
|
###########################################################################################
|
|
|
|
# Determine architecture
|
|
if [ -z "$ARCHITECTURE" ]; then
|
|
ARCH=$(uname -m)
|
|
case $ARCH in
|
|
x86_64|amd64)
|
|
ARCHITECTURE="x64"
|
|
;;
|
|
aarch64|arm64)
|
|
ARCHITECTURE="arm64"
|
|
;;
|
|
*)
|
|
ARCHITECTURE="x64" # Default fallback
|
|
print_warning "Unknown architecture '$ARCH', defaulting to x64"
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
print_info "Target architecture: $ARCHITECTURE"
|
|
|
|
# Set compiler based on architecture
|
|
case $ARCHITECTURE in
|
|
x64)
|
|
export CC="gcc"
|
|
;;
|
|
arm64)
|
|
export CC="aarch64-linux-gnu-gcc"
|
|
;;
|
|
*)
|
|
print_error "Unsupported architecture: $ARCHITECTURE"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
# Check if compiler exists
|
|
if ! command -v $CC &> /dev/null; then
|
|
print_error "Compiler $CC not found"
|
|
if [ "$ARCHITECTURE" = "arm64" ]; then
|
|
print_info "Install ARM64 cross-compiler: sudo apt install gcc-aarch64-linux-gnu"
|
|
fi
|
|
exit 1
|
|
fi
|
|
|
|
###########################################################################################
|
|
############ CHECK DEPENDENCIES
|
|
###########################################################################################
|
|
|
|
print_info "Checking dependencies..."
|
|
|
|
# WebKitGTK 4.1 is the hard requirement.
|
|
if ! command -v pkg-config &> /dev/null; then
|
|
print_error "pkg-config not found"
|
|
print_info "Install with: sudo apt install pkg-config"
|
|
exit 1
|
|
fi
|
|
|
|
if ! pkg-config --exists webkit2gtk-4.1; then
|
|
print_error "webkit2gtk-4.1 not found via pkg-config"
|
|
print_info "Install with: sudo apt install libwebkit2gtk-4.1-dev"
|
|
exit 1
|
|
fi
|
|
|
|
if [ "$VERBOSE" = true ]; then
|
|
print_info "WebKitGTK 4.1 CFLAGS: $(pkg-config --cflags webkit2gtk-4.1)"
|
|
print_info "WebKitGTK 4.1 LIBS: $(pkg-config --libs webkit2gtk-4.1)"
|
|
fi
|
|
|
|
print_success "All dependencies satisfied"
|
|
|
|
###########################################################################################
|
|
############ BUILD
|
|
###########################################################################################
|
|
|
|
# Read version from VERSION file (if present) for the build banner.
|
|
VERSION_STR="(unknown)"
|
|
if [ -f "VERSION" ]; then
|
|
VERSION_STR="v$(tr -d '[:space:]' < VERSION)"
|
|
fi
|
|
|
|
print_info "Building sovereign_browser $VERSION_STR..."
|
|
|
|
MAKE_FLAGS=""
|
|
if [ "$VERBOSE" = true ]; then
|
|
MAKE_FLAGS="V=1"
|
|
fi
|
|
|
|
# Delegate to the Makefile. CC is exported above so cross-compiles work.
|
|
if make $MAKE_FLAGS; then
|
|
print_success "Build complete: ./sovereign_browser $VERSION_STR"
|
|
else
|
|
print_error "Build failed"
|
|
exit 1
|
|
fi
|
|
|
|
# Optional: run immediately.
|
|
if [ "$RUN_AFTER" = true ]; then
|
|
print_info "Launching sovereign_browser..."
|
|
./sovereign_browser
|
|
fi
|