]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/tools/compilationunits.sh
document compilationunits.sh
[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 )
34 QCCDEFS="${QCCDEFS[@]}"
35
36 declare -a QCCFLAGS=(
37     -std=gmqcc
38     -Wall -Werror
39     -futf8
40     -freturn-assignments
41     -frelaxed-switch
42     -Ooverlap-locals
43 )
44 declare -a NOWARN=(
45     -Wno-field-redeclared
46     -Wno-unused-variable
47     -Wno-implicit-function-pointer
48     -Wno-missing-return-values
49 )
50 QCCFLAGS="${QCCFLAGS[@]} ${NOWARN[@]}"
51
52 . qcc.sh
53 cd ..
54
55 function check1() {
56     declare -l prog="${1}"
57     declare -l file="${2}"
58     MODE=${prog}
59     qpp ${file} test.dat \
60             -include lib/_all.inc -include ${prog}/_all.qh \
61             -I. ${QCCIDENT} ${QCCDEFS} > ${WORKDIR}/${prog}.qc
62     qcc ${QCCFLAGS} -o ../${WORKDIR}/test.dat ../${WORKDIR}/${prog}.qc >/dev/null
63 }
64
65 function check() {
66     declare -l prog="${1}"
67     find ${prog} -type f -name '*.qc' -print0 | sort -z | while read -r -d '' file; do
68         check1 ${prog} ${file}
69     done
70 }
71
72 check client
73 check server
74 check menu