5 doc/nestedvm.ivme04.pdf: doc/nestedvm.ivme04.tex doc/acmconf.cls
6 cd doc; pdflatex nestedvm.ivme04.tex && ./pst2pdf && pdflatex nestedvm.ivme04.tex
8 pdf: doc/nestedvm.ivme04.pdf
9 open doc/nestedvm.ivme04.pdf
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)
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)
18 # C sources that are part of the compiler/interpreter
19 mips_sources = crt0.c support_aux.c
20 mips_asm_sources = support.s
22 mips2java_root = $(shell pwd)
23 build = $(mips2java_root)/build
24 tasks = upstream/tasks
27 # MIPS Settings (don't change these)
30 MIPS_CC = mips-unknown-elf-gcc
31 MIPS_CXX = mips-unknown-elf-g++
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 \
40 -ffunction-sections -fdata-sections \
43 MIPS_CFLAGS = $(mips_optflags) $(flags) -I. -Wall -Wno-unused -Werror
44 MIPS_LD = mips-unknown-elf-gcc
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
50 # Java compiler/VM settings
53 ifeq ($(firstword $(JAVAC)),gcj)
54 JAVAC_NODEBUG_FLAGS = -g0
56 JAVAC_NODEBUG_FLAGS = -g:none
59 CLASSPATH = build:upstream/build/bcel/bcel-5.1.jar
67 $(java_sources:src/%.java=build/%.class) \
68 $(java_gen_sources:%.java=%.class)
70 mips_objects = $(mips_sources:%.c=build/org/xwt/mips/%.o) $(mips_asm_sources:%.s=build/org/xwt/mips/%.o)
74 PATH := $(mips2java_root)/upstream/install/bin:$(PATH)
80 all: $(java_classes) $(mips_objects)
81 ifdef NATIVE_MIPS2JAVA_COMPILER
82 all: build/mips2java$(EXE_EXT) $(mips_objects)
86 $(MAKE) -C upstream tasks/$* MIPS_LDFLAGS="$(MIPS_LDFLAGS)" MIPS_CFLAGS="$(flags) $(mips_optflags)"
89 $(MAKE) -C upstream clean_$*
91 errno_h = upstream/install/mips-unknown-elf/include/sys/errno.h
92 $(errno_h): $(tasks)/build_newlib
94 unistd_h = upstream/install/mips-unknown-elf/include/sys/unistd.h
95 $(unistd_h): $(tasks)/build_newlib
98 # Interpreter/Compiler/Runtime Java Compilation
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 $@`
106 $(java_classes): build/org/xwt/mips/util/.Dummy.class
109 $(java_classes): $(tasks)/unpack_bcel $(java_sources) $(java_gen_sources)
110 $(JAVAC) -classpath $(CLASSPATH) -d build $(java_sources) $(java_gen_sources)
112 build/org/xwt/mips/UsermodeConstants.java: src/org/xwt/mips/syscalls.h $(errno_h) $(unistd_h)
113 @mkdir -p `dirname $@`
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 ';\
122 s/ *\# *define \([A-Z_][A-Za-z0-9_]*\) \([0-9][0-9x]*\)/ public static final int \1 = \2;/p';\
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)
132 # MIPS Binary compilation
134 build/%.o: src/%.c $(tasks)/full_toolchain
135 @mkdir -p `dirname $@`
136 $(MIPS_CC) $(MIPS_CFLAGS) $($(notdir $*)_CFLAGS) -c -o $@ $<
138 build/%.o: src/%.s $(tasks)/full_toolchain
139 @mkdir -p `dirname $@`
140 $(MIPS_CC) -x assembler-with-cpp -c -o $@ $<
142 %.s: %.c $(tasks)/full_toolchain
143 $(MIPS_CC) $(MIPS_CFLAGS) $($(notdir $*)_CFLAGS) -c -S -o $@ $<
145 build/%.mips: build/%.o $(mips_objects)
146 $(MIPS_LD) -o $@ $< $(MIPS_LDFLAGS) $($(notdir $*)_LDFLAGS)
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 $@ $<
152 build/%.mips.stripped: build/%.mips
156 # MIPS Compiler generated class compilation
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
162 build/%.class: build/%.java build/org/xwt/mips/Runtime.class
163 $(JAVAC) $(JAVAC_NODEBUG_FLAGS) -classpath build -d build $<
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 /,.,$*) $<
172 # General Java Class compilation
173 build/%.class: src/%.java
174 $(JAVAC) -classpath build -d build $<
177 rm -rf build/tests build/org/xwt/mips *.jar build/mips2java$(EXE_EXT)
182 env.sh: Makefile $(tasks)/full_toolchain build/org/xwt/mips/Compiler.class $(tasks)/unpack_bcel
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' >> $@~
195 @echo "$@ created successfully"
201 runtime_util_classes = SeekableData SeekableByteArray SeekableFile SeekableInputStream
202 runtime_classes = Runtime Registers UsermodeConstants $(runtime_util_classes:%=util/%)
203 unixruntime_classes = $(runtime_classes) UnixRuntime
205 runtime.jar: $(runtime_classes:%=build/org/xwt/mips/%.class)
206 cd build && jar cf ../$@ $(runtime_classes:%=org/xwt/mips/%*.class)
208 unixruntime.jar: $(unixruntime_classes:%=build/org/xwt/mips/%.class)
209 cd build && jar cf ../$@ $(unixruntime_classes:%=org/xwt/mips/%*.class)
215 # These are simply here for convenience. They aren't required
216 # to build or run mips2java
219 build/tests/Env.class: build/org/xwt/mips/Runtime.class build/org/xwt/mips/Interpreter.class
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
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`
235 build/tests/FDTest.class: build/tests/Test.class
236 fdtest: build/tests/FDTest.class
237 $(JAVA) -cp build tests.FDTest
241 Simple_LDFLAGS = -nostdlib
242 simpletest: build/tests/Simple.class
243 $(JAVA) -cp build tests.Simple
246 Paranoia_CFLAGS = "-Wno-error"
247 Paranoia_LDFLAGS = -lm
248 paranoiatest: build/tests/Paranoia.class
249 $(JAVA) -cp build tests.Paranoia
254 FreeType_CFLAGS = -Iupstream/build/freetype/include
255 FreeType_LDFLAGS = -Lupstream/build/freetype/objs -lfreetype
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
263 FTBench_CFLAGS = $(FreeType_CFLAGS)
264 FTBench_LDFLAGS = $(FreeType_LDFLAGS)
265 build/tests/FTBench.o: $(tasks)/build_freetype
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
275 MSPackBench_CFLAGS = -Iupstream/build/libmspack/mspack
276 MSPackBench_LDFLAGS = -Lupstream/build/libmspack/mspack -lmspack
277 build/tests/MSPackBench.o: $(tasks)/build_libmspack
282 build/tests/Echo.class: build/tests/EchoHelper.class
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 $@
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 $@
300 busyboxtest: build/tests/BusyBox.class
301 $(JAVA) -cp build tests.BusyBox ash
306 build/tests/GCTest.mips: $(mips_objects) $(tasks)/build_boehmgc
307 @mkdir -p `dirname $@`
308 cp upstream/build/boehmgc/gctest $@
310 boehmgctest: build/tests/Env.class build/tests/GCTest.class
311 $(JAVA) -cp build tests.Env GC_PRINT_STATS=1 tests.GCTest
318 build/tests/SpeedTest.class: build/org/xwt/mips/Runtime.class
320 tmp/thebride_1280.jpg:
322 cd tmp && wget http://www.kill-bill.com/images/wallpaper/thebride_1280.jpg
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"
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; \
335 echo "Run \"make check\" to get Arial.TTF for the FTBench test"; \
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; \
341 echo "Run \"make check\" to get the MS True Type fonts for the MSPackBench test"; \
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"
349 # Verification checks
352 check: $(patsubst %,build/tests/%.class, FTBench MSPackBench DJpeg GCTest) tmp/thebride_1280.jpg
353 @/bin/bash ./src/tests/check.sh running_from_make
355 compiletests: $(patsubst %,build/tests/%.class,FTBench MSPackBench DJpeg Test FreeTypeDemoHelper MSPackHelper EchoHelper BusyBox GCTest Fork)