ldacbt: use Meson to build

This commit is contained in:
Emily
2026-07-04 17:04:54 +01:00
parent 41633c73d0
commit 5730d31289
2 changed files with 67 additions and 75 deletions
+52
View File
@@ -0,0 +1,52 @@
project(
'ldacbt',
'c',
meson_version: '>=1.10.0',
version: files('VERSION'),
)
pkg = import('pkgconfig')
cc = meson.get_compiler('c')
dep_m = cc.find_library('m')
lib = library(
'ldacBT',
'abr/src/ldacBT_abr.c',
'src/ldacBT.c',
'src/ldaclib.c',
include_directories: [
'abr/inc',
'inc',
],
dependencies: [dep_m],
version: meson.project_version(),
install: true,
)
install_headers(
'abr/inc/ldacBT_abr.h',
'inc/ldacBT.h',
subdir: 'ldac',
)
pkg.generate(
lib,
name: 'ldacBT-enc',
description: 'LDAC Bluetooth encoder',
subdirs: 'ldac',
)
pkg.generate(
lib,
name: 'ldacBT-abr',
description: 'LDAC Bluetooth ABR library',
subdirs: 'ldac',
)
pkg.generate(
lib,
name: 'ldacBT-dec',
description: 'LDAC Bluetooth decoder',
subdirs: 'ldac',
)
+15 -75
View File
@@ -2,6 +2,8 @@
lib,
stdenv,
fetchFromGitHub,
meson,
ninja,
}:
stdenv.mkDerivation (finalAttrs: {
@@ -24,87 +26,25 @@ stdenv.mkDerivation (finalAttrs: {
./0001-abr-drop-support-for-dynamic-loading-libldac.patch
];
env.NIX_CFLAGS_COMPILE = "-O2 -fPIC -fno-merge-constants -Wall -Iinc -Isrc -Iabr/inc";
nativeBuildInputs = [
meson
ninja
];
mesonBuildType = "release";
# The upstream build system is tied to AOSP, so we use our own Meson
# definitions to replace it.
postPatch = ''
ln -s ${./meson.build} meson.build
# Verify finalAttrs.version matches LDACBT_LIB_VER_* in upstream source.
# Guards against silent version drift when the pinned commit changes.
preBuild = ''
awk -v want=${finalAttrs.version} '
/^#define LDACBT_LIB_VER_/ { v = v sep ($3+0); sep = "." }
END {
if (v != want) { print "version mismatch: package says " want ", source reports " v > "/dev/stderr"; exit 1 }
print v
}
' src/ldacBT_api.c
'';
# Upstream ships AOSP build files and a gcc/ makefile that only knows
# about the in-tree layout. Compile and link directly; the entire
# library is two umbrella translation units.
buildPhase = ''
runHook preBuild
soname=libldacBT.so.${lib.versions.major finalAttrs.version}
sofile=libldacBT.so.${finalAttrs.version}
$CC -shared -Wl,-soname,$soname src/ldaclib.c src/ldacBT.c abr/src/ldacBT_abr.c -lm -o $sofile
runHook postBuild
'';
installPhase = ''
runHook preInstall
install -Dm644 -t $out/lib $sofile
ln -s $sofile $out/lib/$soname
ln -s $sofile $out/lib/libldacBT.so
install -Dm644 inc/ldacBT.h $dev/include/ldac/ldacBT.h
install -Dm644 abr/inc/ldacBT_abr.h $dev/include/ldac/ldacBT_abr.h
mkdir -p $dev/lib/pkgconfig
cat > $dev/lib/pkgconfig/ldacBT-dec.pc <<EOF
prefix=$out
exec_prefix=\''${prefix}
libdir=$out/lib
includedir=$dev/include/ldac
Name: ldacBT-dec
Description: LDAC Bluetooth decoder
Version: ${finalAttrs.version}
Libs: -L\''${libdir} -lldacBT
Libs.private: -lm
Cflags: -I\''${includedir}
EOF
cat > $dev/lib/pkgconfig/ldacBT-enc.pc <<EOF
prefix=$out
exec_prefix=\''${prefix}
libdir=$out/lib
includedir=$dev/include/ldac
Name: ldacBT-enc
Description: LDAC Bluetooth encoder
Version: ${finalAttrs.version}
Libs: -L\''${libdir} -lldacBT
Libs.private: -lm
Cflags: -I\''${includedir}
EOF
cat > $dev/lib/pkgconfig/ldacBT-abr.pc <<EOF
prefix=$out
exec_prefix=\''${prefix}
libdir=$out/lib
includedir=$dev/include/ldac
Name: ldacBT-abr
Description: LDAC Bluetooth ABR library
Version: ${finalAttrs.version}
Libs: -L\''${libdir} -lldacBT
Libs.private: -lm
Cflags: -I\''${includedir}
EOF
runHook postInstall
' src/ldacBT_api.c > VERSION
'';
meta = {