tableswitch code
[nestedvm.git] / Makefile
1
2 # What to build
3 #
4
5 doc/nestedvm.ivme04.pdf: doc/nestedvm.ivme04.tex doc/acmconf.cls
6         cd doc; pdflatex nestedvm.ivme04.tex && ./pst2pdf && pdflatex nestedvm.ivme04.tex
7
8 pdf: doc/nestedvm.ivme04.pdf
9         open doc/nestedvm.ivme04.pdf
10
11 # Java sources that are part of the compiler/interpreter
12 java_sources = $(wildcard src/org/xwt/mips/*.java) $(wildcard src/org/xwt/mips/util/*.java)
13
14 # Java sources that are part of the compiler/interpreter that are
15 # generated from other sources
16 java_gen_sources = $(patsubst %,build/org/xwt/mips/%.java, UsermodeConstants)
17
18 # C sources that are part of the compiler/interpreter
19 mips_sources = crt0.c support_aux.c
20 mips_asm_sources = support.s
21
22 mips2java_root = $(shell pwd)
23 build = $(mips2java_root)/build
24 tasks = upstream/tasks
25
26 #
27 # MIPS Settings (don't change these)
28 #
29 flags = -march=mips1
30 MIPS_CC = mips-unknown-elf-gcc
31 MIPS_CXX = mips-unknown-elf-g++
32
33 # Be VERY careful about changing any of these as they can break binary 
34 # compatibility and create hard to find bugs
35 mips_optflags = -O3 -g \
36         -fno-rename-registers -freduce-all-givs \
37         -fno-peephole -fno-peephole2 -fmove-all-movables -fno-schedule-insns \
38         -fno-delayed-branch \
39         -mmemcpy \
40         -ffunction-sections -fdata-sections \
41         -falign-functions=512
42
43 MIPS_CFLAGS = $(mips_optflags) $(flags) -I. -Wall -Wno-unused -Werror
44 MIPS_LD = mips-unknown-elf-gcc
45 MIPS_LDFLAGS= \
46         $(flags) -L$(build)/org/xwt/mips --static \
47         -T $(mips2java_root)/src/org/xwt/mips/linker.ld -Wl,--gc-sections
48 MIPS_STRIP = mips-unknown-elf-strip
49
50 # Java compiler/VM settings
51 JAVAC = javac
52 JAVA = java
53 ifeq ($(firstword $(JAVAC)),gcj)
54         JAVAC_NODEBUG_FLAGS = -g0
55 else
56         JAVAC_NODEBUG_FLAGS = -g:none
57 endif
58
59 CLASSPATH = build:upstream/build/bcel/bcel-5.1.jar
60
61 GCJ = gcj
62 EXE_EXT = 
63
64 #####
65
66 java_classes = \
67         $(java_sources:src/%.java=build/%.class) \
68         $(java_gen_sources:%.java=%.class)
69
70 mips_objects = $(mips_sources:%.c=build/org/xwt/mips/%.o) $(mips_asm_sources:%.s=build/org/xwt/mips/%.o)
71
72 .SECONDARY:
73
74 PATH := $(mips2java_root)/upstream/install/bin:$(PATH)
75 export PATH
76
77 #
78 # General Build Stuff
79 #
80 all: $(java_classes) $(mips_objects)
81 ifdef NATIVE_MIPS2JAVA_COMPILER
82 all: build/mips2java$(EXE_EXT) $(mips_objects)
83 endif
84
85 $(tasks)/%:
86         $(MAKE) -C upstream tasks/$* MIPS_LDFLAGS="$(MIPS_LDFLAGS)" MIPS_CFLAGS="$(flags) $(mips_optflags)"
87
88 upstream_clean_%:
89         $(MAKE) -C upstream clean_$*
90
91 errno_h = upstream/install/mips-unknown-elf/include/sys/errno.h
92 $(errno_h): $(tasks)/build_newlib
93
94 unistd_h = upstream/install/mips-unknown-elf/include/sys/unistd.h
95 $(unistd_h): $(tasks)/build_newlib
96
97 #
98 # Interpreter/Compiler/Runtime Java Compilation
99 #
100
101 # This works around a gcj -C bug
102 ifeq ($(firstword $(JAVAC)),gcj)
103 build/org/xwt/mips/util/.Dummy.class:
104         mkdir -p `dirname $@`
105         touch $@
106 $(java_classes): build/org/xwt/mips/util/.Dummy.class
107 endif
108
109 $(java_classes): $(tasks)/unpack_bcel $(java_sources) $(java_gen_sources)
110         $(JAVAC) -classpath $(CLASSPATH) -d build $(java_sources) $(java_gen_sources)
111
112 build/org/xwt/mips/UsermodeConstants.java: src/org/xwt/mips/syscalls.h $(errno_h) $(unistd_h)
113         @mkdir -p `dirname $@`
114         cat $^ |\
115                 (FILE=org.xwt.mips.UsermodeConstants;\
116                  C="`echo $$FILE | sed 's/.*\.\([^\.]*\)$$/\1/;'`";\
117                  P="`echo $$FILE | sed -n 's/\(.*\)\..*/\1/p;'`";\
118                  [ -n "$$P" ] && echo "package $$P;";\
119                  echo "public interface $$C {";\
120                  tr '\t' ' ' | sed -n ';\
121                  s/  */ /g;\
122                  s/ *\# *define \([A-Z_][A-Za-z0-9_]*\) \([0-9][0-9x]*\)/    public static final int \1 = \2;/p';\
123                  echo "}") > $@
124  
125
126 # FIXME: We're cramming more than we need into the binary here
127 build/mips2java$(EXE_EXT): $(java_sources) $(java_gen_sources)
128         @mkdir -p `dirname $@`
129         $(GCJ) -s -o $@ --main=org.xwt.mips.Compiler $(java_sources) $(java_gen_sources)
130
131 #
132 # MIPS Binary compilation
133 #
134 build/%.o: src/%.c $(tasks)/full_toolchain
135         @mkdir -p `dirname $@`
136         $(MIPS_CC) $(MIPS_CFLAGS) $($(notdir $*)_CFLAGS) -c -o $@ $<
137
138 build/%.o: src/%.s $(tasks)/full_toolchain
139         @mkdir -p `dirname $@`
140         $(MIPS_CC) -x assembler-with-cpp -c -o $@ $<
141
142 %.s: %.c $(tasks)/full_toolchain
143         $(MIPS_CC) $(MIPS_CFLAGS) $($(notdir $*)_CFLAGS) -c -S -o $@ $<
144
145 build/%.mips: build/%.o $(mips_objects)
146         $(MIPS_LD) -o $@ $< $(MIPS_LDFLAGS) $($(notdir $*)_LDFLAGS)
147
148 build/%.mips: src/%.cc $(tasks)/full_toolchain $(mips_objects)
149         @mkdir -p `dirname $@`
150         $(MIPS_CXX) $(MIPS_CFLAGS) $($(notdir $*)_CFLAGS) $(MIPS_LDFLAGS) $($(notdir $*)_LDFLAGS) -o $@ $<
151
152 build/%.mips.stripped: build/%.mips
153         cp $< $@
154         $(MIPS_STRIP) -s $@
155
156 # MIPS Compiler generated class compilation
157 ifdef DO_JAVASOURCE
158
159 build/%.java: build/%.mips build/org/xwt/mips/JavaSourceCompiler.class $(tasks)/unpack_bcel 
160         $(JAVA) -cp $(CLASSPATH) org.xwt.mips.Compiler -outformat javasource $(compiler_flags) $($(notdir $*)_COMPILERFLAGS) $(subst /,.,$*) $< > build/$*.java
161
162 build/%.class: build/%.java build/org/xwt/mips/Runtime.class
163         $(JAVAC) $(JAVAC_NODEBUG_FLAGS) -classpath build -d build $<
164 else
165
166 build/%.class: build/%.mips build/org/xwt/mips/ClassFileCompiler.class $(tasks)/unpack_bcel 
167         $(JAVA) -cp $(CLASSPATH) org.xwt.mips.Compiler -outformat class -outfile $@ $(compiler_flags) $($(notdir $*)_COMPILERFLAGS) $(subst /,.,$*) $<
168
169
170 endif
171
172 # General Java Class compilation
173 build/%.class: src/%.java
174         $(JAVAC) -classpath build -d build $<
175
176 clean:
177         rm -rf build/tests build/org/xwt/mips *.jar build/mips2java$(EXE_EXT)
178
179 #
180 # env.sh
181 #
182 env.sh: Makefile $(tasks)/full_toolchain build/org/xwt/mips/Compiler.class $(tasks)/unpack_bcel 
183         @rm -f "$@~"
184         @echo 'PATH="$(mips2java_root)/build:$(mips2java_root)/upstream/install/bin:$$PATH"; export PATH' >> $@~
185         @echo 'CC=mips-unknown-elf-gcc; export CC' >> $@~
186         @echo 'CXX=mips-unknown-elf-g++; export CXX' >> $@~
187         @echo 'AS=mips-unknown-elf-as; export AS' >> $@~
188         @echo 'LD=mips-unknown-elf-ar; export LD' >> $@~
189         @echo 'RANLIB=mips-unknown-elf-ranlib; export RANLIB' >> $@~
190         @echo 'CFLAGS="$(mips_optflags)"; export CFLAGS' >> $@~
191         @echo 'CXXFLAGS="$(mips_optflags)"; export CXXFLAGS' >> $@~
192         @echo 'LDFLAGS="$(MIPS_LDFLAGS)"; export LDFLAGS' >> $@~
193         @echo 'CLASSPATH=$(mips2java_root)/build:$(mips2java_root)/upstream/build/bcel/bcel-5.1.jar:.; export CLASSPATH' >> $@~
194         @mv "$@~" "$@"
195         @echo "$@ created successfully"
196
197 #
198 # Runtime.jar
199 #
200
201 runtime_util_classes = SeekableData SeekableByteArray SeekableFile SeekableInputStream
202 runtime_classes = Runtime Registers UsermodeConstants  $(runtime_util_classes:%=util/%)
203 unixruntime_classes = $(runtime_classes) UnixRuntime
204
205 runtime.jar: $(runtime_classes:%=build/org/xwt/mips/%.class)
206         cd build && jar cf ../$@ $(runtime_classes:%=org/xwt/mips/%*.class)
207
208 unixruntime.jar: $(unixruntime_classes:%=build/org/xwt/mips/%.class)
209         cd build && jar cf ../$@ $(unixruntime_classes:%=org/xwt/mips/%*.class)
210
211
212
213 #
214 # Tests
215 # These are simply here for convenience. They aren't required 
216 # to build or run mips2java
217 #
218
219 build/tests/Env.class: build/org/xwt/mips/Runtime.class build/org/xwt/mips/Interpreter.class
220
221 # Generic Hello Worldish test
222 test: build/tests/Test.class
223         $(JAVA) -cp build tests.Test "arg 1" "arg 2" "arg 3"
224 inttest: build/tests/Test.mips build/org/xwt/mips/Interpreter.class
225         $(JAVA) -cp build org.xwt.mips.Interpreter build/tests/Test.mips "arg 1" "arg 2" "arg 3"
226 cxxtest: build/tests/CXXTest.class
227         $(JAVA) -cp build tests.CXXTest
228
229 # CallTest
230 build/tests/CallTest.class: build/tests/Test.class
231 calltest: build/tests/CallTest.class
232         $(JAVA) -cp build tests.CallTest `date|perl -pe 's/\D+/ /g;'` `id -u`
233
234 # FDTest
235 build/tests/FDTest.class: build/tests/Test.class
236 fdtest: build/tests/FDTest.class
237         $(JAVA) -cp build tests.FDTest
238
239
240 # Simple
241 Simple_LDFLAGS = -nostdlib
242 simpletest: build/tests/Simple.class
243         $(JAVA) -cp build tests.Simple
244
245 # Paranoia
246 Paranoia_CFLAGS = "-Wno-error"
247 Paranoia_LDFLAGS = -lm
248 paranoiatest: build/tests/Paranoia.class
249         $(JAVA) -cp build tests.Paranoia
250
251 #
252 # Freetype Stuff
253 #
254 FreeType_CFLAGS = -Iupstream/build/freetype/include
255 FreeType_LDFLAGS =  -Lupstream/build/freetype/objs -lfreetype
256
257 FreeTypeDemoHelper_CFLAGS = $(FreeType_CFLAGS)
258 FreeTypeDemoHelper_LDFLAGS = $(FreeType_LDFLAGS)
259 build/tests/FreeTypeDemoHelper.o: $(mips_objects) $(tasks)/build_freetype
260 build/tests/FreeTypeDemoHelper.mips: 
261 build/tests/FreeTypeDemo.class: build/tests/FreeTypeDemoHelper.class
262
263 FTBench_CFLAGS =  $(FreeType_CFLAGS)
264 FTBench_LDFLAGS = $(FreeType_LDFLAGS)
265 build/tests/FTBench.o: $(tasks)/build_freetype
266
267 #
268 # MSPack Stuff
269 #
270 MSPackHelper_CFLAGS = -Iupstream/build/libmspack/mspack
271 MSPackHelper_LDFLAGS = -Lupstream/build/libmspack/mspack -lmspack
272 build/tests/MSPackHelper.o: $(mips_objects) $(tasks)/build_libmspack
273 build/tests/MSPack.class: build/tests/MSPackHelper.class
274
275 MSPackBench_CFLAGS = -Iupstream/build/libmspack/mspack
276 MSPackBench_LDFLAGS = -Lupstream/build/libmspack/mspack -lmspack
277 build/tests/MSPackBench.o: $(tasks)/build_libmspack
278
279 #
280 # Echo
281 #
282 build/tests/Echo.class: build/tests/EchoHelper.class
283
284 #
285 # Libjpeg
286 #
287 DJpeg_COMPILERFLAGS = -o onepage,pagesize=8m
288 build/tests/DJpeg.mips: $(mips_objects) $(tasks)/build_libjpeg
289         @mkdir -p `dirname $@`
290         cp upstream/build/libjpeg/djpeg $@
291
292 #
293 # Busybox
294 #
295 BusyBox_COMPILERFLAGS = -o unixruntime
296 build/tests/BusyBox.mips: $(mips_object) $(tasks)/build_busybox
297         @mkdir -p `dirname $@`
298         cp upstream/build/busybox/busybox $@
299
300 busyboxtest: build/tests/BusyBox.class
301         $(JAVA) -cp build tests.BusyBox ash
302
303 #
304 # Boehm GC
305 #
306 build/tests/GCTest.mips: $(mips_objects) $(tasks)/build_boehmgc
307         @mkdir -p `dirname $@`
308         cp upstream/build/boehmgc/gctest $@
309
310 boehmgctest: build/tests/Env.class build/tests/GCTest.class
311         $(JAVA) -cp build tests.Env GC_PRINT_STATS=1  tests.GCTest
312
313
314 #
315 # Speed tests
316 #
317
318 build/tests/SpeedTest.class: build/org/xwt/mips/Runtime.class
319
320 tmp/thebride_1280.jpg:
321         @mkdir -p tmp
322         cd tmp && wget http://www.kill-bill.com/images/wallpaper/thebride_1280.jpg
323
324 oldspeedtest: build/tests/DJpeg.class tmp/thebride_1280.jpg
325         bash -c "time $(JAVA) -cp build tests.DJpeg -targa -outfile tmp/thebride_1280.tga tmp/thebride_1280.jpg"
326         @echo "e90f6b915aee2fc0d2eb9fc60ace6203  tmp/thebride_1280.tga" | md5sum -c && echo "MD5 is OK"
327
328 speedtest: build/tests/SpeedTest.class build/tests/DJpeg.class build/tests/FTBench.class tmp/thebride_1280.jpg build/tests/MSPackBench.class
329         @echo "Running DJpeg test..."
330         @$(JAVA) -cp build tests.SpeedTest tests.DJpeg 10 -targa -outfile tmp/thebride_1280.tga tmp/thebride_1280.jpg
331         @if [ -e tmp/mspack/Comic.TTF ]; then \
332                 echo "Running FTBench test..."; \
333                 $(JAVA) -cp build tests.SpeedTest tests.FTBench 10 tmp/mspack/Comic.TTF tmp/mspack/Comic.TTF.render; \
334         else \
335                 echo "Run \"make check\" to get Arial.TTF for the FTBench test"; \
336         fi
337         @if [ -e tmp/mspack/comic32.exe ]; then \
338                 echo "Running MSPackBench test..."; \
339                 cd tmp/mspack && $(JAVA) -cp ../../build tests.SpeedTest tests.MSPackBench 10 *32.exe; \
340         else \
341                 echo "Run \"make check\" to get the MS True Type fonts for the MSPackBench test"; \
342         fi
343
344 intspeed: build/tests/DJpeg.mips  build/org/xwt/mips/Interpreter.class tmp/thebride_1280.jpg
345         time $(JAVA) -cp build org.xwt.mips.Interpreter build/tests/DJpeg.mips -targa  -outfile tmp/thebride_1280.tga tmp/thebride_1280.jpg
346         @echo "e90f6b915aee2fc0d2eb9fc60ace6203  tmp/thebride_1280.tga" | md5sum -c && echo "MD5 is OK"
347
348 #
349 # Verification checks
350 #
351
352 check: $(patsubst %,build/tests/%.class, FTBench MSPackBench DJpeg GCTest) tmp/thebride_1280.jpg
353         @/bin/bash ./src/tests/check.sh running_from_make
354
355 compiletests: $(patsubst %,build/tests/%.class,FTBench MSPackBench DJpeg Test FreeTypeDemoHelper MSPackHelper EchoHelper BusyBox GCTest Fork)
356         @true
357