]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/tools/compilationunits.sh
Purge client/defs.qh
[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     # Without -O3, GMQCC thinks some variables are used uninitialized if the initialization is done inside an `if (1)` block
42     # (which is created by e.g. BEGIN_MACRO) which would cause the compilation units test to fail.
43     # There doesn't appear to be any measurable increase in compile time
44     # and it allows us to get rid of some explicit initializations which are just useless noise.
45     -O3
46     -Wall -Werror
47     -futf8
48     -freturn-assignments
49     -frelaxed-switch
50     -Ooverlap-locals
51 )
52 declare -a NOWARN=(
53     -Wno-field-redeclared
54     -Wno-unused-variable
55     -Wno-implicit-function-pointer
56     -Wno-missing-return-values
57 )
58 QCCFLAGS="${QCCFLAGS[@]} ${NOWARN[@]}"
59
60 . qcc.sh
61 cd ..
62
63 function check1() {
64     declare -l prog="${1}"
65     declare -l file="${2}"
66     MODE=${prog}
67     includes="-include lib/_all.inc"
68     [ -f ${prog}/_all.qh ] && includes="${includes} -include ${prog}/_all.qh"
69     qpp ${file} test.dat \
70             ${includes} \
71             -I. ${QCCIDENT} ${QCCDEFS} > ${WORKDIR}/${prog}.qc
72     qcc ${QCCFLAGS} -o ../${WORKDIR}/test.dat ../${WORKDIR}/${prog}.qc >/dev/null
73 }
74
75 function check() {
76     declare -l prog="${1}"
77     find ${prog} -type f -name '*.qc' -print0 | sort -z | while read -r -d '' file; do
78         check1 ${prog} ${file}
79     done
80 }
81
82 if [ ${#@} -eq 0 ]; then
83     check client
84     check server
85     check menu
86 else
87     for var in ${@}; do
88         check ${var}
89     done
90 fi