449 lines
15 KiB
Bash
449 lines
15 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# Copyright (c) 2026 AMLOGIC
|
|
#
|
|
# MediaCtrlSrc build script for AMLbian
|
|
# This script builds mediactrlsrc libraries for Amlogic SoCs
|
|
# Based on mediactrlsrc.bb 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}"
|
|
MEDIACTRLSRC_VERSION="${MEDIACTRLSRC_VERSION:-1.0.0}"
|
|
: "${ARCH:=arm64}"
|
|
KERNEL_VERSION="${KERNEL_VERSION:-6.12}"
|
|
|
|
# Feature flags from DISTRO_FEATURES
|
|
|
|
CAMERA_ENABLE="${CAMERA_ENABLE:-false}"
|
|
HDMIRX_ENABLE="${HDMIRX_ENABLE:-false}"
|
|
|
|
# ==============================================================================
|
|
# Section 4: MediaCtrlSrc Build Functions
|
|
# ==============================================================================
|
|
|
|
function __unset_mediactrlsrc_config {
|
|
# Clean up any environment variables set during build
|
|
unset CFLAGS
|
|
unset CXXFLAGS
|
|
unset LDFLAGS
|
|
unset AMLSRC_MEDIACTRL_CAM
|
|
unset AMLSRC_MEDIACTRL_HDMI
|
|
}
|
|
|
|
function __mediactrlsrc_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 "MEDIACTRLSRC" "aml-comp not found: ${aml_comp_path}" "err"
|
|
exit 1
|
|
fi
|
|
|
|
local source_dir="${aml_comp_path}/vendor/amlogic/mediactrlsrc"
|
|
|
|
if [[ ! -d "${source_dir}" ]]; then
|
|
display_alert "MEDIACTRLSRC" "Source directory not found: ${source_dir}" "err"
|
|
exit 1
|
|
fi
|
|
|
|
display_alert "MEDIACTRLSRC" "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}/Makefile" ]]; then
|
|
display_alert "MEDIACTRLSRC" "Makefile not found in source" "err"
|
|
exit 1
|
|
fi
|
|
|
|
display_alert "MEDIACTRLSRC" "Source prepared successfully" "success"
|
|
}
|
|
|
|
function __mediactrlsrc_build {
|
|
local build_dir="${1}"
|
|
|
|
display_alert "MEDIACTRLSRC" "Starting mediactrlsrc build..." "info"
|
|
|
|
if [[ ! -d "${build_dir}" ]]; then
|
|
display_alert "MEDIACTRLSRC" "Build directory not found: ${build_dir}" "err"
|
|
return 1
|
|
fi
|
|
|
|
# Set build environment
|
|
: "${ARCH:=arm64}"
|
|
CROSS_COMPILE="${CROSS_COMPILE:-aarch64-linux-gnu-}"
|
|
|
|
export ARCH
|
|
export CROSS_COMPILE="${CROSS_COMPILE}"
|
|
|
|
export AMLSRC_MEDIACTRL_CAM="${CAMERA_ENABLE}"
|
|
export AMLSRC_MEDIACTRL_HDMI="${HDMIRX_ENABLE}"
|
|
|
|
display_alert "MEDIACTRLSRC" "CAMERA_ENABLE=${CAMERA_ENABLE}" "info"
|
|
display_alert "MEDIACTRLSRC" "HDMIRX_ENABLE=${HDMIRX_ENABLE}" "info"
|
|
|
|
if [[ -n "${ROOTFS_TEMP}" ]] && [[ -d "${ROOTFS_TEMP}" ]] && [[ -d "${ROOTFS_TEMP}/usr/lib/aarch64-linux-gnu" ]]; then
|
|
SYSROOT="${ROOTFS_TEMP}"
|
|
display_alert "MEDIACTRLSRC" "Using ROOTFS_TEMP as sysroot: ${SYSROOT}" "info"
|
|
else
|
|
display_alert "MEDIACTRLSRC" "ROOTFS_TEMP not found or invalid: ${ROOTFS_TEMP}" "err"
|
|
display_alert "MEDIACTRLSRC" "ROOTFS_TEMP should be created by create_base_rootfs function" "err"
|
|
return 1
|
|
fi
|
|
|
|
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}"
|
|
|
|
local include_flags="-I${ROOTFS_TEMP}/usr/include/aarch64-linux-gnu \
|
|
-I${ROOTFS_TEMP}/usr/include/glib-2.0 \
|
|
-I${ROOTFS_TEMP}/usr/lib/aarch64-linux-gnu/glib-2.0/include"
|
|
|
|
export CPPFLAGS="${CPPFLAGS} ${include_flags}"
|
|
export CFLAGS="${CFLAGS} ${include_flags}"
|
|
export CXXFLAGS="${CXXFLAGS} ${include_flags}"
|
|
|
|
export LDFLAGS="${LDFLAGS} -L${ROOTFS_TEMP}/usr/lib/aarch64-linux-gnu -L${ROOTFS_TEMP}/usr/aarch64-linux-gnu/lib"
|
|
export LDFLAGS="${LDFLAGS} -Wl,-rpath-link,${ROOTFS_TEMP}/usr/lib/aarch64-linux-gnu"
|
|
|
|
cd "${build_dir}"
|
|
|
|
# Create output directory
|
|
local out_dir="${build_dir}/output"
|
|
mkdir -p "${out_dir}"
|
|
|
|
display_alert "MEDIACTRLSRC" "Building using Makefile..." "info"
|
|
display_alert "MEDIACTRLSRC" "CC=${CC}" "debug"
|
|
|
|
# Add include paths
|
|
local current_cflags="${CFLAGS}"
|
|
current_cflags="${current_cflags} -I${build_dir}/include -I${build_dir}/amlv4l2src -I${build_dir}/amlv4l2src/amlsrc"
|
|
|
|
# Build flags from mediactrlsrc.bb
|
|
current_cflags="${current_cflags} -Wno-unused-result -Wno-unused-variable -Wno-unused-function -Os"
|
|
|
|
export CFLAGS="${current_cflags}"
|
|
export CXXFLAGS="${CXXFLAGS} ${current_cflags}"
|
|
|
|
# Run make with OUT_DIR pointing to our output directory
|
|
make OUT_DIR="${out_dir}" \
|
|
TARGET_DIR="${out_dir}" \
|
|
STAGING_DIR="${out_dir}" \
|
|
CC="${CC}" \
|
|
CFLAGS="${CFLAGS} -fPIC -Wall" \
|
|
LDFLAGS="${LDFLAGS}" \
|
|
-j$(nproc) \
|
|
2>&1 | tee "${out_dir}/make.log" || {
|
|
display_alert "MEDIACTRLSRC" "Build failed" "err"
|
|
return 1
|
|
}
|
|
|
|
# Verify the libraries were created
|
|
local libs_created=0
|
|
local expected_libs=("libamlv4l2src.so" "libamlsrc.so")
|
|
|
|
if [[ "${CAMERA_ENABLE}" == "true" ]]; then
|
|
expected_libs+=("libcamsrc.so")
|
|
fi
|
|
|
|
if [[ "${HDMIRX_ENABLE}" == "true" ]]; then
|
|
expected_libs+=("libhdmisrc.so")
|
|
fi
|
|
|
|
for lib in "${expected_libs[@]}"; do
|
|
if [[ -f "${out_dir}/${lib}" ]]; then
|
|
display_alert "MEDIACTRLSRC" "Library created: ${out_dir}/${lib}" "info"
|
|
libs_created=$((libs_created + 1))
|
|
else
|
|
display_alert "MEDIACTRLSRC" "Library not found: ${lib}" "warn"
|
|
fi
|
|
done
|
|
|
|
if [[ ${libs_created} -gt 0 ]]; then
|
|
display_alert "MEDIACTRLSRC" "Build completed successfully (${libs_created} libraries)" "success"
|
|
else
|
|
display_alert "MEDIACTRLSRC" "No libraries were created" "err"
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
function __mediactrlsrc_install {
|
|
local build_dir="${1}"
|
|
local install_dir="${2}"
|
|
|
|
display_alert "MEDIACTRLSRC" "Installing mediactrlsrc..." "info"
|
|
|
|
local out_dir="${build_dir}/output"
|
|
|
|
if [[ ! -d "${out_dir}" ]]; then
|
|
display_alert "MEDIACTRLSRC" "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"
|
|
mkdir -p "${install_dir}/usr/bin"
|
|
|
|
# Install common libraries
|
|
display_alert "MEDIACTRLSRC" "Installing common libraries..." "info"
|
|
|
|
local common_libs=("libamlv4l2src.so" "libamlsrc.so")
|
|
for lib in "${common_libs[@]}"; do
|
|
if [[ -f "${out_dir}/${lib}" ]]; then
|
|
install -m 0644 "${out_dir}/${lib}" "${install_dir}/usr/lib/"
|
|
display_alert "MEDIACTRLSRC" "Installed ${lib} to ${install_dir}/usr/lib/" "debug"
|
|
fi
|
|
done
|
|
|
|
# Install camera components if enabled
|
|
if [[ "${CAMERA_ENABLE}" == "true" ]]; then
|
|
display_alert "MEDIACTRLSRC" "Installing camera components..." "info"
|
|
|
|
if [[ -f "${out_dir}/libcamsrc.so" ]]; then
|
|
install -m 0644 "${out_dir}/libcamsrc.so" "${install_dir}/usr/lib/"
|
|
display_alert "MEDIACTRLSRC" "Installed libcamsrc.so" "debug"
|
|
fi
|
|
|
|
if [[ -f "${out_dir}/camctrl" ]]; then
|
|
install -m 0755 "${out_dir}/camctrl" "${install_dir}/usr/bin/"
|
|
display_alert "MEDIACTRLSRC" "Installed camctrl to ${install_dir}/usr/bin/" "debug"
|
|
fi
|
|
fi
|
|
|
|
# Install HDMI components if enabled
|
|
if [[ "${HDMIRX_ENABLE}" == "true" ]]; then
|
|
display_alert "MEDIACTRLSRC" "Installing HDMI components..." "info"
|
|
|
|
if [[ -f "${out_dir}/libhdmisrc.so" ]]; then
|
|
install -m 0644 "${out_dir}/libhdmisrc.so" "${install_dir}/usr/lib/"
|
|
display_alert "MEDIACTRLSRC" "Installed libhdmisrc.so" "debug"
|
|
fi
|
|
|
|
if [[ -f "${out_dir}/hdmictrl" ]]; then
|
|
install -m 0755 "${out_dir}/hdmictrl" "${install_dir}/usr/bin/"
|
|
display_alert "MEDIACTRLSRC" "Installed hdmictrl to ${install_dir}/usr/bin/" "debug"
|
|
fi
|
|
fi
|
|
|
|
# Install headers
|
|
display_alert "MEDIACTRLSRC" "Installing headers..." "info"
|
|
|
|
# Install amlv4l2src.h
|
|
local amlv4l2src_header="${build_dir}/amlv4l2src/amlv4l2src.h"
|
|
if [[ -f "${amlv4l2src_header}" ]]; then
|
|
install -m 0644 -D "${amlv4l2src_header}" "${install_dir}/usr/include/"
|
|
display_alert "MEDIACTRLSRC" "Installed amlv4l2src.h to ${install_dir}/usr/include/" "debug"
|
|
fi
|
|
|
|
# Install include/*.h files
|
|
local include_dir="${build_dir}/include"
|
|
if [[ -d "${include_dir}" ]]; then
|
|
for header in "${include_dir}"/*.h; do
|
|
if [[ -f "${header}" ]]; then
|
|
install -m 0644 "${header}" "${install_dir}/usr/include/"
|
|
display_alert "MEDIACTRLSRC" "Installed $(basename "${header}")" "debug"
|
|
fi
|
|
done
|
|
fi
|
|
|
|
display_alert "MEDIACTRLSRC" "Installation completed successfully" "success"
|
|
return 0
|
|
}
|
|
|
|
function __mediactrlsrc_create_deb {
|
|
local build_dir="${1}"
|
|
local install_dir="${2}"
|
|
|
|
# Package details
|
|
local pkg_name="mediactrlsrc"
|
|
local version="${MEDIACTRLSRC_VERSION}"
|
|
local architecture="${ARCH:-arm64}"
|
|
local maintainer="Amlbian Builder <[email protected]>"
|
|
local description="Amlogic Media Control Source libraries"
|
|
local description_long="This package provides media control source libraries for Amlogic platforms, including camera and HDMI input support."
|
|
|
|
display_alert "MEDIACTRLSRC" "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 "MEDIACTRLSRC" "Copied installed files to ${deb_dir}" "info"
|
|
else
|
|
display_alert "MEDIACTRLSRC" "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
|
|
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 "MEDIACTRLSRC" "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 "MEDIACTRLSRC" "Debian package created: ${output_dir}/linux-${pkg_name}-${BOARD}-amlbian_${version}_${architecture}.deb" "success"
|
|
else
|
|
display_alert "MEDIACTRLSRC" "Failed to build Debian package" "err"
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
function amlbian_build_mediactrlsrc {
|
|
# Check if mediactrlsrc is enabled in BUILD_UNITS
|
|
if ! is_unit_enabled "mediactrlsrc"; then
|
|
display_alert "[SKIP] >> mediactrlsrc disable in BUILD_UNITS" "" "info"
|
|
return
|
|
fi
|
|
|
|
if ! is_feature_contains "$DISTRO_FEATURES" "mediactrlsrc"; then
|
|
display_alert "[SKIP] >> mediactrlsrc disable in DISTRO_FEATURES" "" "info"
|
|
return
|
|
fi
|
|
|
|
CAMERA_ENABLE="false"
|
|
HDMIRX_ENABLE="true"
|
|
|
|
display_alert "AMLOGIC: Building mediactrlsrc ${MEDIACTRLSRC_VERSION} ${BOARD}" "info"
|
|
display_alert "AMLOGIC: Camera support: ${CAMERA_ENABLE}" "info"
|
|
display_alert "AMLOGIC: HDMI support: ${HDMIRX_ENABLE}" "info"
|
|
|
|
# Define all directory paths (in .tmp directory)
|
|
local build_root="${BUILD_DIR}/.tmp/mediactrlsrc-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"
|
|
|
|
# 准备源代码
|
|
__mediactrlsrc_prepare_source "${build_dir}"
|
|
|
|
# 构建
|
|
if ! __mediactrlsrc_build "${build_dir}"; then
|
|
display_alert "AMLOGIC: mediactrlsrc build failed" "err"
|
|
return 1
|
|
fi
|
|
|
|
# 安装到安装目录
|
|
if ! __mediactrlsrc_install "${build_dir}" "${install_dir}"; then
|
|
display_alert "AMLOGIC: mediactrlsrc installation failed" "err"
|
|
return 1
|
|
fi
|
|
|
|
display_alert "AMLOGIC: Creating Debian package..." "info"
|
|
__mediactrlsrc_create_deb "${build_dir}" "${install_dir}"
|
|
|
|
__unset_mediactrlsrc_config
|
|
|
|
return 0
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Section 5: Main
|
|
# ==============================================================================
|
|
|
|
display_alert "AMLIbian MediaCtrlSrc Build Script" "Version: ${MEDIACTRLSRC_VERSION}, Board: ${BOARD}" "info"
|
|
|
|
amlbian_build_mediactrlsrc
|
|
|
|
display_alert "AMLOGIC: mediactrlsrc build completed" "${BUILD_DIR}/output" "info"
|
|
|
|
# ==============================================================================
|
|
# End of build-mediactrlsrc.sh
|
|
# ============================================================================== |