#!/bin/sh

# If you like, you can specify the location where you installed QLDX here:
# QLDX=$HOME/pkg/qldx

bfx=$QLDX/bin/bfx
ql=$QLDX/bin/ql
syscontain=$QLDX/script/bfx/syscontain.ql
rawlink=$QLDX/script/bfx/rawlink.ql
liftfile=$QLDX/script/bfx/liftfile.ql

if [ $# -lt 1 ]; then
  echo "Usage: bfx-init PACKAGE"
  exit 0
fi

pkg=$1

cd $pkg
if [ -f "configure" ]; then
  ./configure
fi
make
cd -
find $pkg/ -name '*.o' > $pkg.files
# sed "s/^/contain $pkg /" $pkg.files > $pkg.contain
$bfx `cat $pkg.files` -o $pkg.bfx.ta
if [ -f $pkg.contain ]; then
  echo "Containment file $pkg.contain already exists -- we won't overwrite it."
  exit 0
fi
$ql $rawlink $pkg.bfx.ta $pkg.raw.ta || true
$ql $liftfile $pkg.raw.ta $pkg.raw.file.ta || true
$ql $syscontain $pkg.raw.file.ta tmp.con.ta
grep contain tmp.con.ta > $pkg.contain
rm -f tmp.con.ta
