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