[zsh] add CFLAGS, LDFLAGS and PKG_CONFIG_PATH support for keg-only homebrew formulas

This commit is contained in:
Dmytro Meleshko 2019-05-11 14:54:20 +03:00
parent 8c5e2ca4b4
commit 2e49567620

View file

@ -1,7 +1,13 @@
#!/usr/bin/env zsh #!/usr/bin/env zsh
# make these variables unique (-U) arrays (-a) # tie these env variables to zsh arrays
typeset -aU fpath manpath path ldflags cppflags typeset -T LDFLAGS ldflags ' '
typeset -T CPPFLAGS cppflags ' '
typeset -T PKG_CONFIG_PATH pkg_config_path ':'
# keep only unique values in these arrays
typeset -U path fpath manpath ldflags cppflags pkg_config_path
export -U PATH FPATH MANPATH LDFLAGS CPPFLAGS PKG_CONFIG_PATH
if is_macos; then if is_macos; then
path=( path=(
@ -23,8 +29,14 @@ if is_macos; then
"${manpath[@]}" "${manpath[@]}"
) )
export LDFLAGS="-L/usr/local/opt/ruby/lib" for formula in ruby openssl curl; do
export CPPFLAGS="-I/usr/local/opt/ruby/include" formula_path="/usr/local/opt/$formula"
if [[ -d "$formula_path" ]]; then
ldflags+=( -L"$formula_path"/lib )
cppflags+=( -L"$formula_path"/include )
pkg_config_path+=( "$formula_path"/lib/pkgconfig )
fi
done
fi fi
# add Go binaries # add Go binaries
@ -32,21 +44,21 @@ export GOPATH="$HOME/.go"
path=("$GOPATH/bin" "${path[@]}") path=("$GOPATH/bin" "${path[@]}")
# add user binaries # add user binaries
path=(~/bin ~/.local/bin "${path[@]}") path=(~/.local/bin "${path[@]}")
# add my completions # add my binaries and completions
path=("$ZSH_DOTFILES/bin" "${path[@]}")
fpath=("$ZSH_DOTFILES/completions" "${fpath[@]}") fpath=("$ZSH_DOTFILES/completions" "${fpath[@]}")
# check for Rust installed via rustup # check for Rust installed via rustup
if rust_sysroot="$(~/.cargo/bin/rustc --print sysroot 2> /dev/null)"; then rustc=~/.cargo/bin/rustc
# add paths of the current Rust toolchain if [[ -f "$rustc" && -x "$rustc" ]] && rust_sysroot="$("$rustc" --print sysroot)"; then
# add paths of the default Rust toolchain
path=(~/.cargo/bin "${path[@]}") path=(~/.cargo/bin "${path[@]}")
fpath=("$rust_sysroot/share/zsh/site-functions" "${fpath[@]}") fpath=("$rust_sysroot/share/zsh/site-functions" "${fpath[@]}")
manpath=("$rust_sysroot/share/man" "${manpath[@]}") manpath=("$rust_sysroot/share/man" "${manpath[@]}")
fi fi
unset rust_sysroot unset rustc rust_sysroot
# add colon after MANPATH so that it doesn't overwrite system MANPATH # add colon after MANPATH so that it doesn't overwrite system MANPATH
MANPATH="$MANPATH:" MANPATH="$MANPATH:"
export PATH MANPATH