From 1799940d8c10e9bb28c6fe23226737f65626f0b4 Mon Sep 17 00:00:00 2001 From: pproenca <8202400+pproenca@users.noreply.github.com> Date: Fri, 9 Jan 2026 18:03:11 +0000 Subject: [PATCH 1/2] refactor: consolidate duplicated code across build scripts and Makefiles - Create scripts/lib/logging.sh with centralized logging functions - Create scripts/lib/common.sh with shared build utilities (normalize_license, verify_binary_arch, install_cmake_3x) - Create shared/ffmpeg.mk with common FFmpeg codec options (BSD, LGPL, GPL) - Refactor all platform build.sh scripts to use shared libraries - Update docker/build.sh to use shared libraries - Add STRIP variable to darwin config.mk files for consistency with linux - Fix darwin-x64 terminal detection (was missing [[ -t 1 ]] check) - Remove unused variables: CACHE_VERSION, AUTOCONF_DARWIN_ARGS, PARALLEL_CODECS, validate_versions --- docker/build.sh | 93 +++------------- openspec/project.md | 2 +- platforms/darwin-arm64/Makefile | 25 +---- platforms/darwin-arm64/build.sh | 179 ++++--------------------------- platforms/darwin-arm64/config.mk | 3 +- platforms/darwin-x64/Makefile | 25 +---- platforms/darwin-x64/build.sh | 111 ++++--------------- platforms/darwin-x64/config.mk | 3 +- platforms/linux-arm64/Makefile | 25 +---- platforms/linux-arm64/build.sh | 95 ++++------------ platforms/linux-x64/Makefile | 25 +---- platforms/linux-x64/build.sh | 94 ++++------------ scripts/lib/common.sh | 130 ++++++++++++++++++++++ scripts/lib/logging.sh | 89 +++++++++++++++ shared/codecs/codec.mk | 9 +- shared/ffmpeg.mk | 48 +++++++++ shared/versions.mk | 18 ---- 17 files changed, 382 insertions(+), 592 deletions(-) create mode 100644 scripts/lib/common.sh create mode 100644 scripts/lib/logging.sh create mode 100644 shared/ffmpeg.mk diff --git a/docker/build.sh b/docker/build.sh index e0d01ae..c99acfc 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -23,29 +23,11 @@ set -euo pipefail # Resolve script directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" +readonly SCRIPT_DIR PROJECT_ROOT -# ============================================================================= -# Colors -# ============================================================================= - -if [[ -t 1 ]]; then - readonly RED='\033[0;31m' - readonly GREEN='\033[0;32m' - readonly YELLOW='\033[1;33m' - readonly BLUE='\033[0;34m' - readonly NC='\033[0m' -else - readonly RED='' - readonly GREEN='' - readonly YELLOW='' - readonly BLUE='' - readonly NC='' -fi - -log_info() { echo -e "${GREEN}[INFO]${NC} $*"; } -log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; } -log_error() { echo -e "${RED}[ERROR]${NC} $*" >&2; } -log_step() { echo -e "${BLUE}[STEP]${NC} $*"; } +# Source shared libraries +source "${PROJECT_ROOT}/scripts/lib/logging.sh" +source "${PROJECT_ROOT}/scripts/lib/common.sh" # ============================================================================= # Configuration @@ -65,9 +47,11 @@ fi case "$PLATFORM" in linux-x64) DOCKER_TARGET="builder-x64" + EXPECTED_ARCH="x86-64" ;; linux-arm64) DOCKER_TARGET="builder-arm64" + EXPECTED_ARCH="aarch64" ;; *) log_error "Unknown platform: $PLATFORM" @@ -76,31 +60,13 @@ case "$PLATFORM" in ;; esac -# Backwards compatibility: map old values to new -case "$LICENSE" in - bsd|lgpl) - log_warn "DEPRECATION: LICENSE=$LICENSE is deprecated. Use LICENSE=free instead." - LICENSE="free" - ;; - gpl) - log_warn "DEPRECATION: LICENSE=gpl is deprecated. Use LICENSE=non-free instead." - LICENSE="non-free" - ;; -esac - -# Validate license -if [[ ! "$LICENSE" =~ ^(free|non-free)$ ]]; then - log_error "Invalid LICENSE=$LICENSE. Must be: free, non-free" - exit 1 -fi +# Normalize license +LICENSE="$(normalize_license "$LICENSE")" || exit 1 # ============================================================================= # Docker Functions # ============================================================================= -####################################### -# Check if Docker is available and running. -####################################### check_docker() { if ! command -v docker &>/dev/null; then log_error "Docker is not installed" @@ -114,9 +80,6 @@ check_docker() { fi } -####################################### -# Build the Docker image for the platform. -####################################### build_image() { local image_name="ffmpeg-build:${PLATFORM}" @@ -129,10 +92,7 @@ build_image() { "${PROJECT_ROOT}" } -####################################### -# Run the build inside Docker container. -####################################### -run_build() { +run_docker_build() { local image_name="ffmpeg-build:${PLATFORM}" log_step "Running build in container..." @@ -140,11 +100,6 @@ run_build() { log_info "Target: ${TARGET}" log_info "License: ${LICENSE}" - # Run build with project mounted - # --rm: Remove container after exit - # -v: Mount project directory - # -e: Pass environment variables - # -w: Set working directory docker run --rm \ -v "${PROJECT_ROOT}:/build:rw" \ -e "LICENSE=${LICENSE}" \ @@ -154,10 +109,7 @@ run_build() { make -C "/build/platforms/${PLATFORM}" LICENSE="${LICENSE}" "${TARGET}" } -####################################### -# Verify the build output. -####################################### -verify_build() { +verify_docker_build() { local artifacts_dir="${PROJECT_ROOT}/artifacts/${PLATFORM}-${LICENSE}" local ffmpeg_bin="${artifacts_dir}/bin/ffmpeg" @@ -168,29 +120,10 @@ verify_build() { log_step "Verifying build..." - # Verify architecture - local expected_arch - case "$PLATFORM" in - linux-x64) - expected_arch="x86-64" - ;; - linux-arm64) - expected_arch="aarch64" - ;; - esac - - local file_output - file_output="$(file "$ffmpeg_bin")" - - if ! echo "$file_output" | grep -qi "$expected_arch"; then - log_error "Architecture mismatch!" - log_error "Expected: $expected_arch" - log_error "Got: $file_output" + if ! verify_binary_arch "$ffmpeg_bin" "$EXPECTED_ARCH"; then exit 1 fi - log_info "Architecture verified: $expected_arch" - # Verify static linking (only libc, libm, libpthread should be dynamic) log_step "Checking dynamic dependencies..." if command -v ldd &>/dev/null && [[ "$PLATFORM" == "linux-x64" ]]; then @@ -214,10 +147,10 @@ main() { check_docker build_image - run_build + run_docker_build if [[ "$TARGET" == "all" ]] || [[ "$TARGET" == "package" ]]; then - verify_build + verify_docker_build local artifacts_dir="${PROJECT_ROOT}/artifacts/${PLATFORM}-${LICENSE}" echo "" diff --git a/openspec/project.md b/openspec/project.md index 13ff3bf..e499b8f 100644 --- a/openspec/project.md +++ b/openspec/project.md @@ -192,4 +192,4 @@ Each platform's `config.mk` sets: `LIBVPX_TARGET`, `X264_HOST`, `AOM_TARGET_CPU` - npm registry (@pproenca scope) **Version Management:** -All versions, URLs, and checksums centralized in `shared/versions.mk`. Bump `CACHE_VERSION` to invalidate CI cache. +All versions, URLs, and checksums centralized in `shared/versions.mk`. diff --git a/platforms/darwin-arm64/Makefile b/platforms/darwin-arm64/Makefile index 102df88..306c032 100644 --- a/platforms/darwin-arm64/Makefile +++ b/platforms/darwin-arm64/Makefile @@ -52,6 +52,7 @@ include $(ROOT_DIR)/config.mk include $(PROJECT_ROOT)/shared/verify.mk include $(PROJECT_ROOT)/shared/codecs/pkgconfig.mk include $(PROJECT_ROOT)/shared/codecs/codec.mk +include $(PROJECT_ROOT)/shared/ffmpeg.mk # ============================================================================= # Include Individual Codec Build Rules (from shared) @@ -124,29 +125,7 @@ FFMPEG_BASE_OPTS := \ --disable-podpages \ --disable-txtpages -FFMPEG_BSD_OPTS := \ - --enable-libvpx \ - --enable-libaom \ - --enable-libsvtav1 \ - --enable-libdav1d \ - --enable-libopus \ - --enable-libvorbis - -FFMPEG_LGPL_OPTS := \ - --enable-libmp3lame - -FFMPEG_GPL_OPTS := \ - --enable-gpl \ - --enable-libx264 \ - --enable-libx265 - -ifeq ($(LICENSE),free) - FFMPEG_LICENSE_OPTS := $(FFMPEG_BSD_OPTS) $(FFMPEG_LGPL_OPTS) -else - # non-free: includes GPL codecs - FFMPEG_LICENSE_OPTS := $(FFMPEG_BSD_OPTS) $(FFMPEG_LGPL_OPTS) $(FFMPEG_GPL_OPTS) -endif - +# FFmpeg codec options (BSD, LGPL, GPL) defined in shared/ffmpeg.mk FFMPEG_CONFIGURE_OPTS := $(FFMPEG_BASE_OPTS) $(FFMPEG_LICENSE_OPTS) # ----------------------------------------------------------------------------- diff --git a/platforms/darwin-arm64/build.sh b/platforms/darwin-arm64/build.sh index fbfce7f..930ba1a 100755 --- a/platforms/darwin-arm64/build.sh +++ b/platforms/darwin-arm64/build.sh @@ -27,53 +27,21 @@ PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" || { } readonly PROJECT_ROOT +# Source shared libraries +source "${PROJECT_ROOT}/scripts/lib/logging.sh" +source "${PROJECT_ROOT}/scripts/lib/common.sh" + # ============================================================================= -# Colors (disabled when output is not a terminal) +# Platform Configuration # ============================================================================= -if [[ -t 1 ]]; then - readonly RED='\033[0;31m' - readonly GREEN='\033[0;32m' - readonly YELLOW='\033[1;33m' - readonly BLUE='\033[0;34m' - readonly NC='\033[0m' -else - readonly RED='' - readonly GREEN='' - readonly YELLOW='' - readonly BLUE='' - readonly NC='' -fi - -####################################### -# Logging functions -# Globals: -# GREEN, YELLOW, RED, BLUE, NC -# Arguments: -# $* - Message to log -# Outputs: -# Writes message to stdout (or stderr for log_error) -####################################### -log_info() { echo -e "${GREEN}[INFO]${NC} $*"; } -log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; } -log_error() { echo -e "${RED}[ERROR]${NC} $*" >&2; } -log_step() { echo -e "${BLUE}[STEP]${NC} $*"; } +readonly PLATFORM="darwin-arm64" +readonly EXPECTED_ARCH="arm64" # ============================================================================= # Platform Verification # ============================================================================= -####################################### -# Verify the script is running on darwin-arm64. -# Globals: -# None -# Arguments: -# None -# Outputs: -# Writes verification status to stdout -# Returns: -# 0 on success, exits with 1 on wrong platform -####################################### verify_platform() { log_step "Verifying platform..." @@ -90,24 +58,13 @@ verify_platform() { exit 1 fi - log_info "Platform verified: darwin-arm64" + log_info "Platform verified: ${PLATFORM}" } # ============================================================================= # Dependency Installation # ============================================================================= -####################################### -# Check and install required build dependencies via Homebrew. -# Globals: -# None -# Arguments: -# None -# Outputs: -# Writes dependency status to stdout -# Returns: -# 0 on success, exits with 1 if Homebrew missing -####################################### install_dependencies() { log_step "Checking build dependencies..." @@ -117,7 +74,6 @@ install_dependencies() { exit 1 fi - # Homebrew tools (excludes cmake - installed via pip for version control) local tools=( nasm # Assembler for x264 and others meson # Build system for dav1d @@ -145,8 +101,7 @@ install_dependencies() { fi # Install CMake 3.x via pip (CMake 4.x breaks x265, libaom, svt-av1 builds) - # Homebrew only provides CMake 4.x, so we use pip for version control - install_cmake + install_cmake_3x # Show tool versions log_info "Tool versions:" @@ -156,64 +111,16 @@ install_dependencies() { echo " ninja: $(ninja --version)" } -####################################### -# Install CMake 3.x via pip. -# CMake 4.x is incompatible with upstream codec builds (x265, libaom, svt-av1). -# Globals: -# None -# Arguments: -# None -# Outputs: -# Writes installation status to stdout -####################################### -install_cmake() { - local cmake_version - cmake_version="$(cmake --version 2>/dev/null | head -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "0.0.0")" - local cmake_major="${cmake_version%%.*}" - - if [[ "$cmake_major" -ge 4 ]] || ! command -v cmake &>/dev/null; then - log_info "Installing CMake 3.x via pip (CMake 4.x incompatible with codec builds)..." - pip3 install --quiet --break-system-packages 'cmake>=3.20,<4' - fi -} - # ============================================================================= # Build Execution # ============================================================================= -####################################### -# Execute the build via Make. -# Globals: -# SCRIPT_DIR -# LICENSE (env var, optional) -# Arguments: -# $1 - Build target (default: all) -# Outputs: -# Writes build progress to stdout -# Returns: -# 0 on success, exits with 1 on invalid license -####################################### run_build() { local target="${1:-all}" - local license="${LICENSE:-free}" local debug="${DEBUG:-}" - # Backwards compatibility: map old values to new - case "$license" in - bsd|lgpl) - log_warn "DEPRECATION: LICENSE=$license is deprecated. Use LICENSE=free instead." - license="free" - ;; - gpl) - log_warn "DEPRECATION: LICENSE=gpl is deprecated. Use LICENSE=non-free instead." - license="non-free" - ;; - esac - - if [[ ! "$license" =~ ^(free|non-free)$ ]]; then - log_error "Invalid LICENSE=$license. Must be: free, non-free" - exit 1 - fi + local license + license="$(normalize_license "${LICENSE:-free}")" || exit 1 log_step "Starting build..." log_info "Target: ${target}" @@ -221,7 +128,6 @@ run_build() { [[ -n "$debug" ]] && log_info "Debug mode: enabled (showing all warnings)" cd "${SCRIPT_DIR}" - make -j LICENSE="${license}" DEBUG="${debug}" "${target}" } @@ -229,23 +135,13 @@ run_build() { # Main # ============================================================================= -####################################### -# Main entry point. -# Globals: -# SCRIPT_DIR, PROJECT_ROOT -# LICENSE (env var, optional) -# Arguments: -# $1 - Build target (default: all) -# Outputs: -# Writes build progress and results to stdout -####################################### main() { local target="${1:-all}" local license="${LICENSE:-free}" echo "" echo "==========================================" - echo " FFmpeg Build for darwin-arm64" + echo " FFmpeg Build for ${PLATFORM}" echo " License tier: ${license}" echo "==========================================" echo "" @@ -264,55 +160,20 @@ main() { log_info "Build completed successfully!" if [[ "$target" == "all" ]] || [[ "$target" == "package" ]]; then - local artifacts_dir="${PROJECT_ROOT}/artifacts/darwin-arm64-${license}" + # Normalize license for artifacts path + local normalized_license + normalized_license="$(normalize_license "${license}")" || exit 1 + local artifacts_dir="${PROJECT_ROOT}/artifacts/${PLATFORM}-${normalized_license}" + echo "" log_info "Artifacts location: ${artifacts_dir}/" ls -la "${artifacts_dir}/bin/" 2>/dev/null || true # Verify binary architecture matches target - verify_binary_arch "${artifacts_dir}/bin/ffmpeg" "arm64" - fi -} - -# ============================================================================= -# Binary Architecture Verification -# ============================================================================= - -####################################### -# Verify a binary matches the expected architecture. -# Catches cross-compilation failures where host arch leaks into output. -# Globals: -# None -# Arguments: -# $1 - Path to binary file -# $2 - Expected architecture (e.g., "arm64") -# Outputs: -# Writes verification status to stdout -# Returns: -# 0 on success, exits with 1 on mismatch or missing binary -####################################### -verify_binary_arch() { - local binary="$1" - local expected_arch="$2" - - if [[ ! -f "$binary" ]]; then - log_error "Binary not found for architecture verification: $binary" - exit 1 - fi - - log_step "Verifying binary architecture..." - - local file_output - file_output="$(file "$binary")" - - if ! echo "$file_output" | grep -q "$expected_arch"; then - log_error "Architecture mismatch detected!" - log_error "Expected: $expected_arch" - log_error "Got: $file_output" - exit 1 + if ! verify_binary_arch "${artifacts_dir}/bin/ffmpeg" "${EXPECTED_ARCH}"; then + exit 1 + fi fi - - log_info "Architecture verified: $expected_arch" } main "$@" diff --git a/platforms/darwin-arm64/config.mk b/platforms/darwin-arm64/config.mk index 05d47ba..bf334ef 100644 --- a/platforms/darwin-arm64/config.mk +++ b/platforms/darwin-arm64/config.mk @@ -15,6 +15,7 @@ CC := clang CXX := clang++ AR := ar RANLIB := ranlib +STRIP := strip # macOS SDK path SDKROOT := $(shell xcrun --show-sdk-path 2>/dev/null || echo "") @@ -123,7 +124,7 @@ FFMPEG_EXTRA_LIBS := -lpthread -lm -lc++ # Export Variables # ============================================================================= -export CC CXX AR RANLIB +export CC CXX AR RANLIB STRIP export CFLAGS CXXFLAGS LDFLAGS export PKG_CONFIG PKG_CONFIG_LIBDIR export MACOSX_DEPLOYMENT_TARGET diff --git a/platforms/darwin-x64/Makefile b/platforms/darwin-x64/Makefile index 873b1a3..c30df52 100644 --- a/platforms/darwin-x64/Makefile +++ b/platforms/darwin-x64/Makefile @@ -53,6 +53,7 @@ include $(ROOT_DIR)/config.mk include $(PROJECT_ROOT)/shared/verify.mk include $(PROJECT_ROOT)/shared/codecs/pkgconfig.mk include $(PROJECT_ROOT)/shared/codecs/codec.mk +include $(PROJECT_ROOT)/shared/ffmpeg.mk # ============================================================================= # Include Individual Codec Build Rules (from shared) @@ -125,29 +126,7 @@ FFMPEG_BASE_OPTS := \ --disable-podpages \ --disable-txtpages -FFMPEG_BSD_OPTS := \ - --enable-libvpx \ - --enable-libaom \ - --enable-libsvtav1 \ - --enable-libdav1d \ - --enable-libopus \ - --enable-libvorbis - -FFMPEG_LGPL_OPTS := \ - --enable-libmp3lame - -FFMPEG_GPL_OPTS := \ - --enable-gpl \ - --enable-libx264 \ - --enable-libx265 - -ifeq ($(LICENSE),free) - FFMPEG_LICENSE_OPTS := $(FFMPEG_BSD_OPTS) $(FFMPEG_LGPL_OPTS) -else - # non-free: includes GPL codecs - FFMPEG_LICENSE_OPTS := $(FFMPEG_BSD_OPTS) $(FFMPEG_LGPL_OPTS) $(FFMPEG_GPL_OPTS) -endif - +# FFmpeg codec options (BSD, LGPL, GPL) defined in shared/ffmpeg.mk FFMPEG_CONFIGURE_OPTS := $(FFMPEG_BASE_OPTS) $(FFMPEG_LICENSE_OPTS) # ----------------------------------------------------------------------------- diff --git a/platforms/darwin-x64/build.sh b/platforms/darwin-x64/build.sh index 43cce13..a650abe 100755 --- a/platforms/darwin-x64/build.sh +++ b/platforms/darwin-x64/build.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -# shellcheck shell=bash # ============================================================================= # FFmpeg Build Entry Point for darwin-x64 # ============================================================================= @@ -15,9 +14,6 @@ # # Environment: # LICENSE: Build license tier (free, non-free). Default: free -# -# Returns: -# 0 on success, non-zero on failure. # ============================================================================= set -euo pipefail @@ -26,24 +22,16 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" readonly SCRIPT_DIR PROJECT_ROOT -# ============================================================================= -# Colors -# ============================================================================= - -readonly RED='\033[0;31m' -readonly GREEN='\033[0;32m' -readonly YELLOW='\033[1;33m' -readonly BLUE='\033[0;34m' -readonly NC='\033[0m' # No Color +# Source shared libraries +source "${PROJECT_ROOT}/scripts/lib/logging.sh" +source "${PROJECT_ROOT}/scripts/lib/common.sh" # ============================================================================= -# Logging Functions +# Platform Configuration # ============================================================================= -log_info() { echo -e "${GREEN}[INFO]${NC} $*"; } -log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; } -log_error() { echo -e "${RED}[ERROR]${NC} $*" >&2; } -log_step() { echo -e "${BLUE}[STEP]${NC} $*"; } +readonly PLATFORM="darwin-x64" +readonly EXPECTED_ARCH="x86_64" # ============================================================================= # Platform Verification @@ -75,7 +63,6 @@ install_dependencies() { exit 1 fi - # Homebrew tools (excludes cmake, nasm - installed separately for version control) local -a tools=( meson # Build system for dav1d ninja # Build tool for meson @@ -86,8 +73,8 @@ install_dependencies() { ) local -a missing_tools=() - local tool + for tool in "${tools[@]}"; do if ! command -v "${tool}" &>/dev/null; then missing_tools+=("${tool}") @@ -102,11 +89,9 @@ install_dependencies() { fi # Install CMake 3.x via pip (CMake 4.x breaks x265, libaom, svt-av1 builds) - # Homebrew only provides CMake 4.x, so we use pip for version control - install_cmake + install_cmake_3x # Install NASM 2.x from source (NASM 3.x breaks libaom multipass optimization) - # Homebrew only provides NASM 3.x, so we build from source for version control install_nasm # Show tool versions @@ -117,18 +102,6 @@ install_dependencies() { echo " ninja: $(ninja --version)" } -# Install CMake 3.x via pip (upstream codecs incompatible with CMake 4.x) -install_cmake() { - local cmake_version - cmake_version="$(cmake --version 2>/dev/null | head -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "0.0.0")" - local cmake_major="${cmake_version%%.*}" - - if [[ "${cmake_major}" -ge 4 ]] || ! command -v cmake &>/dev/null; then - log_info "Installing CMake 3.x via pip (CMake 4.x incompatible with codec builds)..." - pip3 install --quiet --break-system-packages 'cmake>=3.20,<4' - fi -} - # Install NASM 2.x from source (NASM 3.x breaks libaom multipass optimization check) # See: https://www.linuxfromscratch.org/blfs/view/svn/multimedia/libaom.html install_nasm() { @@ -138,12 +111,12 @@ install_nasm() { if [[ "${nasm_major}" -ge 3 ]] || ! command -v nasm &>/dev/null; then log_info "Building NASM 2.16.03 from source (NASM 3.x incompatible with libaom)..." - local nasm_src="${PROJECT_ROOT}/build/darwin-x64/nasm-2.16.03" + local nasm_src="${PROJECT_ROOT}/build/${PLATFORM}/nasm-2.16.03" local nasm_bin="${nasm_src}/nasm" if [[ ! -f "${nasm_bin}" ]]; then - mkdir -p "${PROJECT_ROOT}/build/darwin-x64" - cd "${PROJECT_ROOT}/build/darwin-x64" + mkdir -p "${PROJECT_ROOT}/build/${PLATFORM}" + cd "${PROJECT_ROOT}/build/${PLATFORM}" curl -sL "https://www.nasm.us/pub/nasm/releasebuilds/2.16.03/nasm-2.16.03.tar.gz" | tar xz cd nasm-2.16.03 ./configure @@ -162,25 +135,10 @@ install_nasm() { run_build() { local target="${1:-all}" - local license="${LICENSE:-free}" local debug="${DEBUG:-}" - # Backwards compatibility: map old values to new - case "$license" in - bsd|lgpl) - log_warn "DEPRECATION: LICENSE=$license is deprecated. Use LICENSE=free instead." - license="free" - ;; - gpl) - log_warn "DEPRECATION: LICENSE=gpl is deprecated. Use LICENSE=non-free instead." - license="non-free" - ;; - esac - - if [[ ! "${license}" =~ ^(free|non-free)$ ]]; then - log_error "Invalid LICENSE=${license}. Must be: free, non-free" - exit 1 - fi + local license + license="$(normalize_license "${LICENSE:-free}")" || exit 1 log_step "Starting build..." log_info "Target: ${target}" @@ -189,40 +147,9 @@ run_build() { [[ -n "${debug}" ]] && log_info "Debug mode: enabled (showing all warnings)" cd "${SCRIPT_DIR}" - make -j LICENSE="${license}" DEBUG="${debug}" "${target}" } -# ============================================================================= -# Binary Architecture Verification -# ============================================================================= -# Ensures built binaries match the target architecture. -# Catches cross-compilation failures where host arch leaks into output. - -verify_binary_arch() { - local binary="$1" - local expected_arch="$2" - - if [[ ! -f "${binary}" ]]; then - log_error "Binary not found for architecture verification: ${binary}" - exit 1 - fi - - log_step "Verifying binary architecture..." - - local file_output - file_output="$(file "${binary}")" - - if ! echo "${file_output}" | grep -q "${expected_arch}"; then - log_error "Architecture mismatch detected!" - log_error "Expected: ${expected_arch}" - log_error "Got: ${file_output}" - exit 1 - fi - - log_info "Architecture verified: ${expected_arch}" -} - # ============================================================================= # Main # ============================================================================= @@ -233,7 +160,7 @@ main() { echo "" echo "==========================================" - echo " FFmpeg Build for darwin-x64" + echo " FFmpeg Build for ${PLATFORM}" echo " License tier: ${license}" echo " (cross-compiled from ARM64)" echo "==========================================" @@ -253,13 +180,19 @@ main() { log_info "Build completed successfully!" if [[ "${target}" == "all" ]] || [[ "${target}" == "package" ]]; then - local artifacts_dir="${PROJECT_ROOT}/artifacts/darwin-x64-${license}" + # Normalize license for artifacts path + local normalized_license + normalized_license="$(normalize_license "${license}")" || exit 1 + local artifacts_dir="${PROJECT_ROOT}/artifacts/${PLATFORM}-${normalized_license}" + echo "" log_info "Artifacts location: ${artifacts_dir}/" ls -la "${artifacts_dir}/bin/" 2>/dev/null || true # Verify binary architecture matches target - verify_binary_arch "${artifacts_dir}/bin/ffmpeg" "x86_64" + if ! verify_binary_arch "${artifacts_dir}/bin/ffmpeg" "${EXPECTED_ARCH}"; then + exit 1 + fi fi } diff --git a/platforms/darwin-x64/config.mk b/platforms/darwin-x64/config.mk index 4a004e9..83a8658 100644 --- a/platforms/darwin-x64/config.mk +++ b/platforms/darwin-x64/config.mk @@ -16,6 +16,7 @@ CC := clang CXX := clang++ AR := ar RANLIB := ranlib +STRIP := strip # macOS SDK path SDKROOT := $(shell xcrun --show-sdk-path 2>/dev/null || echo "") @@ -122,7 +123,7 @@ FFMPEG_EXTRA_LIBS := -lpthread -lm -lc++ # Export Variables # ============================================================================= -export CC CXX AR RANLIB +export CC CXX AR RANLIB STRIP export CFLAGS CXXFLAGS LDFLAGS export PKG_CONFIG PKG_CONFIG_LIBDIR export MACOSX_DEPLOYMENT_TARGET diff --git a/platforms/linux-arm64/Makefile b/platforms/linux-arm64/Makefile index 517ac6b..6d22f46 100644 --- a/platforms/linux-arm64/Makefile +++ b/platforms/linux-arm64/Makefile @@ -48,6 +48,7 @@ include $(ROOT_DIR)/config.mk include $(PROJECT_ROOT)/shared/verify.mk include $(PROJECT_ROOT)/shared/codecs/pkgconfig.mk include $(PROJECT_ROOT)/shared/codecs/codec.mk +include $(PROJECT_ROOT)/shared/ffmpeg.mk # ============================================================================= # Include Individual Codec Build Rules (from shared) @@ -133,29 +134,7 @@ FFMPEG_BASE_OPTS := \ --disable-podpages \ --disable-txtpages -FFMPEG_BSD_OPTS := \ - --enable-libvpx \ - --enable-libaom \ - --enable-libsvtav1 \ - --enable-libdav1d \ - --enable-libopus \ - --enable-libvorbis - -FFMPEG_LGPL_OPTS := \ - --enable-libmp3lame - -FFMPEG_GPL_OPTS := \ - --enable-gpl \ - --enable-libx264 \ - --enable-libx265 - -ifeq ($(LICENSE),free) - FFMPEG_LICENSE_OPTS := $(FFMPEG_BSD_OPTS) $(FFMPEG_LGPL_OPTS) -else - # non-free: includes GPL codecs - FFMPEG_LICENSE_OPTS := $(FFMPEG_BSD_OPTS) $(FFMPEG_LGPL_OPTS) $(FFMPEG_GPL_OPTS) -endif - +# FFmpeg codec options (BSD, LGPL, GPL) defined in shared/ffmpeg.mk FFMPEG_CONFIGURE_OPTS := $(FFMPEG_BASE_OPTS) $(FFMPEG_LICENSE_OPTS) # ----------------------------------------------------------------------------- diff --git a/platforms/linux-arm64/build.sh b/platforms/linux-arm64/build.sh index c72906b..a9cce30 100755 --- a/platforms/linux-arm64/build.sh +++ b/platforms/linux-arm64/build.sh @@ -22,29 +22,18 @@ set -euo pipefail # Resolve script directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" +readonly SCRIPT_DIR PROJECT_ROOT + +# Source shared libraries +source "${PROJECT_ROOT}/scripts/lib/logging.sh" +source "${PROJECT_ROOT}/scripts/lib/common.sh" # ============================================================================= -# Colors +# Platform Configuration # ============================================================================= -if [[ -t 1 ]]; then - readonly RED='\033[0;31m' - readonly GREEN='\033[0;32m' - readonly YELLOW='\033[1;33m' - readonly BLUE='\033[0;34m' - readonly NC='\033[0m' -else - readonly RED='' - readonly GREEN='' - readonly YELLOW='' - readonly BLUE='' - readonly NC='' -fi - -log_info() { echo -e "${GREEN}[INFO]${NC} $*"; } -log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; } -log_error() { echo -e "${RED}[ERROR]${NC} $*" >&2; } -log_step() { echo -e "${BLUE}[STEP]${NC} $*"; } +readonly PLATFORM="linux-arm64" +readonly EXPECTED_ARCH="aarch64" # ============================================================================= # Platform Verification @@ -55,12 +44,11 @@ verify_platform() { if [[ "$(uname -s)" != "Linux" ]]; then log_error "This script must run on Linux" - log_error "Use ./docker/build.sh linux-arm64 for Docker-based builds" + log_error "Use ./docker/build.sh ${PLATFORM} for Docker-based builds" exit 1 fi # Cross-compilation: we build ON x86_64 FOR aarch64 - # So we check for x86_64 host local host_arch host_arch="$(uname -m)" if [[ "$host_arch" != "x86_64" ]]; then @@ -95,7 +83,7 @@ check_dependencies() { if [[ ${#missing[@]} -gt 0 ]]; then log_error "Missing build tools: ${missing[*]}" - log_error "Use Docker: ./docker/build.sh linux-arm64" + log_error "Use Docker: ./docker/build.sh ${PLATFORM}" exit 1 fi @@ -115,66 +103,22 @@ check_dependencies() { run_build() { local target="${1:-all}" - local license="${LICENSE:-free}" local debug="${DEBUG:-}" - # Backwards compatibility: map old values to new - case "$license" in - bsd|lgpl) - log_warn "DEPRECATION: LICENSE=$license is deprecated. Use LICENSE=free instead." - license="free" - ;; - gpl) - log_warn "DEPRECATION: LICENSE=gpl is deprecated. Use LICENSE=non-free instead." - license="non-free" - ;; - esac - - if [[ ! "$license" =~ ^(free|non-free)$ ]]; then - log_error "Invalid LICENSE=$license. Must be: free, non-free" - exit 1 - fi + local license + license="$(normalize_license "${LICENSE:-free}")" || exit 1 log_step "Starting cross-compilation build..." log_info "Target: ${target}" log_info "License tier: ${license}" log_info "Host architecture: $(uname -m)" - log_info "Target architecture: aarch64" + log_info "Target architecture: ${EXPECTED_ARCH}" [[ -n "$debug" ]] && log_info "Debug mode: enabled" cd "${SCRIPT_DIR}" - make -j LICENSE="${license}" DEBUG="${debug}" "${target}" } -# ============================================================================= -# Binary Architecture Verification -# ============================================================================= - -verify_binary_arch() { - local binary="$1" - local expected_arch="$2" - - if [[ ! -f "$binary" ]]; then - log_error "Binary not found: $binary" - exit 1 - fi - - log_step "Verifying binary architecture..." - - local file_output - file_output="$(file "$binary")" - - if ! echo "$file_output" | grep -q "$expected_arch"; then - log_error "Architecture mismatch!" - log_error "Expected: $expected_arch" - log_error "Got: $file_output" - exit 1 - fi - - log_info "Architecture verified: $expected_arch" -} - # ============================================================================= # Main # ============================================================================= @@ -185,7 +129,7 @@ main() { echo "" echo "==========================================" - echo " FFmpeg Cross-Build for linux-arm64" + echo " FFmpeg Cross-Build for ${PLATFORM}" echo " License tier: ${license}" echo "==========================================" echo "" @@ -204,12 +148,19 @@ main() { log_info "Build completed successfully!" if [[ "$target" == "all" ]] || [[ "$target" == "package" ]]; then - local artifacts_dir="${PROJECT_ROOT}/artifacts/linux-arm64-${license}" + # Normalize license for artifacts path + local normalized_license + normalized_license="$(normalize_license "${license}")" || exit 1 + local artifacts_dir="${PROJECT_ROOT}/artifacts/${PLATFORM}-${normalized_license}" + echo "" log_info "Artifacts location: ${artifacts_dir}/" ls -la "${artifacts_dir}/bin/" 2>/dev/null || true - verify_binary_arch "${artifacts_dir}/bin/ffmpeg" "aarch64" + # Verify binary architecture matches target + if ! verify_binary_arch "${artifacts_dir}/bin/ffmpeg" "${EXPECTED_ARCH}"; then + exit 1 + fi fi } diff --git a/platforms/linux-x64/Makefile b/platforms/linux-x64/Makefile index f9ed28e..fb53104 100644 --- a/platforms/linux-x64/Makefile +++ b/platforms/linux-x64/Makefile @@ -52,6 +52,7 @@ include $(ROOT_DIR)/config.mk include $(PROJECT_ROOT)/shared/verify.mk include $(PROJECT_ROOT)/shared/codecs/pkgconfig.mk include $(PROJECT_ROOT)/shared/codecs/codec.mk +include $(PROJECT_ROOT)/shared/ffmpeg.mk # ============================================================================= # Include Individual Codec Build Rules (from shared) @@ -125,29 +126,7 @@ FFMPEG_BASE_OPTS := \ --disable-podpages \ --disable-txtpages -FFMPEG_BSD_OPTS := \ - --enable-libvpx \ - --enable-libaom \ - --enable-libsvtav1 \ - --enable-libdav1d \ - --enable-libopus \ - --enable-libvorbis - -FFMPEG_LGPL_OPTS := \ - --enable-libmp3lame - -FFMPEG_GPL_OPTS := \ - --enable-gpl \ - --enable-libx264 \ - --enable-libx265 - -ifeq ($(LICENSE),free) - FFMPEG_LICENSE_OPTS := $(FFMPEG_BSD_OPTS) $(FFMPEG_LGPL_OPTS) -else - # non-free: includes GPL codecs - FFMPEG_LICENSE_OPTS := $(FFMPEG_BSD_OPTS) $(FFMPEG_LGPL_OPTS) $(FFMPEG_GPL_OPTS) -endif - +# FFmpeg codec options (BSD, LGPL, GPL) defined in shared/ffmpeg.mk FFMPEG_CONFIGURE_OPTS := $(FFMPEG_BASE_OPTS) $(FFMPEG_LICENSE_OPTS) # ----------------------------------------------------------------------------- diff --git a/platforms/linux-x64/build.sh b/platforms/linux-x64/build.sh index 24264ec..0483fc4 100755 --- a/platforms/linux-x64/build.sh +++ b/platforms/linux-x64/build.sh @@ -22,29 +22,18 @@ set -euo pipefail # Resolve script directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)" +readonly SCRIPT_DIR PROJECT_ROOT + +# Source shared libraries +source "${PROJECT_ROOT}/scripts/lib/logging.sh" +source "${PROJECT_ROOT}/scripts/lib/common.sh" # ============================================================================= -# Colors +# Platform Configuration # ============================================================================= -if [[ -t 1 ]]; then - readonly RED='\033[0;31m' - readonly GREEN='\033[0;32m' - readonly YELLOW='\033[1;33m' - readonly BLUE='\033[0;34m' - readonly NC='\033[0m' -else - readonly RED='' - readonly GREEN='' - readonly YELLOW='' - readonly BLUE='' - readonly NC='' -fi - -log_info() { echo -e "${GREEN}[INFO]${NC} $*"; } -log_warn() { echo -e "${YELLOW}[WARN]${NC} $*"; } -log_error() { echo -e "${RED}[ERROR]${NC} $*" >&2; } -log_step() { echo -e "${BLUE}[STEP]${NC} $*"; } +readonly PLATFORM="linux-x64" +readonly EXPECTED_ARCH="x86-64" # ============================================================================= # Platform Verification @@ -55,7 +44,7 @@ verify_platform() { if [[ "$(uname -s)" != "Linux" ]]; then log_error "This script must run on Linux" - log_error "Use ./docker/build.sh linux-x64 for Docker-based builds" + log_error "Use ./docker/build.sh ${PLATFORM} for Docker-based builds" exit 1 fi @@ -67,7 +56,7 @@ verify_platform() { exit 1 fi - log_info "Platform verified: linux-x64" + log_info "Platform verified: ${PLATFORM}" } # ============================================================================= @@ -88,7 +77,7 @@ check_dependencies() { if [[ ${#missing[@]} -gt 0 ]]; then log_error "Missing build tools: ${missing[*]}" - log_error "Install them or use Docker: ./docker/build.sh linux-x64" + log_error "Install them or use Docker: ./docker/build.sh ${PLATFORM}" exit 1 fi @@ -108,25 +97,10 @@ check_dependencies() { run_build() { local target="${1:-all}" - local license="${LICENSE:-free}" local debug="${DEBUG:-}" - # Backwards compatibility: map old values to new - case "$license" in - bsd|lgpl) - log_warn "DEPRECATION: LICENSE=$license is deprecated. Use LICENSE=free instead." - license="free" - ;; - gpl) - log_warn "DEPRECATION: LICENSE=gpl is deprecated. Use LICENSE=non-free instead." - license="non-free" - ;; - esac - - if [[ ! "$license" =~ ^(free|non-free)$ ]]; then - log_error "Invalid LICENSE=$license. Must be: free, non-free" - exit 1 - fi + local license + license="$(normalize_license "${LICENSE:-free}")" || exit 1 log_step "Starting build..." log_info "Target: ${target}" @@ -134,38 +108,9 @@ run_build() { [[ -n "$debug" ]] && log_info "Debug mode: enabled" cd "${SCRIPT_DIR}" - make -j LICENSE="${license}" DEBUG="${debug}" "${target}" } -# ============================================================================= -# Binary Architecture Verification -# ============================================================================= - -verify_binary_arch() { - local binary="$1" - local expected_arch="$2" - - if [[ ! -f "$binary" ]]; then - log_error "Binary not found: $binary" - exit 1 - fi - - log_step "Verifying binary architecture..." - - local file_output - file_output="$(file "$binary")" - - if ! echo "$file_output" | grep -q "$expected_arch"; then - log_error "Architecture mismatch!" - log_error "Expected: $expected_arch" - log_error "Got: $file_output" - exit 1 - fi - - log_info "Architecture verified: $expected_arch" -} - # ============================================================================= # Main # ============================================================================= @@ -176,7 +121,7 @@ main() { echo "" echo "==========================================" - echo " FFmpeg Build for linux-x64" + echo " FFmpeg Build for ${PLATFORM}" echo " License tier: ${license}" echo "==========================================" echo "" @@ -195,12 +140,19 @@ main() { log_info "Build completed successfully!" if [[ "$target" == "all" ]] || [[ "$target" == "package" ]]; then - local artifacts_dir="${PROJECT_ROOT}/artifacts/linux-x64-${license}" + # Normalize license for artifacts path + local normalized_license + normalized_license="$(normalize_license "${license}")" || exit 1 + local artifacts_dir="${PROJECT_ROOT}/artifacts/${PLATFORM}-${normalized_license}" + echo "" log_info "Artifacts location: ${artifacts_dir}/" ls -la "${artifacts_dir}/bin/" 2>/dev/null || true - verify_binary_arch "${artifacts_dir}/bin/ffmpeg" "x86-64" + # Verify binary architecture matches target + if ! verify_binary_arch "${artifacts_dir}/bin/ffmpeg" "${EXPECTED_ARCH}"; then + exit 1 + fi fi } diff --git a/scripts/lib/common.sh b/scripts/lib/common.sh new file mode 100644 index 0000000..e7a7afd --- /dev/null +++ b/scripts/lib/common.sh @@ -0,0 +1,130 @@ +#!/usr/bin/env bash +# ============================================================================= +# Shared Build Functions +# ============================================================================= +# Common functions used across platform build scripts. +# +# Prerequisites: +# - Must source logging.sh first (provides log_* functions) +# - PROJECT_ROOT must be set before sourcing +# +# Usage: +# source "${PROJECT_ROOT}/scripts/lib/logging.sh" +# source "${PROJECT_ROOT}/scripts/lib/common.sh" +# ============================================================================= + +# Prevent double-sourcing +if [[ -n "${__COMMON_SH_SOURCED:-}" ]]; then + return 0 +fi +readonly __COMMON_SH_SOURCED=1 + +# Verify prerequisites +if ! declare -f log_error &>/dev/null; then + echo "ERROR: logging.sh must be sourced before common.sh" >&2 + exit 1 +fi + +# ============================================================================= +# License Normalization +# ============================================================================= + +####################################### +# Normalize license value with backwards compatibility. +# Handles deprecated values: bsd->free, lgpl->free, gpl->non-free +# Globals: +# None +# Arguments: +# $1 - License value to normalize +# Outputs: +# Normalized license value to stdout +# Deprecation warnings to stderr +# Returns: +# 0 on success, 1 on invalid license +####################################### +normalize_license() { + local license="${1:-free}" + + case "$license" in + bsd|lgpl) + log_warn "DEPRECATION: LICENSE=$license is deprecated. Use LICENSE=free instead." + echo "free" + ;; + gpl) + log_warn "DEPRECATION: LICENSE=gpl is deprecated. Use LICENSE=non-free instead." + echo "non-free" + ;; + free|non-free) + echo "$license" + ;; + *) + log_error "Invalid LICENSE=$license. Must be: free, non-free" + return 1 + ;; + esac +} + +# ============================================================================= +# Binary Verification +# ============================================================================= + +####################################### +# Verify binary has expected architecture. +# Globals: +# None +# Arguments: +# $1 - Path to binary +# $2 - Expected architecture pattern (e.g., "arm64", "x86_64", "aarch64") +# Outputs: +# Writes verification status to stdout +# Returns: +# 0 on success, 1 on failure +####################################### +verify_binary_arch() { + local binary="$1" + local expected_arch="$2" + + if [[ ! -f "$binary" ]]; then + log_error "Binary not found: $binary" + return 1 + fi + + log_step "Verifying binary architecture..." + + local file_output + file_output="$(file "$binary")" + + if ! echo "$file_output" | grep -q "$expected_arch"; then + log_error "Architecture mismatch!" + log_error "Expected: $expected_arch" + log_error "Got: $file_output" + return 1 + fi + + log_info "Architecture verified: $expected_arch" +} + +# ============================================================================= +# CMake Installation +# ============================================================================= + +####################################### +# Install CMake 3.x via pip if needed. +# CMake 4.x is incompatible with upstream codec builds (x265, libaom, svt-av1). +# Globals: +# None +# Arguments: +# None +# Outputs: +# Writes installation status to stdout +####################################### +install_cmake_3x() { + local cmake_version + cmake_version="$(cmake --version 2>/dev/null | head -1 | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || echo "0.0.0")" + local cmake_major="${cmake_version%%.*}" + + if [[ "$cmake_major" -ge 4 ]] || ! command -v cmake &>/dev/null; then + log_info "Installing CMake 3.x via pip (CMake 4.x incompatible with codec builds)..." + pip3 install --quiet --break-system-packages 'cmake>=3.20,<4' + fi +} diff --git a/scripts/lib/logging.sh b/scripts/lib/logging.sh new file mode 100644 index 0000000..188574e --- /dev/null +++ b/scripts/lib/logging.sh @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +# ============================================================================= +# Shared Logging Functions +# ============================================================================= +# Centralized logging functions for all build scripts. +# Colors are automatically disabled when output is not a terminal. +# +# Usage: +# source "${PROJECT_ROOT}/scripts/lib/logging.sh" +# +# Functions: +# log_info "message" - Green [INFO] prefix +# log_warn "message" - Yellow [WARN] prefix +# log_error "message" - Red [ERROR] prefix (writes to stderr) +# log_step "message" - Blue [STEP] prefix +# ============================================================================= + +# Prevent double-sourcing +if [[ -n "${__LOGGING_SH_SOURCED:-}" ]]; then + return 0 +fi +readonly __LOGGING_SH_SOURCED=1 + +# ============================================================================= +# Color Definitions +# ============================================================================= +# Colors are disabled when output is not a terminal (e.g., CI logs, pipes) + +if [[ -t 1 ]]; then + readonly LOG_RED='\033[0;31m' + readonly LOG_GREEN='\033[0;32m' + readonly LOG_YELLOW='\033[1;33m' + readonly LOG_BLUE='\033[0;34m' + readonly LOG_NC='\033[0m' +else + readonly LOG_RED='' + readonly LOG_GREEN='' + readonly LOG_YELLOW='' + readonly LOG_BLUE='' + readonly LOG_NC='' +fi + +# ============================================================================= +# Logging Functions +# ============================================================================= + +####################################### +# Log an info message (green prefix). +# Arguments: +# $* - Message to log +# Outputs: +# Writes message to stdout +####################################### +log_info() { + echo -e "${LOG_GREEN}[INFO]${LOG_NC} $*" +} + +####################################### +# Log a warning message (yellow prefix). +# Arguments: +# $* - Message to log +# Outputs: +# Writes message to stdout +####################################### +log_warn() { + echo -e "${LOG_YELLOW}[WARN]${LOG_NC} $*" +} + +####################################### +# Log an error message (red prefix). +# Arguments: +# $* - Message to log +# Outputs: +# Writes message to stderr +####################################### +log_error() { + echo -e "${LOG_RED}[ERROR]${LOG_NC} $*" >&2 +} + +####################################### +# Log a step message (blue prefix). +# Arguments: +# $* - Message to log +# Outputs: +# Writes message to stdout +####################################### +log_step() { + echo -e "${LOG_BLUE}[STEP]${LOG_NC} $*" +} diff --git a/shared/codecs/codec.mk b/shared/codecs/codec.mk index 45a762a..4986ea4 100644 --- a/shared/codecs/codec.mk +++ b/shared/codecs/codec.mk @@ -70,12 +70,7 @@ endif # Dependency Graph # ============================================================================= # Most codecs have no inter-dependencies and can build in parallel. -# Exception: vorbis depends on ogg - -PARALLEL_CODECS := libvpx aom dav1d svt-av1 opus ogg lame x264 x265 - -# Codecs with dependencies (must wait) -# vorbis.stamp depends on ogg.stamp (defined in vorbis.mk) +# Exception: vorbis depends on ogg (defined in vorbis.mk) # ============================================================================= # Common Configure Arguments @@ -87,8 +82,6 @@ AUTOCONF_STATIC_ARGS := \ --disable-shared \ --with-pic -AUTOCONF_DARWIN_ARGS := $(AUTOCONF_STATIC_ARGS) - # ============================================================================= # Phony Targets # ============================================================================= diff --git a/shared/ffmpeg.mk b/shared/ffmpeg.mk new file mode 100644 index 0000000..09f2771 --- /dev/null +++ b/shared/ffmpeg.mk @@ -0,0 +1,48 @@ +# ============================================================================= +# Shared FFmpeg Configuration +# ============================================================================= +# Common FFmpeg configure options shared across all platforms. +# Platform-specific options (architecture, hardware acceleration) are defined +# in each platform's Makefile as FFMPEG_BASE_OPTS. +# +# Usage (in platform Makefile): +# include $(PROJECT_ROOT)/shared/ffmpeg.mk +# FFMPEG_CONFIGURE_OPTS := $(FFMPEG_BASE_OPTS) $(FFMPEG_LICENSE_OPTS) +# ============================================================================= + +# ============================================================================= +# FFmpeg Codec Options (by license tier) +# ============================================================================= +# These are identical across all platforms. + +# BSD-licensed codecs (VP8/VP9, AV1, Opus, Vorbis) +FFMPEG_BSD_OPTS := \ + --enable-libvpx \ + --enable-libaom \ + --enable-libsvtav1 \ + --enable-libdav1d \ + --enable-libopus \ + --enable-libvorbis + +# LGPL-licensed codecs (MP3) +FFMPEG_LGPL_OPTS := \ + --enable-libmp3lame + +# GPL-licensed codecs (H.264, H.265) +FFMPEG_GPL_OPTS := \ + --enable-gpl \ + --enable-libx264 \ + --enable-libx265 + +# ============================================================================= +# License Tier Selection +# ============================================================================= +# Combines codec options based on LICENSE value. +# LICENSE is set in the platform Makefile or via command line. + +ifeq ($(LICENSE),free) + FFMPEG_LICENSE_OPTS := $(FFMPEG_BSD_OPTS) $(FFMPEG_LGPL_OPTS) +else + # non-free: includes GPL codecs + FFMPEG_LICENSE_OPTS := $(FFMPEG_BSD_OPTS) $(FFMPEG_LGPL_OPTS) $(FFMPEG_GPL_OPTS) +endif diff --git a/shared/versions.mk b/shared/versions.mk index 0cb3085..28a89af 100644 --- a/shared/versions.mk +++ b/shared/versions.mk @@ -3,12 +3,8 @@ # ============================================================================= # This file is the single source of truth for all dependency versions. # Grouped by license for clarity. -# -# To update: change version, update URL/SHA256, bump CACHE_VERSION # ============================================================================= -CACHE_VERSION := 1 - # ============================================================================= # FFmpeg # ============================================================================= @@ -68,17 +64,3 @@ X265_URL := https://bitbucket.org/multicoreware/x265_git/downloads/x265_$(X265_V NASM_VERSION := 2.16.03 NASM_URL := https://www.nasm.us/pub/nasm/releasebuilds/$(NASM_VERSION)/nasm-$(NASM_VERSION).tar.gz -# ============================================================================= -# Parse-Time Version Validation -# ============================================================================= -# Ensure git-cloned dependencies use immutable refs (commit hashes) for cache -# correctness. Branch names like "stable" cause stale cache hits. -# -# Note: This validation runs after verify.mk is included by platform Makefiles. -# We define the check here but it only executes if verify.mk is loaded. - -# Defer validation until verify.mk functions are available -# This will be called by Makefiles that include both versions.mk and verify.mk -define validate_versions -$(call validate_immutable_ref,X264_VERSION,x264) -endef From 434f63e1cfad6ad3420c07743a54a2437df6f1cb Mon Sep 17 00:00:00 2001 From: pproenca <8202400+pproenca@users.noreply.github.com> Date: Fri, 9 Jan 2026 18:05:27 +0000 Subject: [PATCH 2/2] style: fix SC2015 shellcheck warning in release.yml Replace `A && B && C || D` pattern with proper if-then-else to avoid ambiguous control flow that shellcheck warns about. --- .github/workflows/release.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 35bda1a..c5c0dfa 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -161,7 +161,10 @@ jobs: cd artifacts # Flatten subdirectories for dir in */; do - [[ -d "$dir" ]] && mv "$dir"* . 2>/dev/null && rmdir "$dir" 2>/dev/null || true + if [[ -d "$dir" ]]; then + mv "$dir"* . 2>/dev/null || true + rmdir "$dir" 2>/dev/null || true + fi done # Verify count