#!/bin/sh
#*=====================================================================*/
#*    serrano/prgm/project/bigloo/bigloo/autoconf/ccwarning            */
#*    -------------------------------------------------------------    */
#*    Author      :  Manuel Serrano                                    */
#*    Creation    :  Tue Mar  7 16:28:42 2017                          */
#*    Last change :  Thu Jul 29 07:18:59 2021 (serrano)                */
#*    Copyright   :  2017-21 Manuel Serrano                            */
#*    -------------------------------------------------------------    */
#*    Disable useless but painful clang warning messages.              */
#*=====================================================================*/

#*---------------------------------------------------------------------*/
#*    flags                                                            */
#*---------------------------------------------------------------------*/
cwarning="-Wno-unused-value -Wno-parentheses-equality -Wno-parentheses -Wno-invalid-source-encoding -Wno-return-type -Wno-trigraphs"

#*---------------------------------------------------------------------*/
#*    We parse the arguments                                           */
#*---------------------------------------------------------------------*/
while : ; do
  case $1 in
    "")
      break;;

    --cflags=*|-cflags=*)
      cflags="`echo $1 | sed 's/^[-a-z]*=//'`";;

    -*)
      echo "Unknown option \"$1\", ignored" >&2;;
  esac
  shift
done

file=$TMP/actest$USER

#*---------------------------------------------------------------------*/
#*    compile                                                          */
#*---------------------------------------------------------------------*/
compilesans="$CC $cflags $file.c -c -Werror >/dev/null"
compile="$CC $cflags $cwarning $file.c -c -Werror >/dev/null"

#*---------------------------------------------------------------------*/
#*    The test C file                                                  */
#*---------------------------------------------------------------------*/
if( test -f $file.c ); then
   rm -f $file.c || exit $?
fi

#*---------------------------------------------------------------------*/
#*    Test                                                             */
#*---------------------------------------------------------------------*/
cat > $file.c <<EOF
#include <stdio.h>

int foo( long x ) {
   puts( "??-" );
   if( x = 3 ) {
      return x + 1;
   } else {
      return x - 1;
   }
}
EOF

#*---------------------------------------------------------------------*/
#*    Compilation test                                                 */
#*---------------------------------------------------------------------*/
if eval "$BUILDSH $compilesans"; then
   \rm -f $file.*
   echo ""
   exit 0
fi

if eval "$BUILDSH $compile"; then
   \rm -f $file.*
   echo $cwarning
   exit 0
fi

\rm -f $file.*
echo ""
exit 0
