# Copyright 2024-2026 Haelwenn (lanodan) Monnier <contact@hacktivis.me>
# Distributed under the terms of the GNU General Public License v2

EAPI=8

inherit toolchain-funcs

DESCRIPTION="HTTP 1.1 webserver, serving static files and CGI/NPH"
HOMEPAGE="https://www.skarnet.org/software/tipidee/"
SRC_URI="https://www.skarnet.org/software/tipidee/${P}.tar.gz"
LICENSE="ISC"
SLOT="0"
KEYWORDS="~amd64"
IUSE="static"

DEPEND="
	static? ( >=dev-libs/skalibs-2.15.1.0:=[static-libs] )
	!static? ( >=dev-libs/skalibs-2.15.1.0:= )
"
RDEPEND="${DEPEND}"

DOCS=( doc examples )

src_prepare() {
	default

	sed -i -e '/AR := /d' -e '/RANLIB := /d' Makefile || die
}

src_configure() {
	tc-export AR CC RANLIB

	# --with-dynlib and --with-sysdeps needs to match skalibs' --dynlibdir and --sysdepdir respectively
	local myconf=(
		--dynlibdir="/$(get_libdir)"
		--libdir="/usr/$(get_libdir)/${PN}"
		--sysconfdir=/etc

		--with-dynlib="/$(get_libdir)"
		--with-sysdeps="/usr/$(get_libdir)/skalibs/"
	)

	if use static; then
		myconf+=(
			--disable-shared
			--enable-allstatic
			--enable-static-libc
		)
	else
		myconf+=(
			--enable-shared
			--disable-allstatic
			--disable-static-libc
		)
	fi

	econf "${myconf[@]}"
}