3 # File name: firmjni/Makefile.in
5 # Author: Till Riedel, Goetz Lindenmaier
9 # Copyright: (c) 2002 Universität Karlsruhe
10 # Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
13 top_srcdir := @top_srcdir@
18 # The library implementing the JNI methods. This name is also
19 # known to the generator for the JNI interface and used in the
21 LIBNAME = libfirmjni.so
23 # The name of the package containing the Firm JNI
26 # where to put libfirmjni.so
28 # where to put the directory firmjni containing the generated
29 # .java and .class files
30 #javadir = @javadir@ @@@ how to specify a dir in configure.in?
32 .PHONY: default all clean realclean depend
34 SHELL_TOUPPER = awk '{for (i=1;i<(NF+1);i=i+1) {printf(toupper(substr($$i,1,1)) substr($$i,2)" ")}}'
35 SHELL_TOLOWER = awk '{for (i=1;i<(NF+1);i=i+1) {printf(tolower(substr($$i,1,1)) substr($$i,2)" ")}}'
37 OFILES = $(MEMBERS:.m=.o)
38 HFILES = $(MEMBERS:.m=.h)
39 JAVAFILES = $(MEMBERS:.m=.java)
40 CLASSFILES = $(MEMBERS:.m=.class)
42 CPPFLAGS = -I$(top_srcdir)/ir/ir -I$(top_srcdir)/ir/common \
43 -I$(top_srcdir)/ir/ident -I$(top_srcdir)/ir/tr \
44 -I$(top_srcdir)/ir/tv -I$(top_srcdir)/ir/debug \
45 -I$(top_srcdir)/ir/ana -I$(top_srcdir)/ir/st @CPPFLAGS@
49 FIRM_HEADERS=$(notdir $(FIRM_PATH_HEADERS))
50 MEMBERS=$(subst .h,.m,$(shell echo $(FIRM_HEADERS)|$(SHELL_TOUPPER)))
51 MEMBERS += $(IMPL_MEMBERS)
53 # How to pass function pointers? Therefore removed.
54 # irgwalk.h typewalk.h
56 # How to pass function pointers? Or how to obtain them?
57 # Irgwalk.m Typewalk.m
59 FIRM_PATH_HEADERS=common/firm.h common/firm_common.h \
60 ident/ident.h tv/tv.h \
61 tr/type.h tr/entity.h tr/type_or_entity.h tr/tpop.h tr/mangle.h \
62 ir/irprog.h ir/irgraph.h ir/irnode.h ir/irmode.h ir/irop.h \
63 ir/ircons.h ir/ircgcons.h ir/irflag.h ir/irvrfy.h ir/irdump.h \
64 ir/iropt.h ir/irgopt.h ir/ircgopt.h \
65 ana/irouts.h ana/irdom.h ana/irloop.h ana/cgana.h \
66 ir/irgmod.h tr/typegmod.h
67 FIRM_SOURCE_DIR_HEADERS=$(addprefix $(SOURCE_DIR)/,$(FIRM_HEADERS))
69 # hand implemented members
70 IMPL_MEMBERS = Dbginfo.m
72 # The directory containing crecoder.jar and, for now,
73 # remove_cpp_comands.perl
74 FIRM_JNI_TOOLS_DIR=$(top_srcdir)/tools
78 ###############################################################################
82 REMOVE_CPP_COMMANDS=$(FIRM_JNI_TOOLS_DIR)/remove_cpp_comands.perl
83 CRECODER=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar
85 all: classfiles javafiles jni
87 classfiles: $(CLASSFILES)
88 javafiles: $(JAVAFILES)
91 javac -classpath .. $<
93 # javah renames these files. the jnibuilder doesn't anticipate this
94 # and generates #includes with the original names.
95 Firm_common.h: Firm_common.class
96 ln -sf Firm_0005fcommon.h Firm_common.h
97 javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
99 Type_or_entity.h: Type_or_entity.class
100 ln -sf Type_0005for_0005fentity.h Type_or_entity.h
101 javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
105 cp $(srcdir)/Dbginfo.java .
106 cp $(srcdir)/Dbginfo.c .
110 javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
113 gcc $(CPPFLAGS) -c $< -o $@
116 gcc $(CPPFLAGS) -c $(@:.o=.c) -o $@
118 jni: $(HFILES) $(OFILES) # ../libfirm.a
119 gcc -shared -fPIC -o $(LIBNAME) *.o -lfirm -L..
122 cp libfirmjni.so $(libdir)
124 # cp *.java @javadir@
125 # cp *.class @javadir@
129 $(MAKE) -C testprograms test
132 rm -rf sources *.c *.h *.o
135 rm -f *~ libfirmjni.so *.vcg *.java *.class
142 $(SOURCE_DIR)/firm_typedefs.h: $(FIRM_SOURCE_HEADERS)
143 mv firm_typedefs.h $@
145 ###############################################################################
146 # Get all the necessary Firm headers.
147 ###############################################################################
148 # Remove C preprocessor commands. Overwrite the header files.
149 # This part should be removed if crecoder integrates the preprocessor.
151 FIRM_SRC_HEADER=$(top_srcdir)/ir/$(filter %/$(notdir $@),$(FIRM_PATH_HEADERS))
153 $(FIRM_SOURCE_DIR_HEADERS): $(SOURCE_DIR)
154 cp $(FIRM_SRC_HEADER) $(SOURCE_DIR)/$(notdir $@)
155 perl $(REMOVE_CPP_COMMANDS) $@
157 # generiert leere dateien ;-(
158 # troff -a -C -z $(FIRM_SRC_HEADER) > $(SOURCE_DIR)/$(notdir $@)
160 $(FIRM_HEADERS):$(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
161 gcc $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$@ -o $@
163 ###############################################################################
164 # Call crecoder to construct from each header a .java file specifying the
165 # java native interface. Further crecoder constructs an implementation of
166 # the java native interface in C calling the real libfirm functions.
167 # For a file "file.h" files "File.java" and "File.c" are generated.
170 H_FROM_JAVA=$(subst .java,.h,$(shell echo $@|$(SHELL_TOLOWER)))
172 %.java: $(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
173 gcc $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$(H_FROM_JAVA) -o $(H_FROM_JAVA)
174 env CLASSPATH=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar:$$CLASSPATH java crecoder/tools/jniBuilder/BuildJNI $(H_FROM_JAVA);\
176 # remove the patched header so that further compilation finds the proper firm headers