#!/bin/bash

srcdir=.
while [ $# -gt 0 ]
do
   if [[ "$1" =~ --srcdir=.* ]]
   then
      srcdir=${1#*=}
      break
   fi
   shift
done

function waf
{
   pkg=$1
   pushd >/dev/null ${pkg}
   shift
   $(which python python2 | tail -1) waf --prefix="." --include="." $@ build || exit 1
   popd >/dev/null 

   . .buildvars

   if [ -e ${pkg}/build/*.a ]
   then
      mkdir -p obj
      pushd obj
      ar vx ../${pkg}/build/*.a
      ar vq ../liblv2.a *
      popd
      rm -rf obj
   fi
}

[ -e liblv2.a ] && exit 0

waf lv2    --no-plugins
waf serd   --static --no-shared --no-utils
waf sord   --static --no-shared --no-utils
waf sratom --static --no-shared
waf lilv   --static --no-shared --no-utils
waf suil   --static --no-shared --no-qt

exit 0
