#!/bin/sh
################################################################################
# autoports - an attempt to implement something like bsd ports on linux.       #
# See /usr/autoports/conf/autoports.conf for some hints on settings.           #
# Created 4/9/2002 by Mike Green <mikey at badpenguins dot com>                   #
# Licensed under the GPLv2.                                                    #
################################################################################

################################################################################
# Apply_Patches()                                                              #
################################################################################
Apply_Patches() {

PATCH_LIST=`ls $FILEDIR/patch-* 2>/dev/null`

if [ -z "$PATCH_LIST" ]; then
   return 0
fi

cd $FAKEROOT/$DIST_SUBDIR || return 1

for patch in $PATCH_LIST
do
   echo "  Apply_Patches: $patch"
   ext="`Get_Extension $patch`"

   case "$ext" in
      bz2) CAT=bzcat       ;;
      zip) CAT="unzip -p"  ;;
      gz)  CAT="zcat"      ;;
      Z)   CAT="zcat"      ;;
      *)   CAT="cat"       ;;
   esac

   $CAT $patch | patch -p1
   if [ $? -ne 0 ]; then
      return 1
   fi
done

return 0

}

################################################################################
# Check_Depends()                                                              #
################################################################################
Check_Depends() {

Check_Fetch_Depends || return 1

[ "$FETCH_ONLY" ] && return 0

Check_Extract_Depends || return 1
Check_Lib_Depends || return 1
Check_Build_Depends || return 1

if [ "$AP_TARGET" = "install" ]; then
   Check_Run_Depends || return 1
fi

return 0

}

################################################################################
# Check_Build_Depends()                                                        #
################################################################################
Check_Build_Depends() {

[ "$BUILD_DEPENDS" ] || return 0

for dep in $BUILD_DEPENDS
do
   dfile="`echo $dep | cut -f1 -d:`"
   if [ ! -f "$dfile" ]; then
      ap="`echo $dep | cut -f2 -d:`"
	  echo "  BUILD_DEPENDS: $dfile"
	  cd $ap >>$LOG 2>&1 || return 1
	  autoport install || return 1
   fi
done

return 0

}

################################################################################
# Check_Dev_Depends()                                                          #
################################################################################
Check_Dev_Depends() {

[ "$DEV_DEPENDS" ] || return 0

for dep in $DEV_DEPENDS
do
   dfile="`echo $dep | cut -f1 -d:`"
   if [ ! -f "$dfile" ]; then
      ap="`echo $dep | cut -f2 -d:`"
	  echo "  DEV_DEPENDS: $dfile"
	  cd $ap >>$LOG 2>&1 || return 1
	  autoport install || return 1
   fi
done

return 0

}

################################################################################
# Check_Distfile()                                                             #
################################################################################
Check_Distfile() {

[ "$NO_DISTFILE" ] && return 0

if [ ! -f "$AP_SRC/$DISTFILE" ]; then
   Fetch_Distfile
   return $?
   else
   return 0
fi

}

################################################################################
# Check_Extract_Depends()                                                      #
################################################################################
Check_Extract_Depends() {

[ "$EXTRACT_DEPENDS" ] || return 0

for dep in $EXTRACT_DEPENDS
do
   dfile="`echo $dep | cut -f1 -d:`"
   if [ ! -f "${AP_SRC}/$dfile" ]; then
      ap="`echo $dep | cut -f2 -d:`"
	  echo "  EXTRACT_DEPENDS: $dfile"
	  cd $ap >>$LOG 2>&1 || return 1
	  autoport fetch || return 1
   fi
done

return 0

}

################################################################################
# Check_Fetch_Depends()                                                        #
################################################################################
Check_Fetch_Depends() {

[ "$FETCH_DEPENDS" ] || return 0

for dep in $FETCH_DEPENDS
do
   dfile="`echo $dep | cut -f1 -d:`"
   if [ ! -f "${AP_SRC}/$dfile" ]; then
      ap="`echo $dep | cut -f2 -d:`"
	  echo "  FETCH_DEPENDS: $dfile"
	  cd $ap >>$LOG 2>&1 || return 1
	  autoport fetch || return 1
   fi
done

return 0

}

