more asserts
[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/st
50
51 LDFLAGS += -I$(topdir)
52
53 FIRM_HEADERS=$(notdir $(FIRM_PATH_HEADERS))
54 MEMBERS=$(subst .h,.m,$(shell echo $(FIRM_HEADERS)|$(SHELL_TOUPPER)))
55 MEMBERS += $(IMPL_MEMBERS)
56
57 # How to pass function pointers? Therefore removed.
58 # irgwalk.h typewalk.h
59
60 # How to pass function pointers? Or how to obtain them?
61 #      Irgwalk.m Typewalk.m
62 #
63 FIRM_PATH_HEADERS=common/firm.h common/firm_common.h \
64         ident/ident.h tv/tv.h \
65         tr/type.h tr/entity.h tr/type_or_entity.h tr/tpop.h tr/mangle.h \
66         ir/irprog.h ir/irgraph.h ir/irnode.h ir/irmode.h ir/irop.h \
67         ir/ircons.h ir/ircgcons.h ir/irflag.h ir/irvrfy.h ir/irdump.h \
68         ir/iropt.h ir/irgopt.h ir/ircgopt.h \
69         ana/irouts.h ana/irdom.h ana/irloop.h ana/cgana.h \
70         ir/irgmod.h tr/typegmod.h
71
72 FIRM_SOURCE_DIR_HEADERS=$(addprefix $(SOURCE_DIR)/,$(FIRM_HEADERS))
73
74 # hand implemented members
75 IMPL_MEMBERS = Dbginfo.m
76
77 ifeq ($(enable_heapanal),yes)
78 IMPL_MEMBERS += Heapanal.m
79 endif
80
81 # The directory containing crecoder.jar and, for now,
82 # remove_cpp_comands.perl
83 FIRM_JNI_TOOLS_DIR=$(top_srcdir)/tools
84
85 WORK_DIR=.
86
87 ###############################################################################
88
89 SOURCE_DIR=sources
90
91 REMOVE_CPP_COMMANDS=$(FIRM_JNI_TOOLS_DIR)/remove_cpp_comands.perl
92 CRECODER=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar
93
94 all:    classfiles javafiles jni
95
96 classfiles: $(CLASSFILES)
97 javafiles: $(JAVAFILES)
98
99 %.class: %.java
100         javac -classpath .. $<
101
102 # javah renames these files.  the jnibuilder doesn't anticipate this
103 # and generates #includes with the original names.
104 Firm_common.h: Firm_common.class
105         ln -sf Firm_0005fcommon.h Firm_common.h
106         javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
107
108 Type_or_entity.h: Type_or_entity.class
109         ln -sf Type_0005for_0005fentity.h Type_or_entity.h
110         javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
111
112
113 Dbginfo.java:
114         cp $(top_srcdir)/firmjni/aux/Dbginfo.java $(top_srcdir)/firmjni/aux/Dbginfo.c .
115
116 Heapanal.java:
117         cp $(top_srcdir)/firmjni/aux/Heapanal.java $(top_srcdir)/firmjni/aux/Heapanal.c .
118
119 %.h:    %.class
120         javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
121
122 %.o:    %.c %.h
123         gcc $(CPPFLAGS) -c $< -o $@
124
125 $(OFILES):
126         gcc $(CPPFLAGS) -c $(@:.o=.c) -o $@
127
128
129 ifeq ($(enable_heapanal),yes)
130 HEAPANALLIB = -lheapanal
131 else
132 HEAPANALLIB =
133 endif
134
135
136 jni:    $(HFILES) $(OFILES)  # ../libfirm.a
137         gcc -shared -fPIC -o $(LIBNAME) *.o -lfirm -L.. $(HEAPANALLIB) $(LDFLAGS) -liberty -L../../sw/lib
138
139 install:
140         cp libfirmjni.so $(libdir)
141 #       mkdir $(javadir)
142 #       cp *.java @javadir@
143 #       cp *.class @javadir@
144
145
146 test:   jni
147         $(MAKE) -C testprograms test
148
149 clean:
150         rm -rf sources *.c *.h *.o
151
152 realclean: clean
153         rm -f *~ libfirmjni.so *.vcg *.java *.class
154
155
156 $(SOURCE_DIR):
157         rm -rf $(SOURCE_DIR)
158         mkdir $(SOURCE_DIR)
159
160 $(SOURCE_DIR)/firm_typedefs.h: $(FIRM_SOURCE_HEADERS)
161         mv firm_typedefs.h $@
162
163 ###############################################################################
164 # Get all the necessary Firm headers.
165 ###############################################################################
166 # Remove C preprocessor commands.  Overwrite the header files.
167 # This part should be removed if crecoder integrates the preprocessor.
168
169 FIRM_SRC_HEADER=$(top_srcdir)/ir/$(filter %/$(notdir $@),$(FIRM_PATH_HEADERS))
170
171
172 # recode: remove "a from C code...
173 $(FIRM_SOURCE_DIR_HEADERS): $(SOURCE_DIR)
174         recode ISO-8859-1..ascii < $(FIRM_SRC_HEADER) > $(SOURCE_DIR)/$(notdir $@)
175         perl $(REMOVE_CPP_COMMANDS) $@
176
177 #       cp $(FIRM_SRC_HEADER) $(SOURCE_DIR)/$(notdir $@)
178 #       recode ISO-8859-1..ascii < $@ > $@.x
179 #       cp $@.x $@
180
181 # generiert leere dateien ;-(
182 #       troff -a -C -z  $(FIRM_SRC_HEADER) > $(SOURCE_DIR)/$(notdir $@)
183
184 $(FIRM_HEADERS):$(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
185         gcc $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$@ -o $@
186
187 ###############################################################################
188 # Call crecoder to construct from each header a .java file specifying the
189 # java native interface.  Further crecoder constructs an implementation of
190 # the java native interface in C calling the real libfirm functions.
191 # For a file "file.h" files "File.java" and "File.c" are generated.
192
193
194 H_FROM_JAVA=$(subst .java,.h,$(shell echo $@|$(SHELL_TOLOWER)))
195
196 %.java: $(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
197         gcc $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$(H_FROM_JAVA) -o $(H_FROM_JAVA)
198         env CLASSPATH=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar:$$CLASSPATH java crecoder/tools/jniBuilder/BuildJNI $(H_FROM_JAVA);\
199         rm $(H_FROM_JAVA);
200 # remove the patched header so that further compilation finds the proper firm headers