how to prepend or append to DYLD_LIBRARY_PATH in Portfile?

Ken Cunningham ken.cunningham.webuse at
Sat Oct 24 16:46:28 UTC 2020

> On Oct 24, 2020, at 8:52 AM, Joshua Root <jmr at> wrote:
> On 2020-10-25 02:18 , Ken Cunningham wrote:
>> It's easy to prepend or append to PATH in a Portfile, but I'm having difficulty seeing how to modify, rather than overwrite, DYLD_LIBRARY_PATH.
>> Usually you just want to set it, but now that it might or might not be set in legacysupport 1.1, I was hoping to just modify rather than overwrite it.
>> I tried a number of different things, but couldn't spot the magic 
>> i missing something simple?
> What did you try? The configure.env, build.env etc. options can be read
> like any other option. You can use lsearch on it to look for entries
> starting with the variable name you're after.
> - Josh

Ah, thanks for the clue.

I had hoped that just something like this would set them both:

configure.env-append        "DYLD_LIBRARY_PATH=${prefix}/lib/lilbgcc"
configure.env-append        “DYLD_LIBRARY_PATH=${workpath}/build”

but I found the second one just obliterates the first one.


So I tried variations of this construct, that works for PATH:

configure.env-append    "PATH=$env(PATH):${bootstrap_dir}/bin”


configure.env-append        "DYLD_LIBRARY_PATH=${prefix}/lib/lilbgcc"
configure.env-append        “DYLD_LIBRARY_PATH=$env(DYLD_LIBRARY_PATH):${workpath}/build”

but that just gives 

DEBUG: no such variable
    (read trace on "env(DYLD_LIBRARY_PATH)")

because the first one doesn’t get set into the environment until the whole Portfile is parsed, obviously in retrospect. 

And likewise testing for it with [info exists …] won’t work either, I can see, because it’s not there yet.

So instead of this method, I will look into running lsearch on *.env, and see if I can sort out how to add some entries if something is already there. 

It looks like the Makefile-1.0 PortGroup might be doing something along these lines — getting a tad complicated, however:

        foreach env_var { \
            PKG_CONFIG_PATH \
        } {
            set value [option configure.[string tolower $env_var]]
            if {$value ne ""} {
                ${phase}.env-append         "$env_var=[join $value :]"
                if {[lsearch -exact ${makefile.override} ${env_var}] != -1} {
                    ${phase}.args-append    $env_var="[join $value :]"

Do you think this:

configure.env-append        "DYLD_LIBRARY_PATH=${prefix}/lib/lilbgcc"
configure.env-append        “DYLD_LIBRARY_PATH=${workpath}/build”

should “just work" to set both without added shenanigans?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the macports-dev mailing list