Files
2026-08-24 10:03:24 +08:00

400 lines
13 KiB
Bash

#!/usr/bin/env bash
#
# SPDX-License-Identifier: GPL-2.0
#
# Copyright (c) 2026 AMLOGIC
#
# gst-plugin-conv build script for AMLbian
# This script builds gst-plugin-conv library for Amlogic SoCs
set -e
umask 022
# Get script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
AMLBIAN_DIR="$(dirname "${SCRIPT_DIR}")" # amlbian/scripts/multimedia
AMLBIAN_DIR="$(dirname "${AMLBIAN_DIR}")" # amlbian/scripts
AMLBIAN_DIR="$(dirname "${AMLBIAN_DIR}")" # amlbian
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}"
DEB_VERSION="${GST_PLUGIN_CONV_VERSION:-1.0}"
#ARCH="${ARCH:-arm64}"
: "${ARCH:=arm64}"
# ==============================================================================
# Section 4: gst-plugin-conv Build Functions
# ==============================================================================
function __unset_gst_plugin_conv_config {
# Clean up any environment variables set during build
unset EXTRA_OEMAKE
unset SYSROOT
unset CFLAGS
unset CXXFLAGS
unset LDFLAGS
unset CPPFLAGS
}
function __gst_plugin_conv_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 "GST-PLUGIN-CONV" "aml-comp not found: ${aml_comp_path}" "err"
exit 1
fi
local source_dir="${aml_comp_path}/multimedia/gst-aml-utils/gst-plugin-conv"
if [[ ! -d "${source_dir}" ]]; then
display_alert "GST-PLUGIN-CONV" "Source directory not found: ${source_dir}" "err"
exit 1
fi
display_alert "GST-PLUGIN-CONV" "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 [[ ! -f "${build_dir}/gst-plugin-conv/configure.ac" ]] && [[ ! -f "${build_dir}/gst-plugin-conv/configure" ]]; then
display_alert "GST-PLUGIN-CONV" "Configure script not found in source" "warning"
fi
display_alert "GST-PLUGIN-CONV" "Source prepared successfully" "success"
}
function __gst_plugin_conv_build {
local build_dir="${1}"
local install_dir="${2}"
display_alert "GST-PLUGIN-CONV" "Starting gst-plugin-conv build..." "info"
# 检查源目录
local src_dir="${build_dir}/gst-plugin-conv"
if [[ ! -d "${src_dir}" ]]; then
display_alert "GST-PLUGIN-CONV" "Source directory not found: ${src_dir}" "err"
return 1
fi
# 设置编译环境
#ARCH="${ARCH:-arm64}"
: "${ARCH:=arm64}"
CROSS_COMPILE="${CROSS_COMPILE:-aarch64-linux-gnu-}"
export ARCH
export CROSS_COMPILE="${CROSS_COMPILE}"
# amlbian_checkout_toolchain
# Check if ROOTFS_TEMP exists, use it as sysroot, otherwise error
local SYSROOT=""
if [[ -n "${ROOTFS_TEMP}" ]] && [[ -d "${ROOTFS_TEMP}" ]] && [[ -d "${ROOTFS_TEMP}/usr/lib/aarch64-linux-gnu" ]]; then
SYSROOT="${ROOTFS_TEMP}"
display_alert "GST-PLUGIN-CONV" "Using ROOTFS_TEMP as sysroot: ${SYSROOT}" "info"
else
display_alert "GST-PLUGIN-CONV" "ROOTFS_TEMP not found or invalid: ${ROOTFS_TEMP}" "err"
display_alert "GST-PLUGIN-CONV" "ROOTFS_TEMP should be created by create_base_rootfs function" "err"
return 1
fi
# Use sysroot configuration
display_alert "GST-PLUGIN-CONV" "Using sysroot: ${SYSROOT}" "info"
export PKG_CONFIG=/usr/bin/pkg-config
export PKG_CONFIG_SYSROOT_DIR="${SYSROOT}"
export PKG_CONFIG_LIBDIR="${SYSROOT}/usr/lib/aarch64-linux-gnu/pkgconfig:${SYSROOT}/usr/share/pkgconfig"
unset PKG_CONFIG_PATH
# Set up flags with sysroot
export CPPFLAGS="${CPPFLAGS} --sysroot=${SYSROOT}"
export CFLAGS="${CFLAGS} --sysroot=${SYSROOT} -fPIC"
export CXXFLAGS="${CXXFLAGS} --sysroot=${SYSROOT} -fPIC"
export LDFLAGS="${LDFLAGS} --sysroot=${SYSROOT}"
# Add sysroot-specific include paths
local include_flags="-I${SYSROOT}/usr/include/aarch64-linux-gnu \
-I${SYSROOT}/usr/include/gstreamer-1.0 \
-I${SYSROOT}/usr/include/glib-2.0 \
-I${SYSROOT}/usr/lib/aarch64-linux-gnu/glib-2.0/include \
-I${SYSROOT}/usr/include/libge2d \
-I${SYSROOT}/usr/include/libdrm \
-I${src_dir}/inc"
export CPPFLAGS="${CPPFLAGS} ${include_flags}"
export CFLAGS="${CFLAGS} ${include_flags}"
export CXXFLAGS="${CXXFLAGS} ${include_flags}"
# Add sysroot-specific library paths
export LDFLAGS="${LDFLAGS} -L${SYSROOT}/usr/lib/aarch64-linux-gnu -L${SYSROOT}/usr/aarch64-linux-gnu/lib"
# 进入源代码目录
cd "${src_dir}" || {
display_alert "GST-PLUGIN-CONV" "Cannot enter source directory: ${src_dir}" "err"
return 1
}
# 1. version config (non-fatal)
if [[ -f "version_config.sh" ]]; then
chmod +x version_config.sh
./version_config.sh "${src_dir}" 2>&1 | tee version.log || true
fi
# 2. clean autotools state
rm -rf config.cache config.status autom4te.cache
# 3. regenerate configure if needed
if [[ ! -f "./configure" ]]; then
display_alert "GST-PLUGIN-CONV" "Regenerating configure script..." "info"
autoreconf -fi 2>&1 | tee autoreconf.log || {
display_alert "GST-PLUGIN-CONV" "autoreconf failed" "err"
return 1
}
fi
# 4. configure
display_alert "GST-PLUGIN-CONV" "Configuring build..." "info"
./configure \
--prefix=/usr \
--libdir=/usr/lib/aarch64-linux-gnu \
--host=aarch64-linux-gnu \
--build=x86_64-linux-gnu \
CC="${CROSS_COMPILE}gcc" \
CFLAGS="${CFLAGS}" \
LDFLAGS="${LDFLAGS}" \
2>&1 | tee config.log || {
display_alert "GST-PLUGIN-CONV" "configure failed" "err"
return 1
}
# 5. build
display_alert "GST-PLUGIN-CONV" "Building..." "info"
local extra_oemake="CROSS=${CROSS_COMPILE} STAGING_DIR=${install_dir} DESTDIR=${install_dir}"
make -j$(nproc) ${extra_oemake} \
LDFLAGS="${LDFLAGS}" \
2>&1 | tee make.log || {
display_alert "GST-PLUGIN-CONV" "make failed" "err"
return 1
}
# 6. install
display_alert "GST-PLUGIN-CONV" "Installing..." "info"
make DESTDIR=${install_dir} install 2>&1 | tee install.log || {
display_alert "GST-PLUGIN-CONV" "install failed" "err"
return 1
}
display_alert "GST-PLUGIN-CONV" "Build completed successfully" "success"
return 0
}
function __gst_plugin_conv_install {
local build_dir="${1}"
local install_dir="${2}"
display_alert "GST-PLUGIN-CONV" "Installing gst-plugin-conv library..." "info"
# 安装目录已经在构建过程中创建了,这里只需验证
local src_dir="${build_dir}/gst-plugin-conv"
if [[ ! -d "${install_dir}" ]]; then
display_alert "GST-PLUGIN-CONV" "Install directory not found: ${install_dir}" "err"
return 1
fi
# 验证安装的文件
local lib_dir="${install_dir}/usr/lib/aarch64-linux-gnu/gstreamer-1.0"
if [[ -f "${lib_dir}/libgstamlvconv.so" ]]; then
display_alert "GST-PLUGIN-CONV" "Library file installed successfully" "info"
else
display_alert "GST-PLUGIN-CONV" "No library file found in install directory" "warning"
fi
display_alert "GST-PLUGIN-CONV" "Installation completed" "success"
return 0
}
function __gst_plugin_conv_create_deb {
local build_dir="${1}"
local install_dir="${2}"
# 设置必要的变量
local pkg_name="gst-plugin-conv"
local version="${DEB_VERSION}"
local architecture="${ARCH}"
local maintainer="Armbian Build <[email protected]>"
local description="Amlogic video conversion GStreamer plugin with GE2D HW"
local description_long="This package provides Amlogic-specific video conversion plugin for GStreamer. This plugin enables GStreamer to use Amlogic's GE2D hardware-accelerated video conversion operations for multimedia processing. It depends on gst-aml-dma-allocator, gst-aml-gfx2d, and gst-aml-drmbufferpool-plugins."
display_alert "GST-PLUGIN-CONV" "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 "GST-PLUGIN-CONV" "Copied installed files to ${deb_dir}" "info"
else
display_alert "GST-PLUGIN-CONV" "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: libgstreamer1.0-0 (>= 1.0.0), gstreamer1.0-plugins-base (>= 1.0.0), libge2d, libdrm2 (>= 2.4.0), gst-aml-dma-allocator, gst-aml-gfx2d, gst-aml-drmbufferpool-plugins
Section: libs
Priority: optional
EOF
# 创建postinst脚本,用于更新ldconfig和GStreamer插件缓存
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
# 更新GStreamer插件缓存
if command -v gst-inspect-1.0 >/dev/null 2>&1; then
gst-inspect-1.0 --gst-info >/dev/null 2>&1 || true
fi
echo "gst-plugin-conv 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 gst-plugin-conv"
fi
exit 0
EOF
chmod 755 "${debian_dir}/prerm"
display_alert "GST-PLUGIN-CONV" "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"
chmod 755 "${output_dir}/linux-${pkg_name}-${BOARD}-amlbian_${version}_${architecture}.deb"
display_alert "GST-PLUGIN-CONV" "Debian package created: ${output_dir}/linux-${pkg_name}-${BOARD}-amlbian_${version}_${architecture}.deb" "success"
else
display_alert "GST-PLUGIN-CONV" "Failed to build Debian package" "err"
return 1
fi
return 0
}
function amlbian_build_gst_plugin_conv {
if ! is_unit_enabled "gst-plugin-conv" && ! is_unit_enabled "gst-aml"; then
display_alert "[SKIP] >> gst-plugin-conv disable in BUILD_UNITS" "" "info"
return
fi
display_alert "AMLOGIC: Building gst-plugin-conv ${DEB_VERSION} ${BOARD}" "info"
# Define all directory paths (in .tmp directory)
local build_root="${BUILD_DIR}/.tmp/gst-plugin-conv-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"
# 准备源代码
__gst_plugin_conv_prepare_source "${build_dir}"
# 构建
if ! __gst_plugin_conv_build "${build_dir}" "${install_dir}"; then
display_alert "AMLOGIC: gst-plugin-conv build failed" "err"
return 1
fi
# 安装到安装目录
if ! __gst_plugin_conv_install "${build_dir}" "${install_dir}"; then
display_alert "AMLOGIC: gst-plugin-conv installation failed" "err"
return 1
fi
display_alert "AMLOGIC: Creating Debian package..." "info"
__gst_plugin_conv_create_deb "${build_dir}" "${install_dir}"
__unset_gst_plugin_conv_config
#chmod -R 777 "${build_root}"
rm -rf "${build_root}"
return 0
}
# ==============================================================================
# Section 5: Main
# ==============================================================================
display_alert "AMLbian gst-plugin-conv Build Script" "Version: ${DEB_VERSION}, Board: ${BOARD}" "info"
amlbian_build_gst_plugin_conv
display_alert "AMLOGIC: gst-plugin-conv build completed" "${BUILD_DIR}/output" "info"
# ==============================================================================
# End of build-gst-plugin-conv.sh
# ==============================================================================