build: improve special environment variable handling (#30722)
The application of JLDFLAGS was missing on many libraries,
and clean up some of this code to avoid needing `override`.
Also add -Wl,-no-undefined on platforms where it is supported
(FreeBSD has problems with it) and not already the default (on
Apple and Win32)—e.g just Linux.