#!/bin/sh

# This is a fake IDL compiler.  It doesn't do much, other than create
# some files that a real IDL compiler might create.  The IDL 
# builder and the IDL-related Mylib.py functctions assume that the
# IDL compiler generates 4 files for an input IDL file baz.idl:
# baz.cpp, baz.h, baz_skel.cpp, and baz_skel.h.
#
# If your IDL compiler generates a different number of files or uses
# different names, you'll have to change SConstruct and Mylib.py
# accordingly.
#
# Note that SCons typically executes all of its commands with the
# current working directory at the root of your source & build
# hierarchy.  This is unlike recursive make, which chdir's into
# individual subdirectories before executing any commands.
#
# Therefore, hopefully your IDL compiler can be told which 
# directory to write its output file(s).  If not, you'll have to
# use the SCons command SConscriptChdir(); see the SCons man page
# for details.

OUTPUT_DIR="."

while [ ! -z "$1" ];
do
	case "$1" in
		--output-dir)
			OUTPUT_DIR="$2"
			shift
		;;
		-*)
			echo "Unknown flag, ignoring: " "$1"
		;;
		*)
			IDL_FILE="$1"
	esac
	shift
done

if [ ! -f "$IDL_FILE" ]; then
	echo "ERROR: IDL file '$IDL_FILE' does not exist, aborting!"
	exit 1
fi

IDL_BASE=`basename $IDL_FILE .idl`
IDL_MOD="$OUTPUT_DIR/$IDL_BASE.cpp"
IDL_HDR="$OUTPUT_DIR/$IDL_BASE.h"
IDL_SKEL_MOD="$OUTPUT_DIR/${IDL_BASE}_skel.cpp"
IDL_SKEL_HDR="$OUTPUT_DIR/${IDL_BASE}_skel.h"

echo "$0: Creating $IDL_MOD"
cat > $IDL_MOD <<EOM
// This was generated by $0.  It is fake!

#include <$IDL_BASE.h>
EOM

echo "$0: Creating $IDL_HDR"
cat > $IDL_HDR <<EOM
// This was generated by $0.  It is fake!

#define __FAKE	      1
EOM

echo "$0: Creating $IDL_SKEL_MOD"
cat > $IDL_SKEL_MOD <<EOM
// This was generated by $0.  It is fake!

#include <${IDL_BASE}_skel.h>
EOM

echo "$0: Creating $IDL_SKEL_HDR"
cat > $IDL_SKEL_HDR <<EOM
// This was generated by $0.  It is fake!

#define __FAKE	      1
EOM

