add build.bat script for Windows installation

This commit is contained in:
Stu Leak 2025-12-04 17:05:52 -05:00
parent 5b8fc452af
commit 44495f23d0
5 changed files with 623 additions and 40 deletions

63
scripts/build-linux.sh Executable file
View File

@ -0,0 +1,63 @@
#!/bin/bash
# VideoTools Build Script
# Cleans dependencies and builds the application with proper error handling
set -e
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BUILD_OUTPUT="$PROJECT_ROOT/VideoTools"
echo "════════════════════════════════════════════════════════════════"
echo " VideoTools Build Script"
echo "════════════════════════════════════════════════════════════════"
echo ""
# Check if go is installed
if ! command -v go &> /dev/null; then
echo "❌ ERROR: Go is not installed. Please install Go 1.21 or later."
exit 1
fi
echo "📦 Go version:"
go version
echo ""
# Change to project directory
cd "$PROJECT_ROOT"
echo "🧹 Cleaning previous builds and cache..."
go clean -cache -modcache -testcache 2>/dev/null || true
rm -f "$BUILD_OUTPUT" 2>/dev/null || true
echo "✓ Cache cleaned"
echo ""
echo "⬇️ Downloading and verifying dependencies..."
go mod download
go mod verify
echo "✓ Dependencies verified"
echo ""
echo "🔨 Building VideoTools..."
# Fyne needs cgo for GLFW/OpenGL bindings; build with CGO enabled.
export CGO_ENABLED=1
if go build -o "$BUILD_OUTPUT" .; then
echo "✓ Build successful!"
echo ""
echo "════════════════════════════════════════════════════════════════"
echo "✅ BUILD COMPLETE"
echo "════════════════════════════════════════════════════════════════"
echo ""
echo "Output: $BUILD_OUTPUT"
echo "Size: $(du -h "$BUILD_OUTPUT" | cut -f1)"
echo ""
echo "To run:"
echo " $PROJECT_ROOT/VideoTools"
echo ""
echo "Or use the convenience script:"
echo " source $PROJECT_ROOT/scripts/alias.sh"
echo " VideoTools"
echo ""
else
echo "❌ Build failed!"
exit 1
fi

163
scripts/build-windows.sh Executable file
View File

