#!/bin/sh -ue
NAME=zstd
VERSION=1.5.6
RELEASE=1
SOURCE="https://github.com/facebook/zstd/releases/download/v${VERSION}/zstd-${VERSION}.tar.gz"

build() {
	msg "configuring zstd..."
	export CC="${CC:-cc}"
	export CFLAGS="${CFLAGS} -static"
	export LDFLAGS="${LDFLAGS} -static"

	msg "building zstd..."
	for target in lib-release zstd; do
		gmake -j"$NPROC" \
			PREFIX="$PREFIX" \
			HAVE_THREAD=1 \
			HAVE_ZLIB=0 \
			HAVE_LZMA=0 \
			HAVE_LZ4=0 \
			BUILD_SHARED=0 \
			"$target" || die "gmake $target failed"
	done

	msg "installing zstd..."
	for dir in lib programs; do
		cd "$dir"
		gmake PREFIX="$PKG/$PREFIX" install || die "gmake install failed in $dir"
		cd ..
	done
}

. ${0%/*}/../../libsh/libdmake.sh
