#!/bin/sh -e

opus=opus-1.5.2
if ! [ -d local/lib ] ; then
    rm -fr local $opus
    tar xf $opus.tar
    cd $opus
    ./configure --prefix=$(realpath ..)/local \
        --enable-deep-plc \
        --enable-osce \
        --disable-doc \
        --disable-extra-programs
    make -j4
    make install
    cd ..
    rm -r $opus
fi
export PKG_CONFIG_PATH="$(realpath local)/lib/pkgconfig:$PKG_CONFIG_PATH"

mkdir -p bin
[ -d vendor ] && vendor="-mod=vendor"
strip=-ldflags=-s
tags="nolibopusfile"
go build -C cmd/vad $strip $vendor -o ../../bin/vors-vad
go build -C cmd/keygen $strip $vendor -o ../../bin/vors-keygen
go build -C cmd/server $strip $vendor -o ../../bin/vors-server
go build -C cmd/client -tags $tags $strip $vendor -o ../../bin/vors-client
