]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/tools/compilationunits.sh
Merge branch 'martin-t/units' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / tools / compilationunits.sh
index 98ea3c6f366dc0eb6be525ec253061321e1f976f..55799ff7c4db70fe3d470284b1c8bc6b4548b69d 100755 (executable)
@@ -1,34 +1,77 @@
-#!/bin/bash
+#!/usr/bin/env bash
 set -eu
-cd "$(dirname "$0")"
-cd ..
+cd ${0%/*}
 
-declare -a NOWARN=(
-    -Wno-field-redeclared
-    -Wno-unused-variable
-    -Wno-implicit-function-pointer
+# This script attempts to build the codebase in every possible header configuration,
+# to check that all files #include what they need, so that we can eventually move away
+# from a unity build and into incremental compilation.
+
+# If these files exist from previous compilation, `./all compile` will stop
+# detecting changes after running this script so delete them to trigger
+# a recompile next time.
+if [ -f ../../csprogs.dat ]; then
+    rm ../../csprogs.dat
+fi
+
+if [ -f ../../menu.dat ]; then
+    rm ../../menu.dat
+fi
+
+if [ -f ../../progs.dat ]; then
+    rm ../../progs.dat
+fi
+
+WORKDIR=../.tmp
+
+CPP="cc -xc -E"
+: ${QCC:=$PWD/../../../../gmqcc/gmqcc}
+
+declare -a QCCDEFS=(
+    -DNDEBUG=1
+    -DXONOTIC=1
+    -DWATERMARK="\"$(git describe --tags --dirty='~')\""
+    -DENABLE_EFFECTINFO=0
+    -DENABLE_DEBUGDRAW=0
+    -DENABLE_DEBUGTRACE=0
 )
-declare QCC=../../../gmqcc/gmqcc
+QCCDEFS="${QCCDEFS[@]}"
 
-declare -a QCC_FLAGS=(
+declare -a QCCFLAGS=(
     -std=gmqcc
     -Wall -Werror
-    -fftepp -fftepp-predefs -Wcpp
     -futf8
     -freturn-assignments
     -frelaxed-switch
     -Ooverlap-locals
 )
+declare -a NOWARN=(
+    -Wno-field-redeclared
+    -Wno-unused-variable
+    -Wno-implicit-function-pointer
+    -Wno-missing-return-values
+)
+QCCFLAGS="${QCCFLAGS[@]} ${NOWARN[@]}"
+
+. qcc.sh
+cd ..
+
+function check1() {
+    declare -l prog="${1}"
+    declare -l file="${2}"
+    MODE=${prog}
+    qpp ${file} test.dat \
+            -include lib/_all.inc -include ${prog}/_all.qh \
+            -I. ${QCCIDENT} ${QCCDEFS} > ${WORKDIR}/${prog}.qc
+    qcc ${QCCFLAGS} -o ../${WORKDIR}/test.dat ../${WORKDIR}/${prog}.qc >/dev/null
+}
 
 function check() {
-    declare -l base="${1}"
-    declare -la predefs=("-D${2}" "lib/_all.inc" "${base}/_all.qh")
-    find "$base" -type f -name '*.qc' -print0 | sort -z | while read -r -d '' file; do
-        echo "$file"
-        ${QCC} "${QCC_FLAGS[@]}" "${NOWARN[@]}" "${predefs[@]}" "$file" >/dev/null
+    declare -l prog="${1}"
+    find ${prog} -type f -name '*.qc' -print0 | sort -z | while read -r -d '' file; do
+        check1 ${prog} ${file}
     done
 }
 
-check client CSQC
-check server SVQC
-check menu MENUQC
+check client
+check server
+check menu