Optimize vehicle impact code by only calling vlen() if damage would be taken
[xonotic/xonotic-data.pk3dir.git] / qcsrc / tools / qcc.sh
1 #!/usr/bin/env bash
2 set -euo pipefail
3 IFS=$' \n\t'
4
5 WORKDIR=${WORKDIR}
6 CPP=${CPP}
7 QCC=${QCC}
8 QCCIDENT="-DGMQCC"
9 QCCDEFS=${QCCDEFS}
10 QCCFLAGS=${QCCFLAGS}
11
12 function qpp() {
13     IN=$1
14     OUT=$2
15     case ${MODE} in
16         client) DEFS="-DGAMEQC -DCSQC"
17         ;;
18         menu) DEFS="-DMENUQC"
19         ;;
20         server) DEFS="-DGAMEQC -DSVQC"
21         ;;
22     esac
23     >&2 echo + ${CPP} "${@:3}" ${DEFS} "${IN}"
24     set +e
25     # additional information
26     ${CPP} "${@:3}" ${DEFS} \
27         -dM 1>"${WORKDIR}/${MODE}_macros.txt" \
28         -H 2>"${WORKDIR}/${MODE}_includes.txt" \
29         "${IN}"
30     # main step
31     ${CPP} "${@:3}" ${DEFS} -MMD -MP -MT "${OUT}" -Wall -Wundef -Werror "${IN}" -o "${WORKDIR}/${MODE}.txt"
32     err=$?
33     set -e
34     if [ ${err} -ne 0 ]; then return ${err}; fi
35     sed -E 's/^#(line)? ([[:digit:]]+) "(.*)".*/'$'\\\n''#pragma file(\3)'$'\\\n''#pragma line(\2)/g' "${WORKDIR}/${MODE}.txt"
36 }
37
38 function qcc() {
39     >&2 echo + $(basename ${QCC}) $@
40     # FIXME: relative compiler path is too deep
41     (cd tools && ${QCC} "$@")
42 }
43
44 $(return >/dev/null 2>&1) || {
45     MODE=$1
46     OUT=$2
47     IN=$3
48     case "${OUT}" in
49       /*)
50         OUT_ABSOLUTE=${OUT}
51         ;;
52       *)
53         OUT_ABSOLUTE=${PWD}/${OUT}
54         ;;
55     esac
56     set -x
57     qpp "${IN}" "${OUT}" -I. ${QCCIDENT} ${QCCDEFS} > "${WORKDIR}/${MODE}.qc"
58     qcc ${QCCFLAGS} -o "${OUT_ABSOLUTE}" "../${WORKDIR}/${MODE}.qc"
59 }