-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnobuild.c
55 lines (45 loc) · 1.24 KB
/
nobuild.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
#define NOBUILD_IMPLEMENTATION
#include "./nobuild.h"
#define SOURCE "nopen.c"
#define BIN "nopen"
#define CC "gcc"
#define LIB "-lmagic"
#define PREFIX "/usr/local/bin/"
#define OLD "c.old"
#define OBJ BIN
void Compile(void) {
CMD(CC, "-c", LIB, SOURCE);
}
void Link(void) {
CMD(CC, "-o", BIN, "nopen.o", LIB, NULL);
}
void Install(void) {
CMD("doas", "cp", "-f", BIN, PREFIX);
}
void Wipe(void) {
CMD("doas", "rm", "-v", PREFIX""BIN);
CMD("rm", BIN, "c.old");
}
int main(int argc, char *argv[]) {
GO_REBUILD_URSELF(argc, argv);
if (argc < 2) {
printf("Usage: %s [-c compile] [-l link] [-i install] [-w wipe]\n", argv[0]);
return EXIT_SUCCESS;
}
for (int i = 1; i < argc; i++) {
char *arg = argv[i];
if (arg[0] == '-') {
for (unsigned long int j = 1; j < strlen(arg); j++) {
switch (arg[j]) {
case 'c': Compile(); break;
case 'l': Link(); break;
case 'i': Install(); break;
case 'w': Wipe(); break;
default: printf("Unknown option: %c\n", arg[j]);
break;
}
}
}
}
return EXIT_SUCCESS;
}