Makefile.in 5.91 KB
Newer Older
Götz Lindenmaier's avatar
Götz Lindenmaier committed
1
2
3
4
5
6
7
8
9
10
11
#
# Project:     libFIRM
# File name:   firmjni/Makefile.in
# Purpose:
# Author:      Till Riedel, Goetz Lindenmaier
# Modified by:
# Created:     2002
# CVS-ID:      $Id$
# Copyright:   (c) 2002 Universitt Karlsruhe
# Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
#
12
13
14
15
16
17

top_srcdir := @top_srcdir@
srcdir = @srcdir@
topdir = ..
subdir = firmjni

18
19
enable_heapanal := @enable_heapanalysis@

20
21
22
# The library implementing the JNI methods.  This name is also
# known to the generator for the JNI interface and used in the
# static initializer.
23
24
LIBNAME = libfirmjni.so

Götz Lindenmaier's avatar
Götz Lindenmaier committed
25
26
27
# The name of the package containing the Firm JNI
PACKAGENAME = firmjni

28
29
include $(topdir)/MakeRules

30
31
32
33
34
35
# where to put libfirmjni.so
libdir = @libdir@
# where to put the directory firmjni containing the generated
# .java and .class files
#javadir = @javadir@         @@@ how to specify a dir in configure.in?

36
37
.PHONY: default all clean realclean depend

38
39
SHELL_TOUPPER = awk '{for (i=1;i<(NF+1);i=i+1) {printf(toupper(substr($$i,1,1)) substr($$i,2)" ")}}'
SHELL_TOLOWER = awk '{for (i=1;i<(NF+1);i=i+1) {printf(tolower(substr($$i,1,1)) substr($$i,2)" ")}}'
40
41
42

OFILES  = $(MEMBERS:.m=.o)
HFILES  = $(MEMBERS:.m=.h)
43
JAVAFILES  = $(MEMBERS:.m=.java)
44
45
CLASSFILES = $(MEMBERS:.m=.class)

46
CPPFLAGS += 	-I$(top_srcdir)/ir/ir  -I$(top_srcdir)/ir/common  	\
47
48
		-I$(top_srcdir)/ir/ident -I$(top_srcdir)/ir/tr  	\
	        -I$(top_srcdir)/ir/tv -I$(top_srcdir)/ir/debug 		\
49
	        -I$(top_srcdir)/ir/ana -I$(top_srcdir)/ir/opt		\
Götz Lindenmaier's avatar
Götz Lindenmaier committed
50
		-I$(top_srcdir)/ir/st -I$(top_srcdir)/ir/stat
51

52
LDFLAGS += -I$(topdir)
53

54
55
FIRM_HEADERS=$(notdir $(FIRM_PATH_HEADERS))
MEMBERS=$(subst .h,.m,$(shell echo $(FIRM_HEADERS)|$(SHELL_TOUPPER)))
56
MEMBERS += $(IMPL_MEMBERS)
57
58
59
60
61
62
63
64

# How to pass function pointers? Therefore removed.
# irgwalk.h typewalk.h

# How to pass function pointers? Or how to obtain them?
#      Irgwalk.m Typewalk.m
#
FIRM_PATH_HEADERS=common/firm.h common/firm_common.h \
65
	ident/ident.h tv/tv.h \
66
67
68
69
70
	tr/type.h tr/entity.h tr/type_or_entity.h tr/tpop.h tr/mangle.h \
	ir/irprog.h ir/irgraph.h ir/irnode.h ir/irmode.h ir/irop.h \
	ir/ircons.h ir/ircgcons.h ir/irflag.h ir/irvrfy.h ir/irdump.h \
	ir/iropt.h ir/irgopt.h ir/ircgopt.h \
	ana/irouts.h ana/irdom.h ana/irloop.h ana/cgana.h \
Götz Lindenmaier's avatar
Götz Lindenmaier committed
71
	ir/irgmod.h tr/typegmod.h opt/tailrec.h stat/firmstat.h
72

73
FIRM_SOURCE_DIR_HEADERS=$(addprefix $(SOURCE_DIR)/,$(FIRM_HEADERS))
74

75
# hand implemented members
76
77
78
79
80
IMPL_MEMBERS = Dbginfo.m

