genmodules 4.5 KB

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