gcc-4.2 vs apple-gcc-4.2

Ryan Schmidt ryandesign at macports.org
Sat Jan 14 20:14:46 PST 2012


On this page:

https://trac.macports.org/wiki/PortfileRecipes#compiler

We have this block of code we recommend portfile authors use when neither clang nor llvm-gcc-4.2 will work, to fall back to gcc-4.2 if that exists, or install and use apple-gcc42 if not:

if {${configure.compiler} == "clang" ||
    ${configure.compiler} == "llvm-gcc-4.2"} {
    configure.compiler gcc-4.2
    if {![file executable ${configure.cc}]} {
        depends_build-append port:apple-gcc42
        configure.compiler apple-gcc-4.2
        # base (as of 2.0.3) doesn't set cxx for apple-gcc-4.2
        configure.cxx ${prefix}/bin/g++-apple-4.2
    }
}

The hope of this code is that on Xcode 4.0 and 4.1, Xcode's gcc-4.2 compiler will be used, and on Xcode 4.2 and up, where gcc is no longer included, the apple-gcc42 port will be built and used.

The problem, we're discovering, is that upgrading to Xcode 4.2 does not remove the gcc compilers previous Xcode versions might have installed. So, a user with Xcode 4.2 might very well have a copy of gcc-4.2 that came from, say, Xcode 3.2. In some cases this will not work and will cause bug reports like this:

https://trac.macports.org/ticket/32811

I suggest we change the recommended block so that we check not for the executability of configure.cc, but for the Xcode version; on Xcode 4.2 and up, we should use apple-gcc42, even if an old gcc-4.2 is still there.

So instead of:

    if {![file executable ${configure.cc}]} {

We should use:

    if {[vercmp $xcodeversion 4.2] >= 0} {

Comments?




More information about the macports-dev mailing list