425 lines
14 KiB
Bash
425 lines
14 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# Copyright (c) 2026 AMLOGIC
|
|
#
|
|
# Libtahoevenc build script for AMLbian
|
|
# This script builds libtahoevenc library for Amlogic SoCs
|
|
|
|
set -e
|
|
|
|
# Get script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
AMLBIAN_DIR="$(dirname "$(dirname "$(dirname "${SCRIPT_DIR}")")")"
|
|
BUILD_DIR="${AMLBIAN_DIR}/../build"
|
|
|
|
# Source common functions
|
|
if [[ -f "${AMLBIAN_DIR}/lib/function-common.sh" ]]; then
|
|
source "${AMLBIAN_DIR}/lib/function-common.sh"
|
|
fi
|
|
|
|
# ==============================================================================
|
|
# Section 2: Default Configuration
|
|
# ==============================================================================
|
|
|
|
BOARD="${BOARD:-s6-bq201}"
|
|
DEB_VERSION="${LIBTAHOEVENC_VERSION:-1.0.0}"
|
|
ARCH="${ARCH:-arm64}"
|
|
|
|
# ==============================================================================
|
|
# Section 4: Libtahoevenc Build Functions
|
|
# ==============================================================================
|
|
|
|
function __unset_libtahoevenc_config {
|
|
# Clean up any environment variables set during build
|
|
unset EXTRA_OEMAKE
|
|
unset SYSROOT
|
|
unset CFLAGS
|
|
unset CXXFLAGS
|
|
unset LDFLAGS
|
|
#unset CROSS_CC_PREFIX
|
|
#unset CC
|
|
#unset CXX
|
|
#unset AR
|
|
}
|
|
|
|
function __libtahoevenc_prepare_source {
|
|
local build_dir="${1}"
|
|
|
|
local aml_comp_path="$(amlbian_get_aml_comp_dir)"
|
|
if [[ -z "${aml_comp_path}" ]] || [[ ! -d "${aml_comp_path}" ]]; then
|
|
display_alert "LIBTAHOEVENC" "aml-comp not found: ${aml_comp_path}" "err"
|
|
exit 1
|
|
fi
|
|
|
|
local source_dir="${aml_comp_path}/hardware/amlogic/libencoder/amvenc_tahoe"
|
|
|
|
if [[ ! -d "${source_dir}" ]]; then
|
|
display_alert "LIBTAHOEVENC" "Source directory not found: ${source_dir}" "err"
|
|
exit 1
|
|
fi
|
|
|
|
display_alert "LIBTAHOEVENC" "Copying source from ${source_dir} to ${build_dir}" "info"
|
|
|
|
# 清空构建目录
|
|
rm -rf "${build_dir}"
|
|
mkdir -p "${build_dir}"
|
|
|
|
# 复制源代码到构建目录
|
|
cp -r "${source_dir}"/* "${build_dir}/" 2>/dev/null || true
|
|
|
|
# Check for necessary source files
|
|
if [[ ! -d "${build_dir}/tahoe_enc" ]]; then
|
|
display_alert "LIBTAHOEVENC" "tahoe_enc directory not found in source" "err"
|
|
exit 1
|
|
fi
|
|
|
|
display_alert "LIBTAHOEVENC" "Source prepared successfully" "success"
|
|
}
|
|
|
|
function __libtahoevenc_build_depend {
|
|
local build_dir="${1}"
|
|
|
|
# libion dependency check
|
|
local libion_dir="${BUILD_DIR}/.tmp/libion-build-${ARCH:-arm64}"
|
|
if [ -z "${libion_dir}" ] || [ ! -d "${libion_dir}" ]; then
|
|
display_alert "LIBTAHOEVENC" "libion not found in ${BUILD_DIR}/.tmp build." "info"
|
|
display_alert "AMLOGIC" "TODO>> Start build libion " "info"
|
|
|
|
if ! (
|
|
source "${AMLBIAN_DIR}/scripts/build-libion.sh"
|
|
); then
|
|
display_alert "ERROR" "build-libion failed" "err"
|
|
return 1
|
|
fi
|
|
|
|
if [ -z "${libion_dir}" ] || [ ! -d "${libion_dir}" ]; then
|
|
display_alert "ERROR" "libion build finished but directory still not found" "err"
|
|
return 1
|
|
fi
|
|
|
|
fi
|
|
|
|
display_alert "LIBTAHOEVENC" "libion dir: ${libion_dir}" "info"
|
|
|
|
# Add libion headers to compilation flags
|
|
local ionmem_head_flags="-I${libion_dir}/build/include -I${libion_dir}/build/include/ion"
|
|
export CPPFLAGS="${CPPFLAGS} -I${libion_dir}/build/include -I${libion_dir}/build/include/ion"
|
|
export CFLAGS="${CFLAGS} -I${libion_dir}/build/include -I${libion_dir}/build/include/ion"
|
|
export CXXFLAGS="${CXXFLAGS} -I${libion_dir}/build/include -I${libion_dir}/build/include/ion"
|
|
|
|
export LDFLAGS="${LDFLAGS} -L${libion_dir}/build"
|
|
}
|
|
|
|
function __libtahoevenc_build {
|
|
local build_dir="${1}"
|
|
local install_dir="${2}"
|
|
|
|
display_alert "LIBTAHOEVENC" "Starting libtahoevenc build..." "info"
|
|
|
|
# 检查源目录
|
|
if [[ ! -d "${build_dir}" ]]; then
|
|
display_alert "LIBTAHOEVENC" "Build directory not found: ${build_dir}" "err"
|
|
return 1
|
|
fi
|
|
|
|
# 设置编译环境
|
|
ARCH="${ARCH:-arm64}"
|
|
CROSS_COMPILE="${CROSS_COMPILE:-aarch64-linux-gnu-}"
|
|
SYSROOT="${SYSROOT:-/opt/arm64-sysroot}"
|
|
|
|
export ARCH="${ARCH}"
|
|
export CROSS_COMPILE="${CROSS_COMPILE}"
|
|
|
|
# amlbian_checkout_toolchain
|
|
|
|
#__libtahoevenc_build_depend "${build_dir}"
|
|
|
|
# 创建输出目录
|
|
local out_dir="${build_dir}/output"
|
|
mkdir -p "${out_dir}"
|
|
|
|
# Set environment variables for Makefile
|
|
export CROSS_CC_PREFIX="${CROSS_COMPILE}"
|
|
export CC="${CROSS_COMPILE}gcc"
|
|
export CXX="${CROSS_COMPILE}g++"
|
|
export AR="${CROSS_COMPILE}ar"
|
|
|
|
# Build libtahoevenc library in tahoe_enc directory
|
|
display_alert "LIBTAHOEVENC" "Building libamvenc_tahoe.so library..." "info"
|
|
cd "${build_dir}/tahoe_enc"
|
|
|
|
# Set CFLAGS for library build
|
|
local lib_cflags="${CFLAGS} -I. -I.. -fPIC"
|
|
|
|
make CC="${CC}" \
|
|
CFLAGS="${lib_cflags}" \
|
|
LDFLAGS="${LDFLAGS} -shared -lpthread" \
|
|
TARGET="libamvenc_tahoe.so" \
|
|
-j$(nproc) \
|
|
2>&1 | tee "${out_dir}/make_lib.log" || {
|
|
display_alert "LIBTAHOEVENC" "Library build failed" "err"
|
|
return 1
|
|
}
|
|
|
|
# Copy library to output directory
|
|
mkdir -p "${out_dir}/lib"
|
|
if [[ -f "libamvenc_tahoe.so" ]]; then
|
|
cp "libamvenc_tahoe.so" "${out_dir}/lib/"
|
|
display_alert "LIBTAHOEVENC" "Library built: ${out_dir}/lib/libamvenc_tahoe.so" "info"
|
|
else
|
|
display_alert "LIBTAHOEVENC" "Library file not found: libamvenc_tahoe.so" "err"
|
|
return 1
|
|
fi
|
|
|
|
# Build tahoe_test
|
|
display_alert "LIBTAHOEVENC" "Building tahoe_test..." "info"
|
|
cd "${build_dir}"
|
|
|
|
# Set test-specific CFLAGS
|
|
local test_cflags="${CFLAGS} -I. -I./tahoe_enc"
|
|
|
|
make CC="${CC}" \
|
|
CXX="${CXX}" \
|
|
CFLAGS="${test_cflags}" \
|
|
LDFLAGS="${LDFLAGS} -lm -lrt -lpthread" \
|
|
TARGET="tahoe_test" \
|
|
-j$(nproc) \
|
|
2>&1 | tee "${out_dir}/make_test.log" || {
|
|
display_alert "LIBTAHOEVENC" "Test program build failed" "err"
|
|
return 1
|
|
}
|
|
|
|
# Copy test program to output directory
|
|
mkdir -p "${out_dir}/bin"
|
|
if [[ -f "tahoe_test" ]]; then
|
|
cp "tahoe_test" "${out_dir}/bin/"
|
|
display_alert "LIBTAHOEVENC" "Test program built: ${out_dir}/bin/tahoe_test" "info"
|
|
else
|
|
display_alert "LIBTAHOEVENC" "Test program not found: tahoe_test" "err"
|
|
return 1
|
|
fi
|
|
|
|
display_alert "LIBTAHOEVENC" "Build completed successfully" "success"
|
|
return 0
|
|
}
|
|
|
|
function __libtahoevenc_install {
|
|
local build_dir="${1}"
|
|
local install_dir="${2}"
|
|
|
|
display_alert "LIBTAHOEVENC" "Installing libtahoevenc library..." "info"
|
|
|
|
# Get SYSROOT from build environment or use default
|
|
local SYSROOT="${SYSROOT:-/opt/arm64-sysroot}"
|
|
|
|
local out_dir="${build_dir}/output"
|
|
|
|
if [[ ! -d "${out_dir}" ]]; then
|
|
display_alert "LIBTAHOEVENC" "Output directory not found: ${out_dir}" "err"
|
|
return 1
|
|
fi
|
|
|
|
# 创建安装目录结构
|
|
mkdir -p "${install_dir}/usr/include"
|
|
mkdir -p "${install_dir}/usr/lib"
|
|
mkdir -p "${install_dir}/usr/bin"
|
|
|
|
# 安装库文件
|
|
display_alert "LIBTAHOEVENC" "Installing library..." "info"
|
|
|
|
local lib_file="${out_dir}/lib/libamvenc_tahoe.so"
|
|
if [[ -f "${lib_file}" ]]; then
|
|
install -m 0644 -D "${lib_file}" "${install_dir}/usr/lib/"
|
|
display_alert "LIBTAHOEVENC" "Library installed to ${install_dir}/usr/lib/" "info"
|
|
else
|
|
display_alert "LIBTAHOEVENC" "Library file not found: ${lib_file}" "err"
|
|
return 1
|
|
fi
|
|
|
|
# 安装头文件
|
|
display_alert "LIBTAHOEVENC" "Installing header..." "info"
|
|
local header_file="${build_dir}/tahoe_enc/vp_codec_tahoe.h"
|
|
if [[ -f "${header_file}" ]]; then
|
|
install -m 0644 -D "${header_file}" "${install_dir}/usr/include/"
|
|
display_alert "LIBTAHOEVENC" "Header installed: vp_codec_tahoe.h" "debug"
|
|
else
|
|
display_alert "LIBTAHOEVENC" "Header file not found: ${header_file}" "warning"
|
|
fi
|
|
|
|
# 安装测试程序
|
|
display_alert "LIBTAHOEVENC" "Installing test program..." "info"
|
|
local test_program="${out_dir}/bin/tahoe_test"
|
|
if [[ -f "${test_program}" ]]; then
|
|
install -m 0755 "${test_program}" "${install_dir}/usr/bin/"
|
|
display_alert "LIBTAHOEVENC" "Binary installed: tahoe_test" "debug"
|
|
else
|
|
display_alert "LIBTAHOEVENC" "Test program not found: ${test_program}" "warning"
|
|
fi
|
|
|
|
display_alert "LIBTAHOEVENC" "Installation completed successfully" "success"
|
|
return 0
|
|
}
|
|
|
|
function __libtahoevenc_create_deb {
|
|
local build_dir="${1}"
|
|
local install_dir="${2}"
|
|
|
|
# 设置必要的变量
|
|
local pkg_name="libtahoevenc"
|
|
local version="${DEB_VERSION}"
|
|
local architecture="${ARCH}"
|
|
local maintainer="Armbian Build <[email protected]>"
|
|
local description="Amlogic libtahoevenc library (encoder hal) for Amlogic Tahoe IP"
|
|
local description_long="This package provides the Amlogic libtahoevenc library used by multimedia encoding on Amlogic Tahoe platforms."
|
|
|
|
display_alert "LIBTAHOEVENC" "Creating Debian package for ${pkg_name} ${version}..." "info"
|
|
|
|
# 创建Debian包控制文件
|
|
local deb_dir="${build_dir}/deb/${pkg_name}-${version}"
|
|
local debian_dir="${deb_dir}/DEBIAN"
|
|
|
|
mkdir -p "${debian_dir}"
|
|
|
|
# 将安装目录的内容复制到debian-root
|
|
if [[ -d "${install_dir}" ]] && [[ "$(ls -A "${install_dir}")" ]]; then
|
|
cp -r "${install_dir}"/* "${deb_dir}/" 2>/dev/null || true
|
|
display_alert "LIBTAHOEVENC" "Copied installed files to ${deb_dir}" "info"
|
|
else
|
|
display_alert "LIBTAHOEVENC" "No installed files found in ${install_dir}" "warn"
|
|
return 0
|
|
fi
|
|
|
|
# 创建control文件
|
|
cat > "${debian_dir}/control" <<EOF
|
|
Package: ${pkg_name}
|
|
Version: ${version}
|
|
Architecture: ${architecture}
|
|
Maintainer: ${maintainer}
|
|
Description: ${description}
|
|
${description_long}
|
|
Depends: libc6, libion
|
|
Section: libs
|
|
Priority: optional
|
|
EOF
|
|
|
|
# 创建postinst脚本,用于更新ldconfig
|
|
cat > "${debian_dir}/postinst" <<EOF
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
if [ "\$1" = "configure" ]; then
|
|
# 更新ldconfig缓存
|
|
if command -v ldconfig >/dev/null 2>&1; then
|
|
ldconfig
|
|
fi
|
|
|
|
echo "Libtahoevenc library installed successfully"
|
|
fi
|
|
|
|
exit 0
|
|
EOF
|
|
|
|
chmod 755 "${debian_dir}/postinst"
|
|
|
|
# 创建prerm脚本
|
|
cat > "${debian_dir}/prerm" <<EOF
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
if [ "\$1" = "remove" ] || [ "\$1" = "deconfigure" ]; then
|
|
# Update ldconfig
|
|
if command -v ldconfig >/dev/null 2>&1; then
|
|
ldconfig
|
|
fi
|
|
echo "Removing libtahoevenc library"
|
|
fi
|
|
|
|
exit 0
|
|
EOF
|
|
|
|
chmod 755 "${debian_dir}/prerm"
|
|
|
|
display_alert "LIBTAHOEVENC" "Building Debian package..." "info"
|
|
|
|
# 构建Debian包
|
|
cd "${build_dir}/deb"
|
|
dpkg-deb --build "${pkg_name}-${version}"
|
|
|
|
local deb_file="${pkg_name}-${version}.deb"
|
|
if [[ -f "${deb_file}" ]]; then
|
|
local output_dir="${BUILD_DIR}/output"
|
|
mkdir -p "${output_dir}"
|
|
mv "${deb_file}" "${output_dir}/linux-${pkg_name}-${BOARD}-amlbian_${version}_${architecture}.deb"
|
|
display_alert "LIBTAHOEVENC" "Debian package created: ${output_dir}/linux-${pkg_name}-${BOARD}-amlbian_${version}_${architecture}.deb" "success"
|
|
else
|
|
display_alert "LIBTAHOEVENC" "Failed to build Debian package" "err"
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
function amlbian_build_libtahoevenc {
|
|
if ! is_unit_enabled "libtahoevenc" && ! is_unit_enabled "libencoder"; then
|
|
display_alert "[SKIP] >> libtahoevenc disable in BUILD_UNITS" "" "info"
|
|
return
|
|
fi
|
|
|
|
if ! is_feature_contains "$MEDIA_FEATURES" "libtahoevenc"; then
|
|
display_alert "[SKIP] >> libtahoevenc disable in MEDIA_FEATURES" "" "info"
|
|
return
|
|
fi
|
|
display_alert "AMLOGIC: Building libtahoevenc ${DEB_VERSION} ${BOARD}" "info"
|
|
|
|
# Define all directory paths (in .tmp directory)
|
|
local build_root="${BUILD_DIR}/.tmp/libtahoevenc-build-${ARCH:-arm64}"
|
|
local build_dir="${build_root}/build" # Build directory with source code
|
|
local install_dir="${build_root}/install" # Install directory
|
|
|
|
rm -rf "${build_root}"
|
|
|
|
# 创建目录
|
|
mkdir -p "${build_dir}" "${install_dir}"
|
|
|
|
display_alert "AMLOGIC: build_dir ${build_dir}" "info"
|
|
display_alert "AMLOGIC: install_dir ${install_dir}" "info"
|
|
display_alert "AMLOGIC: output_dir ${BUILD_DIR}/output" "info"
|
|
|
|
# 准备源代码
|
|
__libtahoevenc_prepare_source "${build_dir}"
|
|
|
|
# 构建
|
|
if ! __libtahoevenc_build "${build_dir}" "${install_dir}"; then
|
|
display_alert "AMLOGIC: Libtahoevenc build failed" "err"
|
|
return 1
|
|
fi
|
|
|
|
# 安装到安装目录
|
|
if ! __libtahoevenc_install "${build_dir}" "${install_dir}"; then
|
|
display_alert "AMLOGIC: Libtahoevenc installation failed" "err"
|
|
return 1
|
|
fi
|
|
|
|
display_alert "AMLOGIC: Creating Debian package..." "info"
|
|
__libtahoevenc_create_deb "${build_dir}" "${install_dir}"
|
|
|
|
__unset_libtahoevenc_config
|
|
|
|
return 0
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Section 5: Main
|
|
# ==============================================================================
|
|
|
|
display_alert "AMLIbian Libtahoevenc Build Script" "Version: ${DEB_VERSION}, Board: ${BOARD}" "info"
|
|
|
|
amlbian_build_libtahoevenc
|
|
|
|
display_alert "AMLOGIC: Libtahoevenc build completed" "${BUILD_DIR}/output" "info"
|
|
|
|
# ==============================================================================
|
|
# End of build_libtahoevenc.sh
|
|
# ============================================================================== |