Last active
September 14, 2024 15:57
-
-
Save spvkgn/60c12010d4cae1243dfee45b0821f692 to your computer and use it in GitHub Desktop.
Script to build a statically linked opus-tools
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -eo pipefail | |
# Script to build a statically linked version of opus-tools | |
# | |
# Release tarballs: | |
# http://downloads.xiph.org/releases/opus/ | |
# http://downloads.xiph.org/releases/ogg/ | |
# http://downloads.xiph.org/releases/flac/ | |
# | |
# Build deps: | |
# Debian/Ubuntu: apt install autoconf automake libtool-bin pkg-config git libarchive-tools wget | |
# Alpine: apk add bash build-base coreutils grep wget tar xz autoconf automake libtool pkgconf git libarchive-tools | |
BUILD_DIR=$PWD/build | |
export PKG_CONFIG_PATH="$BUILD_DIR/lib/pkgconfig" | |
export CFLAGS="-O3 -fno-strict-aliasing -march=native" | |
ARCH=$(uname -m) | |
SUFFIX="-static" | |
get_sources() { | |
SOURCES_URL=http://downloads.xiph.org/releases/ | |
NAME=$1 | |
case $NAME in | |
*"opus"*) SOURCES_URL+="opus" ;; | |
*"ogg"*) SOURCES_URL+="ogg" ;; | |
*"flac"*) SOURCES_URL+="flac" ;; | |
esac | |
echo "Download $NAME sources" | |
wget -qO- $SOURCES_URL |\ | |
grep -Po "href=\"\K$NAME-(\d+\.)+\d+.*\.tar\.(gz|xz)(?=\")" | sort -V | tail -1 |\ | |
xargs -I{} wget -qO- $SOURCES_URL/{} | bsdtar -x | |
} | |
mkdir -p "$BUILD_DIR" | |
# build libogg | |
get_sources libogg | |
( cd libogg-*/ | |
autoreconf -fi && \ | |
./configure --prefix=$BUILD_DIR \ | |
--disable-shared --enable-static \ | |
--disable-dependency-tracking && \ | |
make -j$(nproc) install ) | |
# build FLAC | |
get_sources flac | |
( cd flac-*/ | |
autoreconf -fi && \ | |
./configure --prefix=$BUILD_DIR \ | |
--disable-shared --enable-static \ | |
--disable-dependency-tracking \ | |
--disable-debug \ | |
--disable-oggtest \ | |
--disable-cpplibs \ | |
--disable-doxygen-docs \ | |
--with-ogg="$BUILD_DIR" && \ | |
make -j$(nproc) install ) | |
# build Opus | |
get_sources opus | |
( cd opus-*/ | |
[[ "$ARCH" =~ arm ]] && EXTRA_CONFIG_FLAGS=--enable-fixed-point | |
autoreconf -fi && \ | |
./configure --prefix=$BUILD_DIR \ | |
--disable-shared --enable-static \ | |
--disable-dependency-tracking \ | |
--disable-maintainer-mode \ | |
--disable-doc \ | |
--disable-extra-programs $OPUS_EXTRA_CONFIG_FLAGS && \ | |
make -j$(nproc) install ) | |
# build opusfile | |
get_sources opusfile | |
( cd opusfile-*/ | |
[[ "$ARCH" =~ arm ]] && EXTRA_CONFIG_FLAGS=--enable-fixed-point | |
autoreconf -fi && \ | |
./configure --prefix=$BUILD_DIR \ | |
--disable-shared --enable-static \ | |
--disable-dependency-tracking \ | |
--disable-maintainer-mode \ | |
--disable-examples \ | |
--disable-doc \ | |
--disable-http $EXTRA_CONFIG_FLAGS && \ | |
make -j$(nproc) install ) | |
# build libopusenc | |
get_sources libopusenc | |
( cd libopusenc-*/ | |
autoreconf -fi && \ | |
./configure --prefix=$BUILD_DIR \ | |
--disable-shared --enable-static \ | |
--disable-dependency-tracking \ | |
--disable-maintainer-mode \ | |
--disable-examples \ | |
--disable-doc && \ | |
make -j$(nproc) install ) | |
# build opus-tools | |
git clone --depth 1 https://github.com/xiph/opus-tools.git | |
( cd opus-tools | |
./autogen.sh && \ | |
sed -e 's/@LDFLAGS@/@LDFLAGS@ -all-static/' -i Makefile.in | |
LDFLAGS="-Wl,-static -static -static-libgcc" \ | |
./configure --prefix=$BUILD_DIR \ | |
--disable-dependency-tracking \ | |
--disable-maintainer-mode | |
make -j$(nproc) install ) | |
if ls $BUILD_DIR/bin/opus* > /dev/null 2>&1 ; then | |
for file in $BUILD_DIR/bin/opus* ; do | |
cp $file $PWD/$(basename $file)$SUFFIX && \ | |
strip $PWD/$(basename $file)$SUFFIX | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using
git
https://gist.github.com/guest271314/12a93ff775590867c0862be45fc71161