#!/bin/bash
umask u=rwx,g=rx,o=rx

# http://s.sudre.free.fr/Stuff/PackageMaker_Howto.html

make cbmc-mac-signed

(cd ../goto-cc; make goto-cc-mac-signed)
(cd ../goto-instrument; make goto-instrument-mac-signed)

VERSION=`./cbmc --version`
VERSION_FILE=`echo $VERSION | sed "y/./-/"`
BITS=`getconf LONG_BIT`

echo $VERSION_FILE

mkdir /tmp/cbmc-dist
mkdir /tmp/cbmc-dist/package-root
mkdir /tmp/cbmc-dist/package-root/usr
mkdir /tmp/cbmc-dist/package-root/usr/local
mkdir /tmp/cbmc-dist/package-root/usr/local/bin
mkdir /tmp/cbmc-dist/resources
mkdir /tmp/cbmc-dist/resources/en.lproj

cp ../cbmc/cbmc ../goto-cc/goto-cc \
  ../goto-instrument/goto-instrument /tmp/cbmc-dist/package-root/usr/local/bin/
cp ../../LICENSE /tmp/cbmc-dist/resources/license.html
cp distribution.xml /tmp/cbmc-dist/

echo "Building cbmc-${VERSION_FILE}.pkg (${BITS} bits)"

# Do the 'component package'

pkgbuild \
  --root /tmp/cbmc-dist/package-root/ \
  --identifier org.cprover.cbmc \
  --version $VERSION \
  /tmp/cbmc-dist/cbmc-component.pkg  
  
# Now do the 'product archive'

productbuild \
  --distribution /tmp/cbmc-dist/distribution.xml \
  --resources /tmp/cbmc-dist/resources/ \
  --package-path /tmp/cbmc-dist \
  --version $VERSION \
  /tmp/cbmc-dist/cbmc-${VERSION_FILE}.pkg

echo Copying.
scp /tmp/cbmc-dist/cbmc-${VERSION_FILE}.pkg \
  kroening@dkr-srv.cs.ox.ac.uk:/srv/www/cprover.org/cbmc/download/

#cd /tmp
#rm -R /tmp/cbmc-dist
