[global] Use realpath if HOMEBREW_PREFIX is a symlink

https://github.com/Homebrew/homebrew/issues/26524

HOMEBREW_PREFIX is set to the parent of the dirname of HOMEBREW_BREW_FILE.
If HOMEBREW_PREFIX is a symlink, Keg.link_dir to compute the wrong
relative paths when installing targets. This change checks if is a
symlink and if so sets it to its realpath instead.