

PORTNAME?=	gutenprint
PORTVERSION=	5.2.10
CATEGORIES=	print
MASTER_SITES=	SF/gimp-print/gutenprint-5.2/${PORTVERSION}
PKGNAMESUFFIX?=	-base

MAINTAINER=	ports@MidnightBSD.org
COMMENT=	GutenPrint Printer Driver

LICENSE=	gpl2

CONFLICTS=	gimp-print-[0-9]*

USES=		gettext gmake libtool pathfix pkgconfig tar:bzip2
USE_GNOME=	gtk20
GNU_CONFIGURE=	yes
CONFIGURE_ARGS=--with-gimp=no --with-gimp2=no
USE_LDCONFIG=	yes

CPPFLAGS+=	-I${LOCALBASE}/include -I${PREFIX}/include
LDFLAGS+=	-L${LOCALBASE}/lib -L${PREFIX}/lib

.include <bsd.port.pre.mk>

.if ${SLAVE_PORT}=="yes"
LIB_DEPENDS+=	libgutenprintui2.so:${PORTSDIR}/print/gutenprint-base
PKG_CONFIG?=	${LOCALBASE}/bin/pkg-config
GUTENPRINTUI2_LIBS=`${PKG_CONFIG} --libs gutenprintui2`
.endif

.if defined(GUT_SLAVE) && ${GUT_SLAVE}=="gimp"
LIB_DEPENDS+=	libgimp-2.0.so:${PORTSDIR}/graphics/gimp-app \
		libgutenprint.so:${PORTSDIR}/print/gutenprint-base
CONFIGURE_ARGS=--with-gimp2=yes # Override CONFIGURE_ARGS
BUILD_WRKSRC=	${WRKSRC}/src/gimp2
INSTALL_WRKSRC=	${WRKSRC}/src/gimp2
.else
CONFIGURE_ARGS+=--without-gimp2
.endif

.if defined(GUT_SLAVE) && ${GUT_SLAVE}=="cups"
LIB_DEPENDS+=	libcups.so:${PORTSDIR}/print/cups-client \
		libcupsimage.so:${PORTSDIR}/print/cups-image
RUN_DEPENDS+=	espgs:${PORTSDIR}/print/cups-pstoraster
CONFIGURE_ARGS+=	--with-cups=${PREFIX} \
			--enable-cups-ppds \
			--enable-cups-level3-ppds
BUILD_WRKSRC=	${WRKSRC}/src/cups
INSTALL_WRKSRC=	${WRKSRC}/src/cups
.else
CONFIGURE_ARGS+=	--without-cups
.endif

.if defined(GUT_SLAVE) && ${GUT_SLAVE}=="ijs"
LIB_DEPENDS+=	libijs.so:${PORTSDIR}/print/libijs
CONFIGURE_ARGS+=--with-ijs=yes
BUILD_WRKSRC=	${WRKSRC}/src/ghost
INSTALL_WRKSRC=	${WRKSRC}/src/ghost
.else
CONFIGURE_ARGS+=--without-ghostscript
.endif

.if defined(GUT_SLAVE) && ${GUT_SLAVE}=="foomatic"
BUILD_DEPENDS+=	foomatic-combo-xml:${PORTSDIR}/print/foomatic-db-engine
RUN_DEPENDS+=	foomatic-combo-xml:${PORTSDIR}/print/foomatic-db-engine \
		${LOCALBASE}/share/cups/model/foomatic-db-ppds:${PORTSDIR}/print/foomatic-db
CONFIGURE_ARGS+=--with-foomatic=yes --with-foomatic3=yes
BUILD_WRKSRC=	${WRKSRC}/src/foomatic
INSTALL_WRKSRC=	${WRKSRC}/src/foomatic
.else
CONFIGURE_ARGS+=--without-foomatic
.endif

post-patch:
	@${REINPLACE_CMD} -e 's|/usr/bin/lpstat|${LOCALBASE}/bin/lpstat|' \
		${WRKSRC}/src/gutenprintui2/plist.c
.if ${SLAVE_PORT}=="no" || ${GUT_SLAVE}!="cups"
	@${REINPLACE_CMD} -e 's|cups	||' ${WRKSRC}/src/Makefile.in
.endif
.if ${SLAVE_PORT}=="yes"
	@${REINPLACE_CMD} -e 's|= escputil.1|= |' ${WRKSRC}/man/Makefile.in
.endif
	@${REINPLACE_CMD} -e 's|%%GUTENPRINTUI2_LIBS%%|${GUTENPRINTUI2_LIBS}|' \
		${WRKSRC}/src/gimp2/Makefile.in
	@${REINPLACE_CMD} -e 's|$$libdir/gimp/1.2/plug-ins||g' \
		${WRKSRC}/configure
	@${REINPLACE_CMD} -e 's|= $$(pkglibdir)|= ${PREFIX}/libexec/cups|' \
		${WRKSRC}/src/cups/Makefile.in

pre-build:
.if defined(GUT_SLAVE) && (${GUT_SLAVE}=="foomatic" || ${GUT_SLAVE}=="cups")
	@(cd ${WRKSRC}/src/xml && ${MAKE})
.endif

post-install:
.if ${SLAVE_PORT}=="yes"
	@(cd ${WRKSRC}/man && ${GMAKE} ${INSTALL_TARGET})
.endif

.include <bsd.port.post.mk>
