Backports and other fixes for homebrew