Skip to content

Commit 68bc124

Browse files
committed
make cmd a global variable
1 parent b4e4535 commit 68bc124

File tree

1 file changed

+45
-44
lines changed

1 file changed

+45
-44
lines changed

nob.c

Lines changed: 45 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -9,82 +9,84 @@
99
#define THIRDPARTY_DIR "./thirdparty/"
1010
#define RAYLIB_DIR THIRDPARTY_DIR"raylib-5.0_linux_amd64/"
1111

12-
void cflags(Cmd *cmd)
12+
Cmd cmd = {0};
13+
14+
void cflags(void)
1315
{
14-
cmd_append(cmd, "-Wall", "-Wextra", "-ggdb");
15-
cmd_append(cmd, "-I"RAYLIB_DIR"include");
16-
cmd_append(cmd, "-I"PANIM_DIR);
17-
cmd_append(cmd, "-I.");
16+
cmd_append(&cmd, "-Wall", "-Wextra", "-ggdb");
17+
cmd_append(&cmd, "-I"RAYLIB_DIR"include");
18+
cmd_append(&cmd, "-I"PANIM_DIR);
19+
cmd_append(&cmd, "-I.");
1820
}
1921

20-
void cc(Cmd *cmd)
22+
void cc(void)
2123
{
22-
cmd_append(cmd, "cc");
23-
cflags(cmd);
24+
cmd_append(&cmd, "cc");
25+
cflags();
2426
}
2527

26-
void cxx(Cmd *cmd)
28+
void cxx(void)
2729
{
28-
cmd_append(cmd, "g++");
29-
cmd_append(cmd, "-Wno-missing-field-initializers"); // Very common warning when compiling raymath.h as C++
30-
cflags(cmd);
30+
cmd_append(&cmd, "g++");
31+
cmd_append(&cmd, "-Wno-missing-field-initializers"); // Very common warning when compiling raymath.h as C++
32+
cflags();
3133
}
3234

33-
void libs(Cmd *cmd)
35+
void libs(void)
3436
{
35-
cmd_append(cmd, "-Wl,-rpath="RAYLIB_DIR"lib/");
36-
cmd_append(cmd, "-Wl,-rpath="PANIM_DIR);
37-
cmd_append(cmd, "-L"RAYLIB_DIR"lib");
38-
cmd_append(cmd, "-l:libraylib.so", "-lm", "-ldl", "-lpthread");
37+
cmd_append(&cmd, "-Wl,-rpath="RAYLIB_DIR"lib/");
38+
cmd_append(&cmd, "-Wl,-rpath="PANIM_DIR);
39+
cmd_append(&cmd, "-L"RAYLIB_DIR"lib");
40+
cmd_append(&cmd, "-l:libraylib.so", "-lm", "-ldl", "-lpthread");
3941
}
4042

41-
bool build_plug_c(bool force, Cmd *cmd, const char *source_path, const char *output_path)
43+
bool build_plug_c(bool force, const char *source_path, const char *output_path)
4244
{
4345
int rebuild_is_needed = needs_rebuild1(output_path, source_path);
4446
if (rebuild_is_needed < 0) return false;
4547

4648
if (force || rebuild_is_needed) {
47-
cc(cmd);
48-
cmd_append(cmd, "-fPIC", "-shared", "-Wl,--no-undefined");
49-
cmd_append(cmd, "-o", output_path);
50-
cmd_append(cmd, source_path);
51-
libs(cmd);
52-
return cmd_run(cmd);
49+
cc();
50+
cmd_append(&cmd, "-fPIC", "-shared", "-Wl,--no-undefined");
51+
cmd_append(&cmd, "-o", output_path);
52+
cmd_append(&cmd, source_path);
53+
libs();
54+
return cmd_run(&cmd);
5355
}
5456

5557
nob_log(INFO, "%s is up-to-date", output_path);
5658
return true;
5759
}
5860

