init_stat must be empty if statistics is not enabled
[libfirm] / firmjni / Makefile.in
1 #
2 # Project:     libFIRM
3 # File name:   firmjni/Makefile.in
4 # Purpose:
5 # Author:      Till Riedel, Goetz Lindenmaier
6 # Modified by:
7 # Created:     2002
8 # CVS-ID:      $Id$
9 # Copyright:   (c) 2002 Universität Karlsruhe
10 # Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11 #
12
13 top_srcdir := @top_srcdir@
14 srcdir = @srcdir@
15 topdir = ..
16 subdir = firmjni
17
18 enable_heapanal := @enable_heapanalysis@
19
20 # The library implementing the JNI methods.  This name is also
21 # known to the generator for the JNI interface and used in the
22 # static initializer.
23 LIBNAME = libfirmjni.so
24
25 # The name of the package containing the Firm JNI
26 PACKAGENAME = firmjni
27
28 include $(topdir)/MakeRules
29
30 # where to put libfirmjni.so
31 libdir = @libdir@
32 # where to put the directory firmjni containing the generated
33 # .java and .class files
34 #javadir = @javadir@         @@@ how to specify a dir in configure.in?
35
36 .PHONY: default all clean realclean depend
37
38 SHELL_TOUPPER = awk '{for (i=1;i<(NF+1);i=i+1) {printf(toupper(substr($$i,1,1)) substr($$i,2)" ")}}'
39 SHELL_TOLOWER = awk '{for (i=1;i<(NF+1);i=i+1) {printf(tolower(substr($$i,1,1)) substr($$i,2)" ")}}'
40
41 OFILES  = $(MEMBERS:.m=.o)
42 HFILES  = $(MEMBERS:.m=.h)
43 JAVAFILES  = $(MEMBERS:.m=.java)
44 CLASSFILES = $(MEMBERS:.m=.class)
45
46 CPPFLAGS +=     -I$(top_srcdir)/ir/ir  -I$(top_srcdir)/ir/common        \
47                 -I$(top_srcdir)/ir/ident -I$(top_srcdir)/ir/tr          \
48                 -I$(top_srcdir)/ir/tv -I$(top_srcdir)/ir/debug          \
49                 -I$(top_srcdir)/ir/ana -I$(top_srcdir)/ir/opt           \
50                 -I$(top_srcdir)/ir/st -I$(top_srcdir)/ir/stat
51
52 LDFLAGS += -I$(topdir)
53
54 ifeq ($enable_heapanal,yes)
55 LDFLAGS += -L$(libdir) -lfirmlower -labor
56 endif
57
58 FIRM_HEADERS=$(notdir $(FIRM_PATH_HEADERS))
59 MEMBERS=$(subst .h,.m,$(shell echo $(FIRM_HEADERS)|$(SHELL_TOUPPER)))
60 MEMBERS += $(IMPL_MEMBERS)
61
62 # How to pass function pointers? Therefore removed.
63 # irgwalk.h typewalk.h
64
65 # How to pass function pointers? Or how to obtain them?
66 #      Irgwalk.m Typewalk.m
67 #
68 FIRM_PATH_HEADERS=common/firm.h common/firm_common.h \
69         ident/ident.h tv/tv.h \
70         tr/type.h tr/entity.h tr/type_or_entity.h tr/tpop.h tr/mangle.h \
71         tr/type_identify.h                                      \
72         ir/irprog.h ir/irgraph.h ir/irnode.h ir/irmode.h ir/irop.h \
73         ir/ircons.h ir/ircgcons.h ir/irflag.h ir/irvrfy.h ir/irdump.h \
74         ir/iropt.h ir/irgopt.h ir/ircgopt.h \
75         ana/irouts.h ana/irdom.h ana/irloop.h ana/cgana.h \
76         ir/irgmod.h tr/typegmod.h opt/tailrec.h
77
78 FIRM_SOURCE_DIR_HEADERS=$(addprefix $(SOURCE_DIR)/,$(FIRM_HEADERS))
79
80 # hand implemented members
81 IMPL_MEMBERS = Dbginfo.m
82
83 ifeq ($(enable_heapanal),yes)
84 IMPL_MEMBERS += Heapanal.m
85 endif
86
87 # The directory containing crecoder.jar and, for now,
88 # remove_cpp_comands.perl
89 FIRM_JNI_TOOLS_DIR=$(top_srcdir)/tools
90
91 WORK_DIR=.
92
93 ###############################################################################
94
95 SOURCE_DIR=sources
96
97 REMOVE_CPP_COMMANDS=$(FIRM_JNI_TOOLS_DIR)/remove_cpp_comands.perl
98 CRECODER=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar
99
100 all:    classfiles javafiles jni
101
102 classfiles: $(CLASSFILES)
103 javafiles: $(JAVAFILES)
104
105 %.class: %.java
106         javac -classpath .. $<
107
108 # javah renames these files.  the jnibuilder doesn't anticipate this
109 # and generates #includes with the original names.
110 Firm_common.h: Firm_common.class
111         ln -sf Firm_0005fcommon.h Firm_common.h
112         javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
113
114 Type_or_entity.h: Type_or_entity.class
115         ln -sf Type_0005for_0005fentity.h Type_or_entity.h
116         javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
117
118
119 Dbginfo.java:
120         cp $(top_srcdir)/firmjni/aux/Dbginfo.java $(top_srcdir)/firmjni/aux/Dbginfo.c .
121
122 Heapanal.java:
123         cp $(top_srcdir)/firmjni/aux/Heapanal.java $(top_srcdir)/firmjni/aux/Heapanal.c .
124
125 %.h:    %.class
126         javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
127
128 %.o:    %.c %.h
129         gcc $(CPPFLAGS) -c $< -o $@
130
131 $(OFILES):
132         gcc $(CPPFLAGS) -c $(@:.o=.c) -o $@
133
134
135 ifeq ($(enable_heapanal),yes)
136 HEAPANALLIB = -lheapanal
137 else
138 HEAPANALLIB =
139 endif
140
141 # We need firmlower and abor for heap analysis stuff, wich is called from aux/Heapanal.java
142 # BY the way, what is sw/lib/  can this be removed???
143 jni:    $(HFILES) $(OFILES)  # ../libfirm.a
144         gcc -shared -fPIC -o $(LIBNAME) *.o -lfirm -lxml2 -L.. $(HEAPANALLIB) $(LDFLAGS) -liberty -L../../sw/lib
145 install:
146         cp libfirmjni.so $(libdir)
147 #       mkdir $(javadir)
148 #       cp *.java @javadir@
149 #       cp *.class @javadir@
150
151
152 test:   jni
153         $(MAKE) -C testprograms test
154
155 clean:
156         rm -rf sources *.c *.h *.o
157
158 realclean: clean
159         rm -f *~ libfirmjni.so *.vcg *.java *.class
160
161
162 $(SOURCE_DIR):
163         rm -rf $(SOURCE_DIR)
164         mkdir $(SOURCE_DIR)
165
166 $(SOURCE_DIR)/firm_typedefs.h: $(FIRM_SOURCE_HEADERS)
167         mv firm_typedefs.h $@
168
169 ###############################################################################
170 # Get all the necessary Firm headers.
171 ###############################################################################
172 # Remove C preprocessor commands.  Overwrite the header files.
173 # This part should be removed if crecoder integrates the preprocessor.
174
175 FIRM_SRC_HEADER=$(top_srcdir)/ir/$(filter %/$(notdir $@),$(FIRM_PATH_HEADERS))
176
177
178 # recode: remove "a from C code...
179 $(FIRM_SOURCE_DIR_HEADERS): $(SOURCE_DIR)
180         recode ISO-8859-1..ascii < $(FIRM_SRC_HEADER) > $(SOURCE_DIR)/$(notdir $@)
181         perl $(REMOVE_CPP_COMMANDS) $@
182
183 #       cp $(FIRM_SRC_HEADER) $(SOURCE_DIR)/$(notdir $@)
184 #       recode ISO-8859-1..ascii < $@ > $@.x
185 #       cp $@.x $@
186
187 # generiert leere dateien ;-(
188 #       troff -a -C -z  $(FIRM_SRC_HEADER) > $(SOURCE_DIR)/$(notdir $@)
189
190 $(FIRM_HEADERS):$(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
191         gcc $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$@ -o $@
192
193 ###############################################################################
194 # Call crecoder to construct from each header a .java file specifying the
195 # java native interface.  Further crecoder constructs an implementation of
196 # the java native interface in C calling the real libfirm functions.
197 # For a file "file.h" files "File.java" and "File.c" are generated.
198
199
200 H_FROM_JAVA=$(subst .java,.h,$(shell echo $@|$(SHELL_TOLOWER)))
201
202 %.java: $(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
203         gcc $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$(H_FROM_JAVA) -o $(H_FROM_JAVA)
204         env CLASSPATH=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar:$$CLASSPATH java crecoder/tools/jniBuilder/BuildJNI $(H_FROM_JAVA);\
205         rm $(H_FROM_JAVA);
206 # remove the patched header so that further compilation finds the proper firm headers