Makefile 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. CLOSURE_DIR=closure-compiler
  2. CLOSURE=$(CLOSURE_DIR)/compiler.jar
  3. NASM_TEST_DIR=./tests/nasm
  4. INSTRUCTION_TABLES=src/rust/gen/jit.rs src/rust/gen/jit0f.rs \
  5. src/rust/gen/interpreter.rs src/rust/gen/interpreter0f.rs \
  6. src/rust/gen/analyzer.rs src/rust/gen/analyzer0f.rs \
  7. # Only the dependencies common to both generate_{jit,interpreter}.js
  8. GEN_DEPENDENCIES=$(filter-out gen/generate_interpreter.js gen/generate_jit.js gen/generate_analyzer.js, $(wildcard gen/*.js))
  9. JIT_DEPENDENCIES=$(GEN_DEPENDENCIES) gen/generate_jit.js
  10. INTERPRETER_DEPENDENCIES=$(GEN_DEPENDENCIES) gen/generate_interpreter.js
  11. ANALYZER_DEPENDENCIES=$(GEN_DEPENDENCIES) gen/generate_analyzer.js
  12. STRIP_DEBUG_FLAG=
  13. ifeq ($(STRIP_DEBUG),true)
  14. STRIP_DEBUG_FLAG=--v86-strip-debug
  15. endif
  16. default: build/v86-debug.wasm
  17. all: build/v86_all.js build/libv86.js build/v86.wasm
  18. all-debug: build/libv86-debug.js build/v86-debug.wasm
  19. browser: build/v86_all.js
  20. # Used for nodejs builds and in order to profile code.
  21. # `debug` gives identifiers a readable name, make sure it doesn't have any side effects.
  22. CLOSURE_READABLE=--formatting PRETTY_PRINT --debug
  23. CLOSURE_SOURCE_MAP=\
  24. --source_map_format V3\
  25. --create_source_map '%outname%.map'
  26. #--jscomp_error reportUnknownTypes\
  27. #--jscomp_error unusedLocalVariables\
  28. #--jscomp_error unusedPrivateMembers\
  29. #--new_type_inf\
  30. # Easily breaks code:
  31. #--assume_function_wrapper\
  32. # implies new type inferrence
  33. #--jscomp_error newCheckTypes\
  34. CLOSURE_FLAGS=\
  35. --generate_exports\
  36. --externs src/externs.js\
  37. --warning_level VERBOSE\
  38. --jscomp_error accessControls\
  39. --jscomp_error checkRegExp\
  40. --jscomp_error checkTypes\
  41. --jscomp_error checkVars\
  42. --jscomp_error conformanceViolations\
  43. --jscomp_error const\
  44. --jscomp_error constantProperty\
  45. --jscomp_error deprecated\
  46. --jscomp_error deprecatedAnnotations\
  47. --jscomp_error duplicateMessage\
  48. --jscomp_error es5Strict\
  49. --jscomp_error externsValidation\
  50. --jscomp_error globalThis\
  51. --jscomp_error invalidCasts\
  52. --jscomp_error misplacedTypeAnnotation\
  53. --jscomp_error missingGetCssName\
  54. --jscomp_error missingProperties\
  55. --jscomp_error missingReturn\
  56. --jscomp_error msgDescriptions\
  57. --jscomp_error nonStandardJsDocs\
  58. --jscomp_error suspiciousCode\
  59. --jscomp_error strictModuleDepCheck\
  60. --jscomp_error typeInvalidation\
  61. --jscomp_error undefinedNames\
  62. --jscomp_error undefinedVars\
  63. --jscomp_error unknownDefines\
  64. --jscomp_error visibility\
  65. --use_types_for_optimization\
  66. --summary_detail_level 3\
  67. --language_in ECMASCRIPT_2017\
  68. --language_out ECMASCRIPT_2017
  69. CARGO_FLAGS=\
  70. --target wasm32-unknown-unknown \
  71. -- \
  72. -C linker=tools/rust-lld-wrapper \
  73. -C link-args="--import-table --global-base=18874368 $(STRIP_DEBUG_FLAG)" \
  74. --verbose
  75. CORE_FILES=const.js config.js io.js main.js lib.js ide.js pci.js floppy.js \
  76. memory.js dma.js pit.js vga.js ps2.js pic.js rtc.js uart.js hpet.js acpi.js apic.js ioapic.js \
  77. state.js ne2k.js virtio.js bus.js log.js \
  78. cpu.js debug.js \
  79. elf.js kernel.js
  80. LIB_FILES=9p.js filesystem.js jor1k.js marshall.js utf8.js
  81. BROWSER_FILES=screen.js \
  82. keyboard.js mouse.js serial.js \
  83. network.js lib.js starter.js worker_bus.js dummy_screen.js print_stats.js filestorage.js
  84. RUST_FILES=$(shell find src/rust/ -name '*.rs') \
  85. src/rust/gen/interpreter.rs src/rust/gen/interpreter0f.rs \
  86. src/rust/gen/jit.rs src/rust/gen/jit0f.rs \
  87. src/rust/gen/analyzer.rs src/rust/gen/analyzer0f.rs
  88. CORE_FILES:=$(addprefix src/,$(CORE_FILES))
  89. LIB_FILES:=$(addprefix lib/,$(LIB_FILES))
  90. BROWSER_FILES:=$(addprefix src/browser/,$(BROWSER_FILES))
  91. build/v86_all.js: $(CLOSURE) src/*.js src/browser/*.js lib/*.js
  92. mkdir -p build
  93. -ls -lh build/v86_all.js
  94. java -jar $(CLOSURE) \
  95. --js_output_file build/v86_all.js\
  96. --define=DEBUG=false\
  97. $(CLOSURE_SOURCE_MAP)\
  98. $(CLOSURE_FLAGS)\
  99. --compilation_level ADVANCED\
  100. --js $(CORE_FILES)\
  101. --js $(LIB_FILES)\
  102. --js $(BROWSER_FILES)\
  103. --js src/browser/main.js
  104. echo '//# sourceMappingURL=v86_all.js.map' >> build/v86_all.js
  105. ls -lh build/v86_all.js
  106. build/libv86.js: $(CLOSURE) src/*.js lib/*.js src/browser/*.js
  107. mkdir -p build
  108. -ls -lh build/libv86.js
  109. java -jar $(CLOSURE) \
  110. --js_output_file build/libv86.js\
  111. --define=DEBUG=false\
  112. $(CLOSURE_FLAGS)\
  113. --compilation_level SIMPLE\
  114. --output_wrapper ';(function(){%output%}).call(this);'\
  115. --js $(CORE_FILES)\
  116. --js $(BROWSER_FILES)\
  117. --js $(LIB_FILES)
  118. ls -lh build/libv86.js
  119. build/libv86-debug.js: $(CLOSURE) src/*.js lib/*.js src/browser/*.js
  120. mkdir -p build
  121. java -jar $(CLOSURE) \
  122. --js_output_file build/libv86-debug.js\
  123. --define=DEBUG=true\
  124. $(CLOSURE_FLAGS)\
  125. $(CLOSURE_READABLE)\
  126. --compilation_level SIMPLE\
  127. --output_wrapper ';(function(){%output%}).call(this);'\
  128. --js $(CORE_FILES)\
  129. --js $(BROWSER_FILES)\
  130. --js $(LIB_FILES)
  131. .PHONY: instruction_tables
  132. instruction_tables: $(INSTRUCTION_TABLES)
  133. src/rust/gen/jit.rs: $(JIT_DEPENDENCIES)
  134. ./gen/generate_jit.js --output-dir build/ --table jit
  135. src/rust/gen/jit0f.rs: $(JIT_DEPENDENCIES)
  136. ./gen/generate_jit.js --output-dir build/ --table jit0f
  137. src/rust/gen/interpreter.rs: $(INTERPRETER_DEPENDENCIES)
  138. ./gen/generate_interpreter.js --output-dir build/ --table interpreter
  139. src/rust/gen/interpreter0f.rs: $(INTERPRETER_DEPENDENCIES)
  140. ./gen/generate_interpreter.js --output-dir build/ --table interpreter0f
  141. src/rust/gen/analyzer.rs: $(ANALYZER_DEPENDENCIES)
  142. ./gen/generate_analyzer.js --output-dir build/ --table analyzer
  143. src/rust/gen/analyzer0f.rs: $(ANALYZER_DEPENDENCIES)
  144. ./gen/generate_analyzer.js --output-dir build/ --table analyzer0f
  145. build/v86.wasm: $(RUST_FILES) Cargo.toml
  146. mkdir -p build/
  147. -ls -lh build/v86.wasm
  148. cargo +nightly rustc --release $(CARGO_FLAGS)
  149. mv build/wasm32-unknown-unknown/release/v86.wasm build/v86.wasm
  150. ls -lh build/v86.wasm
  151. build/v86-debug.wasm: $(RUST_FILES) Cargo.toml
  152. mkdir -p build/
  153. -ls -lh build/v86-debug.wasm
  154. cargo +nightly rustc $(CARGO_FLAGS)
  155. mv build/wasm32-unknown-unknown/debug/v86.wasm build/v86-debug.wasm
  156. ls -lh build/v86-debug.wasm
  157. clean:
  158. -rm build/libv86.js
  159. -rm build/libv86-debug.js
  160. -rm build/v86_all.js
  161. -rm build/v86.wasm
  162. -rm build/v86-debug.wasm
  163. -rm $(INSTRUCTION_TABLES)
  164. -rm build/*.map
  165. -rm build/*.wast
  166. $(MAKE) -C $(NASM_TEST_DIR) clean
  167. run:
  168. python3 -m http.server 2> /dev/null
  169. update_version:
  170. set -e ;\
  171. COMMIT=`git log --format="%h" -n 1` ;\
  172. DATE=`git log --date="format:%b %e, %Y %H:%m" --format="%cd" -n 1` ;\
  173. SEARCH='<code>Version: <a href="https://github.com/copy/v86/commits/[a-f0-9]\+">[a-f0-9]\+</a> ([^(]\+)</code>' ;\
  174. REPLACE='<code>Version: <a href="https://github.com/copy/v86/commits/'$$COMMIT'">'$$COMMIT'</a> ('$$DATE')</code>' ;\
  175. sed -i "s@$$SEARCH@$$REPLACE@g" index.html ;\
  176. grep $$COMMIT index.html
  177. $(CLOSURE):
  178. wget -nv -P $(CLOSURE_DIR) http://dl.google.com/closure-compiler/compiler-latest.zip
  179. unzip -d closure-compiler $(CLOSURE_DIR)/compiler-latest.zip \*.jar
  180. mv $(CLOSURE_DIR)/*.jar $(CLOSURE)
  181. rm $(CLOSURE_DIR)/compiler-latest.zip
  182. tests: all-debug
  183. mkdir -p images/integration-test-fs/flat # XXX
  184. cp images/bzImage images/integration-test-fs/
  185. touch images/integration-test-fs/initrd
  186. cd images/integration-test-fs && tar cfv fs.tar bzImage initrd
  187. ./tools/fs2json.py images/integration-test-fs/fs.tar --out images/integration-test-fs/fs.json
  188. ./tools/copy-to-sha256.py images/integration-test-fs/fs.tar images/integration-test-fs/flat
  189. ./tests/full/run.js
  190. tests-release: all
  191. mkdir -p images/integration-test-fs/flat # XXX
  192. cp images/bzImage images/integration-test-fs/
  193. touch images/integration-test-fs/initrd
  194. cd images/integration-test-fs && tar cfv fs.tar bzImage initrd
  195. ./tools/fs2json.py images/integration-test-fs/fs.tar --out images/integration-test-fs/fs.json
  196. ./tools/copy-to-sha256.py images/integration-test-fs/fs.tar images/integration-test-fs/flat
  197. TEST_RELEASE_BUILD=1 ./tests/full/run.js
  198. nasmtests: all-debug
  199. $(MAKE) -C $(NASM_TEST_DIR) all
  200. $(NASM_TEST_DIR)/gen_fixtures.js
  201. $(NASM_TEST_DIR)/run.js
  202. nasmtests-force-jit: all-debug
  203. $(MAKE) -C $(NASM_TEST_DIR) all
  204. $(NASM_TEST_DIR)/gen_fixtures.js
  205. $(NASM_TEST_DIR)/run.js --force-jit
  206. jitpagingtests: all-debug
  207. $(MAKE) -C tests/jit-paging test-jit
  208. ./tests/jit-paging/run.js
  209. qemutests: all-debug
  210. $(MAKE) -C tests/qemu test-i386
  211. ./tests/qemu/run.js > /tmp/v86-test-result
  212. #./tests/qemu/test-i386 > /tmp/v86-test-reference
  213. ./tests/qemu/run-qemu.js > /tmp/v86-test-reference
  214. diff /tmp/v86-test-result /tmp/v86-test-reference
  215. kvm-unit-test: all-debug
  216. (cd tests/kvm-unit-tests && ./configure && make)
  217. tests/kvm-unit-tests/run.js tests/kvm-unit-tests/x86/realmode.flat
  218. kvm-unit-test-release: all
  219. (cd tests/kvm-unit-tests && ./configure && make)
  220. TEST_RELEASE_BUILD=1 tests/kvm-unit-tests/run.js tests/kvm-unit-tests/x86/realmode.flat
  221. expect-tests: all-debug build/libwabt.js
  222. make -C tests/expect/tests
  223. ./tests/expect/run.js
  224. devices-test: all-debug
  225. ./tests/devices/virtio_9p.js
  226. rust-test: $(RUST_FILES)
  227. # RUSTFLAGS="-D warnings"
  228. env RUST_BACKTRACE=full RUST_TEST_THREADS=1 cargo +nightly test -- --nocapture
  229. ./tests/rust/verify-wasmgen-dummy-output.js
  230. rust-no-warnings:
  231. RUSTFLAGS="-D warnings" make all all-debug
  232. rust-test-intensive:
  233. QUICKCHECK_TESTS=100000000 make rust-test
  234. api-tests: all-debug
  235. ./tests/api/clean-shutdown.js
  236. ./tests/api/state.js
  237. ./tests/api/reset.js
  238. all-tests: jshint kvm-unit-test expect-tests qemutests jitpagingtests api-tests rust-test nasmtests nasmtests-force-jit tests
  239. # Skipping:
  240. # - debiantests (requires network)
  241. # - devices-test (hangs)
  242. jshint:
  243. jshint --config=./.jshint.json src tests gen lib --exclude lib/closure-base.js
  244. rustfmt: $(RUST_FILES)
  245. cargo +nightly fmt --all -- --check
  246. build/capstone-x86.min.js:
  247. mkdir -p build
  248. wget -P build https://github.com/AlexAltea/capstone.js/releases/download/v3.0.5-rc1/capstone-x86.min.js
  249. build/libwabt.js:
  250. mkdir -p build
  251. wget -P build https://github.com/WebAssembly/wabt/archive/1.0.6.zip
  252. unzip -j -d build/ build/1.0.6.zip wabt-1.0.6/demo/libwabt.js
  253. rm build/1.0.6.zip
  254. build/xterm.js:
  255. curl https://cdn.jsdelivr.net/npm/xterm@4.2.0-vscode1/lib/xterm.js > build/xterm.js
  256. curl https://cdn.jsdelivr.net/npm/xterm@4.2.0-vscode1/lib/xterm.js.map > build/xterm.js.map
  257. curl https://cdn.jsdelivr.net/npm/xterm@4.2.0-vscode1/css/xterm.css > build/xterm.css