source: trunk/dports/_resources/port1.0/group/compilers-1.0.tcl @ 148770

Last change on this file since 148770 was 148770, checked in by dstrubbe@…, 3 years ago

compilers portgroup: Add gcc7. Fix comments.

  • Property svn:keywords set to Id
File size: 26.2 KB
Line 
1# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2# $Id: compilers-1.0.tcl 148770 2016-05-17 18:20:52Z dstrubbe@macports.org $
3#
4# Copyright (c) 2014 The MacPorts Project
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions are
9# met:
10#
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16# 3. Neither the name of The MacPorts Project nor the names of its
17#    contributors may be used to endorse or promote products derived from
18#    this software without specific prior written permission.
19#
20# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31#
32#
33# This PortGroup sets up default variants for projects that want multiple
34# compilers for providing options for, example, different optimizations. More
35# importantly, this port group provides the ability to interact with packages
36# that need MPI since MPI is just a wrapper around a compiler.
37#
38# Usage:
39#
40#   PortGroup               compilers 1.0
41#
42# Available procedures:
43# compilers.choose {args}
44#   Possible arguments: cc cxx cpp objc fc f77 f90
45#   A list of which of these compilers you want to be set by the variants (e.g. ${configure.cc}).
46#   The default is all of them. Must come before compilers.setup in the Portfile to have an effect.
47# compilers.set_variants_conflict {args}
48#   Add specified variants to the conflicts list of all variants created by this PortGroup.
49#   Useful if another compiler variant is created explicitly in the Portfile. Must come before compilers.setup.
50# compilers.setup {args}
51#   Possible arguments: any compiler variant name with a minus removes it from the list of variants, e.g. -llvm.
52#   -gcc, -dragonegg, -clang remove all compilers of that category. -fortran removes gfortran and g95.
53#   Blacklisted compilers are automatically removed, as are ones that do not support the compilers in compilers.choose:
54#   e.g. if choose is just f90, clang variants will not be added.
55#   This procedure must be in the Portfile to create all the compiler variants and set the default.
56#   Appropriate conflicts, dependencies, etc. are created too.
57#   If a variant is declared already in the Portfile before this line, it will not be redefined.
58# c_active_variant_name {depspec}: which C variant a dependency has set
59# c_variant_name {}: which C variant is set
60# c_variant_isset {}: is a C variant set
61# fortran_active_variant_name {depspec}: which Fortran variant a dependency has set
62# fortran_variant_name {}: which Fortran variant is set
63# fortran_compiler_name {arg}:  converts gfortran into the actual Fortran compiler name; otherwise returns arg
64# clang_variant_isset {}: is a clang variant set
65# clang_variant_name {}: which clang variant is set
66# gcc_variant_isset {}: is a GCC variant set
67# gcc_variant_name {}: which GCC variant is set
68# avx_compiler_isset {}: is a C compiler supporting AVX set
69# fortran_variant_isset {}: is a Fortran variant set
70# compilers.enforce_c {args}: enforce that a dependency has the same C variant as is set here
71# compilers.enforce_fortran {args}: enforce that a dependency has the same Fortran variant as is set here
72# compilers.enforce_some_fortran {args}: enforce that a dependency has some Fortran variant set
73#
74# Options:
75# compilers.clear_archflags: disable archflags ("-arch x86_64", -m64, etc.)
76#
77# The compilers.gcc_default variable may be useful for setting a default compiler variant
78# even in ports that do not use this PortGroup's automatic creation of variants.
79# compilers.libfortran is for use in linking Fortran code with the C or C++ compiler
80
81PortGroup active_variants 1.1
82
83options compilers.variants compilers.gcc_variants compilers.clear_archflags
84default compilers.variants {}
85default compilers.fortran_variants {}
86default compilers.gcc_variants {}
87default compilers.clang_variants {}
88default compilers.dragonegg_variants {}
89default compilers.require_fortran 0
90default compilers.setup_done 0
91default compilers.required_c {}
92default compilers.required_f {}
93default compilers.required_some_f {}
94default compilers.variants_conflict {}
95default compilers.libfortran {}
96default compilers.clear_archflags yes
97
98# also set a default gcc version
99set compilers.gcc_default gcc5
100
101set compilers.list {cc cxx cpp objc fc f77 f90}
102
103# build database of gcc compiler attributes
104set gcc_versions {44 45 46 47 48 49 5 6 7}
105foreach v ${gcc_versions} {
106    # if the string is more than one character insert a '.' into it: e.g 49 -> 4.9
107    set version $v
108    if {[string length $v] > 1} {
109        set version [string index $v 0].[string index $v 1]
110    }
111    lappend compilers.gcc_variants gcc$v
112    set cdb(gcc$v,variant)  gcc$v
113    set cdb(gcc$v,compiler) macports-gcc-$version
114    set cdb(gcc$v,descrip)  "MacPorts gcc $version"
115    set cdb(gcc$v,depends)  port:gcc$v
116    set cdb(gcc$v,dependsl) path:lib/libgcc/libgcc_s.1.dylib:libgcc
117    set cdb(gcc$v,libfortran) ${prefix}/lib/gcc$v/libgfortran.dylib
118    # note: above is ultimately a symlink to ${prefix}/lib/libgcc/libgfortran.3.dylib
119    set cdb(gcc$v,dependsd) port:g95
120    set cdb(gcc$v,dependsa) gcc$v
121    set cdb(gcc$v,conflict) "gfortran g95"
122    set cdb(gcc$v,cc)       ${prefix}/bin/gcc-mp-$version
123    set cdb(gcc$v,cxx)      ${prefix}/bin/g++-mp-$version
124    set cdb(gcc$v,cpp)      ${prefix}/bin/cpp-mp-$version
125    set cdb(gcc$v,objc)     ${prefix}/bin/gcc-mp-$version
126    set cdb(gcc$v,fc)       ${prefix}/bin/gfortran-mp-$version
127    set cdb(gcc$v,f77)      ${prefix}/bin/gfortran-mp-$version
128    set cdb(gcc$v,f90)      ${prefix}/bin/gfortran-mp-$version
129}
130
131set clang_versions {33 34 35 36 37 38}
132foreach v ${clang_versions} {
133    # if the string is more than one character insert a '.' into it: e.g 33 -> 3.3
134    set version $v
135    if {[string length $v] > 1} {
136        set version [string index $v 0].[string index $v 1]
137    }
138    lappend compilers.clang_variants clang$v
139    set cdb(clang$v,variant)  clang$v
140    set cdb(clang$v,compiler) macports-clang-$version
141    set cdb(clang$v,descrip)  "MacPorts clang $version"
142    set cdb(clang$v,depends)  port:clang-$version
143    set cdb(clang$v,dependsl) ""
144    set cdb(clang$v,libfortran) ""
145    set cdb(clang$v,dependsd) ""
146    set cdb(clang$v,dependsa) clang-$version
147    set cdb(clang$v,conflict) ""
148    set cdb(clang$v,cc)       ${prefix}/bin/clang-mp-$version
149    set cdb(clang$v,cxx)      ${prefix}/bin/clang++-mp-$version
150    set cdb(clang$v,cpp)      "${prefix}/bin/clang-mp-$version -E"
151    set cdb(clang$v,objc)     ""
152    set cdb(clang$v,fc)       ""
153    set cdb(clang$v,f77)      ""
154    set cdb(clang$v,f90)      ""
155}
156
157# dragonegg versions match the corresponding clang version until 3.5
158set dragonegg_versions {3 4}
159foreach v ${dragonegg_versions} {
160    lappend compilers.dragonegg_variants dragonegg3$v
161    set cdb(dragonegg3$v,variant)  dragonegg3$v
162    set cdb(dragonegg3$v,compiler) macports-dragonegg-3.$v
163    set cdb(dragonegg3$v,descrip)  "MacPorts dragonegg 3.$v"
164    set cdb(dragonegg3$v,depends)  path:bin/dragonegg-3.$v-gcc:dragonegg-3.$v
165    set cdb(dragonegg3$v,dependsl) path:lib/libgcc/libgcc_s.1.dylib:libgcc
166    set cdb(dragonegg3$v,libfortran) ${prefix}/lib/gcc46/libgfortran.dylib
167    set cdb(dragonegg3$v,dependsd) port:g95
168    set cdb(dragonegg3$v,dependsa) dragonegg-3.$v
169    set cdb(dragonegg3$v,conflict) "gfortran g95"
170    set cdb(dragonegg3$v,cc)       ${prefix}/bin/dragonegg-3.$v-gcc
171    set cdb(dragonegg3$v,cxx)      ${prefix}/bin/dragonegg-3.$v-g++
172    set cdb(dragonegg3$v,cpp)      ${prefix}/bin/dragonegg-3.$v-cpp
173    set cdb(dragonegg3$v,objc)     ""
174    set cdb(dragonegg3$v,fc)       ${prefix}/bin/dragonegg-3.$v-gfortran
175    set cdb(dragonegg3$v,f77)      ${prefix}/bin/dragonegg-3.$v-gfortran
176    set cdb(dragonegg3$v,f90)      ${prefix}/bin/dragonegg-3.$v-gfortran
177}
178
179set cdb(llvm,variant)  llvm
180set cdb(llvm,compiler) llvm-gcc-4.2
181set cdb(llvm,descrip)  "Apple native llvm-gcc 4.2"
182set cdb(llvm,depends)  bin:llvm-gcc-4.2:llvm-gcc42
183set cdb(llvm,dependsl) ""
184set cdb(llvm,libfortran) ""
185set cdb(llvm,dependsd) ""
186set cdb(llvm,dependsa) ""
187set cdb(llvm,conflict) ""
188set cdb(llvm,cc)       llvm-gcc-4.2
189set cdb(llvm,cxx)      llvm-g++-4.2
190set cdb(llvm,cpp)      llvm-cpp-4.2
191set cdb(llvm,objc)     llvm-gcc-4.2
192set cdb(llvm,fc)       ""
193set cdb(llvm,f77)      ""
194set cdb(llvm,f90)      ""
195
196# and lastly we add a gfortran and g95 variant for use with clang* and llvm; note that
197# we don't need gfortran when we are in an "only-fortran" mode
198set cdb(gfortran,variant)  gfortran
199set cdb(gfortran,compiler) gfortran
200set cdb(gfortran,descrip)  "$cdb(${compilers.gcc_default},descrip) Fortran"
201set cdb(gfortran,depends)  $cdb(${compilers.gcc_default},depends)
202set cdb(gfortran,dependsl) $cdb(${compilers.gcc_default},dependsl)
203set cdb(gfortran,libfortran) $cdb(${compilers.gcc_default},libfortran)
204set cdb(gfortran,dependsd) $cdb(${compilers.gcc_default},dependsd)
205set cdb(gfortran,dependsa) $cdb(${compilers.gcc_default},dependsa)
206set cdb(gfortran,conflict) $cdb(${compilers.gcc_default},conflict)
207set cdb(gfortran,cc)       ""
208set cdb(gfortran,cxx)      ""
209set cdb(gfortran,cpp)      ""
210set cdb(gfortran,objc)     ""
211set cdb(gfortran,fc)       $cdb(${compilers.gcc_default},fc)
212set cdb(gfortran,f77)      $cdb(${compilers.gcc_default},f77)
213set cdb(gfortran,f90)      $cdb(${compilers.gcc_default},f90)
214
215set cdb(g95,variant)  g95
216set cdb(g95,compiler) g95
217set cdb(g95,descrip)  "g95 Fortran"
218set cdb(g95,depends)  port:g95
219set cdb(g95,dependsl) ""
220set cdb(g95,libfortran) ${prefix}/lib/g95/x86_64-apple-darwin14/4.2.4/libf95.a
221set cdb(g95,dependsd) ""
222set cdb(g95,dependsa) g95
223set cdb(g95,conflict) ""
224set cdb(g95,cc)       ""
225set cdb(g95,cxx)      ""
226set cdb(g95,cpp)      ""
227set cdb(g95,objc)     ""
228set cdb(g95,fc)       ${prefix}/bin/g95
229set cdb(g95,f77)      ${prefix}/bin/g95
230set cdb(g95,f90)      ${prefix}/bin/g95
231
232foreach cname [array names cdb *,variant] {
233    lappend compilers.variants $cdb($cname)
234}
235
236foreach variant ${compilers.variants} {
237    if {$cdb($variant,f77) ne ""} {
238        lappend compilers.fortran_variants $variant
239    }
240}
241
242proc compilers.set_variants_conflict {args} {
243    global compilers.variants_conflict
244
245    lappend compilers.variants_conflict $args
246}
247
248proc compilers.setup_variants {args} {
249    global cdb compilers.variants compilers.clang_variants compilers.gcc_variants
250    global compilers.dragonegg_variants compilers.fortran_variants compilers.list
251    global compilers.variants_conflict
252    global compilers.clear_archflags
253
254    foreach variant [split $args] {
255        if {$cdb($variant,f77) ne ""} {
256            lappend compilers.fortran_variants $variant
257        }
258
259        if {[variant_exists $variant]} {
260            ui_debug "$variant variant already exists, so not adding the default one"
261        } else {
262            set i [lsearch -exact ${compilers.variants} $variant]
263            set c [lreplace ${compilers.variants} $i $i]
264
265            # Fortran compilers do not conflict with C compilers.
266            # thus, llvm and clang do not conflict with g95 and gfortran
267            if {$variant eq "gfortran" || $variant eq "g95"} {
268                foreach clangcomp [concat ${compilers.clang_variants} {llvm}] {
269                    set i [lsearch -exact $c $clangcomp]
270                    set c [lreplace $c $i $i]
271                }
272            } elseif {[string match clang* $variant] || $variant == "llvm"} {
273                set i [lsearch -exact $c gfortran]
274                set c [lreplace $c $i $i]
275                set i [lsearch -exact $c g95]
276                set c [lreplace $c $i $i]
277            }
278
279            # only add conflicts from the compiler database (set above) if we
280            # actually have the compiler in the list of allowed variants
281            foreach j $cdb($variant,conflict) {
282                if {[lsearch -exact $j ${compilers.variants}] > -1} {
283                    lappend c $j
284                }
285            }
286
287            # for each compiler, set the value if not empty; we can't use
288            # configure.compiler because of dragonegg and possibly other new
289            # compilers that aren't in macports portconfigure.tcl
290            set comp ""
291            foreach compiler ${compilers.list} {               
292                if {$cdb($variant,$compiler) ne ""} {
293                    append comp [subst {
294                        configure.$compiler $cdb($variant,$compiler)
295
296                        # disable archflags
297                        if {${compilers.clear_archflags} && "[info command configure.${compiler}_archflags]" ne ""} {
298                            configure.${compiler}_archflags
299                            configure.ld_archflags
300                        }
301                    }]
302                }
303            }
304
305            eval [subst {
306                variant ${variant} description \
307                    {Build using the $cdb($variant,descrip) compiler} \
308                    conflicts $c ${compilers.variants_conflict} {
309
310                    depends_build-append   $cdb($variant,depends)
311                    depends_lib-append     $cdb($variant,dependsl)
312                    depends_lib-delete     $cdb($variant,dependsd)
313                    depends_skip_archcheck $cdb($variant,dependsa)
314
315                    set compilers.libfortran $cdb($variant,libfortran)
316                    $comp
317                }
318            }]
319        }
320    }
321}
322
323foreach variant ${compilers.gcc_variants} {
324    # we need to check the default_variants so we can't use variant_isset
325    if {[info exists variations($variant)] && $variations($variant) eq "+"} {
326        depends_lib-delete      port:g95
327        break
328    }
329}
330
331proc c_active_variant_name {depspec} {
332    global compilers.variants compilers.fortran_variants
333    set c_list [remove_from_list ${compilers.variants} {gfortran g95}]
334
335    foreach c $c_list {
336        if {![catch {set result [active_variants $depspec $c ""]}]} {
337            if {$result} {
338                return $c
339            }
340        } else {
341            ui_warn "c_active_variant_name: \[active_variants $depspec $fc \"\"\] fails."
342        }
343    }
344
345    return ""
346}
347
348proc c_variant_name {} {
349    global compilers.variants compilers.fortran_variants
350    set c_list [remove_from_list ${compilers.variants} {gfortran g95}]
351
352    foreach cc $c_list {
353        if {[variant_isset $cc]} {
354            return $cc
355        }
356    }
357
358    return ""
359}
360
361proc c_variant_isset {} {
362    return [expr {[c_variant_name] ne ""}]
363}
364
365proc fortran_active_variant_name {depspec} {
366    global compilers.fortran_variants
367
368    foreach fc ${compilers.fortran_variants} {
369        if {![catch {set result [active_variants $depspec $fc ""]}]} {
370            if {$result} {
371                return $fc
372            }
373        } else {
374            ui_warn "fortran_active_variant_name: \[active_variants $depspec $fc \"\"\] fails."
375        }
376    }
377
378    return ""
379}
380
381proc fortran_compiler_name {variant} {
382    global compilers.gcc_default
383
384    if {$variant eq "gfortran"} {
385        return ${compilers.gcc_default}
386    } else {
387        return $variant
388    }
389}
390
391proc fortran_variant_name {} {
392    global compilers.fortran_variants variations
393
394    foreach fc ${compilers.fortran_variants} {
395        # we need to check the default_variants so we can't use variant_isset
396        if {[info exists variations($fc)] && $variations($fc) eq "+"} {
397            return $fc
398        }
399    }
400
401    return ""
402}
403
404proc clang_variant_name {} {
405    global compilers.clang_variants compilers.dragonegg_variants variations
406
407    foreach c ${compilers.clang_variants} {
408        # we need to check the default_variants so we can't use variant_isset
409        if {[info exists variations($c)] && $variations($c) eq "+"} {
410            return $c
411        }
412    }
413
414    foreach c ${compilers.dragonegg_variants} {
415        # we need to check the default_variants so we can't use variant_isset
416        if {[info exists variations($c)] && $variations($c) eq "+"} {
417            return $c
418        }
419    }
420
421    return ""
422}
423
424proc clang_variant_isset {} {
425    return [expr {[clang_variant_name] ne ""}]
426}
427
428proc gcc_variant_name {} {
429    global compilers.gcc_variants variations
430
431    foreach c ${compilers.gcc_variants} {
432        # we need to check the default_variants so we can't use variant_isset
433        if {[info exists variations($c)] && $variations($c) eq "+"} {
434            return $c
435        }
436    }
437
438    return ""
439}
440
441proc gcc_variant_isset {} {
442    return [expr {[gcc_variant_name] ne ""}]
443}
444
445proc avx_compiler_isset {} {
446    global configure.cc
447
448    set cc ${configure.cc}
449
450    # check for mpi
451    if {[string match *mpi* $cc]} {
452        set cc [exec ${configure.cc} -show]
453    }
454
455    if {[string match *clang* $cc]} {
456        return 1
457    }
458
459    return 0
460}
461
462proc fortran_variant_isset {} {
463    return [expr {[fortran_variant_name] ne ""}]
464}
465
466# remove all elements in R from L
467proc remove_from_list {L R} {
468    foreach e $R {
469        set idx [lsearch $L $e]
470        set L [lreplace $L $idx $idx]
471    }
472    return $L
473}
474
475# add all elements in R from L
476proc add_from_list {L A} {
477    return [concat $L $A]
478}
479
480proc compilers.choose {args} {
481    global compilers.list
482
483    # zero out the variable before and append args
484    set compilers.list {}
485    foreach v $args {
486        lappend compilers.list $v
487    }
488}
489
490proc compilers.is_fortran_only {} {
491    global compilers.list
492
493    foreach c {cc cxx cpp objc} {
494        if {[lsearch -exact ${compilers.list} $c] >= 0} {
495            return 0
496        }
497    }
498
499    return 1
500}
501
502proc compilers.is_c_only {} {
503    global compilers.list
504
505    foreach c {f77 f90 fc} {
506        if {[lsearch -exact ${compilers.list} $c] >= 0} {
507            return 0
508        }
509    }
510
511    return 1
512}
513
514proc compilers.enforce_c {args} {
515    global compilers.required_c
516    foreach portname $args {
517        lappend compilers.required_c $portname
518    }
519}
520
521proc compilers.action_enforce_c {args} {
522    ui_debug "compilers.enforce_c list: ${args}"
523    foreach portname $args {
524        if {![catch {set result [active_variants $portname "" ""]}]} {
525            set otcomp  [c_active_variant_name $portname]
526            set mycomp  [c_variant_name]
527
528            if {$otcomp ne "" && $mycomp eq ""} {
529                default_variants +$otcomp
530            } elseif {$otcomp ne $mycomp} {
531                ui_error "Install $portname +$mycomp"
532                return -code error "$portname +$mycomp not installed"
533            }
534        } else {
535            ui_error "Internal error: compilers.enforce_c: '$portname' is not an installed port."
536            return -code error "Internal error: compilers.enforce_c: '$portname' is not an installed port."
537        }
538    }
539}
540
541proc compilers.enforce_fortran {args} {
542    global compilers.required_f
543    foreach portname $args {
544        lappend compilers.required_f $portname
545    }
546}
547
548proc compilers.enforce_some_fortran {args} {
549    global compilers.required_some_f
550    foreach portname $args {
551        lappend compilers.required_some_f $portname
552    }
553}
554
555proc compilers.action_enforce_f {args} {
556    ui_debug "compilers.enforce_fortran list: ${args}"
557    foreach portname $args {
558        if {![catch {set result [active_variants $portname "" ""]}]} {
559            set otf  [fortran_active_variant_name $portname]
560            set myf  [fortran_variant_name]
561
562            if {$otf ne "" && $myf eq ""} {
563                default_variants +$otf
564            } elseif {[fortran_compiler_name $otf] ne [fortran_compiler_name $myf]} {
565                # what if $portname does not have that variant? e.g. maybe it has only gcc5 and we are asking for gfortran.
566                ui_error "Install $portname +$myf"
567                return -code error "$portname +$myf not installed"
568            }
569        } else {
570            ui_error "Internal error: compilers.enforce_fortran: '$portname' is not an installed port."
571            return -code error "Internal error: compilers.enforce_fortran: '$portname' is not an installed port."
572        }
573    }
574}
575
576proc compilers.action_enforce_some_f {args} {
577    ui_debug "compilers.enforce_some_fortran list: ${args}"   
578    foreach portname $args {
579        if {![catch {set result [active_variants $portname "" ""]}]} {
580            if {[fortran_active_variant_name $portname] eq ""} {
581                ui_error "Install $portname with a Fortran variant (e.g. +gfortran, +gccX, +g95)"
582                return -code error "$portname not installed with a Fortran variant"
583            }
584        } else {
585            ui_error "Internal error: compilers.enforce_some_fortran: '$portname' is not an installed port."
586            return -code error "Internal error: compilers.enforce_some_fortran: '$portname' is not an installed port."
587        }
588    }
589}
590
591proc compilers.setup {args} {
592    global cdb compilers.variants compilers.clang_variants compilers.gcc_variants
593    global compilers.dragonegg_variants compilers.fortran_variants
594    global compilers.require_fortran compilers.setup_done compilers.list
595    global compilers.gcc_default
596    global compiler.blacklist
597
598    if {!${compilers.setup_done}} {
599        set add_list {}
600        set remove_list ${compilers.variants}
601
602        # if we are only setting fortran compilers, then we are in "only fortran
603        # mode", i.e. we just need +gccXY and +dragoneggXY for the fortran
604        # compilers so we remove +clangXY and +llvm
605        if {[compilers.is_fortran_only]} {
606            # remove gfortran since that only exists to "complete" clang/llvm
607            set remove_list [remove_from_list ${compilers.fortran_variants} gfortran]
608        } elseif {[compilers.is_c_only]} {
609            # remove gfortran and g95 since those are purely for fortran
610            set remove_list [remove_from_list ${compilers.variants} {gfortran g95}]
611        }
612
613        foreach v $args {
614            # if any negated compiler (e.g. -gcc47) is specified then we are
615            # removing from the default, complete list
616            set mode add
617            if {[string first - $v] == 0} {
618                set mode remove
619
620                #strip the beginning '-' character
621                set v [string range $v 1 end]
622            }
623
624            # handle special cases, such as 'gcc' -> all gcc variants
625            switch -exact $v {
626                gcc {
627                    set ${mode}_list [${mode}_from_list [expr $${mode}_list] ${compilers.gcc_variants}]
628                }
629                dragonegg {
630                    set ${mode}_list [${mode}_from_list [expr $${mode}_list] ${compilers.dragonegg_variants}]
631                }
632                fortran {
633                    # here we just check gfortran and g95, not every fortran
634                    # compatible variant since it makes more sense to specify
635                    # 'fortran' to mean add just the +gfortran and +g95 variants
636                    set ${mode}_list [${mode}_from_list [expr $${mode}_list] {gfortran g95}]
637
638                }
639                clang {
640                    set ${mode}_list [${mode}_from_list [expr $${mode}_list] ${compilers.clang_variants}]
641                }
642                require_fortran {
643                    # this signals that fortran is required and not optional
644                    set compilers.require_fortran 1
645                }
646                default {
647                    if {[info exists cdb($v,variant)] == 0} {
648                        return -code error "no such compiler: $v"
649                    }
650                    set ${mode}_list [${mode}_from_list [expr $${mode}_list] $cdb($v,variant)]
651                }
652            }
653        }
654
655        # also remove compilers blacklisted
656        foreach compiler ${compiler.blacklist} {
657            set matched no
658            foreach variant ${compilers.variants} {
659                if {[string match $compiler $cdb($variant,compiler)]} {
660                    set matched yes
661                    set remove_list [remove_from_list $remove_list $cdb($variant,variant)]
662                }
663            }
664
665            if {!$matched} {
666                ui_debug "Unmatched blacklisted compiler: $compiler"
667            }
668        }
669
670        # remove duplicates
671        set duplicates {}
672        foreach foo $remove_list {
673            if {[lsearch $add_list $foo] != -1} {
674                lappend duplicates $foo
675            }
676        }
677
678        set compilers.variants [lsort [concat [remove_from_list $remove_list $duplicates] $add_list]]
679        eval compilers.setup_variants ${compilers.variants}
680
681        # reverse the gcc list so that the higher numbered ones are default
682        set ordered_variants {gfortran}
683        set seen 0
684        for {set i [llength ${compilers.gcc_variants}]} {[incr i -1] >= 0} {} {
685            # only add entries after the default gcc (the ones before are
686            # considered beta)
687            set v [lindex ${compilers.gcc_variants} $i]
688            if {${compilers.gcc_default} eq $v} {
689                set seen 1
690            }
691
692            if {$seen} {
693                lappend ordered_variants $v
694            }
695        }
696        lappend ordered_variants {g95}
697
698        if {${compilers.require_fortran} && ![fortran_variant_isset]} {
699            foreach fv $ordered_variants {
700                # if the variant exists, then make it default
701                if {[lsearch -exact ${compilers.variants} $fv] > -1} {
702                    default_variants-append +$fv
703                    break
704                }
705            }
706        }
707
708        set compilers.setup_done 1
709    }
710}
711
712# this might also need to be in pre-archivefetch
713pre-fetch {
714    if {${compilers.require_fortran} && [fortran_variant_name] eq ""} {
715        return -code error "must set at least one Fortran variant"
716    }
717    eval compilers.action_enforce_c ${compilers.required_c}
718    eval compilers.action_enforce_f ${compilers.required_f}
719    eval compilers.action_enforce_some_f ${compilers.required_some_f}
720}
Note: See TracBrowser for help on using the repository browser.