#!/bin/sh
set -eu

find opt/resources/ -name '*.copy.c' -exec rm {} ';'
find opt/resources/ -name '*.c' | sed 's/^\(.*\)\.c$/cp \1.c \1.copy\.c/g' | sh

# shellcheck disable=2086
find opt/resources/ -name '*.copy.c' |
	uninclude -E '^#include ' -- $CC $CFLAGS -c

find opt/resources/ -name '*.copy.c' | while read -r file; do
	if ! cmp -s "$file" "$file".expected; then
		cat <<-EOF
			The unincluded file is different from expected.

			See with:
			  $ diff -U5 $file.expected $file
		EOF
		exit 1
	fi
done

rm -f -- *.o
