9deaad43904c75a84c1fa497d3936d4731e6dac4
[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 CLASSFILES = $(MEMBERS:.m=.class)
31
32 CPPFLAGS =      -I$(top_srcdir)/ir/ir  -I$(top_srcdir)/ir/common        \
33                 -I$(top_srcdir)/ir/ident -I$(top_srcdir)/ir/tr          \
34                 -I$(top_srcdir)/ir/tv -I$(top_srcdir)/ir/debug          \
35                 -I$(top_srcdir)/ir/ana -I$(top_srcdir)/ir/st @CPPFLAGS@ \
36                 -D_SIZE_T_
37
38 LDFLAGS += $(topdir)
39
40 FIRM_HEADERS=$(notdir $(FIRM_PATH_HEADERS))
41 MEMBERS=$(subst .h,.m,$(shell echo $(FIRM_HEADERS)|$(SHELL_TOUPPER)))
42
43 # How to pass function pointers? Therefore removed.
44 # irgwalk.h typewalk.h
45
46 # How to pass function pointers? Or how to obtain them?
47 #      Irgwalk.m Typewalk.m
48 #
49 FIRM_PATH_HEADERS=common/firm.h common/firm_common.h \
50         debug/dbginfo.h ident/ident.h tv/tv.h \
51         tr/type.h tr/entity.h tr/type_or_entity.h tr/tpop.h tr/mangle.h \
52         ir/irprog.h ir/irgraph.h ir/irnode.h ir/irmode.h ir/irop.h \
53         ir/ircons.h ir/ircgcons.h ir/irflag.h ir/irvrfy.h ir/irdump.h \
54         ir/iropt.h ir/irgopt.h ir/ircgopt.h \
55         ana/irouts.h ana/irdom.h ana/irloop.h ana/cgana.h \
56         ir/irgmod.h tr/typegmod.h
57 FIRM_SOURCE_DIR_HEADERS=$(addprefix $(SOURCE_DIR)/,$(FIRM_HEADERS))
58
59 # The directory containing crecoder.jar and, for now,
60 # remove_cpp_comands.perl
61 FIRM_JNI_TOOLS_DIR=$(top_srcdir)/tools
62
63 WORK_DIR=.
64
65 ###############################################################################
66
67 SOURCE_DIR=sources
68
69 REMOVE_CPP_COMMANDS=$(FIRM_JNI_TOOLS_DIR)/remove_cpp_comands.perl
70 CRECODER=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar
71
72 all:    classfiles jni
73
74 classfiles: $(CLASSFILES)
75
76 %.class: %.java
77         javac $<
78
79 # javah renames these files.  the jnibuilder doesn't anticipate this
80 # and generates #includes with the original names.
81 Firm_common.h: Firm_common.class
82         ln -sf Firm_0005fcommon.h Firm_common.h
83         javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
84
85 Type_or_entity.h: Type_or_entity.class
86         ln -sf Type_0005for_0005fentity.h Type_or_entity.h
87         javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
88
89 %.h:    %.class
90         javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
91
92 %.o:    %.c %.h
93         gcc $(CPPFLAGS) -c $< -o $@
94
95 $(OFILES):
96         gcc $(CPPFLAGS) -c $(@:.o=.c) -o $@
97
98 jni:    $(HFILES) $(OFILES)  # ../libfirm.a
99         gcc -shared -fPIC -o $(LIBNAME) *.o -lfirm -L..
100
101 install:
102         cp libfirmjni.so $(libdir)
103 #       mkdir $(javadir)
104 #       cp *.java @javadir@
105 #       cp *.class @javadir@
106
107 clean:
108         rm -rf sources *.c *.h *.o
109
110 realclean: clean
111         rm -f *~ libfirmjni.so *.vcg *.java *.class
112
113
114 $(SOURCE_DIR):
115         rm -rf $(SOURCE_DIR)
116         mkdir $(SOURCE_DIR)
117
118 $(SOURCE_DIR)/firm_typedefs.h: $(FIRM_SOURCE_HEADERS)
119         mv firm_typedefs.h $@
120
121 ###############################################################################
122 # Get all the necessary Firm headers.
123 ###############################################################################
124 # Remove C preprocessor commands.  Overwrite the header files.
125 # This part should be removed if crecoder integrates the preprocessor.
126
127 FIRM_SRC_HEADER=$(top_srcdir)/ir/$(filter %/$(notdir $@),$(FIRM_PATH_HEADERS))
128
129 $(FIRM_SOURCE_DIR_HEADERS): $(SOURCE_DIR)
130         troff -a -C -z  $(FIRM_SRC_HEADER) >$(SOURCE_DIR)/$(notdir $@)
131         perl $(REMOVE_CPP_COMMANDS) $@
132
133 $(FIRM_HEADERS):$(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
134         gcc $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$@ -o $@
135
136 ###############################################################################
137 # Call crecoder to construct from each header a .java file specifying the
138 # java native interface.  Further crecoder constructs an implementation of
139 # the java native interface in C calling the real libfirm functions.
140 # For a file "file.h" files "File.java" and "File.c" are generated.
141
142
143 H_FROM_JAVA=$(subst .java,.h,$(shell echo $@|$(SHELL_TOLOWER)))
144
145 %.java: $(FIRM_HEADERS)
146         env CLASSPATH=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar:$$CLASSPATH java crecoder/tools/jniBuilder/BuildJNI $(H_FROM_JAVA);\