80 lines
3 KiB
Bash
Executable file
80 lines
3 KiB
Bash
Executable file
#!/bin/bash
|
|
# The MIT License (MIT)
|
|
#
|
|
# Copyright (C) 2026 Scott Duensing
|
|
#
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
# of this software and associated documentation files (the "Software"), to
|
|
# deal in the Software without restriction, including without limitation the
|
|
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
# sell copies of the Software, and to permit persons to whom the Software is
|
|
# furnished to do so, subject to the following conditions:
|
|
#
|
|
# The above copyright notice and this permission notice shall be included in
|
|
# all copies or substantial portions of the Software.
|
|
#
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
# IN THE SOFTWARE.
|
|
|
|
#
|
|
# analyze.sh -- run the DJGPP build under gcc's -fanalyzer.
|
|
#
|
|
# Usage:
|
|
# ./analyze.sh # analyse the whole build (slow: 2-5x)
|
|
# ./analyze.sh 2>&1 | tee analyze.log
|
|
#
|
|
# How it works:
|
|
#
|
|
# The project Makefiles hardcode -Werror in CFLAGS. gcc evaluates
|
|
# diagnostic flags in order, so a trailing -Wno-error (appended
|
|
# AFTER CFLAGS at compile time) demotes analyzer findings back to
|
|
# warnings -- otherwise the first analyzer hit aborts the build.
|
|
#
|
|
# We do that by setting CC to a wrapper that execs the real compiler
|
|
# with -fanalyzer prepended and -Wno-error appended. make -k keeps
|
|
# building after individual failures so we see every hit in one run.
|
|
#
|
|
# Runs the existing top-level Makefile with an override CC; no
|
|
# Makefile edits required. Output goes to stderr; redirect with
|
|
# '2>&1 | tee analyze.log' to capture.
|
|
|
|
set -u
|
|
|
|
cd "$(dirname "$0")" || exit 1
|
|
|
|
# The DJGPP compiler the build uses (src/common.mk finds the toolchain;
|
|
# DJGPP_PREFIX in the environment overrides it). The query drops a
|
|
# calling make's flags: under make -j they bring its jobserver, and the
|
|
# query then prints directory lines into the path.
|
|
REAL_CC="$(env -u MAKEFLAGS -u MFLAGS -u MAKELEVEL make -s --no-print-directory -f src/common.mk --eval 'printCc: ; @echo $(CC)' printCc)"
|
|
|
|
if [ ! -x "$REAL_CC" ]; then
|
|
echo "analyze.sh: $REAL_CC not executable" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Build the wrapper in a temp dir that the spawned makes can see.
|
|
WRAP_DIR="$(mktemp -d)"
|
|
trap 'rm -rf "$WRAP_DIR"' EXIT
|
|
WRAP="$WRAP_DIR/analyze-cc"
|
|
|
|
cat > "$WRAP" <<WRAPEOF
|
|
#!/bin/bash
|
|
exec "$REAL_CC" -fanalyzer "\$@" -Wno-error
|
|
WRAPEOF
|
|
|
|
chmod +x "$WRAP"
|
|
|
|
echo "analyze.sh: running full build under gcc -fanalyzer..." >&2
|
|
echo "analyze.sh: this will be slow (2-5x normal build time)." >&2
|
|
|
|
# -k = keep going after errors so we collect every analyzer hit
|
|
# CC=... overrides the assignment in each submakefile
|
|
make -k CC="$WRAP" 2>&1
|
|
|
|
echo "analyze.sh: done. Grep for 'Wanalyzer' to see findings." >&2
|