#!/usr/bin/env bash
# Build the program whose -1 is not below 1 twice: with -Wall, then with -Wall
# -Wextra. -Werror turns a warning into a failed build, so the exit status says
# whether the compiler said anything, and then the program runs.
#
# Runs in a scratch copy of ../demo. GCC and clang word the warning
# differently, so the builds print only an exit status; the messages are on the
# page in fences that name the compiler.
set -u
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
cp ../demo/minus_one_below_one.c "$work"/
cd "$work" || exit 1

say()    { printf '$ %s\n' "$*"; eval "$*" 2>&1; }
status() { printf '$ %s\n' "$*"; eval "$*" >/dev/null 2>&1; echo "exit $?"; }

# -Wall alone says nothing about a signed/unsigned comparison in C.
status cc -std=c17 -Wall -pedantic -Werror -o minus_one minus_one_below_one.c
say ./minus_one

# -Wextra brings in -Wsign-compare, and -Werror makes it stop the build.
status cc -std=c17 -Wall -Wextra -pedantic -Werror -o minus_one minus_one_below_one.c
