genmodules 4.3 KB

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