Repository: spack/spack

Issue:
Installation issue: postgresql package cannot locate its own libraries
### Steps to reproduce the issue

```console
spack install gdal@2.1.2+pg~python+png
...
==> Installing gdal-2.1.2-4zxhhgrroqh2yhkoheguugz4bl2wlqkh
==> No binary for gdal-2.1.2-4zxhhgrroqh2yhkoheguugz4bl2wlqkh found: installing from source
==> Fetching https://mirror.spack.io/_source-cache/archive/b5/b597f36bd29a2b4368998ddd32b28c8cdf3c8192237a81b99af83cc17d7fa374.tar.xz
######################################################################## 100.0%
==> Ran patch() for gdal
==> gdal: Executing phase: 'autoreconf'
==> gdal: Executing phase: 'configure'
==> gdal: Executing phase: 'build'
==> gdal: Executing phase: 'install'
==> Error: NoLibrariesError: Unable to recursively locate postgresql libraries in /mnt/local/sinan/spack-0.17.0/opt/spack/linux-centos7-haswell/gcc-7.4.0/postgresql-14.0-r5t3y55wruclg3putbexbi5ogq4kaz5b

/mnt/local/sinan/spack-0.17.0/var/spack/repos/builtin/packages/gdal/package.py:221, in setup_run_environment:
        218        libs = []
        219        for dep in self.spec.dependencies(deptype='link'):
        220            query = self.spec[dep.name]
  >>    221            libs.extend(query.libs.directories)
        222        if sys.platform == 'darwin':
        223            env.prepend_path('DYLD_FALLBACK_LIBRARY_PATH', ':'.join(libs))
        224        else:

See build log for details:
  /cache/sinan/spack-stage/spack-stage-gdal-2.1.2-4zxhhgrroqh2yhkoheguugz4bl2wlqkh/spack-build-out.txt
```

### Information on your system

```
$ spack debug report
* **Spack:** 0.17.0-1-f92a2d6
* **Python:** 3.6.8
* **Platform:** linux-centos7-haswell
* **Concretizer:** clingo
```

### Additional information

Will provider further details soon. 
pinging @adamjstewart 

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have run `spack maintainers <name-of-the-package>` and **@mentioned** any maintainers
- [X] I have uploaded the build log and environment files
- [X] I have searched the issues of this repo and believe this is not a duplicate


Discussion:
Seems to be related to https://github.com/spack/spack/issues/21462
This error message just means that `spec['postgresql'].libs` failed to find a `libpostgresql.so` library in the postgresql installation prefix. We likely just need to add a `libs` property to the package that searches for a different library name.
list of files under postgresql prefix/lib:
```ascii_and_mic.so
cyrillic_and_mic.so
dict_snowball.so
euc2004_sjis2004.so
euc_cn_and_mic.so
euc_jp_and_sjis.so
euc_kr_and_mic.so
euc_tw_and_big5.so
latin2_and_win1250.so
latin_and_mic.so
libecpg.a
libecpg_compat.a
libecpg_compat.so
libecpg_compat.so.3
libecpg_compat.so.3.12
libecpg.so
libecpg.so.6
libecpg.so.6.12
libpgcommon.a
libpgcommon_shlib.a
libpgfeutils.a
libpgport.a
libpgport_shlib.a
libpgtypes.a
libpgtypes.so
libpgtypes.so.3
libpgtypes.so.3.12
libpq.a
libpq.so
libpq.so.5
libpq.so.5.12
libpqwalreceiver.so
pgoutput.so
pgxs
pkgconfig
plpgsql.so
utf8_and_ascii.so
utf8_and_big5.so
utf8_and_cyrillic.so
utf8_and_euc2004.so
utf8_and_euc_cn.so
utf8_and_euc_jp.so
utf8_and_euc_kr.so
utf8_and_euc_tw.so
utf8_and_gb18030.so
utf8_and_gbk.so
utf8_and_iso8859_1.so
utf8_and_iso8859.so
utf8_and_johab.so
utf8_and_sjis2004.so
utf8_and_sjis.so
utf8_and_uhc.so
utf8_and_win.so
```

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/postgresql/package.py b/var/spack/repos/builtin/packages/postgresql/package.py
--- a/var/spack/repos/builtin/packages/postgresql/package.py
+++ b/var/spack/repos/builtin/packages/postgresql/package.py
@@ -125,3 +125,25 @@ def setup_dependent_run_environment(self, env, dependent_spec):
             env.prepend_path('TCLLIBPATH', self.prefix.lib)
         if '+python' in spec:
             env.prepend_path('PYTHONPATH', self.prefix.lib)
+
+    @property
+    def libs(self):
+        stat_libs = ['libecpg_compat', 'libecpg', 'libpgcommon',
+                     'libpgcommon_shlib', 'libpgfeutils', 'libpgport',
+                     'libpgport_shlib', 'libpgtypes', 'libpq']
+        fl_stat = find_libraries(stat_libs, self.prefix, shared=False,
+                                 recursive=True)
+
+        dyn_libs = ['libecpg_compat', 'libecpg', 'libpgtypes', 'libpq',
+                    'libpqwalreceiver', 'plpgsql', 'pgoutput']
+        if '+perl' in self.spec:
+            dyn_libs.append('plperl')
+        if '+python' in self.spec:
+            dyn_libs.append('plpython')
+        if '+tcl' in self.spec:
+            dyn_libs.append('pltcl')
+
+        fl_dyn = find_libraries(dyn_libs, self.prefix, shared=True,
+                                recursive=True)
+
+        return fl_dyn + fl_stat


Test patch: