nobuild.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #define NOBUILD_IMPLEMENTATION
  2. #include "./nobuild.h"
  3. #include "./nobuild.global.h"
  4. static const char *const subdirs[] = {
  5. "bm", "debasm", "bdb", "basm", "bang"
  6. };
  7. static const size_t subdirs_count = sizeof(subdirs) / sizeof(subdirs[0]);
  8. // TODO(#452): the root nobuild does not have the fmt subcommand
  9. void nobuild_all_subdirs(int argc, char **argv)
  10. {
  11. for (size_t i = 0; i < subdirs_count; ++i) {
  12. INFO("------------------------------");
  13. INFO("SUBDIR: %s", subdirs[i]);
  14. INFO("------------------------------");
  15. chdir(subdirs[i]);
  16. #ifdef _WIN32
  17. CMD("cl.exe", "nobuild.c");
  18. Cstr_Array nobuild_args = cstr_array_make(".\\nobuild.exe", NULL);
  19. #else
  20. CMD("cc", "-o", "nobuild", "nobuild.c");
  21. Cstr_Array nobuild_args = cstr_array_make("./nobuild", NULL);
  22. #endif
  23. for (int i = 0; i < argc; ++i) {
  24. nobuild_args = cstr_array_append(nobuild_args, argv[i]);
  25. }
  26. Cmd nobuild_cmd = {nobuild_args};
  27. INFO("CMD: %s", cmd_show(nobuild_cmd));
  28. cmd_run_sync(nobuild_cmd);
  29. chdir("..");
  30. }
  31. }
  32. int main(int argc, char **argv)
  33. {
  34. assert(argc > 0);
  35. if (argc >= 2 && strcmp(argv[1], "help") == 0) {
  36. printf("Usage: ./nobuild [ARGS]\n");
  37. printf("This is the root nobuild file of the project. It simply iterates over all of the subprojects. Builds their corresponding nobuild.c files. And runs them with the provided [ARGS]. The subprojects are\n");
  38. for (size_t i = 0; i < subdirs_count; ++i) {
  39. printf(" %s\n", subdirs[i]);
  40. }
  41. } else {
  42. nobuild_all_subdirs(argc - 1, argv + 1);
  43. }
  44. return 0;
  45. }