]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/tools/compilationunits.sh
Merge branch 'master' into terencehill/bot_waypoints
[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     -Wall -Werror
42     -futf8
43     -freturn-assignments
44     -frelaxed-switch
45     -Ooverlap-locals
46 )
47 declare -a NOWARN=(
48     -Wno-field-redeclared
49     -Wno-unused-variable
50     -Wno-implicit-function-pointer
51     -Wno-missing-return-values
52 )
53 QCCFLAGS="${QCCFLAGS[@]} ${NOWARN[@]}"
54
55 . qcc.sh
56 cd ..
57
58 function check1() {
59     declare -l prog="${1}"
60     declare -l file="${2}"
61     MODE=${prog}
62     includes="-include lib/_all.inc"
63     [ -f ${prog}/_all.qh ] && includes="${includes} -include ${prog}/_all.qh"
64     qpp ${file} test.dat \
65             ${includes} \
66             -I. ${QCCIDENT} ${QCCDEFS} > ${WORKDIR}/${prog}.qc
67     qcc ${QCCFLAGS} -o ../${WORKDIR}/test.dat ../${WORKDIR}/${prog}.qc >/dev/null
68 }
69
70 function check() {
71     declare -l prog="${1}"
72     find ${prog} -type f -name '*.qc' -print0 | sort -z | while read -r -d '' file; do
73         check1 ${prog} ${file}
74     done
75 }
76
77 if [ ${#@} -eq 0 ]; then
78     check client
79     check server
80     check menu
81 else
82     for var in ${@}; do
83         check ${var}
84     done
85 fi