@ -0,0 +1,163 @@
#!/bin/bash
# VideoTools Windows Build Script
# Cross-compiles VideoTools for Windows from Linux
set -e
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BUILD_OUTPUT="$PROJECT_ROOT/VideoTools.exe"
DIST_DIR="$PROJECT_ROOT/dist/windows"
echo "════════════════════════════════════════════════════════════════"
echo " VideoTools Windows Build Script (Cross-Compilation)"
echo "════════════════════════════════════════════════════════════════"
echo ""
# Check if go is installed
if ! command -v go &> /dev/null; then
echo "❌ ERROR: Go is not installed. Please install Go 1.21 or later."
exit 1
fi
echo "📦 Go version:"
go version
echo ""
# Check if MinGW-w64 is installed
if ! command -v x86_64-w64-mingw32-gcc &> /dev/null; then
echo "❌ ERROR: MinGW-w64 cross-compiler not found!"
echo ""
echo "To install on Fedora/RHEL:"
echo " sudo dnf install mingw64-gcc mingw64-winpthreads-static"
echo ""
echo "To install on Debian/Ubuntu:"
echo " sudo apt-get install gcc-mingw-w64"
echo ""
exit 1
fi
echo "🔧 MinGW-w64 detected:"
x86_64-w64-mingw32-gcc --version | head -1
echo ""
# Change to project directory
cd "$PROJECT_ROOT"
echo "🧹 Cleaning previous Windows builds..."
rm -f "$BUILD_OUTPUT" 2>/dev/null || true
rm -rf "$DIST_DIR" 2>/dev/null || true
echo "✓ Previous builds cleaned"
echo ""
echo "⬇️ Downloading and verifying dependencies..."
go mod download
go mod verify
echo "✓ Dependencies verified"
echo ""
echo "🔨 Cross-compiling for Windows (amd64)..."
echo " Target: windows/amd64"
echo " Compiler: x86_64-w64-mingw32-gcc"
echo ""
# Set Windows build environment
export GOOS=windows
export GOARCH=amd64
export CGO_ENABLED=1
export CC=x86_64-w64-mingw32-gcc
export CXX=x86_64-w64-mingw32-g++
# Build flags
# -H windowsgui: Hide console window (GUI application)
# -s -w: Strip debug symbols (smaller binary)
LDFLAGS="-H windowsgui -s -w"
if go build -ldflags="$LDFLAGS" -o "$BUILD_OUTPUT" .; then
echo "✓ Cross-compilation successful!"
echo ""
else
echo "❌ Build failed!"
exit 1
fi
echo "📦 Creating distribution package..."
mkdir -p "$DIST_DIR"
# Copy executable
cp "$BUILD_OUTPUT" "$DIST_DIR/"
echo "✓ Copied VideoTools.exe"
# Copy documentation
cp README.md "$DIST_DIR/" 2>/dev/null || echo "⚠️ README.md not found"
cp LICENSE "$DIST_DIR/" 2>/dev/null || echo "⚠️ LICENSE not found"
# Download and bundle FFmpeg automatically
if [ ! -f "ffmpeg.exe" ]; then
echo "📥 FFmpeg not found locally, downloading..."
FFMPEG_URL="https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip"
FFMPEG_ZIP="$PROJECT_ROOT/ffmpeg-windows.zip"
if command -v wget &> /dev/null; then
wget -q --show-progress "$FFMPEG_URL" -O "$FFMPEG_ZIP"
elif command -v curl &> /dev/null; then
curl -L "$FFMPEG_URL" -o "$FFMPEG_ZIP" --progress-bar
else
echo "⚠️ wget or curl not found. Cannot download FFmpeg automatically."
echo " Please download manually from: $FFMPEG_URL"
echo " Extract ffmpeg.exe and ffprobe.exe to project root"
echo ""
fi
if [ -f "$FFMPEG_ZIP" ]; then
echo "📦 Extracting FFmpeg..."
unzip -q "$FFMPEG_ZIP" "*/bin/ffmpeg.exe" "*/bin/ffprobe.exe" -d "$PROJECT_ROOT/ffmpeg-temp"
# Find and copy the executables (they're nested in a versioned directory)
find "$PROJECT_ROOT/ffmpeg-temp" -name "ffmpeg.exe" -exec cp {} "$PROJECT_ROOT/" \;
find "$PROJECT_ROOT/ffmpeg-temp" -name "ffprobe.exe" -exec cp {} "$PROJECT_ROOT/" \;
# Cleanup
rm -rf "$PROJECT_ROOT/ffmpeg-temp" "$FFMPEG_ZIP"
echo "✓ FFmpeg downloaded and extracted"
fi
fi
# Bundle FFmpeg with the distribution
if [ -f "ffmpeg.exe" ]; then
cp ffmpeg.exe "$DIST_DIR/"
echo "✓ Bundled ffmpeg.exe"
else
echo "⚠️ ffmpeg.exe not found - distribution will require separate FFmpeg installation"
fi
if [ -f "ffprobe.exe" ]; then
cp ffprobe.exe "$DIST_DIR/"
echo "✓ Bundled ffprobe.exe"
else
echo "⚠️ ffprobe.exe not found"
fi
echo ""
echo "════════════════════════════════════════════════════════════════"
echo "✅ WINDOWS BUILD COMPLETE"
echo "════════════════════════════════════════════════════════════════"
echo ""
echo "Output directory: $DIST_DIR"
echo "Contents:"
ls -lh "$DIST_DIR"
echo ""
echo "Windows executable: $DIST_DIR/VideoTools.exe"
echo "Size: $(du -h "$DIST_DIR/VideoTools.exe" | cut -f1)"
echo ""
echo "Next steps:"
echo " 1. Test on Windows 10/11"
echo " 2. Create installer with NSIS (optional)"
echo " 3. Package with FFmpeg for distribution"
echo ""
echo "To download FFmpeg for Windows:"
echo " wget https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip"
echo " unzip ffmpeg-master-latest-win64-gpl.zip"
echo " cp ffmpeg-master-latest-win64-gpl/bin/ffmpeg.exe ."
echo " cp ffmpeg-master-latest-win64-gpl/bin/ffprobe.exe ."
echo " ./scripts/build-windows.sh # Rebuild to include FFmpeg"
echo ""

