#!/bin/sh

export MAKEFLAGS=""
top_srcdir="$(make -s echo-topdir)"

#
# Check that the Win32 config.h is in sync with config.h.in
#

config_h_in="${top_srcdir}/config.h.in"
win32_config_h="${top_srcdir}/build/win32/config.h"

nfails=0
ntokens=0
for key in $(sed -ne 's/.*#undef *\([A-Za-z0-9_]*\).*/\1/p' "$config_h_in");
do
  ntokens=$(($ntokens + 1))
  if ! grep '[ef] \<'"$key"'\>' "$win32_config_h" >/dev/null 2>&1; then
    echo "error: $key missing from build/win32/config.h"
    nfails=$(($nfails + 1))
  fi
done

echo "$ntokens tokens, $nfails errors in Win32 config.h"

if test "$nfails" != "0"; then
  exit 1
fi

exit 0