File indexing completed on 2024-06-16 04:06:49
0001 #! /bin/bash 0002 0003 # Script to build a bundle Macports installation with all digiKam dependencies in a dedicated directory 0004 # This script must be run as sudo 0005 # 0006 # SPDX-FileCopyrightText: 2015 by Shanti <listaccount at revenant dot org> 0007 # SPDX-FileCopyrightText: 2015-2024 by Gilles Caulier <caulier dot gilles at gmail dot com> 0008 # 0009 # SPDX-License-Identifier: BSD-3-Clause 0010 # 0011 0012 # Ask to run as root 0013 (( EUID != 0 )) && exec sudo -- "$0" "$@" 0014 0015 # Halt and catch errors 0016 set -eE 0017 trap 'PREVIOUS_COMMAND=$THIS_COMMAND; THIS_COMMAND=$BASH_COMMAND' DEBUG 0018 trap 'echo "FAILED COMMAND: $PREVIOUS_COMMAND"' ERR 0019 0020 ################################################################################################# 0021 # Manage script traces to log file 0022 0023 mkdir -p ./logs 0024 exec > >(tee ./logs/build-macports.full.log) 2>&1 0025 0026 ################################################################################################# 0027 0028 echo "01-build-macports.sh : build a bundle Macports install with digiKam dependencies." 0029 echo "---------------------------------------------------------------------------------" 0030 0031 ################################################################################################# 0032 # Pre-processing checks 0033 0034 . ./config.sh 0035 . ./common.sh 0036 StartScript 0037 ChecksRunAsRoot 0038 ChecksXCodeCLI 0039 ChecksCPUCores 0040 OsxCodeName 0041 #RegisterRemoteServers 0042 0043 ################################################################################################# 0044 0045 # Paths rules 0046 ORIG_PATH="$PATH" 0047 ORIG_WD="`pwd`" 0048 0049 export PATH=$INSTALL_PREFIX/bin:/$INSTALL_PREFIX/sbin:/$INSTALL_PREFIX/libexec/qt5/bin:$ORIG_PATH 0050 0051 ################################################################################################# 0052 # Check if /opt exists and standard Macports install path 0053 0054 if [ -d "/opt" ] ; then 0055 0056 if [ -d "/opt/local" ] ; then 0057 0058 echo "---------- A standard Macports install exists on /opt/local." 0059 echo " To prevent wrong links from this bundle to this repository" 0060 echo " this one must be disabled (moving to /opt/local.back for ex)." 0061 echo "---------- Aborting..." 0062 exit; 0063 0064 fi 0065 0066 else 0067 0068 echo "---------- /opt do not exist, creating" 0069 0070 mkdir "/opt" 0071 0072 if [ $? -ne 0 ] ; then 0073 0074 echo "---------- Cannot create /opt directory." 0075 echo "---------- Aborting..." 0076 exit; 0077 0078 fi 0079 0080 fi 0081 0082 ################################################################################################# 0083 # Check if a previous bundle already exist 0084 0085 CONTINUE_INSTALL=0 0086 0087 if [ -d "$INSTALL_PREFIX" ] ; then 0088 0089 read -p "$INSTALL_PREFIX already exist. Do you want to remove it or to continue an aborted previous installation ? [(r)emove/(c)ontinue/(s)top] " answer 0090 0091 if echo "$answer" | grep -iq "^r" ;then 0092 0093 echo "---------- Removing existing $INSTALL_PREFIX" 0094 mv $INSTALL_PREFIX $INSTALL_PREFIX.old || true 0095 rm -rf $INSTALL_PREFIX.old || true 0096 0097 elif echo "$answer" | grep -iq "^c" ;then 0098 0099 echo "---------- Continue aborted previous installation in $INSTALL_PREFIX" 0100 CONTINUE_INSTALL=1 0101 0102 else 0103 0104 echo "---------- Aborting..." 0105 exit; 0106 0107 fi 0108 0109 fi 0110 0111 if [[ $CONTINUE_INSTALL == 0 ]]; then 0112 0113 ################################################################################################# 0114 # Target directory creation 0115 0116 echo "---------- Creating $INSTALL_PREFIX" 0117 0118 mkdir -p "$INSTALL_PREFIX" 0119 0120 if [ $? -ne 0 ] ; then 0121 0122 echo "---------- Cannot create target install directory $INSTALL_PREFIX" 0123 echo "---------- Aborting..." 0124 exit; 0125 0126 fi 0127 0128 ################################################################################################# 0129 # Check latest Macports version available if necessary 0130 0131 if [ -z $MP_VERSION ] ; then 0132 0133 MP_LASTEST_VER=$(curl $MP_URL | \ 0134 egrep -o 'href="MacPorts-[0-9]+\.[0-9]+\.[0-9]+' | \ 0135 sed 's/^href="MacPorts-//' | \ 0136 sort -t. -rn -k1,1 -k2,2 -k3,3 | head -1) 0137 0138 if [ -z $MP_LASTEST_VER ] ; then 0139 0140 echo "---------- Cannot check the lastest Macports verion from $MP_URL" 0141 echo "---------- Aborting..." 0142 exit; 0143 0144 fi 0145 0146 echo "---------- Detected lastest Macports version : $MP_LASTEST_VER" 0147 0148 MP_VERSION=$MP_LASTEST_VER 0149 0150 fi 0151 0152 ################################################################################################# 0153 # Build Macports in temporary directory and installation 0154 0155 if [ -d "$MP_BUILDTEMP" ] ; then 0156 0157 echo "---------- Removing existing $MP_BUILDTEMP" 0158 rm -rf "$MP_BUILDTEMP" 0159 0160 fi 0161 0162 echo "---------- Creating $MP_BUILDTEMP" 0163 mkdir "$MP_BUILDTEMP" 0164 0165 if [ $? -ne 0 ] ; then 0166 0167 echo "---------- Cannot create temporary directory $MP_BUILDTEMP to compile Macports" 0168 echo "---------- Aborting..." 0169 exit; 0170 0171 fi 0172 0173 cd "$MP_BUILDTEMP" 0174 echo -e "\n\n" 0175 0176 echo "---------- Downloading MacPorts $MP_VERSION" 0177 curl -o "MacPorts-$MP_VERSION.tar.bz2" "$MP_URL/MacPorts-$MP_VERSION.tar.bz2" 0178 tar jxvf MacPorts-$MP_VERSION.tar.bz2 0179 cd MacPorts-$MP_VERSION 0180 echo -e "\n\n" 0181 0182 echo "---------- Configuring MacPorts" 0183 0184 ./configure --prefix="$INSTALL_PREFIX" \ 0185 --with-applications-dir="$INSTALL_PREFIX/Applications" \ 0186 --with-no-root-privileges \ 0187 --with-install-user="$(id -n -u)" \ 0188 --with-install-group="$(id -n -g)" 0189 0190 echo -e "\n\n" 0191 0192 echo "---------- Building MacPorts" 0193 make -j$CPU_CORES 0194 echo -e "\n\n" 0195 0196 echo "---------- Installing MacPorts" 0197 echo -e "\n\n" 0198 make install && cd "$ORIG_WD" && rm -rf "$MP_BUILDTEMP" 0199 0200 cat << EOF >> "$INSTALL_PREFIX/etc/macports/macports.conf" 0201 +no_root -startupitem 0202 startupitem_type none 0203 startupitem_install no 0204 macosx_deployment_target $OSX_MIN_TARGET 0205 build_arch $ARCH_TARGET 0206 EOF 0207 0208 if [[ $ARCH_TARGET = "arm64" ]] ; then 0209 0210 # No need to build with both architectures embeded (x86 and ARM) for Apple Silicon target 0211 0212 cat << EOF >> "$INSTALL_PREFIX/etc/macports/variants.conf" 0213 +universal 0214 EOF 0215 0216 fi 0217 0218 fi 0219 0220 ################################################################################################# 0221 # Macports update 0222 0223 echo -e "\n" 0224 echo "---------- Updating MacPorts" 0225 port -v selfupdate 0226 0227 if [[ $CONTINUE_INSTALL == 0 ]]; then 0228 0229 # port -v upgrade outdated 0230 echo -e "\n" 0231 0232 #echo "---------- Modifying net-snmp portfile to install when not root" 0233 #sed -e "/install.asroot/ s|yes|no|" -i ".orig" "`port file net-snmp`" 0234 0235 fi 0236 0237 ################################################################################################# 0238 # Dependencies build and installation 0239 0240 echo -e "\n" 0241 echo "---------- Building digiKam dependencies with Macports" 0242 0243 # With OSX less than El Capitan, we need a more recent Clang compiler than one provided by XCode. 0244 # This only concern x86_64 architecture. 0245 0246 if [[ $MAJOR_OSX_VERSION -lt 11 && $MINOR_OSX_VERSION -lt 10 ]]; then 0247 0248 echo "---------- Install more recent Clang compiler from Macports for specific ports" 0249 port install clang_select 0250 port install clang-3.4 0251 port select --set clang mp-clang-3.4 0252 0253 fi 0254 0255 echo -e "\n" 0256 0257 if [[ $ARCH_TARGET = "x86_64" ]] ; then 0258 0259 port install ld64 +ld64_xcode 0260 0261 fi 0262 0263 echo -e "MariaDB Variant=$MP_MARIADB_VARIANT\n" 0264 0265 port install \ 0266 cctools +xcode \ 0267 cmake \ 0268 ccache \ 0269 libpng \ 0270 jpeg \ 0271 tiff \ 0272 boost \ 0273 eigen3 \ 0274 gettext \ 0275 libusb \ 0276 libgphoto2 \ 0277 jasper \ 0278 lcms2 \ 0279 expat \ 0280 libxml2 \ 0281 libxslt \ 0282 libical \ 0283 bison \ 0284 py38-lxml \ 0285 x265 \ 0286 libde265 \ 0287 libheif \ 0288 aom \ 0289 ffmpeg \ 0290 wget +ssl \ 0291 qt5-qtbase \ 0292 qt5-qtdeclarative \ 0293 qt5-qtmacextras \ 0294 qt5-qtquickcontrols \ 0295 qt5-qtxmlpatterns \ 0296 qt5-qtsvg \ 0297 qt5-qttools \ 0298 qt5-qttranslations \ 0299 qt5-qtimageformats \ 0300 qt5-qtmultimedia 0301 qt5-qtnetworkauth \ 0302 qt5-sqlite-plugin \ 0303 qt5-mysql-plugin $MP_MARIADB_VARIANT 0304 0305 port deactivate boost 0306 0307 if [[ $DK_QTWEBENGINE = 1 ]] ; then 0308 0309 port install qt5-qtwebengine 0310 0311 else 0312 0313 port install qt5-qtwebkit 0314 0315 fi 0316 0317 port activate boost 0318 0319 # port broken since a while. check later 0320 # sane-backends \ 0321 0322 echo -e "\n" 0323 0324 echo -e "---------- Compilation logs of Macports packages with suspicious installation\n" 0325 find $INSTALL_PREFIX/var/macports/logs/ -name main.log 0326 echo -e "\n----------" 0327 0328 echo -e "\n" 0329 0330 ################################################################################################# 0331 0332 # Create the build dir for the 3rdparty deps 0333 0334 if [ ! -d $BUILDING_DIR ] ; then 0335 0336 mkdir $BUILDING_DIR 0337 0338 fi 0339 0340 if [ ! -d $DOWNLOAD_DIR ] ; then 0341 0342 mkdir $DOWNLOAD_DIR 0343 0344 fi 0345 0346 cd $BUILDING_DIR 0347 0348 rm -rf $BUILDING_DIR/* || true 0349 0350 cmake $ORIG_WD/../3rdparty \ 0351 -DCMAKE_INSTALL_PREFIX:PATH=$INSTALL_PREFIX \ 0352 -DINSTALL_ROOT=$INSTALL_PREFIX \ 0353 -DEXTERNALS_DOWNLOAD_DIR=$DOWNLOAD_DIR \ 0354 -DKA_VERSION=$DK_KA_VERSION \ 0355 -DKP_VERSION=$DK_KP_VERSION \ 0356 -DKDE_VERSION=$DK_KDE_VERSION \ 0357 -DENABLE_QTVERSION=$DK_QTVERSION \ 0358 -DENABLE_QTWEBENGINE=$DK_QTWEBENGINE \ 0359 -Wno-dev 0360 0361 if [[ $DK_QTWEBENGINE = 0 ]] ; then 0362 cmake --build . --config RelWithDebInfo --target ext_qtwebkit -- -j$CPU_CORES 0363 fi 0364 0365 cmake --build . --config RelWithDebInfo --target ext_opencv -- -j$CPU_CORES 0366 cmake --build . --config RelWithDebInfo --target ext_imagemagick -- -j$CPU_CORES 0367 cmake --build . --config RelWithDebInfo --target ext_libjxl -- -j$CPU_CORES 0368 cmake --build . --config RelWithDebInfo --target ext_libavif -- -j$CPU_CORES 0369 0370 ################################################################################################# 0371 0372 export PATH=$ORIG_PATH 0373 0374 TerminateScript