Skip to content

Commit d77e772

Browse files
committed
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 96f1af0 commit d77e772

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

scripts/build-alsa-tools.sh

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/bash
2+
# SPDX-License-Identifier: BSD-3-Clause
3+
# Copyright(c) 2018 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/alsa-project/alsa-lib.git"
11+
"https://github.com/alsa-project/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+
declare -a COMMIT_ID=(
18+
"HEAD"
19+
"HEAD"
20+
)
21+
22+
# Directory where repositories will be cloned/updated.
23+
BASE_DIR="$HOME/work/sof" # Or any other desired location
24+
25+
# Arguments to pass to ./configure for each repository. Add or remove
26+
declare -a CONFIGURE_ARGS=(
27+
"--prefix=${BASE_DIR}/tools"
28+
"--prefix=${BASE_DIR}/tools \
29+
--with-alsa-prefix=${BASE_DIR}/tools \
30+
--with-alsa-inc-prefix=${BASE_DIR}/tools/include \
31+
--with-sysroot=${BASE_DIR}/tools \
32+
--with-udev-rules-dir=${BASE_DIR}/tools \
33+
PKG_CONFIG_PATH=${BASE_DIR}/tools \
34+
LDFLAGS=-L${BASE_DIR}/tools/lib"
35+
)
36+
37+
# Arguments to pass to make for each repository. Add or remove arguments as needed.
38+
declare -a TARGET_ARGS=(
39+
"--disable-old-symbols"
40+
"--enable-alsatopology"
41+
)
42+
43+
# Function to check if a commit ID exists in a repository
44+
check_commit() {
45+
local repo_dir="$1"
46+
local commit_id="$2"
47+
48+
if [ -z "$commit_id" ]; then
49+
return 0 # Skip check if no commit ID is provided
50+
fi
51+
52+
if ! git -C "$repo_dir" rev-parse --quiet --verify "$commit_id" >/dev/null 2>&1; then
53+
return 1 # Commit ID not found
54+
else
55+
return 0 # Commit ID found
56+
fi
57+
}
58+
59+
60+
# Function to update the repository
61+
update_repo() {
62+
local repo_dir="$1"
63+
echo "Updating repository: $repo_dir"
64+
git -C "$repo_dir" fetch --all
65+
git -C "$repo_dir" pull
66+
}
67+
68+
# Function to build and install the repository
69+
build_and_install() {
70+
local repo_dir="$1"
71+
local configure_args="$2"
72+
local target_args="$3"
73+
74+
echo "Building and installing: $repo_dir $configure_args $target_args"
75+
76+
if [ ! -f "$repo_dir/gitcompile" ]; then
77+
echo "Error: gitcompile not found in $repo_dir" >&2
78+
exit 1
79+
fi
80+
81+
# if configure exists then we can just run make
82+
if [ ! -f "$repo_dir/configure" ]; then
83+
(cd "$repo_dir" && ./gitcompile $configure_args $target_args) || \
84+
{ echo "configure failed in $repo_dir"; exit 1; }
85+
else
86+
(cd "$repo_dir" && make -j) || { echo "make failed in $repo_dir"; exit 1; }
87+
fi
88+
89+
(cd "$repo_dir" && make install) || { echo "make install failed in $repo_dir"; exit 1; }
90+
91+
echo "Build and installation complete for $repo_dir"
92+
}
93+
94+
# Main script logic
95+
mkdir -p "$BASE_DIR"
96+
97+
for ((i = 0; i < ${#REPOS[@]}; i++)); do
98+
echo "Counter: $i, Value: ${REPOS[i]}"
99+
repo_url=${REPOS[i]}
100+
101+
repo_name=$(basename "$repo_url" .git) # Extract repo name
102+
repo_dir="$BASE_DIR/$repo_name"
103+
104+
if [ ! -d "$repo_dir" ]; then
105+
echo "Cloning repository: $repo_url"
106+
git clone "$repo_url" "$repo_dir" || { echo "git clone failed for $repo_url"; exit 1; }
107+
elif ! check_commit "$repo_dir" "${COMMIT_ID[i]}"; then
108+
update_repo "$repo_dir"
109+
else
110+
echo "Repository $repo_name is up to date."
111+
fi
112+
113+
build_and_install "$repo_dir" "${CONFIGURE_ARGS[i]}"
114+
115+
done
116+
117+
echo "All repositories processed."

0 commit comments

Comments
 (0)