5 # Java sources that are part of the compiler/interpreter
6 java_sources = $(wildcard src/org/xwt/mips/*.java) $(wildcard src/org/xwt/mips/util/*.java)
8 # C sources that are part of the compiler/interpreter
9 mips_sources = crt0.c support_aux.c
10 mips_asm_sources = support.s
12 mips2java_root = $(shell pwd)
13 build = $(mips2java_root)/build
14 tasks = upstream/tasks
17 # MIPS Settings (don't change these)
20 MIPS_CC = mips-unknown-elf-gcc
21 MIPS_CXX = mips-unknown-elf-g++
23 # Be VERY careful about changing any of these as they can break binary
24 # compatibility and create hard to find bugs
25 mips_optflags = -O3 -g \
27 -ffunction-sections -fdata-sections \
28 -falign-functions=512 \
29 -fno-rename-registers \
34 MIPS_CFLAGS = $(mips_optflags) $(flags) -I. -Wall -Wno-unused -Werror
35 MIPS_LD = mips-unknown-elf-gcc
37 $(flags) -L$(build)/org/xwt/mips --static \
38 -T $(mips2java_root)/src/org/xwt/mips/linker.ld -Wl,--gc-sections
39 MIPS_STRIP = mips-unknown-elf-strip
41 # Java compiler/VM settings
44 ifeq ($(firstword $(JAVAC)),gcj)
45 JAVAC_NODEBUG_FLAGS = -g0
47 JAVAC_NODEBUG_FLAGS = -g:none
50 bcel_jar = upstream/build/bcel-5.1/bcel-5.1.jar
51 classpath = build:$(bcel_jar)
58 java_classes = $(java_sources:src/%.java=build/%.class)
59 mips_objects = $(mips_sources:%.c=build/org/xwt/mips/%.o) $(mips_asm_sources:%.s=build/org/xwt/mips/%.o)
61 usr = $(mips2java_root)/upstream/install
62 PATH := $(usr)/bin:$(PATH)
68 all: $(java_classes) $(mips_objects)
69 ifdef NATIVE_MIPS2JAVA_COMPILER
70 all: build/mips2java$(EXE_EXT) $(mips_objects)
74 $(MAKE) -C upstream tasks/$* usr="$(usr)" MIPS_LDFLAGS="$(MIPS_LDFLAGS)" MIPS_CFLAGS="$(flags) $(mips_optflags)"
77 $(MAKE) -C upstream clean_$* usr="$(usr)"
79 errno_h = $(usr)/mips-unknown-elf/include/sys/errno.h
80 $(errno_h): $(tasks)/build_newlib
82 unistd_h = $(usr)/mips-unknown-elf/include/sys/unistd.h
83 $(unistd_h): $(tasks)/build_newlib
86 # Interpreter/Compiler/Runtime Java Compilation
89 # This works around a gcj -C bug
90 ifeq ($(firstword $(JAVAC)),gcj)
91 build/org/xwt/mips/util/.Dummy.class:
94 $(java_classes): build/org/xwt/mips/util/.Dummy.class
97 $(java_classes): $(java_sources) $(bcel_jar)
98 $(JAVAC) -classpath $(classpath) -d build $(java_sources)
100 $(bcel_jar): upstream/tasks/extract_bcel
104 # FIXME: We're cramming more than we need into the binary here
105 build/mips2java$(EXE_EXT): $(java_sources) $(java_gen_sources)
106 @mkdir -p `dirname $@`
107 $(GCJ) -s -o $@ --main=org.xwt.mips.Compiler $(java_sources) $(java_gen_sources)
110 # MIPS Binary compilation
112 build/%.o: src/%.c $(tasks)/full_toolchain
113 @mkdir -p `dirname $@`
114 $(MIPS_CC) $(MIPS_CFLAGS) $($(notdir $*)_CFLAGS) -c -o $@ $<
116 build/%.o: src/%.s $(tasks)/full_toolchain
117 @mkdir -p `dirname $@`
118 $(MIPS_CC) -x assembler-with-cpp -c -o $@ $<
120 %.s: %.c $(tasks)/full_toolchain
121 $(MIPS_CC) $(MIPS_CFLAGS) $($(notdir $*)_CFLAGS) -c -S -o $@ $<
123 build/%.mips: build/%.o $(mips_objects)
124 $(MIPS_LD) -o $@ $< $(MIPS_LDFLAGS) $($(notdir $*)_LDFLAGS)
126 build/%.mips: src/%.cc $(tasks)/full_toolchain $(mips_objects)
127 @mkdir -p `dirname $@`
128 $(MIPS_CXX) $(MIPS_CFLAGS) $($(notdir $*)_CFLAGS) $(MIPS_LDFLAGS) $($(notdir $*)_LDFLAGS) -o $@ $<
130 build/%.mips.stripped: build/%.mips
134 # MIPS Compiler generated class compilation
137 build/%.java: build/%.mips build/org/xwt/mips/JavaSourceCompiler.class
138 $(JAVA) -cp $(classpath) org.xwt.mips.Compiler -outformat javasource $(compiler_flags) $($(notdir $*)_COMPILERFLAGS) $(subst /,.,$*) $< > build/$*.java
140 build/%.class: build/%.java build/org/xwt/mips/Runtime.class
141 $(JAVAC) $(JAVAC_NODEBUG_FLAGS) -classpath build -d build $<
144 build/%.class: build/%.mips build/org/xwt/mips/ClassFileCompiler.class
145 $(JAVA) -cp $(classpath) org.xwt.mips.Compiler -outformat class -outfile $@ $(compiler_flags) $($(notdir $*)_COMPILERFLAGS) $(subst /,.,$*) $<
150 # General Java Class compilation
151 build/%.class: src/%.java
152 $(JAVAC) -classpath build -d build $<
155 rm -rf build/tests build/org/xwt/mips *.jar build/mips2java$(EXE_EXT)
160 env.sh: Makefile $(tasks)/full_toolchain build/org/xwt/mips/Compiler.class
162 @echo 'PATH="$(mips2java_root)/build:$(usr)/bin:$$PATH"; export PATH' >> $@~
163 @echo 'CC=mips-unknown-elf-gcc; export CC' >> $@~
164 @echo 'CXX=mips-unknown-elf-g++; export CXX' >> $@~
165 @echo 'AS=mips-unknown-elf-as; export AS' >> $@~
166 @echo 'AR=mips-unknown-elf-ar; export AR' >> $@~
167 @echo 'LD=mips-unknown-elf-ld; export LD' >> $@~
168 @echo 'RANLIB=mips-unknown-elf-ranlib; export RANLIB' >> $@~
169 @echo 'CFLAGS="$(mips_optflags)"; export CFLAGS' >> $@~
170 @echo 'CXXFLAGS="$(mips_optflags)"; export CXXFLAGS' >> $@~
171 @echo 'LDFLAGS="$(MIPS_LDFLAGS)"; export LDFLAGS' >> $@~
172 @echo 'CLASSPATH=$(mips2java_root)/build:$(mips2java_root)/$(bcel_jar):.; export CLASSPATH' >> $@~
174 @echo "$@ created successfully"
180 runtime_util_classes = SeekableData SeekableByteArray SeekableFile SeekableInputStream
181 runtime_classes = Runtime Registers UsermodeConstants $(runtime_util_classes:%=util/%)
182 unixruntime_classes = $(runtime_classes) UnixRuntime
184 runtime.jar: $(runtime_classes:%=build/org/xwt/mips/%.class)
185 cd build && jar cf ../$@ $(runtime_classes:%=org/xwt/mips/%*.class)
187 unixruntime.jar: $(unixruntime_classes:%=build/org/xwt/mips/%.class)
188 cd build && jar cf ../$@ $(unixruntime_classes:%=org/xwt/mips/%*.class)
190 # This is only for Brian to use... don't mess with it
191 rebuild-constants: src/org/xwt/mips/syscalls.h $(errno_h) $(unistd_h)
192 @mkdir -p `dirname $@`
194 echo "// THIS FILE IS AUTOGENERATED! DO NOT EDIT!"; \
195 echo "// run \"make rebuild-constants\" if it needs to be updated"; \
197 echo "package org.xwt.mips;"; \
198 echo "public interface UsermodeConstants {"; \
199 tr '\t' ' ' | sed -n ' \
201 s/ *# *define \([A-Z_][A-Za-z0-9_]*\) \([0-9][0-9x]*\)/ public static final int \1 = \2;/p'; \
203 ) > src/org/xwt/mips/UsermodeConstants.java
207 # These are simply here for convenience. They aren't required
208 # to build or run mips2java
211 build/tests/Env.class: build/org/xwt/mips/Runtime.class build/org/xwt/mips/Interpreter.class
213 # Generic Hello Worldish test
214 test: build/tests/Test.class
215 $(JAVA) -cp build tests.Test "arg 1" "arg 2" "arg 3"
216 inttest: build/tests/Test.mips build/org/xwt/mips/Interpreter.class
217 $(JAVA) -cp build org.xwt.mips.Interpreter build/tests/Test.mips "arg 1" "arg 2" "arg 3"
218 cxxtest: build/tests/CXXTest.class
219 $(JAVA) -cp build tests.CXXTest
222 build/tests/CallTest.class: build/tests/Test.class
223 calltest: build/tests/CallTest.class
224 $(JAVA) -cp build tests.CallTest `date|perl -pe 's/\D+/ /g;'` `id -u`
227 build/tests/FDTest.class: build/tests/Test.class
228 fdtest: build/tests/FDTest.class
229 $(JAVA) -cp build tests.FDTest
233 Simple_LDFLAGS = -nostdlib
234 simpletest: build/tests/Simple.class
235 $(JAVA) -cp build tests.Simple
238 Paranoia_CFLAGS = "-Wno-error"
239 Paranoia_LDFLAGS = -lm
240 paranoiatest: build/tests/Paranoia.class
241 $(JAVA) -cp build tests.Paranoia
246 FreeType_CFLAGS = -Iupstream/build/freetype/include
247 FreeType_LDFLAGS = -Lupstream/build/freetype/objs -lfreetype
249 FreeTypeDemoHelper_CFLAGS = $(FreeType_CFLAGS)
250 FreeTypeDemoHelper_LDFLAGS = $(FreeType_LDFLAGS)
251 build/tests/FreeTypeDemoHelper.o: $(mips_objects) $(tasks)/build_freetype
252 build/tests/FreeTypeDemoHelper.mips:
253 build/tests/FreeTypeDemo.class: build/tests/FreeTypeDemoHelper.class
255 FTBench_CFLAGS = $(FreeType_CFLAGS)
256 FTBench_LDFLAGS = $(FreeType_LDFLAGS)
257 build/tests/FTBench.o: $(tasks)/build_freetype
262 MSPackHelper_CFLAGS = -Iupstream/build/libmspack/mspack
263 MSPackHelper_LDFLAGS = -Lupstream/build/libmspack/mspack -lmspack
264 build/tests/MSPackHelper.o: $(mips_objects) $(tasks)/build_libmspack
265 build/tests/MSPack.class: build/tests/MSPackHelper.class
267 MSPackBench_CFLAGS = -Iupstream/build/libmspack/mspack
268 MSPackBench_LDFLAGS = -Lupstream/build/libmspack/mspack -lmspack
269 build/tests/MSPackBench.o: $(tasks)/build_libmspack
274 build/tests/Echo.class: build/tests/EchoHelper.class
279 DJpeg_COMPILERFLAGS = -o onepage,pagesize=8m
280 build/tests/DJpeg.mips: $(mips_objects) $(tasks)/build_libjpeg
281 @mkdir -p `dirname $@`
282 cp upstream/build/libjpeg/djpeg $@
287 BusyBox_COMPILERFLAGS = -o unixruntime
288 build/tests/BusyBox.mips: $(mips_object) $(tasks)/build_busybox
289 @mkdir -p `dirname $@`
290 cp upstream/build/busybox/busybox $@
292 busyboxtest: build/tests/BusyBox.class
293 $(JAVA) -cp build tests.BusyBox ash
298 build/tests/GCTest.mips: $(mips_objects) $(tasks)/build_boehmgc
299 @mkdir -p `dirname $@`
300 cp upstream/build/boehmgc/gctest $@
302 boehmgctest: build/tests/Env.class build/tests/GCTest.class
303 $(JAVA) -cp build tests.Env GC_PRINT_STATS=1 tests.GCTest
310 build/tests/SpeedTest.class: build/org/xwt/mips/Runtime.class
312 tmp/thebride_1280.jpg:
314 cd tmp && wget http://www.kill-bill.com/images/wallpaper/thebride_1280.jpg
316 oldspeedtest: build/tests/DJpeg.class tmp/thebride_1280.jpg
317 bash -c "time $(JAVA) -cp build tests.DJpeg -targa -outfile tmp/thebride_1280.tga tmp/thebride_1280.jpg"
318 @echo "e90f6b915aee2fc0d2eb9fc60ace6203 tmp/thebride_1280.tga" | md5sum -c && echo "MD5 is OK"
320 djpegspeedtest: build/tests/SpeedTest.class build/tests/DJpeg.class tmp/thebride_1280.jpg
321 @echo "Running DJpeg test..."
322 @$(JAVA) -cp build tests.SpeedTest tests.DJpeg 8 -targa -outfile tmp/thebride_1280.tga tmp/thebride_1280.jpg
324 mspackspeedtest: build/tests/SpeedTest.class build/tests/MSPackBench.class
325 @if [ -e tmp/mspack/comic32.exe ]; then \
326 echo "Running MSPackBench test..."; \
327 cd tmp/mspack && $(JAVA) -cp ../../build tests.SpeedTest tests.MSPackBench 20 *32.exe; \
329 echo "Run \"make check\" to get the MS True Type fonts for the MSPackBench test"; \
332 speedtest: build/tests/SpeedTest.class build/tests/DJpeg.class build/tests/FTBench.class tmp/thebride_1280.jpg build/tests/MSPackBench.class
333 @echo "Running DJpeg test..."
334 @$(JAVA) -cp build tests.SpeedTest tests.DJpeg 10 -targa -outfile tmp/thebride_1280.tga tmp/thebride_1280.jpg
335 @if [ -e tmp/mspack/Comic.TTF ]; then \
336 echo "Running FTBench test..."; \
337 $(JAVA) -cp build tests.SpeedTest tests.FTBench 10 tmp/mspack/Comic.TTF tmp/mspack/Comic.TTF.render; \
339 echo "Run \"make check\" to get Arial.TTF for the FTBench test"; \
341 @if false && [ -e tmp/mspack/comic32.exe ]; then \
342 echo "Running MSPackBench test..."; \
343 cd tmp/mspack && $(JAVA) -cp ../../build tests.SpeedTest tests.MSPackBench 10 *32.exe; \
345 echo "Run \"make check\" to get the MS True Type fonts for the MSPackBench test"; \
348 intspeed: build/tests/DJpeg.mips build/org/xwt/mips/Interpreter.class tmp/thebride_1280.jpg
349 time $(JAVA) -cp build org.xwt.mips.Interpreter build/tests/DJpeg.mips -targa -outfile tmp/thebride_1280.tga tmp/thebride_1280.jpg
350 @echo "e90f6b915aee2fc0d2eb9fc60ace6203 tmp/thebride_1280.tga" | md5sum -c && echo "MD5 is OK"
353 # Verification checks
356 check: $(patsubst %,build/tests/%.class, FTBench MSPackBench DJpeg GCTest) tmp/thebride_1280.jpg
357 @/bin/bash ./src/tests/check.sh running_from_make
359 compiletests: $(patsubst %,build/tests/%.class,FTBench MSPackBench DJpeg Test FreeTypeDemoHelper MSPackHelper EchoHelper BusyBox GCTest Fork)
364 doc/nestedvm.ivme04.pdf: doc/nestedvm.ivme04.tex doc/acmconf.cls
365 cd doc; pdflatex nestedvm.ivme04.tex && ./pst2pdf && pdflatex nestedvm.ivme04.tex
367 pdf: doc/nestedvm.ivme04.pdf
368 open doc/nestedvm.ivme04.pdf