|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
#!/bin/bash
|
|
|
|
|
# Script to generate mac application bundles for KOReader
|
|
|
|
|
COPYRIGHT="Copyright © $(date +"%Y") KOReader"
|
|
|
|
|
|
|
|
|
|
command_exists() {
|
|
|
|
|
type "$1" >/dev/null 2>/dev/null
|
|
|
|
@ -9,88 +10,139 @@ if [ -z "${1}" ]; then
|
|
|
|
|
echo "${0}: can't find KOReader build, please specify a path"
|
|
|
|
|
exit 1
|
|
|
|
|
else
|
|
|
|
|
INSTALL_DIR="${1}"
|
|
|
|
|
VERSION="$(cut -f2 -dv "${1}/koreader/git-rev" | cut -f1,2 -d-)"
|
|
|
|
|
APP_PATH="${1}/bundle"
|
|
|
|
|
APP_BUNDLE="${1}/../KOReader"
|
|
|
|
|
OSX_MAJOR=$(sw_vers -productVersion | cut -d "." -f1)
|
|
|
|
|
OSX_MINOR=$(sw_vers -productVersion | cut -d "." -f2)
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
cat <<EOF >"${INSTALL_DIR}/bundle/Contents/Info.plist"
|
|
|
|
|
# minimum deployment target based on host version
|
|
|
|
|
if [ -z "${MACOSX_DEPLOYMENT_TARGET}" ]; then
|
|
|
|
|
if [ "${OSX_MAJOR}" == 11 ]; then
|
|
|
|
|
MACOSX_DEPLOYMENT_TARGET=10.14
|
|
|
|
|
elif [ "${OSX_MAJOR}" == 10 ]; then
|
|
|
|
|
MACOSX_DEPLOYMENT_TARGET="10.$((OSX_MINOR - 2))"
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Generate PkgInfo and Info.plist
|
|
|
|
|
printf "APPL????" >"${APP_PATH}/Contents/PkgInfo"
|
|
|
|
|
cat <<END >"${APP_PATH}/Contents/Info.plist"
|
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
|
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
|
|
|
<plist version="1.0">
|
|
|
|
|
<dict>
|
|
|
|
|
<key>CFBundleGetInfoString</key>
|
|
|
|
|
<key>CFBundleDevelopmentRegion</key>
|
|
|
|
|
<string>English</string>
|
|
|
|
|
<key>CFBundleName</key>
|
|
|
|
|
<string>KOReader</string>
|
|
|
|
|
<key>CFBundleDisplayName</key>
|
|
|
|
|
<string>KOReader</string>
|
|
|
|
|
<key>CFBundleExecutable</key>
|
|
|
|
|
<string>koreader</string>
|
|
|
|
|
<key>CFBundleIconFile</key>
|
|
|
|
|
<string>icon.icns</string>
|
|
|
|
|
<key>CFBundleIdentifier</key>
|
|
|
|
|
<string>koreader.rocks</string>
|
|
|
|
|
<key>CFBundleName</key>
|
|
|
|
|
<string>KOReader</string>
|
|
|
|
|
<string>rocks.koreader</string>
|
|
|
|
|
<key>CFBundleShortVersionString</key>
|
|
|
|
|
<string>${VERSION}</string>
|
|
|
|
|
<key>CFBundleInfoDictionaryVersion</key>
|
|
|
|
|
<string>6.0</string>
|
|
|
|
|
<key>CFBundlePackageType</key>
|
|
|
|
|
<string>APPL</string>
|
|
|
|
|
<key>CFBundleIconFile</key>
|
|
|
|
|
<string>icon</string>
|
|
|
|
|
<key>CFBundleSignature</key>
|
|
|
|
|
<string>????</string>
|
|
|
|
|
<key>CFBundleVersion</key>
|
|
|
|
|
<string>1.0</string>
|
|
|
|
|
<key>CFBundleDocumentTypes</key>
|
|
|
|
|
<array>
|
|
|
|
|
<dict>
|
|
|
|
|
<key>CFBundleTypeExtensions</key>
|
|
|
|
|
<array>
|
|
|
|
|
<string>azw</string>
|
|
|
|
|
<string>cbz</string>
|
|
|
|
|
<string>chm</string>
|
|
|
|
|
<string>djv</string>
|
|
|
|
|
<string>djvu</string>
|
|
|
|
|
<string>doc</string>
|
|
|
|
|
<string>docx</string>
|
|
|
|
|
<string>epub</string>
|
|
|
|
|
<string>fb2</string>
|
|
|
|
|
<string>htm</string>
|
|
|
|
|
<string>html</string>
|
|
|
|
|
<string>md</string>
|
|
|
|
|
<string>mobi</string>
|
|
|
|
|
<string>pdb</string>
|
|
|
|
|
<string>pdf</string>
|
|
|
|
|
<string>prc</string>
|
|
|
|
|
<string>rtf</string>
|
|
|
|
|
<string>txt</string>
|
|
|
|
|
<string>xhtml</string>
|
|
|
|
|
<string>xps</string>
|
|
|
|
|
</array>
|
|
|
|
|
<key>CFBundleTypeIconFile</key>
|
|
|
|
|
<string>icon</string>
|
|
|
|
|
<key>CFBundleTypeName</key>
|
|
|
|
|
<string>docs</string>
|
|
|
|
|
<key>CFBundleTypeRole</key>
|
|
|
|
|
<string>Viewer</string>
|
|
|
|
|
</dict>
|
|
|
|
|
</array>
|
|
|
|
|
<key>NSHumanReadableCopyright</key>
|
|
|
|
|
<string>${COPYRIGHT}</string>
|
|
|
|
|
<key>NSHighResolutionCapable</key>
|
|
|
|
|
<true/>
|
|
|
|
|
<key>NSPrincipalClass</key>
|
|
|
|
|
<string>NSApplication</string>
|
|
|
|
|
<key>LSMultipleInstancesProhibited</key>
|
|
|
|
|
<true/>
|
|
|
|
|
<key>LSMinimumSystemVersion</key>
|
|
|
|
|
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
|
|
|
|
</dict>
|
|
|
|
|
</plist>
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
|
|
APP_PATH="${INSTALL_DIR}/bundle"
|
|
|
|
|
APP_BUNDLE="${INSTALL_DIR}/../KOReader"
|
|
|
|
|
END
|
|
|
|
|
|
|
|
|
|
# Use otool to change rpath of libraries.
|
|
|
|
|
# Along with libs, serialize.so in common also needs to be fixed
|
|
|
|
|
pushd "${INSTALL_DIR}/bundle/Contents/Resources/koreader" || exit 1
|
|
|
|
|
for directory in common libs; do
|
|
|
|
|
directoryName=$(basename "${directory}")
|
|
|
|
|
echo "Checking ${directory}"
|
|
|
|
|
pushd "${directory}" || exit 1
|
|
|
|
|
for libToCheck in *.so *.dylib; do
|
|
|
|
|
# there may be more than one library to fix, so get all of them and iterate
|
|
|
|
|
libsToChange=$(otool -L "${libToCheck}" | grep "Users.*x86_64" | tr -s " " | cut -f1 -d" ")
|
|
|
|
|
if [ -z "${libsToChange}" ]; then
|
|
|
|
|
echo "Nothing to do, skipping ${libToCheck}"
|
|
|
|
|
else
|
|
|
|
|
for libToChange in ${libsToChange}; do
|
|
|
|
|
fileNameOfLibToChange=$(basename "${libToChange}")
|
|
|
|
|
if [ "${libToCheck}" = "${fileNameOfLibToChange}" ]; then
|
|
|
|
|
echo "Skipping recursive ${libToChange} ${libToCheck}"
|
|
|
|
|
else
|
|
|
|
|
echo "Fixing ${libToCheck} ${libToChange}"
|
|
|
|
|
install_name_tool -change "${libToChange}" "${directoryName}/${fileNameOfLibToChange}" "${libToCheck}"
|
|
|
|
|
# freeze shared libraries, so they can be loaded within the application bundle
|
|
|
|
|
pushd "${APP_PATH}/Contents/koreader" || exit 1
|
|
|
|
|
for dir in common libs; do
|
|
|
|
|
path=$(basename "${dir}")
|
|
|
|
|
pushd "${dir}" || exit 1
|
|
|
|
|
for library in *.so *.dylib; do
|
|
|
|
|
install_name_tool -id "${library}" "$(basename "${library}")"
|
|
|
|
|
# there may be more than one dependency to fix, so get all of them and iterate
|
|
|
|
|
dependencies=$(otool -L "${library}" | grep "Users.*x86_64" | tr -s " " | cut -f1 -d" ")
|
|
|
|
|
if [ -n "${dependencies}" ]; then
|
|
|
|
|
for dependency in ${dependencies}; do
|
|
|
|
|
filename=$(basename "${dependency}")
|
|
|
|
|
if [ ! "${library}" = "${filename}" ]; then
|
|
|
|
|
install_name_tool -change "${dependency}" "${path}/${filename}" "${library}"
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
done
|
|
|
|
|
popd || exit 1
|
|
|
|
|
done
|
|
|
|
|
popd || exit 1
|
|
|
|
|
|
|
|
|
|
# remove things from the bundle
|
|
|
|
|
rm -rf \
|
|
|
|
|
"${APP_PATH}/Contents/Resources/koreader/cache" \
|
|
|
|
|
"${APP_PATH}/Contents/Resources/koreader/clipboard" \
|
|
|
|
|
"${APP_PATH}/Contents/Resources/koreader/history" \
|
|
|
|
|
"${APP_PATH}/Contents/Resources/koreader/ota" \
|
|
|
|
|
"${APP_PATH}/Contents/Resources/koreader/resources/fonts" \
|
|
|
|
|
"${APP_PATH}/Contents/Resources/koreader/resources/icons/src" \
|
|
|
|
|
"${APP_PATH}/Contents/Resources/koreader/resources/kobo-touch.probe.png" \
|
|
|
|
|
"${APP_PATH}/Contents/Resources/koreader/resources/koreader.icns" \
|
|
|
|
|
"${APP_PATH}/Contents/Resources/koreader/rocks/bin" \
|
|
|
|
|
"${APP_PATH}/Contents/Resources/koreader/rocks/lib/luarocks" \
|
|
|
|
|
"${APP_PATH}/Contents/Resources/koreader/screenshots" \
|
|
|
|
|
"${APP_PATH}/Contents/Resources/koreader/spec" \
|
|
|
|
|
"${APP_PATH}/Contents/Resources/koreader/tools" \
|
|
|
|
|
"${APP_PATH}/Contents/Resources/koreader/README.md"
|
|
|
|
|
|
|
|
|
|
mv \
|
|
|
|
|
"${APP_PATH}/Contents/Resources/koreader/COPYING" \
|
|
|
|
|
"${APP_PATH}/Contents/Resources/COPYING"
|
|
|
|
|
BREW=/usr/local/opt
|
|
|
|
|
cp "${BREW}/gettext/lib/libintl.8.dylib" "${BREW}/webp/lib/libwebp.7.dylib" libs
|
|
|
|
|
chmod 777 libs/libintl.8.dylib libs/libwebp.7.dylib
|
|
|
|
|
install_name_tool -id libintl.8.dylib libs/libintl.8.dylib
|
|
|
|
|
install_name_tool -id libwebp.7.dylib libs/libwebp.7.dylib
|
|
|
|
|
install_name_tool -change ${BREW}/gettext/lib/libintl.8.dylib libs/libintl.8.dylib libs/libglib-2.0.dylib
|
|
|
|
|
install_name_tool -change ${BREW}/webp/lib/libwebp.7.dylib libs/libwebp.7.dylib libs/liblept.5.dylib
|
|
|
|
|
install_name_tool -change ${BREW}/webp/lib/libwebp.7.dylib libs/libwebp.7.dylib libs/libtesseract.3.dylib
|
|
|
|
|
|
|
|
|
|
ln -s /usr/bin/tar "${APP_PATH}/Contents/Resources/koreader/tar"
|
|
|
|
|
# prepare bundle for distribution
|
|
|
|
|
ln -s /usr/bin/tar tar
|
|
|
|
|
mv COPYING ../COPYING.txt
|
|
|
|
|
rm -rf cache clipboard history ota \
|
|
|
|
|
l10n/.git l10n/.tx l10n/templates l10n/LICENSE l10n/Makefile l10n/README.md \
|
|
|
|
|
plugins/SSH.koplugin plugins/hello.koplugin plugins/timesync.koplugin \
|
|
|
|
|
plugins/autofrontlight.koplugin resources/fonts resources/icons/src \
|
|
|
|
|
resources/kobo-touch-probe.png resources/koreader.icns rocks/bin \
|
|
|
|
|
rocks/lib/luarocks screenshots spec tools README.md
|
|
|
|
|
popd || exit 1
|
|
|
|
|
|
|
|
|
|
# package as DMG if create-dmg is available
|
|
|
|
|
# reduces size from 80MB to 40MB
|
|
|
|
@ -98,8 +150,7 @@ mv "${APP_PATH}" "${APP_BUNDLE}.app"
|
|
|
|
|
if command_exists "create-dmg"; then
|
|
|
|
|
# create KOReader-$VERSION.dmg with KOReader.app inside
|
|
|
|
|
create-dmg "${APP_BUNDLE}.app" --overwrite
|
|
|
|
|
# create-dmg fails because we omit codesign
|
|
|
|
|
exit 0
|
|
|
|
|
rm -rf "${APP_BUNDLE}.app"
|
|
|
|
|
else
|
|
|
|
|
# rename as KOReader-$VERSION.app
|
|
|
|
|
mv -v "${APP_BUNDLE}.app" "${APP_BUNDLE}-${VERSION}.app"
|
|
|
|
|