#!/bin/sh

# Extract CMake macros during configure
PREFIX="/usr/local"
FLAVOR="mcxtrace"
VERSION="1.1"
MC="mx"
NO_ALTERNATIVES="0"

# Include installation path before any attempt to postconfig
export PATH=${PREFIX}/bin:${PATH}
MCCODE=${FLAVOR}-${VERSION}


if [ "x${NO_ALTERNATIVES}" = "x1" ]; then
  # Setup mccode-select and mccode-select-bundle
  mccode-select-${MCCODE} --no-update-alternatives --bootstrap

  # Setup mcstas/mcxtrace including available tools
  mccode-select-bundle --no-update-alternatives --install \
	    ${FLAVOR} \
	    ${VERSION}
else
  # Setup mccode-select and mccode-select-bundle
  mccode-select-${MCCODE} --bootstrap

  # Setup mcstas/mcxtrace including available tools
  mccode-select-bundle --install \
	    ${FLAVOR} \
	    ${VERSION}
fi


# Check if mcdoc is installed and if it needs to run
if [ -x ${PREFIX}/bin/${MC}doc-${VERSION} ] && \
    [ -d ${PREFIX}/lib/${MCCODE}/examples ]; then
    ${PREFIX}/bin/${MC}doc-${VERSION} --text &>/dev/null
fi
