# $NetBSD: Makefile.common,v 1.14 2022/11/28 19:07:52 gdt Exp $
#
# used by x11/py-sip/Makefile
# used by x11/py-sip-qt5/Makefile

DISTNAME=	sip-4.19.25
CATEGORIES=	x11 devel python
MASTER_SITES=	https://www.riverbankcomputing.com/static/Downloads/sip/${PKGVERSION_NOREV}/

# As of 2022-11 the plan seems to be to have sip(4), sip5 and sip6 in
# parallel.
# Before updating, please ensure that qgis builds and works.  sip4 and
# sip5 are not compatible, and apparently one must use the same sip to
# build py-qt5 and perhaps py-qt5-qscintilla as qgis.  Some hints:
#  https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=964132
# 2022-11: qgis 3.28.1 with pkgsrc py-qt5 fails to build with py-sip5
MAINTAINER=	pkgsrc-users@NetBSD.org
HOMEPAGE=	https://riverbankcomputing.com/software/sip/

DISTINFO_FILE=	${.CURDIR}/../../x11/py-sip/distinfo
PATCHDIR=	${.CURDIR}/../../x11/py-sip/patches

USE_LANGUAGES=		c c++
USE_LIBTOOL=		yes
USE_TOOLS+=		gmake

CONFIGURE_ARGS+=	-b ${PREFIX}/bin
CONFIGURE_ARGS+=	-d ${PREFIX}/${PYSITELIB}
CONFIGURE_ARGS+=	-e ${PREFIX}/${PYINC}
CONFIGURE_ARGS+=	-v ${PREFIX}/share/sip${PYVERSSUFFIX}
CONFIGURE_ARGS+=	CFLAGS=${CFLAGS:Q}
CONFIGURE_ARGS+=	CXXFLAGS=${CXXFLAGS:Q}
CONFIGURE_ARGS+=	INCDIR=${PREFIX}/include
CONFIGURE_ARGS+=	LIBDIR=${PREFIX}/lib

CONFIGURE_ARGS.DragonFly+=	-p freebsd-g++

PY_PATCHPLIST=		yes
PYTHON_VERSIONS_INCOMPATIBLE+= 311 # as of 4.19.25

.include "../../mk/compiler.mk"

.if ${OPSYS} == "Darwin"
CONFIGURE_ARGS+=	CFLAGS_SHLIB=-fno-common
CONFIGURE_ARGS+=	LFLAGS_PLUGIN="-bundle -flat_namespace -undefined suppress"
.else
CONFIGURE_ARGS+=	CFLAGS_SHLIB=-fPIC
CONFIGURE_ARGS+=	CXXFLAGS_SHLIB=-fPIC
.  if ${OPSYS} == "SunOS" && \
      (${CC_VERSION:Mgcc*} || !empty(PKGSRC_COMPILER:Mclang))
CONFIGURE_ARGS+=	-p solaris-g++
# gcc3 uses -mimpure-text to not pass -assert pure-text to the linker
CONFIGURE_ARGS+=	LFLAGS_SHLIB="-shared -mimpure-text"
.  else
CONFIGURE_ARGS+=	LFLAGS_SHLIB="-shared"
.  endif
.endif
CONFIGURE_ARGS+=	LFLAGS=${LDFLAGS:Q}

# Hack: gcc on sparc64 miscompiles sipgen/parser.c at -O2
.if ${MACHINE_ARCH} == "sparc64" && ${CC_VERSION:Mgcc*}
BUILDLINK_TRANSFORM+=	rm:-O2
.endif

SUBST_CLASSES+=		pyversfx
SUBST_STAGE.pyversfx=	pre-configure
SUBST_FILES.pyversfx=	sipgen/sipgen.sbf
SUBST_VARS.pyversfx=	PYVERSSUFFIX
