nob.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <stdbool.h>
  5. #include <stdarg.h>
  6. #include <string.h>
  7. #include <errno.h>
  8. #define NOB_IMPLEMENTATION
  9. #include "./nob.h"
  10. #include "./src_build/configurer.c"
  11. int main(int argc, char **argv)
  12. {
  13. NOB_GO_REBUILD_URSELF(argc, argv);
  14. const char *program = nob_shift_args(&argc, &argv);
  15. const char *old_build_conf_path = "./build/build.conf";
  16. int build_conf_exists = nob_file_exists(old_build_conf_path);
  17. if (build_conf_exists < 0) return 1;
  18. if (build_conf_exists) {
  19. // @backcomp
  20. nob_log(NOB_ERROR, "We found %s. That means your build folder has an old schema.", old_build_conf_path);
  21. nob_log(NOB_ERROR, "Instead of %s you are suppose to use %s to configure the build now.", old_build_conf_path, CONFIG_PATH);
  22. nob_log(NOB_ERROR, "Remove your ./build/ folder and run %s again to regenerate the folder with the new schema.", program);
  23. return 1;
  24. }
  25. nob_log(NOB_INFO, "--- STAGE 1 ---");
  26. if (!nob_mkdir_if_not_exists("build")) return 1;
  27. int config_exists = nob_file_exists(CONFIG_PATH);
  28. if (config_exists < 0) return 1;
  29. if (config_exists == 0) {
  30. if (!generate_default_config(CONFIG_PATH)) return 1;
  31. } else {
  32. nob_log(NOB_INFO, "file `%s` already exists", CONFIG_PATH);
  33. }
  34. if (!generate_config_logger("build/config_logger.c")) return 1;
  35. Nob_Cmd cmd = {0};
  36. const char *stage2_binary = "build/nob_stage2";
  37. nob_cmd_append(&cmd, NOB_REBUILD_URSELF(stage2_binary, "./src_build/nob_stage2.c"));
  38. if (!nob_cmd_run_sync(cmd)) return 1;
  39. cmd.count = 0;
  40. nob_cmd_append(&cmd, stage2_binary);
  41. nob_da_append_many(&cmd, argv, argc);
  42. if (!nob_cmd_run_sync(cmd)) return 1;
  43. return 0;
  44. }