#! /bin/bash
# Last edited on 2025-05-07 16:56:55 by stolfi

echo "comparing pickled library files with originals in JSLIBS ..." 1>&2
ndiff=0
cat 00-SOURCES.txt \
  | sed \
      -e 's:[#].*$::g' \
      -e 's:[ ][ ]*$::g' \
      -e 's:^[ ][ ]*::g' \
      -e 's:[ ][ ]*:@:g' \
  | egrep -e '[a-zA-Z]' \
  > .libfiles

for libfile in `cat .libfiles`; do
  lib=${libfile/@*/}
  file=${libfile/*@/}
  ofile="JSLIBS/${lib}/${file}"
  
  printf "%s comparing ${ofile} ${file} %s\n" "---" "---" 1>&2
  if ! cmp -s ${ofile} ${file} ; then
    prdiff -Bb ${ofile} ${file}
    ndiff=$(( ${ndiff} + 1 ));
  fi
done

if [[ ${ndiff} -gt 0 ]]; then
  echo "** differences detected - fix and recompile" 1>&2
  exit 1
fi
