#!/bin/sh

############################################################
# Copyright (c) 2009-2010 by Aleksey Cheusov
#
# See COPYRIGHT file in the distribution.
############################################################

set -e

LC_ALL=C
export LC_ALL

##################################################

pathpart=compiler_type
if test "$1" = -x; then
    pathpart=cxx_type
    CC="$CXX"
    export CC
fi

##################################################
checks='
        __GNUC__:gcc
         __PCC__:pcc
__INTEL_COMPILER:icc
           __ICC:icc
        _MSC_VER:msc
        __HP_aCC:hpc
         __HP_cc:hpc
   __SUNPRO_C:sunpro
  __SUNPRO_CC:sunpro
     __IBMCPP__:ibmc
       __IBMC__:ibmc
    __BORLANDC__:bcc
  __WATCOMC__:watcom
       __COMO__:como
         __DECC:decc
       __DECCXX:decc
_COMPILER_VERSION:mipspro
'

check_itself (){
    type=unknown

    for i in $checks; do
	define=`echo $i | cut -d: -f1`
	cctype=`echo $i | cut -d: -f2`
	ret=`env CFLAGS= CPPFLAGS= CXXFLAGS= MKC_VERBOSE= MKC_NOCACHE=1 \
	    mkc_check_decl define "$define"`
	if test _1 = "_$ret"; then
	    type=$cctype
	    break
	fi
    done

    echo $type
}

. mkc_check_common.sh

check_and_cache "checking for compiler type" "$cache"

printme '%s\n' "$ret" 1>&2

echo "$ret"