ifeq ($(enable_heapanal),yes)
IMPL_MEMBERS += Heapanal.m
endif
81

82
83
84
85
86
87
88
89
90
91
92
93
94
# The directory containing crecoder.jar and, for now,
# remove_cpp_comands.perl
FIRM_JNI_TOOLS_DIR=$(top_srcdir)/tools

WORK_DIR=.

###############################################################################

SOURCE_DIR=sources

REMOVE_CPP_COMMANDS=$(FIRM_JNI_TOOLS_DIR)/remove_cpp_comands.perl
CRECODER=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar

95
all: 	classfiles javafiles jni
96

97
classfiles: $(CLASSFILES)
98
javafiles: $(JAVAFILES)
99
100

%.class: %.java
101
	javac -classpath .. $<
102

103
104
105
106
107
108
109
110
111
112
# javah renames these files.  the jnibuilder doesn't anticipate this
# and generates #includes with the original names.
Firm_common.h: Firm_common.class
	ln -sf Firm_0005fcommon.h Firm_common.h
	javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)

Type_or_entity.h: Type_or_entity.class
	ln -sf Type_0005for_0005fentity.h Type_or_entity.h
	javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)

113
114

Dbginfo.java:
115
	cp $(top_srcdir)/firmjni/aux/Dbginfo.java $(top_srcdir)/firmjni/aux/Dbginfo.c .
116

Florian Liekweg's avatar
Florian Liekweg committed
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
124
125

%.o:	%.c %.h
	gcc $(CPPFLAGS) -c $< -o $@

126
127
128
$(OFILES):
	gcc $(CPPFLAGS) -c $(@:.o=.c) -o $@

129
130
131
132
133
134
135
136

ifeq ($(enable_heapanal),yes)
HEAPANALLIB = -lheapanal
else
HEAPANALLIB =
endif


137
jni:    $(HFILES) $(OFILES)  # ../libfirm.a
138
	gcc -shared -fPIC -o $(LIBNAME) *.o -lfirm -L.. $(HEAPANALLIB) $(LDFLAGS) -liberty -L../../sw/lib
139
140
141

install:
	cp libfirmjni.so $(libdir)
142
#	mkdir $(javadir)
143
#	cp *.java @javadir@
144
#	cp *.class @javadir@
145

146
147
148
149

test:	jni
	$(MAKE) -C testprograms test

150
151
152
153
154
clean:
	rm -rf sources *.c *.h *.o

realclean: clean
	rm -f *~ libfirmjni.so *.vcg *.java *.class
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171


$(SOURCE_DIR):
	rm -rf $(SOURCE_DIR)
	mkdir $(SOURCE_DIR)

$(SOURCE_DIR)/firm_typedefs.h: $(FIRM_SOURCE_HEADERS)
	mv firm_typedefs.h $@

###############################################################################
# Get all the necessary Firm headers.
###############################################################################
# Remove C preprocessor commands.  Overwrite the header files.
# This part should be removed if crecoder integrates the preprocessor.

FIRM_SRC_HEADER=$(top_srcdir)/ir/$(filter %/$(notdir $@),$(FIRM_PATH_HEADERS))

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
177
	perl $(REMOVE_CPP_COMMANDS) $@

178
179
180
181
#	cp $(FIRM_SRC_HEADER) $(SOURCE_DIR)/$(notdir $@)
#	recode ISO-8859-1..ascii < $@ > $@.x
#	cp $@.x $@

182
183
184
# generiert leere dateien ;-(
#	troff -a -C -z  $(FIRM_SRC_HEADER) > $(SOURCE_DIR)/$(notdir $@)

185
186
187
188
189
190
191
192
193
194
195
196
$(FIRM_HEADERS):$(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
	gcc $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$@ -o $@

###############################################################################
# Call crecoder to construct from each header a .java file specifying the
# java native interface.  Further crecoder constructs an implementation of
# the java native interface in C calling the real libfirm functions.
# For a file "file.h" files "File.java" and "File.c" are generated.


H_FROM_JAVA=$(subst .java,.h,$(shell echo $@|$(SHELL_TOLOWER)))

197
198
%.java: $(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
	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
201
	rm $(H_FROM_JAVA);
# remove the patched header so that further compilation finds the proper firm headers