#!/usr/bin/env bash

m=$HOME/tmp/$$.dat
test -d $HOME/tmp || mkdir -p $HOME/tmp
trap "rm -f $m" EXIT

# Compute an acoustic feature vector describing the audio signal.

err="$0: OXIROOT needs to be set in the environment. Try /home/gpk/oxi or something similar."
OL=${OXIROOT:?$err}/lib
CLUSTERSIZE=0

rewrite=''
s='True'
while true
do
	arg=$1; shift;
	case "$arg" in
	'') break;;
	--) break;;
	-rewrite) rewrite=$m;;
	-qmake) CLUSTERSIZE=$1; shift;;
	-s) s="$1"; shift;;
	*)	g_die "Unrecognized arg: $arg" || exit 2;;
	esac
done

if test "$CLUSTERSIZE" -gt 0 && type qmake >/dev/null 2>&1
then
  np=''
  make="qmake -V -cwd -- -j $CLUSTERSIZE"
else
  np=-j\ $(grep '^processor.:' /proc/cpuinfo | wc -l)
  make=make
fi

>$m
echo OL=$OL >>$m
echo REWRITE=$rewrite >>$m
echo '.PHONY: all' >>$m
echo '.SUFFIXES:' >>$m
echo >>$m
select_fiat_entries.py -select "$s" -show "'all : %s/%s/ue.lbl\n' % (d, f)" DB.fiat >>$m

cat <<'ENDEND' >>$m

%/ue.lbl : %/loud.dat $(OL)/find_utterance_edges_n.py $(REWRITE)
	mkdir -p $$(dirname $*); python $(OL)/find_utterance_edges_n.py -label $@ $*

ENDEND

$make $np -f $m || g_die "$0 fails!" 
