PORTNAME=	xorgxrdp
DISTVERSIONPREFIX=	v
DISTVERSION=	0.10.80.b20260203
# Be sure to bump PORTREVISION after xorg-server update to force rebuild
PORTREVISION=	2
CATEGORIES=	x11-drivers
PKGNAMESUFFIX=	-devel
DIST_SUBDIR=	xrdp

PATCH_SITES=	https://github.com/${GH_ACCOUNT}/${GH_PROJECT}/pull/
PATCHFILES=	406.patch:-p1

MAINTAINER=	meta@FreeBSD.org
COMMENT=	X.Org driver enabling use through an RDP session with xrdp
WWW=		https://www.xrdp.org/

LICENSE=	MIT
LICENSE_FILE=	${WRKSRC}/COPYING

BUILD_DEPENDS=	nasm:devel/nasm
RUN_DEPENDS=	xauth:x11/xauth

FLAVORS=	xorg xlibre
FLAVOR?=	${FLAVORS:[1]}

USES=		autoreconf libtool:build localbase pkgconfig
USE_LDCONFIG=	yes
USE_XORG=	xorgproto
USE_GITHUB=	yes

GH_ACCOUNT=	neutrinolabs
GH_TAGNAME=	7abffbf
GH_TUPLE=	neutrinolabs:xrdp:4d9dde8:xrdp

.if ${FLAVOR} == xlibre
PKGNAMEPREFIX=	xlibre-
USES+=		xlibre
USE_XLIBRE+=	xlibre-server
_XLIBRE_MAJOR_VER=	25
_XMODDIR=	lib/xorg/modules/xlibre-${_XLIBRE_MAJOR_VER}
.else
USE_XORG=	xorg-server
USES+=		xorg
_XMODDIR=	lib/xorg/modules
.endif

GNU_CONFIGURE=	yes
CONFIGURE_ENV=	XRDP_CFLAGS=-I${WRKSRC_xrdp}/common
INSTALL_TARGET=	install-strip

PLIST_SUB+=	XMODDIR=${_XMODDIR}

CONFLICTS=	xorgxrdp

OPTIONS_DEFINE=	DEBUG DRI3
OPTIONS_DEFAULT=	DRI3

DRI3_DESC=	DRI3/Glamor OpenGL Support
DRI3_LIB_DEPENDS=	libepoxy.so:graphics/libepoxy
DRI3_CONFIGURE_ENABLE=	glamor
DRI3_CFLAGS=		-I${LOCALBASE}/include/libdrm
DRI3_SUB_FILES=		pkg-message

# Bug 285815
NO_SHLIB_REQUIRES_GLOB=	libglamoregl.so

post-patch-DEBUG-on:
	${FIND} ${WRKSRC} -type f | ${XARGS} ${REINPLACE_CMD} -e 's|#define LOG_LEVEL [0-9]*|#define LOG_LEVEL 20|'

pre-configure:
	@cd ${WRKSRC} && ./bootstrap

.include <bsd.port.mk>
