Added automatic test procedure to firmjni.
[libfirm] / firmjni / Makefile.in
1
2 # $Id$
3
4 top_srcdir := @top_srcdir@
5 srcdir = @srcdir@
6 topdir = ..
7 subdir = firmjni
8
9 # The library implementing the JNI methods.  This name is also
10 # known to the generator for the JNI interface and used in the
11 # static initializer.
12 LIBNAME = libfirmjni.so
13
14 # The name of the package containing the Firm JNI
15 PACKAGENAME = firmjni
16
17 # where to put libfirmjni.so
18 libdir = @libdir@
19 # where to put the directory firmjni containing the generated
20 # .java and .class files
21 #javadir = @javadir@         @@@ how to specify a dir in configure.in?
22
23 .PHONY: default all clean realclean depend
24
25 SHELL_TOUPPER = awk '{for (i=1;i<(NF+1);i=i+1) {printf(toupper(substr($$i,1,1)) substr($$i,2)" ")}}'
26 SHELL_TOLOWER = awk '{for (i=1;i<(NF+1);i=i+1) {printf(tolower(substr($$i,1,1)) substr($$i,2)" ")}}'
27
28 OFILES  = $(MEMBERS:.m=.o)
29 HFILES  = $(MEMBERS:.m=.h)
30 JAVAFILES  = $(MEMBERS:.m=.java)
31 CLASSFILES = $(MEMBERS:.m=.class)
32
33 CPPFLAGS =      -I$(top_srcdir)/ir/ir  -I$(top_srcdir)/ir/common        \
34                 -I$(top_srcdir)/ir/ident -I$(top_srcdir)/ir/tr          \
35                 -I$(top_srcdir)/ir/tv -I$(top_srcdir)/ir/debug          \
36                 -I$(top_srcdir)/ir/ana -I$(top_srcdir)/ir/st @CPPFLAGS@
37
38 LDFLAGS += $(topdir)
39
40 FIRM_HEADERS=$(notdir $(FIRM_PATH_HEADERS))
41 MEMBERS=$(subst .h,.m,$(shell echo $(FIRM_HEADERS)|$(SHELL_TOUPPER)))
42 MEMBERS += $(IMPL_MEMBERS)
43
44 # How to pass function pointers? Therefore removed.
45 # irgwalk.h typewalk.h
46
47 # How to pass function pointers? Or how to obtain them?
48 #      Irgwalk.m Typewalk.m
49 #
50 FIRM_PATH_HEADERS=common/firm.h common/firm_common.h \
51         ident/ident.h tv/tv.h \
52         tr/type.h tr/entity.h tr/type_or_entity.h tr/tpop.h tr/mangle.h \
53         ir/irprog.h ir/irgraph.h ir/irnode.h ir/irmode.h ir/irop.h \
54         ir/ircons.h ir/ircgcons.h ir/irflag.h ir/irvrfy.h ir/irdump.h \
55         ir/iropt.h ir/irgopt.h ir/ircgopt.h \
56         ana/irouts.h ana/irdom.h ana/irloop.h ana/cgana.h \
57         ir/irgmod.h tr/typegmod.h
58 FIRM_SOURCE_DIR_HEADERS=$(addprefix $(SOURCE_DIR)/,$(FIRM_HEADERS))
59
60 # hand implemented members
61 IMPL_MEMBERS = Dbginfo.m
62
63 # The directory containing crecoder.jar and, for now,
64 # remove_cpp_comands.perl
65 FIRM_JNI_TOOLS_DIR=$(top_srcdir)/tools
66
67 WORK_DIR=.
68
69 ###############################################################################
70
71 SOURCE_DIR=sources
72
73 REMOVE_CPP_COMMANDS=$(FIRM_JNI_TOOLS_DIR)/remove_cpp_comands.perl
74 CRECODER=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar
75
76 all:    classfiles javafiles jni
77
78 classfiles: $(CLASSFILES)
79 javafiles: $(JAVAFILES)
80
81 %.class: %.java
82         javac -classpath .. $<
83
84 # javah renames these files.  the jnibuilder doesn't anticipate this
85 # and generates #includes with the original names.
86 Firm_common.h: Firm_common.class
87         ln -sf Firm_0005fcommon.h Firm_common.h
88         javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
89
90 Type_or_entity.h: Type_or_entity.class
91         ln -sf Type_0005for_0005fentity.h Type_or_entity.h
92         javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
93
94
95 Dbginfo.java:
96         cp $(srcdir)/Dbginfo.java .
97         cp $(srcdir)/Dbginfo.c .
98
99
100 %.h:    %.class
101         javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
102
103 %.o:    %.c %.h
104         gcc $(CPPFLAGS) -c $< -o $@
105
106 $(OFILES):
107         gcc $(CPPFLAGS) -c $(@:.o=.c) -o $@
108
109 jni:    $(HFILES) $(OFILES)  # ../libfirm.a
110         gcc -shared -fPIC -o $(LIBNAME) *.o -lfirm -L..
111
112 install:
113         cp libfirmjni.so $(libdir)
114 #       mkdir $(javadir)
115 #       cp *.java @javadir@
116 #       cp *.class @javadir@
117
118
119 test:   jni
120         $(MAKE) -C testprograms test
121
122 clean:
123         rm -rf sources *.c *.h *.o
124
125 realclean: clean
126         rm -f *~ libfirmjni.so *.vcg *.java *.class
127
128
129 $(SOURCE_DIR):
130         rm -rf $(SOURCE_DIR)
131         mkdir $(SOURCE_DIR)
132
133 $(SOURCE_DIR)/firm_typedefs.h: $(FIRM_SOURCE_HEADERS)
134         mv firm_typedefs.h $@
135
136 ###############################################################################
137 # Get all the necessary Firm headers.
138 ###############################################################################
139 # Remove C preprocessor commands.  Overwrite the header files.
140 # This part should be removed if crecoder integrates the preprocessor.
141
142 FIRM_SRC_HEADER=$(top_srcdir)/ir/$(filter %/$(notdir $@),$(FIRM_PATH_HEADERS))
143
144 $(FIRM_SOURCE_DIR_HEADERS): $(SOURCE_DIR)
145         cp $(FIRM_SRC_HEADER) $(SOURCE_DIR)/$(notdir $@)
146         perl $(REMOVE_CPP_COMMANDS) $@
147
148 # generiert leere dateien ;-(
149 #       troff -a -C -z  $(FIRM_SRC_HEADER) > $(SOURCE_DIR)/$(notdir $@)
150
151 $(FIRM_HEADERS):$(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
152         gcc $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$@ -o $@
153
154 ###############################################################################
155 # Call crecoder to construct from each header a .java file specifying the
156 # java native interface.  Further crecoder constructs an implementation of
157 # the java native interface in C calling the real libfirm functions.
158 # For a file "file.h" files "File.java" and "File.c" are generated.
159
160
161 H_FROM_JAVA=$(subst .java,.h,$(shell echo $@|$(SHELL_TOLOWER)))
162
163 %.java: $(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
164         gcc $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$(H_FROM_JAVA) -o $(H_FROM_JAVA)
165         env CLASSPATH=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar:$$CLASSPATH java crecoder/tools/jniBuilder/BuildJNI $(H_FROM_JAVA);\
166         rm $(H_FROM_JAVA);
167 # remove the patched header so that further compilation finds the proper firm headers