#!/bin/sh
# Each source compiles alone, as a project that vendors it builds it (flak vendors net.c and
# noise.c): -std=c11 -pedantic and the include paths, none of the Makefile's feature-test macros.
# A file that needs _DEFAULT_SOURCE or _GNU_SOURCE defines it itself, before its first include
# (docs/dev/vendoring.md). glibc hides POSIX and BSD calls under -std=c11, so this is the check that
# bites on Linux; macOS shows them all and passes it more easily.
# Usage: sh test/pic/standalone.sh [FILE.c...] (default: every src/*.c and src/tui/*.c)
set -eu
cd "$(dirname "$0")/../.."
CC=${CC:-cc}
[ $# -gt 0 ] || set -- src/*.c src/tui/*.c
rc=0
for f in "$@"; do
if ! out=$($CC -std=c11 -pedantic -Wall -Werror -fsyntax-only -Isrc -isystem vendor/libfossil -isystem vendor/zlib \
-isystem vendor/qrcodegen -isystem vendor/quickjs -isystem vendor/bearssl/inc -DHAVE_LIBFOSSIL_CONFIG_H "$f" 2>&1); then
echo "standalone: $f does not compile alone:"
printf '%s\n' "$out" | grep -E 'error' | head -3 | sed 's/^/ /'
rc=1
fi
done
[ "$rc" = 0 ] && echo "standalone: ok ($# files)"
exit "$rc"