2011-04-20 12:14:44 +00:00
#!/bin/bash
2014-10-26 09:48:57 +00:00
# Building the installer is only tested and supported on 10.9+ with Xcode 6.0.1
2015-10-07 15:55:53 +00:00
# Built package targets 10.10
2013-10-24 08:48:26 +00:00
# Building should also work on older versions with older revisions or slight changes, YMMV
2013-02-20 12:08:29 +00:00
2014-10-26 09:48:57 +00:00
# You need to have the following from homebrew or macports or fink:
# autoconf automake libtool pkg-config
2011-04-20 12:14:44 +00:00
set -ex
test -x ./configure || ./bootstrap
BUILDPATH=${PWD}
2013-03-30 09:13:26 +00:00
2014-10-26 09:48:57 +00:00
# Locate the latest OSX SDK
2014-10-25 17:07:36 +00:00
SDKS_PATH="$(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs"
SDK_PATH="${SDK_PATH:-$SDKS_PATH/$(ls -1 ${SDKS_PATH} | sort -n -k2 -t. -r | head -1)}"
# Set SDK path
2016-05-18 14:09:14 +00:00
export CFLAGS="$CFLAGS -isysroot $SDK_PATH -arch x86_64 -mmacosx-version-min=10.10"
2013-03-30 09:13:26 +00:00
2011-04-20 12:14:44 +00:00
export SED=/usr/bin/sed
PREFIX=/Library/OpenSC
2016-06-03 23:36:14 +00:00
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib/pkgconfig
2011-04-20 12:14:44 +00:00
2016-05-18 14:10:00 +00:00
if ! pkg-config libcrypto --atleast-version=1.0.1; then
# OpenSSL is not installed
if ! test -e $BUILDPATH/openssl_bin/lib/pkgconfig; then
# Build OpenSSL manually, because Apple's binaries are deprecated
if ! test -e openssl; then
git clone --depth=1 https://github.com/openssl/openssl.git -b OpenSSL_1_0_2-stable
fi
cd openssl
KERNEL_BITS=64 ./config --prefix=$PREFIX -mmacosx-version-min=10.10
make clean update depend
make
make INSTALL_PREFIX=$BUILDPATH/openssl_bin install_sw
cd ..
fi
export OPENSSL_CFLAGS="`env PKG_CONFIG_PATH=$BUILDPATH/openssl_bin/$PREFIX/lib/pkgconfig PKG_CONFIG_SYSROOT_DIR=$BUILDPATH/openssl_bin pkg-config --static --cflags libcrypto`"
export OPENSSL_LIBS="` env PKG_CONFIG_PATH=$BUILDPATH/openssl_bin/$PREFIX/lib/pkgconfig PKG_CONFIG_SYSROOT_DIR=$BUILDPATH/openssl_bin pkg-config --static --libs libcrypto`"
fi
2011-04-20 12:14:44 +00:00
./configure --prefix=$PREFIX \
--sysconfdir=$PREFIX/etc \
--disable-dependency-tracking \
--enable-shared \
--disable-static \
--enable-strict \
2013-03-30 09:13:26 +00:00
--disable-assert \
2014-01-04 16:30:09 +00:00
--enable-sm # TODO: remove this (must be sensible default in master)
2011-04-20 12:14:44 +00:00
2013-02-20 12:08:29 +00:00
# always make clean
make clean
2011-04-20 12:14:44 +00:00
# compile
make -j 2
# copy files
rm -rf target
make install DESTDIR=${BUILDPATH}/target
# remove garbage
2015-10-13 13:05:28 +00:00
rm -f target/$PREFIX/lib/*.la
2011-04-20 12:14:44 +00:00
# generate .bundle (required by Adobe Acrobat)
2015-10-13 13:05:28 +00:00
./MacOSX/libtool-bundle target/$PREFIX/lib/opensc-pkcs11.so target/$PREFIX/lib
2011-04-20 12:14:44 +00:00
2013-02-20 12:08:29 +00:00
# Check out OpenSC.tokend, if not already fetched.
2011-04-20 12:14:44 +00:00
if ! test -e OpenSC.tokend; then
2013-02-20 12:08:29 +00:00
git clone http://github.com/OpenSC/OpenSC.tokend.git
2011-04-20 12:14:44 +00:00
fi
# Create the symlink to OpenSC sources
test -L OpenSC.tokend/build/opensc-src || ln -sf ${BUILDPATH}/src OpenSC.tokend/build/opensc-src
2013-12-18 09:48:02 +00:00
# Build and copy OpenSC.tokend
2015-07-02 13:17:51 +00:00
xcodebuild -target OpenSC -configuration Deployment -project OpenSC.tokend/Tokend.xcodeproj install DSTROOT=${PWD}/target
2013-12-18 09:48:02 +00:00
# Prepare target root
2011-04-20 12:14:44 +00:00
# The "UnInstaller"
mkdir -p target/usr/local/bin
cp MacOSX/opensc-uninstall target/usr/local/bin
2013-12-18 09:48:02 +00:00
# Build package
pkgbuild --root target --scripts MacOSX/scripts --identifier org.opensc-project.mac --version @PACKAGE_VERSION@ --install-location / OpenSC.pkg
# Build product
productbuild --distribution MacOSX/Distribution.xml --package-path . --resources MacOSX/resources OpenSC-@PACKAGE_VERSION@.pkg
2011-04-20 12:14:44 +00:00
2014-01-04 16:30:09 +00:00
# Build "uninstaller"
pkgbuild --nopayload --identifier org.opensc-project.mac.uninstall --scripts MacOSX/uninstaller-scripts Uninstall_OpenSC.pkg
2011-04-20 12:14:44 +00:00
# Create .dmg
2013-02-20 12:08:29 +00:00
rm -f OpenSC-@PACKAGE_VERSION@.dmg
2011-04-20 12:14:44 +00:00
TIMESTAMP=$(date +%Y.%m.%d)
2015-09-03 03:41:20 +00:00
i=0
2015-10-14 12:03:51 +00:00
while ! hdiutil create -srcfolder Uninstall_OpenSC.pkg -srcfolder OpenSC-@PACKAGE_VERSION@.pkg -volname "OpenSC @PACKAGE_VERSION@ for Mac OS X 10.10+ (${TIMESTAMP})" OpenSC-@PACKAGE_VERSION@.dmg
2015-09-03 03:41:20 +00:00
do
i=$[$i+1]
if [ $i -gt 2 ]
then
exit 1
fi
done