#!/bin/sh
#require compiletest
#require cflags
#require firestring
#require pthread
#phase init
#after init_cflags
#after init_pthread
#after init_firestring
#phase header
case $PHASE in
	init)
		dispn "Checking for firedns library..."
		PROGRAM="#include <firedns.h>
int main() {
	firedns_resolveip4(\"firestuff.org\");
	return 0;
}"
		compile_test_wrapper "$PROGRAM" "" "" "-lfiredns" || \
		compile_test_wrapper "$PROGRAM" "-I/usr/local/include" "-L/usr/local/lib" "-lfiredns" || \
		compile_test_wrapper "$PROGRAM" "-I/usr/local/include" "-L/usr/local/lib -R/usr/local/lib" "-lfiredns" || \
		{
			if (module "subdir" && test -x firedns/configure); then
				subdir firedns
				disp "Adding -Ifiredns/ to CFLAGS"
				FM_CFLAGS="$FM_CFLAGS -Ifiredns/"
				disp "Adding firedns/libfiredns.a to STATICLIBS"
				FM_STATICLIBS="$FM_STATICLIBS firedns/libfiredns.a"
			elif (module "subdir" && test "$FM_IN_SUBDIR" = "y" && test -x ../firedns/configure); then
				parentdir ../firedns
				disp "Adding -I../firedns/ to CFLAGS"
				FM_CFLAGS="$FM_CFLAGS -I../firedns/"
				disp "Adding ../firedns/libfiredns.a to STATICLIBS"
				FM_STATICLIBS="$FM_STATICLIBS ../firedns/libfiredns.a"
			else
				disp "not found, unable to continue"
				exit 1
			fi
		}
		;;
	header)
		disp "Adding \"#include <firedns.h>\" to header"
		$ECHO "#include <firedns.h>"
		;;
esac
