]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/tools/genmod.sh
Merge branch 'master' into terencehill/glowmod_color_fix
[xonotic/xonotic-data.pk3dir.git] / qcsrc / tools / genmod.sh
1 #!/usr/bin/env bash
2 set -eu
3
4 # This script creates / updates the _mod.qc / _mod.qh / _mod.inc files based on
5 # the qc / qh files present in the qcsrc folder.
6
7 cd ${0%/*}
8 cd ..
9 ROOT=$PWD/
10
11 MOD=_mod
12
13 function hash() {
14     git hash-object $1
15 }
16
17 function genmod() {
18     # use context to work around cmake issue #12619
19     CTX="${PWD#$ROOT}/"
20     if [ -f ${MOD}.inc ]; then
21         oldHashC=$(hash ${MOD}.inc)
22         oldTimeC=$(stat -c "%Y" ${MOD}.inc)
23     fi
24     if [ -f ${MOD}.qh ]; then
25         oldHashH=$(hash ${MOD}.qh)
26         oldTimeH=$(stat -c "%Y" ${MOD}.qh)
27     fi
28     echo '// generated file; do not modify' > ${MOD}.inc
29     echo '// generated file; do not modify' > ${MOD}.qh
30     for f in $(ls | sort -k 1,1 -t .); do
31           if [[ "$f" == cl_* ]]; then f="${f#cl_}"; if [[ -f "$f" ]]; then continue; fi
32         elif [[ "$f" == sv_* ]]; then f="${f#sv_}"; if [[ -f "$f" ]]; then continue; fi
33         elif [[ "$f" == ui_* ]]; then f="${f#ui_}"; if [[ -f "$f" ]]; then continue; fi
34         fi
35         if [[ "$f" == *.qc ]]; then
36             if [[ -f "$f" ]]; then echo -e "#include <${CTX}$f>" >> ${MOD}.inc; fi
37             if [[ -f "${f%.qc}.qh" ]]; then echo -e "#include <${CTX}${f%.qc}.qh>" >> ${MOD}.qh; fi
38             if [[ -f "cl_$f" ]]; then echo -e "#ifdef CSQC\n    #include <${CTX}cl_$f>\n#endif" >> ${MOD}.inc; fi
39             if [[ -f "cl_${f%.qc}.qh" ]]; then echo -e "#ifdef CSQC\n    #include <${CTX}cl_${f%.qc}.qh>\n#endif" >> ${MOD}.qh; fi
40             if [[ -f "sv_$f" ]]; then echo -e "#ifdef SVQC\n    #include <${CTX}sv_$f>\n#endif" >> ${MOD}.inc; fi
41             if [[ -f "sv_${f%.qc}.qh" ]]; then echo -e "#ifdef SVQC\n    #include <${CTX}sv_${f%.qc}.qh>\n#endif" >> ${MOD}.qh; fi
42             if [[ -f "ui_$f" ]]; then echo -e "#ifdef MENUQC\n    #include <${CTX}ui_$f>\n#endif" >> ${MOD}.inc; fi
43             if [[ -f "ui_${f%.qc}.qh" ]]; then echo -e "#ifdef MENUQC\n    #include <${CTX}ui_${f%.qc}.qh>\n#endif" >> ${MOD}.qh; fi
44         fi
45     done
46     declare -l rec=1
47     if [[ -f "_all.inc" ]]; then rec=0; fi
48     for f in *; do if [ -d "$f" ]; then
49         (cd -- "$f" && genmod)
50         if [[ $rec == 1 ]]; then
51             rec=2
52             echo >> ${MOD}.inc
53             echo >> ${MOD}.qh
54         fi
55         if [[ $rec != 0 ]]; then
56             declare -l mod=_mod
57             if [[ -f "$f/_all.inc" ]]; then mod=_all; fi
58             echo "#include <${CTX}$f/${mod}.inc>" >> ${MOD}.inc
59             echo "#include <${CTX}$f/${mod}.qh>" >> ${MOD}.qh
60         fi
61     fi; done
62     newHashC=$(hash ${MOD}.inc)
63     if [[ $newHashC == $oldHashC ]]; then touch -d @$oldTimeC ${MOD}.inc; fi
64     newHashH=$(hash ${MOD}.qh)
65     if [[ $newHashH == $oldHashH ]]; then touch -d @$oldTimeH ${MOD}.qh; fi
66 }
67
68 (cd lib; genmod)
69 (cd common; genmod)
70 (cd ecs; genmod)
71 (cd client; genmod)
72 (cd server; genmod)
73 (cd menu; genmod)