nob_win64_mingw.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #define MUSIALIZER_TARGET_NAME "win64-mingw"
  2. // On windows, mingw doesn't have the `x86_64-w64-mingw32-` prefix for tools such as `windres` or `ar`.
  3. // For gcc, you can use both `x86_64-w64-mingw32-gcc` and just `gcc`
  4. #ifdef _WIN32
  5. #define MAYBE_PREFIXED(x) x
  6. #else
  7. #define MAYBE_PREFIXED(x) "x86_64-w64-mingw32-"x
  8. #endif // _WIN32
  9. bool build_musializer(void)
  10. {
  11. bool result = true;
  12. Cmd cmd = {0};
  13. Procs procs = {0};
  14. cmd_append(&cmd, MAYBE_PREFIXED("windres"));
  15. cmd_append(&cmd, "./src/musializer.rc");
  16. cmd_append(&cmd, "-O", "coff");
  17. cmd_append(&cmd, "-o", "./build/musializer.res");
  18. if (!cmd_run(&cmd)) return_defer(false);
  19. #ifdef MUSIALIZER_HOTRELOAD
  20. cmd_append(&cmd, "x86_64-w64-mingw32-gcc");
  21. cmd_append(&cmd, "-mwindows", "-Wall", "-Wextra", "-ggdb");
  22. cmd_append(&cmd, "-I.");
  23. cmd_append(&cmd, "-I"RAYLIB_SRC_FOLDER);
  24. cmd_append(&cmd, "-fPIC", "-shared");
  25. cmd_append(&cmd, "-static-libgcc");
  26. cmd_append(&cmd, "-o", "./build/libplug.dll");
  27. cmd_append(&cmd,
  28. "./src/plug.c",
  29. "./src/ffmpeg_windows.c",
  30. "./thirdparty/tinyfiledialogs.c");
  31. cmd_append(&cmd,
  32. "-L./build",
  33. "-l:raylib.dll");
  34. cmd_append(&cmd, "-lwinmm", "-lgdi32", "-lole32");
  35. if (!cmd_run(&cmd, .async = &procs)) return_defer(false);
  36. cmd_append(&cmd, "x86_64-w64-mingw32-gcc");
  37. cmd_append(&cmd, "-mwindows", "-Wall", "-Wextra", "-ggdb");
  38. cmd_append(&cmd, "-I.");
  39. cmd_append(&cmd, "-I"RAYLIB_SRC_FOLDER);
  40. cmd_append(&cmd, "-o", "./build/musializer");
  41. cmd_append(&cmd,
  42. "./src/musializer.c",
  43. "./src/hotreload_windows.c");
  44. cmd_append(&cmd,
  45. "-Wl,-rpath=./build/",
  46. "-Wl,-rpath=./",
  47. temp_sprintf("-Wl,-rpath=./build/raylib/%s", MUSIALIZER_TARGET_NAME),
  48. // NOTE: just in case somebody wants to run musializer from within the ./build/ folder
  49. temp_sprintf("-Wl,-rpath=./raylib/%s", MUSIALIZER_TARGET_NAME));
  50. cmd_append(&cmd,
  51. "-L./build",
  52. "-l:raylib.dll");
  53. cmd_append(&cmd, "-lwinmm", "-lgdi32");
  54. if (!cmd_run(&cmd, .async = &procs)) return_defer(false);
  55. if (!procs_flush(&procs)) return_defer(false);
  56. #else
  57. cmd_append(&cmd, "x86_64-w64-mingw32-gcc");
  58. cmd_append(&cmd, "-mwindows", "-Wall", "-Wextra", "-ggdb");
  59. cmd_append(&cmd, "-I.");
  60. cmd_append(&cmd, "-I"RAYLIB_SRC_FOLDER);
  61. cmd_append(&cmd, "-o", "./build/musializer");
  62. cmd_append(&cmd,
  63. "./src/plug.c",
  64. "./src/ffmpeg_windows.c",
  65. "./src/musializer.c",
  66. "./thirdparty/tinyfiledialogs.c",
  67. "./build/musializer.res"
  68. );
  69. cmd_append(&cmd,
  70. temp_sprintf("-L./build/raylib/%s", MUSIALIZER_TARGET_NAME),
  71. "-l:libraylib.a");
  72. cmd_append(&cmd, "-lwinmm", "-lgdi32", "-lole32");
  73. cmd_append(&cmd, "-static");
  74. if (!cmd_run(&cmd)) return_defer(false);
  75. #endif // MUSIALIZER_HOTRELOAD
  76. defer:
  77. cmd_free(cmd);
  78. da_free(procs);
  79. return result;
  80. }
  81. bool build_raylib()
  82. {
  83. bool result = true;
  84. Cmd cmd = {0};
  85. File_Paths object_files = {0};
  86. if (!mkdir_if_not_exists("./build/raylib")) {
  87. return_defer(false);
  88. }
  89. Procs procs = {0};
  90. const char *build_path = temp_sprintf("./build/raylib/%s", MUSIALIZER_TARGET_NAME);
  91. if (!mkdir_if_not_exists(build_path)) {
  92. return_defer(false);
  93. }
  94. for (size_t i = 0; i < ARRAY_LEN(raylib_modules); ++i) {
  95. const char *input_path = temp_sprintf(RAYLIB_SRC_FOLDER"%s.c", raylib_modules[i]);
  96. const char *output_path = temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
  97. output_path = temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
  98. da_append(&object_files, output_path);
  99. if (needs_rebuild(output_path, &input_path, 1)) {
  100. cmd_append(&cmd, "x86_64-w64-mingw32-gcc");
  101. cmd_append(&cmd, "-ggdb", "-DPLATFORM_DESKTOP", "-fPIC", "-DSUPPORT_FILEFORMAT_FLAC=1");
  102. cmd_append(&cmd, "-DPLATFORM_DESKTOP");
  103. cmd_append(&cmd, "-fPIC");
  104. cmd_append(&cmd, "-I"RAYLIB_SRC_FOLDER"external/glfw/include");
  105. cmd_append(&cmd, "-c", input_path);
  106. cmd_append(&cmd, "-o", output_path);
  107. if (!cmd_run(&cmd, .async = &procs)) return_defer(false);
  108. }
  109. }
  110. if (!procs_flush(&procs)) return_defer(false);
  111. #ifndef MUSIALIZER_HOTRELOAD
  112. const char *libraylib_path = temp_sprintf("%s/libraylib.a", build_path);
  113. if (needs_rebuild(libraylib_path, object_files.items, object_files.count)) {
  114. cmd_append(&cmd, MAYBE_PREFIXED("ar"));
  115. cmd_append(&cmd, "-crs", libraylib_path);
  116. for (size_t i = 0; i < ARRAY_LEN(raylib_modules); ++i) {
  117. const char *input_path = temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
  118. cmd_append(&cmd, input_path);
  119. }
  120. if (!cmd_run(&cmd)) return_defer(false);
  121. }
  122. #else
  123. // it cannot load the raylib dll if it not in the same folder as the executable
  124. const char *libraylib_path = "./build/raylib.dll";
  125. if (needs_rebuild(libraylib_path, object_files.items, object_files.count)) {
  126. cmd_append(&cmd, "x86_64-w64-mingw32-gcc");
  127. cmd_append(&cmd, "-shared");
  128. cmd_append(&cmd, "-o", libraylib_path);
  129. for (size_t i = 0; i < ARRAY_LEN(raylib_modules); ++i) {
  130. const char *input_path = temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
  131. cmd_append(&cmd, input_path);
  132. }
  133. cmd_append(&cmd, "-lwinmm", "-lgdi32");
  134. if (!cmd_run(&cmd)) return_defer(false);
  135. }
  136. #endif // MUSIALIZER_HOTRELOAD
  137. defer:
  138. cmd_free(cmd);
  139. da_free(object_files);
  140. return result;
  141. }
  142. bool build_dist(void)
  143. {
  144. #ifdef MUSIALIZER_HOTRELOAD
  145. nob_log(ERROR, "We do not ship with hotreload enabled");
  146. return false;
  147. #else
  148. if (!mkdir_if_not_exists("./musializer-win64-mingw/")) return false;
  149. if (!copy_file("./build/musializer.exe", "./musializer-win64-mingw/musializer.exe")) return false;
  150. if (!copy_directory_recursively("./resources/", "./musializer-win64-mingw/resources/")) return false;
  151. if (!copy_file("musializer-logged.bat", "./musializer-win64-mingw/musializer-logged.bat")) return false;
  152. // TODO: pack ffmpeg.exe with windows build
  153. //if (!copy_file("ffmpeg.exe", "./musializer-win64-mingw/ffmpeg.exe")) return false;
  154. Cmd cmd = {0};
  155. const char *dist_path = "./musializer-win64-mingw.zip";
  156. cmd_append(&cmd, "zip", "-r", dist_path, "./musializer-win64-mingw/");
  157. bool ok = cmd_run(&cmd);
  158. cmd_free(cmd);
  159. if (!ok) return false;
  160. nob_log(INFO, "Created %s", dist_path);
  161. return true;
  162. #endif // MUSIALIZER_HOTRELOAD
  163. }