PORTNAME=	spiralsynthmodular
PORTVERSION=	0.2.2a
PORTREVISION=	14
CATEGORIES=	audio
MASTER_SITES=	SF/spiralmodular/spiralmodular/${PORTVERSION}%20%28Latest%20Version%29
DISTNAME=	spiralmodular-${PORTVERSION}

MAINTAINER=	ports@FreeBSD.org
COMMENT=	Object-oriented modular softsynth/sequencer/sampler
WWW=		https://www.pawfal.org/Software/SSM/

LICENSE=	GPLv2
LICENSE_FILE=	${WRKSRC}/COPYING

BUILD_DEPENDS=	${LOCALBASE}/include/ladspa.h:audio/ladspa
LIB_DEPENDS=	libfltk.so:x11-toolkits/fltk \
		libfontconfig.so:x11-fonts/fontconfig \
		libjack.so:audio/jack \
		libsndfile.so:audio/libsndfile

USES=		localbase xorg
USE_XORG=	x11 xcursor xext xfixes xft xinerama xrender
GNU_CONFIGURE=	yes
CONFIGURE_ENV=	FLTK_CONFIG="${FLTK_CONFIG}"

WRKSRC=		${WRKDIR}/spiralmodular-${PORTVERSION:C|[a-z]+||}

OPTIONS_DEFINE=	OPTIMIZED_CFLAGS

OPTIMIZED_CFLAGS_CFLAGS=-O3 -ffast-math

post-patch:
	@${REINPLACE_CMD} -E -e 's@(-O3|-ffast-math)@@g; \
		s|-Wall||; \
		s|CFLAGS="-pipe|CFLAGS="\$$\{CFLAGS\}|; \
		s|CXXFLAGS="-pipe|CXXFLAGS="\$$\{CXXFLAGS\}|; \
		s|^SpiralSound/Plugins/MidiPlugin/Makefile||; \
		s|MidiPlugin||' \
			${CONFIGURE_WRKSRC}/${CONFIGURE_SCRIPT}
	@${REINPLACE_CMD} -e 's|O_SYNC|O_FSYNC|' \
		${WRKSRC}/SpiralSound/Midi.C
	@${REINPLACE_CMD} -e 's|True|true|; s|False|false|' \
		${WRKSRC}/SpiralSound/Plugins/MatrixPlugin/MatrixPlugin.C
	@${REINPLACE_CMD} -e 's|JackPort::||' \
		${WRKSRC}/SpiralSound/Plugins/JackPlugin/JackPlugin.h
	@${REINPLACE_CMD} -e 's|CVGUI::||' \
		${WRKSRC}/SpiralSound/Plugins/ControllerPlugin/ControllerPluginGUI.h
	@${REINPLACE_CMD} -e 's|Sample::||' \
		${WRKSRC}/SpiralSound/Sample.h
	@${FIND} ${WRKSRC} -name "Makefile.in" | ${XARGS} ${REINPLACE_CMD} -E -e \
		's,-l(dl|rt),,; s|g\+\+|$$(CXX)|; \
		/^(CC|CXX)[[:space:]]*=.+$$/d; \
		s,@FLTK_(C|CXX)FLAGS@,-I${LOCALBASE}/include,; \
		s,(bin|lib)dir),DESTDIR)$$(&,'
	@${FIND} ${WRKSRC} -type f -name "*.C" -o -name "*.cpp" -o -name "*.h" \
		| ${XARGS} ${REINPLACE_CMD} -e '/^#include <FL/s|.h>$$|.H>|; \
		/^#include "FL/s|.h"$$|.H"|; \
		s|fl_file_chooser.H|Fl_File_Chooser.H|g'

post-install:
	${STRIP_CMD} ${STAGEDIR}${PREFIX}/bin/${PORTNAME} \
		${STAGEDIR}${PREFIX}/lib/SpiralPlugins/*.so

.include <bsd.port.mk>
