|
1 | 1 | #define NOB_IMPLEMENTATION |
| 2 | +#define NOB_STRIP_PREFIX |
2 | 3 | #include "nob.h" |
3 | 4 |
|
4 | 5 | // Folder must with with forward slash / |
|
8 | 9 | #define THIRDPARTY_DIR "./thirdparty/" |
9 | 10 | #define RAYLIB_DIR THIRDPARTY_DIR"raylib-5.0_linux_amd64/" |
10 | 11 |
|
11 | | -void cflags(Nob_Cmd *cmd) |
| 12 | +Cmd cmd = {0}; |
| 13 | +Procs procs = {0}; |
| 14 | + |
| 15 | +void cflags(void) |
12 | 16 | { |
13 | | - nob_cmd_append(cmd, "-Wall", "-Wextra", "-ggdb"); |
14 | | - nob_cmd_append(cmd, "-I"RAYLIB_DIR"include"); |
15 | | - nob_cmd_append(cmd, "-I"PANIM_DIR); |
16 | | - nob_cmd_append(cmd, "-I."); |
| 17 | + cmd_append(&cmd, "-Wall", "-Wextra", "-ggdb"); |
| 18 | + cmd_append(&cmd, "-I"RAYLIB_DIR"include"); |
| 19 | + cmd_append(&cmd, "-I"PANIM_DIR); |
| 20 | + cmd_append(&cmd, "-I."); |
17 | 21 | } |
18 | 22 |
|
19 | | -void cc(Nob_Cmd *cmd) |
| 23 | +void cc(void) |
20 | 24 | { |
21 | | - nob_cmd_append(cmd, "cc"); |
22 | | - cflags(cmd); |
| 25 | + cmd_append(&cmd, "cc"); |
| 26 | + cflags(); |
23 | 27 | } |
24 | 28 |
|
25 | | -void cxx(Nob_Cmd *cmd) |
| 29 | +void cxx(void) |
26 | 30 | { |
27 | | - nob_cmd_append(cmd, "g++"); |
28 | | - nob_cmd_append(cmd, "-Wno-missing-field-initializers"); // Very common warning when compiling raymath.h as C++ |
29 | | - cflags(cmd); |
| 31 | + cmd_append(&cmd, "g++"); |
| 32 | + cmd_append(&cmd, "-Wno-missing-field-initializers"); // Very common warning when compiling raymath.h as C++ |
| 33 | + cflags(); |
30 | 34 | } |
31 | 35 |
|
32 | | -void libs(Nob_Cmd *cmd) |
| 36 | +void libs(void) |
33 | 37 | { |
34 | | - nob_cmd_append(cmd, "-Wl,-rpath="RAYLIB_DIR"lib/"); |
35 | | - nob_cmd_append(cmd, "-Wl,-rpath="PANIM_DIR); |
36 | | - nob_cmd_append(cmd, "-L"RAYLIB_DIR"lib"); |
37 | | - nob_cmd_append(cmd, "-l:libraylib.so", "-lm", "-ldl", "-lpthread"); |
| 38 | + cmd_append(&cmd, "-Wl,-rpath="RAYLIB_DIR"lib/"); |
| 39 | + cmd_append(&cmd, "-Wl,-rpath="PANIM_DIR); |
| 40 | + cmd_append(&cmd, "-L"RAYLIB_DIR"lib"); |
| 41 | + cmd_append(&cmd, "-l:libraylib.so", "-lm", "-ldl", "-lpthread"); |
38 | 42 | } |
39 | 43 |
|
40 | | -bool build_plug_c(bool force, Nob_Cmd *cmd, const char *source_path, const char *output_path) |
| 44 | +bool build_plug_c(bool force, const char *source_path, const char *output_path) |
41 | 45 | { |
42 | | - int rebuild_is_needed = nob_needs_rebuild1(output_path, source_path); |
| 46 | + int rebuild_is_needed = needs_rebuild1(output_path, source_path); |
43 | 47 | if (rebuild_is_needed < 0) return false; |
44 | 48 |
|
45 | 49 | if (force || rebuild_is_needed) { |
46 | | - cc(cmd); |
47 | | - nob_cmd_append(cmd, "-fPIC", "-shared", "-Wl,--no-undefined"); |
48 | | - nob_cmd_append(cmd, "-o", output_path); |
49 | | - nob_cmd_append(cmd, source_path); |
50 | | - libs(cmd); |
51 | | - return nob_cmd_run_sync_and_reset(cmd); |
| 50 | + cc(); |
| 51 | + cmd_append(&cmd, "-fPIC", "-shared", "-Wl,--no-undefined"); |
| 52 | + cmd_append(&cmd, "-o", output_path); |
| 53 | + cmd_append(&cmd, source_path); |
| 54 | + libs(); |
| 55 | + return cmd_run(&cmd, .async = &procs); |
52 | 56 | } |
53 | 57 |
|
54 | | - nob_log(NOB_INFO, "%s is up-to-date", output_path); |
| 58 | + nob_log(INFO, "%s is up-to-date", output_path); |
55 | 59 | return true; |
56 | 60 | } |
57 | 61 |
|
58 | | -bool build_plug_cxx(bool force, Nob_Cmd *cmd, const char *source_path, const char *output_path) |
| 62 | +bool build_plug_cxx(bool force, const char *source_path, const char *output_path) |
59 | 63 | { |
60 | | - int rebuild_is_needed = nob_needs_rebuild1(output_path, source_path); |
| 64 | + int rebuild_is_needed = needs_rebuild1(output_path, source_path); |
61 | 65 | if (rebuild_is_needed < 0) return false; |
62 | 66 |
|
63 | 67 | if (force || rebuild_is_needed) { |
64 | | - cxx(cmd); |
65 | | - nob_cmd_append(cmd, "-fPIC", "-shared", "-Wl,--no-undefined"); |
66 | | - nob_cmd_append(cmd, "-o", output_path); |
67 | | - nob_cmd_append(cmd, source_path); |
68 | | - libs(cmd); |
69 | | - return nob_cmd_run_sync_and_reset(cmd); |
| 68 | + cxx(); |
| 69 | + cmd_append(&cmd, "-fPIC", "-shared", "-Wl,--no-undefined"); |
| 70 | + cmd_append(&cmd, "-o", output_path); |
| 71 | + cmd_append(&cmd, source_path); |
| 72 | + libs(); |
| 73 | + return cmd_run(&cmd, .async = &procs); |
70 | 74 | } |
71 | 75 |
|
72 | | - nob_log(NOB_INFO, "%s is up-to-date", output_path); |
| 76 | + nob_log(INFO, "%s is up-to-date", output_path); |
73 | 77 | return true; |
74 | 78 | } |
75 | 79 |
|
76 | | -bool build_exe(bool force, Nob_Cmd *cmd, const char **input_paths, size_t input_paths_len, const char *output_path) |
| 80 | +bool build_exe(bool force, const char **input_paths, size_t input_paths_len, const char *output_path) |
77 | 81 | { |
78 | | - int rebuild_is_needed = nob_needs_rebuild(output_path, input_paths, input_paths_len); |
| 82 | + int rebuild_is_needed = needs_rebuild(output_path, input_paths, input_paths_len); |
79 | 83 | if (rebuild_is_needed < 0) return false; |
80 | 84 |
|
81 | 85 | if (force || rebuild_is_needed) { |
82 | | - cc(cmd); |
83 | | - nob_cmd_append(cmd, "-o", output_path); |
84 | | - nob_da_append_many(cmd, input_paths, input_paths_len); |
85 | | - libs(cmd); |
86 | | - return nob_cmd_run_sync_and_reset(cmd); |
| 86 | + cc(); |
| 87 | + cmd_append(&cmd, "-o", output_path); |
| 88 | + da_append_many(&cmd, input_paths, input_paths_len); |
| 89 | + libs(); |
| 90 | + return cmd_run(&cmd, .async = &procs); |
87 | 91 | } |
88 | 92 |
|
89 | | - nob_log(NOB_INFO, "%s is up-to-date", output_path); |
| 93 | + nob_log(INFO, "%s is up-to-date", output_path); |
90 | 94 | return true; |
91 | 95 | } |
92 | 96 |
|
93 | 97 | int main(int argc, char **argv) |
94 | 98 | { |
95 | 99 | NOB_GO_REBUILD_URSELF(argc, argv); |
96 | 100 |
|
97 | | - const char *program_name = nob_shift_args(&argc, &argv); |
| 101 | + const char *program_name = shift(argv, argc); |
98 | 102 | (void) program_name; |
99 | 103 |
|
100 | 104 | bool force = false; |
101 | 105 | while (argc > 0) { |
102 | | - const char *flag = nob_shift_args(&argc, &argv); |
| 106 | + const char *flag = shift(argv, argc); |
103 | 107 | if (strcmp(flag, "-f") == 0) { |
104 | 108 | force = true; |
105 | 109 | } else { |
106 | | - nob_log(NOB_ERROR, "Unknown flag %s", flag); |
| 110 | + nob_log(ERROR, "Unknown flag %s", flag); |
107 | 111 | return 1; |
108 | 112 | } |
109 | 113 | } |
110 | 114 |
|
111 | | - if (!nob_mkdir_if_not_exists(BUILD_DIR)) return 1; |
| 115 | + if (!mkdir_if_not_exists(BUILD_DIR)) return 1; |
112 | 116 |
|
113 | | - Nob_Cmd cmd = {0}; |
114 | | - if (!build_plug_c(force, &cmd, PLUGS_DIR"tm/plug.c", BUILD_DIR"libtm.so")) return 1; |
115 | | - if (!build_plug_c(force, &cmd, PLUGS_DIR"template/plug.c", BUILD_DIR"libtemplate.so")) return 1; |
116 | | - if (!build_plug_c(force, &cmd, PLUGS_DIR"squares/plug.c", BUILD_DIR"libsquare.so")) return 1; |
117 | | - if (!build_plug_c(force, &cmd, PLUGS_DIR"bezier/plug.c", BUILD_DIR"libbezier.so")) return 1; |
118 | | - if (!build_plug_cxx(force, &cmd, PLUGS_DIR"cpp/plug.cpp", BUILD_DIR"libcpp.so")) return 1; |
| 117 | + if (!build_plug_c(force, PLUGS_DIR"tm/plug.c", BUILD_DIR"libtm.so")) return 1; |
| 118 | + if (!build_plug_c(force, PLUGS_DIR"template/plug.c", BUILD_DIR"libtemplate.so")) return 1; |
| 119 | + if (!build_plug_c(force, PLUGS_DIR"squares/plug.c", BUILD_DIR"libsquare.so")) return 1; |
| 120 | + if (!build_plug_c(force, PLUGS_DIR"bezier/plug.c", BUILD_DIR"libbezier.so")) return 1; |
| 121 | + if (!build_plug_cxx(force, PLUGS_DIR"cpp/plug.cpp", BUILD_DIR"libcpp.so")) return 1; |
119 | 122 |
|
120 | 123 | { |
121 | 124 | const char *output_path = BUILD_DIR"panim"; |
122 | 125 | const char *input_paths[] = { |
123 | 126 | PANIM_DIR"panim.c", |
124 | 127 | PANIM_DIR"ffmpeg_linux.c" |
125 | 128 | }; |
126 | | - size_t input_paths_len = NOB_ARRAY_LEN(input_paths); |
127 | | - if (!build_exe(force, &cmd, input_paths, input_paths_len, output_path)) return 1; |
| 129 | + size_t input_paths_len = ARRAY_LEN(input_paths); |
| 130 | + if (!build_exe(force, input_paths, input_paths_len, output_path)) return 1; |
128 | 131 | } |
129 | 132 |
|
| 133 | + if (!procs_flush(&procs)) return 1; |
| 134 | + |
130 | 135 | return 0; |
131 | 136 | } |
0 commit comments