1#!/usr/bin/env bash
2
3# Snipped and tucked from https://github.com/plietar/librespot/pull/202/commits/21549641d39399cbaec0bc92b36c9951d1b87b90
4# and further inputs from https://github.com/kingosticks/librespot/commit/c55dd20bd6c7e44dd75ff33185cf50b2d3bd79c3
5
6set -eux
7# Get alsa lib and headers
8ALSA_VER="1.0.25-4"
9DEPS=( \
10  "http://mirrordirector.raspbian.org/raspbian/pool/main/a/alsa-lib/libasound2_${ALSA_VER}_armhf.deb" \
11  "http://mirrordirector.raspbian.org/raspbian/pool/main/a/alsa-lib/libasound2-dev_${ALSA_VER}_armhf.deb" \
12)
13
14# Collect Paths
15SYSROOT="/pi-tools/arm-bcm2708/arm-bcm2708hardfp-linux-gnueabi/arm-bcm2708hardfp-linux-gnueabi/sysroot"
16GCC="/pi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin"
17GCC_SYSROOT="$GCC/gcc-sysroot"
18
19
20export PATH=/pi-tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/:$PATH
21
22# Link the compiler
23export TARGET_CC="$GCC/arm-linux-gnueabihf-gcc"
24
25# Create wrapper around gcc to point to rpi sysroot
26echo -e '#!/bin/bash' "\n$TARGET_CC --sysroot $SYSROOT \"\$@\"" > $GCC_SYSROOT
27chmod +x $GCC_SYSROOT
28
29# Add extra target dependencies to our rpi sysroot
30for path in "${DEPS[@]}"; do
31  curl -OL $path
32  dpkg -x $(basename $path) $SYSROOT
33done
34
35# i don't why this is neccessary
36# ln -s ld-linux.so.3 $SYSROOT/lib/ld-linux-armhf.so.3
37
38# point cargo to use gcc wrapper as linker
39echo -e '[target.arm-unknown-linux-gnueabihf]\nlinker = "gcc-sysroot"' > /.cargo/config
40
41# Build
42cargo build --release --target arm-unknown-linux-gnueabihf --no-default-features --features "alsa-backend"
43