In this case, it's GPG that I'm trying to build. Basically, I want to have all the build output go into a subdirectory of my choosing, instead of being installed on my live filesystem.
Setting --prefix=path/to/my/sandbox sends the output of one build where I want it to go, but the next build stage, which depends on the output of the previous build stage, can't find that output.
Example:
$ cd libgpg-error-1.37
$ ./configure --prefix=/Users/falk/GpgSandbox/usr/local
$ make
$ make install
(success: all output placed in /Users/falk/GpgSandbox/usr/local/)
$ cd ../libassuan-2.5.3
$ ./configure --prefix=/Users/falk/GpgSandbox/usr/local
...
configure: error: libgpg-error was not found
$
Is there another option I could have passed to ./configure to get it to find libraries in the sandbox? Should I build inside a VM or a docker container?
Many thanks to @hyde for pointing me in the right direction. The solution was to set a few environment variables before building:
mkdir -p /Users/falk/GpgSandbox/usr/local/
export CPPFLAGS='-I/Users/falk/GpgSandbox/usr/local/include'
export LDFLAGS='-L/Users/falk/GpgSandbox/usr/local/lib'
export PATH="$PATH:/Users/falk/GpgSandbox/usr/local/bin"
cd libgpg-error-1.37/
./configure --prefix=/Users/falk/GpgSandbox/usr/local
make install
(etc.)