#!/bin/sh
#usage: ./build-i386 0.38-0 or 0.38-0test4

if test x$1 == x
then
   echo usage: ./build-i386 0.38-0 or 0.38-0test4
   exit 1
fi

if test -f ../build/pd-$1.src.tar.gz
then
   /bin/echo -n
else
   echo cant find file ../build/pd-$1.src.tar.gz
   exit 1
fi

rm -rf pd-$1 Pd-$1-i386.app

tar xzf ../build/pd-$1.src.tar.gz
cd pd-$1
./autogen.sh
./configure --enable-universal=i386 --enable-jack

#workaround for libpd build wierdness
for i in \
  bob~ bonk~ choice fiddle~ loop~ lrshift~ \pd~ pd~ pique sigmund~ stdout; do
cp /dev/null extra/$i/.deps/libpd_la-$i.Plo
done
cp /dev/null extra/pd~/.deps/libpd_la-pdsched.Plo

if make
then
    echo -n
else
   echo build failed
   exit 1
fi

rm -rf po
cp -pr ../../build/po/ po/

cd mac
./osx-app.sh \
  --wish /Users/msp/work/build/tcltk/pd-wish-8.5.19/mac/Wish-8.5.19.app $1-i386
mv Pd-$1-i386.app ../../
cd ../..
tar czf pd-$1-i386.mac.tar.gz Pd-$1-i386.app
