Merge branch 'martin-t/cvar-descriptions' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / tools / compilationunits.sh
1 #!/usr/bin/env bash
2 set -eu
3 cd ${0%/*}
4
5 # This script attempts to build the codebase in every possible header configuration,
6 # to check that all files #include what they need, so that we can eventually move away
7 # from a unity build and into incremental compilation.
8
9 # If these files exist from previous compilation, `./all compile` will stop
10 # detecting changes after running this script so delete them to trigger
11 # a recompile next time.
12 if [ -f ../../csprogs.dat ]; then
13     rm ../../csprogs.dat
14 fi
15
16 if [ -f ../../menu.dat ]; then
17     rm ../../menu.dat
18 fi
19
20 if [ -f ../../progs.dat ]; then
21     rm ../../progs.dat
22 fi
23
24 WORKDIR=../.tmp
25
26 CPP="cc -xc -E"
27 : ${QCC:=$PWD/../../../../gmqcc/gmqcc}
28
29 declare -a QCCDEFS=(
30     -DNDEBUG=1
31     -DXONOTIC=1
32     -DWATERMARK="\"$(git describe --tags --dirty='~')\""
33     -DENABLE_EFFECTINFO=0
34     -DENABLE_DEBUGDRAW=0
35     -DENABLE_DEBUGTRACE=0
36 )
37 QCCDEFS="${QCCDEFS[@]}"
38
39 declare -a QCCFLAGS=(
40     -std=gmqcc
41     -O3 # optimization to accept variable initialization inside `if (1)` blocks and avoid warnings
42     -Wall -Werror
43     -futf8
44     -freturn-assignments
45     -frelaxed-switch
46     -Ooverlap-locals
47 )
48 declare -a NOWARN=(
49     -Wno-field-redeclared
50     -Wno-unused-variable
51     -Wno-implicit-function-pointer
52     -Wno-missing-return-values
53 )
54 QCCFLAGS="${QCCFLAGS[@]} ${NOWARN[@]}"
55
56 . qcc.sh
57 cd ..
58
59 function check1() {
60     declare -l prog="${1}"
61     declare -l file="${2}"
62     MODE=${prog}
63     includes="-include lib/_all.inc"
64     [ -f ${prog}/_all.qh ] && includes="${includes} -include ${prog}/_all.qh"
65     qpp ${file} test.dat \
66             ${includes} \
67             -I. ${QCCIDENT} ${QCCDEFS} > ${WORKDIR}/${prog}.qc
68     qcc ${QCCFLAGS} -o ../${WORKDIR}/test.dat ../${WORKDIR}/${prog}.qc >/dev/null
69 }
70
71 function check() {
72     declare -l prog="${1}"
73     find ${prog} -type f -name '*.qc' -print0 | sort -z | while read -r -d '' file; do
74         check1 ${prog} ${file}
75     done
76 }
77
78 if [ ${#@} -eq 0 ]; then
79     check client
80     check server
81     check menu
82 else
83     for var in ${@}; do
84         check ${var}
85     done
86 fi