From: Götz Lindenmaier Date: Tue, 5 Nov 2002 16:47:24 +0000 (+0000) Subject: Makefile to generate a jni for firm X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=731688b640632624bf9d77544654cd663c335364;p=libfirm Makefile to generate a jni for firm [r512] --- diff --git a/firmjni/Makefile.in b/firmjni/Makefile.in new file mode 100644 index 000000000..3e249b757 --- /dev/null +++ b/firmjni/Makefile.in @@ -0,0 +1,47 @@ + +# $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 diff --git a/firmjni/README b/firmjni/README new file mode 100644 index 000000000..f9be72302 --- /dev/null +++ b/firmjni/README @@ -0,0 +1,26 @@ + + +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. diff --git a/firmjni/build_firm_jni.in b/firmjni/build_firm_jni.in new file mode 100755 index 000000000..dfce6bc4e --- /dev/null +++ b/firmjni/build_firm_jni.in @@ -0,0 +1,142 @@ +#!/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 Universität 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