356 lines
11 KiB
Bash
356 lines
11 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# SPDX-License-Identifier: GPL-2.0
|
|
#
|
|
# Copyright (c) 2026 AMLOGIC
|
|
#
|
|
# h264bitstream build script for AMLbian
|
|
# This script builds h264bitstream 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"
|
|
MODULE_BUILD_DIR="${SRC}/output/.tmp"
|
|
|
|
# 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="${H264BITSTREAM_VERSION:-1.0}"
|
|
ARCH="${ARCH:-arm64}"
|
|
# ==============================================================================
|
|
# Section 4: h264bitstream Build Functions
|
|
# ==============================================================================
|
|
|
|
function __unset_h264bitstream_config {
|
|
# Clean up any environment variables set during build
|
|
unset SYSROOT
|
|
unset CFLAGS
|
|
unset CXXFLAGS
|
|
unset LDFLAGS
|
|
}
|
|
|
|
function __h264bitstream_prepare_source {
|
|
local build_dir="${1}"
|
|
|
|
local src_uri="${H264BITSTREAM_URI:-https://github.com/aizvorski/h264bitstream.git}"
|
|
local src_rev="${H264BITSTREAM_SRCREV:-34f3c58afa3c47b6cf0a49308a68cbf89c5e0bff}"
|
|
local src_branch="${H264BITSTREAM_BRANCH:-master}"
|
|
|
|
display_alert "H264BITSTREAM" "Cloning source from ${src_uri} to ${build_dir}" "info"
|
|
|
|
# 清空构建目录
|
|
rm -rf "${build_dir}"
|
|
mkdir -p "${build_dir}"
|
|
|
|
git clone "${src_uri}" "${build_dir}" 2>&1 || {
|
|
display_alert "H264BITSTREAM" "git clone failed: ${src_uri}" "err"
|
|
return 1
|
|
}
|
|
|
|
cd "${build_dir}"
|
|
git checkout "${src_branch}" 2>&1 || true
|
|
git checkout "${src_rev}" 2>&1 || {
|
|
display_alert "H264BITSTREAM" "Failed to checkout SRCREV: ${src_rev}" "err"
|
|
return 1
|
|
}
|
|
|
|
# Check for necessary source files
|
|
if [[ ! -f "${build_dir}/configure.ac" ]] && [[ ! -f "${build_dir}/Makefile.am" ]]; then
|
|
display_alert "H264BITSTREAM" "Source files not found in ${build_dir}" "err"
|
|
return 1
|
|
fi
|
|
|
|
display_alert "H264BITSTREAM" "Source prepared successfully" "success"
|
|
}
|
|
|
|
function __h264bitstream_build {
|
|
local build_dir="${1}"
|
|
local install_dir="${2}"
|
|
|
|
display_alert "H264BITSTREAM" "Starting h264bitstream build..." "info"
|
|
|
|
if [[ ! -d "${build_dir}" ]]; then
|
|
display_alert "H264BITSTREAM" "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}"
|
|
|
|
# 创建输出目录
|
|
local out_dir="${build_dir}/output"
|
|
mkdir -p "${out_dir}"
|
|
|
|
export CC="${CROSS_COMPILE}gcc"
|
|
export CXX="${CROSS_COMPILE}g++"
|
|
export AR="${CROSS_COMPILE}ar"
|
|
export CFLAGS="${CFLAGS} -fPIC"
|
|
|
|
# autoreconf 生成 configure
|
|
display_alert "H264BITSTREAM" "Running autoreconf..." "info"
|
|
cd "${build_dir}"
|
|
autoreconf -fi 2>&1 | tee "${out_dir}/autoreconf.log" || {
|
|
display_alert "H264BITSTREAM" "autoreconf failed" "err"
|
|
return 1
|
|
}
|
|
|
|
# configure
|
|
display_alert "H264BITSTREAM" "Configuring..." "info"
|
|
./configure \
|
|
--host="${CROSS_COMPILE%-}" \
|
|
--prefix=/usr \
|
|
--libdir=/usr/lib \
|
|
2>&1 | tee "${out_dir}/configure.log" || {
|
|
display_alert "H264BITSTREAM" "configure failed" "err"
|
|
return 1
|
|
}
|
|
|
|
# 编译
|
|
display_alert "H264BITSTREAM" "Building h264bitstream library..." "info"
|
|
make -j$(nproc) 2>&1 | tee "${out_dir}/make.log" || {
|
|
display_alert "H264BITSTREAM" "Library build failed" "err"
|
|
return 1
|
|
}
|
|
|
|
display_alert "H264BITSTREAM" "Build completed successfully" "success"
|
|
return 0
|
|
}
|
|
|
|
function __h264bitstream_install {
|
|
local build_dir="${1}"
|
|
local install_dir="${2}"
|
|
|
|
display_alert "H264BITSTREAM" "Installing h264bitstream library..." "info"
|
|
|
|
local out_dir="${build_dir}/output"
|
|
|
|
if [[ ! -d "${build_dir}" ]]; then
|
|
display_alert "H264BITSTREAM" "Build directory not found: ${build_dir}" "err"
|
|
return 1
|
|
fi
|
|
|
|
# 创建安装目录结构
|
|
mkdir -p "${install_dir}/usr/include"
|
|
mkdir -p "${install_dir}/usr/lib"
|
|
mkdir -p "${install_dir}/usr/lib/pkgconfig"
|
|
|
|
# 安装库文件
|
|
# 使用 cp -P 保留符号链接,避免 install 解引用导致 ldconfig 报 "not a symbolic link"
|
|
display_alert "H264BITSTREAM" "Installing library..." "info"
|
|
local lib_installed="false"
|
|
local lib_file
|
|
for lib_file in "${build_dir}"/.libs/libh264bitstream.so* "${build_dir}"/libh264bitstream.so*; do
|
|
if [[ -e "${lib_file}" || -L "${lib_file}" ]]; then
|
|
cp -P "${lib_file}" "${install_dir}/usr/lib/"
|
|
lib_installed="true"
|
|
fi
|
|
done
|
|
if [[ "${lib_installed}" != "true" ]]; then
|
|
display_alert "H264BITSTREAM" "Library files not found" "err"
|
|
return 1
|
|
fi
|
|
display_alert "H264BITSTREAM" "Library installed to ${install_dir}/usr/lib/" "info"
|
|
|
|
# 安装头文件
|
|
display_alert "H264BITSTREAM" "Installing headers..." "info"
|
|
local header_file
|
|
for header_file in "${build_dir}"/*.h; do
|
|
if [[ -f "${header_file}" ]]; then
|
|
install -m 0644 "${header_file}" "${install_dir}/usr/include/"
|
|
display_alert "H264BITSTREAM" "Header installed: $(basename "${header_file}")" "debug"
|
|
fi
|
|
done
|
|
|
|
# 安装 pkgconfig 文件(去掉 -ffile-prefix-map 等编译参数,与 .bb do_configure:append 一致)
|
|
local pc_file="${build_dir}/libh264bitstream.pc"
|
|
if [[ -f "${pc_file}" ]]; then
|
|
sed -i -E 's@-f[a-z-]*prefix-map=[^ ]*@@g' "${pc_file}"
|
|
install -m 0644 "${pc_file}" "${install_dir}/usr/lib/pkgconfig/"
|
|
display_alert "H264BITSTREAM" "pkgconfig installed: libh264bitstream.pc" "debug"
|
|
fi
|
|
|
|
display_alert "H264BITSTREAM" "Installation completed successfully" "success"
|
|
return 0
|
|
}
|
|
|
|
function __h264bitstream_create_deb {
|
|
local build_dir="${1}"
|
|
local install_dir="${2}"
|
|
|
|
# 设置必要的变量
|
|
local pkg_name="libh264bitstream"
|
|
local version="${DEB_VERSION}"
|
|
local architecture="${ARCH}"
|
|
local maintainer="Armbian Build <build@armbian.com>"
|
|
local description="h264bitstream library for Amlogic platforms"
|
|
local description_long="This package provides the h264bitstream library used to read and write H.264 bitstreams on Amlogic platforms."
|
|
|
|
display_alert "H264BITSTREAM" "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 "H264BITSTREAM" "Copied installed files to ${deb_dir}" "info"
|
|
else
|
|
display_alert "H264BITSTREAM" "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
|
|
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 "h264bitstream 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 h264bitstream library"
|
|
fi
|
|
|
|
exit 0
|
|
EOF
|
|
|
|
chmod 755 "${debian_dir}/prerm"
|
|
|
|
display_alert "H264BITSTREAM" "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 "H264BITSTREAM" "Debian package created: ${output_dir}/linux-${pkg_name}-${BOARD}-amlbian_${version}_${architecture}.deb" "success"
|
|
else
|
|
display_alert "H264BITSTREAM" "Failed to build Debian package" "err"
|
|
return 1
|
|
fi
|
|
|
|
return 0
|
|
}
|
|
|
|
function amlbian_build_h264bitstream {
|
|
if ! is_unit_enabled "h264bitstream" && ! is_unit_enabled "libencoder"; then
|
|
display_alert "[SKIP] >> h264bitstream disable in BUILD_UNITS" "" "info"
|
|
return
|
|
fi
|
|
|
|
if ! is_feature_contains "$MEDIA_FEATURES" "aml-libamvenc-264"; then
|
|
display_alert "[SKIP] >> aml-libamvenc-264 disable in MEDIA_FEATURES" "" "info"
|
|
return
|
|
fi
|
|
|
|
display_alert "AMLOGIC: Building h264bitstream ${DEB_VERSION} ${BOARD}" "info"
|
|
|
|
# Define all directory paths (in .tmp directory)
|
|
local build_root="${MODULE_BUILD_DIR}/h264bitstream-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"
|
|
|
|
# 准备源代码
|
|
if ! __h264bitstream_prepare_source "${build_dir}"; then
|
|
display_alert "AMLOGIC: h264bitstream prepare source failed" "err"
|
|
return 1
|
|
fi
|
|
|
|
# 构建
|
|
if ! __h264bitstream_build "${build_dir}" "${install_dir}"; then
|
|
display_alert "AMLOGIC: h264bitstream build failed" "err"
|
|
return 1
|
|
fi
|
|
|
|
# 安装到安装目录
|
|
if ! __h264bitstream_install "${build_dir}" "${install_dir}"; then
|
|
display_alert "AMLOGIC: h264bitstream installation failed" "err"
|
|
return 1
|
|
fi
|
|
|
|
display_alert "AMLOGIC: Creating Debian package..." "info"
|
|
__h264bitstream_create_deb "${build_dir}" "${install_dir}"
|
|
|
|
__unset_h264bitstream_config
|
|
|
|
return 0
|
|
}
|
|
|
|
# ==============================================================================
|
|
# Section 5: Main
|
|
# ==============================================================================
|
|
|
|
display_alert "AMLbian h264bitstream Build Script" "Version: ${DEB_VERSION}, Board: ${BOARD}" "info"
|
|
|
|
amlbian_build_h264bitstream
|
|
|
|
display_alert "AMLOGIC: h264bitstream build completed" "${BUILD_DIR}/output" "info"
|
|
|
|
# ==============================================================================
|
|
# End of build-h264bitstream.sh
|
|
# ==============================================================================
|