1 /*
2 SPDX-FileCopyrightText: 2010 Patrick Spendrin <ps_ml@gmx.de>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6
7 /*
8 * This helper program is needed for the Visual Studio compiler
9 * to find out the standard macros, there is no "gcc -dM -E -".
10 * A trick is used to find out the standard macros. You can
11 * exchange the compiler. The standard macros are written in
12 * a environment variable. This helper program analysis this
13 * variable and prints the output to stdout.
14 */
15
16 #include <cstdio>
17 #include <cstdlib>
18 #include <cstring>
19
main(int argc,char ** argv)20 int main(int argc, char**argv)
21 {
22 char *next, *token, *tmp, *equal;
23 int nextlen, currentlen;
24 next = getenv("MSC_CMD_FLAGS");
25
26 while (next != NULL)
27 {
28 token = next;
29 next = strstr(next + 1, " -");
30
31 if(strncmp(token, " -D", 3) == 0) {
32 if(next != NULL)
33 nextlen = strlen(next);
34 else
35 nextlen = 0;
36
37 currentlen = strlen(token);
38 tmp = new char[(currentlen - nextlen + 1)];
39 strncpy(tmp, token, currentlen - nextlen);
40 tmp[currentlen - nextlen] = '\0';
41 equal = strchr(tmp, '=');
42 if(equal != NULL) *equal = ' ';
43 printf("#define %s\n", tmp + 3);
44 delete [] tmp;
45 }
46 }
47 // return an error so that the compiler doesn't check for the output
48 return 1;
49 }
50