Files
MeowOS-For-R3P2/patch_v2/meow_audiod/build_audiod.sh
T
AskaEth 234b4d13b9 fix(audiod): build_audiod.sh 解 rebase 冲突后补主 checkout 回退(worktree 里也能找到固件树)
rebase 到 main(ca042aa,M43 已合入)时 build_audiod.sh 冲突,解决原则:M43 的 cli 目标
time32 接入与 M50 的路径环境变量化**两者都保留**,守护目标仍不链 time32:
  cli    : "$CC" $INC ... -static -DMEOW_TIME32_LIBC_OVERRIDES meow_audio.c ../sdk/meow_time32.c
  audiod : "$ZIG" cc --target=mipsel-linux-gnueabihf.2.22 ... meow_audiod.c bt_dev.c -lpthread -L"$LIBBT" -lasound
(M43 的守护例外注释按 main 的新措辞保留;LIBBT/ASOUND_SRC 环境变量覆盖与 host 链接兜底保留。)

解冲突时发现一个实际问题:`devdocs/fw-baseline/...` 与 `fw_apps/build/...` 这两条 ASOUND_SRC
候选**都没有入库**,在 git worktree 里运行时 REPO=worktree 根,两条都不存在 → 守护目标
直接 exit 1(本仓库正是按 worktree 并行开发的)。补一条回退:用
`git rev-parse --git-common-dir` 的父目录找到**主 checkout**(worktree 下即主仓根),
把主 checkout 里的 devdocs/ 与 fw_apps/ 也列为候选;普通 checkout 下 MAIN==REPO,行为不变。

自证(解完冲突、真实跑本脚本):meow_audiod 68604B/md5 9f58b219…(glibc-dynamic,
NEEDED=libasound.so.2/libc.so.6/libpthread.so.0,interpreter /lib/ld.so.1);
meow_audio 88888B/md5 3909c8d2…(static,含 S24/S32,4263=3/4403=0/16B-layout=OK);
test_time32_abi.sh --builds ALL PASS(build meow_audio src=yes macro=yes)。
2026-11-11 19:38:32 +08:00