################################################################################
# Check_Lib_Depends()                                                          #
################################################################################
Check_Lib_Depends() {

[ "$LIB_DEPENDS" ] || return 0

for dep in $LIB_DEPENDS
do
   ldconfig >/dev/null 2>&1
   lib="`echo $dep | cut -f1 -d:`"
   chk=`ldconfig -p | grep $lib >/dev/null 2>&1`
   if [ $? -ne 0 ]; then
      ap="`echo $dep | cut -f2 -d:`"
	  echo "  LIB_DEPENDS: $lib"
	  cd $ap >>$LOG 2>&1 || return 1
	  autoport install || return 1
          ldconfig >>$LOG 2>&1 || return 1
   fi
done

return 0

}

################################################################################
# Check_Run_Depends()                                                          #
################################################################################
Check_Run_Depends() {

[ "$RUN_DEPENDS" ] || return 0

for dep in $RUN_DEPENDS
do
   dfile="`echo $dep | cut -f1 -d:`"
   if [ ! -f "$dfile" ]; then
      ap="`echo $dep | cut -f2 -d:`"
	  echo "  RUN_DEPENDS: $dfile"
	  cd $ap >>$LOG 2>&1 || return 1
	  autoport install || return 1
   fi
done

return 0

}

################################################################################
# Copy_Docs()                                                                  #
################################################################################
Copy_Docs() {

if [ -z "$DOCLIST" ]; then
   return 0
fi

cd $FAKEROOT/$DIST_SUBDIR || return 1

cp -a $DOCLIST $FAKEROOT/$DOCS >>$LOG 2>&1 || return 1

return 0

}

################################################################################
# Extract_Dependencies()                                                       #
################################################################################
Extract_Dependencies() {

[ "$EXTRACT_DEPENDS" ] || return 0

if [ -z "$EXTRACT_DIR" ]; then
   EXTRACT_DIR="$FAKEROOT/$DIST_SUBDIR"
fi

for dep in $EXTRACT_DEPENDS
do
   dfile="`echo $dep | cut -f1 -d:`"
   if [ ! -r "${AP_SRC}/$dfile" ]; then
      echo
      echo "  Extract_Dependencies: ${AP_SRC}/$dfile missing"
      echo
      exit 1
   fi

   echo "  EXTRACT: $dfile"

   fext="`Get_Extension $dfile`"

   case "$fext" in
      bz2)
         tar xvfj ${AP_SRC}/$dfile -C $EXTRACT_DIR >>$LOG 2>&1 \
         || return 1
      ;;
      zip)
         unzip ${AP_SRC}/$dfile -d $EXTRACT_DIR >>$LOG 2>&1 \
         || return 1
      ;;
      *)
         tar xvfz ${AP_SRC}/$dfile -C $EXTRACT_DIR >>$LOG 2>&1 \
         || return 1
      ;;
   esac
done

return 0

}

################################################################################
# Extract_Source()                                                             #
################################################################################
Extract_Source() {
TARBALL=$1

[ "$NO_EXTRACT" ] && return 0

if [ -n "$USE_BZIP2" ]; then
   tar xvfj $AP_SRC/$DISTFILE -C $FAKEROOT >>$LOG 2>&1 || return 1
elif [ -n "$USE_ZIP" ]; then
   unzip $AP_SRC/$DISTFILE -d $FAKEROOT >>$LOG 2>&1 || return 1
else
   tar xvfz $AP_SRC/$DISTFILE -C $FAKEROOT >>$LOG 2>&1 || return 1
fi

if [ ! -d $FAKEROOT/$DIST_SUBDIR ]; then
   echo
   echo "  Extract_Source: package not extracted to $FAKEROOT/$DIST_SUBDIR"
   echo "  Extract_Source: Fix DIST_SUBDIR"
   echo
   return 1
fi

return 0

}

