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