f8f2855778050adce07622d08cfe48fcbf43be66
[libfirm] / tools / build_firm_jni
1 #!/bin/sh
2
3 # Project:     FIRM
4 # File name:   script/build_firm_jni
5 # Purpose:     skript to build a java native interface for the public headers of firm.
6 # Author:      Goetz Lindenmaier
7 # Modified by:
8 # Created:     30.10.2002
9 # CVS-ID:      $Id$
10 # Copyright:   (c) 2002 Universität Karlsruhe
11 # Licence:
12
13
14 ###############################################################################
15 # Set this variable to the directory which shall contain the JNI implementation
16 FIRM_JNI_DIR=/ben/goetz/proj/libfirm/firm-jni/
17
18 # Set these directories to point to a libfirm installation:
19
20 FIRM_INCLUDE_DIR=/ben/goetz/proj/libfirm/i686/include
21 FIRM_LIB_DIR=/ben/goetz/proj/libfirm/i686
22 FIRM_JNI_TOOLS_DIR=/ben/goetz/proj/libfirm/firm-jni/tools
23
24 # Set this directory to a directory with sufficient space.
25 WORK_DIR=/ben/goetz/proj/libfirm/firm-jni/tmp
26
27 # This is the list of firm headers a JNI interface is generated for
28 FIRM_HEADERS="firm.h firm_common.h dbginfo.h ident.h tv.h
29         type.h entity.h type_or_entity.h tpop.h mangle.h
30         irprog.h irgraph.h irnode.h irmode.h irop.h ircons.h ircgcons.h irflag.h irvrfy.h
31         irdump.h iropt.h irgopt.h ircgopt.h
32         irouts.h irdom.h irloop.h cgana.h
33         irgwalk.h irgmod.h typewalk.h typegmod.h"
34
35 ###############################################################################
36
37 CURRENT_DIR=$PWD
38 SOURCE_DIR=sources
39 PUREC_DIR=purec
40
41 MACHINE=`uname -m`
42 SYS_OS=`uname -s`
43 ARCH_DIR=$MACHINE-$SYS_OS
44
45 LOG_FILE=compile-log.txt
46
47 REMOVE_CPP_COMMANDS=$FIRM_JNI_TOOLS_DIR/remove_cpp_comands.perl
48
49 #
50 # shell initialization
51 #
52 source /afs/info.uni-karlsruhe.de/public/tools/Modules/init/sh
53
54 #
55 # flags
56 #
57 verbose=""
58
59 #
60 # set up directories
61 #
62 rm -rf $WORK_DIR
63 mkdir -p $WORK_DIR
64 cd $WORK_DIR
65
66 ###############################################################################
67
68 analargs () {
69   while [ $# -gt 0 ]; do
70     case $1 in
71       --verbose) verbose="y";;
72       *)         echo "Unknown option "$1;;
73     esac
74     shift
75   done
76 }
77
78 analargs $*
79
80 ###############################################################################
81
82
83 ###############################################################################
84 # Get all the necessary Firm headers.
85 cd $WORK_DIR
86
87 mkdir $PUREC_DIR
88 mkdir $SOURCE_DIR
89
90 for file in $FIRM_HEADERS; do
91     cp $FIRM_INCLUDE_DIR/$file $SOURCE_DIR
92 done;
93
94 cd $SOURCE_DIR
95
96
97 ###############################################################################
98 # Remove C preprocessor commands.  Overwrite the header files.
99 # This part should be removed if crecoder integrates the preprocessor.
100
101 rm -f firm_typedefs.h
102 for file in $FIRM_HEADERS; do
103     perl $REMOVE_CPP_COMMANDS $file
104 done;
105
106 for file in $FIRM_HEADERS; do
107     gcc -E -C -P $file -o ../$PUREC_DIR/$file
108 done;
109
110 cd ../$PUREC_DIR
111
112
113 ###############################################################################
114 # Call crecoder to construct from each header a .java file specifying the
115 # java native interface.  Further crecoder constructs an implementation of
116 # the java native interface in C calling the real libfirm functions.
117 # For a file "file.h" files "File.java" and "File.c" are generated.
118
119 module add jdk-1.3.1-sun
120 export CLASSPATH=$FIRM_JNI_TOOLS_DIR/crecoder.jar:$CLASSPATH
121 for file in $FIRM_HEADERS; do
122    java crecoder/tools/jniBuilder/BuildJNI $file
123 done;
124
125 # Remove the C headers which are no more needed.  They contain
126 # nonsense no C compiler ever should see ;-)
127 rm -f $FIRM_HEADERS
128 # Make the JNI Implementation
129
130 export CPPFLAGS="-I. -I/usr/public2/java/jdk1.3-sun/include/ -I/usr/public2/java/jdk1.3-sun/include/linux/ -I$FIRM_INCLUDE_DIR"
131 export LDFLAGS="-L$FIRM_LIB_DIR"
132
133 make -f $FIRM_JNI_TOOLS_DIR/Makefile
134 mv libfirmjni.so $FIRM_JNI_DIR
135
136 #mv *.java *.class $FIRM_JNI_DIR