scanMods.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/bin/bash
  2. STRUCTS="
  3. World
  4. GameState
  5. "
  6. THUNKS="
  7. World_init
  8. World_initGL
  9. GameState_init
  10. GameState_initGL
  11. "
  12. MODSDIR="./mods"
  13. function processStruct() {
  14. hname=$1
  15. dir=$2
  16. modname=$3
  17. if [ -f $dir/$hname.mixin.h ]; then
  18. echo " struct $hname"
  19. echo -e "\nstruct {" >> $MODSDIR/$hname.generated_mixin.h
  20. echo -e "#include \"$dir/$hname.mixin.h\"" | sed s/^/\\t/ >> $MODSDIR/$hname.generated_mixin.h
  21. echo -e "} mod_$modname;\n" >> $MODSDIR/$hname.generated_mixin.h
  22. fi
  23. }
  24. function processThunk() {
  25. hname=$1
  26. dir=$2
  27. modname=$3
  28. if [ -f $dir/$hname.thunk.c ]; then
  29. echo " thunk $hname"
  30. echo -e "\n{" >> $MODSDIR/$hname.generated_thunk.c
  31. echo -e "#include \"$dir/$hname.thunk.c\"" | sed s/^/\\t/ >> $MODSDIR/$hname.generated_thunk.c
  32. echo -e "};\n" >> $MODSDIR/$hname.generated_thunk.c
  33. fi
  34. }
  35. function processMod() {
  36. for s in $STRUCTS; do
  37. processStruct $s $1 $2
  38. done
  39. for s in $THUNKS; do
  40. processThunk $s $1 $2
  41. done
  42. }
  43. function checkDir() {
  44. bname="$1"
  45. if [ -z $2 ]; then
  46. pname=""
  47. else
  48. pname="${2}_"
  49. fi
  50. touch $bname/Makefile.am
  51. subdirs=""
  52. for dname in `find $bname/* -follow -maxdepth 1 -type d | xargs -n 1 -- basename`; do
  53. if [ -f $bname/$dname/modpack ]; then
  54. packname=`cat $bname/$dname/modpack`
  55. echo "Found mod pack: $packname"
  56. checkDir "$bname/$dname" "$pname$packname"
  57. else
  58. if [ -f $bname/$dname/modname ]; then
  59. modname=`cat $bname/$dname/modname`
  60. subdirs="$subdirs $dname"
  61. echo "Found mod: $modname"
  62. processMod "$bname/$dname" $modname
  63. fi
  64. fi
  65. done
  66. # write the makefile
  67. cat > "$bname/Makefile.am" <<EOF
  68. SUBDIRS = $subdirs
  69. ACLOCAL_AMFLAGS = -I m4
  70. EOF
  71. }
  72. rm ./mods/Makefile.am
  73. # clear out generated files
  74. for s in $STRUCTS; do
  75. echo -e "//\n// GENERATED FILE: DO NOT EDIT\n//\n// included inside struct $s\n\n" > $MODSDIR/$s.generated_mixin.h
  76. done
  77. for s in $THUNKS; do
  78. echo -e "//\n// GENERATED FILE: DO NOT EDIT\n//\n// included inside function $s()\n\n" > $MODSDIR/$s.generated_thunk.c
  79. done
  80. checkDir "./mods"