makefile 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. execve_image: High_level_prototypes/execve_image.c | bin
  82. $(CC) -ggdb High_level_prototypes/execve_image.c -o bin/execve_image
  83. hex: POSIX/Legacy_pieces/hex.c | bin
  84. $(CC) POSIX/Legacy_pieces/hex.c -o bin/hex
  85. xeh: POSIX/Legacy_pieces/xeh.c | bin
  86. $(CC) POSIX/Legacy_pieces/xeh.c -o bin/xeh
  87. # libVM Builds for Development tools
  88. libvm.so: wrapper.c vm_instructions.c vm_halcode.c vm_decode.c vm.h tty.c
  89. $(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
  90. libvm-production.so: wrapper.c vm_instructions.c vm_halcode.c vm_decode.c vm.h
  91. $(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
  92. # Tests
  93. Generate-rom-test: ALL-ROMS
  94. mkdir -p test
  95. sha256sum roms/* | sort -k2 >| test/SHA256SUMS
  96. test_stage0_monitor_asm_match: asm hex stage0_monitor
  97. mkdir -p test/stage0_test_scratch
  98. sed 's/^[^#]*# //' stage0/stage0_monitor.hex0 > test/stage0_test_scratch/stage0_monitor.hex0.s
  99. bin/asm test/stage0_test_scratch/stage0_monitor.hex0.s > test/stage0_test_scratch/stage0_monitor.hex0.hex0
  100. bin/hex < test/stage0_test_scratch/stage0_monitor.hex0.hex0 > test/stage0_test_scratch/stage0_monitor.hex0.bin
  101. bin/asm stage0/stage0_monitor.s > test/stage0_test_scratch/stage0_monitor.s.hex0
  102. bin/hex < test/stage0_test_scratch/stage0_monitor.s.hex0 > test/stage0_test_scratch/stage0_monitor.s.bin
  103. 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
  104. sha256sum -c test/stage0_test_scratch/stage0_monitor.s.expected_sum
  105. 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
  106. sha256sum -c test/stage0_test_scratch/stage0_monitor.hex0.expected_sum
  107. .SILENT: testM0
  108. .PHONY: testM0
  109. testM0: vm16 vm vm64 M0-compact prototype_M0-compact ALL-ROMS
  110. echo assembling ALL-ROMS with prototype_M0-compact and M0 with 32 bit vm and M0-compact with vm, vm64 and vm16; \
  111. VM_LIST='vm vm64 vm16'; \
  112. STAGE_1_UNIFORM_PROG_LIST="stage1_assembler-0 stage1_assembler-1 \
  113. stage1_assembler-2 CAT SET"; \
  114. STAGE_2_UNIFORM_PROG_LIST='cc_x86 forth lisp'; \
  115. ASSEMBLER_PROG_LIST="stage0/stage0_monitor"; \
  116. for stage1prog in $$STAGE_1_UNIFORM_PROG_LIST; do \
  117. ASSEMBLER_PROG_LIST="$$ASSEMBLER_PROG_LIST stage1/$$stage1prog"; \
  118. done; \
  119. ASSEMBLER_PROG_LIST="$$ASSEMBLER_PROG_LIST \
  120. stage1/M0-macro stage1/M0-macro-compact stage1/dehex"; \
  121. for stage2prog in $$STAGE_2_UNIFORM_PROG_LIST; do \
  122. ASSEMBLER_PROG_LIST="$$ASSEMBLER_PROG_LIST stage2/$$stage2prog"; \
  123. done; \
  124. for prog in $$ASSEMBLER_PROG_LIST; do \
  125. cat High_level_prototypes/defs "$$prog".s > "$$prog"_TEMP.s; \
  126. ./prototypes/prototype_M0-compact "$$prog"_TEMP.s > \
  127. "$$prog"_protoM0compact_TEMP.hex2; \
  128. ./bin/vm --memory 256K --rom roms/stage1_assembler-2 \
  129. --tape_01 "$$prog"_protoM0compact_TEMP.hex2 \
  130. --tape_02 "$$prog"_built_protoM0compact > /dev/null 2>&1; \
  131. rm "$$prog"_protoM0compact_TEMP.hex2; \
  132. M0ROMLIST='M0 M0-compact'; \
  133. for rom in $$M0ROMLIST; do \
  134. for vm in $$VM_LIST; do \
  135. if [ $$rom = M0-compact ] || [ $$vm = vm ]; then \
  136. ./bin/$$vm --memory 256K --rom roms/$$rom \
  137. --tape_01 "$$prog"_TEMP.s \
  138. --tape_02 "$$prog"_"$$vm"_TEMP.hex2 > /dev/null 2>&1; \
  139. ./bin/vm --memory 256K --rom roms/stage1_assembler-2 \
  140. --tape_01 "$$prog"_"$$vm"_TEMP.hex2 \
  141. --tape_02 "$$prog"_built_"$$vm"_"$$rom"> /dev/null 2>&1; \
  142. rm "$$prog"_"$$vm"_TEMP.hex2; \
  143. fi; \
  144. done; done; \
  145. rm "$$prog"_TEMP.s; \
  146. done; \
  147. BUILDSUFFIXLIST='protoM0compact'; \
  148. for vm in $$VM_LIST; do \
  149. for rom in $$M0ROMLIST; do \
  150. if [ $$rom = M0-compact ] || [ $$vm = vm ]; then \
  151. BUILDSUFFIXLIST="$$BUILDSUFFIXLIST $$vm"; \
  152. BUILDSUFFIXLIST="$$BUILDSUFFIXLIST"_; \
  153. BUILDSUFFIXLIST="$$BUILDSUFFIXLIST""$$rom"; \
  154. fi; \
  155. done; done; \
  156. for buildsuffix in $$BUILDSUFFIXLIST; do \
  157. cmp roms/stage0_monitor stage0/stage0_monitor_built_"$$buildsuffix"; \
  158. rm stage0/stage0_monitor_built_$$buildsuffix; \
  159. for stage1prog in $$STAGE_1_UNIFORM_PROG_LIST; do \
  160. cmp roms/$$stage1prog stage1/"$$stage1prog"_built_"$$buildsuffix"; \
  161. rm stage1/"$$stage1prog"_built_"$$buildsuffix"; \
  162. done; \
  163. cmp roms/M0 stage1/M0-macro_built_"$$buildsuffix"; \
  164. rm stage1/M0-macro_built_"$$buildsuffix"; \
  165. cmp roms/M0-compact stage1/M0-macro-compact_built_"$$buildsuffix"; \
  166. rm stage1/M0-macro-compact_built_"$$buildsuffix"; \
  167. cmp roms/DEHEX stage1/dehex_built_"$$buildsuffix"; \
  168. rm stage1/dehex_built_"$$buildsuffix"; \
  169. for stage2prog in $$STAGE_2_UNIFORM_PROG_LIST; do \
  170. cmp roms/$$stage2prog stage2/"$$stage2prog"_built_"$$buildsuffix"; \
  171. rm stage2/"$$stage2prog"_built_"$$buildsuffix"; \
  172. done; \
  173. done; \
  174. echo done M0 test
  175. .SILENT: testdisasmpy
  176. .PHONY: testdisasmpy
  177. testdisasmpy: ALL-ROMS M0-compact vm
  178. ROM_LIST="stage0_monitor stage1_assembler-0 \
  179. stage1_assembler-1 stage1_assembler-2 CAT SET M0 M0-compact DEHEX \
  180. cc_x86 forth lisp"; \
  181. for rom in $$ROM_LIST; do \
  182. ./High_level_prototypes/disasm.py --address-mode none \
  183. roms/"$$rom" > "$$rom".TEMP.dis.s; \
  184. cat High_level_prototypes/defs "$$rom".TEMP.dis.s > \
  185. "$$rom".TEMP.dis_cat.s; \
  186. rm "$$rom".TEMP.dis.s; \
  187. ./bin/vm --memory 2M --rom roms/M0 \
  188. --tape_01 "$$rom".TEMP.dis_cat.s \
  189. --tape_02 "$$rom".TEMP.hex2 > /dev/null 2>&1; \
  190. rm "$$rom".TEMP.dis_cat.s ; \
  191. ./bin/vm --memory 256K --rom roms/stage1_assembler-2 \
  192. --tape_01 "$$rom".TEMP.hex2 \
  193. --tape_02 "$$rom".TEMP > /dev/null 2>&1; \
  194. rm "$$rom".TEMP.hex2; \
  195. cmp roms/"$$rom" "$$rom".TEMP; \
  196. rm "$$rom".TEMP; \
  197. done;
  198. test: ALL-ROMS
  199. sha256sum -c test/SHA256SUMS
  200. test-all: ALL-ROMS test/SHA256SUMS test_stage0_monitor_asm_match testM0 testdisasmpy
  201. sha256sum -c test/SHA256SUMS
  202. # Prototypes
  203. ALL-PROTOTYPES: prototype_dehex prototype_M0 prototype_more prototype_SET prototype_stage1_assembler-1 prototype_stage1_assembler-2 prototype_lisp
  204. prototype_dehex: dehex.c | prototypes
  205. gcc stage1/High_level_prototypes/dehex.c -o prototypes/prototype_dehex
  206. prototype_M0: M0-macro.c | prototypes
  207. gcc stage1/High_level_prototypes/M0-macro.c -o prototypes/prototype_M0
  208. prototype_more: more.c tty.c | prototypes
  209. gcc stage1/High_level_prototypes/more.c tty.c -o prototypes/prototype_more
  210. prototype_SET: SET.c tty.c | prototypes
  211. gcc stage1/High_level_prototypes/SET.c tty.c -o prototypes/prototype_SET
  212. prototype_stage1_assembler-1: stage1_assembler-1.c | prototypes
  213. gcc stage1/High_level_prototypes/stage1_assembler-1.c -o prototypes/prototype_stage1_assembler-1
  214. prototype_stage1_assembler-2: stage1_assembler-2.c | prototypes
  215. gcc stage1/High_level_prototypes/stage1_assembler-2.c -o prototypes/prototype_stage1_assembler-2
  216. prototype_M0-compact: M0-macro-compact.c | prototypes
  217. gcc stage1/High_level_prototypes/M0-macro-compact.c -o prototypes/prototype_M0-compact
  218. 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
  219. gcc -O2 stage2/High_level_prototypes/lisp/lisp.h \
  220. stage2/High_level_prototypes/lisp/lisp.c \
  221. stage2/High_level_prototypes/lisp/lisp_cell.c \
  222. stage2/High_level_prototypes/lisp/lisp_eval.c \
  223. stage2/High_level_prototypes/lisp/lisp_print.c \
  224. stage2/High_level_prototypes/lisp/lisp_read.c \
  225. -o prototypes/prototype_lisp
  226. # Clean up after ourselves
  227. .PHONY: clean
  228. clean:
  229. rm -rf bin/
  230. rm -f libvm.so libvm-production.so bin/vm bin/vm-production
  231. rm -rf test/stage0_test_scratch prototypes/
  232. .PHONY: clean-hard
  233. clean-hard: clean
  234. rm -rf bin/ roms/ prototypes/
  235. .PHONY: clean-hardest
  236. clean-hardest:
  237. git reset --hard
  238. git clean -fd
  239. rm -rf bin/ roms/ prototypes/
  240. clean-SO-hard-You-probably-do-NOT-want-this-option-because-it-will-destory-everything:
  241. @echo "I REALLY REALLY HOPE you know what you are doing"
  242. git reset --hard
  243. git clean -xdf
  244. rm -rf bin/ roms/ prototypes/
  245. # Our essential folders
  246. bin:
  247. mkdir -p bin
  248. roms:
  249. mkdir -p roms
  250. prototypes:
  251. mkdir -p prototypes