1#!/bin/sh -
2#       $Id$
3#
4# Run SWIG to generate the C# APIs
5
6t=/tmp/__db_a
7trap 'rm -f $t ; exit 0' 0
8trap 'rm -f $t ; exit 1' 1 2 3 13 15
9
10SWIG=swig
11SWIG_DIR=../libdb_csharp
12SWIG_FILE=$SWIG_DIR/db.i
13
14NAMESPACE="BerkeleyDB.Internal"
15CSHARP_SRCDIR=../csharp/Internal
16
17die() {
18	echo "$@" >&2
19	exit 1
20}
21
22[ -f $SWIG_FILE ] || die "Must be run from the dist directory"
23DIST_DIR=`pwd`
24
25for api in csharp ; do
26	echo "Building $api API"
27	swig_args="-outdir $CSHARP_SRCDIR -namespace $NAMESPACE -dllimport libname -DSWIG_CSHARP_NO_EXCEPTION_HELPER $args"
28
29	$SWIG -Wall -$api $swig_args -I$SWIG_DIR \
30	    -o ../libdb_$api/db_${api}_wrap.c $SWIG_FILE || exit $?
31done
32
33cd $CSHARP_SRCDIR
34[ -f DB.cs ] || exit 1
35
36for f in *.cs ; do
37    # SWIG v1.3 always puts quotes around the imported DLL name.  We're using a
38    # constant, not a string, because the DLL name changes based on Visual
39    # Studio's configuration.  Use sed to remove the quotes.
40    chmod 666 $f
41    sed 's/DllImport(\"libname\"/DllImport(libname/' < $f > $t
42    cp $t $f
43done
44
45cd $DIST_DIR
46
47cd $SWIG_DIR
48# db_config.h must be the first #include, move it to the top of the file.
49(
50      echo '#include "db_config.h"'
51      sed '/#include "db_config.h"/d' < db_csharp_wrap.c
52) > $t && cp $t db_csharp_wrap.c
53
54# The following might become redundant with newer swig versions.
55# builds usually already define _CRT_SECURE_NO_DEPRECATE
56(
57      sed -e '/# define _CRT_SECURE_NO_DEPRECATE/i\
58# undef _CRT_SECURE_NO_DEPRECATE' < db_csharp_wrap.c
59) > $t && cp $t db_csharp_wrap.c
60