#!/bin/sh

#
# Obtain current working directory.
#

SYSDEP_BASE_DIRECTORY=`${SYSDEP_UTIL_PWD}` ||
  SYSDEP_FATAL "could not obtain current working directory (problem with 'pwd')"
export SYSDEP_BASE_DIRECTORY
SYSDEP_DEBUG "SYSDEP_BASE_DIRECTORY ${SYSDEP_BASE_DIRECTORY}"

#
# Assign variables/subprograms for use in modules.
#

SYSDEP_TRY_CONFIG_BIN="${SYSDEP_BASE_DIRECTORY}/sd-configbin"
SYSDEP_TRY_PKG_CONFIG="${SYSDEP_BASE_DIRECTORY}/sd-configpkg"
SYSDEP_TRY_MANUAL="${SYSDEP_BASE_DIRECTORY}/sd-configman"
SYSDEP_FILE="${SYSDEP_BASE_DIRECTORY}/sd-file"
SYSDEP_LINE="${SYSDEP_BASE_DIRECTORY}/sd-line"
SYSDEP_SUBS_FILE="${SYSDEP_BASE_DIRECTORY}/sysdep-subs"

export SYSDEP_TRY_CONFIG_BIN
export SYSDEP_TRY_PKG_CONFIG
export SYSDEP_TRY_MANUAL
export SYSDEP_FILE
export SYSDEP_LINE
export SYSDEP_SUBS_FILE

#
# OUTDIR is below the base directory unless overridden.
#

SYSDEP_OUTPUT_DIRECTORY="${SYSDEP_BASE_DIRECTORY}/../"

#
# Override with contents of conf-outdir, if it exists.
#

if [ -f "conf-outdir" ]
then
  DIRECTORY=`${SYSDEP_LINE} 1 < "conf-outdir"`
  if [ $? -eq 0 ]
  then
    SYSDEP_OUTPUT_DIRECTORY="${DIRECTORY}"
  else
    SYSDEP_FATAL "conf-outdir exists but could not be read"
  fi
fi
export SYSDEP_OUTPUT_DIRECTORY
SYSDEP_DEBUG "SYSDEP_OUTPUT_DIRECTORY ${SYSDEP_OUTPUT_DIRECTORY}"

#
# Obtain name of module based on current directory.
#

if [ $# -ne 1 ]
then
  SYSDEP_FATAL "wrong arguments to sysdep-boot"
fi

SYSDEP_MODULE_PATH="$1"
SYSDEP_MODULE="`${SYSDEP_UTIL_BASENAME} ${SYSDEP_MODULE_PATH}`" ||
  SYSDEP_FATAL "could not translate current working directory (problem with 'basename')"
export SYSDEP_MODULE_PATH
export SYSDEP_MODULE

#
# Ensure status directory exists.
#

SYSDEP_STATUS_DIRECTORY="${SYSDEP_BASE_DIRECTORY}/status"
if [ ! -d "${SYSDEP_STATUS_DIRECTORY}" ]
then
  ${SYSDEP_UTIL_MKDIR} "${SYSDEP_STATUS_DIRECTORY}" ||
    SYSDEP_FATAL "could not create ${SYSDEP_STATUS_DIRECTORY}"
fi
export SYSDEP_STATUS_DIRECTORY

