# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: $ 

DESCRIPTION="A software motion detector. It grabs images from video4linux devices and/or webcams"
HOMEPAGE="http://motion.sourceforge.net"

# Version 3.1.14 only
SRC_URI="mirror://sourceforge/motion/${P}.tar.gz"
LICENSE="GPL-2"
SLOT="0"
KEYWORDS="~x86"
IUSE="mysql postgres"
DEPEND="mysql? ( dev-db/mysql ) 
		postgres? ( dev-db/postgresql )		
		media-video/ffmpeg
		media-libs/jpeg
		sys-apps/sed"
#Note that sed is only a dependancy because of its use in src_compile()

RDEPEND=""

src_compile() {
	# fix breakage in tarball
	chmod +x configure

	#Needed because ffmpeg does not have libavcodec.a but it does have .so
	sed -e 's/libavcodec.a/libavcodec.so/' -i configure

	local myconf=""
    use mysql && myconf="${myconf} --with-mysql"
    use mysql || myconf="${myconf} --without-mysql"
    use postgres && myconf="${myconf} --with-pgsql"
	use postgres || myconf="${myconf} --without-pgsql"
	CFLAGS="-I/usr/include/ffmpeg" econf --with-libavcodec=/usr/lib ${myconf} || die  
	emake || die
    
}

src_install() {
	einstall || die 
	rm ${D}/usr/doc/${P} -r
	dodoc CHANGELOG COPYING CREDITS FAQ INSTALL README README.axis_2100 motion.conf motion.conf.video0 thread2.conf thread1.conf
	dohtml motion_guide.html
	doman motion.1
	
}