Repository: spack/spack

Issue:
Dealing with autotools and %nvhpc
`libtool` doesn't know about `nvc`, `nvc++`, `nvfortran`, only about PGI compilers, and as a result doesn't know how to set some flags for these compilers, in particular `pic`-related ones:

https://git.savannah.gnu.org/cgit/libtool.git/tree/m4/libtool.m4#n4740

A patch was submitted in August 2020 https://www.mail-archive.com/libtool-patches@gnu.org/msg07391.html but this was ignored.

Some packages try to fix libtool themselves now, like MPICH: https://github.com/pmodels/mpich/commit/6ff2ed15b47d5b5c21aabfab75240ed15b4af41a

But we can't expect every autotools package to do this. Also we can't expect packages to come with a configure script generated with a recent libtool (assuming the patch above gets merged in libtool at some point).

So what's the way to deal with it? Add the patch ourselves and force reconfigure, like this?

```python
@property
def force_autoreconf(self):
  return self.spec.satisfies('%nvhpc')

depends_on('libtool+nvhpc_patch', when='%nvhpc')
depends_on('automake', when='%nvhpc')
depends_on('autoconf', when='%nvhpc')
```




Discussion:
We ended up reverting https://github.com/pmodels/mpich/commit/6ff2ed15b47d5b5c21aabfab75240ed15b4af41a and re-applying it with some modifications in https://github.com/pmodels/mpich/pull/5767. I believe the patch that was posted to the libtool list incorrect.
> We ended up reverting [pmodels/mpich@6ff2ed1](https://github.com/pmodels/mpich/commit/6ff2ed15b47d5b5c21aabfab75240ed15b4af41a) and re-applying it with some modifications in [pmodels/mpich#5767](https://github.com/pmodels/mpich/pull/5767). I believe the patch that was posted to the libtool list incorrect.

I could compile mpich 4.0.1 using nvhpc so the patch included in that branch should be fine.
Wouldn't a less invasive approach be something like:

```
if spec.satisfies('%nvhpc'):
    config_args.append('CFLAGS=-fPIC')
```
AutotoolsPackage is patched libtool after configure for some compilers (#12004 and #18620).

Thanks @tkameyama, that's helpful

Resolving patch:
diff --git a/lib/spack/spack/build_systems/autotools.py b/lib/spack/spack/build_systems/autotools.py
--- a/lib/spack/spack/build_systems/autotools.py
+++ b/lib/spack/spack/build_systems/autotools.py
@@ -76,7 +76,7 @@ def patch_config_files(self):
                 or self.spec.satisfies('target=riscv64:'))
 
     #: Whether or not to update ``libtool``
-    #: (currently only for Arm/Clang/Fujitsu compilers)
+    #: (currently only for Arm/Clang/Fujitsu/NVHPC compilers)
     patch_libtool = True
 
     #: Targets for ``make`` during the :py:meth:`~.AutotoolsPackage.build`
@@ -252,7 +252,7 @@ def _set_autotools_environment_variables(self):
     def _do_patch_libtool(self):
         """If configure generates a "libtool" script that does not correctly
         detect the compiler (and patch_libtool is set), patch in the correct
-        flags for the Arm, Clang/Flang, and Fujitsu compilers."""
+        flags for the Arm, Clang/Flang, Fujitsu and NVHPC compilers."""
 
         # Exit early if we are required not to patch libtool
         if not self.patch_libtool:
@@ -263,9 +263,12 @@ def _do_patch_libtool(self):
             self._patch_libtool(libtool_path)
 
     def _patch_libtool(self, libtool_path):
-        if self.spec.satisfies('%arm')\
-                or self.spec.satisfies('%clang')\
-                or self.spec.satisfies('%fj'):
+        if (
+            self.spec.satisfies('%arm') or
+            self.spec.satisfies('%clang') or
+            self.spec.satisfies('%fj') or
+            self.spec.satisfies('%nvhpc')
+        ):
             fs.filter_file('wl=""\n', 'wl="-Wl,"\n', libtool_path)
             fs.filter_file('pic_flag=""\n',
                            'pic_flag="{0}"\n'


Test patch: