1
0

Makefile 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. CLOSURE_DIR=closure-compiler
  2. CLOSURE=$(CLOSURE_DIR)/compiler.jar
  3. BROWSER=chromium
  4. NASM_TEST_DIR=./tests/nasm
  5. COVERAGE_DIR=./tests/coverage
  6. INSTRUCTION_TABLES=build/jit.c build/jit0f_16.c build/jit0f_32.c \
  7. build/interpreter.c build/interpreter0f_16.c build/interpreter0f_32.c \
  8. build/analyzer.c build/analyzer0f_16.c build/analyzer0f_32.c \
  9. # Only the dependencies common to both generate_{jit,interpreter}.js
  10. GEN_DEPENDENCIES=$(filter-out gen/generate_interpreter.js gen/generate_jit.js gen/generate_analyzer.js, $(wildcard gen/*.js))
  11. JIT_DEPENDENCIES=$(GEN_DEPENDENCIES) gen/generate_jit.js
  12. INTERPRETER_DEPENDENCIES=$(GEN_DEPENDENCIES) gen/generate_interpreter.js
  13. ANALYZER_DEPENDENCIES=$(GEN_DEPENDENCIES) gen/generate_analyzer.js
  14. # Enable manually and recompile v86-debug.wasm for coverage-enabled tests
  15. ifeq ($(ENABLE_COV), 1)
  16. CC_COVERAGE_FLAGS=--coverage -fprofile-instr-generate
  17. endif
  18. ifeq ($(JIT_ALWAYS),)
  19. JIT_ALWAYS=false
  20. endif
  21. all: build/v86_all.js
  22. browser: build/v86_all.js
  23. wasm: build/v86.wasm
  24. # Used for nodejs builds and in order to profile code.
  25. # `debug` gives identifiers a readable name, make sure it doesn't have any side effects.
  26. CLOSURE_READABLE=--formatting PRETTY_PRINT --debug
  27. CLOSURE_SOURCE_MAP=\
  28. --source_map_format V3\
  29. --create_source_map '%outname%.map'
  30. #--jscomp_error reportUnknownTypes\
  31. #--jscomp_error unusedLocalVariables\
  32. #--jscomp_error unusedPrivateMembers\
  33. #--new_type_inf\
  34. # Easily breaks code:
  35. #--assume_function_wrapper\
  36. # implies new type inferrence
  37. #--jscomp_error newCheckTypes\
  38. CLOSURE_FLAGS=\
  39. --js lib/closure-base.js\
  40. --generate_exports\
  41. --externs src/externs.js\
  42. --warning_level VERBOSE\
  43. --jscomp_error accessControls\
  44. --jscomp_error ambiguousFunctionDecl\
  45. --jscomp_error checkEventfulObjectDisposal\
  46. --jscomp_error checkRegExp\
  47. --jscomp_error checkTypes\
  48. --jscomp_error checkVars\
  49. --jscomp_error conformanceViolations\
  50. --jscomp_error const\
  51. --jscomp_error constantProperty\
  52. --jscomp_error deprecated\
  53. --jscomp_error deprecatedAnnotations\
  54. --jscomp_error duplicateMessage\
  55. --jscomp_error es3\
  56. --jscomp_error es5Strict\
  57. --jscomp_error externsValidation\
  58. --jscomp_error fileoverviewTags\
  59. --jscomp_error globalThis\
  60. --jscomp_error internetExplorerChecks\
  61. --jscomp_error invalidCasts\
  62. --jscomp_error misplacedTypeAnnotation\
  63. --jscomp_error missingGetCssName\
  64. --jscomp_error missingProperties\
  65. --jscomp_error missingReturn\
  66. --jscomp_error msgDescriptions\
  67. --jscomp_error nonStandardJsDocs\
  68. --jscomp_error suspiciousCode\
  69. --jscomp_error strictModuleDepCheck\
  70. --jscomp_error typeInvalidation\
  71. --jscomp_error undefinedNames\
  72. --jscomp_error undefinedVars\
  73. --jscomp_error unknownDefines\
  74. --jscomp_error visibility\
  75. --use_types_for_optimization\
  76. --summary_detail_level 3\
  77. --language_in ECMASCRIPT5_STRICT
  78. TRANSPILE_ES6_FLAGS=\
  79. --language_in ECMASCRIPT6_STRICT\
  80. --language_out ECMASCRIPT5_STRICT\
  81. CC_FLAGS=\
  82. -std=c11 \
  83. -Isrc/native/ \
  84. -Wall -Wpedantic -Wextra \
  85. -Wno-bitwise-op-parentheses -Wno-gnu-binary-literal \
  86. -fcolor-diagnostics \
  87. -fwrapv \
  88. -g4 \
  89. -s LEGALIZE_JS_FFI=0 \
  90. -s "BINARYEN_TRAP_MODE='allow'" \
  91. -s WASM=1 \
  92. -s SIDE_MODULE=1
  93. CORE_FILES=const.js config.js io.js main.js lib.js coverage.js ide.js pci.js floppy.js \
  94. memory.js dma.js pit.js vga.js ps2.js pic.js rtc.js uart.js hpet.js acpi.js apic.js ioapic.js \
  95. state.js ne2k.js virtio.js bus.js log.js \
  96. cpu.js debug.js \
  97. elf.js codegen.js
  98. LIB_FILES=9p.js filesystem.js jor1k.js marshall.js utf8.js
  99. BROWSER_FILES=screen.js \
  100. keyboard.js mouse.js serial.js \
  101. network.js lib.js starter.js worker_bus.js dummy_screen.js print_stats.js
  102. CORE_FILES:=$(addprefix src/,$(CORE_FILES))
  103. LIB_FILES:=$(addprefix lib/,$(LIB_FILES))
  104. BROWSER_FILES:=$(addprefix src/browser/,$(BROWSER_FILES))
  105. build/v86_all.js: $(CLOSURE) src/*.js src/browser/*.js lib/*.js
  106. mkdir -p build
  107. -ls -lh build/v86_all.js
  108. java -jar $(CLOSURE) \
  109. --js_output_file build/v86_all.js\
  110. --define=DEBUG=false\
  111. $(CLOSURE_SOURCE_MAP)\
  112. $(CLOSURE_FLAGS)\
  113. --compilation_level ADVANCED\
  114. $(TRANSPILE_ES6_FLAGS)\
  115. --js $(CORE_FILES)\
  116. --js $(LIB_FILES)\
  117. --js $(BROWSER_FILES)\
  118. --js src/browser/main.js
  119. echo '//# sourceMappingURL=v86_all.js.map' >> build/v86_all.js
  120. ls -lh build/v86_all.js
  121. build/libv86.js: $(CLOSURE) src/*.js lib/*.js src/browser/*.js
  122. mkdir -p build
  123. -ls -lh build/libv86.js
  124. java -jar $(CLOSURE) \
  125. --js_output_file build/libv86.js\
  126. --define=DEBUG=false\
  127. $(CLOSURE_FLAGS)\
  128. --compilation_level SIMPLE\
  129. $(TRANSPILE_ES6_FLAGS)\
  130. --output_wrapper ';(function(){%output%}).call(this);'\
  131. --js $(CORE_FILES)\
  132. --js $(BROWSER_FILES)\
  133. --js $(LIB_FILES)
  134. ls -lh build/libv86.js
  135. build/libv86-debug.js: $(CLOSURE) src/*.js lib/*.js src/browser/*.js
  136. mkdir -p build
  137. java -jar $(CLOSURE) \
  138. --js_output_file build/libv86-debug.js\
  139. --define=DEBUG=true\
  140. $(CLOSURE_FLAGS)\
  141. $(CLOSURE_READABLE)\
  142. --compilation_level SIMPLE\
  143. $(TRANSPILE_ES6_FLAGS)\
  144. --output_wrapper ';(function(){%output%}).call(this);'\
  145. --js $(CORE_FILES)\
  146. --js $(BROWSER_FILES)\
  147. --js $(LIB_FILES)
  148. .PHONY: instruction_tables
  149. instruction_tables: $(INSTRUCTION_TABLES)
  150. build/jit.c: $(JIT_DEPENDENCIES)
  151. ./gen/generate_jit.js --output-dir build/ --table jit
  152. build/jit0f_16.c: $(JIT_DEPENDENCIES)
  153. ./gen/generate_jit.js --output-dir build/ --table jit0f_16
  154. build/jit0f_32.c: $(JIT_DEPENDENCIES)
  155. ./gen/generate_jit.js --output-dir build/ --table jit0f_32
  156. build/interpreter.c: $(INTERPRETER_DEPENDENCIES)
  157. ./gen/generate_interpreter.js --output-dir build/ --table interpreter
  158. build/interpreter0f_16.c: $(INTERPRETER_DEPENDENCIES)
  159. ./gen/generate_interpreter.js --output-dir build/ --table interpreter0f_16
  160. build/interpreter0f_32.c: $(INTERPRETER_DEPENDENCIES)
  161. ./gen/generate_interpreter.js --output-dir build/ --table interpreter0f_32
  162. build/analyzer.c: $(ANALYZER_DEPENDENCIES)
  163. ./gen/generate_analyzer.js --output-dir build/ --table analyzer
  164. build/analyzer0f_16.c: $(ANALYZER_DEPENDENCIES)
  165. ./gen/generate_analyzer.js --output-dir build/ --table analyzer0f_16
  166. build/analyzer0f_32.c: $(ANALYZER_DEPENDENCIES)
  167. ./gen/generate_analyzer.js --output-dir build/ --table analyzer0f_32
  168. .PHONY: phony
  169. build/JIT_ALWAYS: phony
  170. @if [[ `cat build/JIT_ALWAYS 2>&1` != '$(JIT_ALWAYS)' ]]; then \
  171. echo -n $(JIT_ALWAYS) > build/JIT_ALWAYS ; \
  172. fi
  173. build/v86.wasm: src/native/*.c src/native/*.h src/native/codegen/*.c src/native/codegen/*.h src/native/profiler/* src/native/*.ll $(INSTRUCTION_TABLES) build/JIT_ALWAYS
  174. mkdir -p build
  175. -ls -lh build/v86.wasm
  176. emcc src/native/*.c src/native/profiler/*.c src/native/codegen/codegen.c src/native/*.ll \
  177. $(CC_FLAGS) \
  178. -DDEBUG=false \
  179. -DNDEBUG \
  180. -D"ENABLE_JIT_ALWAYS=$(JIT_ALWAYS)" \
  181. -O3 \
  182. --llvm-opts 3 \
  183. --llvm-lto 3 \
  184. -o build/v86.wasm
  185. ls -lh build/v86.wasm
  186. build/v86-debug.wasm: src/native/*.c src/native/*.h src/native/codegen/*.c src/native/codegen/*.h src/native/profiler/* src/native/*.ll $(INSTRUCTION_TABLES) build/JIT_ALWAYS
  187. mkdir -p build/coverage
  188. -ls -lh build/v86-debug.wasm
  189. emcc src/native/*.c src/native/profiler/*.c src/native/codegen/codegen.c src/native/*.ll \
  190. $(CC_FLAGS) \
  191. $(CC_COVERAGE_FLAGS) \
  192. -D"ENABLE_JIT_ALWAYS=$(JIT_ALWAYS)" \
  193. -Os \
  194. -o build/v86-debug.wasm
  195. ls -lh build/v86-debug.wasm
  196. build/codegen-test.wasm: src/native/*.c src/native/*.h src/native/codegen/*.c src/native/codegen/*.h
  197. mkdir -p build
  198. -ls -lh build/codegen-test.wasm
  199. emcc src/native/codegen/codegen.c \
  200. $(CC_FLAGS) \
  201. -Os \
  202. -o build/codegen-test.wasm
  203. ls -lh build/codegen-test.wasm
  204. clean:
  205. -rm build/libv86.js
  206. -rm build/libv86-debug.js
  207. -rm build/v86_all.js
  208. -rm build/v86.wasm
  209. -rm build/v86-debug.wasm
  210. -rm build/codegen-test.wasm
  211. -rm $(INSTRUCTION_TABLES)
  212. -rm $(addsuffix .bak,$(INSTRUCTION_TABLES))
  213. -rm $(addsuffix .diff,$(INSTRUCTION_TABLES))
  214. -rm build/*.map
  215. -rm build/*.wast
  216. -rm build/coverage/coverage_data*
  217. -rm $(COVERAGE_DIR)/build/*
  218. $(MAKE) -C $(NASM_TEST_DIR) clean
  219. run:
  220. python2 -m SimpleHTTPServer 2> /dev/null
  221. #sleep 1
  222. #$(BROWSER) http://localhost:8000/index.html &
  223. update_version:
  224. set -e ;\
  225. COMMIT=`git log --format="%h" -n 1` ;\
  226. DATE=`git log --date="format:%b %e, %Y %H:%m" --format="%cd" -n 1` ;\
  227. SEARCH='<code>Version: <a href="https://github.com/copy/v86/commits/[a-f0-9]\+">[a-f0-9]\+</a> ([^(]\+)</a></code>' ;\
  228. REPLACE='<code>Version: <a href="https://github.com/copy/v86/commits/'$$COMMIT'">'$$COMMIT'</a> ('$$DATE')</a></code>' ;\
  229. sed -i "s@$$SEARCH@$$REPLACE@g" index.html ;\
  230. grep $$COMMIT index.html
  231. $(CLOSURE):
  232. wget -nv -P $(CLOSURE_DIR) http://dl.google.com/closure-compiler/compiler-latest.zip
  233. unzip -d closure-compiler $(CLOSURE_DIR)/compiler-latest.zip \*.jar
  234. mv $(CLOSURE_DIR)/*.jar $(CLOSURE)
  235. rm $(CLOSURE_DIR)/compiler-latest.zip
  236. tests: build/libv86.js build/v86.wasm
  237. ./tests/full/run.js
  238. nasmtests: build/libv86-debug.js build/v86-debug.wasm
  239. $(MAKE) -C $(NASM_TEST_DIR) all
  240. $(NASM_TEST_DIR)/gen_fixtures.js
  241. $(NASM_TEST_DIR)/run.js
  242. nasmtests-force-jit: build/libv86-debug.js build/v86-debug.wasm
  243. $(MAKE) -C $(NASM_TEST_DIR) all
  244. $(NASM_TEST_DIR)/gen_fixtures.js
  245. $(NASM_TEST_DIR)/run.js --force-jit
  246. jitpagingtests: build/libv86-debug.js build/v86-debug.wasm
  247. $(MAKE) -C tests/jit-paging test-jit
  248. ./tests/jit-paging/run.js
  249. qemutests: build/libv86-debug.js build/v86-debug.wasm
  250. $(MAKE) -C tests/qemu test-i386
  251. ./tests/qemu/run.js > /tmp/v86-test-result
  252. #./tests/qemu/test-i386 > /tmp/v86-test-reference
  253. ./tests/qemu/run-qemu.js > /tmp/v86-test-reference
  254. diff /tmp/v86-test-result /tmp/v86-test-reference
  255. kvm-unit-test: build/libv86-debug.js build/v86-debug.wasm
  256. (cd tests/kvm-unit-tests && ./configure)
  257. $(MAKE) -C tests/kvm-unit-tests
  258. tests/kvm-unit-tests/run.js tests/kvm-unit-tests/x86/realmode.flat
  259. codegen-test: build/codegen-test.wasm
  260. ./tests/codegen/codegen.js
  261. expect-tests: build/libv86-debug.js build/v86-debug.wasm build/libwabt.js
  262. make -C tests/expect/tests
  263. ./tests/expect/run.js
  264. covreport:
  265. mkdir -p $(COVERAGE_DIR)/build/
  266. $(COVERAGE_DIR)/gen_report.js
  267. node_modules/.bin/jshint:
  268. npm install
  269. jshint: node_modules/.bin/jshint
  270. ./node_modules/.bin/jshint --config=./.jshint.json src tests gen
  271. build/capstone-x86.min.js:
  272. mkdir -p build
  273. wget -P build https://github.com/AlexAltea/capstone.js/releases/download/v3.0.5-rc1/capstone-x86.min.js
  274. build/libwabt.js:
  275. mkdir -p build
  276. wget -P build https://raw.githubusercontent.com/WebAssembly/wabt/master/demo/libwabt.js
  277. clang-tidy:
  278. clang-tidy \
  279. src/native/*.c src/native/*.h \
  280. src/native/profiler/*.c src/native/profiler/*.h \
  281. src/native/codegen/*.c src/native/codegen/*.h \
  282. -- -I src/native/ -Wall -Wno-bitwise-op-parentheses -Wno-gnu-binary-literal