-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathmain.c
82 lines (68 loc) · 2.65 KB
/
main.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
81
82
#include <stdio.h>
#include "cmd/root.h"
#include "utils/helper.h"
#include "config/config.h"
#include "utils/log.h"
#define ARGS_BUILD "build"
void print_help() {
printf("Nature Programming Language Compiler %s\n\n", BUILD_VERSION);
printf("Usage:\n");
printf(" nature [command] [flags] [arguments]\n\n");
printf("Available Commands:\n");
printf(" build Build a Nature source file\n\n");
printf("Build Command Usage:\n");
printf(" nature build [flags] <source_file>\n\n");
printf("Build Flags:\n");
printf(" -o <name> Specify output filename (default: main)\n");
printf(" --archive Generate static library (output: lib<name>.a)\n");
printf(" --target Specify target platform for cross-compilation\n");
printf(" --ld <path> Specify the path to the linker\n");
printf(" --ldflags <flags> Specify linker flags\n\n");
printf("Cross Compilation:\n");
printf(" nature build --target <platform> <source_file>\n\n");
printf(" Supported Platforms:\n");
printf(" - linux_amd64 Linux on x86-64 architecture\n");
printf(" - linux_arm64 Linux on ARM 64-bit architecture\n");
printf(" - darwin_amd64 macOS on x86-64 architecture\n");
printf(" - darwin_arm64 macOS on ARM 64-bit architecture (Apple Silicon)\n\n");
printf("Examples:\n");
printf(" nature build main.n # Basic build\n");
printf(" nature build -o test main.n # Custom output name\n");
printf(" nature build --archive main.n # Generate static library\n");
printf(" nature build --target linux_arm64 main.n # Cross-compile for Linux ARM64\n");
printf(" nature build --ld /usr/bin/ld main.n # Custom linker and flags\n\n");
printf("Global Flags:\n");
printf(" --help, -h Show help information\n");
printf(" --version, -v Show version information\n");
}
/**
* nature build main.n [-o hello]
* @param argc
* @param argv
* @return
*/
int main(int argc, char *argv[]) {
// show help if no arguments
if (argc <= 1) {
print_help();
return 0;
}
char *first = argv[1];
if (str_equal(first, "--help") || str_equal(first, "-h")) {
print_help();
return 0;
}
if (str_equal(first, "--version") || str_equal(first, "-v")) {
printf("nature %s - %s build %s\n", BUILD_VERSION, BUILD_TYPE, BUILD_TIME);
return 0;
}
if (str_equal(first, ARGS_BUILD)) {
argv[1] = argv[0];
argv += 1;
cmd_entry(argc - 1, argv);
return 0;
}
printf("unknown command: %s\n", first);
print_help();
return 0;
}