-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathnob.c
More file actions
68 lines (56 loc) · 2.03 KB
/
nob.c
File metadata and controls
68 lines (56 loc) · 2.03 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
#define NOB_IMPLEMENTATION
#define NOB_STRIP_PREFIX
#define NOB_EXPERIMENTAL_DELETE_OLD
#include "./thirdparty/nob.h"
#define BUILD_FOLDER "build/"
#define SRC_FOLDER "src/"
#define THIRDPARTY_FOLDER "thirdparty/"
void build_tool_async(Cmd *cmd, Procs *procs, const char *bin_path, const char *src_path)
{
cmd_append(cmd, "gcc", "-Wall", "-Wextra", "-ggdb", "-I"THIRDPARTY_FOLDER, "-march=native", "-Ofast", "-o", bin_path, src_path, SRC_FOLDER"bpe.c");
da_append(procs, cmd_run_async_and_reset(cmd));
}
const char *tools[] = {
"txt2bpe",
"bpe2dot",
"bpe2bpe",
"bpe_inspect",
"bpe_gen",
"tkn_inspect",
};
int main(int argc, char **argv)
{
NOB_GO_REBUILD_URSELF(argc, argv);
Cmd cmd = {0};
Procs procs = {0};
const char *program_name = shift(argv, argc);
if (!nob_mkdir_if_not_exists(BUILD_FOLDER)) return 1;
if (argc <= 0) {
for (size_t i = 0; i < ARRAY_LEN(tools); ++i) {
const char *bin_path = temp_sprintf(BUILD_FOLDER"%s", tools[i]);
const char *src_path = temp_sprintf(SRC_FOLDER"%s.c", tools[i]);
build_tool_async(&cmd, &procs, bin_path, src_path);
}
if (!procs_wait_and_reset(&procs)) return 1;
return 0;
}
const char *tool_name = shift(argv, argc);
for (size_t i = 0; i < ARRAY_LEN(tools); ++i) {
if (strcmp(tool_name, tools[i]) == 0) {
const char *bin_path = temp_sprintf(BUILD_FOLDER"%s", tools[i]);
const char *src_path = temp_sprintf(SRC_FOLDER"%s.c", tools[i]);
build_tool_async(&cmd, &procs, bin_path, src_path);
if (!procs_wait_and_reset(&procs)) return 1;
cmd_append(&cmd, bin_path);
da_append_many(&cmd, argv, argc);
if (!cmd_run_sync_and_reset(&cmd)) return 1;
return 0;
}
}
nob_log(ERROR, "Unknown tool `%s`", tool_name);
nob_log(ERROR, "Available tools:");
for (size_t i = 0; i < ARRAY_LEN(tools); ++i) {
nob_log(ERROR, " %s", tools[i]);
}
return 0;
}