# Maintainer: Carlo Landmeter <clandmeter@alpinelinux.org>
pkgname=eggdrop
pkgver=1.9.5
pkgrel=1
pkgdesc="World's most popular Open Source IRC bot"
url="https://eggheads.org/"
arch="all"
license='GPL-2.0-or-later'
options="!check" # No test suite
makedepends="openssl-dev>3 tcl-dev"
subpackages="$pkgname-doc"
source="https://github.com/eggheads/eggdrop/releases/download/v$pkgver/eggdrop-$pkgver.tar.gz
	eggdrop-langdir.patch
	utf8.patch
	"
prepare() {
 	default_prepare
	update_config_sub
}

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

package() {
	# workaround for borked Makefile
	mkdir -p "$pkgdir"/usr/share/eggdrop/doc \
		"$pkgdir"/usr/share/eggdrop/help/set/

	make DEST="$pkgdir"/usr/share/eggdrop install
	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

	install -D -m 755 eggdrop "$pkgdir"/usr/bin/eggdrop
	install -D -m 644 doc/man1/eggdrop.1 \
		"$pkgdir"/usr/share/man/man1/eggdrop.1

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

	# 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.9 eggdrop.conf \
		doc/ABOUT doc/BANS doc/BOTNET doc/BUG-REPORT doc/FIRST-SCRIPT \
		doc/MODULES doc/PARTYLINE doc/TRICKS \
		doc/USERS doc/tcl-commands.doc doc/settings \
		doc/html \
		"$pkgdir"/usr/share/doc/eggdrop
}

sha512sums="
863e6f94a92ac02e135c306000379ce516d9c9381eb5ca249e7656f4f0f504a159ddf1f658016d05e422d8036e808664101ab4f8944a42438c273f71b676189b  eggdrop-1.9.5.tar.gz
d8e8655fed028030bc3cfe28207a289d0efbc412c7e01170a4d0bb31200f7ea93df310f19e83b485013ca5d4264694b4956252663cb3a63c3d5e4cc31346e0fe  eggdrop-langdir.patch
7966d4d42994e44a0e571b89f1c66cb41f672d75e6ced7051d1ece23d8c209059c3565b41de950bf9c907701ce7a5e33a215b637587075ed300a002a58eda503  utf8.patch
"
