#!/bin/bash # We grep error messages so we need to be in a suitable default locale. Sorry! export LANG=C tmpfile="/tmp/$$" trap "rm -f '$tmpfile'*" 0 @REAL_CC@ "$@" > "$tmpfile" 2>&1 status=$? if [[ $status -ne 0 ]]; then CC="@REAL_CC@" CC="${CC%% *}" CC="${CC##*/}" # Try eliminating known issues OVERRIDE_CFLAGS=() if [[ "$CC" = 'gcc' ]]; then if grep "declaration of '__cancel_buf' shadows a previous local" "$tmpfile" > /dev/null 2>&1; then # There's a nested pthread_cleanup_push...pthread_cleanup_pop echo "*** Ignoring pthread cleanup nesting" OVERRIDE_CFLAGS[${#OVERRIDE_CFLAGS[@]}]='-Wno-shadow' fi elif [[ "$CC" = 'icc' ]]; then if grep 'error #1599: declaration hides variable "__cancel_buf"' "$tmpfile" > /dev/null 2>&1; then # There's a nested pthread_cleanup_push...pthread_cleanup_pop echo "*** Ignoring pthread cleanup nesting" OVERRIDE_CFLAGS[${#OVERRIDE_CFLAGS[@]}]='-wd1599' fi if grep 'error #1419: external declaration in primary source file' "$tmpfile" > /dev/null 2>&1; then # Unavoidable with YACC/Bison output and _sometimes_ convenient echo "*** Ignoring external declarations in primary source file" OVERRIDE_CFLAGS[${#OVERRIDE_CFLAGS[@]}]='-wd1419' fi if grep 'error #2215: definition at end of file not followed by a semicolon or a declarator' "$tmpfile" > /dev/null 2>&1; then # YACC/Bison generates not-quite-valid code for %union # and may define exernal functions with no previous declaration echo "*** Ignoring missing semicolon at end of file (YACC/Bison generated code?)" OVERRIDE_CFLAGS[${#OVERRIDE_CFLAGS[@]}]='-wd2215' OVERRIDE_CFLAGS[${#OVERRIDE_CFLAGS[@]}]='-wd1418' fi fi if [[ ${#OVERRIDE_CFLAGS[@]} -ne 0 ]]; then echo "*** Retrying using: ${OVERRIDE_CFLAGS[@]}" @REAL_CC@ "$@" "${OVERRIDE_CFLAGS[@]}" > "$tmpfile" 2>&1 status=$? fi # If it still fails try eliminating preprocessor compile time optimizations. # If that fails show the error messages from that attempt. If it succeeds show # the error messages we had previously. if [[ $status -ne 0 ]]; then echo "*** Retry without preprocessor compile time optimizations" @REAL_CC@ -DCW_DEBUG_COMPILE "$@" "${OVERRIDE_CFLAGS[@]}" > "$tmpfile.2" 2>&1 [[ $? -ne 0 ]] && mv -f "$tmpfile.2" "$tmpfile" status=1 fi fi cat "$tmpfile" exit $status