116 lines
7.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# build_audiod.sh — meow_audiod 交叉编译(mipsel glibc-dynamic)+ 宿主多目标可选。
#
# 目标:R3 Pro II / MeowOS(MIPS32 o32,真实 ABI)。audiod 复用 meow_ipc.h(共享协议头,
# -I../meow_launcherd)。audiod 为 svcd 托管的独立守护;meow_audio 为用户侧 CLI。
#
# 【P2 蓝牙链接定案 2026-09-03】设备为 glibc-2.22(ld-2.22.so / libc-2.22.so,非 musl),且
# libasound 会在运行时 dlopen 单独的 bluealsa pcm 插件(/usr/lib/alsa-lib/libasound_module_pcm_bluealsa.so)
# ——故 audiod 必须以**动态 glibc** 形态链接设备现有 libasound.so.2:
# - 用 zig --target=mipsel-linux-gnueabihf.2.22(硬浮点 o32,glibc-2.22 版本引用,设备 libs 齐);
# libasound 原型在 meow_audiod.c 内联声明(不依赖 asoundlib.h)。
# - 删 -static:musl-static 无 dlopen(实测 "Dynamic loading not supported",无法加载 bluealsa 插件);
# musl-dynamic 需设备不存在的 musl ld.so。libasound 链接库来自 libbt/(设备 libasound.so.2 副本)。
# - meow_audio CLI 无 libasound 依赖,保持 musl-static(zig-mipsel-cc)。
#
# 用法:
# ./build_audiod.sh # 交叉编译 → meow_audiod(mipsel glibc-dynamic,BT 直链 libasound)
# ./build_audiod.sh cli # 交叉编译 meow_audio CLI → meow_audio(mipsel musl-static)
# ./build_audiod.sh host # 宿主编译 *_host 并跑 test_audiod_host 回归(FILE sink)
#
# M50 蓝牙输出端到端:audiod 不再读写 /usr/data/alsa.conf(那是 HiBy 播放器的数据文件、语法非法、
# libasound 从不加载),改为 snd_pcm_open("bluealsa:DEV=<mac>,PROFILE=a2dp,CODEC=<token>")
# 内联参数(对应 /etc/alsa/conf.d/20-bluealsa.conf 的 pcm.bluealsa @args),失败必回落 DAC。
#
# 环境变量覆盖:ROOT / REPO 自动推导,ZIG / CC / LIBBT / ASOUND_SRC / CC_HOST 可显式指定。
set -e
cd "$(dirname "$0")"
# ---- 路径解析(M50:全部可被环境变量覆盖,不再硬绑某台机器的目录布局)----
# ROOT 只用于可选的历史路径(旧 .tools/zig-env、hiby_os_crack 解包树);缺省布局下不依赖它。
ROOT="${ROOT:-$HOME/Project/R3ProII}"
REPO="$(cd "$(dirname "$0")/../.." && pwd)" # 仓库根(worktree 亦可)
# mipsel 静态 CC:优先显式环境变量 → 历史 zig 包装脚本 → PATH 里的 zig。
CC="${CC:-}"
if [ -z "$CC" ]; then
if [ -x "$ROOT/.tools/zig-mipsel-cc" ]; then CC="$ROOT/.tools/zig-mipsel-cc"; else CC="zig cc --target=mipsel-linux-musleabi"; fi
fi
# 交叉编译用的 zig:显式 ZIG → 历史 zig-env → PATH。
ZIG="${ZIG:-}"
if [ -z "$ZIG" ]; then
if [ -x "$ROOT/.tools/zig-env/bin/zig" ]; then ZIG="$ROOT/.tools/zig-env/bin/zig"; else ZIG="$(command -v zig || true)"; fi
fi
[ -n "$ZIG" ] || { echo "!! zig not found (set ZIG=/path/to/zig)"; exit 1; }
INC="-I$REPO/patch_v2/meow_launcherd" # 共享协议头(相对仓库根,不再绑 ROOT)
if [ "$1" = "host" ]; then
HOST_CC="${CC_HOST:-cc}"
# BT 目标直链宿主 libasound(无 asoundlib.h,原型内联于 meow_audiod.c)。删 -ldl:BT 不再用 dlopen。
# 优先 -l:libasound.so.2(精确到版本,不依赖 unversioned dev 链接);宿主只装了无版本号
# libasound.so(如 Termux)时退回 -lasound——两者符号集对我们用的 9 个原型等价。
if ! "$HOST_CC" $INC -Os -Wall -Wextra meow_audiod.c bt_dev.c -o meow_audiod_host \
-lpthread -l:libasound.so.2 2>/dev/null; then
"$HOST_CC" $INC -Os -Wall -Wextra meow_audiod.c bt_dev.c -o meow_audiod_host -lpthread -lasound
fi
"$HOST_CC" $INC -Os -Wall -Wextra meow_audio.c -o meow_audio_host -lm
"$HOST_CC" $INC -Os -Wall -Wextra test_audiod_host.c -o test_audiod_host -lm
"$HOST_CC" -Os -Wall -Wextra test_bt_dev.c bt_dev.c -o test_bt_dev -lm
echo "== host builds =="
ls -la meow_audiod_host meow_audio_host test_audiod_host test_bt_dev
file meow_audiod_host meow_audio_host test_audiod_host test_bt_dev
echo "== host regression (test_bt_dev: BT DEV auto-detect) =="
./test_bt_dev || { echo "!! test_bt_dev FAILED"; exit 1; }
echo "== host regression (test_audiod_host) =="
./test_audiod_host || { echo "!! host regression FAILED"; exit 1; }
exit 0
fi
if [ "$1" = "cli" ]; then
# M43: meow_audio 是 musl-static(当前 zig 链),与其它系统组件同源受损 → 链 time32 修
# clock_gettime/usleep(monitor 的 100ms 窗口/轮询)。
"$CC" $INC -Os -Wall -Wextra -static -DMEOW_TIME32_LIBC_OVERRIDES \
meow_audio.c ../sdk/meow_time32.c -o meow_audio -lm
echo "== meow_audio (mipsel static CLI) =="
ls -la meow_audio
md5sum meow_audio
file meow_audio
exit 0
fi
# meow_audiod:mipsel glibc-dynamic,BT 直链 libasound(-Llibbt -lasound)。-lpthread 供播放线程。
# M43 例外:本目标走 glibc-2.22(time_t 32 位、timespec 8 字节)→ 无 musl time64 头/实现错位;
# 当前钉在 fw_content.conf 的出货件则是旧工具链静态 musl,其 4403→ENOSYS→4263+宽度转换本身健康。
# 两种形态都不需要 meow_time32.c(其 __clock_* 接管针对 zig musl 内部符号)。musl-static 的
# meow_audio CLI 已链 time32。
# 链接源 libbt/libasound.so.2.0.0(设备固件 libasound.so.2 副本);缺失时从固件树自拷贝(idempotent)。
# M50:LIBBT / ASOUND_SRC 可被环境变量覆盖;ASOUND_SRC 候选按「显式 → 历史解包树 → 仓内固件基线」
# 顺序取第一个存在的(旧值 $ROOT/hiby_os_crack/... 在多数 checkout 里不存在,set -e 下会直接卡住构建)。
# MAIN = 主 checkout 根(在 git worktree 里运行时,devdocs/ 与 fw_apps/ 这类未入库的固件树
# 只在主 checkout 里;git-common-dir 指向 <main>/.git,其父目录即主 checkout)。普通 checkout 下 == REPO。
MAIN="$(cd "$(git rev-parse --git-common-dir 2>/dev/null || echo .)/.." 2>/dev/null && pwd || true)"
LIBBT="${LIBBT:-libbt}"
if [ -z "$ASOUND_SRC" ]; then
for c in "$ROOT/hiby_os_crack/r3proii/squashfs-root-example/usr/lib/libasound.so.2.0.0" \
"$REPO/devdocs/fw-baseline/squashfs-root/usr/lib/libasound.so.2.0.0" \
"$REPO/fw_apps/build/squashfs-root/usr/lib/libasound.so.2.0.0" \
${MAIN:+"$MAIN/devdocs/fw-baseline/squashfs-root/usr/lib/libasound.so.2.0.0"} \
${MAIN:+"$MAIN/fw_apps/build/squashfs-root/usr/lib/libasound.so.2.0.0"}; do
[ -f "$c" ] && { ASOUND_SRC="$c"; break; }
done
fi
[ -n "$ASOUND_SRC" ] && [ -f "$ASOUND_SRC" ] || {
echo "!! libasound.so.2.0.0 not found (set ASOUND_SRC=/path/to/libasound.so.2.0.0)"; exit 1; }
mkdir -p "$LIBBT"
if [ ! -f "$LIBBT/libasound.so.2.0.0" ]; then cp "$ASOUND_SRC" "$LIBBT/libasound.so.2.0.0"; fi
ln -sf libasound.so.2.0.0 "$LIBBT/libasound.so"
ln -sf libasound.so.2.0.0 "$LIBBT/libasound.so.2"
"$ZIG" cc --target=mipsel-linux-gnueabihf.2.22 $INC -Os -Wall -Wextra meow_audiod.c bt_dev.c -o meow_audiod \
-lpthread -L"$LIBBT" -lasound
echo "== meow_audiod (mipsel glibc-dynamic, BT links libasound.so.2) =="
ls -la meow_audiod
md5sum meow_audiod
file meow_audiod
echo "-- dynamic NEEDED --"
readelf -d meow_audiod 2>/dev/null | grep -iE "needed" || true
echo "-- glibc version refs (max must be <= 2.22) --"
readelf --version-info meow_audiod 2>/dev/null | grep -oE "GLIBC_2\.[0-9]+" | sort -uV | tail -3 || true