package.sh 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. #!/bin/sh
  2. #
  3. # Because nobody's perfect.. ;-)
  4. #
  5. ################################################################################
  6. usage() {
  7. echo "usage: $0 [-b win32 | win64 | psp]"
  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. createpspzip() {
  17. #
  18. # Create the binary package.
  19. #
  20. $SEVENZIP a -tzip dist/$TARGET-psp.zip \
  21. $BINARY_DEPS EBOOT.PBP $DOCS $PSPPAD
  22. }
  23. #
  24. # createzip_dynamic_sdl </path/to/SDL.dll> <POSTFIX>
  25. #
  26. createzip_dynamic_sdl() {
  27. WINDIB_BAT="windib.bat"
  28. #
  29. # Copy SDL here temporarily.
  30. #
  31. cp -f $1 SDL.dll &&
  32. #
  33. # Generate a suitable windib.bat
  34. #
  35. echo "set SDL_VIDEODRIVER=windib" > $WINDIB_BAT &&
  36. echo "start $TARGET.exe" >> $WINDIB_BAT &&
  37. #
  38. # pack the EXE
  39. #
  40. ( $UPX --best $TARGET.exe || echo "UPX isn't available, skipped." ) &&
  41. #
  42. # Create the binary package.
  43. #
  44. $SEVENZIP a -tzip dist/$TARGET-$2.zip \
  45. $BINARY_DEPS $DOCS $TARGET.exe SDL.dll $WINDIB_BAT &&
  46. #
  47. # Remove SDL, and the bat file.
  48. #
  49. rm -f SDL.dll $WINDIB_BAT
  50. }
  51. #
  52. # createzip_dynamic_sdl <POSTFIX>
  53. #
  54. createzip_static_sdl() {
  55. WINDIB_BAT="windib.bat"
  56. #
  57. # Generate a suitable windib.bat
  58. #
  59. echo "set SDL_VIDEODRIVER=windib" > $WINDIB_BAT &&
  60. echo "start $TARGET.exe" >> $WINDIB_BAT &&
  61. #
  62. # pack the EXE
  63. #
  64. ( $UPX --best $TARGET.exe || echo "UPX isn't available, skipped." ) &&
  65. #
  66. # Create the binary package.
  67. #
  68. $SEVENZIP a -tzip dist/$TARGET-$1.zip \
  69. $BINARY_DEPS $DOCS $TARGET.exe $WINDIB_BAT &&
  70. #
  71. # Remove SDL, and the bat file.
  72. #
  73. rm -f $WINDIB_BAT
  74. }
  75. #
  76. # createtbz tar-name-ext [extra-binary]
  77. #
  78. createtbz() {
  79. #
  80. # create temporary directory
  81. #
  82. mkdir -p dist/$TARGET/docs &&
  83. #
  84. # copy binaries into it
  85. #
  86. cp -f --dereference $BINARY_DEPS $TARGET $2 dist/$TARGET &&
  87. #
  88. # copy docs over
  89. #
  90. cp -f --dereference $DOCS dist/$TARGET/docs &&
  91. #
  92. # tar it up
  93. #
  94. tar -C dist -jcvf dist/$TARGET-$1.tar.bz2 $TARGET &&
  95. #
  96. # now delete temporary dir
  97. #
  98. rm -rf dist/$TARGET
  99. }
  100. #
  101. # in case of error; breakout CODE
  102. #
  103. breakout() {
  104. echo "Error $1 occured during packaging, aborted."
  105. exit $1
  106. }
  107. #
  108. # The basename for the source and binary packages.
  109. #
  110. TARGET=`grep TARGET Makefile | head -n1 | sed "s/ //g" | cut -d "=" -f 2`
  111. if [ "$TARGET" == "" ]; then
  112. breakout 1
  113. fi
  114. if [ "$1" == "-h" ]; then
  115. usage
  116. fi
  117. #
  118. # MegaZeux source AND binary distributions depend on these
  119. # files being here. Update this list carefully; things that
  120. # are in source but NOT the binary package should be in
  121. # build deps below.
  122. #
  123. BINARY_DEPS="smzx.pal mzx_ascii.chr mzx_blank.chr mzx_default.chr \
  124. mzx_help.fil mzx_smzx.chr mzx_edit.chr config.txt"
  125. #
  126. # Documents that the binary zip should contain (pathname will be stored too).
  127. #
  128. DOCS="docs/COPYING.DOC docs/changelog.txt docs/port.txt docs/macro.txt"
  129. #
  130. # Various joypad configuration files.
  131. #
  132. PSPPAD="pad.config"
  133. GP2XPAD="pad.config.gp2x"
  134. #
  135. # MegaZeux's build system dependencies; these are packaged in
  136. # addition to binary deps above to complete the source package.
  137. #
  138. BUILD_DEPS="config.sh Makefile package.sh $PSPPAD $GP2XPAD macosx.zip"
  139. #
  140. # These directories are purely for source distributions.
  141. #
  142. SUBDIRS="arch contrib debian docs"
  143. #
  144. # What we actually care about; the complete sources to MegaZeux. Try to
  145. # extract crap Exo's left in the wrong place. Feel free to update this.
  146. #
  147. SRC="src/*.c src/*.cpp src/*.h src/Makefile.in src/old src/utils"
  148. #
  149. # Name of the 7zip extractor. On Windows, this is '7za.exe'. On Linux, this is
  150. # _usually_ '7za', but if you're using a compatible replacement, change this
  151. # here. Only affects Windows binary distributions and PSP binary distributions,
  152. # otherwise GNU tar is used instead.
  153. #
  154. SEVENZIP="7za"
  155. #
  156. # Name of the Ultimate Packer for eXecutables program. On Windows, this is
  157. # 'upx.exe'. On Linux, this is 'upx'. If yours is called something different,
  158. # change it here. This program has to be in $PATH or it is not used.
  159. #
  160. UPX="upx"
  161. #
  162. # Do source package.
  163. #
  164. ################################################################################
  165. echo "Generating source package for $TARGET.."
  166. #
  167. # dist cannot safely exist prior to starting.
  168. #
  169. if [ -d dist ]; then
  170. echo "Destroying dist/.."
  171. rm -rf dist
  172. fi
  173. mkdir -p dist/$TARGET/src &&
  174. cp -pv $BINARY_DEPS $BUILD_DEPS dist/$TARGET &&
  175. cp -pvr $SUBDIRS dist/$TARGET &&
  176. cp -pvr $SRC dist/$TARGET/src &&
  177. # hack for gdm2s3m & libmodplug & misc
  178. rm -f dist/$TARGET/contrib/gdm2s3m/src/{*.a,*.o} &&
  179. rm -f dist/$TARGET/contrib/libmodplug/src/{*.a,*.o} &&
  180. rm -f dist/$TARGET/src/utils/*.o dist/$TARGET/src/utils/txt2hlp{,.exe} &&
  181. rm -f dist/$TARGET/src/utils/txt2hlp.dbg{,.exe} &&
  182. rm -f dist/$TARGET/contrib/icons/*.o &&
  183. # hack for "dist" makefile
  184. cp dist/$TARGET/arch/Makefile.dist dist/$TARGET/Makefile.platform
  185. if [ "$?" != "0" ]; then
  186. breakout 2
  187. fi
  188. rm -f dist/$TARGET/src/config.h
  189. echo "Creating source (${TARGET}src.tar.bz2).."
  190. cd dist
  191. tar --exclude .svn -jcvf ${TARGET}src.tar.bz2 $TARGET
  192. cd ..
  193. if [ "$?" != "0" ]; then
  194. breakout 3
  195. fi
  196. rm -rf dist/$TARGET
  197. echo Built source distribution successfully!
  198. #
  199. # no binary package is required
  200. #
  201. if [ "$1" != "-b" ]; then
  202. echo "Skipping binary package build."
  203. exit 0
  204. fi
  205. #
  206. # Do binary package.
  207. #
  208. ################################################################################
  209. echo "Generating binary package for $2.."
  210. #
  211. # PSP, using ZIP compression via 7ZIP compressor (add pad config)
  212. #
  213. if [ "$2" = "psp" ]; then
  214. createpspzip
  215. exit
  216. fi
  217. #
  218. # Windows, using ZIP compression via 7ZIP compressor
  219. #
  220. if [ "$2" = "win32" ]; then
  221. LIBSDL="`sdl-config --prefix`/bin/SDL.dll"
  222. createzip_dynamic_sdl $LIBSDL x86
  223. exit
  224. fi
  225. #
  226. # Windows x64, using ZIP compression via 7ZIP compressor
  227. #
  228. if [ "$2" = "win64" ]; then
  229. createzip_static_sdl x64
  230. exit
  231. fi
  232. #
  233. # Unknown binary arch
  234. #
  235. echo "Unknown binary architecture.."
  236. echo
  237. usage