91
scripts/build.bat Normal file
View File

@ -0,0 +1,91 @@
@echo off
setlocal enabledelayedexpansion
echo ================================================================
echo VideoTools Windows Build Script
echo ================================================================
echo.
REM ----------------------------
REM Detect Go
REM ----------------------------
where go >nul 2>&1
if %ERRORLEVEL% neq 0 (
echo ❌ ERROR: Go is not installed or not in PATH.
echo Download Go from: https://go.dev/dl/
exit /b 1
)
echo 📦 Go version:
go version
echo.
REM ----------------------------
REM Move to project root
REM ----------------------------
pushd "%~dp0\.."
REM ----------------------------
REM Clean previous build
REM ----------------------------
echo 🧹 Cleaning previous Windows build...
if exist VideoTools.exe del /f VideoTools.exe
echo ✓ Cache cleaned
echo.
REM ----------------------------
REM Download go dependencies
REM ----------------------------
echo ⬇️ Downloading dependencies...
go mod download
if %ERRORLEVEL% neq 0 (
echo ❌ Failed to download dependencies.
exit /b 1
)
echo ✓ Dependencies downloaded
echo.
REM ----------------------------
REM Build VideoTools (Windows GUI mode)
REM Equivalent to:
REM go build -ldflags="-H windowsgui -s -w" -o VideoTools.exe .
REM ----------------------------
echo 🔨 Building VideoTools.exe...
go build ^
-ldflags="-H windowsgui -s -w" ^
-o VideoTools.exe ^
.
if %ERRORLEVEL% neq 0 (
echo ❌ Build failed!
popd
exit /b 1
)
echo ✓ Build successful!
echo.
REM ----------------------------
REM Show file size
REM ----------------------------
for %%A in (VideoTools.exe) do set FILESIZE=%%~zA
echo Output: VideoTools.exe (Size: !FILESIZE! bytes)
echo.
REM ----------------------------
REM Offer to run FFmpeg setup
REM ----------------------------
if exist "%~dp0setup-windows.ps1" (
echo Would you like to download FFmpeg now? (Y/N):
set /p choice=
if /I "!choice!"=="Y" (
powershell -ExecutionPolicy Bypass -File "%~dp0setup-windows.ps1" -Portable
) else (
echo Skipping FFmpeg setup. You can run setup-windows.ps1 later.
)
)
popd
exit /b 0

View File

@ -1,20 +1,43 @@
#!/bin/bash
# VideoTools Build Script
# Cleans dependencies and builds the application with proper error handling
# VideoTools Universal Build Script
# Auto-detects platform and builds accordingly
set -e
PROJECT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BUILD_OUTPUT="$PROJECT_ROOT/VideoTools"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
echo "════════════════════════════════════════════════════════════════"
echo " VideoTools Build Script"
echo " VideoTools Universal Build Script"
echo "════════════════════════════════════════════════════════════════"
echo ""
# Detect platform
PLATFORM="$(uname -s)"
case "${PLATFORM}" in
Linux*)
OS="Linux"
;;
Darwin*)
OS="macOS"
;;
CYGWIN*|MINGW*|MSYS*)
OS="Windows"
;;
*)
echo "❌ Unknown platform: ${PLATFORM}"
exit 1
;;
esac
echo "🔍 Detected platform: $OS"
echo ""
# Check if go is installed
if ! command -v go &> /dev/null; then
echo "❌ ERROR: Go is not installed. Please install Go 1.21 or later."
echo ""
echo "Download from: https://go.dev/dl/"
exit 1
fi
@ -22,42 +45,89 @@ echo "📦 Go version:"
go version
echo ""
# Change to project directory
cd "$PROJECT_ROOT"
# Route to appropriate build script
case "$OS" in
Linux)
echo "→ Building for Linux..."
echo ""
exec "$SCRIPT_DIR/build-linux.sh"
;;
echo "🧹 Cleaning previous builds and cache..."
go clean -cache -modcache -testcache 2>/dev/null || true
rm -f "$BUILD_OUTPUT" 2>/dev/null || true
echo "✓ Cache cleaned"
echo ""
macOS)
echo "→ Building for macOS..."
echo ""
# macOS uses same build process as Linux (native build)
exec "$SCRIPT_DIR/build-linux.sh"
;;
echo "⬇️ Downloading and verifying dependencies..."
go mod download
go mod verify
echo "✓ Dependencies verified"
echo ""
Windows)
echo "→ Building for Windows..."
echo ""
echo "🔨 Building VideoTools..."
# Fyne needs cgo for GLFW/OpenGL bindings; build with CGO enabled.
export CGO_ENABLED=1
if go build -o "$BUILD_OUTPUT" .; then
echo "✓ Build successful!"
echo ""
echo "════════════════════════════════════════════════════════════════"
echo "✅ BUILD COMPLETE"
echo "════════════════════════════════════════════════════════════════"
echo ""
echo "Output: $BUILD_OUTPUT"
echo "Size: $(du -h "$BUILD_OUTPUT" | cut -f1)"
echo ""
echo "To run:"
echo " $PROJECT_ROOT/VideoTools"
echo ""
echo "Or use the convenience script:"
echo " source $PROJECT_ROOT/scripts/alias.sh"
echo " VideoTools"
echo ""
else
echo "❌ Build failed!"
exit 1
fi
# Check if running in Git Bash or similar
if command -v go.exe &> /dev/null; then
# Windows native build
cd "$PROJECT_ROOT"
echo "🧹 Cleaning previous builds..."
rm -f VideoTools.exe 2>/dev/null || true
echo "✓ Cache cleaned"
echo ""
echo "⬇️ Downloading dependencies..."
go mod download
echo "✓ Dependencies downloaded"
echo ""
echo "🔨 Building VideoTools for Windows..."
export CGO_ENABLED=1
# Build with Windows GUI flags
if go build -ldflags="-H windowsgui -s -w" -o VideoTools.exe .; then
echo "✓ Build successful!"
echo ""
# Run setup script to get FFmpeg
if [ -f "setup-windows.bat" ]; then
echo "════════════════════════════════════════════════════════════════"
echo "✅ BUILD COMPLETE"
echo "════════════════════════════════════════════════════════════════"
echo ""
echo "Output: VideoTools.exe"
if [ -f "VideoTools.exe" ]; then
SIZE=$(du -h VideoTools.exe 2>/dev/null | cut -f1 || echo "unknown")
echo "Size: $SIZE"
fi
echo ""
echo "Next step: Get FFmpeg"
echo " Run: setup-windows.bat"
echo " Or: .\scripts\setup-windows.ps1 -Portable"
echo ""
# Offer to run setup automatically
echo "Would you like to download FFmpeg now? (y/n)"
read -r response
if [[ "$response" =~ ^[Yy]$ ]]; then
if command -v powershell &> /dev/null; then
powershell -ExecutionPolicy Bypass -File "$SCRIPT_DIR/setup-windows.ps1" -Portable
else
cmd.exe /c setup-windows.bat
fi
else
echo "You can run setup-windows.bat later to get FFmpeg."
fi
else
echo "✓ Build complete: VideoTools.exe"
fi
else
echo "❌ Build failed!"
exit 1
fi
else
echo "❌ ERROR: go.exe not found."
echo "Please ensure Go is properly installed on Windows."
echo "Download from: https://go.dev/dl/"
exit 1
fi
;;
esac

