123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185 |
- #define MUSIALIZER_TARGET_NAME "win64-mingw"
- // On windows, mingw doesn't have the `x86_64-w64-mingw32-` prefix for tools such as `windres` or `ar`.
- // For gcc, you can use both `x86_64-w64-mingw32-gcc` and just `gcc`
- #ifdef _WIN32
- #define MAYBE_PREFIXED(x) x
- #else
- #define MAYBE_PREFIXED(x) "x86_64-w64-mingw32-"x
- #endif // _WIN32
- bool build_musializer(void)
- {
- bool result = true;
- Cmd cmd = {0};
- Procs procs = {0};
- cmd_append(&cmd, MAYBE_PREFIXED("windres"));
- cmd_append(&cmd, "./src/musializer.rc");
- cmd_append(&cmd, "-O", "coff");
- cmd_append(&cmd, "-o", "./build/musializer.res");
- if (!cmd_run(&cmd)) return_defer(false);
- #ifdef MUSIALIZER_HOTRELOAD
- cmd_append(&cmd, "x86_64-w64-mingw32-gcc");
- cmd_append(&cmd, "-mwindows", "-Wall", "-Wextra", "-ggdb");
- cmd_append(&cmd, "-I.");
- cmd_append(&cmd, "-I"RAYLIB_SRC_FOLDER);
- cmd_append(&cmd, "-fPIC", "-shared");
- cmd_append(&cmd, "-static-libgcc");
- cmd_append(&cmd, "-o", "./build/libplug.dll");
- cmd_append(&cmd,
- "./src/plug.c",
- "./src/ffmpeg_windows.c",
- "./thirdparty/tinyfiledialogs.c");
- cmd_append(&cmd,
- "-L./build",
- "-l:raylib.dll");
- cmd_append(&cmd, "-lwinmm", "-lgdi32", "-lole32");
- if (!cmd_run(&cmd, .async = &procs)) return_defer(false);
- cmd_append(&cmd, "x86_64-w64-mingw32-gcc");
- cmd_append(&cmd, "-mwindows", "-Wall", "-Wextra", "-ggdb");
- cmd_append(&cmd, "-I.");
- cmd_append(&cmd, "-I"RAYLIB_SRC_FOLDER);
- cmd_append(&cmd, "-o", "./build/musializer");
- cmd_append(&cmd,
- "./src/musializer.c",
- "./src/hotreload_windows.c");
- cmd_append(&cmd,
- "-Wl,-rpath=./build/",
- "-Wl,-rpath=./",
- temp_sprintf("-Wl,-rpath=./build/raylib/%s", MUSIALIZER_TARGET_NAME),
- // NOTE: just in case somebody wants to run musializer from within the ./build/ folder
- temp_sprintf("-Wl,-rpath=./raylib/%s", MUSIALIZER_TARGET_NAME));
- cmd_append(&cmd,
- "-L./build",
- "-l:raylib.dll");
- cmd_append(&cmd, "-lwinmm", "-lgdi32");
- if (!cmd_run(&cmd, .async = &procs)) return_defer(false);
- if (!procs_flush(&procs)) return_defer(false);
- #else
- cmd_append(&cmd, "x86_64-w64-mingw32-gcc");
- cmd_append(&cmd, "-mwindows", "-Wall", "-Wextra", "-ggdb");
- cmd_append(&cmd, "-I.");
- cmd_append(&cmd, "-I"RAYLIB_SRC_FOLDER);
- cmd_append(&cmd, "-o", "./build/musializer");
- cmd_append(&cmd,
- "./src/plug.c",
- "./src/ffmpeg_windows.c",
- "./src/musializer.c",
- "./thirdparty/tinyfiledialogs.c",
- "./build/musializer.res"
- );
- cmd_append(&cmd,
- temp_sprintf("-L./build/raylib/%s", MUSIALIZER_TARGET_NAME),
- "-l:libraylib.a");
- cmd_append(&cmd, "-lwinmm", "-lgdi32", "-lole32");
- cmd_append(&cmd, "-static");
- if (!cmd_run(&cmd)) return_defer(false);
- #endif // MUSIALIZER_HOTRELOAD
- defer:
- cmd_free(cmd);
- da_free(procs);
- return result;
- }
- bool build_raylib()
- {
- bool result = true;
- Cmd cmd = {0};
- File_Paths object_files = {0};
- if (!mkdir_if_not_exists("./build/raylib")) {
- return_defer(false);
- }
- Procs procs = {0};
- const char *build_path = temp_sprintf("./build/raylib/%s", MUSIALIZER_TARGET_NAME);
- if (!mkdir_if_not_exists(build_path)) {
- return_defer(false);
- }
- for (size_t i = 0; i < ARRAY_LEN(raylib_modules); ++i) {
- const char *input_path = temp_sprintf(RAYLIB_SRC_FOLDER"%s.c", raylib_modules[i]);
- const char *output_path = temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
- output_path = temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
- da_append(&object_files, output_path);
- if (needs_rebuild(output_path, &input_path, 1)) {
- cmd_append(&cmd, "x86_64-w64-mingw32-gcc");
- cmd_append(&cmd, "-ggdb", "-DPLATFORM_DESKTOP", "-fPIC", "-DSUPPORT_FILEFORMAT_FLAC=1");
- cmd_append(&cmd, "-DPLATFORM_DESKTOP");
- cmd_append(&cmd, "-fPIC");
- cmd_append(&cmd, "-I"RAYLIB_SRC_FOLDER"external/glfw/include");
- cmd_append(&cmd, "-c", input_path);
- cmd_append(&cmd, "-o", output_path);
- if (!cmd_run(&cmd, .async = &procs)) return_defer(false);
- }
- }
- if (!procs_flush(&procs)) return_defer(false);
- #ifndef MUSIALIZER_HOTRELOAD
- const char *libraylib_path = temp_sprintf("%s/libraylib.a", build_path);
- if (needs_rebuild(libraylib_path, object_files.items, object_files.count)) {
- cmd_append(&cmd, MAYBE_PREFIXED("ar"));
- cmd_append(&cmd, "-crs", libraylib_path);
- for (size_t i = 0; i < ARRAY_LEN(raylib_modules); ++i) {
- const char *input_path = temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
- cmd_append(&cmd, input_path);
- }
- if (!cmd_run(&cmd)) return_defer(false);
- }
- #else
- // it cannot load the raylib dll if it not in the same folder as the executable
- const char *libraylib_path = "./build/raylib.dll";
- if (needs_rebuild(libraylib_path, object_files.items, object_files.count)) {
- cmd_append(&cmd, "x86_64-w64-mingw32-gcc");
- cmd_append(&cmd, "-shared");
- cmd_append(&cmd, "-o", libraylib_path);
- for (size_t i = 0; i < ARRAY_LEN(raylib_modules); ++i) {
- const char *input_path = temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
- cmd_append(&cmd, input_path);
- }
- cmd_append(&cmd, "-lwinmm", "-lgdi32");
- if (!cmd_run(&cmd)) return_defer(false);
- }
- #endif // MUSIALIZER_HOTRELOAD
- defer:
- cmd_free(cmd);
- da_free(object_files);
- return result;
- }
- bool build_dist(void)
- {
- #ifdef MUSIALIZER_HOTRELOAD
- nob_log(ERROR, "We do not ship with hotreload enabled");
- return false;
- #else
- if (!mkdir_if_not_exists("./musializer-win64-mingw/")) return false;
- if (!copy_file("./build/musializer.exe", "./musializer-win64-mingw/musializer.exe")) return false;
- if (!copy_directory_recursively("./resources/", "./musializer-win64-mingw/resources/")) return false;
- if (!copy_file("musializer-logged.bat", "./musializer-win64-mingw/musializer-logged.bat")) return false;
- // TODO: pack ffmpeg.exe with windows build
- //if (!copy_file("ffmpeg.exe", "./musializer-win64-mingw/ffmpeg.exe")) return false;
- Cmd cmd = {0};
- const char *dist_path = "./musializer-win64-mingw.zip";
- cmd_append(&cmd, "zip", "-r", dist_path, "./musializer-win64-mingw/");
- bool ok = cmd_run(&cmd);
- cmd_free(cmd);
- if (!ok) return false;
- nob_log(INFO, "Created %s", dist_path);
- return true;
- #endif // MUSIALIZER_HOTRELOAD
- }
|