#Maintainer: Thorsten Muehlfelder <thenktor(at)gmx.de>

pkgname=mongoose
pkgver=3.6
pkgrel=1rl
source=("http://mongoose.googlecode.com/files/mongoose-$pkgver.tgz" "rc.mongoose" "make.patch")
dotnew=('etc/mongoose.conf')
url="http://code.google.com/p/mongoose/"
docs=('COPYING')

slackdesc=\
(
#|-----handy-ruler------------------------------------------------------|
"$pkgname (small http server)"
"Easy to use web server for Windows and UNIX. Mongoose provides simple"
"and clean API for embedding it into existing programs. Targeting Web"
"application developers, embedded system developers, and people who"
"need to setup file sharing quickly."
)

build() {
	cd $startdir/src/${pkgname}
	# create basic license file
	echo "mongoose is licensed under the terms of the MIT license." > COPYING

	# avoid build failure
	# patch -p0 < ../make.patch || return 1
	
	# make linux
	make -j $numjobs linux || return 1
	make test || return 1

	# create dirs
	mkdir -p $startdir/pkg/etc/rc.d/
	mkdir -p $startdir/pkg/usr/sbin/
	mkdir -p $startdir/pkg/usr/
	mkdir -p $startdir/pkg/usr/man/man1/
	mkdir -p $startdir/pkg/var/www/htdocs/

	# install files
	install -m755 -o root -g root mongoose $startdir/pkg/usr/sbin/
	install -m644 -o root -g root mongoose.1 $startdir/pkg/usr/man/man1/

	# install rc script
	cd $startdir/src/
	install -m755 -o root -g root rc.mongoose $startdir/pkg/etc/rc.d/rc.mongoose.new

	# create a config file
	cat << "EOC" > $startdir/pkg/etc/mongoose.conf
# here you can specify the command line options that are used by the
# rc.mongoose init script
CMD_OPTS='-r /var/www/htdocs -p 80 -u nobody -C cgi,pl,php -d yes'
EOC
}

doinst() {
	if [ -r etc/rc.d/rc.mongoose -a -r etc/rc.d/rc.mongoose.new ]; then
		chmod --reference=etc/rc.d/rc.mongoose etc/rc.d/rc.mongoose.new
	fi
	mv etc/rc.d/rc.mongoose.new etc/rc.d/rc.mongoose
}