extTools.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /* voc 2.1.0 [2021/07/05]. Bootstrapping compiler for address size 8, alignment 8. xrtspaSF */
  2. #define SHORTINT INT8
  3. #define INTEGER INT16
  4. #define LONGINT INT32
  5. #define SET UINT32
  6. #include "SYSTEM.h"
  7. #include "Configuration.h"
  8. #include "Heap.h"
  9. #include "Modules.h"
  10. #include "OPM.h"
  11. #include "Out.h"
  12. #include "Platform.h"
  13. #include "Strings.h"
  14. typedef
  15. CHAR extTools_CommandString[4096];
  16. static extTools_CommandString extTools_CFLAGS;
  17. export void extTools_Assemble (CHAR *moduleName, ADDRESS moduleName__len);
  18. static void extTools_InitialiseCompilerCommand (CHAR *s, ADDRESS s__len);
  19. export void extTools_LinkMain (CHAR *moduleName, ADDRESS moduleName__len, BOOLEAN statically, CHAR *additionalopts, ADDRESS additionalopts__len);
  20. static void extTools_execute (CHAR *title, ADDRESS title__len, CHAR *cmd, ADDRESS cmd__len);
  21. static void extTools_execute (CHAR *title, ADDRESS title__len, CHAR *cmd, ADDRESS cmd__len)
  22. {
  23. INT16 r, status, exitcode;
  24. extTools_CommandString fullcmd;
  25. __DUP(title, title__len, CHAR);
  26. __DUP(cmd, cmd__len, CHAR);
  27. if (__IN(18, OPM_Options, 32)) {
  28. Out_String((CHAR*)" ", 3);
  29. Out_String(cmd, cmd__len);
  30. Out_Ln();
  31. }
  32. __COPY(cmd, fullcmd, 4096);
  33. Heap_GC(0);
  34. r = Platform_System(fullcmd, 4096);
  35. status = __MASK(r, -128);
  36. exitcode = __ASHR(r, 8);
  37. if (exitcode > 127) {
  38. exitcode = exitcode - 256;
  39. }
  40. if (r != 0) {
  41. Out_String(title, title__len);
  42. Out_String(cmd, cmd__len);
  43. Out_Ln();
  44. Out_String((CHAR*)"-- failed: status ", 19);
  45. Out_Int(status, 1);
  46. Out_String((CHAR*)", exitcode ", 12);
  47. Out_Int(exitcode, 1);
  48. Out_String((CHAR*)".", 2);
  49. Out_Ln();
  50. if ((status == 0 && exitcode == 127)) {
  51. Out_String((CHAR*)"Is the C compiler in the current command path\?", 47);
  52. Out_Ln();
  53. }
  54. if (status != 0) {
  55. Modules_Halt(status);
  56. } else {
  57. Modules_Halt(exitcode);
  58. }
  59. }
  60. __DEL(title);
  61. __DEL(cmd);
  62. }
  63. static void extTools_InitialiseCompilerCommand (CHAR *s, ADDRESS s__len)
  64. {
  65. __COPY("gcc -fPIC -g", s, s__len);
  66. Strings_Append((CHAR*)" -I \"", 6, (void*)s, s__len);
  67. Strings_Append(OPM_ResourceDir, 1024, (void*)s, s__len);
  68. Strings_Append((CHAR*)"/include\" ", 11, (void*)s, s__len);
  69. Platform_GetEnv((CHAR*)"CFLAGS", 7, (void*)extTools_CFLAGS, 4096);
  70. Strings_Append(extTools_CFLAGS, 4096, (void*)s, s__len);
  71. Strings_Append((CHAR*)" ", 2, (void*)s, s__len);
  72. }
  73. void extTools_Assemble (CHAR *moduleName, ADDRESS moduleName__len)
  74. {
  75. extTools_CommandString cmd;
  76. __DUP(moduleName, moduleName__len, CHAR);
  77. extTools_InitialiseCompilerCommand((void*)cmd, 4096);
  78. Strings_Append((CHAR*)"-c ", 4, (void*)cmd, 4096);
  79. Strings_Append(moduleName, moduleName__len, (void*)cmd, 4096);
  80. Strings_Append((CHAR*)".c", 3, (void*)cmd, 4096);
  81. extTools_execute((CHAR*)"C compile: ", 12, cmd, 4096);
  82. __DEL(moduleName);
  83. }
  84. void extTools_LinkMain (CHAR *moduleName, ADDRESS moduleName__len, BOOLEAN statically, CHAR *additionalopts, ADDRESS additionalopts__len)
  85. {
  86. extTools_CommandString cmd;
  87. __DUP(additionalopts, additionalopts__len, CHAR);
  88. extTools_InitialiseCompilerCommand((void*)cmd, 4096);
  89. Strings_Append(moduleName, moduleName__len, (void*)cmd, 4096);
  90. Strings_Append((CHAR*)".c ", 4, (void*)cmd, 4096);
  91. Strings_Append(additionalopts, additionalopts__len, (void*)cmd, 4096);
  92. if (statically) {
  93. Strings_Append((CHAR*)" -static", 9, (void*)cmd, 4096);
  94. }
  95. Strings_Append((CHAR*)" -o ", 5, (void*)cmd, 4096);
  96. Strings_Append(moduleName, moduleName__len, (void*)cmd, 4096);
  97. if (!statically || 1) {
  98. Strings_Append((CHAR*)" -L\"", 5, (void*)cmd, 4096);
  99. Strings_Append(OPM_InstallDir, 1024, (void*)cmd, 4096);
  100. Strings_Append((CHAR*)"/lib\"", 6, (void*)cmd, 4096);
  101. Strings_Append((CHAR*)" -lvoc", 7, (void*)cmd, 4096);
  102. Strings_Append((CHAR*)"-O", 3, (void*)cmd, 4096);
  103. Strings_Append(OPM_Model, 10, (void*)cmd, 4096);
  104. Strings_Append((CHAR*)"", 1, (void*)cmd, 4096);
  105. }
  106. extTools_execute((CHAR*)"C compile and link: ", 21, cmd, 4096);
  107. __DEL(additionalopts);
  108. }
  109. export void *extTools__init(void)
  110. {
  111. __DEFMOD;
  112. __MODULE_IMPORT(Configuration);
  113. __MODULE_IMPORT(Heap);
  114. __MODULE_IMPORT(Modules);
  115. __MODULE_IMPORT(OPM);
  116. __MODULE_IMPORT(Out);
  117. __MODULE_IMPORT(Platform);
  118. __MODULE_IMPORT(Strings);
  119. __REGMOD("extTools", 0);
  120. /* BEGIN */
  121. __ENDMOD;
  122. }