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