<commit_before># How to build software outside Homebrew with Homebrew keg-only dependencies.

### What does keg-only mean?

See the [FAQ](FAQ.md) on this one. It’s a common question.

As an example:

*OpenSSL isn’t symlinked into my $PATH and non-Homebrew builds can’t find it!*

That’s because Homebrew keeps it locked away in its prefix, accessible only via its opt directory. `keg_only` = Not symlinked into the `$PATH` by default.

### 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 doesn’t enforce `keg_only` onto formulae unless there’s 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 you’ve linked something and there’s no problems at all? Awesome, feel free to ignore the `brew doctor` error. But *please* don’t try to go around it. It’s really hard to help you out if we don’t know the full picture, and we *want* to be able to help you if you get stuck.

### How do I use those tools outside of Homebrew?

Useful, reliable alternatives exist should you desire to use `keg_only` tools outside of Homebrew’s build processes:

----
You can set flags to give configure scripts or Makefiles a nudge in the right direction. An example of flag setting:

```shell
./configure --prefix=/Users/Dave/Downloads CFLAGS=-I$(brew --prefix)/opt/openssl/include LDFLAGS=-L$(brew --prefix)/opt/openssl/lib
```

An example using `pip`:

```shell
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 tool’s bin directory, such as:

```shell
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` utility’s `.pc` file, if it has one. Not all formulae ship with those files.

An example of that is:

```shell
export PKG_CONFIG_PATH=$(brew --prefix)/opt/openssl/lib/pkgconfig
```

If you’re 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:

```shell
pkg-config --variable pc_path pkg-config`
```<commit_msg>keg_only external builds documentation: cleanup<commit_after># How to build software outside Homebrew with Homebrew `keg-only` dependencies

## What does `keg-only` mean?

The [FAQ](FAQ.md) briefly explains this.

As an example:

*OpenSSL isn’t symlinked into my `$PATH` and non-Homebrew builds can’t find it!*

This is because Homebrew keeps it locked inside its individual prefix, rather than symlinking to the publicly-available location, usually `/usr/local`.

## Advice on potential workarounds.

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* do not remove OS X native tools and forcefully replace them with symlinks back to the Homebrew-provided tool. Doing so can and likely will cause significant breakage when attempting to build software.

`brew link --force` creates a warning in `brew doctor` to let both you and maintainers know that link exists and could be causing issues. If you’ve linked something and there’s no problems at all? Feel free to ignore the `brew doctor` error.

## How do I use those tools outside of Homebrew?

Useful, reliable alternatives exist should you wish to use `keg_only` tools outside of Homebrew.

### Build flags:


You can set flags to give configure scripts or Makefiles a nudge in the right direction. An example of flag setting:

```shell
./configure --prefix=/Users/Dave/Downloads CFLAGS=-I$(brew --prefix)/opt/openssl/include LDFLAGS=-L$(brew --prefix)/opt/openssl/lib
```

An example using `pip`:

```shell
CFLAGS=-I$(brew --prefix)/opt/icu4c/include LDFLAGS=-L$(brew --prefix)/opt/icu4c/lib pip install pyicu
```

### `$PATH` modification:

You can temporarily prepend your `$PATH` with the tool’s bin directory, such as:

```shell
export PATH=$(brew --prefix)/opt/openssl/bin:$PATH
```

This will prepend that folder to your `$PATH`, ensuring any build script that searches the `$PATH` will find it first.

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 session, the `$PATH` reverts to the prior state.

### `pkg-config` detection:

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` utility’s `.pc` file, if it has them. Not all formulae ship with those files.

An example of that is:

```shell
export PKG_CONFIG_PATH=$(brew --prefix)/opt/openssl/lib/pkgconfig
```

If you’re curious about the `PKG_CONFIG_PATH` variable `man pkg-config` goes into more detail.

You can get `pkg-config` to detail the default search path with:

```shell
pkg-config --variable pc_path pkg-config
```
{'fraction_non_alphanumeric': 0.08903998704872916, 'fraction_numerical': 0.0006475635421725757, 'mean_word_length': 4.438380281690141, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2410254', 'n_tokens_mistral': 1776, 'n_tokens_neox': 1715, 'n_words': 866}