Skip to content

Commit a6aba8b

Browse files
committed
Merge branch 'upgrade-nob'
2 parents c35d0e6 + 14c12bf commit a6aba8b

2 files changed

Lines changed: 1116 additions & 352 deletions

File tree

nob.c

Lines changed: 60 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#define NOB_IMPLEMENTATION
2+
#define NOB_STRIP_PREFIX
23
#include "nob.h"
34

45
// Folder must with with forward slash /
@@ -8,124 +9,128 @@
89
#define THIRDPARTY_DIR "./thirdparty/"
910
#define RAYLIB_DIR THIRDPARTY_DIR"raylib-5.0_linux_amd64/"
1011

11-
void cflags(Nob_Cmd *cmd)
12+
Cmd cmd = {0};
13+
Procs procs = {0};
14+
15+
void cflags(void)
1216
{
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.");
1721
}
1822

19-
void cc(Nob_Cmd *cmd)
23+
void cc(void)
2024
{
21-
nob_cmd_append(cmd, "cc");
22-
cflags(cmd);
25+
cmd_append(&cmd, "cc");
26+
cflags();
2327
}
2428

25-
void cxx(Nob_Cmd *cmd)
29+
void cxx(void)
2630
{
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();
3034
}
3135

32-
void libs(Nob_Cmd *cmd)
36+
void libs(void)
3337
{
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");
3842
}
3943

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)
4145
{
42-
int rebuild_is_needed = nob_needs_rebuild1(output_path, source_path);
46+
int rebuild_is_needed = needs_rebuild1(output_path, source_path);
4347
if (rebuild_is_needed < 0) return false;
4448

4549
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);
5256
}
5357

54-
nob_log(NOB_INFO, "%s is up-to-date", output_path);
58+
nob_log(INFO, "%s is up-to-date", output_path);
5559
return true;
5660
}
5761

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)
5963
{
60-
int rebuild_is_needed = nob_needs_rebuild1(output_path, source_path);
64+
int rebuild_is_needed = needs_rebuild1(output_path, source_path);
6165
if (rebuild_is_needed < 0) return false;
6266

6367
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);
7074
}
7175

72-
nob_log(NOB_INFO, "%s is up-to-date", output_path);
76+
nob_log(INFO, "%s is up-to-date", output_path);
7377
return true;
7478
}
7579

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)
7781
{
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);
7983
if (rebuild_is_needed < 0) return false;
8084

8185
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);
8791
}
8892

89-
nob_log(NOB_INFO, "%s is up-to-date", output_path);
93+
nob_log(INFO, "%s is up-to-date", output_path);
9094
return true;
9195
}
9296

9397
int main(int argc, char **argv)
9498
{
9599
NOB_GO_REBUILD_URSELF(argc, argv);
96100

97-
const char *program_name = nob_shift_args(&argc, &argv);
101+
const char *program_name = shift(argv, argc);
98102
(void) program_name;
99103

100104
bool force = false;
101105
while (argc > 0) {
102-
const char *flag = nob_shift_args(&argc, &argv);
106+
const char *flag = shift(argv, argc);
103107
if (strcmp(flag, "-f") == 0) {
104108
force = true;
105109
} else {
106-
nob_log(NOB_ERROR, "Unknown flag %s", flag);
110+
nob_log(ERROR, "Unknown flag %s", flag);
107111
return 1;
108112
}
109113
}
110114

111-
if (!nob_mkdir_if_not_exists(BUILD_DIR)) return 1;
115+
if (!mkdir_if_not_exists(BUILD_DIR)) return 1;
112116

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;
119122

120123
{
121124
const char *output_path = BUILD_DIR"panim";
122125
const char *input_paths[] = {
123126
PANIM_DIR"panim.c",
124127
PANIM_DIR"ffmpeg_linux.c"
125128
};
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;
128131
}
129132

133+
if (!procs_flush(&procs)) return 1;
134+
130135
return 0;
131136
}

0 commit comments

Comments
 (0)