-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnob.c
80 lines (71 loc) · 2.66 KB
/
nob.c
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
#define NOB_IMPLEMENTATION
#include "include/nob.h"
#include <string.h>
int main(int argc, char **argv) {
NOB_GO_REBUILD_URSELF(argc, argv);
const char *program = nob_shift_args(&argc, &argv);
const char *src_file1 = "src/coogle-main.c";
const char *src_file2 = "src/match.c";
const char *src_file3 = "src/coogle.c";
const char *out_file = "coogle";
if (nob_file_exists(src_file1) < 0) {
nob_log(NOB_ERROR, "%s Not found", src_file1);
return 1;
}
// TODO: Implement this :- clang -DSTB_C_LEXER_IMPLEMENTATION -x c -c
// stb_c_lexer.h I don't need to do this here, but it's interesting so I'll
// just leave it in here.
Nob_Cmd cmd = {0};
nob_cmd_append(&cmd, "gcc");
nob_cmd_append(&cmd, src_file1, src_file2, src_file3);
nob_cmd_append(&cmd, "-I", "./");
nob_cmd_append(&cmd, "lib/libclang-14.so");
nob_cmd_append(&cmd, "-o", out_file);
nob_cmd_append(&cmd, "-Wall", "-Wextra", "-ggdb", "-pedantic");
if (argc == 0) {
nob_log(NOB_INFO, "Building %s\n", out_file);
if (!nob_cmd_run_sync(cmd))
return 1;
} else if (argc > 0) {
const char *subcmd = nob_shift_args(&argc, &argv);
if (strcmp(subcmd, "run") == 0) {
if (!nob_cmd_run_sync(cmd))
return 1;
nob_log(NOB_INFO, "Running %s\n", out_file);
cmd.count = 0;
Nob_String_Builder run_cmd = {0};
nob_sb_append_cstr(&run_cmd, "./");
nob_sb_append_cstr(&run_cmd, out_file);
nob_cmd_append(&cmd, run_cmd.items);
nob_da_append_many(&cmd, argv, argc);
if (!nob_cmd_run_sync(cmd))
return 1;
nob_sb_free(run_cmd);
} else if (strcmp(subcmd, "clean") == 0) {
cmd.count = 0;
nob_cmd_append(&cmd, "rm", "coogle", "nob", "nob.old");
if (!nob_cmd_run_sync(cmd))
return 1;
return 0;
} else if (strcmp(subcmd, "test") == 0) {
if (!nob_cmd_run_sync(cmd))
return 1;
cmd.count = 0;
Nob_String_Builder run_cmd = {0};
nob_sb_append_cstr(&run_cmd, "./");
nob_sb_append_cstr(&run_cmd, out_file);
nob_cmd_append(&cmd, run_cmd.items);
nob_cmd_append(&cmd, "clang-c/Index.h", "CXCursorKind(CXCursor)");
if (!nob_cmd_run_sync(cmd)) {
nob_sb_free(run_cmd);
return 1;
}
nob_sb_free(run_cmd);
return 0;
} else {
nob_log(NOB_ERROR, "Unknown subcommand: %s\n", subcmd);
return 1;
}
}
return 0;
}