Coding: Search Path Magic

If you ever find yourself needing to build libraries and applications where either don’t have the ability or the desire to install them system-wide directories, then you will need to install them into your home directory. A common location for this is “~/.local“, mimicking the idea of “/usr/local“, but for your user account. However, there are a number of environment variables that you will need to override to get all of the path searching magic to work correctly. I can’t recall a single resource that lists them all, but here is what I stuff into my “.bashrc” to cover everything that I know of:

PREFIX="$HOME/.local"
PATH="$PREFIX/bin:$PREFIX/sbin:$PATH"
PKG_CONFIG_PATH="$PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH"
LD_LIBRARY_PATH="$PREFIX/lib:$LD_LIBRARY_PATH"
LDFLAGS="-L$PREFIX/lib $LDFLAGS"
C_INCLUDE_PATH="$PREFIX/include:$C_INCLUDE_PATH"
CPLUS_INCLUDE_PATH="$PREFIX/include:$CPLUS_INCLUDE_PATH"
MANPATH="$PREFIX/man:$PREFIX/share/man:$MANPATH"
INFOPATH="$PREFIX/info:$PREFIX/share/info:$INFOPATH"
export PATH PKG_CONFIG_PATH LD_LIBRARY_PATH LDFLAGS \
       C_INCLUDE_PATH CPLUS_INCLUDE_PATH MANPATH INFOPATH \
       PREFIX

In most cases, you can now use “./configure --prefix=$PREFIX” to get things to land in the right directory, however there are exceptionally bad packages out there that either don’t use a such a configure script or fail to honor it correctly. In most cases, after you “make && make install”, it should just work.

If you share your home directory across architectures (e.g. a shared home between many different workstations), then you will probably need to modify the magic above to key off of the architecture so that you can build compatible binaries. For example, I use “PREFIX="$HOME/.local/$(uname -p)"” to mix between i686 and x86_64 workstations. Of course, you will have to build things multiple times for each platform.