# $NetBSD: Makefile,v 1.17 2025/12/15 07:46:57 wiz Exp $

DISTNAME=	afpfs-ng-0.8.1
PKGNAME=	fuse-${DISTNAME}
PKGREVISION=	5
CATEGORIES=	filesystems
MASTER_SITES=	# none: the fork is in the Makronix tree (tools/ext-dist.sh makes the archive)


MAINTAINER=	pkgsrc-users@NetBSD.org
HOMEPAGE=	https://sourceforge.net/projects/afpfs-ng/
COMMENT=	FUSE filesystem for network mounting using AFP

GNU_CONFIGURE=	yes

# Cross build: configure cannot run its malloc(0)/realloc(0) tests and would
# define malloc as rpl_malloc, which nothing provides (undefined reference in
# libafpclient.so).  NetBSD's malloc(0) returns a non-null pointer.
CONFIGURE_ENV+=	ac_cv_func_malloc_0_nonnull=yes
CONFIGURE_ENV+=	ac_cv_func_realloc_0_nonnull=yes

# The code is written for the FUSE 2.6 API (configure.ac sets it, the
# package's CFLAGS replace that); refuse's fuse.h defaults to the latest.
CPPFLAGS+=	-DFUSE_USE_VERSION=26
USE_LIBTOOL=	yes
USE_TOOLS+=	gmake
USE_LANGUAGES=	c c++

REPLACE_SH+=	fuse/afpfs

.include "../../mk/readline.buildlink3.mk"

SUBST_CLASSES+=		termcap
SUBST_STAGE.termcap=	pre-configure
SUBST_FILES.termcap=	configure.ac configure cmdline/Makefile.*
.if ${TERMCAP_TYPE} == none
SUBST_SED.termcap+=	-e 's|ncurses||'
.else
SUBST_SED.termcap+=	-e 's|ncurses|${BUILDLINK_LIBNAME.termcap}|'
.endif

# debug.c: In function 'afp_get_command_name':
# debug.c:62:33: error: array subscript has type 'char' [-Werror=char-subscripts]
#          return afp_command_names[code];
#                                  ^
# Maybe fix this later.
BUILDLINK_TRANSFORM+=	rm:-Werror=char-subscripts

.include "../../devel/gmp/buildlink3.mk"
.include "../../security/libgpg-error/buildlink3.mk"
.include "../../security/libgcrypt/buildlink3.mk"

.include "../../mk/fuse.buildlink3.mk"
.include "../../mk/pthread.buildlink3.mk"
# libtool wrote '=<workdir>/.buildlink/lib/libgcrypt.la ...' (libgmp, libgpg-error)
# into dependency_libs of libafpclient.la: a path that exists only during this
# build (build/obj/destdir.amd64/usr/pkg/lib/libafpclient.la, measured
# 2026-11-15, tasksd t0196).  Same reason and fix as in wm/mcde and x11/mcde-motif.
post-install:
	${RUN}${FIND} ${DESTDIR}${PREFIX}/lib -name '*.la' -type f |	\
	while read f; do						\
		${SED} -i -e 's|=${WRKDIR}/.buildlink/lib/|${PREFIX}/lib/|g' $$f; \
	done

.include "../../mk/bsd.pkg.mk"
