nob.c 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #define NOB_IMPLEMENTATION
  2. #define NOB_STRIP_PREFIX
  3. // #define NOB_EXPERIMENTAL_DELETE_OLD // Doesn't work on Windows
  4. // #define NOB_WARN_DEPRECATED
  5. #include "./thirdparty/nob.h"
  6. #include "./src_build/configurer.c"
  7. int main(int argc, char **argv)
  8. {
  9. NOB_GO_REBUILD_URSELF_PLUS(argc, argv, "./thirdparty/nob.h", "./src_build/configurer.c");
  10. const char *program = shift_args(&argc, &argv);
  11. const char *old_build_conf_path = "./build/build.conf";
  12. int build_conf_exists = file_exists(old_build_conf_path);
  13. if (build_conf_exists < 0) return 1;
  14. if (build_conf_exists) {
  15. // @backcomp
  16. nob_log(ERROR, "We found %s. That means your build folder has an old schema.", old_build_conf_path);
  17. nob_log(ERROR, "Instead of %s you are suppose to use %s to configure the build now.", old_build_conf_path, CONFIG_PATH);
  18. nob_log(ERROR, "Remove your ./build/ folder and run %s again to regenerate the folder with the new schema.", program);
  19. return 1;
  20. }
  21. nob_log(INFO, "--- STAGE 1 ---");
  22. if (!mkdir_if_not_exists("build")) return 1;
  23. if (argc > 0) {
  24. const char *command_name = shift(argv, argc);
  25. if (strcmp(command_name, "config") == 0) {
  26. // TODO: an ability to set the target through the `config` command
  27. while (argc > 0) {
  28. const char *flag_name = shift(argv, argc);
  29. bool found = false;
  30. for (size_t i = 0; !found && i < ARRAY_LEN(feature_flags); ++i) {
  31. // TODO: an ability to disable flags that enabled by default
  32. // We don't have such flags yet, but maybe we will at some point?
  33. if (strcmp(feature_flags[i].name, flag_name) == 0) {
  34. feature_flags[i].enabled_by_default = true;
  35. found = true;
  36. }
  37. }
  38. if (!found) {
  39. nob_log(ERROR, "Unknown command `%s`", flag_name);
  40. return 1;
  41. }
  42. }
  43. if (!generate_default_config(CONFIG_PATH)) return 1;
  44. return 0;
  45. } else {
  46. nob_log(ERROR, "Unknown command `%s`", command_name);
  47. return 1;
  48. }
  49. }
  50. int config_exists = file_exists(CONFIG_PATH);
  51. if (config_exists < 0) return 1;
  52. if (config_exists == 0) {
  53. if (!generate_default_config(CONFIG_PATH)) return 1;
  54. } else {
  55. nob_log(INFO, "file `%s` already exists", CONFIG_PATH);
  56. }
  57. if (!generate_config_logger("build/config_logger.c")) return 1;
  58. Cmd cmd = {0};
  59. const char *stage2_binary = "build/nob_stage2";
  60. cmd_append(&cmd, NOB_REBUILD_URSELF(stage2_binary, "./src_build/nob_stage2.c"));
  61. if (!cmd_run(&cmd)) return 1;
  62. cmd_append(&cmd, stage2_binary);
  63. da_append_many(&cmd, argv, argc);
  64. if (!cmd_run(&cmd)) return 1;
  65. return 0;
  66. }