#!/bin/sh
#
# build configuration for nsnotifyd
#
# Written by Tony Finch <dot@dotat.at> in Cambridge.
#
# Permission is hereby granted to use, copy, modify, and/or
# distribute this software for any purpose with or without fee.
#
# This software is provided 'as is', without warranty of any kind.
# In no event shall the authors be liable for any damages arising
# from the use of this software.
#
# SPDX-License-Identifier: 0BSD OR MIT-0

set -eu

with_libc() {
	cat <Makefile.in >Makefile
	echo 'Using libc resolver'
}

with_libresolv() {
	sed '	s|^LIBS=.*|LIBS=-lresolv|;
	' <Makefile.in >Makefile
	echo 'Using libresolv'
}

with_libbind() {
	sed '	s|^LIBDEPS=.*|LIBDEPS=${RESLIB}|;
		s|^LIBFLAGS=.*|LIBFLAGS=-I${RES}/include -L${RES}|;
		s|^LIBS=.*|LIBS=-lbind|;
	' <Makefile.in >Makefile
	make resconfig
	echo 'Using static libbind'
}

check_compile() {
	[ ! -f libbind-6.0.tar.gz ] &&
	cc -o /dev/null version/config-check.c "$@" 2>/dev/null
}

case "$*" in
(--with-libc)
	with_libc
	;;
(--with-libresolv)
	with_libresolv
	;;
(--with-libbind)
	with_libbind
	;;
(*)	if	check_compile
	then	with_libc
	elif	check_compile -lresolv
	then	with_libresolv
	else	with_libbind
	fi
	;;
esac

echo 'Now run make...'
