diff --git a/scripts/build-alsa-tools.sh b/scripts/build-alsa-tools.sh new file mode 100755 index 000000000000..5e1e7f75d39d --- /dev/null +++ b/scripts/build-alsa-tools.sh @@ -0,0 +1,127 @@ +#!/bin/bash +# SPDX-License-Identifier: BSD-3-Clause +# Copyright(c) 2025 Intel Corporation. All rights reserved. + +# fail immediately on any errors +set -e + +# Array of ALSA Git repository URLs. Add or remove repositories as needed. +declare -a REPOS=( + "https://github.com/thesofproject/alsa-lib.git" + "https://github.com/thesofproject/alsa-utils.git" + # Add more repositories here... +) + +# Commit ID to check for (optional). If specified, the script will update +# the repository if this commit ID is not found. Leave empty to skip. +# This array order must align with REPO array above. +declare -a COMMIT_ID=( + "df8f1cc1ec9d9ee15be5e2c23ad25b9389fd8766" + "09550cd393b1a7d307ee6f26637b1ed7bd275e38" + # Add more IDs here... +) + +# Directory where repositories will be cloned/updated. +if [[ -z "$SOF_WORKSPACE" ]]; then + # Environment variable is empty or unset so use default + BASE_DIR="$HOME/work/sof" +else + # Environment variable exists and has a value + BASE_DIR="$SOF_WORKSPACE" +fi + +# Arguments to pass to ./configure for each repository. Add or remove +declare -a CONFIGURE_ARGS=( + "--prefix=${BASE_DIR}/tools" + "--prefix=${BASE_DIR}/tools \ + --with-alsa-prefix=${BASE_DIR}/tools \ + --with-alsa-inc-prefix=${BASE_DIR}/tools/include \ + --with-sysroot=${BASE_DIR}/tools \ + --with-udev-rules-dir=${BASE_DIR}/tools \ + PKG_CONFIG_PATH=${BASE_DIR}/tools \ + LDFLAGS=-L${BASE_DIR}/tools/lib \ + --with-asound-state-dir=${BASE_DIR}/tools/var/lib/alsa \ + --with-systemdsystemunitdir=${BASE_DIR}/tools/lib/systemd/system" +) + +# Arguments to pass to make for each repository. Add or remove arguments as needed. +declare -a TARGET_ARGS=( + "--disable-old-symbols" + "--enable-alsatopology" +) + +# Function to check if a commit ID exists in a repository +check_commit() { + local repo_dir="$1" + local commit_id="$2" + + if [ -z "$commit_id" ]; then + return 0 # Skip check if no commit ID is provided + fi + + if ! git -C "$repo_dir" rev-parse --quiet --verify "$commit_id" >/dev/null 2>&1; then + return 1 # Commit ID not found + else + return 0 # Commit ID found + fi +} + + +# Function to update the repository +update_repo() { + local repo_dir="$1" + echo "Updating repository: $repo_dir" + git -C "$repo_dir" fetch --all + git -C "$repo_dir" pull +} + +# Function to build and install the repository +build_and_install() { + local repo_dir="$1" + local configure_args="$2" + local target_args="$3" + + echo "Building and installing: $repo_dir $configure_args $target_args" + + if [ ! -f "$repo_dir/gitcompile" ]; then + echo "Error: gitcompile not found in $repo_dir" >&2 + exit 1 + fi + + # if Makefile exists then we can just run make + if [ ! -f "$repo_dir/Makefile" ]; then + (cd "$repo_dir" && ./gitcompile $configure_args $target_args) || \ + { echo "configure failed in $repo_dir"; exit 1; } + else + (cd "$repo_dir" && make -j) || { echo "make failed in $repo_dir"; exit 1; } + fi + + (cd "$repo_dir" && make install) || { echo "make install failed in $repo_dir"; exit 1; } + + echo "Build and installation complete for $repo_dir" +} + +# Main script logic +mkdir -p "$BASE_DIR" + +for ((i = 0; i < ${#REPOS[@]}; i++)); do + echo "Counter: $i, Value: ${REPOS[i]}" + repo_url=${REPOS[i]} + + repo_name=$(basename "$repo_url" .git) # Extract repo name + repo_dir="$BASE_DIR/$repo_name" + + if [ ! -d "$repo_dir" ]; then + echo "Cloning repository: $repo_url" + git clone "$repo_url" "$repo_dir" || { echo "git clone failed for $repo_url"; exit 1; } + elif ! check_commit "$repo_dir" "${COMMIT_ID[i]}"; then + update_repo "$repo_dir" + else + echo "Repository $repo_name is up to date." + fi + + build_and_install "$repo_dir" "${CONFIGURE_ARGS[i]}" + +done + +echo "All repositories processed." diff --git a/scripts/build-tools.sh b/scripts/build-tools.sh index 496ca4c2d7cc..658c8279045a 100755 --- a/scripts/build-tools.sh +++ b/scripts/build-tools.sh @@ -16,7 +16,7 @@ Attention: the list below is _not_ exhaustive. To re-build _everything_ from scratch don't select any particular target; this will build the CMake's default target "ALL". -usage: $0 [-c|-f|-h|-l|-p|-t|-T] +usage: $0 [-c|-f|-h|-l|-p|-t|-T|-A] -h Display help -c Rebuild ctl/ @@ -25,6 +25,7 @@ usage: $0 [-c|-f|-h|-l|-p|-t|-T] -p Rebuild probes/ -T Rebuild topology/ (not topology/development/! Use ALL) -t Rebuild test/topology/ (or tools/test/topology/tplg-build.sh directly) + -A Clone and rebuild local ALSA lib and utils. -C No build, only CMake re-configuration. Shows CMake targets. EOFUSAGE @@ -101,6 +102,7 @@ main() DO_BUILD_ctl=false DO_BUILD_fuzzer=false + DO_BUILD_alsa=false DO_BUILD_logger=false DO_BUILD_probes=false DO_BUILD_tests=false @@ -109,7 +111,7 @@ main() # eval is a sometimes necessary evil # shellcheck disable=SC2034 - while getopts "cfhlptTC" OPTION; do + while getopts "cfhlptTCA" OPTION; do case "$OPTION" in c) DO_BUILD_ctl=true ;; f) DO_BUILD_fuzzer=true ;; @@ -118,6 +120,7 @@ main() t) DO_BUILD_tests=true ;; T) DO_BUILD_topologies=true ;; C) CMAKE_ONLY=true ;; + A) DO_BUILD_alsa=true ;; h) print_usage; exit 1;; *) print_usage; exit 1;; esac @@ -125,6 +128,10 @@ main() shift "$((OPTIND - 1))" reconfigure_build + if "$DO_BUILD_alsa"; then + $SOF_TOP/scripts/build-alsa-tools.sh + fi + if "$CMAKE_ONLY"; then print_build_info exit diff --git a/scripts/docker-run.sh b/scripts/docker-run.sh index 4b3d64fe1c12..a34f10fb1d57 100755 --- a/scripts/docker-run.sh +++ b/scripts/docker-run.sh @@ -33,8 +33,6 @@ test "$(id -u)" = 1000 || >&2 printf "Warning: this script should be run as user ID 1000 to match the container's account\n" set -x -# FIXME: During the transition to sudo-cwd.sh, the tag will be "latest_ubuntu22.04". -# Later it will be back to latest docker run -i -v "${SOF_TOP}":/home/sof/work/sof.git \ -v "${SOF_TOP}":/home/sof/work/sof-bind-mount-DO-NOT-DELETE \ --env CMAKE_BUILD_TYPE \ @@ -45,4 +43,4 @@ docker run -i -v "${SOF_TOP}":/home/sof/work/sof.git \ --env http_proxy="$http_proxy" \ --env https_proxy="$https_proxy" \ $SOF_DOCKER_RUN \ - thesofproject/sof:latest_ubuntu22.04 ./scripts/sudo-cwd.sh "$@" + thesofproject/sof:latest ./scripts/sudo-cwd.sh "$@" diff --git a/tools/ctl/CMakeLists.txt b/tools/ctl/CMakeLists.txt index 70735f88da65..5c4c2dd315b5 100644 --- a/tools/ctl/CMakeLists.txt +++ b/tools/ctl/CMakeLists.txt @@ -4,6 +4,9 @@ add_executable(sof-ctl ctl.c ) +target_link_directories(sof-ctl BEFORE + PRIVATE "${SOF_ROOT_SOURCE_DIRECTORY}/../tools/lib") + target_link_libraries(sof-ctl PRIVATE "-lasound" ) @@ -13,6 +16,7 @@ target_compile_options(sof-ctl PRIVATE ) target_include_directories(sof-ctl PRIVATE + "${SOF_ROOT_SOURCE_DIRECTORY}/../tools/include" "${SOF_ROOT_SOURCE_DIRECTORY}/src/include" "${SOF_ROOT_SOURCE_DIRECTORY}" ) diff --git a/tools/topology/CMakeLists.txt b/tools/topology/CMakeLists.txt index 4b7b36d1a2a1..be032f730dde 100644 --- a/tools/topology/CMakeLists.txt +++ b/tools/topology/CMakeLists.txt @@ -1,4 +1,48 @@ set(SOF_TOPOLOGY_BINARY_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}") +set(SOF_ALSA_TOOLS_DIR "${SOF_ROOT_SOURCE_DIRECTORY}/../tools/bin") +set(ALSATPLG_CMD "${SOF_ALSA_TOOLS_DIR}/alsatplg") + +function(alsatplg_version OUT_STATUS OUT_VERSION) + execute_process(COMMAND ${ALSATPLG_CMD} --version + RESULT_VARIABLE status + OUTPUT_VARIABLE stdout + OUTPUT_STRIP_TRAILING_WHITESPACE) + message(DEBUG "${ALSATPLG_CMD} --version: status=${status}, output=${stdout}") + + set(${OUT_STATUS} "${status}" PARENT_SCOPE) + + # Some error messages have already been printed on stderr + if(NOT status EQUAL 0) + message(WARNING "${ALSATPLG_CMD} --version returned status: ${status}, +${stdout}") + return() + endif() + + string(REPLACE "\n" ";" ALSA_VERSION_LIST ${stdout}) + list(GET ALSA_VERSION_LIST 0 ALSATPLG_VERSION) + string(REGEX MATCH "[0-9]\.[0-9]\.*[0-9]*" ALSATPLG_VERSION_NUMBER ${ALSATPLG_VERSION}) + + set(${OUT_VERSION} "${ALSATPLG_VERSION_NUMBER}" PARENT_SCOPE) +endfunction() + + +# Being written in C, `alsatplg` silently ignores some invalid inputs +# and produces an corrupt .tplg file instead of returning an error code +# that fails the build. For instance, alsatplg versions < 1.2.5 silently +# corrupt `codec_consumer` and turn it into `codec_master` instead. +# Longer story in #5192. +alsatplg_version(STATUS ALSATPLG_VERSION_NUMBER) +if(NOT STATUS EQUAL 0) + message(WARNING "${ALSATPLG_CMD} failed: ${STATUS}; all topologies skipped") + return() +else() + if(${ALSATPLG_VERSION_NUMBER} VERSION_LESS "1.2.5") + message(WARNING "All topologies skipped: minimum alsatplg version 1.2.5,\ + found ${ALSATPLG_VERSION_NUMBER}.") + return() + endif() + # success +endif() # This use of VERBOSE relies on original CMake behavior. # From the add_custom_command() manual: @@ -23,7 +67,7 @@ macro(add_alsatplg_command) # permissions are hardcoded and only the user can read # the -o(utput) file. # See bug https://github.com/alsa-project/alsa-utils/issues/126 - COMMAND alsatplg \$\${VERBOSE:+-v 1} -c ${ARGV0} -o ${ARGV1} + COMMAND ${ALSATPLG_CMD} \$\${VERBOSE:+-v 1} -c ${ARGV0} -o ${ARGV1} USES_TERMINAL ) endmacro() @@ -41,7 +85,7 @@ macro(add_alsatplg2_command input_file output_file include_path) MAIN_DEPENDENCY ${input_file} OUTPUT ${output_file} # -p to pre-process Topology2.0 conf file - COMMAND ALSA_CONFIG_DIR=${CMAKE_SOURCE_DIR}/topology/topology2 alsatplg \$\${VERBOSE:+-v 1} + COMMAND ALSA_CONFIG_DIR=${CMAKE_SOURCE_DIR}/topology/topology2 ${ALSATPLG_CMD} \$\${VERBOSE:+-v 1} -I ${include_path} -D "'${defines}'" -p -c ${input_file} -o ${output_file} USES_TERMINAL )