#!/bin/sh

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at https://mozilla.org/MPL/2.0/.


## Wrapper script for creating xpt files from idl files

# Parameters
# 1 - python directory
# 2 - additional interfaces dir
# 3 - Directory of typelib.py
# 4 - DIST directory
# 4 .. n - idl file name


mkdir -p _xpidlgen

PYTHON=$1
SDK_DIR=$2
TYPELIB_DIR=$3
DIST=$4

shift 4

XPTFILES=""

while [ $# -gt 0 ]; do
  XPIFILE=$1
  XPTFILE=`basename $1 | sed s/.idl$/.xpt/`
  XPTFILES="$XPTFILES  _xpidlgen/$XPTFILE"

  ${PYTHON} \
    ${TYPELIB_DIR}/typelib.py \
    -I${SDK_DIR} \
    -o _xpidlgen/${XPTFILE} \
    ${XPIFILE}

  if [ $? -ne 0 ]; then
    echo "** Could not create xpt file for $XPIFILE"
    exit 1
  fi

#   ${PYTHON} -u ${TOPDIR}/mozilla/config/pythonpath.py \
#     -I${TOPDIR}/mozilla/xpcom/typelib/xpt/tools \
#     ${DEPTH}/mozilla/dist/sdk/bin/header.py \
#     -I${TOPDIR}/mailnews/extensions/enigmail/public \
#     -I../../../../mozilla/dist/idl \
#     ${SRCDIR}/${XPTBASE}.idl \
#     -d .deps/${XPTBASE}.pp \
#     -o ${HDRFILE}

  shift
done

mkdir -p ${DIST}/components

${PYTHON} \
  ${TYPELIB_DIR}/xpt.py \
  link \
  ${DIST}/components/enigmail.xpt \
  $XPTFILES

