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