source "$GRIMOIRE/MESON_DEPENDS" &&

depends dbus &&
depends dbus-glib &&
depends GETTEXT &&
depends glib2 &&
depends libnl &&
depends libgcrypt &&
depends libndp &&
depends readline &&
depends util-linux &&
depends DEVICE-MANAGER &&

optional_depends iptables '' '' "Enable iptables support" &&
optional_depends nftables '' '' "Enable nftables support" &&

optional_depends libpsl \
                 libpsl=true \
                 libpsl=false \
                 "Link against libpsl" &&

if [ -n "$LOGGING_BACKEND" ] ;then
  case "$LOGGING_BACKEND" in
    syslog) depends SYSTEM-LOGGER ;;
    journal) depends systemd ;;
  esac
  LOGGING_BACKEND_OPT="config_logging_backend_default=$LOGGING_BACKEND"
fi &&
persistent_add LOGGING_BACKEND_OPT &&

if [ -n "$SESSION_TRACKING" ] ;then
  case "$SESSION_TRACKING" in
    none) SESSION_TRACKING="no" ;;
    consolekit)
      depends CONSOLE-MANAGER "session_tracking_consolekit=true" &&
      unset SESSION_TRACKING
      ;;
    *)
      depends "$SESSION_TRACKING" "session_tracking_consolekit=false"
      ;;
  esac &&
  SESSION_TRACKING_OPT="${SESSION_TRACKING:+session_tracking=$SESSION_TRACKING}"
fi &&
persistent_add SESSION_TRACKING_OPT &&

for s in CONSOLE-MANAGER elogind systemd ;do
  case "$s" in
    CONSOLE-MANAGER)
      s=$(get_spell_provider "${SPELL}" "CONSOLE-MANAGER") &&
      case "$s" in
        none) unset s ;;
      esac &&
      if [ -z "$s" ] ;then
        optional_depends CONSOLE-MANAGER '' '' "Enable ConsoleKit support" &&
        continue
      fi
      ;;
  esac &&
  if ! is_depends_enabled "$SPELL" "$s" ;then
    optional_depends "$s" '' '' "Enable $s support"
  fi
done

if [ -n "$SUSPEND_RESUME" ] ;then
  case "$SUSPEND_RESUME" in
    auto) ;;
    none) unset SUSPEND_RESUME ;;
    *) depends "$SUSPEND_RESUME" ;;
  esac &&
  SUSPEND_RESUME_OPT="${SUSPEND_RESUME:+suspend_resume=$SUSPEND_RESUME}"
fi &&
persistent_add SUSPEND_RESUME_OPT &&

if ! is_depends_enabled "$SPELL" upower ;then
  optional_depends upower '' '' "Enable upower suspend/resume support"
fi &&

depends libgudev &&

if [ -n "$NETWORK_MANAGER_CRYPTO" ] ;then
  case "$NETWORK_MANAGER_CRYPTO" in
    none) NETWORK_MANAGER_CRYPTO="null" ;;
    *) depends "$NETWORK_MANAGER_CRYPTO" ;;
  esac &&
  NM_CRYPTO="crypto=$NETWORK_MANAGER_CRYPTO"
fi &&
persistent_add NM_CRYPTO &&

optional_depends newt \
                 nmtui=true \
                 nmtui=false \
                 "Build nmtui" &&

optional_depends policykit \
                 polkit=true \
                 polkit=false \
                 "Enable PolicyKit support?" &&

case "$DEFAULT_DHCP" in
  dhcpcd) depends "$DEFAULT_DHCP" "${DEFAULT_DHCP}=true" ;;
  # we don't yet have a dhclient spell
  #dhclient) depends "$DEFAULT_DHCP" "${DEFAULT_DHCP}=true" ;;
esac &&

# when we have a dhclient spell, add it to the for loop list below
for s in dhcpcd ;do
  if ! is_depends_enabled "$SPELL" "$s" ;then
    optional_depends "$s" \
                     "$s=true" \
                     "$s=false" \
                     "Enable $s DHCP client support"
  fi
done &&

optional_depends ppp \
                 ppp=true \
                 ppp=false \
                 "Enable PPP/PPPoE support?" &&

optional_depends IFUPDOWN \
                 ifupdown=true \
                 ifupdown=false \
                 "Network activation" &&

if [ -n "$DEFAULT_WIFI" ] ;then
  case "$DEFAULT_WIFI" in
    iwd) depends iwd iwd=true ;;
    wpa_supplicant) depends wpa_supplicant ;;
  esac
fi &&

for s in iwd wpa_supplicant ;do
  if ! is_depends_enabled "$SPELL" "$s" ;then
    case "$s" in
      iwd)
        optional_depends "$s" \
                         "$s=true" \
                         "$s=false" \
                         "Enable $s support"
        ;;
      *) optional_depends "$s" '' '' "Enable $s support" ;;
    esac
  fi
done &&

optional_depends modemmanager \
                 modem_manager=true \
                 modem_manager=false \
                 "Modem Manager support" &&

optional_depends audit \
                 libaudit=yes \
                 libaudit=no \
                 "audit support" &&

optional_depends jansson \
                 ovs=true \
                 ovs=false \
                 "Open vSwitch integration" &&

optional_depends libselinux \
                 selinux=true \
                 selinux=false \
                 "Security Enhanced Linux support" &&

optional_depends dnsmasq '' '' "Enable dnsmasq support" &&

if [ -n "$NM_DOCS" ] && [ x"$NM_DOCS"x = x"y"x ] ;then
  depends gtk-doc docs=true
fi &&

optional_depends vala \
                 vapi=true \
                 vapi=false \
                 "Build api docs"

if is_depends_enabled "$SPELL" vala ||
   is_depends_enabled "$SPELL" gtk-doc ||
   "${NM_DOCS#*=}" ;then
  depends gobject-introspection introspection=true &&
  depends pygobject3
fi &&

if ! is_depends_enabled "$SPELL" gobject-introspection ;then
  optional_depends gobject-introspection \
                   introspection=true \
                   introspection=false \
                   "Enable introspection support"
fi &&

if "${CONNECTION_CHECK##*=}" ;then
  runtime_depends curl
fi &&

suggest_depends linux-firmware
