genmodules 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 "*.hpp" -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. FILES="$(sourcefind "$library" | sed "s/^/ /")"
  67. if [[ ${#FILES} -gt 2 ]]; then
  68. printf "if $NAME\n"
  69. printf "liblove${love_amsuffix}_la_SOURCES += \\\\\n"
  70. printf "${FILES:0:${#FILES}-2}\nendif\n\n"
  71. fi
  72. done
  73. cd ../..
  74. }
  75. genflags()
  76. {
  77. for flag in $flags; do
  78. prettyflag="$(echo "$flag" | sed 's/-/ love./' | sed 's/-/./g')"
  79. varflag="enable_$(echo "$flag" | sed 's/^[^-]*-//' | sed 's/[^a-zA-Z0-9]/_/')"
  80. defineflag="LOVE_ENABLE_$(upper $(echo $flag | sed 's/^[^-]*-//' | sed 's/-/_/g'))"
  81. amflag="$(upper $(echo love-$flag | sed 's/-/_/g'))"
  82. printf "AC_ARG_ENABLE([$flag], [ --disable-$flag Turn off $prettyflag], [], [$varflag=true])\n"
  83. printf "AH_TEMPLATE([$defineflag], [])\n"
  84. printf "if test x\"\$$varflag\" = xtrue; then\n"
  85. printf " AC_DEFINE([$defineflag], [])\n"
  86. printf "fi\n"
  87. printf "AM_CONDITIONAL([$amflag], [test x\$$varflag = xtrue])\n\n"
  88. done
  89. }
  90. echo Generating src/Makefile.am ...
  91. inc_current='$(srcdir)'
  92. inc_modules="$inc_current/modules"
  93. inc_libraries="$inc_current/libraries"
  94. cat > src/Makefile.am << EOF
  95. AM_CPPFLAGS = -I$inc_current -I$inc_modules -I$inc_libraries -I$inc_libraries/enet/libenet/include \$(LOVE_INCLUDES) \$(FILE_OFFSET)\
  96. \$(SDL_CFLAGS) \$(lua_CFLAGS) \$(freetype2_CFLAGS)\
  97. \$(openal_CFLAGS) \$(zlib_CFLAGS) \$(libmodplug_CFLAGS)\
  98. \$(vorbisfile_CFLAGS)
  99. AUTOMAKE_OPTIONS = subdir-objects
  100. SUBDIRS =
  101. SUFFIXES = .lua .lua.h
  102. if LOVE_BUILD_EXE
  103. # LÖVE executable
  104. bin_PROGRAMS = love${love_suffix}
  105. #love_LDFLAGS =
  106. love${love_amsuffix}_LDADD = liblove${love_suffix}.la \$(lua_LIBS)
  107. love${love_amsuffix}_SOURCES = love.cpp
  108. if LOVE_TARGET_OSX
  109. love${love_amsuffix}_LIBTOOLFLAGS = --tag=OBJCXX
  110. love${love_amsuffix}_SOURCES += \\
  111. ../platform/macosx/OSX.h \\
  112. ../platform/macosx/OSX.mm
  113. else
  114. love${love_amsuffix}_LIBTOOLFLAGS = --tag=CXX
  115. endif
  116. endif
  117. # Compile scripts
  118. .lua.lua.h:
  119. cd scripts; \
  120. \$(LUA_EXECUTABLE) auto.lua \$<
  121. # libLÖVE
  122. lib_LTLIBRARIES = liblove${love_suffix}.la
  123. liblove${love_amsuffix}_la_LDFLAGS = -module -export-dynamic \$(LDFLAGS)
  124. liblove${love_amsuffix}_la_LIBADD = \
  125. \$(SDL_LIBS) \$(freetype2_LIBS) \$(lua_LIBS)\
  126. \$(openal_LIBS) \$(zlib_LIBS) \$(libmodplug_LIBS)\
  127. \$(vorbisfile_LIBS)
  128. EOF
  129. genmodules >> src/Makefile.am
  130. cat >> src/Makefile.am << EOF
  131. if !LOVE_NOMPG123
  132. liblove${love_amsuffix}_la_SOURCES += \\
  133. ./modules/sound/lullaby/Mpg123Decoder.cpp \\
  134. ./modules/sound/lullaby/Mpg123Decoder.h
  135. endif
  136. EOF
  137. echo "src/Makefile.am is updated! ^.^"
  138. echo "Generating configure-modules.ac"
  139. genflags > configure-modules.ac
  140. cat >> configure-modules.ac << EOF
  141. AC_SUBST([LOVE_SUFFIX], [${love_suffix}])
  142. EOF
  143. echo "configure-modules.ac is updated! ^.^"