Jonathan is correct. You are confusing shell script with makefiles. You cannot run arbitrary commands in makefiles, and there are only a subset of the tests available from the shell syntax. So anyway, I assumed this might work:
ifndef PGLIB
if [ -d "/usr/local/pgsql" ]; then
export PGLIB=/usr/local/pgsql/lib;
else
export PGLIB=/usr/lib
fi
endif
but it turns out that the fragment of script above is executed in its own 'sh -c', and can't assign variables to the makefile. Moreover, IIAC, makefile 'variables' can only be target definitions.
Eventually one has to give up and start working with autoconf/automake.