178 lines
5.4 KiB
Bash
Executable File
178 lines
5.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# Build development containers for various platforms
|
|
# Usage: ./scripts/build-container.sh <platform> [version]
|
|
#
|
|
# Platforms: 3ds, switch, wiiu, wii, gamecube, nds, gba
|
|
# Version: Semantic version (default: 0.1.0)
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
|
|
|
# Colors for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Print colored message
|
|
print_msg() {
|
|
local color=$1
|
|
shift
|
|
echo -e "${color}$*${NC}"
|
|
}
|
|
|
|
# Print usage
|
|
usage() {
|
|
cat << EOF
|
|
Usage: $0 <platform> [version]
|
|
|
|
Build development container for specified platform.
|
|
|
|
Platforms:
|
|
3ds Nintendo 3DS (devkitARM)
|
|
switch Nintendo Switch (devkitA64) - Not yet implemented
|
|
wiiu Nintendo Wii U (devkitPPC) - Not yet implemented
|
|
wii Nintendo Wii (devkitPPC) - Not yet implemented
|
|
gamecube Nintendo GameCube (devkitPPC) - Not yet implemented
|
|
nds Nintendo DS (devkitARM) - Not yet implemented
|
|
gba Game Boy Advance (devkitARM) - Not yet implemented
|
|
|
|
Version:
|
|
Semantic version tag (default: 0.1.0)
|
|
Example: 0.1.0, 1.0.0, 0.2.0-beta
|
|
|
|
Examples:
|
|
$0 3ds # Build 3DS container with version 0.1.0
|
|
$0 3ds 0.2.0 # Build 3DS container with version 0.2.0
|
|
$0 switch # Build Switch container (when implemented)
|
|
|
|
Environment Variables:
|
|
CONTAINER_RUNTIME Container runtime to use (podman or docker, default: auto-detect)
|
|
|
|
EOF
|
|
exit 1
|
|
}
|
|
|
|
# Detect container runtime
|
|
detect_runtime() {
|
|
if [ -n "$CONTAINER_RUNTIME" ]; then
|
|
echo "$CONTAINER_RUNTIME"
|
|
return
|
|
fi
|
|
|
|
if command -v podman &> /dev/null; then
|
|
echo "podman"
|
|
elif command -v docker &> /dev/null; then
|
|
echo "docker"
|
|
else
|
|
print_msg "$RED" "Error: Neither podman nor docker found in PATH"
|
|
print_msg "$YELLOW" "Please install podman (recommended) or docker"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Build container
|
|
build_container() {
|
|
local platform=$1
|
|
local version=$2
|
|
local dockerfile="docker/${platform}.Dockerfile"
|
|
local image_name="tomusan/devkitarm-${platform}"
|
|
|
|
if [ ! -f "$PROJECT_ROOT/$dockerfile" ]; then
|
|
print_msg "$RED" "Error: Dockerfile not found: $dockerfile"
|
|
print_msg "$YELLOW" "This platform may not be implemented yet."
|
|
exit 1
|
|
fi
|
|
|
|
local runtime
|
|
runtime=$(detect_runtime)
|
|
|
|
print_msg "$BLUE" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
print_msg "$GREEN" "Building ${platform} container"
|
|
print_msg "$BLUE" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo
|
|
print_msg "$YELLOW" "Platform: $platform"
|
|
print_msg "$YELLOW" "Version: $version"
|
|
print_msg "$YELLOW" "Runtime: $runtime"
|
|
print_msg "$YELLOW" "Dockerfile: $dockerfile"
|
|
print_msg "$YELLOW" "Image: ${image_name}:${version}"
|
|
print_msg "$YELLOW" " ${image_name}:latest"
|
|
echo
|
|
|
|
cd "$PROJECT_ROOT"
|
|
|
|
# Build with both version and latest tags
|
|
print_msg "$GREEN" "Starting build..."
|
|
echo
|
|
|
|
"$runtime" build \
|
|
-t "${image_name}:${version}" \
|
|
-t "${image_name}:latest" \
|
|
-f "$dockerfile" \
|
|
.
|
|
|
|
local exit_code=$?
|
|
|
|
if [ $exit_code -eq 0 ]; then
|
|
echo
|
|
print_msg "$BLUE" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
print_msg "$GREEN" "✓ Build successful!"
|
|
print_msg "$BLUE" "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
|
echo
|
|
print_msg "$GREEN" "Tagged images:"
|
|
print_msg "$YELLOW" " ${image_name}:${version}"
|
|
print_msg "$YELLOW" " ${image_name}:latest"
|
|
echo
|
|
print_msg "$GREEN" "To use this container:"
|
|
print_msg "$YELLOW" " $runtime run --rm -v ./your-project:/project:z ${image_name}:latest make"
|
|
echo
|
|
print_msg "$GREEN" "For interactive shell:"
|
|
print_msg "$YELLOW" " $runtime run -it --rm -v ./your-project:/project:z ${image_name}:latest bash"
|
|
echo
|
|
else
|
|
echo
|
|
print_msg "$RED" "✗ Build failed with exit code $exit_code"
|
|
exit $exit_code
|
|
fi
|
|
}
|
|
|
|
# Main
|
|
main() {
|
|
if [ $# -lt 1 ]; then
|
|
usage
|
|
fi
|
|
|
|
local platform=$1
|
|
local version=${2:-0.1.0}
|
|
|
|
# Validate platform
|
|
case "$platform" in
|
|
3ds)
|
|
;;
|
|
switch|wiiu|wii|gamecube|nds|gba)
|
|
print_msg "$RED" "Error: Platform '$platform' is not yet implemented"
|
|
print_msg "$YELLOW" "Currently only '3ds' is available"
|
|
exit 1
|
|
;;
|
|
*)
|
|
print_msg "$RED" "Error: Unknown platform '$platform'"
|
|
echo
|
|
usage
|
|
;;
|
|
esac
|
|
|
|
# Validate version format (basic semantic versioning)
|
|
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$ ]]; then
|
|
print_msg "$RED" "Error: Invalid version format '$version'"
|
|
print_msg "$YELLOW" "Expected format: X.Y.Z or X.Y.Z-label (e.g., 0.1.0, 1.0.0, 0.2.0-beta)"
|
|
exit 1
|
|
fi
|
|
|
|
build_container "$platform" "$version"
|
|
}
|
|
|
|
main "$@"
|