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