#!/bin/bash

# Delete references to deleted headers in dependency files in the build
# tree.

[ -z "$*" ] && exit # NOP.

[ -d "$CETPKG_BUILD" ] || \
  { echo "ERROR: CETPKG_BUILD vacuous or not set" 1>&2; exit 1; }

for arg in "$@"; do args+=(-e "$arg"); done
find "$CETPKG_BUILD" -type f \( -name '*.d' -o -name '*.deps' \) -print0 | \
  xargs -0 grep -l -z -Z -I -F -w "${args[@]}" | \
  xargs -0 rm -fv "$CETPKG_BUILD/.ninja_deps"
