#!/bin/sh -ue
NAME=eiwd
VERSION=git
RELEASE=1
SOURCE="https://github.com/illiliti/eiwd.git
	iwd.sv::sv"

build() {
	msg "cloning ell..."
	rm -rf ell
	git clone --depth=1 https://git.kernel.org/pub/scm/libs/ell/ell.git ell-repo || die "ell clone failed"

	msg "setting up ell symlinks..."
	mkdir -p ell
	ln -sf ../ell-repo/ell/test-private.h ell/test-private.h
	( cd ell && for f in ../ell-repo/ell/*; do
		[ -f "$f" ] || continue
		ln -sf "$f" "$(basename "$f")"
	done )

	msg "bootstrapping eiwd..."
	./bootstrap || die "bootstrap failed"

	msg "configuring eiwd..."
	./configure \
		--prefix="$PREFIX" \
		--localstatedir=/var \
		--disable-systemd-service \
		--disable-manual-pages \
		--disable-dbus \
		--disable-client \
		--disable-monitor \
		--enable-static \
		CC="${CC:-cc}" \
		CFLAGS="${CFLAGS:--O2} -static" \
		LDFLAGS="${LDFLAGS:--static}" || die "configure failed"

	msg "building eiwd..."
	gmake -j"$NPROC" || die "gmake failed"

	msg "installing eiwd..."
	gmake DESTDIR="$PKG" install || die "gmake install failed"

	# eiwd installs daemon in /libexec/iwd; provide /bin/iwd for runtime scripts.
	mkdir -p "$PKG/$PREFIX/bin"
	ln -sf ../libexec/iwd "$PKG/$PREFIX/bin/iwd"
}

. ${0%/*}/../../libsh/libdmake.sh
