# $OpenBSD$

COMMENT =	English branch of ONScripter, a game scripting engine

DISTNAME =	onscripter-en-${V}-src
PKGNAME =	onscripter-en-${V}
V =		20110628

CATEGORIES =	games

HOMEPAGE =	https://web.archive.org/web/http://unclemion.com/onscripter/

MAINTAINER =	Nam Nguyen <namn@berkeley.edu>

# GPLv2+
PERMIT_PACKAGE =	Yes

WANTLIB += ${COMPILER_LIBCXX} SDL SDL_image SDL_mixer SDL_ttf
WANTLIB += bz2 c freetype jpeg m ogg png smpeg vorbis vorbisfile
WANTLIB += z

MASTER_SITES =	https://kaisernet.neocities.org/onscripter/releases/

EXTRACT_SUFX =	.tar.bz2

# c++-98
COMPILER =	base-clang ports-gcc base-gcc

# tests require font and visual inspection
NO_TEST =	Yes

BUILD_DEPENDS =	graphics/jpeg
RUN_DEPENDS =	fonts/ja-sazanami-ttf
LIB_DEPENDS =	audio/libvorbis \
		archivers/bzip2 \
		devel/sdl \
		devel/sdl-image \
		devel/sdl-mixer \
		devel/sdl-ttf

USE_GMAKE =		Yes
CONFIGURE_STYLE =	gnu
# use clang and do not error on warnings
CONFIGURE_ARGS +=	--unsupported-compiler \
			--no-werror
CONFIGURE_ENV +=	CC="${CC}" \
			CXX="${CXX}"

pre-configure:
# tools need sjis2utf16.o and flags
	sed -i "s,^\(TOOL_INCS.*\),\1 -I${LOCALBASE}/include,g" \
		${WRKSRC}/Makefile.onscripter
	sed -i "s,\(TOOL_LIBS.*\),\1 sjis2utf16.o -L${LOCALBASE}/lib,g" \
		${WRKSRC}/Makefile.onscripter
# drop -O3 and -fomit-frame-pointer for debugging
	sed -i "s,-O3.*fomit-frame-pointer,${CXXFLAGS},g" ${WRKSRC}/configure
# bz2 configure check needs flags
	sed -i "s,-lbz2,-L${LOCALBASE}/lib -I${LOCALBASE}/include -lbz2,g" \
		${WRKSRC}/configure
# detect platforms to pick up platform-specific graphics routines
	sed -i "s,^\*86_64\*,*amd64*|*86_64*,g" ${WRKSRC}/configure
	sed -i "s,^\*86\*,*i386*|*86*,g" ${WRKSRC}/configure
	sed -i "s,^\*powerpc\*,*macppc*|*powerpc*,g" ${WRKSRC}/configure

pre-build:
# parallel builds can build sjis2utf16.o in incorrect order, so build it first
	@cd ${WRKSRC} && env -i ${MAKE_ENV} ${MAKE_PROGRAM} ${MAKE_FLAGS} \
		-f ${MAKE_FILE} sjis2utf16.o

TOOLS =	batchconv ns2conv ns2dec ns2make nsaconv nsadec nsamake nscdec \
	nscmake sarconv sardec sarmake

do-install:
.for _tool in ${TOOLS}
	${INSTALL_PROGRAM} ${WRKSRC}/tools/${_tool} ${PREFIX}/bin
	${INSTALL_MAN} ${WRKSRC}/tools/man/${_tool}.1 ${PREFIX}/man/man1
.endfor
	${INSTALL_PROGRAM} ${WRKSRC}/onscripter-en ${PREFIX}/bin

.include <bsd.port.mk>