################################################################################
# Fetch_Distfile()                                                             #
################################################################################
Fetch_Distfile() {

[ "$NO_DISTFILE" ] && return 0

if [ -z "$MASTER_SITES" ]; then
   echo
   echo "  Fetch_Distfile: MASTER_SITES not set in pkg.conf"
   echo
   return 1
fi

if [ ! -w "$AP_SRC" ]; then
   echo
   echo "  Fetch_Distfile: write access denied to $AP_SRC"
   echo
   return 1
fi

for pkgsite in $MASTER_SITES
do
   cd $AP_SRC >>$LOG 2>&1 || return 1

   prot="`echo $pkgsite | cut -f1 -d:`"
   if [ -z "$prot" ]; then
      echo
      echo "  Fetch_Distfile: could not determine fetch protocol"
      echo
      return 1
   elif [ "$prot" = "ftp" ]; then
      FETCH_CMD=$FTP_FETCH_CMD
	  FETCH_BEFORE_ARG=$FTP_FETCH_BEFORE_ARGS
	  FETCH_AFTER_ARGS=$FTP_FETCH_AFTER_ARGS
	  FETCH_ENV=$FTP_FETCH_ENV
   elif [ "$prot" = "http" ]; then
      FETCH_CMD=$HTTP_FETCH_CMD
	  FETCH_BEFORE_ARTG=$HTTP_FETCH_BEFORE_ARGS
	  FETCH_AFTER_ARGS=$HTTP_FETCH_AFTER_ARGS
	  FETCH_ENV=$HTTP_FETCH_ENV
   fi

   if [ -z "$FETCH_CMD" ]; then
      echo
      echo "  Fetch_Distfile: could not determine FETCH_CMD"
      echo
      return 1
   fi

   if [ ! -x "$FETCH_CMD" ]; then
      echo
      echo "  Fetch_Distfile: execute access denied to $FETCH_CMD"
      echo
      return 1
   fi


   if [ "$MASTER_SITE_SUBDIR" ]; then
      URL="$pkgsite/$MASTER_SITE_SUBDIR/$DISTFILE"
      else
      URL="$pkgsite/$DISTFILE"
   fi

   echo "  Fetch_Distfile: $URL"

   eval $FETCH_CMD $FETCH_BEFORE_ARGS $URL $FETCH_AFTER_ARGS # >>$LOG 2>&1

   if [ $? -eq 0 -a -f $AP_SRC/$DISTFILE ]; then
      return 0
   fi
done

if [ ! -f $AP_SRC/$DISTFILE ]; then
   return 1
fi

}

################################################################################
# Get_Distfile_Name                                                            #
################################################################################
Get_Distfile_Name() {

if [ -n "$USE_BZIP2" ]; then
   echo "$DISTNAME.tar.bz2"
elif [ -n "$USE_ZIP" ]; then
   echo "$DISTNAME.zip"
elif [ -n "$USE_COMPRESS" ]; then
   echo "$DISTNAME.tar.Z"
elif [ -n "$USE_TGZ" ]; then
   echo "$DISTNAME.tgz"
elif [ -n "$USE_RPM" ]; then
   echo "$DISTNAME.rpm"
else
   echo "$DISTNAME.tar.gz"
fi

}

################################################################################
# Get_Extension()                                                              #
################################################################################
Get_Extension() {
fname=$1

local IFS

IFS=.
set -- $fname
if [ $# -eq 1 ]; then
   return 0
fi
shift `expr $# - 1`
echo $1

}

################################################################################
# Install_Package()                                                            #
################################################################################
Install_Package() {

[ "$NEVER_INSTALL" ] && return 0
[ "$NEVER_PACKAGE" ] && return 0

echo "  INSTALL: $TARGET/$PACKAGE.tgz"

installpkg $TARGET/$PACKAGE.tgz >>$LOG 2>&1

return $?

}

################################################################################
# Make_Package()                                                               #
################################################################################
Make_Package() {

[ "$NEVER_PACKAGE" ] && return 0

if [ "$MP_ROOT" = "y" ]; then
   echo "  Make_Package: changing ownership to root recursively"
   chown -R root:root $FAKEROOT >>$LOG 2>&1 || return 1
fi

cd $FAKEROOT
FOUNDLINKS="`find $FAKEROOT -type l`"

if [ -n "$FOUNDLINKS" ]; then
echo "$MP_LINKS
$MP_PERMS" | makepkg $TARGET/$PACKAGE.tgz >>$LOG 2>&1
 else
   echo $MP_PERMS | makepkg $TARGET/$PACKAGE.tgz >>$LOG 2>&1
fi

if [ $? -ne 0 -o ! -f $TARGET/$PACKAGE.tgz ]; then
   echo
   echo "  Make_Package: failed to create $TARGET/$PACKAGE.tgz"
   echo
   return 1
fi

echo "  Make_Package: created $TARGET/$PACKAGE.tgz"

return 0

}

################################################################################
# Remove_Source()                                                              #
################################################################################
Remove_Source() {

[ "$NO_DISTFILE" ] && return 0

rm -rf $FAKEROOT/$DIST_SUBDIR || return 1

}

################################################################################
# SanityCheck()                                                                #
################################################################################
SanityCheck() {

if [ ! -f $AP_SRC/$DISTFILE -a -z "$NO_DISTFILE" ]; then
   echo
   echo "  SanityCheck: could not locate $AP_SRC/$DISTFILE"
   echo
   return 1
fi

if [ -f $TARGET/$PACKAGE.tgz -a ! -w $TARGET/$PACKAGE.tgz ]; then
   echo
   echo "  SanityCheck:  write access denied to $TARGET/$PACKAGE.tgz"
   echo
   return 1
fi

#
# verify the compile script exists
#
if [ ! -f $SCRIPTDIR/Compile_Source ]; then
   echo
   echo "  SanityCheck:  $SCRIPTDIR/Compile_Source missing"
   echo
   return 1
fi

#
# verify extra files exist if FILES is set
#
if [ -n "$FILES" ]; then
   for fname in $FILES
   do
      if [ ! -f $FILEDIR/$fname ]; then
         echo
         echo "  SanityCheck:  $FILEDIR/$fname missing"
         echo
         return 1
      fi
   done
fi

#
# verify MP_xxxx is set
#
[ -z "$MP_LINKS" ] && MP_LINKS=y
[ -z "$MP_PERMS" ] && MP_PERMS=y
[ -z "$MP_ROOT" ]  && MP_ROOT=y
case $MP_LINKS in
   y|n)
      :
   ;;
   *)
      echo
      echo "  SanityCheck: MP_LINKS set incorrectly"
      echo
      return 1
   ;;
