Files
BPI-CM9-Linux/aml-comp/multimedia/libiamf/code/build_roku.sh
T

140 lines
4.0 KiB
Bash
Raw Normal View History

2026-08-13 11:28:40 +08:00
#!/bin/bash
# SPDX-License-Identifier: (GPL-2.0-only OR MIT)
# Copyright (C) 2025 Amlogic, Inc. All rights reserved
# Roku ARM32 Cross-compilation Build Script
# Downloads toolchain from official repository and builds libiamf
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
TOOLCHAIN_DIR="$SCRIPT_DIR/toolchain/arm-roku-linux-gnueabi"
TOOLCHAIN_PORTING_KIT="$TOOLCHAIN_DIR/porting_kit"
TOOLCHAIN_BIN="$TOOLCHAIN_DIR/gcc-14/20241120/bin"
# Roku porting kit repository
ROKU_PORTING_KIT_REPO="ssh://scgit.amlogic.com:29418/linux/roku_porting_kit"
echo "========================================="
echo " Linux Roku ARM32 Biuld Script"
echo "========================================="
echo "Project: $SCRIPT_DIR"
echo "Toolchain: $TOOLCHAIN_BIN"
echo ""
# Function to download toolchain
download_toolchain()
{
echo "Downloading Roku toolchain..."
echo "Repository: $ROKU_PORTING_KIT_REPO"
echo "Target: $TOOLCHAIN_DIR"
if [ ! -d "$TOOLCHAIN_PORTING_KIT" ]; then
# Create toolchain directory
mkdir -p "$TOOLCHAIN_DIR"
if ! git clone --depth 1 "$ROKU_PORTING_KIT_REPO" "$TOOLCHAIN_DIR"; then
echo "Error: Failed to clone repository"
echo "Please ensure:"
echo "1. SSH access to scgit.amlogic.com:29418"
echo "2. Network connectivity"
exit 1
fi
fi
# Copy gcc-14 toolchain to target directory
cp -rf $TOOLCHAIN_PORTING_KIT/os/toolchain/gcc-14 $TOOLCHAIN_DIR
# Clean up: remove everything except gcc-14 directory in TOOLCHAIN_DIR
echo "Cleaning up unnecessary files, keeping only gcc-14..."
cd $TOOLCHAIN_DIR
# List all items (including hidden files) and remove everything except gcc-14
for item in * .[^.]* ..?*; do
# Skip if glob pattern doesn't match any files
[ -e "$item" ] || continue
if [ "$item" != "gcc-14" ] && [ "$item" != "." ] && [ "$item" != ".." ]; then
echo "Removing: $item"
rm -rf "$item"
fi
done
echo "✓ Toolchain downloaded and cleaned successfully!"
}
# Function to build project
build_project()
{
echo "Building libiamf for ARM32..."
# Update CMake toolchain to use local toolchain
local cmake_toolchain="$SCRIPT_DIR/build/cmake/toolchains/arm-roku-linux.cmake"
if [ -f "$cmake_toolchain" ]; then
echo "Using CMake toolchain: $cmake_toolchain"
echo "Toolchain will auto-detect: $TOOLCHAIN_BIN"
else
echo "Error: CMake toolchain file not found: $cmake_toolchain"
exit 1
fi
# Build dependencies
echo "Building codec dependencies..."
cd "$SCRIPT_DIR/dep_codecs"
./build.sh --arm-roku-linux_toolchain
# Build main library
echo "Building main library..."
cd "$SCRIPT_DIR"
mkdir -p build_libs
cd build_libs
cmake .. \
-DCMAKE_TOOLCHAIN_FILE="$cmake_toolchain" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=ON
make -j$(nproc)
echo "✓ Build completed"
echo "Output: $SCRIPT_DIR/build_libs/"
}
# Main execution
main()
{
# Check if toolchain exists
if [ ! -d "$TOOLCHAIN_BIN" ]; then
download_toolchain
else
echo "✓ Toolchain already exists"
fi
# Set PATH to include toolchain
export PATH="$TOOLCHAIN_BIN:$PATH"
echo "Toolchain added to PATH: $TOOLCHAIN_BIN"
# Build project
build_project
echo ""
echo "========================================="
echo " Build completed successfully!"
echo "========================================="
echo "Library: $SCRIPT_DIR/build_libs/lib/libiamf-ahal.so"
echo ""
# Post-build cleanup
echo "Starting post-build cleanup..."
if [ -f "$SCRIPT_DIR/cleanup_post_build.sh" ]; then
chmod +x "$SCRIPT_DIR/cleanup_post_build.sh"
# Run cleanup script automatically (skip confirmation)
CLEANUP_AUTO=1 "$SCRIPT_DIR/cleanup_post_build.sh"
echo "✓ Post-build cleanup completed"
else
echo "Warning: cleanup_post_build.sh not found, skipping cleanup"
fi
}
# Run main function
main "$@"