File indexing completed on 2024-05-19 04:58:30

0001 #!/bin/sh
0002 ###############################################################################
0003 # Compile Falkon source and pack it as Appimage.
0004 ###############################################################################
0005 set -e
0006 
0007 SCRIPT_PATH="$(dirname "$(readlink -f "$0")")"
0008 NCPUS=$(getconf _NPROCESSORS_ONLN)  || :
0009 
0010 which mksquashfs >/dev/null 2>&1 || TEST=no
0011 which chrpath >/dev/null 2>&1 || TEST=no
0012 TEST=${TEST:-yes}
0013 
0014 if [ $(which qmake 2>/dev/null) ]; then
0015 SYSTEM_QMAKE=$(which qmake)
0016 elif [ $(which qmake-qt5 2>/dev/null) ]; then
0017 SYSTEM_QMAKE=$(which qmake-qt5)
0018 fi
0019 
0020 BLD1="\033[1m"
0021 BLD0="\033[21m"
0022 ITL1="\033[3m"
0023 ITL0="\033[23m"
0024 UDR1="\033[4m"
0025 UDR0="\033[24m"
0026 CRS1="\033[9m"
0027 CRS0="\033[29m"
0028 RDFG="\033[31m"
0029 RDBG="\033[41m"
0030 DFFG="\033[39m"
0031 DFBG="\033[49m"
0032 ALL0="\033[00m"
0033 
0034 LIBDIRPATH=lib ; export LIBDIRPATH
0035 SOURCE_DIR=${SOURCE_DIR:-${SCRIPT_PATH}/..} ; export SOURCE_DIR
0036 QMAKE=${QMAKE:-$SYSTEM_QMAKE} ; export QMAKE
0037 DEBUG_BUILD="-DCMAKE_BUILD_TYPE=Debug" ; export DEBUG_BUILD
0038 
0039 CFLAGS="${CFLAGS:--O2 -g -pipe -Wall }" ; export CFLAGS ;
0040 CXXFLAGS="${CXXFLAGS:--O2 -g -pipe -Wall }" ; export CXXFLAGS ;
0041 LDFLAGS="${LDFLAGS:--Wl,-z,relro }"; export LDFLAGS ;
0042 
0043 optPrint(){
0044 printf "\n\t\t${ITL1}VALID OPTIONS ARE${ITL0}:\n
0045          --sourcedir=[path]
0046          --outdir=[path]
0047          --qmake=[path to executable]
0048          --disable-debug | -D
0049          --runtime=[path]
0050          --disable-x11
0051          --disable-dbus
0052          --update-source | -U
0053          --help | -h | help |-H\n\n"
0054 }
0055 
0056 helpPrint(){
0057 printf "\n\t\t\t${ITL1}PARAMETERS${ITL0}:
0058 
0059 ${BLD1}--disable-x11${BLD0}
0060 
0061           Disable all X11 calls.
0062           Enable this when building for Wayland-only.
0063           All X11 calls are guarded by runtime X11 platform check
0064           even without this option.
0065 
0066 
0067 ${BLD1}--disable-dbus${BLD0}
0068 
0069           Build without QtDBus module. Native desktop notifications
0070           will be disabled.
0071 
0072 
0073 ${BLD1}--sourcedir=${BLD0}
0074 
0075           Assuming this script is located in ${ITL1}falkon/linux${ITL0},
0076           otherwise you must specify the path to
0077           Falkon source directory.
0078 
0079                ${UDR1}example:--sourcedir="/home/build/falkon"${UDR0}
0080 
0081 ${BLD1}--outdir=${BLD0}
0082 
0083           Where to copy final AppImage.
0084 
0085 ${BLD1}--runtime=[path]${BLD0}
0086 
0087           Path to precompiled „${BLD1}runtime.c${BLD0}“ ${ITL1}(part of AppImageKit)${ITL0}.
0088           More info at: ${UDR1}https://github.com/probonopd/AppImageKit${UDR0}
0089           ${BLD1}Mandatory option${BLD0}
0090 
0091 ${BLD1}--disable-debug | -D${BLD0}
0092 
0093           You may want to disable debug build.
0094           (enabled by default)
0095 
0096 
0097 ${BLD1}--update-source | -U${BLD0}
0098 
0099           Fetches the information from Falkon online git repository
0100           and merges it with your local copy
0101 
0102 
0103 ${BLD1}--qmake=${BLD0}
0104 
0105           Full path to qmake executable.
0106           This option is mandatory in case you want
0107           to create an AppImage.
0108 \n"
0109 }
0110 
0111 printConf(){
0112 printf "\n\tBuild configuration:\n
0113     Library path=${LIBDIRPATH}
0114     Source dir=${SOURCE_DIR}
0115     Debug build=${DEBUG_BUILD}
0116     Disable X11=${YNOX11}
0117     Disable DBUS=${DISABLE_DBUS}
0118     Runtime binary=${RUNTIME_BINARY}
0119     Qmake=${QMAKE}\n" | sed -r 's/=$/ » Not set/g'
0120 }
0121 
0122 getVal(){
0123 echo $* | sed -r 's/([[:graph:]]*=)//'
0124 }
0125 
0126 varAssign(){
0127 while [ $# != 0 ] ;do
0128         CFG_OPT="$1"
0129         case "${CFG_OPT}" in
0130          --sourcedir=*)
0131                SOURCE_DIR=$(getVal "${CFG_OPT}")
0132                 export SOURCE_DIR
0133              ;;
0134          --outdir=*)
0135                 OUT_DIR=$(getVal "${CFG_OPT}")
0136                 export OUT_DIR
0137              ;;
0138          --disable-debug|-D)
0139                 unset DEBUG_BUILD
0140              ;;
0141          --runtime=*)
0142                 RUNTIME_BINARY=$(getVal "${CFG_OPT}")
0143                 export RUNTIME_BINARY
0144              ;;
0145          --disable-x11)
0146                 YNOX11="-DNO_X11:BOOL=TRUE"
0147                 export YNOX11
0148              ;;
0149          --disable-bus)
0150                 DISABLE_DBUS="-DDISABLE_DBUS:BOOL=TRUE"
0151                 export DISABLE_DBUS
0152              ;;
0153          --qmake=*)
0154                 QMAKE=$(getVal "${CFG_OPT}")
0155                 export QMAKE
0156              ;;
0157          --update-source|-U)
0158                 UPDATE_SOURCE="true"
0159                 export UPDATE_SOURCE
0160              ;;
0161          --help|help|-h|-H)
0162                 helpPrint
0163                 exit 1
0164              ;;
0165         *)
0166                 printf "\n${RDBG}unknown parameter: ${CFG_OPT}${DFBG}\n"
0167                 optPrint
0168                 exit 1
0169                 ;;
0170      esac
0171      shift
0172 done
0173 }
0174 
0175 nowBldImg(){
0176 
0177 cd "${SOURCE_DIR}"
0178 
0179 if [[ "${UPDATE_SOURCE}" == "true" ]]; then
0180 git pull || :
0181 fi
0182 
0183 rm -fr build || :
0184 mkdir build && cd build
0185 
0186 QTFILESARETHERE=$(${QMAKE} -query | grep INSTALL_PREFIX | sed 's/QT_INSTALL_PREFIX://')
0187 LIBSARETHERE=$(${QMAKE} -query | grep INSTALL_LIBS | sed 's/QT_INSTALL_LIBS://')
0188 PLUGINSARETHERE=$(${QMAKE} -query | grep INSTALL_PLUGINS | sed 's/QT_INSTALL_PLUGINS://')
0189 QMLSARETHERE=$(${QMAKE} -query | grep INSTALL_QML | sed 's/QT_INSTALL_QML://')
0190 TRANSLATIONSARETHERE=$(${QMAKE} -query | grep INSTALL_TRANSLATIONS | sed 's/QT_INSTALL_TRANSLATIONS://')
0191 LIBEXECSARETHERE=$(${QMAKE} -query | grep INSTALL_LIBEXECS | sed 's/QT_INSTALL_LIBEXECS://')
0192 
0193 NODEFOPT="${DEBUG_BUILD} ${YNOX11} ${DISABLE_DBUS}"
0194 
0195 cmake ${NODEFOPT}                     \
0196 -DBUILD_SHARED_LIBS:BOOL=TRUE          \
0197 -DCMAKE_SKIP_RPATH:BOOL=OFF             \
0198 -DCMAKE_SKIP_INSTALL_RPATH:BOOL=NO       \
0199 -DQMAKE_EXECUTABLE:FILEPATH=${QMAKE}      \
0200 -DCMAKE_PREFIX_PATH=${QTFILESARETHERE}     \
0201 -DFALKON_PLUGIN_PATH=""                     \
0202 -DKDE_INSTALL_LIBDIR:PATH="${LIBDIRPATH}" ..
0203 
0204 printf "Compiling Falkon with the following settings:\n"
0205 printConf
0206 
0207 make -j$NCPUS
0208 if [[ $? == 0 ]] ; then
0209 make DESTDIR="${PWD}" install
0210 fi
0211 
0212 mv usr/local bundle_build_dir
0213 pushd bundle_build_dir/lib/plugins/falkon
0214 chrpath --replace '$ORIGIN/../..' *.so
0215 popd
0216 
0217 NEEDEDLIBSLIST="libicudata.so.56
0218 libicui18n.so.56
0219 libicuuc.so.56
0220 libQt5Core.so.5
0221 libQt5DBus.so.5
0222 libQt5Gui.so.5
0223 libQt5Multimedia.so.5
0224 libQt5MultimediaWidgets.so.5
0225 libQt5Network.so.5
0226 libQt5OpenGL.so.5
0227 libQt5Positioning.so.5
0228 libQt5PrintSupport.so.5
0229 libQt5Qml.so.5
0230 libQt5Quick.so.5
0231 libQt5QuickWidgets.so.5
0232 libQt5Sql.so.5
0233 libQt5Svg.so.5
0234 libQt5WebChannel.so.5
0235 libQt5WebEngineCore.so.5
0236 libQt5WebEngine.so.5
0237 libQt5WebEngineWidgets.so.5
0238 libQt5Widgets.so.5
0239 libQt5X11Extras.so.5
0240 libQt5XcbQpa.so.5
0241 libQt5Concurrent.so.5
0242 libQt5Xml.so.5"
0243 
0244 NEEDEDPLUGINSLIST="bearer
0245 generic
0246 iconengines
0247 imageformats
0248 platforminputcontexts
0249 platformthemes
0250 printsupport
0251 xcbglintegrations"
0252 
0253 mkdir -p bundle_build_dir/plugins/{platforms,sqldrivers} \
0254 bundle_build_dir/qtwebengine_dictionaries \
0255 bundle_build_dir/qml \
0256 bundle_build_dir/translations || :
0257 for L in ${NEEDEDLIBSLIST} ; do
0258   cp -d ${LIBSARETHERE}/${L}* bundle_build_dir/lib ;
0259 done
0260 
0261 for P in ${NEEDEDPLUGINSLIST} ; do
0262   cp -r ${PLUGINSARETHERE}/${P} bundle_build_dir/plugins ;
0263 done
0264 if [[ -d "${PLUGINSARETHERE}/kf5/org.kde.kwindowsystem.platforms" ]]; then
0265 mkdir bundle_build_dir/plugins/kf5
0266 cp -r ${PLUGINSARETHERE}/kf5/org.kde.kwindowsystem.platforms bundle_build_dir/plugins/kf5
0267 fi
0268 install ${PLUGINSARETHERE}/platforms/libqxcb.so bundle_build_dir/plugins/platforms
0269 install ${PLUGINSARETHERE}/sqldrivers/libqsqlite.so bundle_build_dir/plugins/sqldrivers
0270 cp -r ${QMLSARETHERE}/{QtQuick.2,QtWebEngine} bundle_build_dir/qml
0271 cp -r ${QTFILESARETHERE}/resources bundle_build_dir
0272 cp -r ${TRANSLATIONSARETHERE}/qtwebengine_locales bundle_build_dir/translations
0273 cp ${LIBEXECSARETHERE}/QtWebEngineProcess bundle_build_dir
0274 
0275 CRYPTONEEDED="$(ldd 'bin/falkon'| grep libcrypto | sed 's/.*=>//;s/(.*//')"
0276 LIBSSLNEEDED="$(echo "${CRYPTONEEDED}"  | sed 's/crypto/ssl/')"
0277 install ${CRYPTONEEDED} ${LIBSSLNEEDED} bundle_build_dir/lib
0278 
0279 CRYPTOLINKED="$(basename "${CRYPTONEEDED}")"
0280 LIBSSLLINKED="$(basename "${LIBSSLNEEDED}")"
0281 
0282 #Try to include all ssl v1.0 variants.
0283 for LINK in {libcrypto.so,libcrypto.so.10,libcrypto.so.1.0.0} ; do
0284   if [[ ! -e bundle_build_dir/lib/${LINK} ]] ; then
0285     ln -s ${CRYPTOLINKED} bundle_build_dir/lib/${LINK}
0286   fi
0287 done
0288 
0289 for LNKS in {libssl.so,libssl.so.10,libssl.so.1.0.0} ; do
0290   if [[ ! -e bundle_build_dir/lib/${LNKS} ]] ; then
0291     ln -s ${CRYPTOLINKED} bundle_build_dir/lib/${LNKS}
0292   fi
0293 done
0294 
0295 cp ../linux/applications/org.kde.falkon.desktop bundle_build_dir
0296 cp ../linux/hicolor/128-apps-falkon.png bundle_build_dir/falkon.png
0297 ln -s falkon.png bundle_build_dir/.DirIcon
0298 
0299 pushd bundle_build_dir
0300 mv bin/falkon ./ && rm -fr bin
0301 chrpath --replace '$ORIGIN' lib/libFalkonPrivate.so.3.*
0302 chrpath --replace '$ORIGIN/lib' falkon
0303 chrpath --replace '$ORIGIN/lib' QtWebEngineProcess
0304 
0305 cat <<EOQTCFG >qt.conf
0306 [Paths]
0307 Plugins=plugins
0308 Imports=qml
0309 Qml2Imports=qml
0310 LibraryExecutables=.
0311 EOQTCFG
0312 
0313 cat <<EOF >AppRun
0314 #!/bin/sh
0315 
0316 set -e
0317 
0318 FALKON_DIR="\$(dirname "\$(readlink -f "\$0")")"
0319 
0320 XDG_DATA_DIRS="\${FALKON_DIR}/share:\${XDG_DATA_DIRS}"
0321 FALKON_PLUGIN_PATH="\${FALKON_DIR}/lib/plugins/falkon"
0322 export XDG_DATA_DIRS FALKON_PLUGIN_PATH
0323 
0324 cd "\${FALKON_DIR}/"
0325 exec ./falkon "\$@"
0326 EOF
0327 chmod +x AppRun
0328 popd
0329 
0330 printf "Generating app image\n"
0331 mksquashfs bundle_build_dir falkon.squashfs -root-owned -noappend
0332 
0333 cat "${RUNTIME_BINARY}" >bin/Falkon.AppImage
0334 cat falkon.squashfs >>bin/Falkon.AppImage
0335 chmod a+x bin/Falkon.AppImage
0336 }
0337 
0338 varAssign $*
0339 
0340 if [[ ! -x ${QMAKE} ]] ;then
0341 printf "${RDFG}ERROR${DFFG}: ${BLD1}qmake${BLD0} was not found! Please use ${BLD1}--qmake=${BLD0} option to specify the path where it is located!\n"
0342 exit 1
0343 fi
0344 
0345 if [[ ! -d "${SOURCE_DIR}/src" ]]; then
0346 printf "Please install ${UDR1}$0${UDR0} in „${BLD1}scripts${BLD0}“ ${ITL1}(a sub folder in Falkon source directory)${ITL0},
0347 or specify the source path with ${BLD1}--sourcedir=${BLD0}full/path!\n"
0348 exit 1
0349 fi
0350 
0351 if [[ ${TEST} != "yes" ]]  ; then
0352 printf "${RDFG}You must have the following tools installed:${DFFG}
0353           ${ITL1}mksquashfs, chrpath${ITL0}!\n"
0354 exit 1
0355 fi
0356 
0357 if [[ "${QMAKE}" == "${SYSTEM_QMAKE}" ]] ; then
0358 printf "${RDFG}You should use precompiled Qt package${DFFG}
0359 downloaded from ${UDR1}${ITL1}http://download.qt.io/official_releases/qt/${ALL0}\n"
0360 exit 1
0361 elif
0362 [[ -z ${RUNTIME_BINARY} ]] ; then
0363 printf "\n${RDFG}Required precompiled „${BLD1}runtime${BLD0}“ binary!${DFFG}
0364 It's a part of ${ITL1}AppImageKit${ITL0}
0365 ${UDR1}https://github.com/probonopd/AppImageKit${UDR0}\n"
0366 exit 1
0367 fi
0368 
0369 nowBldImg
0370 
0371 if [[ $? == 0 ]] && [[ -x bin/Falkon.AppImage ]]; then
0372  printf "\\033c"
0373  printf "Done!\nThe compiled files are in "${PWD}"/bin\n"
0374  if [ ! -z "$OUT_DIR" ]; then
0375      cp bin/Falkon.AppImage "$OUT_DIR"
0376  fi
0377 fi
0378 
0379 exit 0