#!/bin/sh

if [ "$help" != "1" ]
then
	# Determine how to lookup dependencies of executable for  OS
	targetos=$(uname -s)
	case $targetos in
	Darwin)
		LDD="otool -L"
		;;
	Linux|FreeBSD|NetBSD)
		LDD="ldd"
		;;
	*)
		;;
	esac

	pkg-config sox
	if [ $? -eq 0 ]
	then
		disable_sox=0
		echo "CFLAGS += $(pkg-config --cflags sox)" > config.mak
		echo "LDFLAGS += $(pkg-config --libs sox)" >> config.mak
		[ $(pkg-config --modversion sox | cut -d. -f1) -gt 13 ] && echo "CFLAGS += -DSOX14" >> config.mak
	else
		which libst-config > /dev/null 2>&1
		if [ $? -eq 0 ]
		then
			disable_sox=0

			# determine if we need libsndfile
			$LDD $(which sox) | grep libsndfile > /dev/null
			[ $? -eq 0 ] && libsndfile="-lsndfile"

			# determine if we need libsamplerate
			$LDD $(which sox) | grep libsamplerate > /dev/null
			[ $? -eq 0 ] && libsamplerate="-lsamplerate"

			echo "CFLAGS += $(libst-config --cflags) -I../.." > config.mak
			echo "LDFLAGS += -lst $(libst-config --libs) $libsndfile $libsamplerate" >> config.mak
		else
			echo "- sox not found: disabling"
			touch ../disable-sox
		fi
	fi

	exit 0
fi
