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