#!bash
# vim:ff=unix:enc=utf8:ts=3:sw=3:et

# src2pkg-ng - package creation toolkit
# Copyright (C) 2005-2009 Gilbert Ashley
# Copyright (C) 2009 Timothy Goya

# src2pkg-ng is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2 as 
# published by the Free Software Foundation

# src2pkg-ng is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with src2pkg-ng.  If not, see <http://www.gnu.org/licenses/>.

detect_build_type() {
   declare CONFIG_DIR="$1"
   shift 1
   declare TYPE=""
   for TYPE in "$@" ; do
      if is_build_$TYPE "$CONFIG_DIR" ; then
         echo "$TYPE"
         return
      fi
   done
   echo "none"
}

configure_cmd_auto() {
   CONFIG_DIR="$1"
   shift 1

   tprintf $"@summary{Detecting configure type}: "
   CONFIGURE_TYPE="$(detect_build_type "$CONFIG_DIR" "${CONFIGURE_TYPES[@]}")"
   echo "$CONFIGURE_TYPE"
   configure_cmd_$CONFIGURE_TYPE "$CONFIG_DIR" "$@"
}

compile_cmd_auto() {
   CONFIG_DIR="$1"
   shift 1

   tprintf $"@summary{Detecting compile type}: "
   COMPILE_TYPE="$(detect_build_type "$CONFIG_DIR" "${COMPILE_TYPES[@]}")"
   echo "$COMPILE_TYPE"
   compile_cmd_$COMPILE_TYPE "$CONFIG_DIR" "$@"
}

install_cmd_auto() {
   CONFIG_DIR="$1"
   PKG_DIR="$2"
   shift 2

   tprintf $"@summary{Detecting install type}: "
   INSTALL_TYPE="$(detect_build_type "$CONFIG_DIR" "${INSTALL_TYPES[@]}")"
   echo "$INSTALL_TYPE"
   install_cmd_$INSTALL_TYPE "$CONFIG_DIR" "$PKG_DIR" "$@"
}
