X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=tools%2Fconfigurator%2Fconfigurator.c;h=2e5b09c2b984c252c8a2bfd9a397960af057c344;hb=fc8784e07e1daada5ff1a652098628f039a62850;hp=4cb84d0b5301b7f9a5743ecdeb44f10442561e96;hpb=aacc2cb8e22a369b910816dc41a6a411d29a12bb;p=ccan diff --git a/tools/configurator/configurator.c b/tools/configurator/configurator.c index 4cb84d0b..2e5b09c2 100644 --- a/tools/configurator/configurator.c +++ b/tools/configurator/configurator.c @@ -38,9 +38,21 @@ #define pclose _pclose #endif +#ifdef _MSC_VER +#define DEFAULT_COMPILER "cl" +/* Note: Dash options avoid POSIX path conversion when used under msys bash + * and are therefore preferred to slash (e.g. -nologo over /nologo) + * Note: Disable Warning 4200 "nonstandard extension used : zero-sized array + * in struct/union" for flexible array members. + */ +#define DEFAULT_FLAGS "-nologo -Zi -W4 -wd4200 " \ + "-D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS" +#define DEFAULT_OUTPUT_EXE_FLAG "-Fe:" +#else #define DEFAULT_COMPILER "cc" #define DEFAULT_FLAGS "-g3 -ggdb -Wall -Wundef -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wold-style-definition" #define DEFAULT_OUTPUT_EXE_FLAG "-o" +#endif #define OUTPUT_FILE "configurator.out" #define INPUT_FILE "configuratortest.c" @@ -90,7 +102,8 @@ static struct test tests[] = { "#include \n" "static char *func(int x) {" " char *p;\n" - " if (asprintf(&p, \"%u\", x) == -1) p = NULL;" + " if (asprintf(&p, \"%u\", x) == -1) \n" + " p = NULL;\n" " return p;\n" "}" }, { "HAVE_ATTRIBUTE_COLD", DEFINES_FUNC, NULL, NULL, @@ -147,8 +160,12 @@ static struct test tests[] = { "return __builtin_ffsl(0L) == 0 ? 0 : 1;" }, { "HAVE_BUILTIN_FFSLL", INSIDE_MAIN, NULL, NULL, "return __builtin_ffsll(0LL) == 0 ? 0 : 1;" }, + { "HAVE_BUILTIN_POPCOUNT", INSIDE_MAIN, NULL, NULL, + "return __builtin_popcount(255) == 8 ? 0 : 1;" }, { "HAVE_BUILTIN_POPCOUNTL", INSIDE_MAIN, NULL, NULL, "return __builtin_popcountl(255L) == 8 ? 0 : 1;" }, + { "HAVE_BUILTIN_POPCOUNTLL", INSIDE_MAIN, NULL, NULL, + "return __builtin_popcountll(255LL) == 8 ? 0 : 1;" }, { "HAVE_BUILTIN_TYPES_COMPATIBLE_P", INSIDE_MAIN, NULL, NULL, "return __builtin_types_compatible_p(char *, int) ? 1 : 0;" }, { "HAVE_ICCARM_INTRINSICS", DEFINES_FUNC, NULL, NULL, @@ -303,6 +320,8 @@ static struct test tests[] = { "#include \n" }, { "HAVE_SYS_TERMIOS_H", OUTSIDE_MAIN, NULL, NULL, "#include \n" }, + { "HAVE_SYS_UNISTD_H", OUTSIDE_MAIN, NULL, NULL, + "#include \n" }, { "HAVE_TYPEOF", INSIDE_MAIN, NULL, NULL, "__typeof__(argc) i; i = argc; return i == argc ? 0 : 1;" }, { "HAVE_UNALIGNED_ACCESS", DEFINES_EVERYTHING|EXECUTE, NULL, NULL, @@ -656,13 +675,15 @@ int main(int argc, const char *argv[]) const char *default_args[] = { "", DEFAULT_COMPILER, DEFAULT_FLAGS, NULL }; const char *outflag = DEFAULT_OUTPUT_EXE_FLAG; + const char *configurator_cc = NULL; + const char *orig_cc; if (argc > 0) progname = argv[0]; while (argc > 1) { if (strcmp(argv[1], "--help") == 0) { - printf("Usage: configurator [-v] [-O] [ ...]\n" + printf("Usage: configurator [-v] [-O] [--configurator-cc=] [ ...]\n" " will have \" \" appended\n" "Default: %s %s %s\n", DEFAULT_COMPILER, DEFAULT_FLAGS, @@ -687,6 +708,10 @@ int main(int argc, const char *argv[]) argc--; argv++; verbose += 2; + } else if (strncmp(argv[1], "--configurator-cc=", 18) == 0) { + configurator_cc = argv[1] + 18; + argc--; + argv++; } else { break; } @@ -695,6 +720,10 @@ int main(int argc, const char *argv[]) if (argc == 1) argv = default_args; + orig_cc = argv[1]; + if (configurator_cc) + argv[1] = configurator_cc; + cmd = connect_args(argv, outflag, OUTPUT_FILE " " INPUT_FILE); for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) run_test(cmd, &tests[i]); @@ -709,7 +738,7 @@ int main(int argc, const char *argv[]) printf("#ifndef _GNU_SOURCE\n"); printf("#define _GNU_SOURCE /* Always use GNU extensions. */\n"); printf("#endif\n"); - printf("#define CCAN_COMPILER \"%s\"\n", argv[1]); + printf("#define CCAN_COMPILER \"%s\"\n", orig_cc); cmd = connect_args(argv + 1, "", ""); printf("#define CCAN_CFLAGS \"%s\"\n", cmd); free(cmd);