esac
case $MP_PERMS in
   y|n)
      :
   ;;
   *)
      echo
      echo "  SanityCheck: MP_PERMS set incorrectly"
      echo
      return 1
   ;;
esac
case $MP_ROOT in
   y|n)
      :
   ;;
   *)
      echo
      echo "  SanityCheck: MP_ROOT set incorrectly"
      echo
      return 1
   ;;
esac

if [ "$MP_PERMS" = "y" -o "$MP_ROOT" = "y" ]; then
   if [ $UID -ne 0 ]; then
      echo
      echo "  SanityCheck: You are not root, you moron"
      echo "  SanityCheck: Set MP_PERMS and MP_ROOT correctly"
      echo
      return 1
   fi
fi

#
# create directories
#
#echo "  SanityCheck: creating $TMP"
rm -rf $TMP
mkdir -p $TMP || return 1

#echo "  SanityCheck: creating $FAKEROOT"
mkdir -p $FAKEROOT || return 1

#echo "  SanityCheck: creating $TARGET"
if [ ! -d $TARGET ]; then
   mkdir -p $TARGET   || return 1
fi

if [ -n "$EXTRAS" ]; then
   for dname in $EXTRAS
   do
      #echo "  SanityCheck: creating ${FAKEROOT}${dname}"
      mkdir -p $FAKEROOT/$dname || return 1
   done
fi

#
# verify we can write to TARGET if packaging or installing
#
if [ ! "$AP_TARGET" = "fetch" -a ! -w "$TARGET" ]; then
   echo
   echo "  SanityCheck: write access denied to $TARGET"
   echo
   return 1
fi

#
# set logging
#
if [ -z "$LOG" ]; then
   LOG="/dev/null"
fi

if [ -n "$LOG" -a "$LOG" != "/dev/null" ]; then
   rm -f $LOG
fi

echo "  SanityCheck: logging to: $LOG"

return 0

}

################################################################################
# Show_Usage()                                                                 #
################################################################################
Show_Usage() {
echo
echo "usage: autoport install|fetch|package|world|dev"
echo
echo "  install: builds/copies the package to \$AP_CODE and installs it"
echo "  fetch:   retrieves the source only"
echo "  package: builds/copies the package to \$AP_CODE"
echo "  world:   packages EVERYTHING"
echo "  dev:     install development packages"
echo
echo "  This command must be performed in the packaging directory that is"
echo "  being installed (/usr/autoports/xxx/xxx)."
echo
exit 1

}

################################################################################
# Strip_Binaries()                                                             #
################################################################################
Strip_Binaries() {

[ "$NO_STRIP" ] && return 0

STRIPLIST=`find $FAKEROOT ! -path "$FAKEROOT/$DIST_SUBDIR/*" -type f -perm +1`
for i in $STRIPLIST
do
   BINTYPE=`file $i`
   ISEXE=`echo $BINTYPE | grep -c "LSB executable"`
   if [ "$ISEXE" -gt 0 ]; then
      echo "  Strip_Binaries: `basename $i`"
      strip --strip-unneeded $i >>$LOG 2>&1
   fi
   ISLIB=`echo $BINTYPE | grep -c "LSB shared object"`
   if [ "$ISLIB" -gt 0 ]; then
      echo "  Strip_Binaries: `basename $i`"
      strip --strip-debug $i >>$LOG 2>&1
   fi
done

return 0

}

