# New ports collection makefile for:	epkowa
# Date created:		Dec.23, 2008
# Whom:			luigi@FreeBSD.org
#
# Maintainers:		Luigi Rizzo <luigi@FreeBSD.org>
# $FreeBSD: $
#
# This port builds the sane-epkowa driver for SANE.
#
# Version 2.11.0 is the last that works without patches, and it is
# enough to detect the NX400 scanner.
# Version 2.15.0 builds with the attached patches, but then has various
# failures at runtime that I am still tracking. This goes for both the
# sane backend and the iscan frontend.
# 
# For reference, the standard SANE backends are accessible through cvs as
# cvs co -z3 -d:pserver:anonymous@cvs.alioth.debian.org:/cvsroot/sane co sane-backends
#
# The source for this program is accessible at
#
#	 http://www.avasys.jp/lx-bin2/linux_e/spc/DL1.do#download
#
# The download interface requests to fill a form, and returns the most
# recent version of the software. However, the license is GPL-like, and the
# documentation coming with the code (README, non-free/AVASYSPL.en.txt)
# explicitly mentions that source redistribution is allowed.
#
# Earlier versions of the code are available at the following addresses:
# http://linux.avasys.jp/drivers/iscan/2.15.0/iscan_2.15.0-3.tar.gz
# http://lx1.avasys.jp/iscan/2.7.0/iscan-2.7.0-1.c2.tar.gz
# http://lx1.avasys.jp/iscan/2.8.0/iscan-2.8.0-1.c2.tar.gz
# -- unknown URL for version 2.9.0
# http://lx1.avasys.jp/iscan/2.10.0/iscan_2.10.0-1.tar.gz
# http://lx1.avasys.jp/iscan/2.11.0/iscan_2.11.0-1.tar.gz
# http://lx1.avasys.jp/iscan/2.12.0/iscan_2.12.0-4.tar.gz
# --- version 2.13 never released
# http://lx1.avasys.jp/iscan/2.14.0/iscan_2.14.0-3.tar.gz
# http://lx1.avasys.jp/iscan/2.15.0/iscan_2.15.0-3.tar.gz
#
# Version 2.7.0 to 2.11.0 build on FreeBSD without any patch,
# newer versions require changes similar to those in this port.

PORTNAME=	epkowa
PORTVERSION=	2.11.0
CATEGORIES=	graphics
MASTER_SITES=	http://lx1.avasys.jp/iscan/${PORTVERSION}/
DISTFILES= iscan_${PORTVERSION}-1${EXTRACT_SUFX}

# use the following two lines for 2.15.0
# MASTER_SITES=	http://linux.avasys.jp/drivers/iscan/${PORTVERSION}/	#
# DISTFILES= iscan_${PORTVERSION}-3${EXTRACT_SUFX}
# following two for 2.11.0

WRKSRC=${WRKDIR}/iscan-${PORTVERSION}

EXTRACT_SUFX=	.tar.gz 
MAINTAINER=	luigi@FreeBSD.org
COMMENT=	epkowa sane driver for FreeBSD

MAN5=		sane-epkowa.5

# We use LIB_DEPENDS, but the dependency is also at build time
LIB_DEPENDS+=	ltdl:${PORTSDIR}/devel/libltdl15
LIB_DEPENDS+=	usb:${PORTSDIR}/devel/libusb
LIB_DEPENDS+=	getline:${PORTSDIR}/devel/libgetline
#BUILD_DEPENDS+=	${LOCALBASE}/lib/libltdl.so:${PORTSDIR}/devel/libltdl15

# The original uses gmake and ./configure
# Also pass appropriate flags to configure to use FreeBSD locations.
USE_GMAKE=	yes
GNU_CONFIGURE=	yes
CONFIGURE_ARGS+=  --prefix=/usr/local LDFLAGS="-L/usr/local/lib -lgetline" CPPFLAGS=-I/usr/local/include

.include <bsd.port.pre.mk>

.if $(PORTVERSION) != "2.15.0"
do-patch:	# nothing to do

do-build:
	( cd ${WRKSRC}/libltdl ; gmake )
	( cd ${WRKSRC}/sanei ; gmake )
	( cd ${WRKSRC}/backend ; gmake )
	( cd ${WRKSRC}/doc ; gmake )
.else
.warning new version, not working yet
# The non-free library does not link with FreeBSD unless you remove
# versioned symbols.
post-patch:
	( cd ${WRKSRC}/non-free; cp -p libesmod-i386.so x.so; \
	objcopy -R .gnu.version x.so libesmod-i386.so )

# only build the backend part
do-build:
	( cd ${WRKSRC}/backend ; gmake )
	( cd ${WRKSRC}/doc ; gmake )
.endif
do-install:
	@${INSTALL_MAN} ${WRKSRC}/doc/sane-epkowa.5 ${PREFIX}/man/man5
	@${INSTALL_DATA} ${WRKSRC}/backend/.libs/libsane-epkowa.so.1 \
		${PREFIX}/lib/sane/
	@(cd ${PREFIX}/lib/sane; ${LN} -s libsane-epkowa.so.1 libsane-epkowa.so )
	@echo "usb /dev/uscanner0" > ${PREFIX}/etc/sane.d/epkowa.conf
	@echo "epkowa" >> ${PREFIX}/etc/sane.d/dll.conf

.include <bsd.port.post.mk>
