# Template file for '7zip'
pkgname=7zip
version=23.01
revision=1
short_desc="File archiver with a high compression ratio"
maintainer="Roberto Ricci <io@r-ricci.it>"
license="LGPL-2.1-or-later, BSD-3-Clause"
homepage="https://www.7-zip.org"
changelog="https://www.7-zip.org/history.txt"
distfiles="https://www.7-zip.org/a/7z${version//./}-src.tar.xz"
checksum=356071007360e5a1824d9904993e8b2480b51b570e8c9faf7c0f58ebe4bf9f74
alternatives="
 7z:7z:/usr/bin/7zip
 7z:7za:/usr/bin/7zip
 7z:7zr:/usr/bin/7zip"

if [ "$XBPS_TARGET_LIBC" = musl ]; then
	# missing pthread_attr_setaffinity_np()
	CFLAGS+=" -DZ7_AFFINITY_DISABLE"
	CXXFLAGS+=" -DZ7_AFFINITY_DISABLE"
fi

do_build() {
	cd "${wrksrc}/CPP/7zip/Bundles/Alone2"

	case "$XBPS_TARGET_MACHINE" in
	aarch64*) _7z_makefile="../../cmpl_gcc_arm64.mak";;
	*)        _7z_makefile="../../cmpl_gcc.mak";;
	esac

	for opts in "O=b/norar DISABLE_RAR_COMPRESS=1" "O=b/rar"; do
		make "$makejobs" -f "$_7z_makefile" \
			CC="$CC" CXX="$CXX" \
			VOID_CFLAGS="$CFLAGS" VOID_CXXFLAGS="$CXXFLAGS" \
			VOID_LDFLAGS="$LDFLAGS" VOID_CPPFLAGS="$CPPFLAGS" \
			$opts
	done
}

do_install() {
	vbin "${wrksrc}/CPP/7zip/Bundles/Alone2/b/norar/7zz" 7zip
	vlicense "${wrksrc}/DOC/License.txt"
}

7zip-unrar_package() {
	license+=", custom:freeware"
	repository=nonfree
	short_desc+=" - RAR support"
	alternatives="
	 7z:7z:/usr/bin/7zip-unrar
	 7z:7za:/usr/bin/7zip-unrar
	 7z:7zr:/usr/bin/7zip-unrar"

	pkg_install() {
		vbin "${wrksrc}/CPP/7zip/Bundles/Alone2/b/rar/7zz" 7zip-unrar
		vlicense "${wrksrc}/DOC/License.txt"
	}
}

p7zip_package() {
	build_style=meta
	depends=7zip
	short_desc="Command-line version of the 7zip compressed file archive"
	short_desc+=" (transitional dummy package)"
}

p7zip-unrar_package() {
	build_style=meta
	repository=nonfree
	depends=7zip-unrar
	short_desc="Command-line version of the 7zip compressed file archive - RAR support"
	short_desc+=" (transitional dummy package)"
}
