Debian Codegraph @

project/bundles/macports/common.sh

raw
1 #!/bin/bash
2
3 # SPDX-FileCopyrightText: 2013-2026 by Gilles Caulier <caulier dot gilles at gmail dot com>
4 #
5 # SPDX-License-Identifier: BSD-3-Clause
6 #
7
8 ########################################################################
9 # Check if run as root
10 ChecksRunAsRoot()
11 {
12
13 if [[ $EUID -ne 0 ]]; then
14 echo "This script should be run as root using sudo command."
15 exit 1
16 else
17 echo "Check run as root passed..."
18 fi
19
20 }
21
22 ########################################################################
23 # Check if Xcode Command Line tools are installed
24 ChecksXCodeCLI()
25 {
26
27 xcode-select --print-path
28
29 if [[ $? -ne 0 ]]; then
30 echo "XCode CLI tools are not installed"
31 echo "See http://www.macports.org/install.php for details."
32 exit 1
33 else
34 echo "Check XCode CLI tools passed..."
35 fi
36
37 export MACOSX_DEPLOYMENT_TARGET=$OSX_MIN_TARGET
38 echo "Target OSX minimal version: $MACOSX_DEPLOYMENT_TARGET"
39
40 MACOS_MAJOR=`echo $MACOSX_DEPLOYMENT_TARGET | awk -F '.' '{print $1 "." $2}'| cut -d . -f 1`
41 MACOS_MINOR=`echo $MACOSX_DEPLOYMENT_TARGET | awk -F '.' '{print $1 "." $2}'| cut -d . -f 2`
42
43 if [[ $MACOS_MAJOR -lt 11 && $MACOS_MINOR -lt 9 ]]; then
44 export CXXFLAGS=-stdlib=libc++
45 fi
46
47 if [[ ! -d /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX$MACOS_MAJOR.$MACOS_MINOR.sdk ]] ; then
48
49 echo "XCode Target SDK $MACOS_MAJOR.$MACOS_MINOR as minimal version is not installed in /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs"
50
51 if [[ ! -d $DOWNLOAD_DIR/macos-sdk.git ]] ; then
52
53 echo "Downloading archive of SDK from https://github.com/alexey-lysiuk/macos-sdk, please wait..."
54 git clone https://github.com/alexey-lysiuk/macos-sdk.git $DOWNLOAD_DIR/macos-sdk.git
55
56 fi
57
58 echo "Copying SDK $MACOS_MAJOR.$MACOS_MINOR into XCode, please wait..."
59 cp -R $DOWNLOAD_DIR/macos-sdk.git/MacOSX$MACOS_MAJOR.$MACOS_MINOR.sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/
60
61 else
62
63 echo "Check XCode Target SDK minimal version passed..."
64
65 fi
66
67 # Adjust the property "MinimumSDKVersion" from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Info.plist
68 /usr/libexec/PlistBuddy -c "Set MinimumSDKVersion $MACOS_MAJOR.$MACOS_MINOR" /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Info.plist
69
70 if [[ $HOST_ARCH = "arm64" ]] ; then
71
72 # Install Metal SDK for QtWebEngine
73 xcodebuild -downloadComponent MetalToolchain
74
75 fi
76
77 }
78
79 ########################################################################
80 # Check if Macports is installed
81 ChecksMacports()
82 {
83
84 which port
85
86 if [[ $? -ne 0 ]]; then
87 echo "Macports is not installed"
88 echo "See http://www.macports.org/install.php for details."
89 exit 1
90 else
91 echo "Check Macports passed..."
92 fi
93
94 }
95
96 ########################################################################
97 # Check CPU core available (Linux or MacOS)
98 ChecksCPUCores()
99 {
100
101 CPU_CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu)
102
103 if [[ $CPU_CORES -gt 1 ]]; then
104 CPU_CORES=$((CPU_CORES-1))
105 fi
106
107 echo "CPU Cores to use : $CPU_CORES"
108
109 }
110
111 ########################################################################
112 # Performs All Checks
113 CommonChecks()
114 {
115
116 ChecksRunAsRoot
117 ChecksXCodeCLI
118 ChecksMacports
119
120 }
121
122 ########################################################################
123 # For time execution measurement ; startup
124 StartScript()
125 {
126
127 BEGIN_SCRIPT=$(date +"%s")
128
129 }
130
131 ########################################################################
132 # For time execution measurement : shutdown
133 TerminateScript()
134 {
135
136 TERMIN_SCRIPT=$(date +"%s")
137 difftimelps=$(($TERMIN_SCRIPT-$BEGIN_SCRIPT))
138 echo "Elaspsed time for script execution : $(($difftimelps / 3600 )) hours $((($difftimelps % 3600) / 60)) minutes $(($difftimelps % 60)) seconds"
139
140 }
141
142 ########################################################################
143 # Set strings with detected MacOS info :
144 # $MAJOR_OSX_VERSION : detected MacOS major ID (as 10, 11, 12)
145 # $MINOR_OSX_VERSION : detected MacOS minor ID (as 7 for 10.7 or 10 for 10.10)
146 # $OSX_CODE_NAME : detected MacOS code name
147 OsxCodeName()
148 {
149
150 MAJOR_OSX_VERSION=$(sw_vers -productVersion | awk -F '.' '{print $1 "." $2}'| cut -d . -f 1)
151 MINOR_OSX_VERSION=$(sw_vers -productVersion | awk -F '.' '{print $1 "." $2}'| cut -d . -f 2)
152
153 if [[ $MAJOR_OSX_VERSION == "10" ]] ; then
154
155 if [[ $MINOR_OSX_VERSION == "15" ]]
156 then OSX_CODE_NAME="Catalina"
157 elif [[ $MINOR_OSX_VERSION == "14" ]]
158 then OSX_CODE_NAME="Mojave"
159 elif [[ $MINOR_OSX_VERSION == "13" ]]
160 then OSX_CODE_NAME="HighSierra"
161 elif [[ $MINOR_OSX_VERSION == "12" ]]
162 then OSX_CODE_NAME="Sierra"
163 elif [[ $MINOR_OSX_VERSION == "11" ]]
164 then OSX_CODE_NAME="ElCapitan"
165 elif [[ $MINOR_OSX_VERSION == "10" ]]
166 then OSX_CODE_NAME="Yosemite"
167 elif [[ $MINOR_OSX_VERSION == "9" ]]
168 then OSX_CODE_NAME="Mavericks"
169 elif [[ $MINOR_OSX_VERSION == "8" ]]
170 then OSX_CODE_NAME="MountainLion"
171 elif [[ $MINOR_OSX_VERSION == "7" ]]
172 then OSX_CODE_NAME="Lion"
173 elif [[ $MINOR_OSX_VERSION == "6" ]]
174 then OSX_CODE_NAME="SnowLeopard"
175 elif [[ $MINOR_OSX_VERSION == "5" ]]
176 then OSX_CODE_NAME="Leopard"
177 elif [[ $MINOR_OSX_VERSION == "4" ]]
178 then OSX_CODE_NAME="Tiger"
179 elif [[ $MINOR_OSX_VERSION == "3" ]]
180 then OSX_CODE_NAME="Panther"
181 elif [[ $MINOR_OSX_VERSION == "2" ]]
182 then OSX_CODE_NAME="Jaguar"
183 elif [[ $MINOR_OSX_VERSION == "1" ]]
184 then OSX_CODE_NAME="Puma"
185 elif [[ $MINOR_OSX_VERSION == "0" ]]
186 then OSX_CODE_NAME="Cheetah"
187 fi
188
189 elif [[ $MAJOR_OSX_VERSION == "11" ]]
190 then OSX_CODE_NAME="BigSur"
191
192 elif [[ $MAJOR_OSX_VERSION == "12" ]]
193 then OSX_CODE_NAME="Monterey"
194
195 elif [[ $MAJOR_OSX_VERSION == "13" ]]
196 then OSX_CODE_NAME="Ventura"
197
198 elif [[ $MAJOR_OSX_VERSION == "14" ]]
199 then OSX_CODE_NAME="Sonoma"
200
201 elif [[ $MAJOR_OSX_VERSION == "15" ]]
202 then OSX_CODE_NAME="Sequoia"
203
204 elif [[ $MAJOR_OSX_VERSION == "26" ]]
205 then OSX_CODE_NAME="Tahoe"
206
207 fi
208
209 echo -e "---------- Detected OSX version $MAJOR_OSX_VERSION.$MINOR_OSX_VERSION and code name $OSX_CODE_NAME"
210
211 }
212
213 #################################################################################################
214 # Relocate list of binaries files.
215 # Replace INSTALL_PREFIX by @rpath in library paths dependencies registered in bin file.
216 # List of bin files to patch is passed as first argument.
217 RelocatableBinaries()
218 {
219
220 RPATHSTR="@rpath"
221
222 FILESLIST=("${!1}")
223
224 #echo "Relocatable list: ${FILESLIST[@]}"
225
226 for FILE in ${FILESLIST[@]} ; do
227
228 ISMACHO=`file "$FILE" | grep "Mach-O" || true`
229
230 # Do not touch debug extension
231 ISDSYM=`file "$FILE" | grep "dSYM" || true`
232
233 if [[ $ISMACHO ]] && [[ ! $ISDSYM ]] ; then
234
235 # For each file from bin list, we replace the absolute path to external dependency with a relative path
236 # NOTE: relative path must be resolved in main executable later.
237
238 echo "Relocate $FILE"
239
240 # List all external dependencies starting with INSTALL_PREFIX
241
242 DEPS=$(otool -L $FILE | grep $INSTALL_PREFIX | awk -F ' \\\(' '{print $1}')
243
244 for EXTLIB in $DEPS ; do
245
246 RPATHLIB=${EXTLIB/$INSTALL_PREFIX/$RPATHSTR}
247 # echo " $EXTLIB ==> $RPATHLIB"
248 install_name_tool -change $EXTLIB $RPATHLIB $FILE
249
250 done
251
252 fi
253
254 done
255
256 }
257
258 ########################################################################
259 # Automatically register the remote servers has know hosts
260 RegisterRemoteServers()
261 {
262
263 SERVER_LIST="\
264 invent.kde.org \
265 tinami.kde.org \
266 "
267
268 if [[ ! -f ~/.ssh/known_hosts ]] ; then
269 touch ~/.ssh/known_hosts
270 fi
271
272 for server in $SERVER_LIST; do
273
274 echo "Register $server"
275
276 ssh-keygen -R $server
277 ssh-keyscan -H $server >> ~/.ssh/known_hosts
278
279 done
280
281 }