# $NetBSD: Makefile,v 1.75 2026/01/29 00:35:05 gdt Exp $

DISTNAME=	bup-0.33.71.883
CATEGORIES=	sysutils
MASTER_SITES=	${MASTER_SITE_GITHUB:=bup/}
GITHUB_TAG=	89ddbc64a7f2430c1c99b8cd17212c77e380f5ad
# bup has two problems that make packaging difficult.  One is that
# building man pages requires non-portable tools (pandoc).  The other
# is that it is hosted on github, which makes hosting tarballs
# difficult.  The combination of this leads to having a branch "man"
# in bup's git which has autogenerated man pages.  The third problem
# is that github.mk assumes that there is one distfile.

# Upstream should have a tag for built man pages, but doesn't.
# EXTRACT_SUFX default value is set too late, so using it in SITES.* fails.
EXTRACT_SUFX=		.tar.gz
MAN_TAG=		26d961455dc071f166a3f6f54e6ceb0b71cf2524
MAN_UNPACK=		bup-${MAN_TAG}
MAN_DISTFILE=		bup-man-${MAN_TAG}${EXTRACT_SUFX}
SITES.${MAN_DISTFILE}=	-${MASTER_SITE_GITHUB:=bup/bup/archive/}${MAN_TAG}${EXTRACT_SUFX}
# Upstream provides html, but we choose not to include it in the package.
#HTML_TAG=		66eccb7eb49575d006d193276018d9551ac5b4d4
DISTFILES=		${DEFAULT_DISTFILES} ${MAN_DISTFILE}

MAINTAINER=	gdt@NetBSD.org
HOMEPAGE=	https://github.com/bup/bup
COMMENT=	Highly efficient file backup system based on the git packfile format
LICENSE=	gnu-gpl-v2

USE_LANGUAGES=	c
USE_TOOLS+=	bash gmake perl:run
HAS_CONFIGURE=	yes
CONFIG_SHELL=	bash

# On macOS 10.13, building bup fails with defaults but builds with
# USE_CWRAPPERS=no.   The error is
#   Looking for cpp (/path/to/pkgsrc/sysutils/bup/work/.cwrapper/bin/cpp) (can't run cpp as a pipeline)

DEPENDS+=	par2-[0-9]*:../../archivers/par2
DEPENDS+=	${PYPKGPREFIX}-tornado-[0-9]*:../../www/py-tornado
DEPENDS+=	git-base-[0-9]*:../../devel/git-base
TEST_DEPENDS+=	${PYPKGPREFIX}-test-[0-9]*:../../devel/py-test
TEST_DEPENDS+=	${PYPKGPREFIX}-test-xdist-[0-9]*:../../devel/py-test-xdist
TEST_DEPENDS+=	rsync-[0-9]*:../../net/rsync
TEST_DEPENDS+=	rdiff-backup-[0-9]*:../../sysutils/rdiff-backup

DIST_MANPAGES=		${WRKDIR}/${MAN_UNPACK}

ALL_ENV+=	BUP_PYTHON_CONFIG=${PREFIX}/bin/python${PYVERSSUFFIX}-config

MAKE_FILE=	GNUmakefile
MAKE_FLAGS+=	PREFIX=${PREFIX}
MAKE_FLAGS+=	PYTHON=${PYTHONBIN}
MAKE_FLAGS+=	MANDIR=${DESTDIR}${PREFIX}/${PKGMANDIR}

# Even if converters/pandoc is installed, pretend as if it isn't
MAKE_FLAGS+=	PANDOC=

