configure: add -std=c99 conditionally (#45739)
Many users seem to try to override the default CC and/or CFLAGS without
knowing the effect of what they are doing. Our build configuration needs
a confirming C99 compiler, which may require a specific option to select
the language version. This commit adds a dynamic test that makes sure
the compiler is invoked with appropriate options.
@@ -395,7 +395,7 @@ | ||
395 | 395 | # define options for debugging |
396 | 396 | if ${debug} |
397 | 397 | then |
398 | - cc="${CC-gcc -std=c99}" | |
398 | + cc="${CC-gcc}" | |
399 | 399 | cflags="${CFLAGS--pedantic -MMD -Wall -Wextra -O1 -fno-inline -ggdb}" |
400 | 400 | else |
401 | 401 | defconfigh "NDEBUG" |
@@ -413,12 +413,12 @@ | ||
413 | 413 | checked "yes" |
414 | 414 | elif |
415 | 415 | [ x"${cc}" = x"c99" ] && [ x"${CC+set}" != x"set" ] && ( |
416 | - cc='gcc -std=c99' | |
416 | + cc='gcc' | |
417 | 417 | trymake && tryexec |
418 | 418 | ) |
419 | 419 | then |
420 | - checked "yes (using gcc -std=c99)" | |
421 | - cc='gcc -std=c99' | |
420 | + checked "yes (using gcc)" | |
421 | + cc='gcc' | |
422 | 422 | else |
423 | 423 | checked "no" |
424 | 424 | printf 'Compiler "%s" not found or not working.\n' "${CC-${cc}}" >&2 |
@@ -447,6 +447,36 @@ | ||
447 | 447 | unset savecflags |
448 | 448 | fi |
449 | 449 | |
450 | +# find compiler option for C99 support | |
451 | +checking 'additional option to compile C99 code' | |
452 | +cat >"${tempsrc}" <<END | |
453 | +int main(int argc, char **argv) { | |
454 | +if (argc == 0) return 0; | |
455 | +int vla[argc]; | |
456 | +vla[0] = 42; | |
457 | +// one-line comment | |
458 | +struct s { int v; } i = { .v = argv[0][0] }; | |
459 | +return vla[0] + i.v; | |
460 | +} | |
461 | +END | |
462 | +if | |
463 | + trycompile | |
464 | +then | |
465 | + checked "none needed" | |
466 | +elif | |
467 | + [ x"${CFLAGS+set}" != x"set" ] && | |
468 | + cflags="${cflags} -std=c99" && | |
469 | + trycompile | |
470 | +then | |
471 | + checked "with -std=c99" | |
472 | +else | |
473 | + checked "failed" | |
474 | + printf 'Compiler "%s" does not seem to support C99.\n' "${CC-${cc}}" >&2 | |
475 | + printf 'The compiler was tested with these options: %s\n' \ | |
476 | + "${CFLAGS-${cflags}} ${CADDS-${null}}" >&2 | |
477 | + fail | |
478 | +fi | |
479 | + | |
450 | 480 | # check if make supports include statements |
451 | 481 | checking 'whether make supports include statements' |
452 | 482 | if |