
SUPPORTED_DRIVERS="i915 i965 nouveau r200 radeon swrast"
SUPPORTED_GALLIUM="i915 nouveau r300 r600 svga swrast"

make_drivers_checklist() {

  # For each locale, extract name, title and charmap information
  for driver in $SUPPORTED_DRIVERS; do
      title=$driver

    echo "\"$driver\" \"$title\" \"on\" "
  done
}

make_gallium_drivers_checklist() {

  # For each locale, extract name, title and charmap information
  for driver in $SUPPORTED_GALLIUM; do
      title=$driver

    echo "\"$driver\" \"$title\" \"on\" "
  done
}

select_drivers() {
  BACKTITLE="MesaLib Configuration"
      TITLE="Driver Selection"
       HELP=""
  make_drivers_checklist | xargs \
  dialog --backtitle "$BACKTITLE" \
         --title     "$TITLE"     \
         --stdout                 \
         --separate-output        \
         --checklist "$HELP"      \
         0 0 0
}

select_gallium_drivers() {
  BACKTITLE="Gallium Configuration"
      TITLE="Gallium Driver Selection"
       HELP=""
  make_gallium_drivers_checklist | xargs \
  dialog --backtitle "$BACKTITLE" \
         --title     "$TITLE"     \
         --stdout                 \
         --separate-output        \
         --checklist "$HELP"      \
         0 0 0
}

if ! grep -q "MESADRIVER=" $MODULE_CONFIG; then
  MESADRIVER=`select_drivers`
  set_module_config MESADRIVER "$MESADRIVER"
fi

mquery GALLIUM "Enable Gallium llvm renderer? (Needed for rX00)" y "--enable-gallium-llvm" "--disable-gallium-llvm"

# mquery doesn't return or set env's, so read out the result:
GALLIUM=`get_module_config GALLIUM`

if [[ $GALLIUM == y ]] ; then
  if ! grep -q "GALLIUMDRIVER=" $MODULE_CONFIG; then
    GALLIUMDRIVER=`select_gallium_drivers`
    set_module_config GALLIUMDRIVER "$GALLIUMDRIVER"
  fi
fi

mquery XA "Enable XA support?" y "--enable-xa" "--disable-xa"
if [[ $GALLIUM == y ]]; then
  mquery EGL "Enable EGL (for i9x5)?" y "--enable-egl --enable-gallium-egl" "--disable-egl --disable-gallium-egl"
  mquery OPENVG "Enable openVG?" y "--enable-openvg" "--disable-openvg"
  mquery D3D "Enable D3D API's?" n "--enable-d3d1x --enable-gallium-g3dvl" "--disable-d3d1x --disable-gallium-g3dvl"
else
  mquery EGL "Enable EGL (for i9x5)?" y "--enable-egl" "--disable-egl"
  mquery D3D "Enable D3D API's?" n "--enable-d3d1x" "--disable-d3d1x"
fi
mquery TEXTURE_FLOAT "Enable patented texture-float? (if this patent is valid in your country choose N)" n "--enable-texture-float" "--disable-texture-float"
mquery ENABLE_GLX_TLS "Enable glx-tls? (lin -r xorg-server also)" y "--enable-glx-tls" "--disable-glx-tls"
