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