genmodules 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #!/bin/bash
  2. love_suffix="$1"
  3. flags=""
  4. upper()
  5. {
  6. echo "$@" | tr '[:lower:]' '[:upper:]'
  7. }
  8. implfind()
  9. {
  10. find "$1" -maxdepth 1 -type d -exec basename '{}' \; | grep -v "^\." | tail -n +2
  11. }
  12. sourcefind()
  13. {
  14. find "$1" $2 -type f \( -iname "*.c" -o -iname "*.cpp" -o -iname "*.h" -o -iname "*.lch" \) | awk "{print \"./$prefix\"\$0\" \\\\\"}" | grep -v -f"$LOVEROOT/platform/unix/exclude"
  15. }
  16. handlemodule()
  17. {
  18. module="$1"
  19. DEFINENAME="LOVE_MODULE_$(upper "$module")"
  20. printf "$DEFINENAME"
  21. }
  22. handleimpl()
  23. {
  24. module="$1"
  25. implementation="$2"
  26. name="$3"
  27. printf "if $name\n"
  28. FILES="$(sourcefind "$module/$implementation" | sed "s/^/ /")"
  29. if [[ "x$FILES" != "x" ]]; then
  30. printf "liblove${love_suffix}_la_SOURCES += \\\\\n"
  31. printf "${FILES:0:${#FILES}-2}\n"
  32. fi
  33. printf "endif\n\n"
  34. }
  35. genmodules()
  36. {
  37. LOVEROOT="$(pwd)"
  38. cd src
  39. printf "liblove${love_suffix}_la_SOURCES = \\\\\n"
  40. sourcefind "common" | sed "s/^/ /"
  41. FILES="$(sourcefind "scripts" | sed "s/^/ /")"
  42. printf "${FILES:0:${#FILES}-2}\n\n"
  43. cd modules
  44. prefix="modules/"
  45. for module in *; do
  46. NAME=$(handlemodule "$module")
  47. flags="$flags module-$module"
  48. printf "if $NAME\n"
  49. for implementation in $(implfind "$module"); do
  50. flags="$flags implementation-$module-$implementation"
  51. handleimpl "$module" "$implementation" "LOVE_IMPLEMENTATION_$(upper "$module")_$(upper "$implementation")"
  52. done
  53. FILES="$(sourcefind "$module" "-maxdepth 1" | sed "s/^/ /")"
  54. if [[ "x$FILES" != "x" ]]; then
  55. printf "liblove${love_suffix}_la_SOURCES += \\\\\n"
  56. printf "${FILES:0:${#FILES}-2}\n"
  57. fi
  58. printf "endif\n\n"
  59. done
  60. cd ../libraries
  61. prefix="libraries/"
  62. for library in *; do
  63. NAME="LOVE_LIBRARY_$(upper "$library")"
  64. flags="$flags library-$library"
  65. printf "if $NAME\n"
  66. printf "liblove${love_suffix}_la_SOURCES += \\\\\n"
  67. FILES="$(sourcefind "$library" | sed "s/^/ /")"
  68. printf "${FILES:0:${#FILES}-2}\nendif\n\n"
  69. done
  70. cd ../..
  71. }
  72. genflags()
  73. {
  74. for flag in $flags; do
  75. prettyflag="$(echo "$flag" | sed 's/-/ love./' | sed 's/-/./g')"
  76. varflag="enable_$(echo "$flag" | sed 's/^[^-]*-//' | sed 's/[^a-zA-Z0-9]/_/')"
  77. defineflag="LOVE_ENABLE_$(upper $(echo $flag | sed 's/^[^-]*-//' | sed 's/-/_/g'))"
  78. amflag="$(upper $(echo love-$flag | sed 's/-/_/g'))"
  79. printf "AC_ARG_ENABLE([$flag], [ --disable-$flag Turn off $prettyflag], [], [$varflag=true])\n"
  80. printf "AH_TEMPLATE([$defineflag], [])\n"
  81. printf "if test x\"\$$varflag\" == xtrue; then\n"
  82. printf " AC_DEFINE([$defineflag], [])\n"
  83. printf "fi\n"
  84. printf "AM_CONDITIONAL([$amflag], [test x\$$varflag == xtrue])\n\n"
  85. done
  86. }
  87. echo Generating src/Makefile.am ...
  88. inc_current='$(srcdir)'
  89. inc_modules="$inc_current/modules"
  90. inc_libraries="$inc_current/libraries"
  91. cat > src/Makefile.am << EOF
  92. AM_CPPFLAGS = -I$inc_current -I$inc_modules -I$inc_libraries -I$inc_libraries/enet/libenet/include \$(LOVE_INCLUDES) \$(FILE_OFFSET) \$(SDL_CFLAGS) \$(freetype2_CFLAGS) \$(lua_CFLAGS)
  93. AUTOMAKE_OPTIONS = subdir-objects
  94. SUBDIRS =
  95. if LOVE_BUILD_EXE
  96. # LÖVE executable
  97. bin_PROGRAMS = love${love_suffix}
  98. #love_LDFLAGS =
  99. love${love_suffix}_LDADD = liblove${love_suffix}.la \$(lua_LIBS)
  100. love${love_suffix}_SOURCES = love.cpp
  101. if LOVE_TARGET_OSX
  102. love${love_suffix}_LIBTOOLFLAGS = --tag=OBJCXX
  103. love${love_suffix}_SOURCES += \\
  104. ../platform/macosx/OSX.h \\
  105. ../platform/macosx/OSX.mm
  106. else
  107. love${love_suffix}_LIBTOOLFLAGS = --tag=CXX
  108. endif
  109. endif
  110. # Compile scripts
  111. #scripts/%.lua.h: scripts/%.lua
  112. # cd scripts; \
  113. # lua auto.lua \$*
  114. #TODO: Figure out how to only do this on gnu make, and detect which lua
  115. # executable to run
  116. # libLÖVE
  117. lib_LTLIBRARIES = liblove${love_suffix}.la
  118. liblove${love_suffix}_la_LDFLAGS = -module -export-dynamic \$(LDFLAGS) \$(SDL_LIBS) \$(freetype2_LIBS) \$(lua_LIBS)
  119. EOF
  120. genmodules >> src/Makefile.am
  121. cat >> src/Makefile.am << EOF
  122. if !LOVE_NOMPG123
  123. liblove${love_suffix}_la_SOURCES += \\
  124. ./modules/sound/lullaby/Mpg123Decoder.cpp \\
  125. ./modules/sound/lullaby/Mpg123Decoder.h
  126. endif
  127. EOF
  128. echo "src/Makefile.am is updated! ^.^"
  129. echo "Generating configure-modules.ac"
  130. genflags > configure-modules.ac
  131. echo "configure-modules.ac is updated! ^.^"