-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathqpdfview.sh
executable file
·203 lines (174 loc) · 7.06 KB
/
qpdfview.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#!/bin/bash
SELF_DIR=$(dirname "$0")
pushd "$SELF_DIR" &>/dev/null
SELF_DIR="$(pwd)"
popd &>/dev/null
WORK_DIR="$(pwd)"
QPDFVIEW_BDIR="${WORK_DIR}/build"
QPDFVIEW_DIR="${WORK_DIR}/dist"
QPDFVIEW_APP="${QPDFVIEW_BDIR}/qpdfview.app"
QPDFVIEW_REV=2161
if [ "${QPDFVIEW_EDITION}" = "" ]; then
QPDFVIEW_EDITION=1
fi
check_depedencies() {
echo "Checking dependencies..."
for tool in qmake make macdeployqt patch; do
if [ "$(which ${tool})" = "" ]; then
echo "${tool} is missing"
exit 1
fi
done
}
obtain_sources() {
echo "Obtaining sources..."
if [ -d "${QPDFVIEW_DIR}" ]; then
echo "Assuming done!"
return
fi
python3 -m breezy branch lp:qpdfview dist -r "${QPDFVIEW_REV}" || exit 1
pushd "${QPDFVIEW_DIR}" &>/dev/null || exit 1
for patch in "${SELF_DIR}/patches"/*.diff; do
echo "Applying ${patch}"
patch -p0 < "${patch}" || exit 1
done
popd &>/dev/null || exit 1
}
compile_bundle() {
echo "Compiling bundle..."
rm -rf "${QPDFVIEW_APP}" "${QPDFVIEW_BDIR}" || exit 1
mkdir -p "${QPDFVIEW_BDIR}" || exit 1
pushd "${QPDFVIEW_BDIR}" &>/dev/null || exit 1
if [ "$FITZ_PLUGIN_INCLUDEPATH" = "" ]; then
FITZ_PLUGIN_INCLUDEPATH=$(brew --prefix mupdf-tools)/include
fi
if [ "$FITZ_PLUGIN_LINKPATH" = "" ]; then
FITZ_PLUGIN_LINKPATH=$(brew --prefix mupdf-tools)/lib
fi
if [ "$FITZ_PLUGIN_LIBS" = "" ]; then
FITZ_PLUGIN_LIBS="-lmupdf -lmupdf-third -L$(brew --prefix mujs)/lib -lmujs -L$(brew --prefix freetype)/lib -lfreetype -L$(brew --prefix harfbuzz)/lib -lharfbuzz -lz -L$(brew --prefix jpeg)/lib -ljpeg -L$(brew --prefix jbig2dec)/lib -ljbig2dec -L$(brew --prefix openjpeg)/lib -lopenjp2 -L$(brew --prefix lcms2)/lib -llcms2"
fi
qmake APP_DIR_DATA_PATH=../Resources CONFIG+=with_fitz \
FITZ_PLUGIN_INCLUDEPATH=${FITZ_PLUGIN_INCLUDEPATH} \
FITZ_PLUGIN_LIBS="-L${FITZ_PLUGIN_LINKPATH} ${FITZ_PLUGIN_LIBS}" \
"${QPDFVIEW_DIR}/qpdfview.pro" || exit 1
make -j || exit 1
popd &>/dev/null || exit 1
}
bundle_plugins() {
echo "Bundling plugins..."
rm -rf "${QPDFVIEW_APP}/Contents/MacOS"/*.dylib || exit 1
cp "${QPDFVIEW_BDIR}"/*.dylib "${QPDFVIEW_APP}/Contents/MacOS" || exit 1
}
bundle_translations() {
echo "Bundling translation files..."
local tl_dir="${QPDFVIEW_APP}/Contents/Resources"
mkdir -p "${tl_dir}"
for tl in "${QPDFVIEW_DIR}/translations"/*.ts; do
tl_file=$(basename "${tl/.ts/.qm}")
lconvert -i "${tl}" -o "${tl_dir}/${tl_file}" || exit 1
done
}
bundle_help() {
echo "Bundling help data..."
local help_dir="${QPDFVIEW_APP}/Contents/Resources"
cp -r "${QPDFVIEW_DIR}/help"/* "${help_dir}" || exit 1
}
bundle_icon() {
echo "Bundling icon file..."
local infile="${QPDFVIEW_DIR}/icons/qpdfview.svg"
local outfile="${QPDFVIEW_DIR}/icons/qpdfview.icns"
local dest="${outfile}.iconset"
rm -rf "${dest}" "${outfile}" || exit 1
mkdir "${dest}" || exit 1
convert -background none -size '!16x16' "$infile" "$dest/icon_16x16.png" || exit 1
convert -background none -size '!32x32' "$infile" "$dest/[email protected]" || exit 1
cp "$dest/[email protected]" "$dest/icon_32x32.png" || exit 1
convert -background none -size '!64x64' "$infile" "$dest/[email protected]" || exit 1
convert -background none -size '!128x128' "$infile" "$dest/icon_128x128.png" || exit 1
convert -background none -size '!256x256' "$infile" "$dest/[email protected]" || exit 1
cp "$dest/[email protected]" "$dest/icon_256x256.png" || exit 1
convert -background none -size '!512x512' "$infile" "$dest/[email protected]" || exit 1
cp "$dest/[email protected]" "$dest/icon_512x512.png" || exit 1
convert -background none -size '!1024x1024' "$infile" "$dest/[email protected]" || exit 1
iconutil -c icns -o "${outfile}" "${dest}" || exit 1
rm -rf "$dest"
cp "${outfile}" "${QPDFVIEW_APP}/Contents/Resources/qpdfview.icns" || exit 1
/usr/libexec/PlistBuddy -c 'Delete CFBundleIconFile' "${QPDFVIEW_APP}/Contents/Info.plist" &>/dev/null
/usr/libexec/PlistBuddy -c 'Add CFBundleIconFile string qpdfview' "${QPDFVIEW_APP}/Contents/Info.plist" || exit 1
}
bundle_icon_premade() {
echo "Bundling icon file..."
cp "${SELF_DIR}/qpdfview.icns" "${QPDFVIEW_APP}/Contents/Resources/qpdfview.icns" || exit 1
/usr/libexec/PlistBuddy -c 'Delete CFBundleIconFile' "${QPDFVIEW_APP}/Contents/Info.plist" &>/dev/null
/usr/libexec/PlistBuddy -c 'Add CFBundleIconFile string qpdfview' "${QPDFVIEW_APP}/Contents/Info.plist" || exit 1
}
bundle_formats() {
echo "Bundling finder formats..."
/usr/libexec/PlistBuddy -c 'Delete CFBundleDocumentTypes' "${QPDFVIEW_APP}/Contents/Info.plist" &>/dev/null
/usr/libexec/PlistBuddy -c "Merge ${SELF_DIR}/formats.plist" "${QPDFVIEW_APP}/Contents/Info.plist" || exit 1
}
bundle_fonts() {
if [ "$FONTCONFIG_PATH" = "" ]; then
if [ -f "/usr/local/etc/fonts/fonts.conf" ]; then
FONTCONFIG_PATH=/usr/local/etc/fonts
elif [ -f "/opt/local/etc/fonts/fonts.conf" ]; then
FONTCONFIG_PATH=/opt/local/etc/fonts
else
echo "WARN: Unable to find fonts.conf"
echo "Hint: Set FONTCONFIG_PATH variable!"
return
fi
fi
cp -r "$FONTCONFIG_PATH" "${QPDFVIEW_APP}/Contents/Resources/fonts" || exit 1
}
deploy_bundle() {
echo "Deploying bundle..."
/usr/libexec/PlistBuddy -c 'Delete CFBundleIdentifier' "${QPDFVIEW_APP}/Contents/Info.plist" &>/dev/null
/usr/libexec/PlistBuddy -c 'Add CFBundleIdentifier string as.vit9696.qpdfview' "${QPDFVIEW_APP}/Contents/Info.plist" || exit 1
local version=$(cat "${QPDFVIEW_DIR}/qpdfview.pri" | grep APPLICATION_VERSION | sed 's/.*= //')
local revision="r${QPDFVIEW_REV}u${QPDFVIEW_EDITION}"
local full_version="${version}-${revision}"
/usr/libexec/PlistBuddy -c "Add CFBundleVersion string ${full_version}" "${QPDFVIEW_APP}/Contents/Info.plist" || exit 1
/usr/libexec/PlistBuddy -c "Add CFBundleShortVersionString string ${full_version}" "${QPDFVIEW_APP}/Contents/Info.plist" || exit 1
macdeployqt "${QPDFVIEW_APP}" || exit 1
}
archive_bundle() {
echo "Archiving bundle..."
pushd "${QPDFVIEW_BDIR}" &>/dev/null || exit 1
local version=$(cat "${QPDFVIEW_DIR}/qpdfview.pri" | grep APPLICATION_VERSION | sed 's/.*= //')
local revision="r${QPDFVIEW_REV}u${QPDFVIEW_EDITION}"
local full_version="${version}-${revision}"
if [ -x "$DEPLOY_SCRIPT" ]; then
local extension="dmg"
local mime="application/octet-stream"
else
local extension="zip"
local mime="application/zip"
fi
local name="qpdfview-${full_version}-$(uname -m).${extension}"
if [ "$GITHUB_ENV" != "" ]; then
echo "VERSION=${version}" >> "$GITHUB_ENV"
echo "REVISION=${revision}" >> "$GITHUB_ENV"
echo "FILENAME=${name}" >> "$GITHUB_ENV"
echo "CONTENT_TYPE=${mime}" >> "$GITHUB_ENV"
fi
# codesign -s "Apple Developer" --deep qpdfview.app || exit 1
if [ -x "$DEPLOY_SCRIPT" ]; then
"$DEPLOY_SCRIPT" "${QPDFVIEW_BDIR}/qpdfview.app" "${WORK_DIR}/${name}" || exit 1
else
zip -qry ../"${name}" qpdfview.app || exit 1
fi
popd &>/dev/null || exit 1
}
check_depedencies
obtain_sources
compile_bundle
bundle_plugins
bundle_translations
bundle_help
bundle_icon_premade
bundle_formats
bundle_fonts
deploy_bundle
archive_bundle