167 lines
5.0 KiB
Bash
Executable File
167 lines
5.0 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# SPDX-License-Identifier: (GPL-2.0-only OR MIT)
|
|
# Copyright (C) 2025 Amlogic, Inc. All rights reserved
|
|
# Post-build cleanup script
|
|
# Removes all intermediate build files while preserving toolchain and final libraries
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
|
|
echo "========================================"
|
|
echo " Post-Build Cleanup Script"
|
|
echo "========================================"
|
|
echo "Project: $SCRIPT_DIR"
|
|
echo ""
|
|
|
|
# Function to clean up build directories
|
|
cleanup_build_files()
|
|
{
|
|
echo "Cleaning CMake build files..."
|
|
|
|
# Remove main build directory (keeping final libraries)
|
|
if [ -d "$SCRIPT_DIR/build_libs" ]; then
|
|
echo "Cleaning build_libs directory..."
|
|
cd "$SCRIPT_DIR/build_libs"
|
|
|
|
# Keep the final library but remove build files
|
|
if [ -f "libiamf-ahal.so" ]; then
|
|
mkdir -p ../lib_output
|
|
cp libiamf-ahal.so ../lib_output/
|
|
echo "✓ Final library backed up to lib_output/"
|
|
fi
|
|
|
|
cd "$SCRIPT_DIR"
|
|
rm -rf build_libs
|
|
|
|
# Restore the library
|
|
if [ -d "lib_output" ]; then
|
|
mkdir -p build_libs/lib
|
|
mv lib_output/libiamf-ahal.so build_libs/lib/
|
|
rm -rf lib_output
|
|
echo "✓ Final library restored"
|
|
fi
|
|
fi
|
|
|
|
}
|
|
|
|
# Function to clean up codec dependencies
|
|
cleanup_codec_files()
|
|
{
|
|
echo "Cleaning codec dependency files..."
|
|
|
|
cd "$SCRIPT_DIR/dep_codecs"
|
|
|
|
# Clean up AAC source and build files
|
|
if [ -d "aac" ]; then
|
|
echo "Cleaning AAC source files..."
|
|
cd aac
|
|
find . -name "*.tar.gz" -delete 2>/dev/null || true
|
|
find . -name "fdk-aac-*" -type d -exec rm -rf {} + 2>/dev/null || true
|
|
cd ..
|
|
fi
|
|
|
|
# Clean up OPUS source and build files
|
|
if [ -d "opus" ]; then
|
|
echo "Cleaning OPUS source files..."
|
|
cd opus
|
|
find . -name "*.tar.gz" -delete 2>/dev/null || true
|
|
find . -name "opus-*" -type d -exec rm -rf {} + 2>/dev/null || true
|
|
cd ..
|
|
fi
|
|
|
|
# Clean up FLAC source and build files
|
|
if [ -d "flac" ]; then
|
|
echo "Cleaning FLAC source files..."
|
|
cd flac
|
|
find . -name "*.tar.xz" -delete 2>/dev/null || true
|
|
find . -name "flac-*" -type d -exec rm -rf {} + 2>/dev/null || true
|
|
cd ..
|
|
fi
|
|
|
|
# Clean up CMake generated files in lib directory
|
|
if [ -d "lib/cmake" ]; then
|
|
echo "Cleaning CMake configuration files..."
|
|
rm -rf lib/cmake
|
|
fi
|
|
|
|
# Clean up pkgconfig files in lib directory
|
|
if [ -d "lib/pkgconfig" ]; then
|
|
echo "Cleaning pkgconfig files..."
|
|
rm -rf lib/pkgconfig
|
|
fi
|
|
|
|
# Clean up documentation generated during build
|
|
if [ -d "share" ]; then
|
|
echo "Cleaning generated documentation..."
|
|
rm -rf share
|
|
fi
|
|
|
|
# Clean up bin directory (build tools, not needed after compile)
|
|
if [ -d "bin" ]; then
|
|
echo "Cleaning build tools in bin directory..."
|
|
rm -rf bin
|
|
fi
|
|
|
|
# Clean up any .la files (libtool archive files, not needed for static linking)
|
|
find lib -name "*.la" -delete 2>/dev/null || true
|
|
|
|
# Clean up only specific generated files in include directory
|
|
if [ -d "include" ]; then
|
|
echo "Cleaning specific generated files in include directory..."
|
|
# Only remove FLAC++ C++ headers (these are often not needed for C projects)
|
|
# Keep the main C API headers (FLAC/, fdk-aac/, opus/) as they are important
|
|
if [ -d "include/FLAC++" ]; then
|
|
echo "Removing FLAC++ C++ headers (C++ bindings not needed for this project)"
|
|
rm -rf include/FLAC++
|
|
fi
|
|
# Note: Keep include/FLAC/, include/fdk-aac/, include/opus/ as they contain
|
|
# important API headers needed for linking and future development
|
|
fi
|
|
|
|
echo "✓ Codec source files cleaned"
|
|
echo "✓ CMake configuration files cleaned (lib/cmake/)"
|
|
echo "✓ pkg-config files cleaned (lib/pkgconfig/)"
|
|
echo "✓ Generated documentation cleaned (share/)"
|
|
echo "✓ Build tools cleaned (bin/)"
|
|
echo "✓ Libtool archive files (.la) cleaned"
|
|
echo "✓ FLAC++ C++ headers cleaned (include/FLAC++/)"
|
|
echo "✓ Important API headers preserved (include/FLAC/, include/fdk-aac/, include/opus/)"
|
|
echo "✓ Compiled codec libraries preserved (.a files)"
|
|
}
|
|
|
|
# Main cleanup execution
|
|
main()
|
|
{
|
|
# Check for automatic mode
|
|
if [ "$CLEANUP_AUTO" = "1" ]; then
|
|
echo "Running in automatic mode - no confirmation required"
|
|
else
|
|
# Confirm cleanup
|
|
echo "This will remove all build intermediate files but preserve:"
|
|
echo "- Final compiled libraries"
|
|
echo "- Toolchain directory"
|
|
echo "- Source code"
|
|
echo ""
|
|
read -p "Continue with cleanup? (y/N): " -n 1 -r
|
|
echo
|
|
|
|
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
|
echo "Cleanup cancelled."
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
echo "Starting cleanup..."
|
|
|
|
# Execute cleanup functions
|
|
cleanup_build_files
|
|
cleanup_codec_files
|
|
|
|
echo ""
|
|
echo "✓ Cleanup completed successfully!"
|
|
}
|
|
|
|
# Run main function
|
|
main "$@" |