brew/share/doc/homebrew/How-to-build-software-outside-Homebrew-with-Homebrew-keg-only-dependencies.md
Dominyk Tiller 0d2ae7147c Documenting keg-only outside of Homebrew.
How-to-use-keg-only-outside-of-brew:
* A new piece of documentation detailing how to deal with using
keg_only formula outside of Brew itself. We’ve had a lot of questions
and issues about this recently, and the solutions aren’t as easy and
explicit to find elsewhere, so detailing it here may help reduce some
of the questions we’ve seen recently.
* I possibly whinged too much in the second section. I’m open to
criticism and being called whiny.
* Details flags, prepending the $PATH, and dealing with pkg-config.

Closes Homebrew/homebrew#34608.

Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
2014-12-05 11:25:08 +00:00

54 lines
3.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# How to build software outside Homebrew with Homebrew keg-only dependencies.
### What does keg-only mean?
See the [FAQ](FAQ.md) on this one. Its a common question.
As an example:
*OpenSSL isnt symlinked into my $PATH and non-Homebrew builds cant find it!*
Thats because Homebrew keeps it locked away in its prefix, accessible only via its opt directory. `keg_only` = Not symlinked into the `$PATH` by default.
### But how do I get non-Homebrew builds to find those tools?
A number of people in this situation are either forcefully linking `keg_only` tools with `brew link --force` or moving default system utilities out of the `$PATH` and replacing them with manually-created symlinks to the Homebrew-provided tool.
Please, *please* do not remove OS X native tools and forcefully replace them with symlinks back to the Homebrew-provided tool. Homebrew doesnt enforce `keg_only` onto formulae unless theres a specific, good reason for doing so, and that reason is usually that forcing that link breaks a whole boat full of builds.
It is also incredibly difficult to debug a build failure if you make changes to the Homebrew-provided tools installed that `brew` is unaware of. `brew link --force` deliberately creates a warning in `brew doctor` to let both you and maintainers know that link exists and could be causing issues.
If youve linked something and theres no problems at all? Awesome, feel free to ignore the `brew doctor` error. But *please* dont try to go around it. Its really hard to help you out if we dont know the full picture, and we *want* to be able to help you if you get stuck.
### Alright. Stop complaining at me, I get it - but how do I use those tools outside of Homework?
Useful, reliable alternatives exist should you desire to use `keg_only` tools outside of Homebrews build processes:
----
You can set flags to give configure scripts or Makefiles a nudge in the right direction. An example of flag setting:
`./configure --prefix=/Users/Dave/Downloads CFLAGS=-I$(brew --prefix)/opt/openssl/include LDFLAGS=-L$(brew --prefix)/opt/openssl/lib`
An example using `pip`:
`CFLAGS=-I$(brew --prefix)/opt/icu4c/include LDFLAGS=-L$(brew --prefix)/opt/icu4c/lib pip install pyicu`
----
You can temporarily prepend your `$PATH` with the tools bin directory, such as:
`export PATH=$(brew --prefix)/opt/openssl/bin:$PATH`
This will immediately move that folder to the front of your `$PATH`, ensuring any build script that searches the `$PATH` will find it.
Changing your `$PATH` using that command ensures the change only exists for the duration of that shell session. Once you are no longer in that terminal tab/window, the `$PATH` ceases to be prepended.
----
If the tool you are attempting to build is [pkg-config](https://en.wikipedia.org/wiki/Pkg-config) aware, you can amend your `PKG_CONFIG_PATH` to find that `keg_only` utilitys `.pc` file, if it has one. Not all formulae ship with those files.
An example of that is:
`export PKG_CONFIG_PATH=$(brew --prefix)/opt/openssl/lib/pkgconfig `
If youre curious about `PKG_CONFIG_PATH` and which paths it searches by default, `man pkg-config` goes into detail on that.
You can also get `pkg-config` to detail its currently searched paths with:
`pkg-config --variable pc_path pkg-config`