-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnob.c
65 lines (51 loc) · 2.19 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
#define NOB_IMPLEMENTATION
#define NOB_STRIP_PREFIX
#include "nob.h"
#define BUILD_FOLDER "build/"
#define EXAMPLES_FOLDER "examples/"
#define SRC_FOLDER "src/"
#define cc_with_cflags(cmd) cmd_append(cmd, "gcc", "-Wall", "-Wextra", "-ggdb", "-I.", "-I"SRC_FOLDER)
#define cc_output(cmd, output_path) cmd_append(cmd, "-o", output_path)
#define cc_no_link(cmd) cmd_append(cmd, "-c")
#define cc_input(cmd, ...) cmd_append(cmd, __VA_ARGS__)
int main(int argc, char **argv)
{
NOB_GO_REBUILD_URSELF_PLUS(argc, argv, "nob.h");
Cmd cmd = {0};
Nob_Procs procs = {0};
if (!nob_mkdir_if_not_exists(BUILD_FOLDER)) return 1;
cc_with_cflags(&cmd);
cc_no_link(&cmd);
cc_output(&cmd, BUILD_FOLDER"cws.o");
cc_input(&cmd, SRC_FOLDER"cws.c");
da_append(&procs, nob_cmd_run_async_and_reset(&cmd));
cc_with_cflags(&cmd);
cc_no_link(&cmd);
cc_output(&cmd, BUILD_FOLDER"coroutine.o");
cc_input(&cmd, SRC_FOLDER"coroutine.c");
da_append(&procs, nob_cmd_run_async_and_reset(&cmd));
if (!nob_procs_wait_and_reset(&procs)) return 1;
cmd_append(&cmd, "ar", "-rcs", BUILD_FOLDER"libcws.a", BUILD_FOLDER"coroutine.o", BUILD_FOLDER"cws.o");
da_append(&procs, nob_cmd_run_async_and_reset(&cmd));
if (!nob_procs_wait_and_reset(&procs)) return 1;
cc_with_cflags(&cmd);
cc_output(&cmd, BUILD_FOLDER"01_plain_echo_server");
cc_input(&cmd, EXAMPLES_FOLDER"01_plain_echo_server.c", BUILD_FOLDER"libcws.a");
da_append(&procs, nob_cmd_run_async_and_reset(&cmd));
cc_with_cflags(&cmd);
cc_output(&cmd, BUILD_FOLDER"02_plain_async_echo_server");
cc_input(&cmd, EXAMPLES_FOLDER"02_plain_async_echo_server.c", BUILD_FOLDER"libcws.a");
da_append(&procs, nob_cmd_run_async_and_reset(&cmd));
// TODO: detect the presense of c3c and if it's missing don't try to build the C3 example
cmd_append(&cmd,
"c3c", "compile",
"-g",
"-l", BUILD_FOLDER"libcws.a",
"-o", BUILD_FOLDER"11_plain_echo_server",
EXAMPLES_FOLDER"11_plain_echo_server.c3",
SRC_FOLDER"cws.c3",
SRC_FOLDER"coroutine.c3");
da_append(&procs, nob_cmd_run_async_and_reset(&cmd));
if (!nob_procs_wait_and_reset(&procs)) return 1;
return 0;
}