Ticket #33890: multipcompilers.patch

File multipcompilers.patch, 4.4 KB (added by seanfarley (Sean Farley), 12 years ago)

adds a new port group for generating compiler variants

  • new file dports/_resources/port1.0/group/multiplecompilers-1.0.tcl

    diff --git a/dports/_resources/port1.0/group/multiplecompilers-1.0.tcl b/dports/_resources/port1.0/group/multiplecompilers-1.0.tcl
    new file mode 100644
    - +  
     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$
     3#
     4# Copyright (c) 2012 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 m
     34#
     35# Usage:
     36#
     37#   PortGroup               multiplecompilers 1.0
     38
     39# build database of gcc 4{4..7} compiler attributes
     40foreach v {4 5 6 7} {
     41    set db(gcc4$v,variant)  "gcc4$v"
     42    set db(gcc4$v,compiler) "macports-gcc-4.$v"
     43    set db(gcc4$v,descrip)  "MacPorts gcc 4.$v"
     44    set db(gcc4$v,depends)  port:gcc4$v
     45    set db(gcc4$v,flags)    {
     46        {{"-PIC"} {"-fPIC"}}
     47    }
     48}
     49
     50set db(clang,variant)  clang
     51set db(clang,compiler) clang
     52set db(clang,descrip)  "Mac OS X clang"
     53set db(clang,depends)  bin:clang:clang
     54set db(clang,flags)    {
     55    {{"-PIC"} {"-fPIC"}}
     56}
     57
     58set db(llvm,variant)  llvm
     59set db(llvm,compiler) llvm-gcc-4.2
     60set db(llvm,descrip)  "Mac OS X llvm-gcc 4.2"
     61set db(llvm,depends)  bin:llvm-gcc-4.2:llvm-gcc42
     62set db(llvm,flags)    {
     63    {{"-fPIC"} {"-PIC"}}
     64}
     65
     66set db(system_gcc,variant)  system_gcc
     67set db(system_gcc,compiler) gcc-4.2
     68set db(system_gcc,descrip)  "Mac OS X gcc 4.2"
     69set db(system_gcc,depends)  bin:gcc-4.2:llvm-gcc42
     70set db(system_gcc,flags)    {
     71    {{"-fPIC"} {"-PIC"}}
     72}
     73
     74set variants {}
     75foreach name [array names db *,variant] {
     76    lappend variants $db($name)
     77}
     78
     79foreach variant $variants {
     80    if {[variant_exists $variant]} {
     81        ui_debug "$variant variant already exists, so not adding the default one"
     82    } else {
     83        set i [lsearch -exact $variants $variant]
     84        set c [lreplace $variants $i $i]
     85
     86        # for each pair of flags (old,new), build a string of if statements to replace old with new
     87        set f ""
     88        foreach flag $db($variant,flags) {
     89            foreach {old new} $flag {
     90                append f [subst {
     91                    if {\[string first $old \${configure.cflags}\] > -1} {
     92                        configure.cflags-delete $old
     93                        configure.cflags-append $new
     94                    }
     95                    if {\[string first $old \${configure.cxxflags}\] > -1} {
     96                        configure.cxxflags-delete $old
     97                        configure.cxxflags-append $new
     98                    }
     99                }]
     100            }
     101        }
     102
     103        eval [subst {
     104            variant ${variant} description {Build using the $db($variant,descrip) compiler} conflicts $c {
     105                depends_lib-append $db($variant,depends)
     106                configure.compiler $db($variant,compiler)
     107
     108                $f
     109            }
     110        }]
     111    }
     112}
     113
     114default_variants +clang