-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
119 lines (94 loc) · 4.05 KB
/
main.c
File metadata and controls
119 lines (94 loc) · 4.05 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <external.h>
#include "buildeka_module.h"
i32 main(int argc, char **argv){
MemBook *cp = MemBook_Make(NULL);
void *args[3];
if(cp == NULL){
Fatal(FUNCNAME, FILENAME, LINENUMBER, "MemBook created successfully", NULL);
}
MemCh *m = MemCh_Make();
if(m == NULL){
Fatal(FUNCNAME, FILENAME, LINENUMBER, "MemCh created successfully", NULL);
}
Caneka_InitBase(m);
BuildCtx_ToSInit(m);
DebugStack_Push(NULL, 0);
CliArgs *cli = CliArgs_Make(argc, argv);
Str *helpKey = K(m, "help");
Str *noColorKey = K(m, "no-color");
Str *quietKey = K(m, "quiet");
Str *runKey = K(m, "run");
Str *modulesKey = K(m, "module");
Str *optionsKey = K(m, "option");
Str *licenceKey = K(m, "licence");
Str *versionKey = K(m, "version");
Str *srcKey = K(m, "src");
Str *typeKey = K(m, "type");
Str *dirKey = K(m, "dir");
Str *libDirKey = K(m, "libDirs");
Str *srcPrefixKey = K(m, "src-prefix");
Args_Add(cli, helpKey, NULL, ARG_OPTIONAL, Sv(m, "Show this help message."));
Args_Add(cli, noColorKey, NULL, ARG_OPTIONAL,
Sv(m, "Skip ansi color sequences in output."));
Args_Add(cli, srcKey, NULL, ARG_MULTIPLE,
Sv(m, "Source code files or directories to build."));
Args_Add(cli, srcPrefixKey, S(m, "src"), ARG_DEFAULT,
Sv(m, "Source code files prefix. The path before the module names."));
Args_Add(cli, optionsKey, NULL, ARG_MULTIPLE|ARG_OPTIONAL,
Sv(m, "Optional dependency source modules to include."));
Span *libDirs = Span_Make(m);
Span_Add(libDirs, S(m, "/usr/lib64"));
Args_Add(cli, libDirKey, libDirs, ARG_MULTIPLE|ARG_DEFAULT,
Sv(m, "lib directories to source static or linked libraries from."));
Args_Add(cli, dirKey, S(m, "build"), ARG_DEFAULT,
Sv(m, "Build directory to use for objects and binary assets/executables."));
Span *types = Span_Make(m);
Span_Add(types, S(m, "exec"));
Span_Add(types, S(m, "static"));
Args_Add(cli, typeKey, types, ARG_CHOICE|ARG_DEFAULT,
Sv(m, "Type of binary asset to create, static builds a static library,"
" exec builds and executable."));
Args_Add(cli, quietKey, NULL, ARG_OPTIONAL,
Sv(m, "Output a list of compiled targets instead of the progress bar."));
Args_Add(cli, runKey, NULL, ARG_OPTIONAL,
Sv(m, "Run the binary after it is built."));
Args_Add(cli, licenceKey, NULL, ARG_OPTIONAL,
Sv(m, "Show build program intellectual property licence."));
Args_Add(cli, versionKey, NULL, ARG_OPTIONAL,
Sv(m, "Show build program version."));
CliArgs_Parse(cli);
BuildCtx *ctx = BuildCtx_Make(m);
StrVec *prefix = StrVec_From(m, CliArgs_Get(cli, srcPrefixKey));
IoUtil_Annotate(m, prefix);
ctx->input.buildDir = CliArgs_GetAbsPath(cli, dirKey);
ctx->input.buildDir->type.state |= STRVEC_NOSHRINK;
ctx->current.dest = StrVec_Copy(m, ctx->input.buildDir);
ctx->dir = StrVec_Copy(m, ctx->input.buildDir);
ctx->src = CliArgs_GetAbsPath(cli, srcPrefixKey);
ctx->current.source = CliArgs_GetAbsPath(cli, srcPrefixKey);
ctx->current.liblist = Span_Make(m);
ctx->input.sources = CliArgs_Get(cli, srcKey);
ctx->input.srcPrefix = prefix;
ctx->input.srcPrefix->type.state |= STRVEC_NOSHRINK;
ctx->input.totalSources = I32_Wrapped(m, 0);
ctx->input.countSources = I32_Wrapped(m, 0);
ctx->input.totalModules = I32_Wrapped(m, 0);
ctx->input.countModules = I32_Wrapped(m, 0);
ctx->input.totalModuleSources = I32_Wrapped(m, 0);
ctx->input.countModuleSources = I32_Wrapped(m, 0);
Table *options = BuildCtx_GenOptionsTable(ctx, CliArgs_Get(cli, optionsKey));
ctx->input.options = options;
if(CliArgs_Get(cli, quietKey)){
BuildCtx_SetQuiet(TRUE);
}else{
BuildCli_SetupStatus(ctx);
}
BuildCtx_Build(ctx);
args[0] = CliArgs_Get(cli, srcKey);
args[1] = CliArgs_Get(cli, dirKey);
args[2] = NULL;
Out("^g.Build succeeded $ -> ./$/bin/^0\n", args);
CliArgs_Free(cli);
DebugStack_Pop();
return 0;
}