# Maintainer: Carlo Landmeter <clandmeter@gmail.com>
pkgname=eggdrop
pkgver=1.6.21
pkgrel=2
pkgdesc="World's most popular Open Source IRC bot"
url="http://www.eggheads.org/"
arch="all"
license='GPL2'
depends="tcl"
makedepends="tcl-dev !bind-libs"
install=
subpackages="$pkgname-doc $pkgname-logs2html $pkgname-gseen"
source="ftp://ftp.eggheads.org/pub/eggdrop/GNU/1.6/${pkgname}${pkgver}.tar.bz2
	eggdrop-langdir.patch
	gseen.mod.patch
	logs2html.mod.patch
	fix-inline-functions.patch"

_builddir="$srcdir/${pkgname}${pkgver}"

prepare() {
	cd "$_builddir"
	update_config_sub || return 1
	for i in $source; do
		case $i in
		*.patch) msg $i; patch -p1 -i "$srcdir"/$i || return 1;;
		esac
	done
}

build() {
	cd "$_builddir"
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--with-tcllib=/usr/lib/libtcl8.6.so \
		--with-tclinc=/usr/include/tcl.h \
		|| return 1
	make config || return 1
	make -j1 || return 1
}

package() {
	cd "$_builddir"
	make -j1 INSTALL="install -p" DEST="$pkgdir"/usr/share/eggdrop install \
		|| return 1
	rm -rf "$pkgdir"/usr/share/eggdrop/README \
		"$pkgdir"/usr/share/eggdrop/doc \
		"$pkgdir"/usr/share/eggdrop/eggdrop* \
		"$pkgdir"/usr/share/eggdrop/filesys \
		"$pkgdir"/usr/share/eggdrop/logs \
		"$pkgdir"/usr/share/eggdrop/modules \
		"$pkgdir"/usr/share/eggdrop/scripts/CONTENTS \
		|| return 1
	install -D -m 755 eggdrop "$pkgdir"/usr/bin/eggdrop || return 1
	install -D -m 644 doc/man1/eggdrop.1 \
		"$pkgdir"/usr/share/man/man1/eggdrop.1 || return 1

	#move modules to /usr/lib
	mkdir "$pkgdir"/usr/lib
	mv "$pkgdir"/usr/share/eggdrop/modules-* \
		"$pkgdir"/usr/lib/eggdrop || return 1


	# Fix paths of example eggdrop.conf
	sed -i -e '2d' -e '1s@^.*@#!/usr/bin/eggdrop@' \
		-e 's@scripts/@/usr/share/eggdrop/scripts/@g' \
		-e 's@help/@/usr/share/eggdrop/help/@g' \
		-e 's@modules/@/usr/lib/eggdrop/@g' \
		eggdrop.conf

	mkdir -p "$pkgdir"/usr/share/doc/eggdrop
	cp -a \
		COPYING FEATURES NEWS README doc/Changes1.6 eggdrop.conf \
		doc/ABOUT doc/BANS doc/BOTNET doc/BUG-REPORT doc/FIRST-SCRIPT \
		doc/MODULES doc/PARTYLINE doc/TEXT-SUBSTITUTIONS doc/TRICKS \
		doc/USERS doc/WEIRD-MESSAGES doc/tcl-commands.doc doc/settings \
		doc/html \
		"$pkgdir"/usr/share/doc/eggdrop
}

logs2html() {
	pkgdesc="logs2html module for eggdrop"
	install=""
	cd "$_builddir"

	for dir in language help; do
		mkdir -p "$subpkgdir"/usr/share/eggdrop/$dir
		mv "$pkgdir"/usr/share/eggdrop/$dir/logs2html.* "$subpkgdir"/usr/share/eggdrop/$dir/ || return 1
	done

	mkdir -p "$subpkgdir"/usr/lib/eggdrop
	mv "$pkgdir"/usr/lib/eggdrop/logs2html.so \
		"$subpkgdir"/usr/lib/eggdrop/ || return 1

	mkdir -p "$subpkgdir"/usr/share/eggdrop/log2html

	for files in logs2html.conf top100.tpl user.css readme.txt chan.list; do
		cp src/mod/logs2html.mod/${files} "$subpkgdir"/usr/share/eggdrop/log2html/ || return 1
	done
}


gseen() {
	pkgdesc="gseen module for eggdrop"
	install=""
	cd "$_builddir"
	mkdir -p "$subpkgdir"/usr/share/eggdrop/language
	mv "$pkgdir"/usr/share/eggdrop/language/gseen.* \
		"$subpkgdir"/usr/share/eggdrop/language/ || return 1
	mkdir -p "$subpkgdir"/usr/lib/eggdrop
	mv "$pkgdir"/usr/lib/eggdrop/gseen.so \
		"$subpkgdir"/usr/lib/eggdrop/ || return 1
	mkdir -p "$subpkgdir"/usr/share/eggdrop/gseen
	cp src/mod/gseen.mod/gseen.conf "$subpkgdir"/usr/share/eggdrop/gseen/ \
		|| return 1
	cp src/mod/gseen.mod/README "$subpkgdir"/usr/share/eggdrop/gseen/ \
		|| return 1
}

md5sums="5663b2daecc790e6e9237e1d5a2caa50  eggdrop1.6.21.tar.bz2
fdc2a01f611f14a8132225c8294f5039  eggdrop-langdir.patch
853a8526472ee964a8c94046cb9ae8b8  gseen.mod.patch
8b12435d0944b47898758d74bb227778  logs2html.mod.patch
648a3827438060f1a977a59d761a6300  fix-inline-functions.patch"
sha256sums="75bd5573a609eac3940c0b6ca8251c3f38ea5d54b520e1cad93c650b4bc21754  eggdrop1.6.21.tar.bz2
85d1cc18ebb002755e6d4a2996ff6f12768df3e0412001011db695a982887510  eggdrop-langdir.patch
a0597de68d9b0a8d2adeb7cfaf6ffa1e248a6e21df709d3d887e6a4519562462  gseen.mod.patch
197c73af2e6d484ea78796faeb4290c6ce557aa641291d496c6878daf5454e16  logs2html.mod.patch
a5c1c06b7c07d5a1f0943a1df73c2e262b28d98921ea4aa2353b826b6775c8c7  fix-inline-functions.patch"
sha512sums="9fd9a86c1c4b59a47a5eed4e2306e829a01bac2ad29e990ca9c0ec630d5814fd649a9216dae9ce49f734e3ac1728beb4f479ca10af583bd513f43bbbea23a653  eggdrop1.6.21.tar.bz2
e8b36fb3c444bd884def46082f2c4f0683d1ba8bf05015344e1a2cf634955c8f1e8ccef62c3c2d93958151cf2ce1595adc352c0de3c76ceed7b89c28f48ea96f  eggdrop-langdir.patch
b7bc853b73a9a86ed19dae2cb9edaededbeaa0c163034dc8106239818b8d1fb7c7381fa933fda786cb1c5026283821ec6e3a85a1bbc73db736668f1615dfe2f7  gseen.mod.patch
8380c414d5193f7a48b5b91384c0181b472dd6cd541a3e9921453b945af3a959d6f58e6bfdcc311ba7b1ed15a44b2225c1d0f1a00526da75cacd4b8650591229  logs2html.mod.patch
bbe12761c35298604ffeb90a1dfb1c928fa7b83e6366578e8f1b298dda72dea19931812c70b6f9475b7b0449b0e799fd9cbee52e8d40be04eb33484274589340  fix-inline-functions.patch"