59-
bool build_plug_cxx(bool force, Cmd *cmd, const char *source_path, const char *output_path)
61+
bool build_plug_cxx(bool force, const char *source_path, const char *output_path)
6062
{
6163
int rebuild_is_needed = needs_rebuild1(output_path, source_path);
6264
if (rebuild_is_needed < 0) return false;
6365

6466
if (force || rebuild_is_needed) {
65-
cxx(cmd);
66-
cmd_append(cmd, "-fPIC", "-shared", "-Wl,--no-undefined");
67-
cmd_append(cmd, "-o", output_path);
68-
cmd_append(cmd, source_path);
69-
libs(cmd);
70-
return cmd_run(cmd);
67+
cxx();
68+
cmd_append(&cmd, "-fPIC", "-shared", "-Wl,--no-undefined");
69+
cmd_append(&cmd, "-o", output_path);
70+
cmd_append(&cmd, source_path);
71+
libs();
72+
return cmd_run(&cmd);
7173
}
7274

7375
nob_log(INFO, "%s is up-to-date", output_path);
7476
return true;
7577
}
7678

77-
bool build_exe(bool force, Cmd *cmd, const char **input_paths, size_t input_paths_len, const char *output_path)
79+
bool build_exe(bool force, const char **input_paths, size_t input_paths_len, const char *output_path)
7880
{
7981
int rebuild_is_needed = needs_rebuild(output_path, input_paths, input_paths_len);
8082
if (rebuild_is_needed < 0) return false;
8183

8284
if (force || rebuild_is_needed) {
83-
cc(cmd);
84-
cmd_append(cmd, "-o", output_path);
85-
da_append_many(cmd, input_paths, input_paths_len);
86-
libs(cmd);
87-
return cmd_run(cmd);
85+
cc();
86+
cmd_append(&cmd, "-o", output_path);
87+
da_append_many(&cmd, input_paths, input_paths_len);
88+
libs();
89+
return cmd_run(&cmd);
8890
}
8991

9092
nob_log(INFO, "%s is up-to-date", output_path);
@@ -111,12 +113,11 @@ int main(int argc, char **argv)
111113

112114
if (!mkdir_if_not_exists(BUILD_DIR)) return 1;
113115

114-
Cmd cmd = {0};
115-
if (!build_plug_c(force, &cmd, PLUGS_DIR"tm/plug.c", BUILD_DIR"libtm.so")) return 1;
116-
if (!build_plug_c(force, &cmd, PLUGS_DIR"template/plug.c", BUILD_DIR"libtemplate.so")) return 1;
117-
if (!build_plug_c(force, &cmd, PLUGS_DIR"squares/plug.c", BUILD_DIR"libsquare.so")) return 1;
118-
if (!build_plug_c(force, &cmd, PLUGS_DIR"bezier/plug.c", BUILD_DIR"libbezier.so")) return 1;
119-
if (!build_plug_cxx(force, &cmd, PLUGS_DIR"cpp/plug.cpp", BUILD_DIR"libcpp.so")) return 1;
116+
if (!build_plug_c(force, PLUGS_DIR"tm/plug.c", BUILD_DIR"libtm.so")) return 1;
117+
if (!build_plug_c(force, PLUGS_DIR"template/plug.c", BUILD_DIR"libtemplate.so")) return 1;
118+
if (!build_plug_c(force, PLUGS_DIR"squares/plug.c", BUILD_DIR"libsquare.so")) return 1;
119+
if (!build_plug_c(force, PLUGS_DIR"bezier/plug.c", BUILD_DIR"libbezier.so")) return 1;
120+
if (!build_plug_cxx(force, PLUGS_DIR"cpp/plug.cpp", BUILD_DIR"libcpp.so")) return 1;
120121

121122
{
122123
const char *output_path = BUILD_DIR"panim";
@@ -125,7 +126,7 @@ int main(int argc, char **argv)
125126
PANIM_DIR"ffmpeg_linux.c"
126127
};
127128
size_t input_paths_len = ARRAY_LEN(input_paths);
128-
if (!build_exe(force, &cmd, input_paths, input_paths_len, output_path)) return 1;
129+
if (!build_exe(force, input_paths, input_paths_len, output_path)) return 1;
129130
}
130131

131132
return 0;

0 commit comments

Comments
 (0)