Skip to content

Commit bdfad4e

Browse files
lgirdwoodlrgirdwo
authored andcommitted
scripts: add a script to build a local alsa tools
This script builds a local installation of ALSA lib and associated ALSA utilities that does not impact the system ALSA installation. This will enable a later update to locally build topologies without using the docker container. Signed-off-by: Liam Girdwood <liam.r.girdwood@intel.com>
1 parent b6ee409 commit bdfad4e

File tree

1 file changed

+127
-0
lines changed

1 file changed

+127
-0
lines changed

scripts/build-alsa-tools.sh

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
# Copyright(c) 2025 Intel Corporation. All rights reserved.
4+
5+
# fail immediately on any errors
6+
set -e
7+
8+
# Array of ALSA Git repository URLs. Add or remove repositories as needed.
9+
declare -a REPOS=(
10+
"https://github.com/thesofproject/alsa-lib.git"
11+
"https://github.com/thesofproject/alsa-utils.git"
12+
# Add more repositories here...
13+
)
14+
15+
# Commit ID to check for (optional). If specified, the script will update
16+
# the repository if this commit ID is not found. Leave empty to skip.
17+
# This array order must align with REPO array above.
18+
declare -a COMMIT_ID=(
19+
"df8f1cc1ec9d9ee15be5e2c23ad25b9389fd8766"
20+
"09550cd393b1a7d307ee6f26637b1ed7bd275e38"
21+
# Add more IDs here...
22+
)
23+
24+
# Directory where repositories will be cloned/updated.
25+
if [[ -z "$SOF_WORKSPACE" ]]; then
26+
# Environment variable is empty or unset so use default
27+
BASE_DIR="$HOME/work/sof"
28+
else
29+
# Environment variable exists and has a value
30+
BASE_DIR="$SOF_WORKSPACE"
31+
fi
32+
33+
# Arguments to pass to ./configure for each repository. Add or remove
34+
declare -a CONFIGURE_ARGS=(
35+
"--prefix=${BASE_DIR}/tools"
36+
"--prefix=${BASE_DIR}/tools \
37+
--with-alsa-prefix=${BASE_DIR}/tools \
38+
--with-alsa-inc-prefix=${BASE_DIR}/tools/include \
39+
--with-sysroot=${BASE_DIR}/tools \
40+
--with-udev-rules-dir=${BASE_DIR}/tools \
41+
PKG_CONFIG_PATH=${BASE_DIR}/tools \
42+
LDFLAGS=-L${BASE_DIR}/tools/lib \
43+
--with-asound-state-dir=${BASE_DIR}/tools/var/lib/alsa \
44+
--with-systemdsystemunitdir=${BASE_DIR}/tools/lib/systemd/system"
45+
)
46+
47+
# Arguments to pass to make for each repository. Add or remove arguments as needed.
48+
declare -a TARGET_ARGS=(
49+
"--disable-old-symbols"
50+
"--enable-alsatopology"
51+
)
52+
53+
# Function to check if a commit ID exists in a repository
54+
check_commit() {
55+
local repo_dir="$1"
56+
local commit_id="$2"
57+
58+
if [ -z "$commit_id" ]; then
59+
return 0 # Skip check if no commit ID is provided
60+
fi
61+
62+
if ! git -C "$repo_dir" rev-parse --quiet --verify "$commit_id" >/dev/null 2>&1; then
63+
return 1 # Commit ID not found
64+
else
65+
return 0 # Commit ID found
66+
fi
67+
}
68+
69+
70+
# Function to update the repository
71+
update_repo() {
72+
local repo_dir="$1"
73+
echo "Updating repository: $repo_dir"
74+
git -C "$repo_dir" fetch --all
75+
git -C "$repo_dir" pull
76+
}
77+
78+
# Function to build and install the repository
79+
build_and_install() {
80+
local repo_dir="$1"
81+
local configure_args="$2"
82+
local target_args="$3"
83+
84+
echo "Building and installing: $repo_dir $configure_args $target_args"
85+
86+
if [ ! -f "$repo_dir/gitcompile" ]; then
87+
echo "Error: gitcompile not found in $repo_dir" >&2
88+
exit 1
89+
fi
90+
91+
# if Makefile exists then we can just run make
92+
if [ ! -f "$repo_dir/Makefile" ]; then
93+
(cd "$repo_dir" && ./gitcompile $configure_args $target_args) || \
94+
{ echo "configure failed in $repo_dir"; exit 1; }
95+
else
96+
(cd "$repo_dir" && make -j) || { echo "make failed in $repo_dir"; exit 1; }
97+
fi
98+
99+
(cd "$repo_dir" && make install) || { echo "make install failed in $repo_dir"; exit 1; }
100+
101+
echo "Build and installation complete for $repo_dir"
102+
}
103+
104+
# Main script logic
105+
mkdir -p "$BASE_DIR"
106+
107+
for ((i = 0; i < ${#REPOS[@]}; i++)); do
108+
echo "Counter: $i, Value: ${REPOS[i]}"
109+
repo_url=${REPOS[i]}
110+
111+
repo_name=$(basename "$repo_url" .git) # Extract repo name
112+
repo_dir="$BASE_DIR/$repo_name"
113+
114+
if [ ! -d "$repo_dir" ]; then
115+
echo "Cloning repository: $repo_url"
116+
git clone "$repo_url" "$repo_dir" || { echo "git clone failed for $repo_url"; exit 1; }
117+
elif ! check_commit "$repo_dir" "${COMMIT_ID[i]}"; then
118+
update_repo "$repo_dir"
119+
else
120+
echo "Repository $repo_name is up to date."
121+
fi
122+
123+
build_and_install "$repo_dir" "${CONFIGURE_ARGS[i]}"
124+
125+
done
126+
127+
echo "All repositories processed."

0 commit comments

Comments
 (0)