summaryrefslogtreecommitdiff
path: root/dist/s_csharp_swig
blob: de52c874ce2a769d0606756af97306bc4baf20db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/sh -
#       $Id$
#
# Run SWIG to generate the C# APIs

t=/tmp/__db_a
trap 'rm -f $t ; exit 0' 0
trap 'rm -f $t ; exit 1' 1 2 3 13 15

SWIG=swig
SWIG_DIR=../libdb_csharp
SWIG_FILE=$SWIG_DIR/db.i

NAMESPACE="BerkeleyDB.Internal"
CSHARP_SRCDIR=../csharp/Internal

die() {
	echo "$@" >&2
	exit 1
}

[ -f $SWIG_FILE ] || die "Must be run from the dist directory"
DIST_DIR=`pwd`

for api in csharp ; do
	echo "Building $api API"
	swig_args="-outdir $CSHARP_SRCDIR -namespace $NAMESPACE -dllimport libname -DSWIG_CSHARP_NO_EXCEPTION_HELPER $args"

	$SWIG -Wall -$api $swig_args -I$SWIG_DIR \
	    -o ../libdb_$api/db_${api}_wrap.c $SWIG_FILE || exit $?
done

cd $CSHARP_SRCDIR
[ -f DB.cs ] || exit 1

for f in *.cs ; do
    # SWIG v1.3 always puts quotes around the imported DLL name.  We're using a
    # constant, not a string, because the DLL name changes based on Visual
    # Studio's configuration.  Use sed to remove the quotes.
    chmod 666 $f
    sed 's/DllImport(\"libname\"/DllImport(libname/' < $f > $t
    cp $t $f
done

cd $DIST_DIR

cd $SWIG_DIR
# db_config.h must be the first #include, move it to the top of the file.
(
      echo '#include "db_config.h"'
      sed '/#include "db_config.h"/d' < db_csharp_wrap.c
) > $t && cp $t db_csharp_wrap.c

# The following might become redundant with newer swig versions.
# builds usually already define _CRT_SECURE_NO_DEPRECATE
(
      sed -e '/# define _CRT_SECURE_NO_DEPRECATE/i\
# undef _CRT_SECURE_NO_DEPRECATE' < db_csharp_wrap.c
) > $t && cp $t db_csharp_wrap.c