genmodules 4.3 KB

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