SUPPORTED_TARGETS="i386-softmmu x86_64-softmmu arm-softmmu cris-softmmu m68k-softmmu mips-softmmu mipsel-softmmu mips64-softmmu mips64el-softmmu ppc-softmmu ppcemb-softmmu ppc64-softmmu sh4-softmmu sh4eb-softmmu sparc-softmmu i386-linux-user x86_64-linux-user alpha-linux-user arm-linux-user armeb-linux-user cris-linux-user m68k-linux-user mips-linux-user mipsel-linux-user ppc-linux-user ppc64-linux-user ppc64abi32-linux-user sh4-linux-user sh4eb-linux-user sparc-linux-user sparc64-linux-user sparc32plus-linux-user"


make_targets_checklist() {
  for target in $SUPPORTED_TARGETS; do
    title=$target
    echo "\"$target\" \"$title\" \"off\" "
  done
}

select_targets() {
  BACKTITLE="Qemu Target Configuration"
      TITLE="Target Selection"
       HELP="Select targes you want to build"
  make_targets_checklist | xargs  \
  dialog --backtitle "$BACKTITLE" \
         --title     "$TITLE"     \
         --stdout                 \
         --separate-output        \
         --checklist "$HELP"      \
         0 0 0
}

if ! grep -q CONFIGURED $MODULE_CONFIG; then
  if grep -q "TARGETLIST=" $MODULE_CONFIG; then
    message "Selecting targets is optional"
  fi

  if query "Would you like to select arch targets? If not selected, all targets will be installed." y ; then
    TARGETLIST=`select_targets`
    TEMP=`grep -v "TARGETLIST="          $MODULE_CONFIG`
    echo "$TEMP"                       > $MODULE_CONFIG
    echo "TARGETLIST=\"$TARGETLIST\"" >> $MODULE_CONFIG

  fi

  echo "OPTS=\"\$OPTS $OPTS\"" >> $MODULE_CONFIG
  echo "CONFIGURED=y"          >> $MODULE_CONFIG
fi
