PORTNAME=	sdl2-compat
DISTVERSION=	2.32.74
CATEGORIES=	devel wayland
MASTER_SITES=	https://github.com/libsdl-org/sdl2-compat/releases/download/release-${DISTVERSION}/

MAINTAINER=	monwarez@mailoo.org
COMMENT=	SDL2 compatibility layer that uses SDL 3.0 behind the scenes
WWW=		https://github.com/libsdl-org/sdl2-compat

LICENSE=	ZLIB
LICENSE_FILE=	${WRKSRC}/LICENSE.txt

BUILD_DEPENDS=	${LOCALBASE}/include/X11/Xlib.h:x11/libX11

USES=		cmake:testing localbase sdl
USE_LDCONFIG=	yes
USE_SDL=	sdl3
CMAKE_OFF=	SDL2COMPAT_DEVEL
CMAKE_OFF+=	${CMAKE_TESTING_ON}
CMAKE_TESTING_ON=	SDL2COMPAT_TESTS

PLIST_SUB=	LIBVERSION=0.${DISTVERSION:R:E}00.${DISTVERSION:E}

PORTSCOUT=	limitw:1,even

post-install:
	@${ECHO_CMD} "libSDL2-2.0.so.0 libSDL2-2.0-compat.so.0" \
		>${STAGEDIR}${PREFIX}/etc/libmap.d/${PORTNAME}.conf

pre-test:
	@${REINPLACE_CMD} -i.tests -e '/CMAKE_SKIP_RPATH/d' \
		${WRKSRC}/CMakeLists.txt

post-test:
.if defined(WAYLAND_DISPLAY) || defined(DISPLAY) || exists(/dev/dri/card0)
. for t in joystick keys
	(cd ${TEST_WRKSRC}/test && ./test$t)
. endfor
. for t in gl2
	(cd ${TEST_WRKSRC}/test && timeout --preserve-status 3 ./test$t)
. endfor
.endif

.include <bsd.port.mk>
