package.sh 4.9 KB

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