#!/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`"
patchgccversion="s,\"gcc\",\"$patchgccversion\","
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 "Fri Mar  4 19:52:48 CET 2011"
#define BTOR_VERSION "1.4.1"
#define BTOR_ID "376e6b097a9a63af246339a13dd0e61b8774db77"
EOF
