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

0001 #! /bin/bash
0002 
0003 # Script to build digiKam using MacPorts
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 MacPorts."
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/libexec/qt5/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.macports > ./tmp.macports ; mv -f ./tmp.macports ./bootstrap.macports
0140 sed -e "s/DBUILD_TESTING=ON/DBUILD_TESTING=OFF/g"               ./bootstrap.macports > ./tmp.macports ; mv -f ./tmp.macports ./bootstrap.macports
0141 sed -e "s/DENABLE_DBUS=ON/DENABLE_DBUS=OFF/g"                   ./bootstrap.macports > ./tmp.macports ; mv -f ./tmp.macports ./bootstrap.macports
0142 sed -e "s/DENABLE_APPSTYLES=OFF/DENABLE_APPSTYLES=ON/g"         ./bootstrap.macports > ./tmp.macports ; mv -f ./tmp.macports ./bootstrap.macports
0143 
0144 if [[ $DK_QTWEBENGINE = 0 ]] ; then
0145 
0146     sed -e "s/DENABLE_QWEBENGINE=ON/DENABLE_QWEBENGINE=OFF/g"   ./bootstrap.macports > ./tmp.macports ; mv -f ./tmp.macports ./bootstrap.macports
0147 
0148 fi
0149 
0150 chmod +x ./bootstrap.macports
0151 
0152 cp -f $ORIG_WD/fixbundledatapath.sh $DK_BUILDTEMP/digikam-$DK_VERSION
0153 
0154 ./fixbundledatapath.sh
0155 
0156 ./bootstrap.macports "$INSTALL_PREFIX" "Debug" "x86_64" "-Wno-dev"
0157 
0158 if [ $? -ne 0 ]; then
0159     echo "---------- Cannot configure digiKam $DK_VERSION."
0160     echo "---------- Aborting..."
0161     exit;
0162 fi
0163 
0164 echo -e "\n\n"
0165 echo "---------- Building digiKam $DK_VERSION"
0166 
0167 cd build
0168 make -j$CPU_CORES
0169 
0170 if [ $? -ne 0 ]; then
0171     echo "---------- Cannot compile digiKam $DK_VERSION."
0172     echo "---------- Aborting..."
0173     exit;
0174 fi
0175 
0176 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
0177 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
0178 
0179 # Copy manifests for rolling release codes included in digiKam core.
0180 cp  $DK_BUILDTEMP/digikam-$DK_VERSION/core/libs/dimg/filters/transform/lqr/liblqr_manifest.txt $ORIG_WD/data
0181 cp  $DK_BUILDTEMP/digikam-$DK_VERSION/core/libs/rawengine/libraw/libraw_manifest.txt $ORIG_WD/data
0182 cp  $DK_BUILDTEMP/digikam-$DK_VERSION/core/libs/dplugins/webservices/o2/o2_manifest.txt $ORIG_WD/data
0183 
0184 echo -e "\n\n"
0185 echo "---------- Installing digiKam $DK_VERSION"
0186 echo -e "\n\n"
0187 
0188 make install/fast && cd "$ORIG_WD"
0189 
0190 if [ $? -ne 0 ]; then
0191     echo "---------- Cannot install digiKam $DK_VERSION."
0192     echo "---------- Aborting..."
0193     exit;
0194 fi
0195 
0196 #################################################################################################
0197 # Install Extra Plugins
0198 
0199 cd $BUILDING_DIR
0200 
0201 rm -rf $BUILDING_DIR/* || true
0202 
0203 cmake $ORIG_WD/../3rdparty \
0204        -DCMAKE_INSTALL_PREFIX:PATH=$INSTALL_PREFIX \
0205        -DINSTALL_ROOT=$INSTALL_PREFIX \
0206        -DEXTERNALS_DOWNLOAD_DIR=$DOWNLOAD_DIR \
0207        -DKP_VERSION=$DK_KP_VERSION \
0208        -DKA_VERSION=$DK_KA_VERSION \
0209        -DKDE_VERSION=$DK_KDE_VERSION \
0210        -DENABLE_QTVERSION=$DK_QTVERSION \
0211        -DENABLE_QTWEBENGINE=$DK_QTWEBENGINE \
0212        -Wno-dev
0213 
0214 cmake --build . --config RelWithDebInfo --target ext_gmic_qt    -- -j$CPU_CORES
0215 cmake --build . --config RelWithDebInfo --target ext_mosaicwall -- -j$CPU_CORES
0216 cmake --build . --config RelWithDebInfo --target ext_flowview   -- -j$CPU_CORES
0217 
0218 mv -f $INSTALL_PREFIX/libexec/qt5/plugins/digikam/editor/*.so* $INSTALL_PREFIX/lib/plugins/digikam/editor/
0219 
0220 #################################################################################################
0221 
0222 export PATH=$ORIG_PATH
0223 
0224 TerminateScript