Commit 731688b6 authored by Götz Lindenmaier's avatar Götz Lindenmaier
Browse files

Makefile to generate a jni for firm

[r512]
parent 0e80ce9b
# $Id$
top_srcdir := @top_srcdir@
srcdir = @srcdir@
topdir = ..
subdir = firmjni
libdir = @libdir@ # where to find libfirm.a and where to put libfirmjni.so
LIBNAME = libfirmjni.so
.PHONY: default all clean realclean depend
MEMBERS = Firm.m Firm.m Firm_common.m Dbginfo.m Ident.m Tv.m \
Type.m Entity.m Type_or_entity.m Tpop.m Mangle.m \
Irprog.m Irgraph.m Irnode.m Irmode.m Irop.m Ircons.m Ircgcons.m \
Irflag.m Irvrfy.m Irdump.m Iropt.m Irgopt.m Ircgopt.m \
Irouts.m Irdom.m Irloop.m Cgana.m \
Irgwalk.m Irgmod.m Typewalk.m Typegmod.m
OFILES = $(MEMBERS:.m=.o)
HFILES = $(MEMBERS:.m=.h)
all: jni
%.class: %.java
javac $<
%.h: %.class
javah $(<:.class=)
%.o: %.c %.h
gcc $(CPPFLAGS) -c $< -o $@
jni: $(HFILES) $(OFILES) $(libdir)libfirm.a
gcc -shared -fPIC -o $(LIBNAME) *.o -L$(libdir) -lfirm
install:
cp libfirmjni.so $(libdir)
# cp *.java @javadir@
clean:
rm -rf sources *.c *.h *.o
realclean: clean
rm -f *~ libfirmjni.so *.vcg *.java *.class
Call
sh build_firm_jni
to generate a Java native interface for firm.
This script still contains various IPD specific settings,
e.g. oaths to the header files needed for JNI. This will be changed
at some point.
Generating the JNI requires various syntactic properties of the
header files that restrict legal C.
Do not use methods that generate a non null terminated String
from Idents (as idToStr). This will probably cause a segmentation
fault.
Some methods generated might not work yet. Please report this to
goetz@ipd.info.uni-karlsruhe.de
For now _all_ enumerators are generated into _all_ classes.
This results from deficiencies in the crecoder and will be removed
at some place.
Use only the enumerators defined in the corresponding c headers.
E.g., irm_X is defined in irmode.h, so use Irmode.irm_X, but not
Type.irm_X or any other definition in the java files.
#!/bin/sh
# Project: FIRM
# File name: script/build_firm_jni
# Purpose: skript to build a java native interface for the public headers of firm.
# Author: Goetz Lindenmaier
# Modified by:
# Created: 30.10.2002
# CVS-ID: $Id$
# Copyright: (c) 2002 Universitt Karlsruhe
# Licence:
top_srcdir=@top_srcdir@
srcdir=@srcdir@
topdir=..
subdir=firmjni
###############################################################################
# The directory which shall contain the JNI implementation after installation.
FIRM_JNI_DIR=./
# This is the list of firm headers a JNI interface is generated for
# If you change this list, also change the list in Makefile.in
FIRM_HEADERS="firm.h firm_common.h dbginfo.h ident.h tv.h
type.h entity.h type_or_entity.h tpop.h mangle.h
irprog.h irgraph.h irnode.h irmode.h irop.h ircons.h ircgcons.h
irflag.h irvrfy.h irdump.h iropt.h irgopt.h ircgopt.h
irouts.h irdom.h irloop.h cgana.h
irgwalk.h irgmod.h typewalk.h typegmod.h"
# These directories point to a libfirm installation:
FIRM_INCLUDE_DIR=@includedir@
FIRM_LIB_DIR=@libdir@
# The directory containing crecoder.jar and, for now,
# remove_cpp_comands.perl
FIRM_JNI_TOOLS_DIR=$top_srcdir/tools
WORK_DIR=.
###############################################################################
CURRENT_DIR=$PWD
SOURCE_DIR=sources
MACHINE=`uname -m`
SYS_OS=`uname -s`
ARCH_DIR=$MACHINE-$SYS_OS
LOG_FILE=compile-log.txt
REMOVE_CPP_COMMANDS=$FIRM_JNI_TOOLS_DIR/remove_cpp_comands.perl
CRECODER=$FIRM_JNI_TOOLS_DIR/crecoder.jar
#
# shell initialization
#
source /afs/info.uni-karlsruhe.de/public/tools/Modules/init/sh
#
# flags
#
verbose=""
#
# set up directories
#
#rm -rf $WORK_DIR
#mkdir -p $WORK_DIR
cd $WORK_DIR
###############################################################################
analargs () {
while [ $# -gt 0 ]; do
case $1 in
--verbose) verbose="y";;
*) echo "Unknown option "$1;;
esac
shift
done
}
analargs $*
###############################################################################
###############################################################################
# Get all the necessary Firm headers.
cd $WORK_DIR
rm -rf $SOURCE_DIR
mkdir $SOURCE_DIR
for file in $FIRM_HEADERS; do
cp $FIRM_INCLUDE_DIR/$file $SOURCE_DIR
done;
###############################################################################
# Remove C preprocessor commands. Overwrite the header files.
# This part should be removed if crecoder integrates the preprocessor.
rm -f $SOURCE_DIR/firm_typedefs.h
for file in $FIRM_HEADERS; do
perl $REMOVE_CPP_COMMANDS $SOURCE_DIR/$file
done;
# the perl script dumps this file in the dir it is called from
mv firm_typedefs.h $SOURCE_DIR
for file in $FIRM_HEADERS; do
gcc -E -C -P $SOURCE_DIR/$file -o $file
done;
###############################################################################
# Call crecoder to construct from each header a .java file specifying the
# java native interface. Further crecoder constructs an implementation of
# the java native interface in C calling the real libfirm functions.
# For a file "file.h" files "File.java" and "File.c" are generated.
module add jdk-1.3.1-sun
export CLASSPATH=$FIRM_JNI_TOOLS_DIR/crecoder.jar:$CLASSPATH
#echo $CLASSPATH
for file in $FIRM_HEADERS; do
java crecoder/tools/jniBuilder/BuildJNI $file
done;
# Remove the C headers which are no more needed. They contain
# nonsense no C compiler ever should see ;-)
rm -f $FIRM_HEADERS
# Make the JNI Implementation
export CPPFLAGS="-I. -I/usr/public2/java/jdk1.3.1-sun/include/ -I/usr/public2/java/jdk1.3.1-sun/include/linux/ -I$FIRM_INCLUDE_DIR"
export LDFLAGS="-L$FIRM_LIB_DIR"
# javah renames these files. the jnibuilder doesn't anticipate this
# and generates #includes with the original names.
ln -s Firm_0005fcommon.h Firm_common.h
ln -s Type_0005for_0005fentity.h Type_or_entity.h
make -f Makefile
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment