Debian Codegraph @

project/bundles/macports/01-build-macports.sh

raw
1 #! /bin/bash
2
3 # Script to build a bundle Macports installation with all digiKam dependencies in a dedicated directory
4 # This script must be run as sudo
5 #
6 # SPDX-FileCopyrightText: 2015 by Shanti <listaccount at revenant dot org>
7 # SPDX-FileCopyrightText: 2015-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
8 #
9 # SPDX-License-Identifier: BSD-3-Clause
10 #
11
12 # Ask to run as root
13 (( EUID != 0 )) && exec sudo -- "$0" "$@"
14
15 # Halt and catch errors
16 set -eE
17 trap 'PREVIOUS_COMMAND=$THIS_COMMAND; THIS_COMMAND=$BASH_COMMAND' DEBUG
18 trap 'echo "FAILED COMMAND: $PREVIOUS_COMMAND"' ERR
19
20 #################################################################################################
21 # Manage script traces to log file
22
23 mkdir -p ./logs
24 exec > >(tee ./logs/build-macports.full.log) 2>&1
25
26 #################################################################################################
27
28 echo "01-build-macports.sh : build a bundle Macports install with digiKam dependencies."
29 echo "---------------------------------------------------------------------------------"
30
31 #################################################################################################
32 # Pre-processing checks
33
34 . ./config.sh
35 . ./common.sh
36 StartScript
37 ChecksRunAsRoot
38 ChecksXCodeCLI
39 ChecksCPUCores
40 OsxCodeName
41 #RegisterRemoteServers
42
43 #################################################################################################
44
45 # Paths rules
46 ORIG_PATH="$PATH"
47 ORIG_WD="`pwd`"
48
49 export PATH=$INSTALL_PREFIX/bin:/$INSTALL_PREFIX/sbin:/$INSTALL_PREFIX/libexec/qt$DK_QTVERSION/bin:$ORIG_PATH:/$INSTALL_PREFIX/libexec/gnubin
50 echo "PATH=$PATH"
51 export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH/$INSTALL_PREFIX
52 echo "DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH"
53
54 #################################################################################################
55 # Check if /opt exists and standard Macports install path
56
57 if [ ! -d "/opt" ] ; then
58
59 echo "---------- /opt do not exist, creating"
60
61 mkdir "/opt"
62
63 if [ $? -ne 0 ] ; then
64
65 echo "---------- Cannot create /opt directory."
66 echo "---------- Aborting..."
67 exit;
68
69 fi
70
71 fi
72
73 #################################################################################################
74 # Check if a previous bundle already exist
75
76 CONTINUE_INSTALL=0
77
78 if [ -d "$INSTALL_PREFIX" ] ; then
79
80 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
81
82 if echo "$answer" | grep -iq "^r" ;then
83
84 echo "---------- Removing existing $INSTALL_PREFIX"
85 mv $INSTALL_PREFIX $INSTALL_PREFIX.old || true
86 rm -rf $INSTALL_PREFIX.old || true
87
88 elif echo "$answer" | grep -iq "^c" ;then
89
90 echo "---------- Continue aborted previous installation in $INSTALL_PREFIX"
91 CONTINUE_INSTALL=1
92
93 else
94
95 echo "---------- Aborting..."
96 exit;
97
98 fi
99
100 fi
101
102 if [[ $CONTINUE_INSTALL == 0 ]]; then
103
104 #################################################################################################
105 # Target directory creation
106
107 echo "---------- Creating $INSTALL_PREFIX"
108
109 mkdir -p "$INSTALL_PREFIX"
110
111 if [ $? -ne 0 ] ; then
112
113 echo "---------- Cannot create target install directory $INSTALL_PREFIX"
114 echo "---------- Aborting..."
115 exit;
116
117 fi
118
119 #################################################################################################
120 # Check latest Macports version available if necessary
121
122 if [ -z $MP_VERSION ] ; then
123
124 MP_LASTEST_VER=$(curl $MP_URL | \
125 egrep -o 'href="MacPorts-[0-9]+\.[0-9]+\.[0-9]+' | \
126 sed 's/^href="MacPorts-//' | \
127 sort -t. -rn -k1,1 -k2,2 -k3,3 | head -1)
128
129 if [ -z $MP_LASTEST_VER ] ; then
130
131 echo "---------- Cannot check the latest Macports version from $MP_URL"
132 echo "---------- Aborting..."
133 exit;
134
135 fi
136
137 echo "---------- Detected latest Macports version : $MP_LASTEST_VER"
138
139 MP_VERSION=$MP_LASTEST_VER
140
141 fi
142
143 #################################################################################################
144 # Build Macports in temporary directory and installation
145
146 if [ -d "$MP_BUILDTEMP" ] ; then
147
148 echo "---------- Removing existing $MP_BUILDTEMP"
149 rm -rf "$MP_BUILDTEMP"
150
151 fi
152
153 echo "---------- Creating $MP_BUILDTEMP"
154 mkdir "$MP_BUILDTEMP"
155
156 if [ $? -ne 0 ] ; then
157
158 echo "---------- Cannot create temporary directory $MP_BUILDTEMP to compile Macports"
159 echo "---------- Aborting..."
160 exit;
161
162 fi
163
164 cd "$MP_BUILDTEMP"
165 echo -e "\n\n"
166
167 echo "---------- Downloading MacPorts $MP_VERSION"
168 curl -o "MacPorts-$MP_VERSION.tar.bz2" "$MP_URL/MacPorts-$MP_VERSION.tar.bz2"
169 tar jxvf MacPorts-$MP_VERSION.tar.bz2
170 cd MacPorts-$MP_VERSION
171 echo -e "\n\n"
172
173 echo "---------- Configuring MacPorts"
174
175 ./configure --prefix="$INSTALL_PREFIX" \
176 --with-applications-dir="$INSTALL_PREFIX/Applications" \
177 --with-no-root-privileges \
178 --with-install-user="$(id -n -u)" \
179 --with-install-group="$(id -n -g)"
180
181 echo -e "\n\n"
182
183 echo "---------- Building MacPorts"
184 make -j$CPU_CORES
185 echo -e "\n\n"
186
187 echo "---------- Installing MacPorts"
188 echo -e "\n\n"
189 make install && cd "$ORIG_WD" && rm -rf "$MP_BUILDTEMP"
190
191 cat << EOF >> "$INSTALL_PREFIX/etc/macports/macports.conf"
192 +no_root -startupitem
193 startupitem_type none
194 startupitem_install no
195 macosx_deployment_target $OSX_MIN_TARGET
196 build_arch $HOST_ARCH
197 EOF
198
199 if [[ $HOST_ARCH = "arm64" && $MP_UNIVERSAL == 1 ]] ; then
200
201 # Build with both architectures embedded (x86 and ARM) for Apple Silicon target
202
203 cat << EOF >> "$INSTALL_PREFIX/etc/macports/variants.conf"
204 +universal
205 EOF
206
207 fi
208
209 fi
210
211 #################################################################################################
212 # Macports update
213
214 echo -e "\n"
215 echo "---------- Updating MacPorts"
216 port -v selfupdate
217
218 #cd patches
219 #./applypatches.sh
220 cd $ORIG_WD
221
222 if [[ $CONTINUE_INSTALL == 0 ]]; then
223
224 # port -v upgrade outdated
225 echo -e "\n"
226
227 #echo "---------- Modifying net-snmp portfile to install when not root"
228 #sed -e "/install.asroot/ s|yes|no|" -i ".orig" "`port file net-snmp`"
229
230 fi
231
232 #################################################################################################
233
234 # Create the build dir for the 3rdparty deps compiled with CMake
235
236 if [ ! -d $BUILDING_DIR ] ; then
237
238 mkdir $BUILDING_DIR
239
240 fi
241
242 if [ ! -d $DOWNLOAD_DIR ] ; then
243
244 mkdir $DOWNLOAD_DIR
245
246 fi
247
248 cd $BUILDING_DIR
249
250 rm -rf $BUILDING_DIR/* || true
251
252 #################################################################################################
253 # Dependencies build and installation
254
255 echo -e "\n"
256 echo "---------- Building digiKam dependencies with Macports"
257
258 # With MacOS less than El Capitan, we need a more recent Clang compiler than one provided by XCode.
259 # This only concern x86_64 architecture.
260
261 if [[ $MAJOR_OSX_VERSION -lt 11 && $MINOR_OSX_VERSION -lt 10 ]]; then
262
263 echo "---------- Install more recent Clang compiler from Macports for specific ports"
264 port install clang_select
265 port install clang-3.4
266 port select --set clang mp-clang-3.4
267
268 fi
269
270 echo -e "\n"
271
272 if [[ $HOST_ARCH = "x86_64" ]] ; then
273
274 port install ld64 +ld64_xcode
275
276 fi
277
278 echo -e "MariaDB Variant=$MP_MARIADB_VARIANT\n"
279
280 # To fix broken ports with m4 tool detection.
281
282 port install m4
283
284 if [ ! -f $INSTALL_PREFIX/bin/m4 ] ; then
285
286 cp -f $INSTALL_PREFIX/libexec/gnubin/m4 $INSTALL_PREFIX/bin/
287
288 fi
289
290
291 port install git
292 port install cctools +xcode
293 port install cmake
294 port install libpng
295 port install jpeg
296 port install tiff
297 port install eigen3
298 port install gettext
299 port install jasper
300 port install lcms2
301 port install expat
302 port install libxml2
303 port install libxslt
304 port install bison
305 port install x265
306 port install libde265
307 port install libfdk-aac
308 port install lame
309 port install speex
310 port install libtheora
311 port install xvid
312 port install libass
313 port install opus-tools
314 port install libvpx
315 port install aom
316 port install libusb
317 port install libgphoto2
318 port install wget +ssl
319 port install libical
320
321 port install libheif +x265 -tests -rav1e -kvazaar
322 port install ffmpeg8 +gpl2 +nonfree
323
324 if [ ! -f $INSTALL_PREFIX/bin/ffmpeg ] ; then
325
326 # Need to push ffmpeg8 from $INSTALL_PREFIX/libexec/ffmpeg8 to $INSTALL_PREFIX
327 cp -r $INSTALL_PREFIX/libexec/ffmpeg8/include $INSTALL_PREFIX
328 cp -r $INSTALL_PREFIX/libexec/ffmpeg8/lib $INSTALL_PREFIX
329 mv $INSTALL_PREFIX/bin/ffmpeg8 $INSTALL_PREFIX/bin/ffmpeg
330
331 fi
332
333 port install --allow-failing qt$DK_QTVERSION$MP_QTSUBVERSION-qtbase -examples -tests
334 port install --allow-failing qt$DK_QTVERSION$MP_QTSUBVERSION-qtdeclarative -examples -tests
335
336 if [[ $DK_QTVERSION = 5 ]] ; then
337
338 port install --allow-failing qt$DK_QTVERSION$MP_QTSUBVERSION-qtmacextras -examples -tests
339 port install --allow-failing qt$DK_QTVERSION$MP_QTSUBVERSION-qtquickcontrols -examples -tests
340 port install --allow-failing qt$DK_QTVERSION$MP_QTSUBVERSION-qtxmlpatterns -examples -tests
341 fi
342
343 port install --allow-failing qt$DK_QTVERSION$MP_QTSUBVERSION-qtscxml -examples -tests
344 port install --allow-failing qt$DK_QTVERSION$MP_QTSUBVERSION-qtsvg -examples -tests
345 port install --allow-failing qt$DK_QTVERSION$MP_QTSUBVERSION-qttools -examples -tests
346 port install --allow-failing qt$DK_QTVERSION$MP_QTSUBVERSION-qttranslations
347 port install --allow-failing qt$DK_QTVERSION$MP_QTSUBVERSION-qtimageformats -examples -tests
348 port install --allow-failing qt$DK_QTVERSION$MP_QTSUBVERSION-qtmultimedia -examples -tests
349 port install --allow-failing qt$DK_QTVERSION$MP_QTSUBVERSION-qtnetworkauth -examples -tests
350 port install --allow-failing qt$DK_QTVERSION$MP_QTSUBVERSION-sqlite-plugin
351 port install --allow-failing qt$DK_QTVERSION$MP_QTSUBVERSION-mysql-plugin $MP_MARIADB_VARIANT
352 port install --allow-failing qt$DK_QTVERSION$MP_QTSUBVERSION-qtwebengine -examples -tests
353
354 port install boost
355
356 cmake $ORIG_WD/../3rdparty \
357 -DCMAKE_INSTALL_PREFIX:PATH=$INSTALL_PREFIX \
358 -DINSTALL_ROOT=$INSTALL_PREFIX \
359 -DEXTERNALS_DOWNLOAD_DIR=$DOWNLOAD_DIR \
360 -DKA_VERSION=$DK_KA_VERSION \
361 -DKP_VERSION=$DK_KP_VERSION \
362 -DKDE_VERSION=$DK_KDE_VERSION \
363 -DENABLE_QTVERSION=$DK_QTVERSION \
364 -DDK_APPLE_PACKAGE_MANAGER=$DK_APPLE_PACKAGE_MANAGER \
365 -DARCH_TARGET=$TARGET_ARCH \
366 -Wno-dev
367
368 cmake --build . --config RelWithDebInfo --target ext_opencv -- -j$CPU_CORES
369 cmake --build . --config RelWithDebInfo --target ext_imagemagick -- -j$CPU_CORES
370
371 port install libjxl
372 port install libavif -docs -tests
373
374 # for rll.py script.
375 port install python27
376 port select --set python2 python27
377
378 #################################################################################################
379
380 export PATH=$ORIG_PATH
381
382 TerminateScript