196
scripts/setup-windows.ps1 Normal file
View File

@ -0,0 +1,196 @@
# VideoTools Windows Setup Script
# Automatically downloads FFmpeg and sets up VideoTools
param(
[switch]$Portable,
[switch]$System
)
$ErrorActionPreference = "Stop"
Write-Host "════════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host " VideoTools Windows Setup" -ForegroundColor Cyan
Write-Host "════════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
# Determine installation type
if (-not $Portable -and -not $System) {
Write-Host "Choose installation type:" -ForegroundColor Yellow
Write-Host " 1) Portable (bundle FFmpeg with VideoTools)"
Write-Host " 2) System-wide (install FFmpeg to PATH)"
Write-Host ""
$choice = Read-Host "Enter choice (1 or 2)"
if ($choice -eq "2") {
$System = $true
} else {
$Portable = $true
}
}
$scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$projectRoot = Split-Path -Parent $scriptDir
$distDir = Join-Path $projectRoot "dist\windows"
# FFmpeg download URL
$ffmpegUrl = "https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-master-latest-win64-gpl.zip"
$ffmpegZip = Join-Path $env:TEMP "ffmpeg-windows.zip"
$ffmpegExtract = Join-Path $env:TEMP "ffmpeg-extract"
Write-Host "📦 Downloading FFmpeg for Windows..." -ForegroundColor Green
Write-Host " Source: $ffmpegUrl" -ForegroundColor Gray
Write-Host ""
try {
# Download FFmpeg
Invoke-WebRequest -Uri $ffmpegUrl -OutFile $ffmpegZip -UseBasicParsing
Write-Host "✓ Download complete" -ForegroundColor Green
Write-Host ""
# Extract FFmpeg
Write-Host "📂 Extracting FFmpeg..." -ForegroundColor Green
if (Test-Path $ffmpegExtract) {
Remove-Item $ffmpegExtract -Recurse -Force
}
Expand-Archive -Path $ffmpegZip -DestinationPath $ffmpegExtract -Force
# Find the bin directory (it's nested in a versioned folder)
$binDir = Get-ChildItem -Path $ffmpegExtract -Recurse -Directory -Filter "bin" | Select-Object -First 1
$ffmpegExe = Join-Path $binDir.FullName "ffmpeg.exe"
$ffprobeExe = Join-Path $binDir.FullName "ffprobe.exe"
if (-not (Test-Path $ffmpegExe)) {
throw "FFmpeg executable not found in downloaded archive"
}
Write-Host "✓ Extraction complete" -ForegroundColor Green
Write-Host ""
if ($Portable) {
# Portable installation - copy to dist directory
Write-Host "📦 Setting up portable installation..." -ForegroundColor Green
if (-not (Test-Path $distDir)) {
New-Item -ItemType Directory -Path $distDir -Force | Out-Null
}
# Copy FFmpeg executables
Copy-Item $ffmpegExe -Destination $distDir -Force
Copy-Item $ffprobeExe -Destination $distDir -Force
Write-Host "✓ FFmpeg installed to: $distDir" -ForegroundColor Green
Write-Host ""
# Check if VideoTools.exe exists
$videoToolsExe = Join-Path $distDir "VideoTools.exe"
if (Test-Path $videoToolsExe) {
Write-Host "════════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host "✅ SETUP COMPLETE (Portable)" -ForegroundColor Green
Write-Host "════════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
Write-Host "Installation directory: $distDir" -ForegroundColor White
Write-Host ""
Write-Host "Contents:" -ForegroundColor White
Get-ChildItem $distDir | Format-Table Name, Length -AutoSize
Write-Host ""
Write-Host "To run VideoTools:" -ForegroundColor Yellow
Write-Host " $videoToolsExe" -ForegroundColor White
Write-Host ""
Write-Host "Or double-click VideoTools.exe in:" -ForegroundColor Yellow
Write-Host " $distDir" -ForegroundColor White
} else {
Write-Host "════════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host "⚠️ FFmpeg Setup Complete, VideoTools.exe Not Found" -ForegroundColor Yellow
Write-Host "════════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
Write-Host "FFmpeg has been downloaded to: $distDir" -ForegroundColor White
Write-Host ""
Write-Host "Next steps:" -ForegroundColor Yellow
Write-Host " 1. Build VideoTools.exe (see README.md)" -ForegroundColor White
Write-Host " 2. Copy VideoTools.exe to: $distDir" -ForegroundColor White
Write-Host " 3. Run VideoTools.exe" -ForegroundColor White
}
} elseif ($System) {
# System-wide installation - install to Program Files and add to PATH
Write-Host "📦 Installing FFmpeg system-wide..." -ForegroundColor Green
Write-Host " (This requires administrator privileges)" -ForegroundColor Yellow
Write-Host ""
$installDir = "C:\Program Files\ffmpeg\bin"
# Check if running as administrator
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Host "⚠️ This script needs to run as Administrator for system-wide installation." -ForegroundColor Red
Write-Host ""
Write-Host "Please:" -ForegroundColor Yellow
Write-Host " 1. Right-click PowerShell" -ForegroundColor White
Write-Host " 2. Select 'Run as Administrator'" -ForegroundColor White
Write-Host " 3. Run this script again with -System flag" -ForegroundColor White
Write-Host ""
Write-Host "Or use portable installation instead:" -ForegroundColor Yellow
Write-Host " .\scripts\setup-windows.ps1 -Portable" -ForegroundColor White
Write-Host ""
exit 1
}
# Create installation directory
if (-not (Test-Path $installDir)) {
New-Item -ItemType Directory -Path $installDir -Force | Out-Null
}
# Copy FFmpeg executables
Copy-Item $ffmpegExe -Destination $installDir -Force
Copy-Item $ffprobeExe -Destination $installDir -Force
Write-Host "✓ FFmpeg installed to: $installDir" -ForegroundColor Green
Write-Host ""
# Add to PATH if not already present
$currentPath = [Environment]::GetEnvironmentVariable("Path", "Machine")
if ($currentPath -notlike "*$installDir*") {
Write-Host "📝 Adding FFmpeg to system PATH..." -ForegroundColor Green
[Environment]::SetEnvironmentVariable("Path", "$currentPath;$installDir", "Machine")
$env:Path = "$env:Path;$installDir"
Write-Host "✓ PATH updated" -ForegroundColor Green
} else {
Write-Host "✓ FFmpeg already in PATH" -ForegroundColor Green
}
Write-Host ""
# Verify installation
Write-Host "🔍 Verifying installation..." -ForegroundColor Green
$ffmpegVersion = & "$installDir\ffmpeg.exe" -version 2>&1 | Select-Object -First 1
Write-Host "$ffmpegVersion" -ForegroundColor Green
Write-Host ""
Write-Host "════════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host "✅ SETUP COMPLETE (System-wide)" -ForegroundColor Green
Write-Host "════════════════════════════════════════════════════════════════" -ForegroundColor Cyan
Write-Host ""
Write-Host "FFmpeg installed to: $installDir" -ForegroundColor White
Write-Host "PATH updated: Yes" -ForegroundColor White
Write-Host ""
Write-Host "You can now run VideoTools from anywhere." -ForegroundColor Yellow
Write-Host ""
Write-Host "⚠️ Note: Restart any open Command Prompt or PowerShell windows" -ForegroundColor Yellow
Write-Host " for the PATH changes to take effect." -ForegroundColor Yellow
}
} catch {
Write-Host ""
Write-Host "❌ Setup failed: $_" -ForegroundColor Red
Write-Host ""
exit 1
} finally {
# Cleanup
if (Test-Path $ffmpegZip) {
Remove-Item $ffmpegZip -Force
}
if (Test-Path $ffmpegExtract) {
Remove-Item $ffmpegExtract -Recurse -Force
}
}
Write-Host ""