package.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. #!/bin/sh
  2. #
  3. # Because nobody's perfect.. ;-)
  4. #
  5. ################################################################################
  6. function usage {
  7. echo "usage: $0 [-b win32 | macos | linux-i686 | linux-amd64]"
  8. echo
  9. echo " -b Builds a binary distribution for the specified arch."
  10. echo " -h Displays this help text."
  11. exit 0
  12. }
  13. #
  14. # createzip /path/to/SDL.dll
  15. #
  16. function createzip {
  17. #
  18. # Copy SDL here temporarily.
  19. #
  20. cp -f $1 SDL.dll &&
  21. #
  22. # Create the binary package.
  23. #
  24. 7za.exe a -tzip dist/$TARGET.zip \
  25. $BINARY_DEPS $DOCS $TARGET.exe SDL.dll &&
  26. #
  27. # Remove SDL.
  28. #
  29. rm -f SDL.dll
  30. }
  31. #
  32. # createtbz tar-name-ext [extra-binary]
  33. #
  34. function createtbz {
  35. #
  36. # create temporary directory
  37. #
  38. mkdir -p dist/$TARGET/docs &&
  39. #
  40. # copy binaries into it
  41. #
  42. cp -f --dereference $BINARY_DEPS $TARGET $2 dist/$TARGET &&
  43. #
  44. # copy docs over
  45. #
  46. cp -f --dereference $DOCS dist/$TARGET/docs &&
  47. #
  48. # tar it up
  49. #
  50. tar -C dist -jcvf dist/$TARGET-$1.tar.bz2 $TARGET &&
  51. #
  52. # now delete temporary dir
  53. #
  54. rm -rf dist/$TARGET
  55. }
  56. #
  57. # in case of error; breakout CODE
  58. #
  59. function breakout {
  60. echo "Error $1 occured during packaging, aborted."
  61. exit $1
  62. }
  63. #
  64. # The basename for the source and binary packages.
  65. #
  66. TARGET=`cat Makefile.in | grep TARGET | cut -d " " -f6`
  67. if [ "$TARGET" == "" ]; then
  68. breakout 1
  69. fi
  70. if [ "$1" == "-h" ]; then
  71. usage
  72. fi
  73. #
  74. # MegaZeux source AND binary distributions depend on these
  75. # files being here. Update this list carefully; things that
  76. # are in source but NOT the binary package should be in
  77. # build deps below.
  78. #
  79. BINARY_DEPS="smzx.pal mzx_ascii.chr mzx_blank.chr mzx_default.chr \
  80. mzx_help.fil mzx_smzx.chr mzx_edit.chr config.txt"
  81. #
  82. # Documents that the binary zip should contain (pathname will be stored too).
  83. #
  84. DOCS="docs/COPYING.DOC docs/changelog.txt docs/port.txt docs/macro.txt"
  85. #
  86. # MegaZeux's build system dependencies; these are packaged in
  87. # addition to binary deps above to complete the source package.
  88. #
  89. BUILD_DEPS="config.sh Makefile Makefile.in package.sh"
  90. #
  91. # These directories are purely for source distributions.
  92. #
  93. SUBDIRS="arch contrib docs"
  94. #
  95. # What we actually care about; the complete sources to MegaZeux. Try to
  96. # extract crap Exo's left in the wrong place. Feel free to update this.
  97. #
  98. SRC="src/*.cpp src/*.h src/Makefile"
  99. #
  100. # Do source package.
  101. #
  102. ################################################################################
  103. echo "Generating source package for $TARGET.."
  104. #
  105. # dist cannot safely exist prior to starting.
  106. #
  107. if [ -d dist ]; then
  108. echo "Destroying dist/.."
  109. rm -rf dist
  110. fi
  111. mkdir -p dist/$TARGET/src &&
  112. cp -pv $BINARY_DEPS $BUILD_DEPS dist/$TARGET &&
  113. cp -pvr $SUBDIRS dist/$TARGET &&
  114. cp -pv $SRC dist/$TARGET/src &&
  115. # hack for gdm2s3m & libmodplug
  116. rm -f dist/$TARGET/contrib/gdm2s3m/src/{*.a,*.o} &&
  117. rm -f dist/$TARGET/contrib/libmodplug/src/{*.a,*.o} &&
  118. # hack for "dist" makefile
  119. cp dist/$TARGET/arch/Makefile.dist dist/$TARGET/Makefile.platform
  120. if [ "$?" != "0" ]; then
  121. breakout 2
  122. fi
  123. rm -f dist/$TARGET/src/config.h
  124. echo "Creating source (${TARGET}src.tar.bz2).."
  125. cd dist
  126. tar --exclude CVS -jcvf ${TARGET}src.tar.bz2 $TARGET
  127. cd ..
  128. if [ "$?" != "0" ]; then
  129. breakout 3
  130. fi
  131. rm -rf dist/$TARGET
  132. echo Built source distribution successfully!
  133. #
  134. # no binary package is required
  135. #
  136. if [ "$1" != "-b" ]; then
  137. echo "Skipping binary package build."
  138. exit 0
  139. fi
  140. #
  141. # Do binary package.
  142. #
  143. ################################################################################
  144. echo "Generating binary package for $2.."
  145. #
  146. # Windows, using ZIP compression via 7ZIP compressor
  147. #
  148. if [ "$2" = "win32" ]; then
  149. LIBSDL="/usr/lib/SDL.dll" # Exo's mingw install
  150. createzip $LIBSDL
  151. exit
  152. fi
  153. #
  154. # MacOS X, using tar.bz2 compression.
  155. #
  156. if [ "$2" = "macos" ]; then
  157. LIBSDL="~/dev/lib/libSDL-1.2.0.dylib" # burst or beige's mac
  158. createtbz osx-ppc $LIBSDL
  159. exit
  160. fi
  161. #
  162. # NOTE: THE LINUX BUILDS SHOULD HAVE STDC++ STATICALLY LINKED!
  163. # NOTE: THEY MUST ALSO HAVE RELATIVE DIRECTORY LOOKUPS ENABLED!
  164. #
  165. #
  166. # Linux/i686, using tar.bz2 compression (NO SDL)
  167. #
  168. if [ "$2" = "linux-i686" ]; then
  169. createtbz linux-i686
  170. exit
  171. fi
  172. #
  173. # Linux/amd64, using tar.bz2 compression (NO SDL)
  174. #
  175. if [ "$2" = "linux-amd64" ]; then
  176. createtbz linux-amd64
  177. exit
  178. fi
  179. #
  180. # Unknown binary arch
  181. #
  182. echo "Unknown binary architecture.."
  183. echo
  184. usage