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 enable_heapanal := @enable_heapanalysis@
19 enable_libcore := @enable_libcore@
20 enable_external_effects := @enable_external_effects@
21 disable_libiberty := @disable_libiberty@
23 # The library implementing the JNI methods. This name is also
24 # known to the generator for the JNI interface and used in the
26 LIBNAME = libfirmjni.so
28 # The name of the package containing the Firm JNI
31 include $(topdir)/MakeRules
33 # where to put libfirmjni.so
35 # where to put the directory firmjni containing the generated
36 # .java and .class files
37 #javadir = @javadir@ @@@ how to specify a dir in configure.in?
39 .PHONY: default all clean realclean depend
41 SHELL_TOUPPER = awk '{for (i=1;i<(NF+1);i=i+1) {printf(toupper(substr($$i,1,1)) substr($$i,2)" ")}}'
42 SHELL_TOLOWER = awk '{for (i=1;i<(NF+1);i=i+1) {printf(tolower(substr($$i,1,1)) substr($$i,2)" ")}}'
44 OFILES = $(MEMBERS:.m=.o)
45 HFILES = $(MEMBERS:.m=.h)
46 JAVAFILES = $(MEMBERS:.m=.java)
47 CLASSFILES = $(MEMBERS:.m=.class)
49 CPPFLAGS += -I$(top_srcdir)/ir/ir -I$(top_srcdir)/ir/common \
50 -I$(top_srcdir)/ir/ident -I$(top_srcdir)/ir/tr \
51 -I$(top_srcdir)/ir/tv -I$(top_srcdir)/ir/debug \
52 -I$(top_srcdir)/ir/ana -I$(top_srcdir)/ir/opt \
53 -I$(top_srcdir)/ir/st -I$(top_srcdir)/ir/stat \
54 -I$(top_srcdir)/ir/arch -I$(top_srcdir)/ir/lower \
55 -I$(topdir)/ir/config \
58 LDFLAGS += -L$(libdir)
60 ifeq ($(enable_heapanal),yes)
61 LDFLAGS += -lfirmlower -labor -lheapanal
64 ifeq ($(enable_libcore),yes)
68 ifeq ($(enable_external_effects),yes)
72 ifeq ($(disable_libiberty),yes)
77 FIRM_HEADERS=$(notdir $(FIRM_PATH_HEADERS))
78 MEMBERS=$(subst .h,.m,$(shell echo $(FIRM_HEADERS)|$(SHELL_TOUPPER)))
79 MEMBERS += $(IMPL_MEMBERS)
81 # How to pass function pointers? Therefore removed.
82 # irgwalk.h typewalk.h firmwalk.h
84 # How to pass function pointers? Or how to obtain them?
85 # Irgwalk.m Typewalk.m
88 # common/debug.h requieres libcore
89 # ir/irprintf.h crecoder cannot handle va_list
93 common/firm_common.h \
107 ana/interval_analysis.h \
108 ana/field_temperature.h \
109 ana/execution_frequency.h \
111 ana/irconsconfirm.h \
112 ana/analyze_irg_args.h \
138 opt/loop_unrolling.h \
140 opt/opt_polymorphy.h \
144 opt/scalar_replace.h \
155 tr/type_or_entity.h \
158 tr/tr_inheritance.h \
164 lower/lower_intrinsics.h \
165 lower/lower_calls.h \
168 FIRM_SOURCE_DIR_HEADERS=$(addprefix $(SOURCE_DIR)/,$(FIRM_HEADERS))
170 # hand implemented members
171 IMPL_MEMBERS = Dbginfo.m
173 ifeq ($(enable_heapanal),yes)
174 IMPL_MEMBERS += Heapanal.m
177 # The directory containing crecoder.jar and, for now,
178 # remove_cpp_comands.perl
179 FIRM_JNI_TOOLS_DIR=$(top_srcdir)/tools
183 ###############################################################################
187 REMOVE_CPP_COMMANDS=$(FIRM_JNI_TOOLS_DIR)/remove_cpp_comands.perl
188 CRECODER=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar
190 all: classfiles javafiles jni
192 classfiles: $(CLASSFILES)
193 javafiles: $(JAVAFILES)
196 javac -classpath .. $<
198 # javah renames these files. the jnibuilder doesn't anticipate this
199 # and generates #includes with the original names.
200 Firm_common.h: Firm_common.class
201 ln -sf Firm_0005fcommon.h Firm_common.h
202 javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
204 Type_or_entity.h: Type_or_entity.class
205 ln -sf Type_0005for_0005fentity.h Type_or_entity.h
206 javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
210 cp $(top_srcdir)/firmjni/auxilliary/Dbginfo.java $(top_srcdir)/firmjni/auxilliary/Dbginfo.c .
213 cp $(top_srcdir)/firmjni/auxilliary/Heapanal.java $(top_srcdir)/firmjni/auxilliary/Heapanal.c .
216 javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
219 $(CC) $(CPPFLAGS) -c $< -o $@
222 $(CC) $(CPPFLAGS) -c $(@:.o=.c) -o $@
225 # We need firmlower and abor for heap analysis stuff, which is called from auxilliary/Heapanal.java
226 # BY the way, what is ../../sw/lib/ can this be removed? Probaly, so I did.
227 jni: $(HFILES) $(OFILES) # ../libfirm.a
228 $(CC) -shared -fPIC -o $(LIBNAME) *.o -lfirm -L.. $(LDFLAGS)
230 cp libfirmjni.so $(libdir)
232 # cp *.java @javadir@
233 # cp *.class @javadir@
237 $(MAKE) -C testprograms test
240 rm -rf sources *.c *.h *.o
243 rm -f *~ libfirmjni.so *.vcg *.java *.class
250 $(SOURCE_DIR)/firm_typedefs.h: $(FIRM_SOURCE_HEADERS)
251 mv firm_typedefs.h $@
253 ###############################################################################
254 # Get all the necessary Firm headers.
255 ###############################################################################
256 # Remove C preprocessor commands. Overwrite the header files.
257 # This part should be removed if crecoder integrates the preprocessor.
259 FIRM_SRC_HEADER=$(top_srcdir)/ir/$(filter %/$(notdir $@),$(FIRM_PATH_HEADERS))
262 # recode: remove "a from C code...
263 $(FIRM_SOURCE_DIR_HEADERS): $(SOURCE_DIR)
264 recode ISO-8859-1..ascii < $(FIRM_SRC_HEADER) > $(SOURCE_DIR)/$(notdir $@)
265 perl $(REMOVE_CPP_COMMANDS) $@
267 # cp $(FIRM_SRC_HEADER) $(SOURCE_DIR)/$(notdir $@)
268 # recode ISO-8859-1..ascii < $@ > $@.x
271 # generiert leere dateien ;-(
272 # troff -a -C -z $(FIRM_SRC_HEADER) > $(SOURCE_DIR)/$(notdir $@)
274 $(FIRM_HEADERS):$(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
275 $(CC) $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$@ -o $@
277 ###############################################################################
278 # Call crecoder to construct from each header a .java file specifying the
279 # java native interface. Further crecoder constructs an implementation of
280 # the java native interface in C calling the real libfirm functions.
281 # For a file "file.h" files "File.java" and "File.c" are generated.
284 H_FROM_JAVA=$(subst .java,.h,$(shell echo $@|$(SHELL_TOLOWER)))
286 %.java: $(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
287 $(CC) $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$(H_FROM_JAVA) -o $(H_FROM_JAVA)
288 env CLASSPATH=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar:$$CLASSPATH java crecoder/tools/jniBuilder/BuildJNI $(H_FROM_JAVA) ;\
290 # remove the patched header so that further compilation finds the proper firm headers