271 | | |
272 | | ### The following code was adapted from the portfiles |
273 | | ### of ports such as openvdb and openimageio |
274 | | |
275 | | # Get major version from version string |
276 | | proc get_major {version} { return [lindex [split ${version} .] 0] } |
277 | | |
278 | | set clang_versions {5.0 6.0 7.0 8.0 9.0 10 11 12 13} |
279 | | set clang_variants {} |
280 | | foreach v $clang_versions { |
281 | | lappend clang_variants clang[get_major $v] |
282 | | } |
283 | | |
284 | | # this default version should stay synchronized with |
285 | | # the default macports_clang option in the SConstruct |
286 | | # file that is part of the Godot source code |
287 | | set sconstruct_default_mp_clang 5 |
288 | | |
289 | | # On older macOS versions, use clang variant by default |
290 | | if {[string match macports-clang-* ${configure.compiler}] || \ |
291 | | ${os.platform} eq "darwin" && ${os.major} <= 14} \ |
292 | | { |
293 | | set has_clang_variant no |
294 | | foreach v $clang_versions { |
295 | | if {[variant_isset clang[get_major $v]]} { |
296 | | set has_clang_variant yes |
297 | | } |
298 | | } |
299 | | if {!$has_clang_variant} { |
300 | | if {[regexp {macports-clang-([0-9]+(?:\.[0-9]+)*)} \ |
301 | | ${configure.compiler} result clang_version]} \ |
302 | | { |
303 | | default_variants-append +clang[get_major $clang_version] |
304 | | } else { |
305 | | # Unable to determine $clang_version, |
306 | | # so use most recent clang |
307 | | default_variants-append +clang[get_major [ |
308 | | lindex $clang_versions end |
309 | | ]] |
310 | | } |
311 | | } |
312 | | } |
313 | | |
314 | | # Configure the variants |
315 | | foreach clang_ver $clang_versions { |
316 | | set clang_ver_major [get_major $clang_ver] |
317 | | |
318 | | set i [lsearch -exact $clang_variants clang$clang_ver_major] |
319 | | set c [lreplace $clang_variants $i $i] |
320 | | |
321 | | variant clang$clang_ver_major conflicts {*}${c} \ |
322 | | description "Build using MacPorts Clang $clang_ver" {} |
323 | | if {[variant_isset clang$clang_ver_major]} { |
324 | | set selected_clang_v $clang_ver |
325 | | depends_build-append port:clang-$selected_clang_v |
326 | | compiler.whitelist macports-clang-$selected_clang_v |
327 | | build.args-append macports_clang=$selected_clang_v |
328 | | post-configure { |
329 | | if {[get_major $selected_clang_v] != \ |
330 | | $sconstruct_default_mp_clang} \ |
331 | | { |
332 | | if {$subport eq "${name}-3.2"} { |
333 | | set f ${worksrcpath}/SConstruct |
334 | | } else { |
335 | | set f ${worksrcpath}/platform/osx/detect.py |
336 | | } |
337 | | reinplace \ |
338 | | s|$sconstruct_default_mp_clang\.0|$selected_clang_v|g \ |
339 | | $f |
340 | | } |
341 | | } |
342 | | } |
343 | | } |