nob_linux.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #define MUSIALIZER_TARGET_NAME "linux"
  2. bool build_musializer(void)
  3. {
  4. bool result = true;
  5. Cmd cmd = {0};
  6. Procs procs = {0};
  7. #ifdef MUSIALIZER_HOTRELOAD
  8. // TODO: add a way to replace `cc` with something else GCC compatible on POSIX
  9. // Like `clang` for instance
  10. cmd_append(&cmd, "cc",
  11. "-Wall", "-Wextra", "-ggdb",
  12. "-I.", "-I"RAYLIB_SRC_FOLDER,
  13. "-fPIC", "-shared",
  14. "-o", "./build/libplug.so",
  15. "./src/plug.c", "./src/ffmpeg_posix.c", "./thirdparty/tinyfiledialogs.c",
  16. temp_sprintf("-L./build/raylib/%s", MUSIALIZER_TARGET_NAME), "-l:libraylib.so",
  17. "-O3", "-march=native", "-ffast-math",
  18. "-lm", "-ldl", "-flto=auto", "-lpthread");
  19. if (!cmd_run(&cmd)) return_defer(false);
  20. cmd_append(&cmd, "cc",
  21. "-Wall", "-Wextra", "-ggdb",
  22. "-I.", "-I"RAYLIB_SRC_FOLDER,
  23. "-o", "./build/musializer",
  24. "./src/musializer.c", "./src/hotreload_posix.c",
  25. "-Wl,-rpath=./build/",
  26. "-Wl,-rpath=./",
  27. temp_sprintf("-Wl,-rpath=./build/raylib/%s", MUSIALIZER_TARGET_NAME),
  28. // NOTE: just in case somebody wants to run musializer from within the ./build/ folder
  29. temp_sprintf("-Wl,-rpath=./raylib/%s", MUSIALIZER_TARGET_NAME),
  30. temp_sprintf("-L./build/raylib/%s", MUSIALIZER_TARGET_NAME),
  31. "-O3", "-march=native", "-ffast-math",
  32. "-l:libraylib.so", "-lm", "-ldl", "-flto=auto", "-lpthread");
  33. if (!cmd_run(&cmd)) return_defer(false);
  34. if (!procs_flush(&procs)) return_defer(false);
  35. #else
  36. cmd_append(&cmd, "cc",
  37. "-Wall", "-Wextra", "-ggdb",
  38. "-I.",
  39. "-I"RAYLIB_SRC_FOLDER,
  40. "-o", "./build/musializer",
  41. "./src/plug.c", "./src/ffmpeg_posix.c", "./src/musializer.c", "./thirdparty/tinyfiledialogs.c",
  42. temp_sprintf("-L./build/raylib/%s", MUSIALIZER_TARGET_NAME), "-l:libraylib.a",
  43. "-O3", "-march=native", "-ffast-math",
  44. "-lm", "-ldl", "-flto=auto", "-lpthread");
  45. if (!cmd_run(&cmd)) return_defer(false);
  46. #endif // MUSIALIZER_HOTRELOAD
  47. defer:
  48. cmd_free(cmd);
  49. da_free(procs);
  50. return result;
  51. }
  52. bool build_raylib(void)
  53. {
  54. bool result = true;
  55. Cmd cmd = {0};
  56. File_Paths object_files = {0};
  57. if (!mkdir_if_not_exists("./build/raylib")) {
  58. return_defer(false);
  59. }
  60. Procs procs = {0};
  61. const char *build_path = temp_sprintf("./build/raylib/%s", MUSIALIZER_TARGET_NAME);
  62. if (!mkdir_if_not_exists(build_path)) {
  63. return_defer(false);
  64. }
  65. for (size_t i = 0; i < ARRAY_LEN(raylib_modules); ++i) {
  66. const char *input_path = temp_sprintf(RAYLIB_SRC_FOLDER"%s.c", raylib_modules[i]);
  67. const char *output_path = temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
  68. output_path = temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
  69. da_append(&object_files, output_path);
  70. if (needs_rebuild(output_path, &input_path, 1)) {
  71. cmd_append(&cmd, "cc",
  72. "-ggdb", "-DPLATFORM_DESKTOP", "-D_GLFW_X11", "-fPIC", "-DSUPPORT_FILEFORMAT_FLAC=1",
  73. "-I"RAYLIB_SRC_FOLDER"external/glfw/include",
  74. "-c", input_path,
  75. "-o", output_path);
  76. if (!cmd_run(&cmd, .async = &procs)) return_defer(false);
  77. }
  78. }
  79. if (!procs_flush(&procs)) return_defer(false);
  80. #ifndef MUSIALIZER_HOTRELOAD
  81. const char *libraylib_path = temp_sprintf("%s/libraylib.a", build_path);
  82. if (needs_rebuild(libraylib_path, object_files.items, object_files.count)) {
  83. cmd_append(&cmd, "ar", "-crs", libraylib_path);
  84. for (size_t i = 0; i < ARRAY_LEN(raylib_modules); ++i) {
  85. const char *input_path = temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
  86. cmd_append(&cmd, input_path);
  87. }
  88. if (!cmd_run(&cmd)) return_defer(false);
  89. }
  90. #else
  91. const char *libraylib_path = temp_sprintf("%s/libraylib.so", build_path);
  92. if (needs_rebuild(libraylib_path, object_files.items, object_files.count)) {
  93. cmd_append(&cmd, "cc", "-shared", "-o", libraylib_path);
  94. for (size_t i = 0; i < ARRAY_LEN(raylib_modules); ++i) {
  95. const char *input_path = temp_sprintf("%s/%s.o", build_path, raylib_modules[i]);
  96. cmd_append(&cmd, input_path);
  97. }
  98. if (!cmd_run(&cmd)) return_defer(false);
  99. }
  100. #endif // MUSIALIZER_HOTRELOAD
  101. defer:
  102. cmd_free(cmd);
  103. da_free(object_files);
  104. return result;
  105. }
  106. bool build_dist()
  107. {
  108. #ifdef MUSIALIZER_HOTRELOAD
  109. nob_log(ERROR, "We do not ship with hotreload enabled");
  110. return false;
  111. #else
  112. if (!mkdir_if_not_exists("./musializer-linux-x86_64/")) return false;
  113. if (!copy_file("./build/musializer", "./musializer-linux-x86_64/musializer")) return false;
  114. if (!copy_directory_recursively("./resources/", "./musializer-linux-x86_64/resources/")) return false;
  115. // TODO: should we pack ffmpeg with Linux build?
  116. // There are some static executables for Linux
  117. Cmd cmd = {0};
  118. cmd_append(&cmd, "tar", "fvcz", "./musializer-linux-x86_64.tar.gz", "./musializer-linux-x86_64");
  119. bool ok = cmd_run(&cmd);
  120. cmd_free(cmd);
  121. if (!ok) return false;
  122. return true;
  123. #endif // MUSIALIZER_HOTRELOAD
  124. }