env.sh fix
[nestedvm.git] / Makefile
1
2 # What to build
3 #
4
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)
7
8 # C sources that are part of the compiler/interpreter
9 mips_sources = crt0.c support_aux.c
10 mips_asm_sources = support.s
11
12 mips2java_root = $(shell pwd)
13 build = $(mips2java_root)/build
14 tasks = upstream/tasks
15
16 #
17 # MIPS Settings (don't change these)
18 #
19 flags = -march=mips1
20 MIPS_CC = mips-unknown-elf-gcc
21 MIPS_CXX = mips-unknown-elf-g++
22
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 \
26         -mmemcpy \
27         -ffunction-sections -fdata-sections \
28         -falign-functions=512 \
29         -fno-rename-registers \
30         -fno-schedule-insns \
31         -fno-delayed-branch \
32         -freduce-all-givs
33
34 MIPS_CFLAGS = $(mips_optflags) $(flags) -I. -Wall -Wno-unused -Werror
35 MIPS_LD = mips-unknown-elf-gcc
36 MIPS_LDFLAGS= \
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
40
41 # Java compiler/VM settings
42 JAVAC = javac
43 JAVA = java
44 ifeq ($(firstword $(JAVAC)),gcj)
45         JAVAC_NODEBUG_FLAGS = -g0
46 else
47         JAVAC_NODEBUG_FLAGS = -g:none
48 endif
49
50 bcel_jar = upstream/build/bcel-5.1/bcel-5.1.jar
51 classpath = build:$(bcel_jar)
52
53 GCJ = gcj
54 EXE_EXT = 
55
56 #####
57
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)
60
61 usr = $(mips2java_root)/upstream/install
62 PATH := $(usr)/bin:$(PATH)
63 export PATH
64
65 #
66 # General Build Stuff
67 #
68 all: $(java_classes) $(mips_objects)
69 ifdef NATIVE_MIPS2JAVA_COMPILER
70 all: build/mips2java$(EXE_EXT) $(mips_objects)
71 endif
72
73 $(tasks)/%:
74         $(MAKE) -C upstream tasks/$* usr="$(usr)" MIPS_LDFLAGS="$(MIPS_LDFLAGS)" MIPS_CFLAGS="$(flags) $(mips_optflags)"
75
76 upstream_clean_%:
77         $(MAKE) -C upstream clean_$* usr="$(usr)"
78
79 errno_h = $(usr)/mips-unknown-elf/include/sys/errno.h
80 $(errno_h): $(tasks)/build_newlib
81
82 unistd_h = $(usr)/mips-unknown-elf/include/sys/unistd.h
83 $(unistd_h): $(tasks)/build_newlib
84
85 #
86 # Interpreter/Compiler/Runtime Java Compilation
87 #
88
89 # This works around a gcj -C bug
90 ifeq ($(firstword $(JAVAC)),gcj)
91 build/org/xwt/mips/util/.Dummy.class:
92         mkdir -p `dirname $@`
93         touch $@
94 $(java_classes): build/org/xwt/mips/util/.Dummy.class
95 endif
96
97 $(java_classes): $(java_sources) $(bcel_jar)
98         $(JAVAC) -classpath $(classpath) -d build $(java_sources)
99
100 $(bcel_jar): upstream/tasks/extract_bcel
101         @true
102
103 # GCJ Stuff
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)
108
109 #
110 # MIPS Binary compilation
111 #
112 build/%.o: src/%.c $(tasks)/full_toolchain
113         @mkdir -p `dirname $@`
114         $(MIPS_CC) $(MIPS_CFLAGS) $($(notdir $*)_CFLAGS) -c -o $@ $<
115
116 build/%.o: src/%.s $(tasks)/full_toolchain
117         @mkdir -p `dirname $@`
118         $(MIPS_CC) -x assembler-with-cpp -c -o $@ $<
119
120 %.s: %.c $(tasks)/full_toolchain
121         $(MIPS_CC) $(MIPS_CFLAGS) $($(notdir $*)_CFLAGS) -c -S -o $@ $<
122
123 build/%.mips: build/%.o $(mips_objects)
124         $(MIPS_LD) -o $@ $< $(MIPS_LDFLAGS) $($(notdir $*)_LDFLAGS)
125
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 $@ $<
129
130 build/%.mips.stripped: build/%.mips
131         cp $< $@
132         $(MIPS_STRIP) -s $@
133
134 # MIPS Compiler generated class compilation
135 ifdef DO_JAVASOURCE
136
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
139
140 build/%.class: build/%.java build/org/xwt/mips/Runtime.class
141         $(JAVAC) $(JAVAC_NODEBUG_FLAGS) -classpath build -d build $<
142 else
143
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 /,.,$*) $<
146
147
148 endif
149
150 # General Java Class compilation
151 build/%.class: src/%.java
152         $(JAVAC) -classpath build -d build $<
153
154 clean:
155         rm -rf build/tests build/org/xwt/mips *.jar build/mips2java$(EXE_EXT)
156
157 #
158 # env.sh
159 #
160 env.sh: Makefile $(tasks)/full_toolchain build/org/xwt/mips/Compiler.class
161         @rm -f "$@~"
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' >> $@~
173         @mv "$@~" "$@"
174         @echo "$@ created successfully"
175
176 #
177 # Runtime.jar
178 #
179
180 runtime_util_classes = SeekableData SeekableByteArray SeekableFile SeekableInputStream
181 runtime_classes = Runtime Registers UsermodeConstants  $(runtime_util_classes:%=util/%)
182 unixruntime_classes = $(runtime_classes) UnixRuntime
183
184 runtime.jar: $(runtime_classes:%=build/org/xwt/mips/%.class)
185         cd build && jar cf ../$@ $(runtime_classes:%=org/xwt/mips/%*.class)
186
187 unixruntime.jar: $(unixruntime_classes:%=build/org/xwt/mips/%.class)
188         cd build && jar cf ../$@ $(unixruntime_classes:%=org/xwt/mips/%*.class)
189
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 $@`
193         cat $^ | ( \
194                 echo "// THIS FILE IS AUTOGENERATED! DO NOT EDIT!"; \
195                 echo "// run \"make rebuild-constants\" if it needs to be updated"; \
196                 echo ""; \
197                 echo "package org.xwt.mips;"; \
198                 echo "public interface UsermodeConstants {"; \
199                 tr '\t' ' ' | sed -n ' \
200                         s/  */ /g; \
201                         s/ *# *define \([A-Z_][A-Za-z0-9_]*\) \([0-9][0-9x]*\)/    public static final int \1 = \2;/p'; \
202                 echo "}"; \
203         ) > src/org/xwt/mips/UsermodeConstants.java
204         
205 #
206 # Tests
207 # These are simply here for convenience. They aren't required 
208 # to build or run mips2java
209 #
210
211 build/tests/Env.class: build/org/xwt/mips/Runtime.class build/org/xwt/mips/Interpreter.class
212
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
220
221 # CallTest
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`
225
226 # FDTest
227 build/tests/FDTest.class: build/tests/Test.class
228 fdtest: build/tests/FDTest.class
229         $(JAVA) -cp build tests.FDTest
230
231
232 # Simple
233 Simple_LDFLAGS = -nostdlib
234 simpletest: build/tests/Simple.class
235         $(JAVA) -cp build tests.Simple
236
237 # Paranoia
238 Paranoia_CFLAGS = "-Wno-error"
239 Paranoia_LDFLAGS = -lm
240 paranoiatest: build/tests/Paranoia.class
241         $(JAVA) -cp build tests.Paranoia
242         
243 #
244 # Freetype Stuff
245 #
246 FreeType_CFLAGS = -Iupstream/build/freetype/include
247 FreeType_LDFLAGS =  -Lupstream/build/freetype/objs -lfreetype
248
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
254
255 FTBench_CFLAGS =  $(FreeType_CFLAGS)
256 FTBench_LDFLAGS = $(FreeType_LDFLAGS)
257 build/tests/FTBench.o: $(tasks)/build_freetype
258
259 #
260 # MSPack Stuff
261 #
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
266
267 MSPackBench_CFLAGS = -Iupstream/build/libmspack/mspack
268 MSPackBench_LDFLAGS = -Lupstream/build/libmspack/mspack -lmspack
269 build/tests/MSPackBench.o: $(tasks)/build_libmspack
270
271 #
272 # Echo
273 #
274 build/tests/Echo.class: build/tests/EchoHelper.class
275
276 #
277 # Libjpeg
278 #
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 $@
283
284 #
285 # Busybox
286 #
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 $@
291         
292 busyboxtest: build/tests/BusyBox.class
293         $(JAVA) -cp build tests.BusyBox ash
294
295 #
296 # Boehm GC
297 #
298 build/tests/GCTest.mips: $(mips_objects) $(tasks)/build_boehmgc
299         @mkdir -p `dirname $@`
300         cp upstream/build/boehmgc/gctest $@
301
302 boehmgctest: build/tests/Env.class build/tests/GCTest.class
303         $(JAVA) -cp build tests.Env GC_PRINT_STATS=1  tests.GCTest
304
305
306 #
307 # Speed tests
308 #
309
310 build/tests/SpeedTest.class: build/org/xwt/mips/Runtime.class
311
312 tmp/thebride_1280.jpg:
313         @mkdir -p tmp
314         cd tmp && wget http://www.kill-bill.com/images/wallpaper/thebride_1280.jpg
315
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"
319
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
323
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; \
328         else \
329                 echo "Run \"make check\" to get the MS True Type fonts for the MSPackBench test"; \
330         fi
331
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; \
338         else \
339                 echo "Run \"make check\" to get Arial.TTF for the FTBench test"; \
340         fi
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; \
344         else \
345                 echo "Run \"make check\" to get the MS True Type fonts for the MSPackBench test"; \
346         fi
347
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"
351
352 #
353 # Verification checks
354 #
355
356 check: $(patsubst %,build/tests/%.class, FTBench MSPackBench DJpeg GCTest) tmp/thebride_1280.jpg
357         @/bin/bash ./src/tests/check.sh running_from_make
358
359 compiletests: $(patsubst %,build/tests/%.class,FTBench MSPackBench DJpeg Test FreeTypeDemoHelper MSPackHelper EchoHelper BusyBox GCTest Fork)
360         @true
361
362
363 # IVME Paper
364 doc/nestedvm.ivme04.pdf: doc/nestedvm.ivme04.tex doc/acmconf.cls
365         cd doc; pdflatex nestedvm.ivme04.tex && ./pst2pdf && pdflatex nestedvm.ivme04.tex
366
367 pdf: doc/nestedvm.ivme04.pdf
368         open doc/nestedvm.ivme04.pdf