makemacpkg.in 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. #!/bin/sh
  2. set -u
  3. set -e
  4. trap onexit INT
  5. trap onexit TERM
  6. trap onexit EXIT
  7. TMPDIR=
  8. onexit()
  9. {
  10. if [ ! "$TMPDIR" = "" ]; then
  11. rm -rf $TMPDIR
  12. fi
  13. }
  14. safedirmove ()
  15. {
  16. if [ "$1" = "$2" ]; then
  17. return 0
  18. fi
  19. if [ "$1" = "" -o ! -d "$1" ]; then
  20. echo safedirmove: source dir $1 is not valid
  21. return 1
  22. fi
  23. if [ "$2" = "" -o -e "$2" ]; then
  24. echo safedirmove: dest dir $2 is not valid
  25. return 1
  26. fi
  27. if [ "$3" = "" -o -e "$3" ]; then
  28. echo safedirmove: tmp dir $3 is not valid
  29. return 1
  30. fi
  31. mkdir -p $3
  32. mv $1/* $3/
  33. rmdir $1
  34. mkdir -p $2
  35. mv $3/* $2/
  36. rmdir $3
  37. return 0
  38. }
  39. usage()
  40. {
  41. echo "$0 [universal] [-lipo [path to lipo]]"
  42. exit 1
  43. }
  44. UNIVERSAL=0
  45. PKGNAME=@PKGNAME@
  46. VERSION=@VERSION@
  47. BUILD=@BUILD@
  48. SRCDIR=@CMAKE_CURRENT_SOURCE_DIR@
  49. BUILDDIR32=@OSX_32BIT_BUILD@
  50. BUILDDIRARMV7=@IOS_ARMV7_BUILD@
  51. BUILDDIRARMV7S=@IOS_ARMV7S_BUILD@
  52. BUILDDIRARMV8=@IOS_ARMV8_BUILD@
  53. WITH_JAVA=@WITH_JAVA@
  54. OSX_APP_CERT_NAME="@OSX_APP_CERT_NAME@"
  55. OSX_INST_CERT_NAME="@OSX_INST_CERT_NAME@"
  56. LIPO=lipo
  57. PREFIX=@CMAKE_INSTALL_PREFIX@
  58. BINDIR=@CMAKE_INSTALL_FULL_BINDIR@
  59. DOCDIR=@CMAKE_INSTALL_FULL_DOCDIR@
  60. LIBDIR=@CMAKE_INSTALL_FULL_LIBDIR@
  61. LIBJPEG_DSO_NAME=libjpeg.@SO_MAJOR_VERSION@.@SO_AGE@.@SO_MINOR_VERSION@.dylib
  62. TURBOJPEG_DSO_NAME=libturbojpeg.@TURBOJPEG_SO_VERSION@.dylib
  63. while [ $# -gt 0 ]; do
  64. case $1 in
  65. -h*)
  66. usage 0
  67. ;;
  68. -lipo)
  69. if [ $# -gt 1 ]; then
  70. if [[ ! "$2" =~ -.* ]]; then
  71. LIPO=$2; shift
  72. fi
  73. fi
  74. ;;
  75. universal)
  76. UNIVERSAL=1
  77. ;;
  78. esac
  79. shift
  80. done
  81. if [ -f $PKGNAME-$VERSION.dmg ]; then
  82. rm -f $PKGNAME-$VERSION.dmg
  83. fi
  84. umask 022
  85. TMPDIR=`mktemp -d /tmp/$PKGNAME-build.XXXXXX`
  86. PKGROOT=$TMPDIR/pkg/Package_Root
  87. mkdir -p $PKGROOT
  88. make install DESTDIR=$PKGROOT
  89. if [ "$PREFIX" = "@CMAKE_INSTALL_DEFAULT_PREFIX@" -a "$DOCDIR" = "@CMAKE_INSTALL_DEFAULT_PREFIX@/doc" ]; then
  90. mkdir -p $PKGROOT/Library/Documentation
  91. safedirmove $PKGROOT$DOCDIR $PKGROOT/Library/Documentation/$PKGNAME $TMPDIR/__tmpdoc
  92. ln -fs /Library/Documentation/$PKGNAME $PKGROOT$DOCDIR
  93. fi
  94. if [ $UNIVERSAL = 1 -a "$BUILDDIR32" != "" ]; then
  95. if [ ! -d $BUILDDIR32 ]; then
  96. echo ERROR: 32-bit build directory $BUILDDIR32 does not exist
  97. exit 1
  98. fi
  99. if [ ! -f $BUILDDIR32/Makefile ]; then
  100. echo ERROR: 32-bit build directory $BUILDDIR32 is not configured
  101. exit 1
  102. fi
  103. mkdir -p $TMPDIR/dist.x86
  104. pushd $BUILDDIR32
  105. make install DESTDIR=$TMPDIR/dist.x86
  106. popd
  107. $LIPO -create \
  108. -arch i386 $TMPDIR/dist.x86/$LIBDIR/$LIBJPEG_DSO_NAME \
  109. -arch x86_64 $PKGROOT/$LIBDIR/$LIBJPEG_DSO_NAME \
  110. -output $PKGROOT/$LIBDIR/$LIBJPEG_DSO_NAME
  111. $LIPO -create \
  112. -arch i386 $TMPDIR/dist.x86/$LIBDIR/libjpeg.a \
  113. -arch x86_64 $PKGROOT/$LIBDIR/libjpeg.a \
  114. -output $PKGROOT/$LIBDIR/libjpeg.a
  115. $LIPO -create \
  116. -arch i386 $TMPDIR/dist.x86/$LIBDIR/$TURBOJPEG_DSO_NAME \
  117. -arch x86_64 $PKGROOT/$LIBDIR/$TURBOJPEG_DSO_NAME \
  118. -output $PKGROOT/$LIBDIR/$TURBOJPEG_DSO_NAME
  119. $LIPO -create \
  120. -arch i386 $TMPDIR/dist.x86/$LIBDIR/libturbojpeg.a \
  121. -arch x86_64 $PKGROOT/$LIBDIR/libturbojpeg.a \
  122. -output $PKGROOT/$LIBDIR/libturbojpeg.a
  123. $LIPO -create \
  124. -arch i386 $TMPDIR/dist.x86/$BINDIR/cjpeg \
  125. -arch x86_64 $PKGROOT/$BINDIR/cjpeg \
  126. -output $PKGROOT/$BINDIR/cjpeg
  127. $LIPO -create \
  128. -arch i386 $TMPDIR/dist.x86/$BINDIR/djpeg \
  129. -arch x86_64 $PKGROOT/$BINDIR/djpeg \
  130. -output $PKGROOT/$BINDIR/djpeg
  131. $LIPO -create \
  132. -arch i386 $TMPDIR/dist.x86/$BINDIR/jpegtran \
  133. -arch x86_64 $PKGROOT/$BINDIR/jpegtran \
  134. -output $PKGROOT/$BINDIR/jpegtran
  135. $LIPO -create \
  136. -arch i386 $TMPDIR/dist.x86/$BINDIR/tjbench \
  137. -arch x86_64 $PKGROOT/$BINDIR/tjbench \
  138. -output $PKGROOT/$BINDIR/tjbench
  139. $LIPO -create \
  140. -arch i386 $TMPDIR/dist.x86/$BINDIR/rdjpgcom \
  141. -arch x86_64 $PKGROOT/$BINDIR/rdjpgcom \
  142. -output $PKGROOT/$BINDIR/rdjpgcom
  143. $LIPO -create \
  144. -arch i386 $TMPDIR/dist.x86/$BINDIR/wrjpgcom \
  145. -arch x86_64 $PKGROOT/$BINDIR/wrjpgcom \
  146. -output $PKGROOT/$BINDIR/wrjpgcom
  147. fi
  148. install_ios()
  149. {
  150. BUILDDIR=$1
  151. ARCHNAME=$2
  152. DIRNAME=$3
  153. LIPOARCH=$4
  154. if [ ! -d $BUILDDIR ]; then
  155. echo ERROR: $ARCHNAME build directory $BUILDDIR does not exist
  156. exit 1
  157. fi
  158. if [ ! -f $BUILDDIR/Makefile ]; then
  159. echo ERROR: $ARCHNAME build directory $BUILDDIR is not configured
  160. exit 1
  161. fi
  162. mkdir -p $TMPDIR/dist.$DIRNAME
  163. pushd $BUILDDIR
  164. make install DESTDIR=$TMPDIR/dist.$DIRNAME
  165. popd
  166. $LIPO -create \
  167. $PKGROOT/$LIBDIR/$LIBJPEG_DSO_NAME \
  168. -arch $LIPOARCH $TMPDIR/dist.$DIRNAME/$LIBDIR/$LIBJPEG_DSO_NAME \
  169. -output $PKGROOT/$LIBDIR/$LIBJPEG_DSO_NAME
  170. $LIPO -create \
  171. $PKGROOT/$LIBDIR/libjpeg.a \
  172. -arch $LIPOARCH $TMPDIR/dist.$DIRNAME/$LIBDIR/libjpeg.a \
  173. -output $PKGROOT/$LIBDIR/libjpeg.a
  174. $LIPO -create \
  175. $PKGROOT/$LIBDIR/$TURBOJPEG_DSO_NAME \
  176. -arch $LIPOARCH $TMPDIR/dist.$DIRNAME/$LIBDIR/$TURBOJPEG_DSO_NAME \
  177. -output $PKGROOT/$LIBDIR/$TURBOJPEG_DSO_NAME
  178. $LIPO -create \
  179. $PKGROOT/$LIBDIR/libturbojpeg.a \
  180. -arch $LIPOARCH $TMPDIR/dist.$DIRNAME/$LIBDIR/libturbojpeg.a \
  181. -output $PKGROOT/$LIBDIR/libturbojpeg.a
  182. $LIPO -create \
  183. $PKGROOT/$BINDIR/cjpeg \
  184. -arch $LIPOARCH $TMPDIR/dist.$DIRNAME/$BINDIR/cjpeg \
  185. -output $PKGROOT/$BINDIR/cjpeg
  186. $LIPO -create \
  187. $PKGROOT/$BINDIR/djpeg \
  188. -arch $LIPOARCH $TMPDIR/dist.$DIRNAME/$BINDIR/djpeg \
  189. -output $PKGROOT/$BINDIR/djpeg
  190. $LIPO -create \
  191. $PKGROOT/$BINDIR/jpegtran \
  192. -arch $LIPOARCH $TMPDIR/dist.$DIRNAME/$BINDIR/jpegtran \
  193. -output $PKGROOT/$BINDIR/jpegtran
  194. $LIPO -create \
  195. $PKGROOT/$BINDIR/tjbench \
  196. -arch $LIPOARCH $TMPDIR/dist.$DIRNAME/$BINDIR/tjbench \
  197. -output $PKGROOT/$BINDIR/tjbench
  198. $LIPO -create \
  199. $PKGROOT/$BINDIR/rdjpgcom \
  200. -arch $LIPOARCH $TMPDIR/dist.$DIRNAME/$BINDIR/rdjpgcom \
  201. -output $PKGROOT/$BINDIR/rdjpgcom
  202. $LIPO -create \
  203. $PKGROOT/$BINDIR/wrjpgcom \
  204. -arch $LIPOARCH $TMPDIR/dist.$DIRNAME/$BINDIR/wrjpgcom \
  205. -output $PKGROOT/$BINDIR/wrjpgcom
  206. }
  207. if [ $UNIVERSAL = 1 -a "$BUILDDIRARMV7" != "" ]; then
  208. install_ios $BUILDDIRARMV7 ARMv7 armv7 arm
  209. fi
  210. if [ $UNIVERSAL = 1 -a "$BUILDDIRARMV7S" != "" ]; then
  211. install_ios $BUILDDIRARMV7S ARMv7s armv7s arm
  212. fi
  213. if [ $UNIVERSAL = 1 -a "$BUILDDIRARMV8" != "" ]; then
  214. install_ios $BUILDDIRARMV8 ARMv8 armv8 arm64
  215. fi
  216. install_name_tool -id $LIBDIR/$LIBJPEG_DSO_NAME $PKGROOT/$LIBDIR/$LIBJPEG_DSO_NAME
  217. install_name_tool -id $LIBDIR/$TURBOJPEG_DSO_NAME $PKGROOT/$LIBDIR/$TURBOJPEG_DSO_NAME
  218. if [ $WITH_JAVA = 1 ]; then
  219. ln -fs $TURBOJPEG_DSO_NAME $PKGROOT/$LIBDIR/libturbojpeg.jnilib
  220. fi
  221. if [ "$PREFIX" = "@CMAKE_INSTALL_DEFAULT_PREFIX@" -a "$LIBDIR" = "@CMAKE_INSTALL_DEFAULT_PREFIX@/lib" ]; then
  222. if [ ! -h $PKGROOT/$PREFIX/lib32 ]; then
  223. ln -fs lib $PKGROOT/$PREFIX/lib32
  224. fi
  225. if [ ! -h $PKGROOT/$PREFIX/lib64 ]; then
  226. ln -fs lib $PKGROOT/$PREFIX/lib64
  227. fi
  228. fi
  229. mkdir -p $TMPDIR/pkg
  230. install -m 755 pkgscripts/uninstall $PKGROOT/$BINDIR/
  231. find $PKGROOT -type f | while read file; do xattr -c $file; done
  232. cp $SRCDIR/release/License.rtf $SRCDIR/release/Welcome.rtf $SRCDIR/release/ReadMe.txt $TMPDIR/pkg/
  233. mkdir $TMPDIR/dmg
  234. pkgbuild --root $PKGROOT --version $VERSION.$BUILD --identifier @PKGID@ \
  235. $TMPDIR/pkg/$PKGNAME.pkg
  236. SUFFIX=
  237. if [ "$OSX_INST_CERT_NAME" != "" ]; then
  238. SUFFIX=-unsigned
  239. fi
  240. productbuild --distribution pkgscripts/Distribution.xml \
  241. --package-path $TMPDIR/pkg/ --resources $TMPDIR/pkg/ \
  242. $TMPDIR/dmg/$PKGNAME$SUFFIX.pkg
  243. if [ "$OSX_INST_CERT_NAME" != "" ]; then
  244. productsign --sign "$OSX_INST_CERT_NAME" --timestamp \
  245. $TMPDIR/dmg/$PKGNAME$SUFFIX.pkg $TMPDIR/dmg/$PKGNAME.pkg
  246. rm -r $TMPDIR/dmg/$PKGNAME$SUFFIX.pkg
  247. pkgutil --check-signature $TMPDIR/dmg/$PKGNAME.pkg
  248. fi
  249. hdiutil create -fs HFS+ -volname $PKGNAME-$VERSION \
  250. -srcfolder "$TMPDIR/dmg" $TMPDIR/$PKGNAME-$VERSION.dmg
  251. if [ "$OSX_APP_CERT_NAME" != "" ]; then
  252. codesign -s "$OSX_APP_CERT_NAME" --timestamp $TMPDIR/$PKGNAME-$VERSION.dmg
  253. codesign -vv $TMPDIR/$PKGNAME-$VERSION.dmg
  254. fi
  255. cp $TMPDIR/$PKGNAME-$VERSION.dmg .
  256. exit