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 JAVAFILES = $(MEMBERS:.m=.java)
31 CLASSFILES = $(MEMBERS:.m=.class)
33 CPPFLAGS = -I$(top_srcdir)/ir/ir -I$(top_srcdir)/ir/common \
34 -I$(top_srcdir)/ir/ident -I$(top_srcdir)/ir/tr \
35 -I$(top_srcdir)/ir/tv -I$(top_srcdir)/ir/debug \
36 -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)))
42 MEMBERS += $(IMPL_MEMBERS)
44 # How to pass function pointers? Therefore removed.
45 # irgwalk.h typewalk.h
47 # How to pass function pointers? Or how to obtain them?
48 # Irgwalk.m Typewalk.m
50 FIRM_PATH_HEADERS=common/firm.h common/firm_common.h \
51 ident/ident.h tv/tv.h \
52 tr/type.h tr/entity.h tr/type_or_entity.h tr/tpop.h tr/mangle.h \
53 ir/irprog.h ir/irgraph.h ir/irnode.h ir/irmode.h ir/irop.h \
54 ir/ircons.h ir/ircgcons.h ir/irflag.h ir/irvrfy.h ir/irdump.h \
55 ir/iropt.h ir/irgopt.h ir/ircgopt.h \
56 ana/irouts.h ana/irdom.h ana/irloop.h ana/cgana.h \
57 ir/irgmod.h tr/typegmod.h
58 FIRM_SOURCE_DIR_HEADERS=$(addprefix $(SOURCE_DIR)/,$(FIRM_HEADERS))
60 # hand implemented members
61 IMPL_MEMBERS = Dbginfo.m
63 # The directory containing crecoder.jar and, for now,
64 # remove_cpp_comands.perl
65 FIRM_JNI_TOOLS_DIR=$(top_srcdir)/tools
69 ###############################################################################
73 REMOVE_CPP_COMMANDS=$(FIRM_JNI_TOOLS_DIR)/remove_cpp_comands.perl
74 CRECODER=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar
76 all: classfiles javafiles jni
78 classfiles: $(CLASSFILES)
79 javafiles: $(JAVAFILES)
82 javac -classpath .. $<
84 # javah renames these files. the jnibuilder doesn't anticipate this
85 # and generates #includes with the original names.
86 Firm_common.h: Firm_common.class
87 ln -sf Firm_0005fcommon.h Firm_common.h
88 javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
90 Type_or_entity.h: Type_or_entity.class
91 ln -sf Type_0005for_0005fentity.h Type_or_entity.h
92 javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
96 cp $(srcdir)/Dbginfo.java .
97 cp $(srcdir)/Dbginfo.c .
101 javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
104 gcc $(CPPFLAGS) -c $< -o $@
107 gcc $(CPPFLAGS) -c $(@:.o=.c) -o $@
109 jni: $(HFILES) $(OFILES) # ../libfirm.a
110 gcc -shared -fPIC -o $(LIBNAME) *.o -lfirm -L..
113 cp libfirmjni.so $(libdir)
115 # cp *.java @javadir@
116 # cp *.class @javadir@
120 $(MAKE) -C testprograms test
123 rm -rf sources *.c *.h *.o
126 rm -f *~ libfirmjni.so *.vcg *.java *.class
133 $(SOURCE_DIR)/firm_typedefs.h: $(FIRM_SOURCE_HEADERS)
134 mv firm_typedefs.h $@
136 ###############################################################################
137 # Get all the necessary Firm headers.
138 ###############################################################################
139 # Remove C preprocessor commands. Overwrite the header files.
140 # This part should be removed if crecoder integrates the preprocessor.
142 FIRM_SRC_HEADER=$(top_srcdir)/ir/$(filter %/$(notdir $@),$(FIRM_PATH_HEADERS))
144 $(FIRM_SOURCE_DIR_HEADERS): $(SOURCE_DIR)
145 cp $(FIRM_SRC_HEADER) $(SOURCE_DIR)/$(notdir $@)
146 perl $(REMOVE_CPP_COMMANDS) $@
148 # generiert leere dateien ;-(
149 # troff -a -C -z $(FIRM_SRC_HEADER) > $(SOURCE_DIR)/$(notdir $@)
151 $(FIRM_HEADERS):$(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
152 gcc $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$@ -o $@
154 ###############################################################################
155 # Call crecoder to construct from each header a .java file specifying the
156 # java native interface. Further crecoder constructs an implementation of
157 # the java native interface in C calling the real libfirm functions.
158 # For a file "file.h" files "File.java" and "File.c" are generated.
161 H_FROM_JAVA=$(subst .java,.h,$(shell echo $@|$(SHELL_TOLOWER)))
163 %.java: $(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
164 gcc $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$(H_FROM_JAVA) -o $(H_FROM_JAVA)
165 env CLASSPATH=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar:$$CLASSPATH java crecoder/tools/jniBuilder/BuildJNI $(H_FROM_JAVA);\
167 # remove the patched header so that further compilation finds the proper firm headers