################################################################################
# Verify_Conf()                                                                #
################################################################################
Verify_Conf() {

if [ -z "$AP_ROOT" ]; then
   echo
   echo "  Verify_Conf: AP_ROOT not set in $AP_CONF"
   echo
   exit 1
elif [ -z "$AP_SRC" ]; then
   echo
   echo "  Verify_Conf: AP_SRC not set in $AP_CONF"
   echo
   exit 1
elif [ -z "$AP_CODE" ]; then
   echo
   echo "  Verify_Conf: AP_CODE not set in $AP_CONF"
   echo
   exit 1
elif [ -z "$AP_BUILD" ]; then
   echo
   echo "  Verify_Conf: AP_BUILD not set in $AP_CONF"
   echo
   exit 1
elif [ -z "$AP_TMP" ]; then
   echo
   echo "  Verify_Conf: AP_TMP not set in $AP_CONF"
   echo
   exit 1
fi

if [ ! -d $AP_ROOT ]; then
   echo
   echo "  Verify_Conf: $AP_ROOT missing"
   echo
   exit 1
fi

for pdir in $AP_SRC $AP_CODE $AP_BUILD #$AP_TMP
do
   if [ ! -d $pdir ]; then
      mkdir -p $pdir >/dev/null 2>&1
      if [ $? -ne 0 ]; then
         echo
         echo "   Verify_Conf: $pdir cannot be created"
         echo
         exit 1
      fi
   fi
done

return 0

}

################################################################################
# Verify_Pkg_Conf()                                                            #
################################################################################
Verify_Pkg_Conf() {

if [ -z "$MASTERDIR" ]; then
   echo
   echo "  Verify_Pkg_Conf: MASTERDIR not set in pkg.conf"
   echo
   exit 1
fi

if [ -z "$PKGNAME" ]; then
   echo
   echo "  Verify_Pkg_Conf: PKGNAME not set in pkg.conf"
   echo
   exit 1
elif [ -z "$CATEGORIES" ]; then
   echo
   echo "  Verify_Pkg_Conf: CATEGORIES not set in pkg.conf"
   echo
   exit 1
fi

if [ ! -d $MASTERDIR ]; then
   echo
   echo "  Verify_Pkg_Conf: $MASTERDIR does not exist"
   echo
   exit 1
fi

if [ -n "$ROOT_REQUIRED" -a ! "$UID" -eq 0 -a -z "$FETCH_ONLY" ]; then
   echo
   echo "  Verify_Pkg_Conf: ROOT_REQUIRED is set"
   echo
   exit 1
fi

return 0

}

################################################################################
# VerifyReturnCode()                                                           #
################################################################################
VerifyReturnCode() {
funcname=$1
shift

$funcname "$*"
code=$?

if [ $code -ne 0 ]; then
   echo
   echo "   VerifyReturnCode: $funcname() rc=$code"
   echo
   if [ -z "$TESTBUILD" ]; then
      rm -rf $TMP
   else
      echo
      echo "  VerifyReturnCode: TESTBUILD set - not removing work directory"
      echo
   fi
   exit 1
fi

}

