# Function to remove old package directories and make new ones. 
# To be invoked inside a package build file.
mkandenterbuilddir() {
  # $TMP, $PKG and $PKGDEST are set in bldpkg.conf. 
  PKGDOCS="$PKG/doc/$APP-$VERSION"
  # Remove any old $PKG staging directory left by any previous build.
  # We are about to rm -rf something, so trying a bit hard not to delete
  # the wrong directory
  if ! inarray "${PKG}" "${SM_PROTECTEDDIRECTORIES[@]}" ; then
    rm -rf "$PKG"
  else 
    systemdirectorydeletionmessage
    echo "'"$PKG"' IS LISTED AS A PROTECTED DIRECTORY BUT 
ACCIDENTALLY LISTED AS A VALUE FOR "'$PKG'" VARIABLE!! ABORTING!!"
    exit 1
  fi
     
  # Now create all essential build-related directories
  mkdir -p "$SM_TMP" "$PKG" "$PKGDOCS" "$PKGDEST" 

  echo "[INFO] Leaving source directory $SRCDIR"
  echo "[INFO] Entering build directory $SM_TMP"
  cd "$SM_TMP"
}

