/
portconfigure.tcl
1557 lines (1458 loc) · 62.6 KB
/
portconfigure.tcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:filetype=tcl:et:sw=4:ts=4:sts=4
#
# Copyright (c) 2007 - 2015 The MacPorts Project
# Copyright (c) 2007 Markus W. Weissmann <mww@macports.org>
# Copyright (c) 2002 - 2003 Apple Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of Apple Inc. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
package provide portconfigure 1.0
package require portutil 1.0
set org.macports.configure [target_new org.macports.configure portconfigure::configure_main]
target_provides ${org.macports.configure} configure
target_requires ${org.macports.configure} main fetch checksum extract patch
target_prerun ${org.macports.configure} portconfigure::configure_start
namespace eval portconfigure {
}
# ********** BEGIN C++ / OBJECTIVE-C++ **********
options configure.cxx \
configure.cxx_archflags \
configure.cxx_stdlib \
configure.cxxflags \
configure.objcxx \
configure.objcxx_archflags \
configure.objcxxflags \
configure.universal_cxxflags \
configure.universal_objcxxflags
default configure.cxx {[portconfigure::configure_get_compiler cxx]}
default configure.cxx_archflags {[portconfigure::configure_get_archflags cxx]}
default configure.cxx_stdlib {[portconfigure::configure_get_cxx_stdlib]}
default configure.cxxflags \
{[portconfigure::construct_cxxflags ${configure.optflags}]}
default configure.objcxx {[portconfigure::configure_get_compiler objcxx]}
default configure.objcxx_archflags {[portconfigure::configure_get_archflags objcxx]}
# No current reason for OBJCXXFLAGS to differ from CXXFLAGS.
default configure.objcxxflags {${configure.cxxflags}}
default configure.universal_cxxflags {[portconfigure::configure_get_universal_archflags]}
default configure.universal_objcxxflags {${configure.universal_cxxflags}}
# Don't let Portfiles trash "-stdlib"; if they want to remove it, they
# should clear configure.cxx_stdlib.
option_proc configure.cxxflags portconfigure::stdlib_trace
option_proc configure.objcxxflags portconfigure::stdlib_trace
proc portconfigure::should_add_stdlib {} {
set has_stdlib [expr {[option configure.cxx_stdlib] ne ""}]
set is_clang [string match *clang* [option configure.cxx]]
return [expr {$has_stdlib && $is_clang}]
}
proc portconfigure::should_add_cxx_abi {} {
# prior to OS X Mavericks, libstdc++ was the default C++ runtime, so
# assume MacPorts libstdc++ must be ABI compatible with system libstdc++
# for OS X Mavericks and above, users must select libstdc++, so
# assume they want default ABI compatibility
# see https://gcc.gnu.org/onlinedocs/gcc-5.2.0/libstdc++/manual/manual/using_dual_abi.html
return [expr {
[option configure.cxx_stdlib] eq "macports-libstdc++" &&
[option os.platform] eq "darwin" &&
[option os.major] < 13
}]
}
proc portconfigure::construct_cxxflags {flags} {
if {[portconfigure::should_add_stdlib]} {
lappend flags -stdlib=[option configure.cxx_stdlib]
}
if {[portconfigure::should_add_cxx_abi]} {
lappend flags -D_GLIBCXX_USE_CXX11_ABI=0
}
return $flags
}
proc portconfigure::stdlib_trace {opt action args} {
foreach flag [lsearch -all -inline [option $opt] -stdlib=*] {
$opt-delete $flag
}
foreach flag [lsearch -all -inline [option $opt] -D_GLIBCXX_USE_CXX11_ABI=0] {
$opt-delete $flag
}
if {$action eq "read"} {
if {[portconfigure::should_add_stdlib]} {
$opt-append -stdlib=[option configure.cxx_stdlib]
}
if {[portconfigure::should_add_cxx_abi]} {
$opt-append -D_GLIBCXX_USE_CXX11_ABI=0
}
}
}
# helper function to set configure.cxx_stdlib
proc portconfigure::configure_get_cxx_stdlib {} {
global cxx_stdlib compiler.cxx_standard
if {${compiler.cxx_standard} eq ""} {
return ""
} elseif {${cxx_stdlib} eq "libstdc++" && ${compiler.cxx_standard} >= 2011} {
return macports-libstdc++
} else {
return ${cxx_stdlib}
}
}
# ********** END C++ / OBJECTIVE-C++ **********
# ********** Begin Fortran **********
options \
compiler.require_fortran \
compiler.fortran_fallback
default compiler.require_fortran no
default compiler.fortran_fallback {[portconfigure::get_fortran_fallback]}
# ********** End Fortran **********
# define options
commands configure autoreconf automake autoconf xmkmf
# defaults
default configure.env ""
default configure.pre_args {--prefix=${prefix}}
default configure.cmd ./configure
default configure.nice {${buildnicevalue}}
default configure.dir {${worksrcpath}}
default autoreconf.dir {${worksrcpath}}
default autoreconf.args "--install --verbose"
default autoconf.dir {${worksrcpath}}
default autoconf.args --verbose
default automake.dir {${worksrcpath}}
default automake.args --verbose
default xmkmf.cmd xmkmf
default xmkmf.dir {${worksrcpath}}
default use_configure yes
option_proc use_autoreconf portconfigure::set_configure_type
option_proc use_automake portconfigure::set_configure_type
option_proc use_autoconf portconfigure::set_configure_type
option_proc use_xmkmf portconfigure::set_configure_type
option_proc autoreconf.cmd portconfigure::set_configure_type
option_proc automake.cmd portconfigure::set_configure_type
option_proc autoconf.cmd portconfigure::set_configure_type
option_proc xmkmf.cmd portconfigure::set_configure_type
##
# Local helper proc
proc portconfigure::add_build_dep { type dep } {
global ${type}.cmd option_defaults
if {![info exists ${type}.cmd] || (
([info exists option_defaults(${type}.cmd)] && [set ${type}.cmd] eq $option_defaults(${type}.cmd)) ||
(![info exists option_defaults(${type}.cmd)] && [set ${type}.cmd] eq ${type})
)} {
# Add dependencies if they are not already in the list
depends_build-delete {*}$dep
depends_build-append {*}$dep
}
}
##
# Adds dependencies for the binaries which will be called, but only if it is
# the default. If .cmd was overwritten the port has to care for deps itself.
proc portconfigure::set_configure_type {option action args} {
global autoreconf.cmd automake.cmd autoconf.cmd xmkmf.cmd
array set configure_map {
autoconf {port:autoconf port:automake port:libtool}
xmkmf port:imake
}
if {$action eq "set"} {
switch $option {
autoreconf.cmd -
automake.cmd -
autoconf.cmd {
depends_build-delete {*}$configure_map(autoconf)
}
xmkmf.cmd {
depends_build-delete {*}$configure_map(xmkmf)
}
use_xmkmf {
if {[tbool args]} {
depends_build-append {*}$configure_map(xmkmf)
}
}
default {
# strip "use_"
set type [string range $option 4 end]
if {[tbool args]} {
add_build_dep $type $configure_map(autoconf)
}
}
}
}
}
options configure.asroot
default configure.asroot no
# Configure special environment variables.
# We could have m32/m64/march/mtune be global configurable at some point.
options configure.m32 configure.m64 configure.march configure.mtune
default configure.march {}
default configure.mtune {}
# We could have debug/optimizations be global configurable at some point.
options configure.optflags \
configure.cflags \
configure.objcflags \
configure.cppflags configure.ldflags configure.libs \
configure.fflags configure.f90flags configure.fcflags \
configure.classpath
# compiler flags section
default configure.optflags -Os
default configure.cflags {${configure.optflags}}
default configure.objcflags {${configure.optflags}}
default configure.cppflags {-I${prefix}/include}
default configure.ldflags {-L${prefix}/lib -Wl,-headerpad_max_install_names}
default configure.libs {}
default configure.fflags {${configure.optflags}}
default configure.f90flags {${configure.optflags}}
default configure.fcflags {${configure.optflags}}
default configure.classpath {}
# tools section
options configure.perl configure.python configure.ruby \
configure.install configure.awk configure.bison \
configure.pkg_config configure.pkg_config_path
default configure.perl {}
default configure.python {}
default configure.ruby {}
default configure.install {${portutil::autoconf::install_command}}
default configure.awk {}
default configure.bison {}
default configure.pkg_config {}
default configure.pkg_config_path {}
options configure.build_arch configure.ld_archflags \
configure.sdk_version configure.sdkroot \
configure.developer_dir
default configure.build_arch {[portconfigure::choose_supported_archs ${build_arch}]}
default configure.ld_archflags {[portconfigure::configure_get_ld_archflags]}
default configure.sdk_version {$macosx_sdk_version}
default configure.sdkroot {[portconfigure::configure_get_sdkroot ${configure.sdk_version}]}
default configure.developer_dir {[portconfigure::configure_get_developer_dir]}
foreach tool {cc objc f77 f90 fc} {
options configure.${tool}_archflags
default configure.${tool}_archflags "\[portconfigure::configure_get_archflags $tool\]"
}
options configure.universal_archs configure.universal_args \
configure.universal_cflags \
configure.universal_objcflags \
configure.universal_cppflags configure.universal_ldflags
default configure.universal_archs {[portconfigure::choose_supported_archs ${universal_archs}]}
default configure.universal_args --disable-dependency-tracking
default configure.universal_cflags {[portconfigure::configure_get_universal_archflags]}
default configure.universal_objcflags {${configure.universal_cflags}}
default configure.universal_cppflags {}
default configure.universal_ldflags {[portconfigure::configure_get_universal_archflags]}
# Select a distinct compiler (C, C preprocessor, C++)
options configure.ccache configure.distcc configure.pipe configure.cc \
configure.cpp configure.objc configure.f77 \
configure.f90 configure.fc configure.javac configure.compiler \
compiler.blacklist compiler.whitelist compiler.fallback
default configure.ccache {${configureccache}}
default configure.distcc {${configuredistcc}}
default configure.pipe {${configurepipe}}
foreach tool {cc objc cpp f77 f90 fc javac} {
default configure.$tool "\[portconfigure::configure_get_compiler $tool\]"
}
default configure.compiler {[portconfigure::configure_get_default_compiler]}
default compiler.fallback {[portconfigure::get_compiler_fallback]}
default compiler.blacklist {}
default compiler.whitelist {}
# Compiler Restrictions
# compiler.c_standard Standard for the C programming language (1989, 1999, 2011, etc.)
# compiler.cxx_standard Standard for the C++ programming language (1998, 2011, 2014, 2017, etc.)
# compiler.openmp_version Version of OpenMP required (blank, 2.5, 3.0, 3.1, 4.0, 4.5, etc.)
# compiler.mpi MacPorts port that provides MPI (blank, mpich, openmpi)
# compiler.thread_local_storage Is thread local storage required, e.g. __thread, _Thread_local, std::thread_local (yes, no)
options \
compiler.c_standard \
compiler.cxx_standard \
compiler.openmp_version \
compiler.mpi \
compiler.thread_local_storage
default compiler.c_standard {[expr {$supported_archs ne "noarch" ? 1989 : ""}]}
default compiler.cxx_standard {[expr {$supported_archs ne "noarch" ? 1998 : ""}]}
default compiler.openmp_version {}
default compiler.mpi {}
default compiler.thread_local_storage no
set_ui_prefix
proc portconfigure::configure_start {args} {
global UI_PREFIX
ui_notice "$UI_PREFIX [format [msgcat::mc "Configuring %s"] [option subport]]"
set compiler [option configure.compiler]
set valid_compilers {
{^apple-gcc-(4\.[02])$} {MacPorts Apple GCC %s}
{^cc$} {System cc}
{^clang$} {Xcode Clang}
{^gcc$} {System GCC}
{^gcc-(3\.3|4\.[02])$} {Xcode GCC %s}
{^llvm-gcc-4\.2$} {Xcode LLVM-GCC 4.2}
{^macports-clang$} {MacPorts Clang (port select)}
{^macports-clang-(\d+\.\d+)$} {MacPorts Clang %s}
{^macports-gcc$} {MacPorts GCC (port select)}
{^macports-gcc-(\d+(?:\.\d+)?)$} {MacPorts GCC %s}
{^macports-llvm-gcc-4\.2$} {MacPorts LLVM-GCC 4.2}
{^macports-g95$} {MacPorts G95}
{^macports-mpich-default$} {MacPorts MPICH Wrapper for MacPorts' Default C/C++ Compiler}
{^macports-openmpi-default$} {MacPorts Open MPI Wrapper for MacPorts' Default C/C++ Compiler}
{^macports-mpich-clang$} {MacPorts MPICH Wrapper for Xcode Clang}
{^macports-openmpi-clang$} {MacPorts Open MPI Wrapper for Xcode Clang}
{^macports-mpich-clang-(\d+\.\d+)$}
{MacPorts MPICH Wrapper for Clang %s}
{^macports-openmpi-clang-(\d+\.\d+)$}
{MacPorts Open MPI Wrapper for Clang %s}
{^macports-mpich-gcc-(\d+(?:\.\d+)?)$}
{MacPorts MPICH Wrapper for GCC %s}
{^macports-openmpi-gcc-(\d+(?:\.\d+)?)$}
{MacPorts Open MPI Wrapper for GCC %s}
}
foreach {re fmt} $valid_compilers {
if {[set matches [regexp -inline $re $compiler]] ne ""} {
set compiler_name [format $fmt {*}[lrange $matches 1 end]]
break
}
}
if {![info exists compiler_name]} {
return -code error "Invalid value for configure.compiler: $compiler"
}
ui_debug "Preferred compilers: [option compiler.fallback]"
ui_debug "Using compiler '$compiler_name'"
# Additional ccache directory setup
global configure.ccache ccache_dir ccache_size macportsuser
if {${configure.ccache}} {
# Create ccache directory with correct permissions with root privileges
elevateToRoot "configure ccache"
if {[catch {
file mkdir ${ccache_dir}
file attributes ${ccache_dir} -owner ${macportsuser} -permissions 0755
} result]} {
ui_warn "ccache_dir ${ccache_dir} could not be created; disabling ccache: $result"
set configure.ccache no
}
dropPrivileges
# Initialize ccache directory with the given maximum size
if {${configure.ccache}} {
if {[catch {
exec ccache -M ${ccache_size} >/dev/null
} result]} {
ui_warn "ccache_dir ${ccache_dir} could not be initialized; disabling ccache: $result"
set configure.ccache no
}
}
}
}
# internal function to choose the default configure.build_arch and
# configure.universal_archs based on supported_archs and build_arch or
# universal_archs
proc portconfigure::choose_supported_archs {archs} {
global supported_archs configure.sdk_version
# macOS 10.14 SDK only supports one arch, x86_64
if {${configure.sdk_version} ne "" && [vercmp ${configure.sdk_version} 10.14] >= 0} {
if {"x86_64" in $archs && ($supported_archs eq "" || "x86_64" in $supported_archs)} {
return x86_64
} else {
return ""
}
} elseif {$supported_archs eq ""} {
return $archs
}
set ret {}
foreach arch $archs {
if {$arch in $supported_archs} {
set add_arch $arch
} elseif {$arch eq "x86_64" && "i386" in $supported_archs} {
set add_arch "i386"
} elseif {$arch eq "ppc64" && "ppc" in $supported_archs} {
set add_arch "ppc"
} else {
continue
}
if {$add_arch ni $ret} {
lappend ret $add_arch
}
}
return $ret
}
# internal function to determine the compiler flags to select an arch
proc portconfigure::configure_get_archflags {tool} {
global configure.build_arch configure.m32 configure.m64 configure.compiler
set flags ""
if {[tbool configure.m64]} {
set flags "-m64"
} elseif {[tbool configure.m32]} {
set flags "-m32"
} elseif {${configure.build_arch} ne ""} {
if {[arch_flag_supported ${configure.compiler}] &&
$tool in {cc cxx objc objcxx}
} then {
set flags "-arch ${configure.build_arch}"
} elseif {${configure.build_arch} eq "x86_64" || ${configure.build_arch} eq "ppc64"} {
set flags "-m64"
} elseif {${configure.compiler} ne "gcc-3.3"} {
set flags "-m32"
}
}
return $flags
}
# internal function to determine the ld flags to select an arch
# Unfortunately there's no consistent way to do this when the compiler
# doesn't support -arch, because it could be used to link rather than using
# ld directly. So we punt and let portfiles deal with that case.
proc portconfigure::configure_get_ld_archflags {} {
global configure.build_arch configure.compiler
if {${configure.build_arch} ne "" && [arch_flag_supported ${configure.compiler}]} {
return "-arch ${configure.build_arch}"
} else {
return ""
}
}
proc portconfigure::configure_get_sdkroot {sdk_version} {
global developer_dir macosx_version xcodeversion os.arch os.platform use_xcode
# This is only relevant for macOS
if {${os.platform} ne "darwin"} {
return {}
}
# Special hack for Tiger/ppc, since the system libraries do not contain intel slices
if {${os.arch} eq "powerpc" && $macosx_version eq "10.4" && [variant_exists universal] && [variant_isset universal]} {
return ${developer_dir}/SDKs/MacOSX10.4u.sdk
}
# Use the DevSDK (eg: /usr/include) if present and the requested SDK version matches the host version
if {$sdk_version eq $macosx_version && [file exists /usr/include]} {
return {}
}
set cltpath /Library/Developer/CommandLineTools
# Check CLT first if Xcode shouldn't be used
if {![tbool use_xcode]} {
set sdk ${cltpath}/SDKs/MacOSX${sdk_version}.sdk
if {[file exists $sdk]} {
return $sdk
}
if {[info exists ::portconfigure::sdkroot_cache(macosx${sdk_version})]} {
if {$::portconfigure::sdkroot_cache(macosx${sdk_version}) ne ""} {
return $::portconfigure::sdkroot_cache(macosx${sdk_version})
}
# negative result cached, do nothing here
} elseif {![catch {exec env DEVELOPER_DIR=${cltpath} xcrun --sdk macosx${sdk_version} --show-sdk-path 2> /dev/null} sdk]} {
set ::portconfigure::sdkroot_cache(macosx${sdk_version}) $sdk
return $sdk
} else {
set ::portconfigure::sdkroot_cache(macosx${sdk_version}) ""
}
# Fallback on "macosx"
set sdk ${cltpath}/SDKs/MacOSX.sdk
if {[file exists $sdk]} {
return $sdk
}
if {[info exists ::portconfigure::sdkroot_cache(macosx)]} {
if {$::portconfigure::sdkroot_cache(macosx) ne ""} {
return $::portconfigure::sdkroot_cache(macosx)
}
# negative result cached, do nothing here
} elseif {![catch {exec env DEVELOPER_DIR=${cltpath} xcrun --sdk macosx --show-sdk-path 2> /dev/null} sdk]} {
set ::portconfigure::sdkroot_cache(macosx) $sdk
return $sdk
} else {
set ::portconfigure::sdkroot_cache(macosx) ""
}
}
if {[vercmp $xcodeversion 4.3] < 0} {
set sdks_dir ${developer_dir}/SDKs
} else {
set sdks_dir ${developer_dir}/Platforms/MacOSX.platform/Developer/SDKs
}
if {$sdk_version eq "10.4"} {
set sdk ${sdks_dir}/MacOSX10.4u.sdk
} else {
set sdk ${sdks_dir}/MacOSX${sdk_version}.sdk
}
if {[file exists $sdk]} {
return $sdk
}
if {[info exists ::portconfigure::sdkroot_cache(macosx${sdk_version},noclt)]} {
if {$::portconfigure::sdkroot_cache(macosx${sdk_version},noclt) ne ""} {
return $::portconfigure::sdkroot_cache(macosx${sdk_version},noclt)
}
# negative result cached, do nothing here
} elseif {![catch {exec xcrun --sdk macosx${sdk_version} --show-sdk-path 2> /dev/null} sdk]} {
set ::portconfigure::sdkroot_cache(macosx${sdk_version},noclt) $sdk
return $sdk
} else {
set ::portconfigure::sdkroot_cache(macosx${sdk_version},noclt) ""
}
set sdk ${cltpath}/SDKs/MacOSX${sdk_version}.sdk
if {[file exists $sdk]} {
return $sdk
}
set sdk ${sdks_dir}/MacOSX.sdk
if {[file exists $sdk]} {
return $sdk
}
# Support falling back to "macosx" if it is present.
# This leads to problems when it is newer than the base OS because many OSS assume that
# the SDK version matches the deployment target, so they unconditionally try to use
# symbols that are only available on newer OS versions..
# But it's better than not being able to build at all. Recent Xcode released have been able
# to run on 10.x but only include an SDK for 10.x+1. Combined with the disappearance of
# /usr/include, that means not having this fallback would cause great breakage.
# See <https://trac.macports.org/ticket/57143>
if {[info exists ::portconfigure::sdkroot_cache(macosx,noclt)]} {
# no negative-cached case here because that would mean overall failure
return $::portconfigure::sdkroot_cache(macosx,noclt)
} elseif {![catch {exec xcrun --sdk macosx --show-sdk-path 2> /dev/null} sdk]} {
set ::portconfigure::sdkroot_cache(macosx,noclt) $sdk
return $sdk
}
ui_error "Unable to determine location of a macOS SDK."
return -code error "Unable to determine location of a macOS SDK."
}
# internal function to determine DEVELOPER_DIR according to Xcode dependency
proc portconfigure::configure_get_developer_dir {} {
global use_xcode developer_dir
set cltpath "/Library/Developer/CommandLineTools"
# Assume that the existence of libxcselect indiciates the earliest version of
# macOS that places CLT in /Library/Developer/CommandLineTools
# If port is Xcode-dependent or CommandLineTools directory is invalid, set to developer_dir
if {[tbool use_xcode]} {
return ${developer_dir}
} else {
return ${cltpath}
}
}
# internal function to determine the "-arch xy" flags for the compiler
proc portconfigure::configure_get_universal_archflags {} {
global configure.universal_archs
set flags ""
foreach arch ${configure.universal_archs} {
if {$flags eq ""} {
set flags "-arch $arch"
} else {
append flags " -arch $arch"
}
}
return $flags
}
# internal proc to determine if the compiler supports -arch
proc portconfigure::arch_flag_supported {compiler {multiple_arch_flags no}} {
if {${multiple_arch_flags}} {
return [regexp {^gcc-4|llvm|apple|clang} ${compiler}]
} else {
# GCC prior to 4.7 does not accept -arch flag
if {[regexp {^macports(?:-[^-]+)?-gcc-4\.[0-6]} ${compiler}]} {
return no
} else {
return yes
}
}
}
proc portconfigure::compiler_port_name {compiler} {
set valid_compiler_ports {
{^apple-gcc-(\d+)\.(\d+)$} {apple-gcc%s%s}
{^macports-clang-(\d+\.\d+)$} {clang-%s}
{^macports-(llvm-)?gcc-(\d+)(?:\.(\d+))?$} {%sgcc%s%s}
{^macports-(mpich|openmpi|mpich-devel|openmpi-devel)-default$} {%s-default}
{^macports-(mpich|openmpi|mpich-devel|openmpi-devel)-clang$} {%s-clang}
{^macports-(mpich|openmpi|mpich-devel|openmpi-devel)-clang-(\d+)\.(\d+)$} {%s-clang%s%s}
{^macports-(mpich|openmpi|mpich-devel|openmpi-devel)-gcc-(\d+)(?:\.(\d+))?$} {%s-gcc%s%s}
{^macports-g95$} {g95}
}
foreach {re fmt} $valid_compiler_ports {
if {[set matches [regexp -inline $re $compiler]] ne ""} {
return [format $fmt {*}[lrange $matches 1 end]]
}
}
return {}
}
proc portconfigure::compiler_is_port {compiler} {
return [expr {[portconfigure::compiler_port_name ${compiler}] ne ""}]
}
# configure_get_default_compiler is fairly expensive, so cache the result
set ::portconfigure::recompute_default_compiler 1
set ::portconfigure::cached_default_compiler {}
# changing these options will invalidate the cache
foreach varname {compiler.whitelist compiler.fallback compiler.blacklist
compiler.c_standard compiler.cxx_standard compiler.openmp_version
compiler.mpi compiler.thread_local_storage configure.cxx_stdlib} {
trace add variable $varname write portconfigure::recompute_default_compiler_proc
}
proc portconfigure::recompute_default_compiler_proc {varname unused op} {
set ::portconfigure::recompute_default_compiler 1
}
# internal function to determine the default compiler
proc portconfigure::configure_get_default_compiler {} {
if {!$::portconfigure::recompute_default_compiler} {
return $::portconfigure::cached_default_compiler
}
set ::portconfigure::recompute_default_compiler 0
if {[option compiler.whitelist] ne ""} {
set search_list [option compiler.whitelist]
} else {
set search_list [option compiler.fallback]
}
foreach compiler $search_list {
set allowed yes
foreach pattern [option compiler.blacklist] {
if {[string match $pattern $compiler]} {
set allowed no
break
}
}
if {$allowed &&
([file executable [configure_get_compiler cc $compiler]] ||
[compiler_is_port $compiler])
} then {
set ::portconfigure::cached_default_compiler $compiler
return $compiler
}
}
ui_warn "All compilers are either blacklisted or unavailable; defaulting to first fallback option"
set ::portconfigure::cached_default_compiler [lindex [option compiler.fallback] 0]
return $::portconfigure::cached_default_compiler
}
# internal function to determine the Fortran compiler
proc portconfigure::configure_get_fortran_compiler {} {
global configure.compiler
if {[portconfigure::configure_get_compiler fc ${configure.compiler}] ne ""} {
return ${configure.compiler}
}
foreach compiler [option compiler.fortran_fallback] {
set allowed yes
foreach pattern [option compiler.blacklist] {
if {[string match $pattern $compiler]} {
set allowed no
break
}
}
if {$allowed &&
([file executable [configure_get_compiler fc $compiler]] ||
[compiler_is_port $compiler])
} then {
return $compiler
}
}
ui_warn "All Fortran compilers are either blacklisted or unavailable; defaulting to first fallback option"
return [lindex [option compiler.fortran_fallback] 0]
}
#
# internal utility procedure to return the greater of two versions
proc portconfigure::max_version {verA verB} {
if {[vercmp $verA $verB] >= 0} {
return $verA
} else {
return $verB
}
}
#
# https://releases.llvm.org/3.1/docs/ClangReleaseNotes.html#cchanges
# https://gcc.gnu.org/c99status.html
# https://gcc.gnu.org/wiki/C11Status
# https://trac.macports.org/wiki/XcodeVersionInfo
#--------------------------------------------------------------------
#| C Standard | Clang | Xcode Clang | Xcode | GCC |
#|------------------------------------------------------------------|
#| 1989 (C89) | - | - | - | - |
#| 1999 (C99) | - | - | - | 4.0 |
#| 2011 (C11) | 3.1 | 318.0.61 | 4.3 | 4.9 |
#--------------------------------------------------------------------
#
# https://clang.llvm.org/cxx_status.html
# https://gcc.gnu.org/projects/cxx-status.html
# https://en.cppreference.com/w/cpp/compiler_support
# Xcode release notes
# https://trac.macports.org/wiki/XcodeVersionInfo
#--------------------------------------------------------------------
#| C++ Standard | Clang | Xcode Clang | Xcode | GCC |
#|--------------------------------=---------------------------------|
#| 1998 (C++98) | - | - | - | - |
#| 2011 (C++11) | 3.3 | 500.2.75 | 5.0 | 4.8.1 |
#| 2014 (C++14) | 3.4 | 600.0.54 | 6.1 | 5 |
#| 2017 (C++17) | 5.0 | 902.0.39.1 | 9.3 | 7 |
#--------------------------------------------------------------------
#
# https://openmp.llvm.org
# https://gcc.gnu.org/wiki/openmp
# https://trac.macports.org/wiki/XcodeVersionInfo
#----------------------------------------------------------------
#| OpenMP Version | Clang | Xcode Clang | Xcode | GCC |
#|---------------------------------------------------------------
#| 2.5 | 3.8 | Future? | Future? | 4.2 |
#| 3.0 | 3.8 | Future? | Future? | 4.4 |
#| 3.1 | 3.8 | Future? | Future? | 4.7 |
#| 4.0 | Partial | Future? | Future? | 4.9 |
#| 4.5 | Partial | Future? | Future? | ??? |
#----------------------------------------------------------------
#
# utility procedure: get minimum command line compilers version based on restrictions
proc portconfigure::get_min_command_line {compiler} {
global compiler.c_standard compiler.cxx_standard compiler.openmp_version compiler.thread_local_storage os.major
set min_value 1.0
if {${compiler.openmp_version} ne ""} {
return none
}
if {${compiler.thread_local_storage} && ${os.major} < 11} {
# thread-local storage only works on Mac OS X Lion and above
# GCC & MacPorts Clang emulate thread-local storage
return none
}
if {[option configure.cxx_stdlib] eq "macports-libstdc++"} {
return none
}
switch ${compiler} {
clang {
if {[option configure.cxx_stdlib] eq "libc++"} {
if {${os.major} < 11} {
# no Xcode clang can build against libc++ on < 10.7
return none
}
}
if {${compiler.c_standard} >= 2011} {
set min_value [max_version $min_value 318.0.61]
}
if {${compiler.cxx_standard} >= 2017} {
set min_value [max_version $min_value 902.0.39.1]
} elseif {${compiler.cxx_standard} >= 2014} {
set min_value [max_version $min_value 600.0.54]
} elseif {${compiler.cxx_standard} >= 2011} {
set min_value [max_version $min_value 500.2.75]
}
}
llvm-gcc-4.2 -
gcc-4.2 -
gcc-4.0 -
apple-gcc-4.2 {
if {${compiler.c_standard} > 1999 || ${compiler.cxx_standard} >= 2011 || [option configure.cxx_stdlib] eq "libc++"} {
return none
}
}
default {
return -code error "don't recognize compiler \"${compiler}\""
}
}
return ${min_value}
}
# utility procedure: get minimum Clang version based on restrictions
proc portconfigure::get_min_clang {} {
global compiler.c_standard compiler.cxx_standard compiler.openmp_version compiler.thread_local_storage
set min_value 1.0
if {${compiler.c_standard} >= 2011} {
set min_value [max_version $min_value 3.1]
}
if {${compiler.cxx_standard} >= 2017} {
set min_value [max_version $min_value 5.0]
} elseif {${compiler.cxx_standard} >= 2014} {
set min_value [max_version $min_value 3.4]
} elseif {${compiler.cxx_standard} >= 2011} {
set min_value [max_version $min_value 3.3]
}
if {[vercmp ${compiler.openmp_version} 4.0] >= 0} {
set min_value [max_version $min_value 6.0]
} elseif {[vercmp ${compiler.openmp_version} 2.5] >= 0} {
set min_value [max_version $min_value 3.8]
}
if {${compiler.thread_local_storage}} {
# MacPorts patches certain versions of Clang to emulate thread-local storage
set min_value [max_version $min_value 5.0]
}
return ${min_value}
}
# utility procedure: get minimum GCC version based on restrictions
proc portconfigure::get_min_gcc {} {
global compiler.c_standard compiler.cxx_standard compiler.openmp_version compiler.thread_local_storage
if {[option configure.cxx_stdlib] ne "" && [option configure.cxx_stdlib] ne "macports-libstdc++"} {
return none
}
set min_value 1.0
if {${compiler.c_standard} >= 2011} {
set min_value [max_version $min_value 4.3]
} elseif {${compiler.c_standard} >= 1999} {
set min_value [max_version $min_value 4.0]
}
if {${compiler.cxx_standard} >= 2017} {
set min_value [max_version $min_value 7.0]
} elseif {${compiler.cxx_standard} >= 2014} {
set min_value [max_version $min_value 5.0]
} elseif {${compiler.cxx_standard} >= 2011} {
set min_value [max_version $min_value 4.8.1]
}
if {[vercmp ${compiler.openmp_version} 4.5] >= 0} {
set min_value [max_version $min_value 8.1]
} elseif {[vercmp ${compiler.openmp_version} 4.0] >= 0} {
set min_value [max_version $min_value 4.9]
} elseif {[vercmp ${compiler.openmp_version} 3.1] >= 0} {
set min_value [max_version $min_value 4.7]
} elseif {[vercmp ${compiler.openmp_version} 3.0] >= 0} {
set min_value [max_version $min_value 4.4]
} elseif {[vercmp ${compiler.openmp_version} 2.5] >= 0} {
set min_value [max_version $min_value 4.4]
}
if {${compiler.thread_local_storage}} {
# GCC emulates thread-local storage, but it seems to be broken on older versions of GCC
set min_value [max_version $min_value 4.5]
}
return ${min_value}
}
# utility procedure: get minimum Gfortran version based on restrictions
proc portconfigure::get_min_gfortran {} {
global compiler.openmp_version compiler.thread_local_storage
set min_value 1.0
if {[vercmp ${compiler.openmp_version} 4.5] >= 0} {
set min_value [max_version $min_value 8.1]
} elseif {[vercmp ${compiler.openmp_version} 4.0] >= 0} {
set min_value [max_version $min_value 4.9]
} elseif {[vercmp ${compiler.openmp_version} 3.1] >= 0} {
set min_value [max_version $min_value 4.7]
} elseif {[vercmp ${compiler.openmp_version} 2.5] >= 0} {
set min_value [max_version $min_value 4.4]
}
if {${compiler.thread_local_storage}} {
# GCC emulates thread-local storage, but it seems to be broken on older versions of GCC
set min_value [max_version $min_value 4.5]
}
return ${min_value}
}
#
proc portconfigure::g95_ok {} {
global compiler.openmp_version os.platform xcodeversion
if {${os.platform} eq "darwin" && ([vercmp $xcodeversion 9.0] > 0)} {
# see https://github.com/macports/macports-ports/commit/6b905efc9d5586366ac498ed78d6ac51c120d33f
return no
}
if {${compiler.openmp_version} ne ""} {
# G95 does not support OpenMP
return no
}
return yes
}
# utility procedure: get Apple compilers based on Xcode version
proc portconfigure::get_apple_compilers_xcode_version {} {
global xcodeversion
# https://developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Chapters/Introduction.html
# https://developer.apple.com/library/content/documentation/CompilerTools/Conceptual/LLVMCompilerOverview/index.html
# Xcode 3.2 relase notes (Link?)
# About Xcode 3.1 Tools (about_xcode_tools_3.1.pdf, Link?)
# About Xcode 3.2 (about_xcode_3.2.pdf, Link?)
#
# Xcode 5 does not support use of the LLVM-GCC compiler and the GDB debugger.
# From Xcode 4.2, Clang is the default compiler for Mac OS X.
# llvm-gcc4.2 is now the default system compiler in Xcode 4.
# The LLVM compiler is the next-generation compiler, introduced in Xcode 3.2
# GCC 4.0 has been removed from Xcode 4.
#
# attempt to include all available compilers except gcc-3*
# attempt to have the default compilers first
if {[vercmp ${xcodeversion} 5] >= 0} {
set compilers {clang}
} elseif {[vercmp ${xcodeversion} 4.3] >= 0} {
set compilers {clang llvm-gcc-4.2}
} elseif {[vercmp ${xcodeversion} 4.2] >= 0} {
# llvm-gcc is more reliable
# see https://github.com/macports/macports-base/commit/10d62cb51b1f0f9703a873173bac468eee69d01a
set compilers {llvm-gcc-4.2 clang}
} elseif {[vercmp ${xcodeversion} 4.0] >= 0} {
set compilers {llvm-gcc-4.2 clang gcc-4.2}
} else {
# Legacy Cases
if {[string match *10.4u* [option configure.sdkroot]]} {
# from Xcode 3.2 release notes:
# GCC 4.2 cannot be used with the Mac OS X 10.4u SDK.
# If you want to build targets using the 10.4u SDK on Xcode 3.2, you must set the Compiler Version to GCC 4.0
set compilers {gcc-4.0}
} else {
if {[vercmp ${xcodeversion} 3.2] >= 0} {
# from about_xcode_3.2.pdf:
# GCC 4.2 is the primary system compiler for the 10.6 SDK
# clang does *not* provide clang++, but configure.cxx will fall back to llvm-g++-4.2
set compilers {gcc-4.2 llvm-gcc-4.2 clang gcc-4.0}
} elseif {[vercmp ${xcodeversion} 3.1] >= 0} {
# from about_xcode_tools_3.1.pdf:
# GCC 4.2 & LLVM GCC 4.2 optional compilers
# assume they exist
set compilers {gcc-4.2 llvm-gcc-4.2 apple-gcc-4.2 gcc-4.0}
} elseif {[vercmp ${xcodeversion} 3.0] >= 0} {
set compilers {apple-gcc-4.2 gcc-4.0}
} else {
set compilers {apple-gcc-4.2 gcc-4.0}
}
}
}
return $compilers
}
# utility procedure: get compilers created by Apple based on OS version
proc portconfigure::get_apple_compilers_os_version {} {
global os.major
if {${os.major} >= 13} {
# 5.0.1 <= Xcode
set test_compilers {clang}
} elseif {${os.major} >= 12} {
# 4.4 <= Xcode <= 5.1.1
set test_compilers {clang llvm-gcc-4.2}
} elseif {${os.major} >= 11} {
# 4.1 <= Xcode <= 4.6.3
set test_compilers {clang llvm-gcc-4.2 gcc-4.2}
} else {
# Command Line Tools is only available for Mac OS X 10.7 Lion and above
set test_compilers ""
}
set compilers ""
foreach cc ${test_compilers} {
if {[file executable [find_developer_tool $cc]]} {
lappend compilers $cc
}
}
return $compilers
}
# utility procedure: get Clang compilers based on os.major
proc portconfigure::get_clang_compilers {} {
global os.major porturl
set compilers ""
set compiler_file [getportresourcepath $porturl "port1.0/compilers/clang_compilers.tcl"]
if {[file exists ${compiler_file}]} {
source ${compiler_file}
} else {
ui_debug "clang_compilers.tcl not found in ports tree, using built-in selections"
lappend compilers macports-clang-8.0 macports-clang-7.0 macports-clang-6.0 macports-clang-5.0
if {${os.major} < 16} {
# The Sierra SDK requires a toolchain that supports class properties
lappend compilers macports-clang-3.7 macports-clang-3.4
if {${os.major} < 9} {
lappend compilers macports-clang-3.3
}