makefile 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. ## Copyright (C) 2016 Jeremiah Orians
  2. ## This file is part of stage0.
  3. ##
  4. ## stage0 is free software: you can redistribute it and/or modify
  5. ## it under the terms of the GNU General Public License as published by
  6. ## the Free Software Foundation, either version 3 of the License, or
  7. ## (at your option) any later version.
  8. ##
  9. ## stage0 is distributed in the hope that it will be useful,
  10. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ## GNU General Public License for more details.
  13. ##
  14. ## You should have received a copy of the GNU General Public License
  15. ## along with stage0. If not, see <http://www.gnu.org/licenses/>.
  16. # Don't rebuild the built things in bin or roms
  17. VPATH = bin:roms:prototypes:stage1/High_level_prototypes:stage2/High_level_prototypes
  18. # Collections of tools
  19. all: libvm.so vm ALL-ROMS ALL-PROTOTYPES
  20. production: libvm-production.so vm-production asm dis ALL-ROMS
  21. development: vm libvm.so asm dis ALL-ROMS
  22. # VM Builds
  23. vm-minimal: vm.h vm_types.h vm_globals.c vm_minimal.c vm_instructions.c vm_halcode.c vm_decode.c functions/require.c functions/file_print.c functions/match.c | bin
  24. $(CC) -DVM32=true vm_minimal.c vm_globals.c vm_instructions.c vm_halcode.c vm_decode.c functions/require.c functions/file_print.c functions/match.c -o bin/vm-minimal
  25. vm16: vm.h vm_types.h vm_globals.c vm.c vm_instructions.c vm_halcode.c vm_decode.c tty.c functions/require.c functions/file_print.c functions/match.c | bin
  26. $(CC) -ggdb -DVM16=true -Dtty_lib=true vm.c vm_globals.c vm_instructions.c vm_halcode.c vm_decode.c tty.c functions/require.c functions/file_print.c functions/match.c -o bin/vm16
  27. vm: vm.h vm_types.h vm_globals.c vm.c vm_instructions.c vm_halcode.c vm_decode.c tty.c functions/require.c functions/file_print.c functions/match.c | bin
  28. $(CC) -ggdb -DVM32=true -Dtty_lib=true vm.c vm_globals.c vm_instructions.c vm_halcode.c vm_decode.c tty.c functions/require.c functions/file_print.c functions/match.c -o bin/vm
  29. vm64: vm.h vm_types.h vm_globals.c vm.c vm_instructions.c vm_halcode.c vm_decode.c tty.c functions/require.c functions/file_print.c functions/match.c | bin
  30. $(CC) -ggdb -DVM64=true -Dtty_lib=true vm.c vm_globals.c vm_instructions.c vm_halcode.c vm_decode.c tty.c functions/require.c functions/file_print.c functions/match.c -o bin/vm64
  31. vm-production: vm.h vm_types.h vm_globals.c vm.c vm_instructions.c vm_halcode.c vm_decode.c functions/require.c functions/file_print.c functions/match.c | bin
  32. $(CC) -DVM32=true vm.c vm_globals.c vm_instructions.c vm_halcode.c vm_decode.c functions/require.c functions/file_print.c functions/match.c -o bin/vm-production
  33. vm-trace: vm.h vm_types.h vm_globals.c vm.c vm_instructions.c vm_halcode.c vm_decode.c tty.c dynamic_execution_trace.c functions/require.c functions/file_print.c functions/match.c | bin
  34. $(CC) -DVM32=true -ggdb -Dtty_lib=true -DTRACE=true vm.c vm_globals.c vm_instructions.c vm_halcode.c vm_decode.c tty.c dynamic_execution_trace.c functions/require.c functions/file_print.c functions/match.c -o bin/vm
  35. # Build the roms
  36. ALL-ROMS: stage0_monitor stage1_assembler-0 SET DEHEX stage1_assembler-1 stage1_assembler-2 M0 CAT lisp cc_x86 forth
  37. stage0_monitor: vm stage0/stage0_monitor.hex0 | roms
  38. ./bin/vm --rom seed/NATIVE/knight/hex0-seed --tape_01 stage0/stage0_monitor.hex0 --tape_02 roms/stage0_monitor
  39. stage1_assembler-0: vm stage1/stage1_assembler-0.hex0 | roms
  40. ./bin/vm --rom seed/NATIVE/knight/hex0-seed --tape_01 stage1/stage1_assembler-0.hex0 --tape_02 roms/stage1_assembler-0
  41. SET: stage1_assembler-2 vm stage1/SET.hex2 | roms
  42. ./bin/vm --rom roms/stage1_assembler-2 --tape_01 stage1/SET.hex2 --tape_02 roms/SET
  43. DEHEX: stage1_assembler-0 vm stage1/dehex.hex0 | roms
  44. ./bin/vm --rom roms/stage1_assembler-0 --tape_01 stage1/dehex.hex0 --tape_02 roms/DEHEX
  45. stage1_assembler-1: stage1_assembler-0 vm stage1/stage1_assembler-1.hex0 | roms
  46. ./bin/vm --rom roms/stage1_assembler-0 --tape_01 stage1/stage1_assembler-1.hex0 --tape_02 roms/stage1_assembler-1
  47. stage1_assembler-2: stage1_assembler-1 vm stage1/stage1_assembler-2.hex1 | roms
  48. ./bin/vm --rom roms/stage1_assembler-1 --tape_01 stage1/stage1_assembler-2.hex1 --tape_02 roms/stage1_assembler-2
  49. M0: stage1_assembler-2 vm stage1/M0-macro.hex2 | roms
  50. ./bin/vm --rom roms/stage1_assembler-2 --tape_01 stage1/M0-macro.hex2 --tape_02 roms/M0 --memory 48K
  51. M0-compact: M0 stage1_assembler-2 vm stage1/M0-macro-compact.s | roms
  52. cat High_level_prototypes/defs stage1/M0-macro-compact.s >| M0_TEMP
  53. ./bin/vm --rom roms/M0 --tape_01 M0_TEMP --tape_02 M0_TEMP2 --memory 64K
  54. ./bin/vm --rom roms/stage1_assembler-2 --tape_01 M0_TEMP2 --tape_02 roms/M0-compact --memory 5K
  55. rm M0_TEMP M0_TEMP2
  56. CAT: M0 stage1_assembler-2 vm High_level_prototypes/defs stage1/CAT.s | roms
  57. cat High_level_prototypes/defs stage1/CAT.s >| CAT_TEMP
  58. ./bin/vm --rom roms/M0 --tape_01 CAT_TEMP --tape_02 CAT_TEMP2 --memory 48K
  59. ./bin/vm --rom roms/stage1_assembler-2 --tape_01 CAT_TEMP2 --tape_02 roms/CAT --memory 48K
  60. rm CAT_TEMP CAT_TEMP2
  61. lisp: M0-compact stage1_assembler-2 vm High_level_prototypes/defs stage2/lisp.s | roms
  62. cat High_level_prototypes/defs stage2/lisp.s > lisp_TEMP
  63. ./bin/vm --rom roms/M0-compact --tape_01 lisp_TEMP --tape_02 lisp_TEMP2 --memory 9K
  64. ./bin/vm --rom roms/stage1_assembler-2 --tape_01 lisp_TEMP2 --tape_02 roms/lisp --memory 48K
  65. rm lisp_TEMP lisp_TEMP2
  66. cc_x86: M0-compact stage1_assembler-2 vm High_level_prototypes/defs stage2/cc_x86.s | roms
  67. cat High_level_prototypes/defs stage2/cc_x86.s > cc_TEMP
  68. ./bin/vm --rom roms/M0-compact --tape_01 cc_TEMP --tape_02 cc_TEMP2 --memory 9K
  69. ./bin/vm --rom roms/stage1_assembler-2 --tape_01 cc_TEMP2 --tape_02 roms/cc_x86 --memory 32K
  70. rm cc_TEMP cc_TEMP2
  71. forth: M0-compact stage1_assembler-2 vm High_level_prototypes/defs stage2/forth.s | roms
  72. cat High_level_prototypes/defs stage2/forth.s > forth_TEMP
  73. ./bin/vm --rom roms/M0-compact --tape_01 forth_TEMP --tape_02 forth_TEMP2 --memory 9K
  74. ./bin/vm --rom roms/stage1_assembler-2 --tape_01 forth_TEMP2 --tape_02 roms/forth --memory 12K
  75. rm forth_TEMP forth_TEMP2
  76. # Primitive development tools, not required but it was handy
  77. asm: High_level_prototypes/asm.c | bin
  78. $(CC) -ggdb High_level_prototypes/asm.c -o bin/asm
  79. dis: High_level_prototypes/disasm.c | bin
  80. $(CC) -ggdb High_level_prototypes/disasm.c -o bin/dis
  81. hex: POSIX/Legacy_pieces/hex.c | bin
  82. $(CC) POSIX/Legacy_pieces/hex.c -o bin/hex
  83. xeh: POSIX/Legacy_pieces/xeh.c | bin
  84. $(CC) POSIX/Legacy_pieces/xeh.c -o bin/xeh
  85. # libVM Builds for Development tools
  86. libvm.so: wrapper.c vm_instructions.c vm_halcode.c vm_decode.c vm.h tty.c
  87. $(CC) -ggdb -DVM32=true -Dtty_lib=true -shared -Wl,-soname,libvm.so -o libvm.so -fPIC wrapper.c vm_globals.c vm_instructions.c vm_halcode.c vm_decode.c tty.c functions/require.c functions/file_print.c
  88. libvm-production.so: wrapper.c vm_instructions.c vm_halcode.c vm_decode.c vm.h
  89. $(CC) -DVM32=true -shared -Wl,-soname,libvm.so -o libvm-production.so -fPIC wrapper.c vm_globals.c vm_instructions.c vm_halcode.c vm_decode.c functions/require.c functions/file_print.c
  90. # Tests
  91. Generate-rom-test: ALL-ROMS
  92. mkdir -p test
  93. sha256sum roms/* | sort -k2 >| test/SHA256SUMS
  94. test_stage0_monitor_asm_match: asm hex stage0_monitor
  95. mkdir -p test/stage0_test_scratch
  96. sed 's/^[^#]*# //' stage0/stage0_monitor.hex0 > test/stage0_test_scratch/stage0_monitor.hex0.s
  97. bin/asm test/stage0_test_scratch/stage0_monitor.hex0.s > test/stage0_test_scratch/stage0_monitor.hex0.hex0
  98. bin/hex < test/stage0_test_scratch/stage0_monitor.hex0.hex0 > test/stage0_test_scratch/stage0_monitor.hex0.bin
  99. bin/asm stage0/stage0_monitor.s > test/stage0_test_scratch/stage0_monitor.s.hex0
  100. bin/hex < test/stage0_test_scratch/stage0_monitor.s.hex0 > test/stage0_test_scratch/stage0_monitor.s.bin
  101. sha256sum roms/stage0_monitor | sed 's@roms/stage0_monitor@test/stage0_test_scratch/stage0_monitor.s.bin@' > test/stage0_test_scratch/stage0_monitor.s.expected_sum
  102. sha256sum -c test/stage0_test_scratch/stage0_monitor.s.expected_sum
  103. sha256sum roms/stage0_monitor | sed 's@roms/stage0_monitor@test/stage0_test_scratch/stage0_monitor.hex0.bin@' > test/stage0_test_scratch/stage0_monitor.hex0.expected_sum
  104. sha256sum -c test/stage0_test_scratch/stage0_monitor.hex0.expected_sum
  105. .SILENT: testM0
  106. .PHONY: testM0
  107. testM0: vm16 vm vm64 M0-compact prototype_M0-compact ALL-ROMS
  108. echo assembling ALL-ROMS with prototype_M0-compact and M0 with 32 bit vm and M0-compact with vm, vm64 and vm16; \
  109. VM_LIST='vm vm64 vm16'; \
  110. STAGE_1_UNIFORM_PROG_LIST="stage1_assembler-0 stage1_assembler-1 \
  111. stage1_assembler-2 CAT SET"; \
  112. STAGE_2_UNIFORM_PROG_LIST='cc_x86 forth lisp'; \
  113. ASSEMBLER_PROG_LIST="stage0/stage0_monitor"; \
  114. for stage1prog in $$STAGE_1_UNIFORM_PROG_LIST; do \
  115. ASSEMBLER_PROG_LIST="$$ASSEMBLER_PROG_LIST stage1/$$stage1prog"; \
  116. done; \
  117. ASSEMBLER_PROG_LIST="$$ASSEMBLER_PROG_LIST \
  118. stage1/M0-macro stage1/M0-macro-compact stage1/dehex"; \
  119. for stage2prog in $$STAGE_2_UNIFORM_PROG_LIST; do \
  120. ASSEMBLER_PROG_LIST="$$ASSEMBLER_PROG_LIST stage2/$$stage2prog"; \
  121. done; \
  122. for prog in $$ASSEMBLER_PROG_LIST; do \
  123. cat High_level_prototypes/defs "$$prog".s > "$$prog"_TEMP.s; \
  124. ./prototypes/prototype_M0-compact "$$prog"_TEMP.s > \
  125. "$$prog"_protoM0compact_TEMP.hex2; \
  126. ./bin/vm --memory 256K --rom roms/stage1_assembler-2 \
  127. --tape_01 "$$prog"_protoM0compact_TEMP.hex2 \
  128. --tape_02 "$$prog"_built_protoM0compact > /dev/null 2>&1; \
  129. rm "$$prog"_protoM0compact_TEMP.hex2; \
  130. M0ROMLIST='M0 M0-compact'; \
  131. for rom in $$M0ROMLIST; do \
  132. for vm in $$VM_LIST; do \
  133. if [ $$rom = M0-compact ] || [ $$vm = vm ]; then \
  134. ./bin/$$vm --memory 256K --rom roms/$$rom \
  135. --tape_01 "$$prog"_TEMP.s \
  136. --tape_02 "$$prog"_"$$vm"_TEMP.hex2 > /dev/null 2>&1; \
  137. ./bin/vm --memory 256K --rom roms/stage1_assembler-2 \
  138. --tape_01 "$$prog"_"$$vm"_TEMP.hex2 \
  139. --tape_02 "$$prog"_built_"$$vm"_"$$rom"> /dev/null 2>&1; \
  140. rm "$$prog"_"$$vm"_TEMP.hex2; \
  141. fi; \
  142. done; done; \
  143. rm "$$prog"_TEMP.s; \
  144. done; \
  145. BUILDSUFFIXLIST='protoM0compact'; \
  146. for vm in $$VM_LIST; do \
  147. for rom in $$M0ROMLIST; do \
  148. if [ $$rom = M0-compact ] || [ $$vm = vm ]; then \
  149. BUILDSUFFIXLIST="$$BUILDSUFFIXLIST $$vm"; \
  150. BUILDSUFFIXLIST="$$BUILDSUFFIXLIST"_; \
  151. BUILDSUFFIXLIST="$$BUILDSUFFIXLIST""$$rom"; \
  152. fi; \
  153. done; done; \
  154. for buildsuffix in $$BUILDSUFFIXLIST; do \
  155. cmp roms/stage0_monitor stage0/stage0_monitor_built_"$$buildsuffix"; \
  156. rm stage0/stage0_monitor_built_$$buildsuffix; \
  157. for stage1prog in $$STAGE_1_UNIFORM_PROG_LIST; do \
  158. cmp roms/$$stage1prog stage1/"$$stage1prog"_built_"$$buildsuffix"; \
  159. rm stage1/"$$stage1prog"_built_"$$buildsuffix"; \
  160. done; \
  161. cmp roms/M0 stage1/M0-macro_built_"$$buildsuffix"; \
  162. rm stage1/M0-macro_built_"$$buildsuffix"; \
  163. cmp roms/M0-compact stage1/M0-macro-compact_built_"$$buildsuffix"; \
  164. rm stage1/M0-macro-compact_built_"$$buildsuffix"; \
  165. cmp roms/DEHEX stage1/dehex_built_"$$buildsuffix"; \
  166. rm stage1/dehex_built_"$$buildsuffix"; \
  167. for stage2prog in $$STAGE_2_UNIFORM_PROG_LIST; do \
  168. cmp roms/$$stage2prog stage2/"$$stage2prog"_built_"$$buildsuffix"; \
  169. rm stage2/"$$stage2prog"_built_"$$buildsuffix"; \
  170. done; \
  171. done; \
  172. echo done M0 test
  173. .SILENT: testdisasmpy
  174. .PHONY: testdisasmpy
  175. testdisasmpy: ALL-ROMS M0-compact vm
  176. ROM_LIST="stage0_monitor stage1_assembler-0 \
  177. stage1_assembler-1 stage1_assembler-2 CAT SET M0 M0-compact DEHEX \
  178. cc_x86 forth lisp"; \
  179. for rom in $$ROM_LIST; do \
  180. ./High_level_prototypes/disasm.py --address-mode none \
  181. roms/"$$rom" > "$$rom".TEMP.dis.s; \
  182. cat High_level_prototypes/defs "$$rom".TEMP.dis.s > \
  183. "$$rom".TEMP.dis_cat.s; \
  184. rm "$$rom".TEMP.dis.s; \
  185. ./bin/vm --memory 2M --rom roms/M0 \
  186. --tape_01 "$$rom".TEMP.dis_cat.s \
  187. --tape_02 "$$rom".TEMP.hex2 > /dev/null 2>&1; \
  188. rm "$$rom".TEMP.dis_cat.s ; \
  189. ./bin/vm --memory 256K --rom roms/stage1_assembler-2 \
  190. --tape_01 "$$rom".TEMP.hex2 \
  191. --tape_02 "$$rom".TEMP > /dev/null 2>&1; \
  192. rm "$$rom".TEMP.hex2; \
  193. cmp roms/"$$rom" "$$rom".TEMP; \
  194. rm "$$rom".TEMP; \
  195. done;
  196. test: ALL-ROMS
  197. sha256sum -c test/SHA256SUMS
  198. test-all: ALL-ROMS test/SHA256SUMS test_stage0_monitor_asm_match testM0 testdisasmpy
  199. sha256sum -c test/SHA256SUMS
  200. # Prototypes
  201. ALL-PROTOTYPES: prototype_dehex prototype_M0 prototype_more prototype_SET prototype_stage1_assembler-1 prototype_stage1_assembler-2 prototype_lisp
  202. prototype_dehex: dehex.c | prototypes
  203. gcc stage1/High_level_prototypes/dehex.c -o prototypes/prototype_dehex
  204. prototype_M0: M0-macro.c | prototypes
  205. gcc stage1/High_level_prototypes/M0-macro.c -o prototypes/prototype_M0
  206. prototype_more: more.c tty.c | prototypes
  207. gcc stage1/High_level_prototypes/more.c tty.c -o prototypes/prototype_more
  208. prototype_SET: SET.c tty.c | prototypes
  209. gcc stage1/High_level_prototypes/SET.c tty.c -o prototypes/prototype_SET
  210. prototype_stage1_assembler-1: stage1_assembler-1.c | prototypes
  211. gcc stage1/High_level_prototypes/stage1_assembler-1.c -o prototypes/prototype_stage1_assembler-1
  212. prototype_stage1_assembler-2: stage1_assembler-2.c | prototypes
  213. gcc stage1/High_level_prototypes/stage1_assembler-2.c -o prototypes/prototype_stage1_assembler-2
  214. prototype_M0-compact: M0-macro-compact.c | prototypes
  215. gcc stage1/High_level_prototypes/M0-macro-compact.c -o prototypes/prototype_M0-compact
  216. prototype_lisp: stage2/High_level_prototypes/lisp/lisp.c stage2/High_level_prototypes/lisp/lisp.h stage2/High_level_prototypes/lisp/lisp_cell.c stage2/High_level_prototypes/lisp/lisp_eval.c stage2/High_level_prototypes/lisp/lisp_print.c stage2/High_level_prototypes/lisp/lisp_read.c | prototypes
  217. gcc -O2 stage2/High_level_prototypes/lisp/lisp.h \
  218. stage2/High_level_prototypes/lisp/lisp.c \
  219. stage2/High_level_prototypes/lisp/lisp_cell.c \
  220. stage2/High_level_prototypes/lisp/lisp_eval.c \
  221. stage2/High_level_prototypes/lisp/lisp_print.c \
  222. stage2/High_level_prototypes/lisp/lisp_read.c \
  223. -o prototypes/prototype_lisp
  224. # Clean up after ourselves
  225. .PHONY: clean
  226. clean:
  227. rm -rf bin/
  228. rm -f libvm.so libvm-production.so bin/vm bin/vm-production
  229. rm -rf test/stage0_test_scratch prototypes/
  230. .PHONY: clean-hard
  231. clean-hard: clean
  232. rm -rf bin/ roms/ prototypes/
  233. .PHONY: clean-hardest
  234. clean-hardest:
  235. git reset --hard
  236. git clean -fd
  237. rm -rf bin/ roms/ prototypes/
  238. clean-SO-hard-You-probably-do-NOT-want-this-option-because-it-will-destory-everything:
  239. @echo "I REALLY REALLY HOPE you know what you are doing"
  240. git reset --hard
  241. git clean -xdf
  242. rm -rf bin/ roms/ prototypes/
  243. # Our essential folders
  244. bin:
  245. mkdir -p bin
  246. roms:
  247. mkdir -p roms
  248. prototypes:
  249. mkdir -p prototypes