#!/bin/ksh
#      **********************************************
#      *                                            *
#      *  Produce dependencies for Message Catalogs *
#      *                                            *
#      **********************************************
#
#                        COPYRIGHT (c) 1994  BY
#         SIGMET INCORPORATED, WESTFORD MASSACHUSETTS, U.S.A.
# 
# THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND  COPIED
# ONLY  IN  ACCORDANCE WITH  THE  TERMS  OF  SUCH  LICENSE  AND WITH THE
# INCLUSION OF THE ABOVE COPYRIGHT NOTICE.  THIS SOFTWARE  OR  ANY OTHER
# COPIES  THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY
# OTHER PERSON.  NO TITLE TO AND OWNERSHIP OF  THE  SOFTWARE  IS  HEREBY
# TRANSFERED.
#

if [ "$1" = "" ] ; then exit 0 ; fi

# Scan through the first arg to make a list of include directories
# to search, and locate the name(s) of the file(s) that define the message
# values.
#
INCDIRS="" ; INCFILES=""
for ITEM in $1 ; do
  DIR="${ITEM#-I}"
  if [ "${DIR}" != "${ITEM}" ] ; then
    if [ -d ${DIR} ] ; then
      INCDIRS="${INCDIRS} ${DIR}"
    fi
  fi
  FILE="${ITEM#-DMSG_HEADER=\"}"
  if [ "${FILE}" != "${ITEM}" ] ; then
    INCFILES="${INCFILES} ${FILE%\"*}"
  fi
done

if [ "${INCDIRS}" = "" ] ; then
  echo "mkmf_msg: No include directories found" 1>&2 ; exit 1
fi
if [ "${INCFILES}" = "" ] ; then
  echo "mkmf_msg: No include files found" 1>&2 ; exit 1
fi

# Loop through each include file, locate which directory it is found
# in, and add that to the list.
#
DEPENDLINE="messages.usg: messages.msg"
for FILE in $INCFILES ; do
  FOUND="false"
  for DIR in $INCDIRS ; do
    if [ -r "${DIR}/${FILE}" ] ; then
      DEPENDLINE="${DEPENDLINE} ${DIR}/${FILE}"
      FOUND="true" ; break
    fi
  done
  if [ "${FOUND}" = "false" ] ; then
    echo "mkmf_msg: Could not locate '${FILE}'" 1>&2 ; exit 1
  fi
done

echo "${DEPENDLINE}"
