#!/bin/sh
# bpp-make replace Ports.mk. @2002 by Antonio Gallo

# include bpp library
. /usr/libexec/bpp-functions

# Init vars
[ "$BPPROOT" = "" ] && BPPROOT=/badpenguin

# First of all try to guess about which package we are talking about :-)
if [ -f "$1/install/INFO" ]; then
  PKGROOT="$1"
elif [ -f "`pwd`/install/INFO" ]; then
  PKGROOT="`pwd`"
elif [ -f "$BPPROOT/$1/install/INFO" ]; then
  PKGROOT="$BPPROOT/$1"
else
  echoc RED "bpp-make: it was impossibile to find the directory where is"
  echoc RED "          the package to install. Use it as option"
  exit 1
fi

# Set system variable
PKGINFO=${PKGROOT}/install/INFO
WORKDIR=${PKGROOT}/workdir

# Load package settings
if [ ! -f "$PKGINFO" ]; then
  echoc RED "bpp-make: info file not found ($PKGINFO)"
  exit 1
fi
. "$PKGINFO"

# Set other variables
BPPFILE=${BPPROOT}/packages/${SECTION}/${PACKAGE}_${VERSION}.bpp
BPPLOCALFILE=${PKGROOT}/${PACKAGE}_${VERSION}.bpp

# export
export BPPROOT PKGROOT PKGINFO WORKDIR
export PACKAGE VERSION KVERSION EVERSION SECTION SOURCE_DIR

# Check if the package already exist
if [ -f $BPPFILE ]; then
  echoc GREEN "bpp-make: package already exists ($BPPFILE)"
  exit 0
fi


echo "bpp-make: compiling the package"
bpp-compile "$1"
ASSERT "$?" "error while compiling"


if [ -f $BPPLOCALFILE ]; then
  echoc YELLOW "bpp-make: package already builded ($BPPLOCALFILE)"
  exit 0
fi
bpp-build "$1"
ASSERT "$?" "error while building"



echoc GREEN "`basename $0`: done"
exit 0


	@make available
