Add BSD license file
[platform/upstream/db4.git] / dist / s_java_swig
1 #!/bin/sh -
2 #       $Id$
3 #
4 # Run SWIG to generate the Java APIs
5
6 t=/tmp/__db_a
7 trap 'rm -f $t ; exit 0' 0
8 trap 'rm -f $t ; exit 1' 1 2 3 13 15
9
10 SWIG=swig
11 SWIG_DIR=../libdb_java
12 SWIG_FILE=$SWIG_DIR/db.i
13 PACKAGE="com.sleepycat.db.internal"
14
15 die() {
16         echo "$@" >&2
17         exit 1
18 }
19
20 [ -f $SWIG_FILE ] || die "Must be run from the dist directory"
21
22 for api in java ; do
23         echo "Building $api API"
24
25         swig_args=""
26         case $api in
27         java)
28                 swig_args="-nodefaultctor -nodefaultdtor -package $PACKAGE $args"
29                 ;;
30         esac
31
32         $SWIG -Wall -$api $swig_args -I$SWIG_DIR \
33             -o ../libdb_$api/db_${api}_wrap.c $SWIG_FILE || exit $?
34 done
35
36 # Skip Java sources if run with "-n"
37 if [ "x$1" = "x-n" ] ; then
38         rm -f $SWIG_DIR/*.java
39         exit 0
40 fi
41
42 # Fixups for Java
43 JAVA_SRCTOP=../java/src
44 JAVA_PKGDIR=com/sleepycat/db/internal
45 JAVA_SRCDIR=$JAVA_SRCTOP/$JAVA_PKGDIR
46
47 # SWIG 1.3.18 puts the Java files in the same directory as the native code.
48 cd $SWIG_DIR
49 [ -f Db.java ] || exit 1
50
51 for f in *.java ; do
52         case $f in
53                 SWIGTYPE*)
54                         die "Interface contains unresolved types: $f"
55         esac
56         rm -f $JAVA_SRCDIR/$f
57         perl -p $SWIG_DIR/java-post.pl < $f > $JAVA_SRCDIR/$f || exit $?
58         rm -f $f
59 done
60
61 # db_config.h must be the first #include, move it to the top of the file.
62 (
63       echo '#include "db_config.h"'
64       sed '/#include "db_config.h"/d' < db_java_wrap.c
65 ) > $t && cp $t db_java_wrap.c
66
67 # The following might become redundant with newer swig versions.
68 # builds usually already define _CRT_SECURE_NO_DEPRECATE
69 (
70       sed -e '/# define _CRT_SECURE_NO_DEPRECATE/i\
71 # undef _CRT_SECURE_NO_DEPRECATE' < db_java_wrap.c
72 ) > $t && cp $t db_java_wrap.c
73