# $NetBSD: Makefile,v 1.45 2022/01/23 22:04:33 wiz Exp $

DISTNAME=	zstd-1.5.2
CATEGORIES=	archivers
MASTER_SITES=	${MASTER_SITE_GITHUB:=facebook/}
GITHUB_TAG=	v${PKGVERSION_NOREV}

MAINTAINER=	pkgsrc-users@NetBSD.org
HOMEPAGE=	https://facebook.github.io/zstd/
COMMENT=	Fast real-time compression algorithm
LICENSE=	modified-bsd OR gnu-gpl-v2

CHECK_PORTABILITY_SKIP+=	tests/playTests.sh

# 1.4.8
# ld: ../lib/libzstd.a: error adding symbols: no more archived files
# ld:../lib/libzstd.a: file format not recognized; treating as linker script
# ld:../lib/libzstd.a:1: syntax error
# or
# ld: ../lib/libzstd.a: error adding symbols: file format not recognized
# reported as
# https://github.com/facebook/zstd/issues/2453
#MAKE_JOBS_SAFE=		no

.include "../../mk/bsd.prefs.mk"

# See HASH and BUILD_DIR in lib/Makefile and programs/Makefile.
# Set BUILD_DIR so that HASH is not needed and there is no
# need for coreutils as a dependency.
# HASH is set to false because programs/Makefile try to
# execute HASH in order to see if it exists but the result
# is unused when BUILD_DIR is set.
MAKE_ENV+=		BUILD_DIR=obj
MAKE_ENV+=		HASH=${FALSE}

USE_LANGUAGES=		c c++
USE_TOOLS+=		ggrep gmake pkg-config
PKGCONFIG_OVERRIDE+=	lib/libzstd.pc.in
MAKE_FLAGS=		MANDIR=${PREFIX}/${PKGMANDIR}
MAKE_FLAGS+=		mandir=${PREFIX}/${PKGMANDIR}
MAKE_FLAGS+=		INSTALL=${INSTALL:Q}

.if !empty(USE_CROSS_COMPILE:M[yY][eE][sS])
BUILD_TARGET=		allzstd
.else
BUILD_TARGET=		allmost
.endif
TEST_TARGET=		test

# Needed for nanosleep() on Solaris 10, PR pkg/56225
LDFLAGS.SunOS+=		-lrt

post-install:
	lndir.sh -l sf ${PREFIX}/bin ${PREFIX}/native/usr/bin ${DESTDIR}
	lndir.sh -l sf ${PREFIX}/include ${PREFIX}/native/usr/include ${DESTDIR}
	lndir.sh -l sf ${PREFIX}/lib ${PREFIX}/native/usr/lib ${DESTDIR}

#	lndir.sh ${DESTDIR}${PREFIX}/bin ${DESTDIR}${PREFIX}/native/usr/bin
#	lndir.sh ${DESTDIR}${PREFIX}/include ${DESTDIR}${PREFIX}/native/usr/include
#	lndir.sh ${DESTDIR}${PREFIX}/lib ${DESTDIR}${PREFIX}/native/usr/lib

#.include "../../mk/bsd.prefs.mk"
.if !empty(USE_CROSS_COMPILE:M[yY][eE][sS])
PLIST_SRC=
GENERATE_PLIST+= \
	cd ${DESTDIR}${PREFIX} && \
	${FIND} * \( -type f -o -type l \) -print | ${SORT} ;
.endif

.include "../../archivers/lz4/buildlink3.mk"
.include "../../archivers/xz/buildlink3.mk"
.include "../../devel/zlib/buildlink3.mk"
.include "../../mk/bsd.pkg.mk"
