configurer.c 4.6 KB

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