-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathnob_linux.c
More file actions
144 lines (124 loc) · 5.1 KB
/
nob_linux.c
File metadata and controls
144 lines (124 loc) · 5.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#define MUSIALIZER_TARGET_NAME "linux"
bool build_musializer(void)
{
bool result = true;
Cmd cmd = {0};
Procs procs = {0};
#ifdef MUSIALIZER_HOTRELOAD
// TODO: add a way to replace `cc` with something else GCC compatible on POSIX
// Like `clang` for instance
cmd_append(&cmd, "cc",
"-Wall", "-Wextra", "-ggdb",
"-I.", "-I"RAYLIB_SRC_FOLDER,
"-fPIC", "-shared",
"-o", "./build/libplug.so",
"./src/plug.c", "./src/ffmpeg_posix.c", "./thirdparty/tinyfiledialogs.c",
temp_sprintf("-L./build/raylib/%s", MUSIALIZER_TARGET_NAME), "-l:libraylib.so",
"-O3", "-march=native", "-ffast-math",
"-lm", "-ldl", "-flto=auto", "-lpthread");
if (!cmd_run(&cmd)) return_defer(false);
cmd_append(&cmd, "cc",
"-Wall", "-Wextra", "-ggdb",
"-I.", "-I"RAYLIB_SRC_FOLDER,
"-o", "./build/musializer",
"./src/musializer.c", "./src/hotreload_posix.c",
"-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),
temp_sprintf("-L./build/raylib/%s", MUSIALIZER_TARGET_NAME),
"-O3", "-march=native", "-ffast-math",
"-l:libraylib.so", "-lm", "-ldl", "-flto=auto", "-lpthread");
if (!cmd_run(&cmd)) return_defer(false);
if (!procs_flush(&procs)) return_defer(false);
#else
cmd_append(&cmd, "cc",
"-Wall", "-Wextra", "-ggdb",
"-I.",
"-I"RAYLIB_SRC_FOLDER,
"-o", "./build/musializer",
"./src/plug.c", "./src/ffmpeg_posix.c", "./src/musializer.c", "./thirdparty/tinyfiledialogs.c",
temp_sprintf("-L./build/raylib/%s", MUSIALIZER_TARGET_NAME), "-l:libraylib.a",
"-O3", "-march=native", "-ffast-math",
"-lm", "-ldl", "-flto=auto", "-lpthread");
if (!cmd_run(&cmd)) return_defer(false);
#endif // MUSIALIZER_HOTRELOAD
defer:
cmd_free(cmd);
da_free(procs);
return result;
}
bool build_raylib(void)
{
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, "cc",
"-ggdb", "-DPLATFORM_DESKTOP", "-D_GLFW_X11", "-fPIC", "-DSUPPORT_FILEFORMAT_FLAC=1",
"-I"RAYLIB_SRC_FOLDER"external/glfw/include",
"-c", input_path,
"-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, "ar", "-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
const char *libraylib_path = temp_sprintf("%s/libraylib.so", build_path);
if (needs_rebuild(libraylib_path, object_files.items, object_files.count)) {
cmd_append(&cmd, "cc", "-shared", "-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);
}
if (!cmd_run(&cmd)) return_defer(false);
}
#endif // MUSIALIZER_HOTRELOAD
defer:
cmd_free(cmd);
da_free(object_files);
return result;
}
bool build_dist()
{
#ifdef MUSIALIZER_HOTRELOAD
nob_log(ERROR, "We do not ship with hotreload enabled");
return false;
#else
if (!mkdir_if_not_exists("./musializer-linux-x86_64/")) return false;
if (!copy_file("./build/musializer", "./musializer-linux-x86_64/musializer")) return false;
if (!copy_directory_recursively("./resources/", "./musializer-linux-x86_64/resources/")) return false;
// TODO: should we pack ffmpeg with Linux build?
// There are some static executables for Linux
Cmd cmd = {0};
cmd_append(&cmd, "tar", "fvcz", "./musializer-linux-x86_64.tar.gz", "./musializer-linux-x86_64");
bool ok = cmd_run(&cmd);
cmd_free(cmd);
if (!ok) return false;
return true;
#endif // MUSIALIZER_HOTRELOAD
}