forked from libtrading/libtrading
-
Notifications
You must be signed in to change notification settings - Fork 2
/
libtrading-config.c
88 lines (72 loc) · 1.5 KB
/
libtrading-config.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
83
84
85
86
87
88
#include <stdbool.h>
#include <getopt.h>
#include <libgen.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
static const char *program;
static const char *usage_fmt =
"Usage: %s <option>\n"
"\n"
"Options:\n"
" --version Print libtrading version.\n"
" --cflags C compiler flags for files that include libtrading headers.\n"
" --ldflags Linker flags.\n"
" --libs Libraries needed to link against libtrading.\n";
static void usage(void)
{
fprintf(stderr, usage_fmt, program);
exit(EXIT_FAILURE);
}
static const struct option options[] = {
{ "version", no_argument, NULL, 'v' },
{ "ldflags", no_argument, NULL, 'd' },
{ "cflags", no_argument, NULL, 'c' },
{ "libs", no_argument, NULL, 'l' },
};
static bool version;
static bool ldflags;
static bool cflags;
static bool libs;
static void parse_args(int argc, char *argv[])
{
int opt;
while ((opt = getopt_long(argc, argv, "cdlv", options, NULL)) != -1) {
switch (opt) {
case 'v':
version = true;
break;
case 'd':
ldflags = true;
break;
case 'c':
cflags = true;
break;
case 'l':
libs = true;
break;
default:
usage();
break;
}
}
}
int main(int argc, char *argv[])
{
program = basename(argv[0]);
if (argc == 1)
usage();
parse_args(argc, argv);
if (version) {
printf("%s\n", LIBTRADING_VERSION);
return EXIT_SUCCESS;
}
if (cflags)
printf("-I" PREFIX "/include ");
if (ldflags)
printf("-L" PREFIX "/lib ");
if (libs)
printf("-ltrading -lz ");
printf("\n");
return EXIT_SUCCESS;
}