File indexing completed on 2024-06-16 04:06:49

0001 #! /bin/bash
0002 
0003 # Script to build digiKam using HomeBrew
0004 # This script must be run as sudo
0005 #
0006 # SPDX-FileCopyrightText: 2015-2024 by Gilles Caulier  <caulier dot gilles at gmail dot com>
0007 #
0008 # SPDX-License-Identifier: BSD-3-Clause
0009 #
0010 
0011 # Ask to run as root
0012 (( EUID != 0 )) && exec sudo -- "$0" "$@"
0013 
0014 # Halt and catch errors
0015 set -eE
0016 trap 'PREVIOUS_COMMAND=$THIS_COMMAND; THIS_COMMAND=$BASH_COMMAND' DEBUG
0017 trap 'echo "FAILED COMMAND: $PREVIOUS_COMMAND"' ERR
0018 
0019 #################################################################################################
0020 # Manage script traces to log file
0021 
0022 mkdir -p ./logs
0023 exec > >(tee ./logs/build-digikam.full.log) 2>&1
0024 
0025 #################################################################################################
0026 
0027 echo "03-build-digikam.sh : build digiKam using HomeBrew."
0028 echo "---------------------------------------------------"
0029 
0030 #################################################################################################
0031 # Pre-processing checks
0032 
0033 . ./config.sh
0034 . ./common.sh
0035 StartScript
0036 ChecksRunAsRoot
0037 ChecksXCodeCLI
0038 ChecksCPUCores
0039 OsxCodeName
0040 #RegisterRemoteServers
0041 
0042 #################################################################################################
0043 
0044 # Paths rules
0045 ORIG_PATH="$PATH"
0046 ORIG_WD="`pwd`"
0047 
0048 export PATH=$INSTALL_PREFIX/bin:/$INSTALL_PREFIX/sbin:/$INSTALL_PREFIX/opt/qt6/bin:/$INSTALL_PREFIX/opt/bison/bin:$ORIG_PATH
0049 
0050 #################################################################################################
0051 # Install out-dated dependencies
0052 
0053 cd $BUILDING_DIR
0054 
0055 rm -rf $BUILDING_DIR/* || true
0056 
0057 #cmake $ORIG_WD/../3rdparty \
0058 #       -DCMAKE_INSTALL_PREFIX:PATH=$INSTALL_PREFIX \
0059 #       -DINSTALL_ROOT=$INSTALL_PREFIX \
0060 #       -DEXTERNALS_DOWNLOAD_DIR=$DOWNLOAD_DIR \
0061 #       -DKP_VERSION=$DK_KP_VERSION \
0062 #       -DKA_VERSION=$DK_KA_VERSION \
0063 #       -DKDE_VERSION=$DK_KDE_VERSION \
0064 #       -DENABLE_QTVERSION=$DK_QTVERSION \
0065 #       -DENABLE_QTWEBENGINE=$DK_QTWEBENGINE \
0066 #       -DMACOSX_DEPLOYMENT_TARGET=$OSX_MIN_TARGET \
0067 #       -Wno-dev
0068 
0069 #cmake --build . --config RelWithDebInfo --target ext_exiv2   -- -j$CPU_CORES
0070 #cp $DOWNLOAD_DIR/exiv2_manifest.txt $ORIG_WD/data/
0071 #cmake --build . --config RelWithDebInfo --target ext_lensfun -- -j$CPU_CORES
0072 #cp $DOWNLOAD_DIR/lensfun_manifest.txt $ORIG_WD/data/
0073 
0074 #################################################################################################
0075 # Build digiKam in temporary directory and installation
0076 
0077 # Clean up previous install (see bug #459276)
0078 
0079 cd "$INSTALL_PREFIX"
0080 
0081 # This is odd: grep -E under macOS return an error if nothing is found
0082 touch digikam.txt
0083 
0084 FILES=$(find . | grep -E '(digikam|showfoto)')
0085 
0086 for FILE in $FILES ; do
0087     if [[ -f ${FILE} || -d ${FILE} ]] ; then
0088         echo -e "   ==> $INSTALL_PREFIX/${FILE} will be removed from previous install"
0089         rm -fr $INSTALL_PREFIX/${FILE}
0090     fi
0091 done
0092 
0093 cd $BUILDING_DIR
0094 
0095 if [ -d "$DK_BUILDTEMP/digikam-$DK_VERSION" ] ; then
0096 
0097     echo "---------- Updating existing $DK_BUILDTEMP"
0098 
0099     cd "$DK_BUILDTEMP"
0100     cd digikam-$DK_VERSION
0101 
0102     git reset --hard
0103     git pull
0104 
0105     rm -fr build
0106     mkdir -p build
0107 
0108 else
0109 
0110     echo "---------- Creating $DK_BUILDTEMP"
0111     mkdir -p "$DK_BUILDTEMP"
0112 
0113     if [ $? -ne 0 ] ; then
0114         echo "---------- Cannot create $DK_BUILDTEMP directory."
0115         echo "---------- Aborting..."
0116         exit;
0117     fi
0118 
0119     cd "$DK_BUILDTEMP"
0120     echo -e "\n\n"
0121     echo "---------- Downloading digiKam $DK_VERSION"
0122 
0123     git clone --progress --verbose --branch $DK_VERSION --single-branch $DK_GITURL digikam-$DK_VERSION
0124     cd digikam-$DK_VERSION
0125 
0126     if [ $? -ne 0 ] ; then
0127         echo "---------- Cannot clone repositories."
0128         echo "---------- Aborting..."
0129         exit;
0130     fi
0131 
0132     mkdir build
0133 
0134 fi
0135 
0136 echo -e "\n\n"
0137 echo "---------- Configure digiKam $DK_VERSION"
0138 
0139 sed -e "s/DIGIKAMSC_COMPILE_PO=OFF/DIGIKAMSC_COMPILE_PO=ON/g"   ./bootstrap.homebrew > ./tmp.homebrew ; mv -f ./tmp.homebrew ./bootstrap.homebrew
0140 sed -e "s/DBUILD_TESTING=ON/DBUILD_TESTING=OFF/g"               ./bootstrap.homebrew > ./tmp.homebrew ; mv -f ./tmp.homebrew ./bootstrap.homebrew
0141 sed -e "s/DENABLE_DBUS=ON/DENABLE_DBUS=OFF/g"                   ./bootstrap.homebrew > ./tmp.homebrew ; mv -f ./tmp.homebrew ./bootstrap.homebrew
0142 sed -e "s/DENABLE_APPSTYLES=OFF/DENABLE_APPSTYLES=ON/g"         ./bootstrap.homebrew > ./tmp.homebrew ; mv -f ./tmp.homebrew ./bootstrap.homebrew
0143 
0144 
0145 chmod +x ./bootstrap.homebrew
0146 
0147 cp -f $ORIG_WD/fixbundledatapath.sh $DK_BUILDTEMP/digikam-$DK_VERSION
0148 
0149 ./fixbundledatapath.sh
0150 
0151 ./bootstrap.homebrew "$INSTALL_PREFIX" "Debug" "arm64" "-Wno-dev"
0152 
0153 if [ $? -ne 0 ]; then
0154     echo "---------- Cannot configure digiKam $DK_VERSION."
0155     echo "---------- Aborting..."
0156     exit;
0157 fi
0158 
0159 echo -e "\n\n"
0160 echo "---------- Building digiKam $DK_VERSION"
0161 
0162 cd build
0163 make -j$CPU_CORES
0164 
0165 if [ $? -ne 0 ]; then
0166     echo "---------- Cannot compile digiKam $DK_VERSION."
0167     echo "---------- Aborting..."
0168     exit;
0169 fi
0170 
0171 cat $DK_BUILDTEMP/digikam-$DK_VERSION/build/core/app/utils/digikam_version.h   | grep "digikam_version\[\]" | awk '{print $6}' | tr -d '";'  > $ORIG_WD/data/RELEASEID.txt
0172 cat $DK_BUILDTEMP/digikam-$DK_VERSION/build/core/app/utils/digikam_builddate.h | grep "define BUILD_DATE"   | awk '{print $3}' | tr -d '"\n' > $ORIG_WD/data/BUILDDATE.txt
0173 
0174 # Copy manifests for rolling release codes included in digiKam core.
0175 cp  $DK_BUILDTEMP/digikam-$DK_VERSION/core/libs/dimg/filters/transform/lqr/liblqr_manifest.txt $ORIG_WD/data
0176 cp  $DK_BUILDTEMP/digikam-$DK_VERSION/core/libs/rawengine/libraw/libraw_manifest.txt $ORIG_WD/data
0177 cp  $DK_BUILDTEMP/digikam-$DK_VERSION/core/libs/dplugins/webservices/o2/o2_manifest.txt $ORIG_WD/data
0178 
0179 echo -e "\n\n"
0180 echo "---------- Installing digiKam $DK_VERSION"
0181 echo -e "\n\n"
0182 
0183 make install/fast && cd "$ORIG_WD"
0184 
0185 if [ $? -ne 0 ]; then
0186     echo "---------- Cannot install digiKam $DK_VERSION."
0187     echo "---------- Aborting..."
0188     exit;
0189 fi
0190 
0191 #################################################################################################
0192 # Install Extra Plugins
0193 
0194 cd $BUILDING_DIR
0195 
0196 rm -rf $BUILDING_DIR/* || true
0197 
0198 cmake $ORIG_WD/../3rdparty \
0199        -DCMAKE_INSTALL_PREFIX:PATH=$INSTALL_PREFIX \
0200        -DINSTALL_ROOT=$INSTALL_PREFIX \
0201        -DEXTERNALS_DOWNLOAD_DIR=$DOWNLOAD_DIR \
0202        -DKP_VERSION=$DK_KP_VERSION \
0203        -DKA_VERSION=$DK_KA_VERSION \
0204        -DKDE_VERSION=$DK_KDE_VERSION \
0205        -DENABLE_QTVERSION=$DK_QTVERSION \
0206        -DENABLE_QTWEBENGINE=$DK_QTWEBENGINE \
0207        -Wno-dev
0208 
0209 cmake --build . --config RelWithDebInfo --target ext_gmic_qt    -- -j$CPU_CORES
0210 cmake --build . --config RelWithDebInfo --target ext_mosaicwall -- -j$CPU_CORES
0211 cmake --build . --config RelWithDebInfo --target ext_flowview   -- -j$CPU_CORES
0212 
0213 #################################################################################################
0214 
0215 export PATH=$ORIG_PATH
0216 
0217 TerminateScript