# Description: Configuration GUI for niri (Wayland compositor)
# URL: https://github.com/stefonarch/niri-settings
# Maintainer: Jay Lanagan, j at lngn dot net
# Depends on: libjuice libsrtp

name=libdatachannel
version=0.24.1
release=1
_plog_commit=e5c033e317a01b2703d13aab42288d09b2efdafc
_usrsctp_commit=07f871bda23943c43c9e74cc54f25130459de830
source=(https://github.com/paullouisageneau/$name/archive/v$version/$name-$version.tar.gz
https://github.com/SergiusTheBest/plog/archive/$_plog_commit/plog-$_plog_commit.tar.gz
https://github.com/sctplab/usrsctp/archive/$_usrsctp_commit/usrsctp-$_usrsctp_commit.tar.gz)
renames=(SKIP SKIP SKIP)

unpack_source() {
  mkdir -p $SRC/$name-$version/deps/{plog,usrsctp}
  local i url orig rename local_file base
  for (( i=0; i<${#source[@]}; i++ )); do
    url="${source[i]}"
    orig="$(get_filename "$url")"
    rename="${renames[i]}"
    local_file="$orig"
    if [ -n "$rename" ] && [ "$rename" != "SKIP" ]; then
      local_file="$PKGMK_SOURCE_DIR/$rename"
    fi
    base="${local_file##*/}"

    case "$base" in
      $name-$version.tar.gz)
        bsdtar -p -o -C "$SRC" -xf "$local_file" ;;
      plog-$_plog_commit.tar.gz)
        bsdtar -p -o -C "$SRC/$name-$version/deps/plog" \
               --strip-components 1 -xf "$local_file" ;;
      usrsctp-$_usrsctp_commit.tar.gz)
        bsdtar -p -o -C "$SRC/$name-$version/deps/usrsctp" \
               --strip-components 1 -xf "$local_file" ;;
      *)
        cp "$local_file" "$SRC" ;;
    esac
  done
}

build() {

  cmake -B build -S $name-$version \
    -D CMAKE_INSTALL_PREFIX=/usr \
    -D CMAKE_INSTALL_LIBDIR=lib \
    -D CMAKE_BUILD_TYPE=Release \
    -D USE_GNUTLS=0 \
    -D USE_NICE=0 \
    -D USE_SYSTEM_JUICE=1 \
    -D USE_SYSTEM_SRTP=1 \
    -D NO_EXAMPLES=1 \
    -D NO_TESTS=1 \
    -Wno-dev
  make -C build

  cd build
  make install/strip DESTDIR=$PKG

}
