]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/tools/genmod.sh
Merge branch 'master' into TimePath/scrollpanel
[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     if [ -f ${MOD}.inc ]; then
17         oldHashC=$(hash ${MOD}.inc)
18         oldTimeC=$(stat -c "%Y" ${MOD}.inc)
19     fi
20     if [ -f ${MOD}.qh ]; then
21         oldHashH=$(hash ${MOD}.qh)
22         oldTimeH=$(stat -c "%Y" ${MOD}.qh)
23     fi
24     echo '// generated file; do not modify' > ${MOD}.inc
25     echo '// generated file; do not modify' > ${MOD}.qh
26     for f in $(ls | sort -k 1,1 -t .); do
27           if [[ "$f" == cl_* ]]; then f="${f#cl_}"; if [[ -f "$f" ]]; then continue; fi
28         elif [[ "$f" == sv_* ]]; then f="${f#sv_}"; if [[ -f "$f" ]]; then continue; fi
29         elif [[ "$f" == ui_* ]]; then f="${f#ui_}"; if [[ -f "$f" ]]; then continue; fi
30         fi
31         if [[ "$f" == *.qc ]]; then
32             if [[ -f "$f" ]]; then echo -e "#include <${CTX}$f>" >> ${MOD}.inc; fi
33             if [[ -f "${f%.qc}.qh" ]]; then echo -e "#include <${CTX}${f%.qc}.qh>" >> ${MOD}.qh; fi
34             if [[ -f "cl_$f" ]]; then echo -e "#ifdef CSQC\n    #include <${CTX}cl_$f>\n#endif" >> ${MOD}.inc; fi
35             if [[ -f "cl_${f%.qc}.qh" ]]; then echo -e "#ifdef CSQC\n    #include <${CTX}cl_${f%.qc}.qh>\n#endif" >> ${MOD}.qh; fi
36             if [[ -f "sv_$f" ]]; then echo -e "#ifdef SVQC\n    #include <${CTX}sv_$f>\n#endif" >> ${MOD}.inc; fi
37             if [[ -f "sv_${f%.qc}.qh" ]]; then echo -e "#ifdef SVQC\n    #include <${CTX}sv_${f%.qc}.qh>\n#endif" >> ${MOD}.qh; fi
38             if [[ -f "ui_$f" ]]; then echo -e "#ifdef MENUQC\n    #include <${CTX}ui_$f>\n#endif" >> ${MOD}.inc; fi
39             if [[ -f "ui_${f%.qc}.qh" ]]; then echo -e "#ifdef MENUQC\n    #include <${CTX}ui_${f%.qc}.qh>\n#endif" >> ${MOD}.qh; fi
40         fi
41     done
42     declare -l rec=1
43     if [[ -f "_all.inc" ]]; then rec=0; fi
44     for f in *; do if [ -d "$f" ]; then
45         (cd -- "$f" && genmod)
46         if [[ $rec == 1 ]]; then
47             rec=2
48             echo >> ${MOD}.inc
49             echo >> ${MOD}.qh
50         fi
51         if [[ $rec != 0 ]]; then
52             declare -l mod=_mod
53             if [[ -f "$f/_all.inc" ]]; then mod=_all; fi
54             echo "#include <${CTX}$f/${mod}.inc>" >> ${MOD}.inc
55             echo "#include <${CTX}$f/${mod}.qh>" >> ${MOD}.qh
56         fi
57     fi; done
58     newHashC=$(hash ${MOD}.inc)
59     if [[ $newHashC == $oldHashC ]]; then touch -d @$oldTimeC ${MOD}.inc; fi
60     newHashH=$(hash ${MOD}.qh)
61     if [[ $newHashH == $oldHashH ]]; then touch -d @$oldTimeH ${MOD}.qh; fi
62 }
63
64 (cd lib; genmod)
65 (cd common; genmod)
66 (cd ecs; genmod)
67 (cd client; genmod)
68 (cd server; genmod)
69 (cd menu; genmod)