################################################################################
# Main flow starts here.                                                       #
################################################################################
if [ $# -ne 1 ]; then
   Show_Usage
   exit 1
fi

[ "$MASTERDIR" ] || MASTERDIR=`pwd`

#
# load autoports.conf
#
if [ -z "$AP_CONF" ]; then
   if [ -f ~/.autoports.conf ]; then
      AP_CONF=~/.autoports.conf
   elif [ -f /etc/autoports.conf ]; then
      AP_CONF=/etc/autoports.conf
   elif [ -f /usr/autoports/conf/autoports.conf ]; then
      AP_CONF=/usr/autoports/conf/autoports.conf
   else
      echo
      echo "  cannot locate autoports.conf"
      echo
      exit 1
   fi
fi

echo
echo "RUNNING: `pwd`"

if [ ! -r $AP_CONF ]; then
   echo
   echo "  $AP_CONF missing"
   echo
   exit 1
else
   . $AP_CONF
   Verify_Conf
fi

if [ -z "$ARCH" ]; then
   ARCH=`uname -m`
fi

#
# verify args
#
case "$1" in
   clean)
      AP_TARGET=clean
      echo "cleaning out all work directories"
      dlist="`find $AP_BUILD -type d -name work`"
      for i in $dlist
      do
         echo "  $i"
         rm -rf $i
      done
      exit 0
      ;;
   dev)
      LOG=/dev/null
      Check_Dev_Depends
      exit 0
      ;;
   fetch)
      AP_TARGET=fetch
      FETCH_ONLY=yes
      ;;
   install)
      AP_TARGET=install
      TARGET_ROOT=$AP_CODE
      INSTALL_PKG=yes
      ;;
   package)
      AP_TARGET=package
      TARGET_ROOT=$AP_CODE
      ;;
   wipe)
      AP_TARGET=wipe
      echo "wiping all packages"
      [ "$AP_CODE" -a -w "$AP_CODE" ] && rm -rf $AP_CODE/*
      echo "wiping all source files"
      [ "$AP_SRC" -a -w "$AP_SRC" ] && rm -rf $AP_SRC/*
      exit 0
      ;;
   world)
      AP_TARGET=world
      list="`find $AP_BUILD -type f -name pkg.conf | sort -n`"
      for i in $list
      do
         cd `dirname $i`
	 autoport package
	 if [ $? -ne 0 ]; then
            echo
	    echo "failed on `dirname $i`"
            echo
	    exit 1
	 fi
      done
      exit 0
      ;;
   *)
      Show_Usage
      ;;
esac

#
# generate file names/paths for build
#
TMP=$AP_TMP/tmp-$$
export TMP
FAKEROOT=$TMP/fakeroot

#
# check for pkg.conf
#
if [ -f ./pkg.conf ]; then
   . pkg.conf
   Verify_Pkg_Conf
else
   echo
   echo "  no pkg.conf"
   echo
   exit 1
fi

#
# generate file names/paths for build
#
FILEDIR=$MASTERDIR/files
if [ "$GENERIC_KERNEL_BUILD" ]; then
   SCRIPTDIR="${AP_ROOT}/bin/kernel_build"
else
   SCRIPTDIR=$MASTERDIR/scripts
fi

#
# concoct the filenames
#
if [ -z "$DISTNAME" ]; then
   DISTNAME=$PKGNAME-$PKGVERSION
fi
if [ -z "$DISTFILE" ]; then
   DISTFILE=`Get_Distfile_Name`
fi
if [ -z "$DIST_SUBDIR" ]; then
   DIST_SUBDIR=$DISTNAME
fi

#
# Use the first category listed for the category
# target directory
#
set -- $CATEGORIES
TARGET=$TARGET_ROOT/$1

#
# final package name (no path)
#
[ "$PKGREVISION" ] || PKGREVISION=1
[ "$PKGREVISION" -lt 1 ] && PKGREVISION=1
[ "$PKGVERSION" ] || PKGVERSION=0.0.1

PACKAGE=$PKGNAME-$PKGVERSION-$ARCH-$PKGREVISION

if [ -f "$TARGET/$PACKAGE.tgz" ]; then
   if [ "$INSTALL_PKG" = "yes" ]; then
      VerifyReturnCode Check_Lib_Depends
      VerifyReturnCode Check_Run_Depends
      VerifyReturnCode Install_Package
   else
      echo "  $PACKAGE.tgz exists"
   fi
   exit 0
fi

#
# Generate the DOCS path for lazy people :)
#
if [ -n "$DOCLIST" -a -z "$DOCS" ]; then
   DOCS="/usr/doc/$PKGNAME-$PKGVERSION"
   EXTRAS="$DOCS $EXTRAS"
fi

VerifyReturnCode Check_Depends

[ "$IS_STUB" ] && exit 0

VerifyReturnCode Check_Distfile

[ "$FETCH_ONLY" ] && exit 0

VerifyReturnCode Check_Dev_Depends
VerifyReturnCode SanityCheck
VerifyReturnCode Extract_Source
VerifyReturnCode Extract_Dependencies
VerifyReturnCode Apply_Patches

. $SCRIPTDIR/Compile_Source
VerifyReturnCode Compile_Source

VerifyReturnCode Copy_Docs

if [ -f $SCRIPTDIR/Customize_Package ]; then
   . $SCRIPTDIR/Customize_Package
   VerifyReturnCode Customize_Package
fi

VerifyReturnCode Strip_Binaries
VerifyReturnCode Remove_Source
VerifyReturnCode Make_Package

cd $MASTERDIR
rm -rf $TMP

if [ "$INSTALL_PKG" = "yes" ]; then
   VerifyReturnCode Install_Package
fi
