4 top_srcdir := @top_srcdir@
9 # The library implementing the JNI methods. This name is also
10 # known to the generator for the JNI interface and used in the
12 LIBNAME = libfirmjni.so
14 # The name of the package containing the Firm JNI
17 # where to put libfirmjni.so
19 # where to put the directory firmjni containing the generated
20 # .java and .class files
21 #javadir = @javadir@ @@@ how to specify a dir in configure.in?
23 .PHONY: default all clean realclean depend
25 SHELL_TOUPPER = awk '{for (i=1;i<(NF+1);i=i+1) {printf(toupper(substr($$i,1,1)) substr($$i,2)" ")}}'
26 SHELL_TOLOWER = awk '{for (i=1;i<(NF+1);i=i+1) {printf(tolower(substr($$i,1,1)) substr($$i,2)" ")}}'
28 OFILES = $(MEMBERS:.m=.o)
29 HFILES = $(MEMBERS:.m=.h)
30 CLASSFILES = $(MEMBERS:.m=.class)
32 CPPFLAGS = -I$(top_srcdir)/ir/ir -I$(top_srcdir)/ir/common \
33 -I$(top_srcdir)/ir/ident -I$(top_srcdir)/ir/tr \
34 -I$(top_srcdir)/ir/tv -I$(top_srcdir)/ir/debug \
35 -I$(top_srcdir)/ir/ana -I$(top_srcdir)/ir/st @CPPFLAGS@ \
40 FIRM_HEADERS=$(notdir $(FIRM_PATH_HEADERS))
41 MEMBERS=$(subst .h,.m,$(shell echo $(FIRM_HEADERS)|$(SHELL_TOUPPER)))
43 # How to pass function pointers? Therefore removed.
44 # irgwalk.h typewalk.h
46 # How to pass function pointers? Or how to obtain them?
47 # Irgwalk.m Typewalk.m
49 FIRM_PATH_HEADERS=common/firm.h common/firm_common.h \
50 debug/dbginfo.h ident/ident.h tv/tv.h \
51 tr/type.h tr/entity.h tr/type_or_entity.h tr/tpop.h tr/mangle.h \
52 ir/irprog.h ir/irgraph.h ir/irnode.h ir/irmode.h ir/irop.h \
53 ir/ircons.h ir/ircgcons.h ir/irflag.h ir/irvrfy.h ir/irdump.h \
54 ir/iropt.h ir/irgopt.h ir/ircgopt.h \
55 ana/irouts.h ana/irdom.h ana/irloop.h ana/cgana.h \
56 ir/irgmod.h tr/typegmod.h
57 FIRM_SOURCE_DIR_HEADERS=$(addprefix $(SOURCE_DIR)/,$(FIRM_HEADERS))
59 # The directory containing crecoder.jar and, for now,
60 # remove_cpp_comands.perl
61 FIRM_JNI_TOOLS_DIR=$(top_srcdir)/tools
65 ###############################################################################
69 REMOVE_CPP_COMMANDS=$(FIRM_JNI_TOOLS_DIR)/remove_cpp_comands.perl
70 CRECODER=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar
74 classfiles: $(CLASSFILES)
79 # javah renames these files. the jnibuilder doesn't anticipate this
80 # and generates #includes with the original names.
81 Firm_common.h: Firm_common.class
82 ln -sf Firm_0005fcommon.h Firm_common.h
83 javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
85 Type_or_entity.h: Type_or_entity.class
86 ln -sf Type_0005for_0005fentity.h Type_or_entity.h
87 javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
90 javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
93 gcc $(CPPFLAGS) -c $< -o $@
96 gcc $(CPPFLAGS) -c $(@:.o=.c) -o $@
98 jni: $(HFILES) $(OFILES) # ../libfirm.a
99 gcc -shared -fPIC -o $(LIBNAME) *.o -lfirm -L..
102 cp libfirmjni.so $(libdir)
104 # cp *.java @javadir@
105 # cp *.class @javadir@
108 rm -rf sources *.c *.h *.o
111 rm -f *~ libfirmjni.so *.vcg *.java *.class
118 $(SOURCE_DIR)/firm_typedefs.h: $(FIRM_SOURCE_HEADERS)
119 mv firm_typedefs.h $@
121 ###############################################################################
122 # Get all the necessary Firm headers.
123 ###############################################################################
124 # Remove C preprocessor commands. Overwrite the header files.
125 # This part should be removed if crecoder integrates the preprocessor.
127 FIRM_SRC_HEADER=$(top_srcdir)/ir/$(filter %/$(notdir $@),$(FIRM_PATH_HEADERS))
129 $(FIRM_SOURCE_DIR_HEADERS): $(SOURCE_DIR)
130 troff -a -C -z $(FIRM_SRC_HEADER) >$(SOURCE_DIR)/$(notdir $@)
131 perl $(REMOVE_CPP_COMMANDS) $@
133 $(FIRM_HEADERS):$(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
134 gcc $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$@ -o $@
136 ###############################################################################
137 # Call crecoder to construct from each header a .java file specifying the
138 # java native interface. Further crecoder constructs an implementation of
139 # the java native interface in C calling the real libfirm functions.
140 # For a file "file.h" files "File.java" and "File.c" are generated.
143 H_FROM_JAVA=$(subst .java,.h,$(shell echo $@|$(SHELL_TOLOWER)))
145 %.java: $(FIRM_HEADERS)
146 env CLASSPATH=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar:$$CLASSPATH java crecoder/tools/jniBuilder/BuildJNI $(H_FROM_JAVA);\