# Common include for lang/pypy and lang/pypy3
# Also includes bsd.port.pre.mk

.if !defined(LICENSE)
LICENSE=	MIT PSFL
LICENSE_COMB=	multi
.endif

USES+=		compiler:c11

PYTHON_IMPL?=	${PORTNAME}
PYPY_DIR=	${PYTHON_IMPL}-${DISTVERSION:C|([0-9])\.([0-9]+).*|\1.\2|}
PLIST_SUB+=	PYPY_DIR=${PYPY_DIR} \
		PYPY_CFFI_VER=${PYPY_CFFI_VER} \
		PYPY_LDLIBRARY=${PYPY_LDLIBRARY}

.if ${PYTHON_IMPL} == pypy

DISTVERSION=	7.3.14
PY_VERSION_SHORT=	2.7
PYPY_CFFI_VER=	${PYTHON_IMPL}-73
PYPY_LDLIBRARY=	libpypy-c.so
PYPY_EXECUTABLE=	pypy-c

.else # ${PYTHON_IMPL} == pypy3

DISTVERSION=	7.3.14
PYPY_CFFI_VER=	${PYTHON_IMPL_NODOT}-pp${DISTVERSION:S|.||:C|\..*||}-${OPSYS:tl}${OSREL:C|\..*||}
PLIST_SUB+=	PYTHON_IMPL_MINOR=${PYTHON_IMPL_MINOR} \
		PY_VERSION_SHORT=${PY_VERSION_SHORT} \
		PYPY_BCTAG=${PYPY_BCTAG}

OPTIONS_DEFINE=	BYTECOMPILE
OPTIONS_DEFAULT=	BYTECOMPILE

BYTECOMPILE_DESC=	Enable to build byte-compiled Python files

OPTIONS_SINGLE+=	FORPYIMPL BCSTYLE

OPTIONS_SINGLE_FORPYIMPL=	FORPYIMPL39 FORPYIMPL310

FORPYIMPL_DESC=		Required Python compatibility
FORPYIMPL39_DESC=	Build for compat to Python 3.9
FORPYIMPL310_DESC=	Build for compat to Python 3.10

OPTIONS_SINGLE_BCSTYLE=	BCTIMESTAMP BCCHECKEDHASH BCUNCHECKEDHASH

BCSTYLE_DESC=	PEP-552 .pyc-File Invalidation Modes
BCTIMESTAMP_DESC=	Traditional timestamp based .pyc file invalidataion
BCCHECKEDHASH_DESC=	Use checked hash based .pyc file invalidataion
BCUNCHECKEDHASH_DESC=	Use unchecked hash based .pyc file invalidataion

OPTIONS_SUB=		yes
OPTIONS_DEFAULT+=	FORPYIMPL39 BCUNCHECKEDHASH

BCTIMESTAMP_VARS=	COMPILEALL_INVALIDATIONMODE=timestamp
BCCHECKEDHASH_VARS=	COMPILEALL_INVALIDATIONMODE=checked-hash
BCUNCHECKEDHASH_VARS=	COMPILEALL_INVALIDATIONMODE=unchecked-hash

.endif

PY_VERSION_NODOT=       ${PY_VERSION_SHORT:S/.//}
PYTHON_IMPL_MINOR=	pypy${PY_VERSION_SHORT}
PYTHON_IMPL_NODOT=	pypy${PY_VERSION_NODOT}

DISTINFO_FILE=		${.CURDIR}/distinfo.py${PY_VERSION_NODOT}

.include <bsd.port.options.mk>

.if ${PORT_OPTIONS:MFORPYIMPL39}
PY_VERSION_SHORT=	3.9
PYPY_LDLIBRARY=		libpypy3.9-c.so
PYPY_EXECUTABLE=	pypy3.9-c
PYPY_BCTAG=		.pypy39
.endif
.if ${PORT_OPTIONS:MFORPYIMPL310}
PY_VERSION_SHORT=	3.10
PYPY_LDLIBRARY=		libpypy3.10-c.so
PYPY_EXECUTABLE=	pypy3.10-c
PYPY_BCTAG=		.pypy310
.endif

.include <bsd.port.pre.mk>
