Opened 5 months ago

Last modified 5 months ago

#57695 new enhancement

Set AR, NM and RANLIB env. variables

Reported by: RJVB (René Bertin) Owned by:
Priority: Normal Milestone:
Component: base Version:
Keywords: Cc:
Port:

Description (last modified by RJVB (René Bertin))

I like to use link time optimisation where feasible and have learned through experience that this can cause link failures in projects that use static libraries (intermediate/private and/or public). This can be avoided by using a more homogeneous toolchain, i.e.

if {[string match *clang++-mp* ${configure.cxx}]} {
    configure.env-append \
                AR="[string map {"clang++" "llvm-ar"} ${configure.cxx}]" \
                NM="[string map {"clang++" "llvm-nm"} ${configure.cxx}]" \
                RANLIB="[string map {"clang++" "llvm-ranlib"} ${configure.cxx}]"
} elseif {[string match *clang-mp* ${configure.cc}]} {
    configure.env-append \
                AR="[string map {"clang" "llvm-ar"} ${configure.cc}]" \
                NM="[string map {"clang" "llvm-nm"} ${configure.cc}]" \
                RANLIB="[string map {"clang" "llvm-ranlib"} ${configure.cc}]"
}

The mentioned experience comes from Linux but I don't see why similar issues couldn't arise on Mac, for similar reasons (the default ar and/or ranlib not being able to create a usable static library from llvm objects). I think it shouldn't hurt to set the AR, NM and RANLIB env. variables as shown above from "base", along with CC, CXX etc. Or add configure.ar, configure.nm and configure.ranlib option variables?

Equivalent for in the cmake PortGroup (pre-configure block):

    if {[string match *clang++-mp* ${configure.cxx}]} {
        if {[string first "DCMAKE_AR=" ${configure.args}] eq -1} {
            configure.args-append \
                                -DCMAKE_AR=[string map {"clang++" "llvm-ar"} ${configure.cxx}]
        }
        if {[string first "DCMAKE_NM=" ${configure.args}] eq -1} {
            configure.args-append \
                                -DCMAKE_NM=[string map {"clang++" "llvm-nm"} ${configure.cxx}]
        }
        if {[string first "DCMAKE_RANLIB=" ${configure.args}] eq -1} {
            configure.args-append \
                                -DCMAKE_RANLIB=[string map {"clang++" "llvm-ranlib"} ${configure.cxx}]
        }
    } elseif {[string match *clang-mp* ${configure.cc}]} {
        if {[string first "DCMAKE_AR=" ${configure.args}] eq -1} {
            configure.args-append \
                                -DCMAKE_AR=[string map {"clang" "llvm-ar"} ${configure.cc}]
        }
        if {[string first "DCMAKE_NM=" ${configure.args}] eq -1} {
            configure.args-append \
                                -DCMAKE_NM=[string map {"clang" "llvm-nm"} ${configure.cc}]
        }
        if {[string first "DCMAKE_RANLIB=" ${configure.args}] eq -1} {
            configure.args-append \
                                -DCMAKE_RANLIB=[string map {"clang" "llvm-ranlib"} ${configure.cc}]
        }
    }

Change History (1)

comment:1 Changed 5 months ago by RJVB (René Bertin)

Description: modified (diff)
Note: See TracTickets for help on using tickets.