#!/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 http://mozilla.org/MPL/2.0/.


## Wrapper script for creating xpt files from idl files

# Parameters
# 1 - mozilla top directory
# 2 - source dir
# 3 - depth (relative path to top level dir)
# 4 .. n - idl file name


mkdir -p .deps _xpidlgen

PYTHON=$1
TOPDIR=$2
SRCDIR=$3
DEPTH=$4

shift 4

while [ $# -gt 0 ]; do
  XPTFILE=$1
  XPTBASE=`basename $1 | sed s/.xpt$//`
  HDRFILE=`echo $1 | sed s/.xpt$/.h/`

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

  ${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
