configurer.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #define RAYLIB_VERSION "5.5"
  2. #define CONFIG_PATH "./build/config.h"
  3. #define RAYLIB_SRC_FOLDER "./thirdparty/raylib-" RAYLIB_VERSION "/src/"
  4. typedef struct {
  5. const char *macro;
  6. bool enabled_by_default;
  7. } Target_Flag;
  8. static Target_Flag target_flags[] = {
  9. {
  10. .macro = "MUSIALIZER_TARGET_LINUX",
  11. #if defined(linux) || defined(__linux) || defined(__linux__)
  12. .enabled_by_default = true,
  13. #else
  14. .enabled_by_default = false,
  15. #endif
  16. },
  17. {
  18. .macro = "MUSIALIZER_TARGET_WIN64_MINGW",
  19. #if (defined(WIN32) || defined(_WIN32)) && defined(__MINGW32__)
  20. .enabled_by_default = true,
  21. #else
  22. .enabled_by_default = false,
  23. #endif
  24. },
  25. {
  26. .macro = "MUSIALIZER_TARGET_WIN64_MSVC",
  27. #if (defined(WIN32) || defined(_WIN32)) && defined(_MSC_VER)
  28. .enabled_by_default = true,
  29. #else
  30. .enabled_by_default = false,
  31. #endif
  32. },
  33. {
  34. .macro = "MUSIALIZER_TARGET_MACOS",
  35. #if defined(__APPLE__) || defined(__MACH__)
  36. .enabled_by_default = true,
  37. #else
  38. .enabled_by_default = false,
  39. #endif
  40. },
  41. {
  42. .macro = "MUSIALIZER_TARGET_OPENBSD",
  43. #if defined(__OpenBSD__)
  44. .enabled_by_default = true,
  45. #else
  46. .enabled_by_default = false,
  47. #endif
  48. },
  49. };
  50. typedef struct {
  51. const char *name;
  52. const char *macro;
  53. const char *description;
  54. bool enabled_by_default;
  55. } Feature_Flag;
  56. static Feature_Flag feature_flags[] = {
  57. {
  58. .macro = "MUSIALIZER_HOTRELOAD",
  59. .name = "hotreload",
  60. .description = "Moves everything in src/plug.c to a separate \"DLL\" so it can be hotreloaded.",
  61. },
  62. {
  63. .macro = "MUSIALIZER_UNBUNDLE",
  64. .name = "unbundle",
  65. .description = "Don't bundle resources/ folder with the executable and load the resources directly from the folder.",
  66. },
  67. {
  68. .macro = "MUSIALIZER_MICROPHONE",
  69. .name = "microphone",
  70. .description = "Unfinished feature that enables capturing sound from the mic."
  71. },
  72. };
  73. // Removed feature flags
  74. #ifdef MUSIALIZER_ACT_ON_PRESS
  75. #error "MUSIALIZER_ACT_ON_PRESS no longer exists. Please remove it from your build/config.h"
  76. #endif // MUSIALIZER_ACT_ON_PRESS
  77. #define genf(out, ...) \
  78. do { \
  79. fprintf((out), __VA_ARGS__); \
  80. fprintf((out), " // %s:%d\n", __FILE__, __LINE__); \
  81. } while(0)
  82. bool generate_default_config(const char *file_path)
  83. {
  84. nob_log(NOB_INFO, "Generating %s", file_path);
  85. FILE *f = fopen(file_path, "wb");
  86. if (f == NULL) {
  87. nob_log(NOB_ERROR, "Could not generate %s: %s", file_path, strerror(errno));
  88. return false;
  89. }
  90. // TODO: generate_default_config() should also log what platform it picked
  91. fprintf(f, "//// Build target. Pick only one!\n");
  92. for (size_t i = 0; i < NOB_ARRAY_LEN(target_flags); ++i) {
  93. if (target_flags[i].enabled_by_default) {
  94. fprintf(f, "#define %s\n", target_flags[i].macro);
  95. } else {
  96. fprintf(f, "// #define %s\n", target_flags[i].macro);
  97. }
  98. }
  99. fprintf(f, "\n");
  100. for (size_t i = 0; i < NOB_ARRAY_LEN(feature_flags); ++i) {
  101. fprintf(f, "//// %s\n", feature_flags[i].description);
  102. if (feature_flags[i].enabled_by_default) {
  103. nob_log(INFO, "%s: ENABLED", feature_flags[i].name);
  104. fprintf(f, "#define %s\n", feature_flags[i].macro);
  105. } else {
  106. nob_log(INFO, "%s: DISABLED", feature_flags[i].name);
  107. fprintf(f, "// #define %s\n", feature_flags[i].macro);
  108. }
  109. fprintf(f, "\n");
  110. }
  111. fclose(f);
  112. return true;
  113. }
  114. bool generate_config_logger(const char *config_logger_path)
  115. {
  116. nob_log(NOB_INFO, "Generating %s", config_logger_path);
  117. FILE *f = fopen(config_logger_path, "wb");
  118. if (f == NULL) {
  119. nob_log(NOB_ERROR, "Could not generate %s: %s", config_logger_path, strerror(errno));
  120. return false;
  121. }
  122. genf(f, "void log_config(Nob_Log_Level level)");
  123. genf(f, "{");
  124. genf(f, " nob_log(level, \"Target: %%s\", MUSIALIZER_TARGET_NAME);");
  125. for (size_t i = 0; i < NOB_ARRAY_LEN(feature_flags); ++i) {
  126. genf(f, " #ifdef %s", feature_flags[i].macro);
  127. genf(f, " nob_log(level, \"%s: ENABLED\");", feature_flags[i].name);
  128. genf(f, " #else");
  129. genf(f, " nob_log(level, \"%s: DISABLED\");", feature_flags[i].name);
  130. genf(f, " #endif");
  131. }
  132. genf(f, "}");
  133. fclose(f);
  134. return true;
  135. }