Added .cvsignore
[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 # The library implementing the JNI methods.  This name is also
19 # known to the generator for the JNI interface and used in the
20 # static initializer.
21 LIBNAME = libfirmjni.so
22
23 # The name of the package containing the Firm JNI
24 PACKAGENAME = firmjni
25
26 # where to put libfirmjni.so
27 libdir = @libdir@
28 # where to put the directory firmjni containing the generated
29 # .java and .class files
30 #javadir = @javadir@         @@@ how to specify a dir in configure.in?
31
32 .PHONY: default all clean realclean depend
33
34 SHELL_TOUPPER = awk '{for (i=1;i<(NF+1);i=i+1) {printf(toupper(substr($$i,1,1)) substr($$i,2)" ")}}'
35 SHELL_TOLOWER = awk '{for (i=1;i<(NF+1);i=i+1) {printf(tolower(substr($$i,1,1)) substr($$i,2)" ")}}'
36
37 OFILES  = $(MEMBERS:.m=.o)
38 HFILES  = $(MEMBERS:.m=.h)
39 JAVAFILES  = $(MEMBERS:.m=.java)
40 CLASSFILES = $(MEMBERS:.m=.class)
41
42 CPPFLAGS =      -I$(top_srcdir)/ir/ir  -I$(top_srcdir)/ir/common        \
43                 -I$(top_srcdir)/ir/ident -I$(top_srcdir)/ir/tr          \
44                 -I$(top_srcdir)/ir/tv -I$(top_srcdir)/ir/debug          \
45                 -I$(top_srcdir)/ir/ana -I$(top_srcdir)/ir/st \
46                         -I$(top_srcdir)/../opt/heapanal \
47                         -I$(top_srcdir)/include \
48                         -I/usr/local/jdk1.3.1/include \
49                         -I/usr/local/jdk1.3.1/include/freebsd @CPPFLAGS@
50
51 LDFLAGS += $(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 FIRM_SOURCE_DIR_HEADERS=$(addprefix $(SOURCE_DIR)/,$(FIRM_HEADERS))
72
73 # hand implemented members
74 IMPL_MEMBERS = Dbginfo.m Heapanal.m
75
76 # The directory containing crecoder.jar and, for now,
77 # remove_cpp_comands.perl
78 FIRM_JNI_TOOLS_DIR=$(top_srcdir)/tools
79
80 WORK_DIR=.
81
82 ###############################################################################
83
84 SOURCE_DIR=sources
85
86 REMOVE_CPP_COMMANDS=$(FIRM_JNI_TOOLS_DIR)/remove_cpp_comands.perl
87 CRECODER=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar
88
89 all:    classfiles javafiles jni
90
91 classfiles: $(CLASSFILES)
92 javafiles: $(JAVAFILES)
93
94 %.class: %.java
95         javac -classpath .. $<
96
97 # javah renames these files.  the jnibuilder doesn't anticipate this
98 # and generates #includes with the original names.
99 Firm_common.h: Firm_common.class
100         ln -sf Firm_0005fcommon.h Firm_common.h
101         javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
102
103 Type_or_entity.h: Type_or_entity.class
104         ln -sf Type_0005for_0005fentity.h Type_or_entity.h
105         javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
106
107
108 Dbginfo.java:
109         cp $(top_srcdir)/aux/Dbginfo.java $(top_srcdir)/aux/Dbginfo.c .
110
111 Heapanal.java:
112         cp $(top_srcdir)/aux/Heapanal.java $(top_srcdir)/aux/Heapanal.c .
113
114 %.h:    %.class
115         javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
116
117 %.o:    %.c %.h
118         gcc $(CPPFLAGS) -c $< -o $@
119
120 $(OFILES):
121         gcc $(CPPFLAGS) -c $(@:.o=.c) -o $@
122
123 jni:    $(HFILES) $(OFILES)  # ../libfirm.a
124         gcc -shared -fPIC -o $(LIBNAME) *.o -lfirm -L.. -lheapanal -L../../opt/heapanal \
125         -liberty -L../../sw/lib
126
127 install:
128         cp libfirmjni.so $(libdir)
129 #       mkdir $(javadir)
130 #       cp *.java @javadir@
131 #       cp *.class @javadir@
132
133
134 test:   jni
135         $(MAKE) -C testprograms test
136
137 clean:
138         rm -rf sources *.c *.h *.o
139
140 realclean: clean
141         rm -f *~ libfirmjni.so *.vcg *.java *.class
142
143
144 $(SOURCE_DIR):
145         rm -rf $(SOURCE_DIR)
146         mkdir $(SOURCE_DIR)
147
148 $(SOURCE_DIR)/firm_typedefs.h: $(FIRM_SOURCE_HEADERS)
149         mv firm_typedefs.h $@
150
151 ###############################################################################
152 # Get all the necessary Firm headers.
153 ###############################################################################
154 # Remove C preprocessor commands.  Overwrite the header files.
155 # This part should be removed if crecoder integrates the preprocessor.
156
157 FIRM_SRC_HEADER=$(top_srcdir)/ir/$(filter %/$(notdir $@),$(FIRM_PATH_HEADERS))
158
159
160 # recode: remove "a from C code...
161 $(FIRM_SOURCE_DIR_HEADERS): $(SOURCE_DIR)
162         recode ISO-8859-1..ascii < $(FIRM_SRC_HEADER) > $(SOURCE_DIR)/$(notdir $@)
163         perl $(REMOVE_CPP_COMMANDS) $@
164
165 #       cp $(FIRM_SRC_HEADER) $(SOURCE_DIR)/$(notdir $@)
166 #       recode ISO-8859-1..ascii < $@ > $@.x
167 #       cp $@.x $@
168
169 # generiert leere dateien ;-(
170 #       troff -a -C -z  $(FIRM_SRC_HEADER) > $(SOURCE_DIR)/$(notdir $@)
171
172 $(FIRM_HEADERS):$(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
173         gcc $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$@ -o $@
174
175 ###############################################################################
176 # Call crecoder to construct from each header a .java file specifying the
177 # java native interface.  Further crecoder constructs an implementation of
178 # the java native interface in C calling the real libfirm functions.
179 # For a file "file.h" files "File.java" and "File.c" are generated.
180
181
182 H_FROM_JAVA=$(subst .java,.h,$(shell echo $@|$(SHELL_TOLOWER)))
183
184 %.java: $(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
185         gcc $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$(H_FROM_JAVA) -o $(H_FROM_JAVA)
186         env CLASSPATH=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar:$$CLASSPATH java crecoder/tools/jniBuilder/BuildJNI $(H_FROM_JAVA);\
187         rm $(H_FROM_JAVA);
188 # remove the patched header so that further compilation finds the proper firm headers