~aman/static-opus-tools

97df5c98572ec1d9bf11aac979049a835ecaaeb1 — Aman Verma 2 months ago 19f9a24
Update build script.
4 files changed, 45 insertions(+), 32 deletions(-)

M Dockerfile
M README.md
M build.sh
M build.yml
M Dockerfile => Dockerfile +1 -1
@@ 8,4 8,4 @@ WORKDIR /home/builder
USER builder
COPY /SHA256SUMS SHA256SUMS
COPY /build.sh build.sh
# RUN ./build.sh
RUN ./build.sh

M README.md => README.md +1 -0
@@ 42,3 42,4 @@ for the build at <https://builds.sr.ht/~aman/job/301491>.
## Todo

- Experiment with LTO (-flto in CFLAGS and LDFLAGS).
- Try compiling with Clang and LLD.

M build.sh => build.sh +42 -30
@@ 17,23 17,18 @@ download() {
    curl -fsL -o libflac.tar.xz "$libflac_url"
    curl -fsL -o libopus.tar.gz "$libopus_url" &
    curl -fsL -o opusfile.tar.gz "$opusfile_url"
    if ! git clone "https://gitlab.xiph.org/xiph/opus-tools.git" git_opus-tools; then
        git -C opus-tools pull
    if ! git clone "https://gitlab.xiph.org/xiph/opus-tools.git" --quiet git_opus-tools; then
        git -C opus-tools pull --quiet
    fi
    if ! git clone "https://gitlab.xiph.org/xiph/libopusenc.git" git_libopusenc; then
        git -C libopusenc pull
    if ! git clone "https://gitlab.xiph.org/xiph/libopusenc.git" --quiet git_libopusenc; then
        git -C libopusenc pull --quiet
    fi
    wait

}

check() {
    sha256sum -c SHA256SUMS
}

die() {
    printf '%s\n' "$1"
    exit 1
    sha256sum -c SHA256SUMS >/dev/null
}

# If all of these files and directories don't already exist, then we need to download them.


@@ 42,32 37,43 @@ if ! { [ -f libogg.tar.xz ] && [ -f libflac.tar.xz ] && [ -f libopus.tar.gz ] &&
fi

if ! check; then
    die "BUILD: Check failed."
    printf "BUILD: Check failed.\n"
    exit 1
fi

export static_flags='-no-pie -static -static-libgcc -static-libstdc++ --static'
# Uncomment this if you are building on a local machine for that machine.
# export CFLAGS='-O3 -pipe -march=native'
export CFLAGS='-O3 -pipe -flto -march=haswell'
export LDFLAGS='-flto'
# Haswell (Intel 4th gen) is a good baseline but use native if you are only going to use
# the binary on one machine.
export CFLAGS='-O3 -pipe -flto -march=haswell -no-pie -static -static-libgcc --static'
export LDFLAGS='-flto -no-pie -static -static-libgcc --static'
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

# Fail without interaction if password is needed.
sudo='sudo -n'
# Verbose and use good amount of threads.
make="make -j$mk_threads V=1"

# For looking at logs later on.
printf '\n==============================================================\n'
printf 'CFLAGS USED:\n    %s\n' "$CFLAGS"
printf 'LDFLAGS USED:\n    %s\n' "$LDFLAGS"
printf '==============================================================\n'

# Build libogg
(
    tar -xJf libogg.tar.xz
    cd libogg-*
    ./configure --enable-static --disable-shared --prefix /usr/local
    make -j$mk_threads
    sudo make install
    $make
    $sudo make install
)

# Build libflac
(
    tar -xJf libflac.tar.xz
    cd flac-*
    ./configure --enable-static --disable-shared --prefix /usr/local CFLAGS="$CFLAGS $static_flags"
    make -j$mk_threads
    sudo make install
    ./configure --enable-static --disable-shared --prefix /usr/local
    $make
    $sudo make install
)

# Build libopus


@@ 75,8 81,8 @@ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
    tar -xzf libopus.tar.gz
    cd opus-*
    ./configure --enable-float-approx --enable-static --disable-shared --prefix /usr/local
    make -j$mk_threads
    sudo make install
    $make
    $sudo make install
)

# Build opusfile


@@ 84,8 90,8 @@ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
    tar -xzf opusfile.tar.gz
    cd opusfile-*
    ./configure --disable-http --enable-static --disable-shared --prefix /usr/local
    make -j$mk_threads
    sudo make install
    $make
    $sudo make install
)

# Build libopusenc


@@ 93,15 99,21 @@ export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
    cd git_libopusenc
    ./autogen.sh
    ./configure --enable-static --disable-shared --prefix /usr/local
    make -j$mk_threads
    sudo make install
    $make
    $sudo make install
)

# Build opus-tools
(
    cd git_opus-tools
    ./autogen.sh
    ./configure --enable-static --disable-shared --prefix /usr/local CFLAGS="$CFLAGS $static_flags"
    make -j$mk_threads
    sudo make install
    ./configure --enable-static --disable-shared --prefix /usr/local
    $make
    $sudo make install
)

opus_binaries='/usr/local/bin/opusenc /usr/local/bin/opusdec /usr/local/bin/opusinfo'
flac_binaries='/usr/local/bin/flac /usr/local/bin/metaflac'
$sudo strip -s $opus_binaries $flac_binaries
printf 'CHECKSUMS:\n'
sha256sum $opus_binaries $flac_binaries

M build.yml => build.yml +1 -1
@@ 3,7 3,7 @@ arch: x86_64
packages: [build-base, autoconf, automake, libtool, git, curl, sudo, pkgconf, nasm]
sources: ["https://git.sr.ht/~aman/static-opus-tools"]
tasks:
  - build: 'cd static-opus-tools && ./build.sh'
  - build: "cd static-opus-tools && ./build.sh"
artifacts:
  - "/usr/local/bin/flac"
  - "/usr/local/bin/metaflac"