#!/bin/sh

die () {
   echo "*** mkconfig: $*" 1>&2
   exit 1
}

[ -f makefile ] || die "can not find 'makefile'"

cat<<EOF
/**********************************************************/
/* Automatically generated by './mkconfig': do note edit! */
/**********************************************************/
EOF

if [ ! x"`grep '^CC=gcc$' makefile`" =  x ]
then
  patchgccversion="`gcc --version|head -1|sed -e 's/,/ /g'`"
  patchgccversion="s,gcc,$patchgccversion,g"
else
  patchgccversion="s,DUMMY,DUMMY,"
fi

sed \
  -e '/^C[A-Z]*=/!d' \
  -e 's,^,#define BTOR_,' \
  -e 's,= *, ",' \
  -e 's,$,",' \
  makefile | sed -e "$patchgccversion"

echo "#define BTOR_OS \"`uname -srmn`\""
echo "#define BTOR_COMPILED \"`date`\""
cat<<EOF
#define BTOR_RELEASED "Sat Oct 13 13:59:09 CEST 2012"
#define BTOR_VERSION "1.5.118"
#define BTOR_ID "6b56be42e9d2a80527f44ae7ef8b031e8e4ce478"
EOF
