• Idar Tollefsen's avatar
    configure.in: Replaces hardcoded CFLAGS with compiler checks. · 0e79075f
    Idar Tollefsen authored
    Hardcoding CFLAGS without checking if the flags are supported isn't a
    good idea. For instance, if no CFLAGS where given, it would
    unconditionally add -O4 as the optimization flag. Clang doesn't have
    -O4. It understands it, but will issue a warning for every compilation
    unit that -O4 is equal to -O3. Clang also doesn't have
    -fexpensive-optimizations.
    
    This changes it to actually check for supported compiler flags and only
    adds them if the compiler understands them.
    
    There are several details here.
    
    CFLAGS where previously set at the start, before AC_PROG_CC since that
    adds default flags. That check now instead seta a EMPTY_CFLAGS marker
    that's later used to determine if we should add the previously hardcoded
    flags.
    
    The variable supported_cflags will be filled with the flags the compiler
    supports and eventually CFLAGS will be set to supported_cflags.
    
    For correct detection, -Werror (or equivalent) needs to be in effect for
    the compiler to issue an error for unknown flags. This is therefore
    checked first and added to CFLAGS while performing the checks. This is not
    added to supported_cflags and does therefore not end up on the final
    CFLAGS.
    
    Next, the check for -fPIC has been migrated from a platform check to a
    compiler flag check. If found to work, it's added both to supported_cflags
    and to LDFLAGS as it needs to be present during linking as well.
    
    Then comes the check for the flags that were previously added
    unconditionally if CFLAGS was empty, in the order they were before.
    Of particular note here is the split in logic to check for the
    optimization flag. It will check -O4 first. If -O4 is supported, it will
    not check for others. If -O4 is not supported, it will check -O3.
    
    The final compiler flags check is for disabling warnings. This is new and,
    like -fPIC, is done regardless of whether CFLAGS was empty or not. The
    only check here so far is for -Wno-language-extension-token which Clang
    needs to stop complaining about inline assembly statements. Note that the
    checks for warnings needs sed to convert from the -Wno-<warning> form to
    the -W<warning> form, so a AC_PROG_SED check is added to the top with the
    other program checks. This is because the -Wno-<warning> form isn't
    consulted unless there is warning (at least by GCC) so the flag would
    always be accepted. The -W<warning> form mean the compiler is forced to
    consider it up front.
    0e79075f