#	$Makronix$
#
# junction -- one of the project's own programs, the source is ext/src/junction.

DISTNAME=	junction-0.1
CATEGORIES=	misc
MASTER_SITES=	# empty
DISTFILES=	# empty

MAINTAINER=	lotherk@lother.io
COMMENT=	Policy router for OpenAI-compatible model endpoints
LICENSE=	cncl-1.0

NO_CONFIGURE=	yes
NO_BUILDLINK=	yes
BUILD_TARGET=	all
INSTALL_TARGET=	install

MAKE_FLAGS+=	PREFIX=${PREFIX}
MAKE_FLAGS+=	DESTDIR=${DESTDIR}

# junction's Makefile is GNU make (ifeq, $(wildcard)).
USE_TOOLS+=	gmake
MAKE_PROGRAM=	${GMAKE}

# Its own defaults (dialect, _POSIX_C_SOURCE, -pthread) are replaced by a
# variable on the command line, so they are repeated here.  TLS: the Makefile
# looks for openssl/ssl.h on the BUILD host, which in a cross build is the
# wrong place; the target's base system has libssl and libcrypto, so J_HAVE_TLS
# and the libraries are given outright.  -D_NETBSD_SOURCE: NetBSD's headers hide
# usleep(3) behind it (src/mcp.c:640, measured 2026-11-23); _DEFAULT_SOURCE is
# glibc's.  No -Werror.
MAKE_FLAGS+=	CFLAGS=${CFLAGS:Q}\ -std=c99\ -pthread
MAKE_FLAGS+=	CPPFLAGS=-D_POSIX_C_SOURCE=200809L\ -D_DEFAULT_SOURCE\ -D_NETBSD_SOURCE\ -DJ_HAVE_TLS
MAKE_FLAGS+=	LDFLAGS=${LDFLAGS:Q}\ -pthread
MAKE_FLAGS+=	TLS_LIBS=-lssl\ -lcrypto

# The source is ext/src/junction in this repository, the tree git tracks and a person
# edits -- not a tarball (net/fetch and pkgtools/pkg_install build from their
# files/ the same way: no DISTFILES, no distinfo, and do-extract fills WRKSRC).
# Three levels above the directory pkgsrc builds in: the development tree, /mnt
# inside the build chroot and /usr/src on an installed system.  'pwd -P' because
# pkgsrc refuses a WRKDIR path that is not canonical and the mirror in pkgsrc/
# is reached through a symlink (tools/ext-sync.sh).
_MAKRONIX_TOP!=	cd ${.CURDIR}/../../.. && pwd -P
SRC=		${_MAKRONIX_TOP}/ext/src/junction

# The copy is made by a script, not by ${CP} -R: pkgsrc extracts once, and
# a commit after that never reached the work directory (tools/ext-extract.sh).
do-extract:
	${RUN}${SH} ${_MAKRONIX_TOP}/tools/ext-extract.sh ${SRC} ${WRKSRC}

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