[jon@localhost openldap-2.4.23]$ env CPPFLAGS=/usr/local/BerkeleyDB.5.1/include
[...]
checking whether we are using the GNU C compiler... yes
I don't believe that passing a directory on the command line is meanignful to the GNU C compiler.
That looks like bash; try:
CPPFLAGS='-I/usr/local/BerkeleyDB.5.1/include' ./configure
perhaps?
NOTE: If you're going to put the elbow grease into compiling, try OpenLDAP 2.4.26. See http://www.openldap.org/software/release/changes.html for reasons why.