. "${GRIMOIRE}/FUNCTIONS" &&

depends -sub "CXX" gcc &&
depends bison &&
depends flex  &&
depends gettext   &&
depends libdrm &&
depends util-macros &&
depends expat &&
depends libxdamage &&
depends libx11 &&
depends libxshmfence &&
depends nettle  &&
# Build process needs to work on some XML with that.
# I do not test all configurations, therefore I pulled
# the direct python dependency out of the llvm branch,
# to be on the safe side.
depends python  &&
depends -sub PYTHON libxml2 &&

depends xorgproto &&

if [[ "${MESALIB_BRANCH}" == "scm" ]]; then
  depends git
fi &&

if [[ "${MESALIB_BUILD}" == "dri" ]]; then
  depends libxext &&
  depends libxxf86vm &&
  depends libxdamage &&
  depends libxfixes &&
  depends libxcb &&
  depends expat &&
  optional_depends DEVICE-MANAGER \
                   "" \
                   "--enable-sysfs" \
                   "Use a device manager instead of sysfs" &&

 optional_depends llvm \
                  "--enable-llvm --enable-egl" \
                  "--disable-llvm" \
                  "for Gallium drivers" &&

  if is_depends_enabled "${SPELL}" "llvm"; then
    depends LIBELF  &&
    depends mako    &&

    local AVAILABLE_GALLIUM="i915 nouveau r300 r600 radeonsi freedreno svga swrast vc4 virgl etnaviv imx" &&

    list_remove MESALIB_GALLIUM 'llvmpipe'  &&
    list_remove MESALIB_GALLIUM 'radeon'  &&

    config_query_multi MESALIB_GALLIUM \
                      "What Gallium3D drivers would you like to build?" \
                      all ${AVAILABLE_GALLIUM} &&
    if list_find "${MESALIB_GALLIUM}" "all"; then
      MESALIB_GALLIUM=${AVAILABLE_GALLIUM}
    fi &&

    # remove obsolete fbdev option
    list_remove MESA_EGL fbdev &&
    list_remove MESA_EGL wayland &&

    config_query_multi MESA_EGL "which EGL platforms?" android drm surfaceless x11 &&

      list_remove MESALIB_OPTS '--disable-shared-glapi'  &&
      list_add    MESALIB_OPTS '--enable-shared-glapi'

      config_query_option MESALIB_OPTS "enable Generic Buffer Management?" n \
                        "--enable-gbm" "--disable-gbm"
      config_query_option MESALIB_OPTS "enable support for OpenGL ES 2.x API?" n \
                        "--enable-gles2" "--disable-gles2"

    if list_find "${MESALIB_GALLIUM}" "i915"; then
      sub_depends libdrm INTEL
    fi &&
    if list_find "${MESALIB_GALLIUM}" "nouveau"; then
      sub_depends libdrm NOUVEAU
    fi &&
    if (list_find "${MESALIB_GALLIUM}" "r300") ||
      (list_find "${MESALIB_GALLIUM}" "r600"); then
      sub_depends libdrm RADEON
    fi &&
    if list_find "${MESALIB_GALLIUM}" "radeonsi"; then
      sub_depends libdrm AMD
    fi
  fi
fi &&

if ( list_find  "${MESALIB_DRIVERS}"  i915 ) || \
   ( list_find  "${MESALIB_DRIVERS}" i965); then
  sub_depends libdrm INTEL
fi &&

if ( list_find  "${MESALIB_DRIVERS}" r200) || \
   ( list_find  "${MESALIB_DRIVERS}" radeon); then
  sub_depends libdrm RADEON
fi &&

if ( list_find "${MESALIB_DRIVERS}" nouveau); then
  sub_depends libdrm NOUVEAU
fi &&

optional_depends libva    "--enable-va"    "--disable-va"    "video acceleration support" &&
optional_depends libvdpau "--enable-vdpau" "--disable-vdpau" "VDPAU support" &&
optional_depends libxvmc  "--enable-xvmc"  "--disable-xvmc"  "XvMC support (obsolete)"
optional_depends libunwind "--enable-libunwind" "--disable-libunwind" "debugging" &&
optional_depends libglvnd "--enable-libglvnd" "--disable-libglvnd" "GLVND support" &&

if ! is_depends_enabled "${SPELL}" "libglvnd"; then
  optional_depends smgl-gl_select "" "" "allow select OPENGL provider via SMGL script"
fi
