1#!/bin/sh
2###############################################################################
3# Compile Falkon source and pack it as Appimage.
4###############################################################################
5set -e
6
7SCRIPT_PATH="$(dirname "$(readlink -f "$0")")"
8NCPUS=$(getconf _NPROCESSORS_ONLN)  || :
9
10which mksquashfs >/dev/null 2>&1 || TEST=no
11which chrpath >/dev/null 2>&1 || TEST=no
12TEST=${TEST:-yes}
13
14if [ $(which qmake 2>/dev/null) ]; then
15SYSTEM_QMAKE=$(which qmake)
16elif [ $(which qmake-qt5 2>/dev/null) ]; then
17SYSTEM_QMAKE=$(which qmake-qt5)
18fi
19
20BLD1="\033[1m"
21BLD0="\033[21m"
22ITL1="\033[3m"
23ITL0="\033[23m"
24UDR1="\033[4m"
25UDR0="\033[24m"
26CRS1="\033[9m"
27CRS0="\033[29m"
28RDFG="\033[31m"
29RDBG="\033[41m"
30DFFG="\033[39m"
31DFBG="\033[49m"
32ALL0="\033[00m"
33
34LIBDIRPATH=lib ; export LIBDIRPATH
35SOURCE_DIR=${SOURCE_DIR:-${SCRIPT_PATH}/..} ; export SOURCE_DIR
36QMAKE=${QMAKE:-$SYSTEM_QMAKE} ; export QMAKE
37DEBUG_BUILD="-DCMAKE_BUILD_TYPE=Debug" ; export DEBUG_BUILD
38
39CFLAGS="${CFLAGS:--O2 -g -pipe -Wall }" ; export CFLAGS ;
40CXXFLAGS="${CXXFLAGS:--O2 -g -pipe -Wall }" ; export CXXFLAGS ;
41LDFLAGS="${LDFLAGS:--Wl,-z,relro }"; export LDFLAGS ;
42
43optPrint(){
44printf "\n\t\t${ITL1}VALID OPTIONS ARE${ITL0}:\n
45         --sourcedir=[path]
46         --outdir=[path]
47         --qmake=[path to executable]
48         --disable-debug | -D
49         --runtime=[path]
50         --disable-x11
51         --disable-dbus
52         --update-source | -U
53         --help | -h | help |-H\n\n"
54}
55
56helpPrint(){
57printf "\n\t\t\t${ITL1}PARAMETERS${ITL0}:
58
59${BLD1}--disable-x11${BLD0}
60
61          Disable all X11 calls.
62          Enable this when building for Wayland-only.
63          All X11 calls are guarded by runtime X11 platform check
64          even without this option.
65
66
67${BLD1}--disable-dbus${BLD0}
68
69          Build without QtDBus module. Native desktop notifications
70          will be disabled.
71
72
73${BLD1}--sourcedir=${BLD0}
74
75          Assuming this script is located in ${ITL1}falkon/linux${ITL0},
76          otherwise you must specify the path to
77          Falkon source directory.
78
79               ${UDR1}example:--sourcedir="/home/build/falkon"${UDR0}
80
81${BLD1}--outdir=${BLD0}
82
83          Where to copy final AppImage.
84
85${BLD1}--runtime=[path]${BLD0}
86
87          Path to precompiled „${BLD1}runtime.c${BLD0}“ ${ITL1}(part of AppImageKit)${ITL0}.
88          More info at: ${UDR1}https://github.com/probonopd/AppImageKit${UDR0}
89          ${BLD1}Mandatory option${BLD0}
90
91${BLD1}--disable-debug | -D${BLD0}
92
93          You may want to disable debug build.
94          (enabled by default)
95
96
97${BLD1}--update-source | -U${BLD0}
98
99          Fetches the information from Falkon online git repository
100          and merges it with your local copy
101
102
103${BLD1}--qmake=${BLD0}
104
105          Full path to qmake executable.
106          This option is mandatory in case you want
107          to create an AppImage.
108\n"
109}
110
111printConf(){
112printf "\n\tBuild configuration:\n
113    Library path=${LIBDIRPATH}
114    Source dir=${SOURCE_DIR}
115    Debug build=${DEBUG_BUILD}
116    Disable X11=${YNOX11}
117    Disable DBUS=${DISABLE_DBUS}
118    Runtime binary=${RUNTIME_BINARY}
119    Qmake=${QMAKE}\n" | sed -r 's/=$/ » Not set/g'
120}
121
122getVal(){
123echo $* | sed -r 's/([[:graph:]]*=)//'
124}
125
126varAssign(){
127while [ $# != 0 ] ;do
128        CFG_OPT="$1"
129        case "${CFG_OPT}" in
130         --sourcedir=*)
131               SOURCE_DIR=$(getVal "${CFG_OPT}")
132                export SOURCE_DIR
133             ;;
134         --outdir=*)
135                OUT_DIR=$(getVal "${CFG_OPT}")
136                export OUT_DIR
137             ;;
138         --disable-debug|-D)
139                unset DEBUG_BUILD
140             ;;
141         --runtime=*)
142                RUNTIME_BINARY=$(getVal "${CFG_OPT}")
143                export RUNTIME_BINARY
144             ;;
145         --disable-x11)
146                YNOX11="-DNO_X11:BOOL=TRUE"
147                export YNOX11
148             ;;
149         --disable-bus)
150                DISABLE_DBUS="-DDISABLE_DBUS:BOOL=TRUE"
151                export DISABLE_DBUS
152             ;;
153         --qmake=*)
154                QMAKE=$(getVal "${CFG_OPT}")
155                export QMAKE
156             ;;
157         --update-source|-U)
158                UPDATE_SOURCE="true"
159                export UPDATE_SOURCE
160             ;;
161         --help|help|-h|-H)
162                helpPrint
163                exit 1
164             ;;
165        *)
166                printf "\n${RDBG}unknown parameter: ${CFG_OPT}${DFBG}\n"
167                optPrint
168                exit 1
169                ;;
170     esac
171     shift
172done
173}
174
175nowBldImg(){
176
177cd "${SOURCE_DIR}"
178
179if [[ "${UPDATE_SOURCE}" == "true" ]]; then
180git pull || :
181fi
182
183rm -fr build || :
184mkdir build && cd build
185
186QTFILESARETHERE=$(${QMAKE} -query | grep INSTALL_PREFIX | sed 's/QT_INSTALL_PREFIX://')
187LIBSARETHERE=$(${QMAKE} -query | grep INSTALL_LIBS | sed 's/QT_INSTALL_LIBS://')
188PLUGINSARETHERE=$(${QMAKE} -query | grep INSTALL_PLUGINS | sed 's/QT_INSTALL_PLUGINS://')
189QMLSARETHERE=$(${QMAKE} -query | grep INSTALL_QML | sed 's/QT_INSTALL_QML://')
190TRANSLATIONSARETHERE=$(${QMAKE} -query | grep INSTALL_TRANSLATIONS | sed 's/QT_INSTALL_TRANSLATIONS://')
191LIBEXECSARETHERE=$(${QMAKE} -query | grep INSTALL_LIBEXECS | sed 's/QT_INSTALL_LIBEXECS://')
192
193NODEFOPT="${DEBUG_BUILD} ${YNOX11} ${DISABLE_DBUS}"
194
195cmake ${NODEFOPT}                     \
196-DBUILD_SHARED_LIBS:BOOL=TRUE          \
197-DCMAKE_SKIP_RPATH:BOOL=OFF             \
198-DCMAKE_SKIP_INSTALL_RPATH:BOOL=NO       \
199-DQMAKE_EXECUTABLE:FILEPATH=${QMAKE}      \
200-DCMAKE_PREFIX_PATH=${QTFILESARETHERE}     \
201-DFALKON_PLUGIN_PATH=""                     \
202-DKDE_INSTALL_LIBDIR:PATH="${LIBDIRPATH}" ..
203
204printf "Compiling Falkon with the following settings:\n"
205printConf
206
207make -j$NCPUS
208if [[ $? == 0 ]] ; then
209make DESTDIR="${PWD}" install
210fi
211
212mv usr/local bundle_build_dir
213pushd bundle_build_dir/lib/plugins/falkon
214chrpath --replace '$ORIGIN/../..' *.so
215popd
216
217NEEDEDLIBSLIST="libicudata.so.56
218libicui18n.so.56
219libicuuc.so.56
220libQt5Core.so.5
221libQt5DBus.so.5
222libQt5Gui.so.5
223libQt5Multimedia.so.5
224libQt5MultimediaWidgets.so.5
225libQt5Network.so.5
226libQt5OpenGL.so.5
227libQt5Positioning.so.5
228libQt5PrintSupport.so.5
229libQt5Qml.so.5
230libQt5Quick.so.5
231libQt5QuickWidgets.so.5
232libQt5Sql.so.5
233libQt5Svg.so.5
234libQt5WebChannel.so.5
235libQt5WebEngineCore.so.5
236libQt5WebEngine.so.5
237libQt5WebEngineWidgets.so.5
238libQt5Widgets.so.5
239libQt5X11Extras.so.5
240libQt5XcbQpa.so.5
241libQt5Concurrent.so.5
242libQt5Xml.so.5"
243
244NEEDEDPLUGINSLIST="bearer
245generic
246iconengines
247imageformats
248platforminputcontexts
249platformthemes
250printsupport
251xcbglintegrations"
252
253mkdir -p bundle_build_dir/plugins/{platforms,sqldrivers} \
254bundle_build_dir/qtwebengine_dictionaries \
255bundle_build_dir/qml \
256bundle_build_dir/translations || :
257for L in ${NEEDEDLIBSLIST} ; do
258  cp -d ${LIBSARETHERE}/${L}* bundle_build_dir/lib ;
259done
260
261for P in ${NEEDEDPLUGINSLIST} ; do
262  cp -r ${PLUGINSARETHERE}/${P} bundle_build_dir/plugins ;
263done
264if [[ -d "${PLUGINSARETHERE}/kf5/org.kde.kwindowsystem.platforms" ]]; then
265mkdir bundle_build_dir/plugins/kf5
266cp -r ${PLUGINSARETHERE}/kf5/org.kde.kwindowsystem.platforms bundle_build_dir/plugins/kf5
267fi
268install ${PLUGINSARETHERE}/platforms/libqxcb.so bundle_build_dir/plugins/platforms
269install ${PLUGINSARETHERE}/sqldrivers/libqsqlite.so bundle_build_dir/plugins/sqldrivers
270cp -r ${QMLSARETHERE}/{QtQuick.2,QtWebEngine} bundle_build_dir/qml
271cp -r ${QTFILESARETHERE}/resources bundle_build_dir
272cp -r ${TRANSLATIONSARETHERE}/qtwebengine_locales bundle_build_dir/translations
273cp ${LIBEXECSARETHERE}/QtWebEngineProcess bundle_build_dir
274
275CRYPTONEEDED="$(ldd 'bin/falkon'| grep libcrypto | sed 's/.*=>//;s/(.*//')"
276LIBSSLNEEDED="$(echo "${CRYPTONEEDED}"  | sed 's/crypto/ssl/')"
277install ${CRYPTONEEDED} ${LIBSSLNEEDED} bundle_build_dir/lib
278
279CRYPTOLINKED="$(basename "${CRYPTONEEDED}")"
280LIBSSLLINKED="$(basename "${LIBSSLNEEDED}")"
281
282#Try to include all ssl v1.0 variants.
283for LINK in {libcrypto.so,libcrypto.so.10,libcrypto.so.1.0.0} ; do
284  if [[ ! -e bundle_build_dir/lib/${LINK} ]] ; then
285    ln -s ${CRYPTOLINKED} bundle_build_dir/lib/${LINK}
286  fi
287done
288
289for LNKS in {libssl.so,libssl.so.10,libssl.so.1.0.0} ; do
290  if [[ ! -e bundle_build_dir/lib/${LNKS} ]] ; then
291    ln -s ${CRYPTOLINKED} bundle_build_dir/lib/${LNKS}
292  fi
293done
294
295cp ../linux/applications/org.kde.falkon.desktop bundle_build_dir
296cp ../linux/hicolor/128-apps-falkon.png bundle_build_dir/falkon.png
297ln -s falkon.png bundle_build_dir/.DirIcon
298
299pushd bundle_build_dir
300mv bin/falkon ./ && rm -fr bin
301chrpath --replace '$ORIGIN' lib/libFalkonPrivate.so.3.*
302chrpath --replace '$ORIGIN/lib' falkon
303chrpath --replace '$ORIGIN/lib' QtWebEngineProcess
304
305cat <<EOQTCFG >qt.conf
306[Paths]
307Plugins=plugins
308Imports=qml
309Qml2Imports=qml
310LibraryExecutables=.
311EOQTCFG
312
313cat <<EOF >AppRun
314#!/bin/sh
315
316set -e
317
318FALKON_DIR="\$(dirname "\$(readlink -f "\$0")")"
319
320XDG_DATA_DIRS="\${FALKON_DIR}/share:\${XDG_DATA_DIRS}"
321FALKON_PLUGIN_PATH="\${FALKON_DIR}/lib/plugins/falkon"
322export XDG_DATA_DIRS FALKON_PLUGIN_PATH
323
324cd "\${FALKON_DIR}/"
325exec ./falkon "\$@"
326EOF
327chmod +x AppRun
328popd
329
330printf "Generating app image\n"
331mksquashfs bundle_build_dir falkon.squashfs -root-owned -noappend
332
333cat "${RUNTIME_BINARY}" >bin/Falkon.AppImage
334cat falkon.squashfs >>bin/Falkon.AppImage
335chmod a+x bin/Falkon.AppImage
336}
337
338varAssign $*
339
340if [[ ! -x ${QMAKE} ]] ;then
341printf "${RDFG}ERROR${DFFG}: ${BLD1}qmake${BLD0} was not found! Please use ${BLD1}--qmake=${BLD0} option to specify the path where it is located!\n"
342exit 1
343fi
344
345if [[ ! -d "${SOURCE_DIR}/src" ]]; then
346printf "Please install ${UDR1}$0${UDR0} in „${BLD1}scripts${BLD0}“ ${ITL1}(a sub folder in Falkon source directory)${ITL0},
347or specify the source path with ${BLD1}--sourcedir=${BLD0}full/path!\n"
348exit 1
349fi
350
351if [[ ${TEST} != "yes" ]]  ; then
352printf "${RDFG}You must have the following tools installed:${DFFG}
353          ${ITL1}mksquashfs, chrpath${ITL0}!\n"
354exit 1
355fi
356
357if [[ "${QMAKE}" == "${SYSTEM_QMAKE}" ]] ; then
358printf "${RDFG}You should use precompiled Qt package${DFFG}
359downloaded from ${UDR1}${ITL1}http://download.qt.io/official_releases/qt/${ALL0}\n"
360exit 1
361elif
362[[ -z ${RUNTIME_BINARY} ]] ; then
363printf "\n${RDFG}Required precompiled „${BLD1}runtime${BLD0}“ binary!${DFFG}
364It's a part of ${ITL1}AppImageKit${ITL0}
365${UDR1}https://github.com/probonopd/AppImageKit${UDR0}\n"
366exit 1
367fi
368
369nowBldImg
370
371if [[ $? == 0 ]] && [[ -x bin/Falkon.AppImage ]]; then
372 printf "\\033c"
373 printf "Done!\nThe compiled files are in "${PWD}"/bin\n"
374 if [ ! -z "$OUT_DIR" ]; then
375     cp bin/Falkon.AppImage "$OUT_DIR"
376 fi
377fi
378
379exit 0
380