466 lines
16 KiB
Bash
466 lines
16 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# Copyright (c) 2026 AMLOGIC
|
|
#
|
|
# AML-AMAUDIOUTILS library build script for AMLbian
|
|
# This script builds aml-amaudioutils library for Amlogic SoCs
|
|
# Based on compile-aml-amaudioutils.sh functionality
|
|
|
|
set -e
|
|
|
|
# Get script directory
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
AMLBIAN_DIR="$(dirname "$(dirname "${SCRIPT_DIR}")")"
|
|
BUILD_DIR="${SRC}"
|
|
|
|
# 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}"
|
|
AML_AMAUDIOUTILS_VERSION="${AML_AMAUDIOUTILS_VERSION:-1.0.0}"
|
|
ARCH="${ARCH:-arm64}"
|
|
|
|
# ==============================================================================
|
|
# Section 4: AML-AMAUDIOUTILS library Build Functions
|
|
# ==============================================================================
|
|
|
|
function __unset_aml_amaudioutils_config {
|
|
# Clean up any environment variables set during build
|
|
unset CFLAGS
|
|
unset CXXFLAGS
|
|
unset LDFLAGS
|
|
unset CC_FLAG
|
|
unset LD_FLAG
|
|
unset CPPFLAGS
|
|
}
|
|
|
|
function __aml_amaudioutils_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 "AML-AMAUDIOUTILS" "aml-comp not found: ${aml_comp_path}" "err"
|
|
exit 1
|
|
fi
|
|
|
|
local source_dir="${aml_comp_path}/multimedia/aml_amaudioutils"
|
|
|
|
if [[ ! -d "${source_dir}" ]]; then
|
|
display_alert "AML-AMAUDIOUTILS" "Source directory not found: ${source_dir}" "err"
|
|
exit 1
|
|
fi
|
|
|
|
display_alert "AML-AMAUDIOUTILS" "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
|
|
|
|
# Create necessary directories for build
|
|
if [[ ! -d "${build_dir}/src" ]]; then
|
|
mkdir -p "${build_dir}/src"
|
|
fi
|
|
|
|
# Check for necessary source files
|
|
if [[ ! -f "${build_dir}/Makefile" ]]; then
|
|
display_alert "AML-AMAUDIOUTILS" "Makefile not found in source" "err"
|
|
exit 1
|
|
fi
|
|
|
|
display_alert "AML-AMAUDIOUTILS" "Source prepared successfully" "success"
|
|
}
|
|
|
|
function __aml_amaudioutils_build {
|
|
local build_dir="${1}"
|
|
|
|
display_alert "AML-AMAUDIOUTILS" "Starting aml-amaudioutils build..." "info"
|
|
|
|
if [[ ! -d "${build_dir}" ]]; then
|
|
display_alert "AML-AMAUDIOUTILS" "Build directory not found: ${build_dir}" "err"
|
|
return 1
|
|
fi
|
|
|
|
#ln -sf /usr/include/boost ${build_dir}/include/boost
|
|
|
|
# Set build environment
|
|
ARCH="${ARCH:-arm64}"
|
|
CROSS_COMPILE="${CROSS_COMPILE:-aarch64-linux-gnu-}"
|
|
|
|
export ARCH="${ARCH}"
|
|
export CROSS_COMPILE="${CROSS_COMPILE}"
|
|
|
|
# ============================
|
|
# 平台宏(关键)
|
|
# ============================
|
|
# 添加必要的头文件包含
|
|
COMMON_FLAGS="-DFLOATING_POINT -D_GNU_SOURCE -DHAVE_PTHREADS -DEXPORT= -include string.h"
|
|
|
|
# ============================
|
|
# pthread
|
|
# ============================
|
|
export LDFLAGS="${LDFLAGS} -lpthread"
|
|
|
|
# Set build flags based on TOOLCHAIN_NEON_SUPPORT
|
|
local extra_flags=""
|
|
|
|
if [[ "${ARCH}" == "arm64" || "${ARCH}" == "aarch64" ]]; then
|
|
extra_flags="TOOLCHAIN_NEON_SUPPORT=n"
|
|
display_alert "AML-AMAUDIOUTILS" "ARM64 detected, disabling explicit NEON flags" "info"
|
|
fi
|
|
|
|
# Check if liblog is available (dependency)
|
|
display_alert "AML-AMAUDIOUTILS" "Checking dependencies..." "info"
|
|
|
|
local aml_comp_path="$(amlbian_get_aml_comp_dir)"
|
|
if [[ -z "${aml_comp_path}" ]]; then
|
|
display_alert "AML-AMAUDIOUTILS" "aml-comp not found" "err"
|
|
exit 1
|
|
fi
|
|
|
|
local liblog_header="${aml_comp_path}/vendor/amlogic/aml_commonlib/liblog/include/cutils/log.h"
|
|
|
|
if [[ -f "${liblog_header}" ]]; then
|
|
display_alert "AML-AMAUDIOUTILS" "Found Amlogic log header: ${liblog_header}" "success"
|
|
|
|
# 添加包含路径到编译器标志
|
|
local liblog_include_dir="${aml_comp_path}/vendor/amlogic/aml_commonlib/liblog/include"
|
|
export CPPFLAGS="${CPPFLAGS} -I${liblog_include_dir}"
|
|
export CFLAGS="${CFLAGS} -I${liblog_include_dir}"
|
|
export CXXFLAGS="${CXXFLAGS} -I${liblog_include_dir}"
|
|
|
|
display_alert "AML-AMAUDIOUTILS" "Added include path: ${liblog_include_dir}" "info"
|
|
else
|
|
display_alert "AML-AMAUDIOUTILS" "Amlogic log headers not found at: ${liblog_header}" "warning"
|
|
fi
|
|
|
|
INCLUDE_FLAGS="-fPIC \
|
|
-I${build_dir}/include \
|
|
-I${build_dir}/include/speex \
|
|
-I${build_dir}/include/IpcBuffer"
|
|
|
|
# 添加确保 C 链接的标志,防止 C++ 名称修饰
|
|
# 使用 -fvisibility=default 确保符号被导出
|
|
VISIBILITY_FLAGS="-fvisibility=default"
|
|
|
|
export CFLAGS="${CFLAGS} ${COMMON_FLAGS} ${INCLUDE_FLAGS} ${VISIBILITY_FLAGS}"
|
|
export CXXFLAGS="${CXXFLAGS} ${COMMON_FLAGS} ${INCLUDE_FLAGS} ${VISIBILITY_FLAGS}"
|
|
|
|
|
|
# Build aml-amaudioutils
|
|
display_alert "AML-AMAUDIOUTILS" "Building aml-amaudioutils..." "info"
|
|
|
|
cd "${build_dir}"
|
|
|
|
# 确保 C++ 文件使用 C++ 编译器
|
|
# 修改 Makefile 中的 C++ 编译规则
|
|
if [[ -f "${build_dir}/Makefile" ]]; then
|
|
display_alert "AML-AMAUDIOUTILS" "确保 Makefile 正确编译 C++ 文件..." "info"
|
|
|
|
# 备份原 Makefile
|
|
cp "${build_dir}/Makefile" "${build_dir}/Makefile.orig"
|
|
|
|
# 修改 C++ 编译规则,使用 $(CXX) 而不是 $(CC)
|
|
sed -i 's/^\$(AML_BUILD_DIR)\/%.o: %.cpp$$/$(AML_BUILD_DIR)\/%.o: %.cpp/' "${build_dir}/Makefile"
|
|
sed -i 's/^ \$(CC) -c \$(CFLAGS) \$(CXXFLAGS) -o \$\@ \$\<$$/ $(CXX) -c $(CFLAGS) $(CXXFLAGS) -o $@ $</' "${build_dir}/Makefile"
|
|
|
|
display_alert "AML-AMAUDIOUTILS" "已更新 Makefile 使用 C++ 编译器" "success"
|
|
fi
|
|
|
|
# 注意:COMMON_FLAGS 中已经包含 -DEXPORT=,这里不需要重复定义
|
|
|
|
# 直接修改 str_parms.h 和 str_parms.cpp 文件,确保 C 链接
|
|
local str_parms_h_file="${build_dir}/include/cutils/str_parms.h"
|
|
local str_parms_cpp_file="${build_dir}/src/cutils/str_parms.cpp"
|
|
|
|
if [[ -f "${str_parms_h_file}" ]]; then
|
|
display_alert "AML-AMAUDIOUTILS" "确保 ${str_parms_h_file} 使用正确的 C 链接..." "info"
|
|
|
|
# 备份原文件
|
|
cp "${str_parms_h_file}" "${str_parms_h_file}.orig"
|
|
|
|
# 在 __BEGIN_DECLS 前添加明确的 extern "C" 开始
|
|
# 在 __END_DECLS 后添加明确的 extern "C" 结束
|
|
sed -i 's/__BEGIN_DECLS/#ifdef __cplusplus\nextern "C" {\n#endif/' "${str_parms_h_file}"
|
|
sed -i 's/__END_DECLS/#ifdef __cplusplus\n}\n#endif/' "${str_parms_h_file}"
|
|
|
|
display_alert "AML-AMAUDIOUTILS" "已更新 str_parms.h 确保 C 链接" "success"
|
|
fi
|
|
|
|
if [[ -f "${str_parms_cpp_file}" ]]; then
|
|
display_alert "AML-AMAUDIOUTILS" "确保 ${str_parms_cpp_file} 使用 C 链接..." "info"
|
|
|
|
# 备份原文件
|
|
cp "${str_parms_cpp_file}" "${str_parms_cpp_file}.orig"
|
|
|
|
# 使用更兼容的方式在文件开头添加 extern "C" 包装
|
|
# 创建一个临时文件
|
|
local temp_file="${str_parms_cpp_file}.tmp"
|
|
{
|
|
echo '// C linkage fix - added by amlbian build script'
|
|
echo '#ifdef __cplusplus'
|
|
echo 'extern "C" {'
|
|
echo '#endif'
|
|
echo ''
|
|
cat "${str_parms_cpp_file}"
|
|
echo ''
|
|
echo '#ifdef __cplusplus'
|
|
echo '}'
|
|
echo '#endif'
|
|
} > "${temp_file}"
|
|
|
|
# 用临时文件替换原文件
|
|
mv "${temp_file}" "${str_parms_cpp_file}"
|
|
|
|
display_alert "AML-AMAUDIOUTILS" "已更新 str_parms.cpp 确保 C 链接" "success"
|
|
fi
|
|
|
|
# Create output directory
|
|
local out_dir="${build_dir}/output"
|
|
mkdir -p "${out_dir}"
|
|
|
|
# Build with appropriate flags
|
|
make ${extra_flags} \
|
|
AML_BUILD_DIR="${out_dir}" \
|
|
STAGING_DIR="${out_dir}" \
|
|
TARGET_DIR="${out_dir}" \
|
|
CC="${CC}" \
|
|
CFLAGS="${CFLAGS}" \
|
|
LDFLAGS="${LDFLAGS}" \
|
|
ARCH="${ARCH}" \
|
|
-j$(nproc) \
|
|
"${out_dir}/libcutils.so" \
|
|
2>&1 | tee make.log || {
|
|
display_alert "AML-AMAUDIOUTILS" "Build failed" "err"
|
|
return 1
|
|
}
|
|
|
|
# Copy built library to output directory
|
|
cp -f "${build_dir}/libcutils.so" "${out_dir}/" 2>/dev/null || true
|
|
|
|
display_alert "AML-AMAUDIOUTILS" "Build completed successfully" "success"
|
|
return 0
|
|
}
|
|
|
|
function __aml_amaudioutils_install {
|
|
local build_dir="${1}"
|
|
local install_dir="${2}"
|
|
|
|
display_alert "AML-AMAUDIOUTILS" "Installing aml-amaudioutils..." "info"
|
|
|
|
local out_dir="${build_dir}/output"
|
|
|
|
if [[ ! -d "${out_dir}" ]]; then
|
|
display_alert "AML-AMAUDIOUTILS" "Output directory not found: ${out_dir}" "err"
|
|
return 1
|
|
fi
|
|
|
|
# Create installation directories
|
|
mkdir -p "${install_dir}/usr/lib"
|
|
mkdir -p "${install_dir}/usr/include/audio_utils"
|
|
mkdir -p "${install_dir}/usr/include/IpcBuffer"
|
|
mkdir -p "${install_dir}/usr/include/cutils"
|
|
|
|
# Install libraries
|
|
display_alert "AML-AMAUDIOUTILS" "Installing libraries..." "info"
|
|
|
|
# Copy library files
|
|
local lib_files=("libamaudioutils.so" "libcutils.so")
|
|
for lib_file in "${lib_files[@]}"; do
|
|
if [[ -f "${out_dir}/${lib_file}" ]]; then
|
|
install -m 0644 "${out_dir}/${lib_file}" "${install_dir}/usr/lib/"
|
|
display_alert "AML-AMAUDIOUTILS" "Installed ${lib_file} to ${install_dir}/usr/lib/" "debug"
|
|
elif [[ -f "${build_dir}/${lib_file}" ]]; then
|
|
install -m 0644 "${build_dir}/${lib_file}" "${install_dir}/usr/lib/"
|
|
display_alert "AML-AMAUDIOUTILS" "Installed ${lib_file}" "debug"
|
|
fi
|
|
done
|
|
|
|
# Install headers
|
|
display_alert "AML-AMAUDIOUTILS" "Installing headers..." "info"
|
|
if [[ -d "${build_dir}/include/audio_utils" ]]; then
|
|
cp -r "${build_dir}/include/audio_utils/"* "${install_dir}/usr/include/audio_utils/" 2>/dev/null || true
|
|
display_alert "AML-AMAUDIOUTILS" "Installed audio_utils headers" "debug"
|
|
fi
|
|
if [[ -d "${build_dir}/include/IpcBuffer" ]]; then
|
|
cp -r "${build_dir}/include/IpcBuffer/"* "${install_dir}/usr/include/IpcBuffer/" 2>/dev/null || true
|
|
display_alert "AML-AMAUDIOUTILS" "Installed IpcBuffer headers" "debug"
|
|
fi
|
|
if [[ -d "${build_dir}/include/cutils" ]]; then
|
|
cp -r "${build_dir}/include/cutils/"* "${install_dir}/usr/include/cutils/" 2>/dev/null || true
|
|
display_alert "AML-AMAUDIOUTILS" "Installed cutils headers" "debug"
|
|
fi
|
|
|
|
display_alert "AML-AMAUDIOUTILS" "Installation completed successfully" "success"
|
|
return 0
|
|
}
|
|
|
|
function __aml_amaudioutils_create_deb {
|
|
local build_dir="${1}"
|
|
local install_dir="${2}"
|
|
|
|
# Package details
|
|
local pkg_name="amaudioutils"
|
|
local version="${AML_AMAUDIOUTILS_VERSION}"
|
|
local architecture="${ARCH:-arm64}"
|
|
local maintainer="Amlbian Builder <[email protected]>"
|
|
local description="Amlogic Audio Utilities library"
|
|
local description_long="This package provides audio utilities libraries for Amlogic platforms, including libamaudioutils and libcutils."
|
|
|
|
display_alert "AML-AMAUDIOUTILS" "Creating Debian package for ${pkg_name} ${version}..." "info"
|
|
|
|
# Create Debian package directory structure
|
|
local deb_dir="${build_dir}/deb/${pkg_name}-${version}"
|
|
local debian_dir="${deb_dir}/DEBIAN"
|
|
|
|
mkdir -p "${debian_dir}"
|
|
|
|
# Copy installed files to package directory
|
|
if [[ -d "${install_dir}" ]] && [[ "$(ls -A "${install_dir}")" ]]; then
|
|
cp -r "${install_dir}"/* "${deb_dir}/" 2>/dev/null || true
|
|
display_alert "AML-AMAUDIOUTILS" "Copied installed files to ${deb_dir}" "info"
|
|
else
|
|
display_alert "AML-AMAUDIOUTILS" "No installed files found in ${install_dir}" "warning"
|
|
return 0
|
|
fi
|
|
|
|
# Create control file
|
|
cat > "${debian_dir}/control" <<EOF
|
|
Package: ${pkg_name}
|
|
Version: ${version}
|
|
Architecture: ${architecture}
|
|
Maintainer: ${maintainer}
|
|
Description: ${description}
|
|
${description_long}
|
|
Depends: libc6, liblog
|
|
Section: libs
|
|
Priority: optional
|
|
EOF
|
|
|
|
# Create postinst script for ldconfig
|
|
cat > "${debian_dir}/postinst" << 'POSTINST_EOF'
|
|
#!/bin/sh
|
|
set -e
|
|
|
|
if [ "$1" = "configure" ]; then
|
|
# Update ldconfig cache
|
|
if command -v ldconfig >/dev/null 2>&1; then
|
|
ldconfig
|
|
fi
|
|
fi
|
|
|
|
exit 0
|
|
POSTINST_EOF
|
|
|
|
chmod 755 "${debian_dir}/postinst"
|
|
|
|
# Create prerm script
|
|
cat > "${debian_dir}/prerm" << '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
|
|
fi
|
|
|
|
exit 0
|
|
PRERM_EOF
|
|
|
|
chmod 755 "${debian_dir}/prerm"
|
|
|
|
display_alert "AML-AMAUDIOUTILS" "Building Debian package..." "info"
|
|
|
|
# Build Debian package
|
|
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 "AML-AMAUDIOUTILS" "Debian package created: ${output_dir}/linux-${pkg_name}-${BOARD}-amlbian_${version}_${architecture}.deb" "success"
|
|
else
|
|
display_alert "AML-AMAUDIOUTILS" "Failed to build Debian package" "err"
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
function amlbian_build_aml_amaudioutils {
|
|
if ! is_unit_enabled "amaudioutils" && ! is_unit_enabled "tvserver"; then
|
|
display_alert "[SKIP] >> aml-amaudioutils disable in BUILD_UNITS" "" "info"
|
|
return
|
|
fi
|
|
|
|
if ! is_feature_contains "$DISTRO_FEATURES" "tvserver"; then
|
|
display_alert "[SKIP] >> tvserver disable in DISTRO_FEATURES" "" "info"
|
|
return
|
|
fi
|
|
|
|
display_alert "AMLOGIC: Building aml-amaudioutils ${AML_AMAUDIOUTILS_VERSION} ${BOARD}" "info"
|
|
|
|
# Define all directory paths (in .tmp directory)
|
|
local build_root="${BUILD_DIR}/.tmp/aml-amaudioutils-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"
|
|
|
|
# 准备源代码
|
|
__aml_amaudioutils_prepare_source "${build_dir}"
|
|
|
|
# 构建
|
|
if ! __aml_amaudioutils_build "${build_dir}"; then
|
|
display_alert "AMLOGIC: aml-amaudioutils build failed" "err"
|
|
return 1
|
|
fi
|
|
|
|
# 安装到安装目录
|
|
if ! __aml_amaudioutils_install "${build_dir}" "${install_dir}"; then
|
|
display_alert "AMLOGIC: aml-amaudioutils installation failed" "err"
|
|
return 1
|
|
fi
|
|
|
|
display_alert "AMLOGIC: Creating Debian package..." "info"
|
|
__aml_amaudioutils_create_deb "${build_dir}" "${install_dir}"
|
|
|
|
__unset_aml_amaudioutils_config
|
|
|
|
return 0
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Section 5: Main
|
|
# ==============================================================================
|
|
|
|
display_alert "AMLIbian AML-AMAUDIOUTILS Build Script" "Version: ${AML_AMAUDIOUTILS_VERSION}, Board: ${BOARD}" "info"
|
|
|
|
amlbian_build_aml_amaudioutils
|
|
|
|
display_alert "AMLOGIC: aml-amaudioutils build completed" "${BUILD_DIR}/output" "info"
|
|
|
|
# ==============================================================================
|
|
# End of build-aml-amaudioutils.sh
|
|
# ============================================================================== |