build.sh 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. #! /bin/sh
  2. # Copyright © 2017 Jan Nieuwenhuizen <janneke@gnu.org>
  3. # Copyright © 2017 Jeremiah Orians
  4. #
  5. # This file is part of mescc-tools.
  6. #
  7. # mescc-tools is free software; you can redistribute it and/or modify it
  8. # under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 3 of the License, or (at
  10. # your option) any later version.
  11. #
  12. # mescc-tools is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License
  18. # along with mescc-tools. If not, see <http://www.gnu.org/licenses/>.
  19. set -eux
  20. M2=${M2-../M2-Planet}
  21. MESCC_TOOLS_SEED=${MESCC_TOOLS_SEED-../mescc-tools-seed}
  22. #########################################
  23. # Phase-0 Build from external binaries #
  24. # To be replaced by a trusted path #
  25. #########################################
  26. # Make sure we have our required output directory
  27. [ -e bin ] || mkdir -p bin
  28. # blood-elf
  29. $M2/bin/M2-Planet \
  30. -f $M2/functions/exit.c \
  31. -f $M2/functions/file.c \
  32. -f functions/file_print.c \
  33. -f $M2/functions/malloc.c \
  34. -f $M2/functions/calloc.c \
  35. -f functions/match.c \
  36. -f blood-elf.c \
  37. --debug \
  38. -o blood-elf.M1 || exit 1
  39. # Build debug footer
  40. $MESCC_TOOLS_SEED/blood-elf-0 \
  41. -f blood-elf.M1 \
  42. -o blood-elf-footer.M1 || exit 2
  43. # Macro assemble with libc written in M1-Macro
  44. $MESCC_TOOLS_SEED/M1-0 \
  45. -f $M2/test/common_x86/x86_defs.M1 \
  46. -f $M2/functions/libc-core.M1 \
  47. -f blood-elf.M1 \
  48. -f blood-elf-footer.M1 \
  49. --LittleEndian \
  50. --architecture x86 \
  51. -o blood-elf.hex2 || exit 3
  52. # Resolve all linkages
  53. $MESCC_TOOLS_SEED/hex2-0 \
  54. -f elf_headers/elf32-debug.hex2 \
  55. -f blood-elf.hex2 \
  56. --LittleEndian \
  57. --architecture x86 \
  58. --BaseAddress 0x8048000 \
  59. -o bin/blood-elf-0 \
  60. --exec_enable || exit 4
  61. # Build
  62. # M1-macro phase
  63. $M2/bin/M2-Planet \
  64. -f $M2/functions/exit.c \
  65. -f $M2/functions/file.c \
  66. -f functions/file_print.c \
  67. -f $M2/functions/malloc.c \
  68. -f $M2/functions/calloc.c \
  69. -f functions/match.c \
  70. -f functions/numerate_number.c \
  71. -f functions/string.c \
  72. -f functions/in_set.c \
  73. -f M1-macro.c \
  74. --debug \
  75. -o M1-macro.M1 || exit 5
  76. # Build debug footer
  77. $MESCC_TOOLS_SEED/blood-elf-0 \
  78. -f M1-macro.M1 \
  79. -o M1-macro-footer.M1 || exit 6
  80. # Macro assemble with libc written in M1-Macro
  81. $MESCC_TOOLS_SEED/M1-0 \
  82. -f $M2/test/common_x86/x86_defs.M1 \
  83. -f $M2/functions/libc-core.M1 \
  84. -f M1-macro.M1 \
  85. -f M1-macro-footer.M1 \
  86. --LittleEndian \
  87. --architecture x86 \
  88. -o M1-macro.hex2 || exit 7
  89. # Resolve all linkages
  90. $MESCC_TOOLS_SEED/hex2-0 \
  91. -f elf_headers/elf32-debug.hex2 \
  92. -f M1-macro.hex2 \
  93. --LittleEndian \
  94. --architecture x86 \
  95. --BaseAddress 0x8048000 \
  96. -o bin/M1-0 \
  97. --exec_enable || exit 8
  98. # hex2
  99. $M2/bin/M2-Planet \
  100. -f $M2/functions/exit.c \
  101. -f $M2/functions/file.c \
  102. -f functions/file_print.c \
  103. -f $M2/functions/malloc.c \
  104. -f $M2/functions/calloc.c \
  105. -f functions/match.c \
  106. -f functions/numerate_number.c \
  107. -f functions/in_set.c \
  108. -f $M2/functions/stat.c \
  109. -f hex2_linker.c \
  110. --debug \
  111. -o hex2_linker.M1 || exit 9
  112. # Build debug footer
  113. $MESCC_TOOLS_SEED/blood-elf-0 \
  114. -f hex2_linker.M1 \
  115. -o hex2_linker-footer.M1 || exit 10
  116. # Macro assemble with libc written in M1-Macro
  117. $MESCC_TOOLS_SEED/M1-0 \
  118. -f $M2/test/common_x86/x86_defs.M1 \
  119. -f $M2/functions/libc-core.M1 \
  120. -f hex2_linker.M1 \
  121. -f hex2_linker-footer.M1 \
  122. --LittleEndian \
  123. --architecture x86 \
  124. -o hex2_linker.hex2|| exit 11
  125. # Resolve all linkages
  126. $MESCC_TOOLS_SEED/hex2-0 \
  127. -f elf_headers/elf32-debug.hex2 \
  128. -f hex2_linker.hex2 \
  129. --LittleEndian \
  130. --architecture x86 \
  131. --BaseAddress 0x8048000 \
  132. -o bin/hex2-0 \
  133. --exec_enable || exit 12
  134. #########################
  135. # Phase-1 Self-host #
  136. #########################
  137. # blood-elf
  138. # Build debug footer
  139. ./bin/blood-elf-0 \
  140. -f blood-elf.M1 \
  141. -o blood-elf-footer.M1 || exit 13
  142. # Macro assemble with libc written in M1-Macro
  143. ./bin/M1-0 \
  144. -f $M2/test/common_x86/x86_defs.M1 \
  145. -f $M2/functions/libc-core.M1 \
  146. -f blood-elf.M1 \
  147. -f blood-elf-footer.M1 \
  148. --LittleEndian \
  149. --architecture x86 \
  150. -o blood-elf.hex2 || exit 14
  151. # Resolve all linkages
  152. ./bin/hex2-0 \
  153. -f elf_headers/elf32-debug.hex2 \
  154. -f blood-elf.hex2 \
  155. --LittleEndian \
  156. --architecture x86 \
  157. --BaseAddress 0x8048000 \
  158. -o bin/blood-elf \
  159. --exec_enable || exit 15
  160. # M1-macro
  161. # Build debug footer
  162. ./bin/blood-elf \
  163. -f M1-macro.M1 \
  164. -o M1-macro-footer.M1 || exit 16
  165. # Macro assemble with libc written in M1-Macro
  166. ./bin/M1-0 \
  167. -f $M2/test/common_x86/x86_defs.M1 \
  168. -f $M2/functions/libc-core.M1 \
  169. -f M1-macro.M1 \
  170. -f M1-macro-footer.M1 \
  171. --LittleEndian \
  172. --architecture x86 \
  173. -o M1-macro.hex2 || exit 17
  174. # Resolve all linkages
  175. ./bin/hex2-0 \
  176. -f elf_headers/elf32-debug.hex2 \
  177. -f M1-macro.hex2 \
  178. --LittleEndian \
  179. --architecture x86 \
  180. --BaseAddress 0x8048000 \
  181. -o bin/M1 \
  182. --exec_enable || exit 18
  183. # hex2
  184. # Build debug footer
  185. ./bin/blood-elf \
  186. -f hex2_linker.M1 \
  187. -o hex2_linker-footer.M1 || exit 19
  188. # Macro assemble with libc written in M1-Macro
  189. ./bin/M1 \
  190. -f $M2/test/common_x86/x86_defs.M1 \
  191. -f $M2/functions/libc-core.M1 \
  192. -f hex2_linker.M1 \
  193. -f hex2_linker-footer.M1 \
  194. --LittleEndian \
  195. --architecture x86 \
  196. -o hex2_linker.hex2|| exit 20
  197. # Resolve all linkages
  198. ./bin/hex2-0 \
  199. -f elf_headers/elf32-debug.hex2 \
  200. -f hex2_linker.hex2 \
  201. --LittleEndian \
  202. --architecture x86 \
  203. --BaseAddress 0x8048000 \
  204. -o bin/hex2 \
  205. --exec_enable || exit 21
  206. # Clean up after ourself
  207. rm -f bin/blood-elf-0 bin/M1-0 bin/hex2-0
  208. # Build pieces that were not needed in bootstrap
  209. # but are generally useful
  210. # get_machine
  211. $M2/bin/M2-Planet \
  212. -f $M2/functions/exit.c \
  213. -f $M2/functions/file.c \
  214. -f functions/file_print.c \
  215. -f $M2/functions/malloc.c \
  216. -f $M2/functions/calloc.c \
  217. -f $M2/functions/uname.c \
  218. -f get_machine.c \
  219. --debug \
  220. -o get_machine.M1 || exit 22
  221. # Build debug footer
  222. ./bin/blood-elf \
  223. -f get_machine.M1 \
  224. -o get_machine-footer.M1 || exit 23
  225. # Macro assemble with libc written in M1-Macro
  226. ./bin/M1 \
  227. -f $M2/test/common_x86/x86_defs.M1 \
  228. -f $M2/functions/libc-core.M1 \
  229. -f get_machine.M1 \
  230. -f get_machine-footer.M1 \
  231. --LittleEndian \
  232. --architecture x86 \
  233. -o get_machine.hex2 || exit 24
  234. # Resolve all linkages
  235. ./bin/hex2 \
  236. -f elf_headers/elf32-debug.hex2 \
  237. -f get_machine.hex2 \
  238. --LittleEndian \
  239. --architecture x86 \
  240. --BaseAddress 0x8048000 \
  241. -o bin/get_machine \
  242. --exec_enable || exit 25
  243. # exec_enable
  244. $M2/bin/M2-Planet \
  245. -f $M2/functions/file.c \
  246. -f functions/file_print.c \
  247. -f $M2/functions/exit.c \
  248. -f $M2/functions/stat.c \
  249. -f exec_enable.c \
  250. --debug \
  251. -o exec_enable.M1 || exit 26
  252. # Build debug footer
  253. ./bin/blood-elf \
  254. -f exec_enable.M1 \
  255. -o exec_enable-footer.M1 || exit 27
  256. # Macro assemble with libc written in M1-Macro
  257. ./bin/M1 \
  258. -f $M2/test/common_x86/x86_defs.M1 \
  259. -f $M2/functions/libc-core.M1 \
  260. -f exec_enable.M1 \
  261. -f exec_enable-footer.M1 \
  262. --LittleEndian \
  263. --architecture x86 \
  264. -o exec_enable.hex2 || exit 28
  265. # Resolve all linkages
  266. ./bin/hex2 \
  267. -f elf_headers/elf32-debug.hex2 \
  268. -f exec_enable.hex2 \
  269. --LittleEndian \
  270. --architecture x86 \
  271. --BaseAddress 0x8048000 \
  272. -o bin/exec_enable \
  273. --exec_enable || exit 29
  274. # TODO
  275. # kaem