autotools: fix a parallel build race condition spotted by the pull-tester

libleveldb.a and libmemenv.a should be able to build in parallel, but in
practice calling the leveldb makefile ends up rewriting build_config.mk. If
one target tries to build while the other is halfway through writing the
.mk, the make ends up in an undefined state.

Fix that by making one depend on the other. This also reorders the variables
to be passed by param rather than via the environment, and combines the targets
into a single rule to avoid needless duplication.
Merge pull request #3001 from theuni/fix-make-race

autotools: fix a parallel build race condition spotted by the pull-tester