# find work/ -type f |xargs egrep 'env.*bash'|awk -F: '{print $1}' | sed -e s,work/bup-5f9cf697b3daa3d4d6899f9366ebc1fd64161a32/,,
# and merge to the list
REPLACE_BASH+=		configure
REPLACE_BASH+=		dev/checksum
REPLACE_BASH+=		dev/compare-trees
REPLACE_BASH+=		dev/configure-sampledata
REPLACE_BASH+=		dev/force-delete
REPLACE_BASH+=		dev/git-cat-tree
REPLACE_BASH+=		dev/path-fs
REPLACE_BASH+=		dev/perf-glance
REPLACE_BASH+=		dev/prep-for-debianish-build
REPLACE_BASH+=		dev/prep-for-macos-build
REPLACE_BASH+=		dev/refresh
REPLACE_BASH+=		dev/sync-tree
REPLACE_BASH+=		dev/system-info
REPLACE_BASH+=		dev/update-checkout-info
REPLACE_BASH+=		dev/update-doc-branches
REPLACE_BASH+=		dev/validate-python
REPLACE_BASH+=		dev/with-tty
REPLACE_BASH+=		lib/cmd/bup-import-rdiff-backup
REPLACE_BASH+=		pylint
REPLACE_BASH+=		test/ext/test-btl
REPLACE_BASH+=		test/ext/test-cat-file
REPLACE_BASH+=		test/ext/test-comparative-split-join
REPLACE_BASH+=		test/ext/test-compression
REPLACE_BASH+=		test/ext/test-drecurse
REPLACE_BASH+=		test/ext/test-empty-metadata
REPLACE_BASH+=		test/ext/test-fsck
REPLACE_BASH+=		test/ext/test-fuse
REPLACE_BASH+=		test/ext/test-gc
REPLACE_BASH+=		test/ext/test-gc-removes-incomplete-trees
REPLACE_BASH+=		test/ext/test-get-excludes
REPLACE_BASH+=		test/ext/test-get-missing
REPLACE_BASH+=		test/ext/test-get-repair-bupm
REPLACE_BASH+=		test/ext/test-get-repair-symlinks
REPLACE_BASH+=		test/ext/test-get-rewrite-missing
REPLACE_BASH+=		test/ext/test-help
REPLACE_BASH+=		test/ext/test-import-duplicity
REPLACE_BASH+=		test/ext/test-import-rdiff-backup
REPLACE_BASH+=		test/ext/test-index
REPLACE_BASH+=		test/ext/test-index-check-device
REPLACE_BASH+=		test/ext/test-index-clear
REPLACE_BASH+=		test/ext/test-index-save-type-change
REPLACE_BASH+=		test/ext/test-init
REPLACE_BASH+=		test/ext/test-install
REPLACE_BASH+=		test/ext/test-list-idx
REPLACE_BASH+=		test/ext/test-ls
REPLACE_BASH+=		test/ext/test-ls-remote
REPLACE_BASH+=		test/ext/test-main
REPLACE_BASH+=		test/ext/test-meta
REPLACE_BASH+=		test/ext/test-meta-acls
REPLACE_BASH+=		test/ext/test-misc
REPLACE_BASH+=		test/ext/test-on
REPLACE_BASH+=		test/ext/test-packsizelimit
REPLACE_BASH+=		test/ext/test-redundant-saves
REPLACE_BASH+=		test/ext/test-restore-map-owner
REPLACE_BASH+=		test/ext/test-restore-single-file
REPLACE_BASH+=		test/ext/test-rewrite
REPLACE_BASH+=		test/ext/test-rm
REPLACE_BASH+=		test/ext/test-rm-between-index-and-save
REPLACE_BASH+=		test/ext/test-save-creates-no-unrefs
REPLACE_BASH+=		test/ext/test-save-data-race
REPLACE_BASH+=		test/ext/test-save-errors
REPLACE_BASH+=		test/ext/test-save-restore
REPLACE_BASH+=		test/ext/test-save-restore-excludes
REPLACE_BASH+=		test/ext/test-save-smaller
REPLACE_BASH+=		test/ext/test-save-strip-graft
REPLACE_BASH+=		test/ext/test-save-symlink-race
REPLACE_BASH+=		test/ext/test-save-with-valid-parent
REPLACE_BASH+=		test/ext/test-sparse-files
REPLACE_BASH+=		test/ext/test-split-files-config
REPLACE_BASH+=		test/ext/test-split-join
REPLACE_BASH+=		test/ext/test-tag
REPLACE_BASH+=		test/ext/test-treesplit
REPLACE_BASH+=		test/ext/test-tz
REPLACE_BASH+=		test/ext/test-validate-object-links
REPLACE_BASH+=		test/ext/test-validate-ref-links
REPLACE_BASH+=		test/ext/test-validate-refs
REPLACE_BASH+=		test/ext/test-versioning-and-archive
REPLACE_BASH+=		test/ext/test-walk-object-order
REPLACE_BASH+=		test/ext/test-web
REPLACE_BASH+=		test/ext/test-xdev

DOCDIR=			share/doc/${PKGBASE}

INSTALLATION_DIRS+=	${PKGMANDIR}/man1 ${DOCDIR}

post-install:
	${INSTALL_DATA} ${DIST_MANPAGES}/*.1 ${DESTDIR}${PREFIX}/${PKGMANDIR}/man1
	${INSTALL_DATA} ${WRKSRC}/DESIGN.md ${DESTDIR}${PREFIX}/${DOCDIR}
	${INSTALL_DATA} ${WRKSRC}/README.md ${DESTDIR}${PREFIX}/${DOCDIR}

.include "options.mk"

# Note that tests 1) will fail on a fs mounted noatime, 2) need a lot
# of space, perhaps 1 GB, and 3) can fail with test data at the DST
# boundary because of what I believe is a bug in NetBSD libc.
TEST_TARGET=	test
# \todo Pass MAKE_JOBS into "gmake test" via -j.
TEST_ENV+=	TZ=UTC

# \todo Investigate "bup ftp" crash with NetBSD editline and resolve.
.include "../../devel/readline/buildlink3.mk"
.include "../../lang/python/application.mk"
.include "../../mk/bsd.pkg.mk"
