#!/usr/bin/env bash
#
# SPDX-FileCopyrightText: 2021 René de Hesselle <dehesselle@web.de>
#
# SPDX-License-Identifier: GPL-2.0-or-later

### description ################################################################

# This script is a wrapper around the jhbuild binary to run it in our
# configured environment (etc/jhb.conf).

### shellcheck #################################################################

# Nothing here.

### dependencies ###############################################################

#---------------------------------------------------------- source configuration

source "$(dirname "${BASH_SOURCE[0]}")"/../../etc/jhb.conf.sh

#------------------------------------------- source common functions from bash_d

# bash_d is already available (it's part of etc/jhb.conf)

bash_d_include error

### variables ##################################################################

# Nothing here.

### functions ##################################################################

# Nothing here.

### main #######################################################################

if $CI; then   # break in CI, otherwise we get interactive prompt by JHBuild
  error_trace_enable
fi

case "$1" in
  debug)
    echo_d "doing nothing"
    ;;
  configure)
    jhbuild_configure "$2"   # e.g. 'jhbuild/myapp.modules'
    ccache_configure
    ;;
  *)
    if  sys_wrkdir_is_usable &&
        sdkroot_exists &&
        sys_usrlocal_is_clean; then

      # these checks may issue warnings but have have no consequences otherwise
      sys_macos_is_recommended || true
      sys_sdk_is_recommended || true
    else
      exit 1    # cannot continue
    fi
    "$USR_DIR"/bin/jhbuild "$@"
    ;;
esac