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