The ./config/acx_libpq.m4 is broken. The test compile to check if find_my_exec() can be compiled puts -lpgport before -lpgcommon. Since both are .a libraries (at least in 9.5), this doesn't work because -lpgcommon is referencing objects in -lpgport. Linking in -lpgport first doesn't pull those objects in, so the link fails and ./configure complains that it cannot find pgport. The attached patch fixes configure.
Created attachment 214 [details] Patch to fix ./configure --with-pgport on Linux
Created attachment 215 [details] Updated v2 of configure patch. Apparently some modules have shifted around between -lpgcommon and -lpgport, making the link order dependent on the major PostgreSQL version. Since these are old style .a libraries during ./configure, the link order matters. To not overcomplicate the acx_libpq check, we can specify each library twice.
This patch looks fine. You can commit it