Repository: spack/spack

Issue:
Installation issue: mfem+gslib
### Steps to reproduce the issue

```console
$ spack spec -I mfem~amgx~conduit~~cuda~debug+examples~gnutls+gslib+lapack+libceed~libunwind+metis+miniapps~mpfr+mpi~netcdf~occa~openmp~petsc~pumi~raja+shared+static~strumpack+suite-sparse~sundials~superlu-dist~threadsafe~umpire+zlib
Input spec
--------------------------------
 -   mfem~amgx~conduit~~cuda~debug+examples~gnutls+gslib+lapack+libceed~libunwind+metis+miniapps~mpfr+mpi~netcdf~occa~openmp~petsc~pumi~raja+shared+static~strumpack+suite-sparse~sundials~superlu-dist~threadsafe~umpire+zlib

Concretized
--------------------------------
 -   mfem@4.6.0%gcc@12.3.0~amgx~conduit~cuda~debug+examples~exceptions~fms~ginkgo~gnutls+gslib~hiop+lapack+libceed~libunwind+metis+miniapps~mpfr+mpi~netcdf~occa~openmp~petsc~pumi~raja~rocm+shared~slepc+static~strumpack+suite-sparse~sundials~superlu-dist~threadsafe~umpire+zlib build_system=generic patches=718f073 timer=auto arch=linux-rocky8-cascadelake
[+]      ^gslib@1.0.7%gcc@12.3.0~blas+mpi+mpiio build_system=generic arch=linux-rocky8-cascadelake
[+]      ^hypre@2.29.0%gcc@12.3.0~caliper~complex~cuda~debug+fortran~gptune~int64~internal-superlu~magma~mixedint+mpi~openmp~rocm+shared~superlu-dist~sycl~umpire~unified-memory build_system=autotools arch=linux-rocky8-cascadelake
[+]          ^gmake@4.4.1%gcc@12.3.0~guile build_system=generic arch=linux-rocky8-cascadelake
[+]      ^libceed@0.12.0%gcc@12.3.0~cuda~debug~libxsmm~magma~occa~rocm build_system=makefile arch=linux-rocky8-cascadelake
[+]      ^metis@5.1.0%gcc@12.3.0~gdb~int64~ipo~real64+shared build_system=cmake build_type=Release generator=make patches=4991da9,93a7903,b1225da arch=linux-rocky8-cascadelake
[+]          ^cmake@3.27.7%gcc@12.3.0~doc+ncurses+ownlibs build_system=generic build_type=Release arch=linux-rocky8-cascadelake
[+]              ^curl@8.4.0%gcc@12.3.0~gssapi~ldap~libidn2~librtmp~libssh~libssh2+nghttp2 build_system=autotools libs=shared,static tls=openssl arch=linux-rocky8-cascadelake
[+]                  ^nghttp2@1.57.0%gcc@12.3.0 build_system=autotools arch=linux-rocky8-cascadelake
[+]                  ^openssl@3.1.3%gcc@12.3.0~docs+shared build_system=generic certs=mozilla arch=linux-rocky8-cascadelake
[+]                      ^ca-certificates-mozilla@2023-05-30%gcc@12.3.0 build_system=generic arch=linux-rocky8-cascadelake
[+]                  ^pkgconf@1.9.5%gcc@12.3.0 build_system=autotools arch=linux-rocky8-cascadelake
[+]              ^ncurses@6.4%gcc@12.3.0~symlinks+termlib abi=none build_system=autotools arch=linux-rocky8-cascadelake
[e]      ^mvapich2@2.3.7%gcc@12.3.0~alloca~cuda~debug~hwloc_graphics~hwlocv2+regcache+wrapperrpath build_system=autotools ch3_rank_bits=32 fabrics=mrail file_systems=auto patches=d98d8e7 process_managers=auto threads=multiple arch=linux-rocky8-cascadelake
[+]      ^openblas@0.3.24%gcc@12.3.0~bignuma~consistent_fpcsr+fortran~ilp64+locking+pic+shared build_system=makefile symbol_suffix=none threads=none arch=linux-rocky8-cascadelake
[+]          ^perl@5.38.0%gcc@12.3.0+cpanm+opcode+open+shared+threads build_system=generic patches=714e4d1 arch=linux-rocky8-cascadelake
[+]              ^berkeley-db@18.1.40%gcc@12.3.0+cxx~docs+stl build_system=autotools patches=26090f4,b231fcc arch=linux-rocky8-cascadelake
[+]              ^bzip2@1.0.8%gcc@12.3.0~debug~pic+shared build_system=generic arch=linux-rocky8-cascadelake
[+]              ^gdbm@1.23%gcc@12.3.0 build_system=autotools arch=linux-rocky8-cascadelake
[+]                  ^readline@8.2%gcc@12.3.0 build_system=autotools patches=bbf97f1 arch=linux-rocky8-cascadelake
[+]      ^suite-sparse@5.13.0%gcc@12.3.0~cuda~graphblas~openmp+pic build_system=generic arch=linux-rocky8-cascadelake
[+]          ^gmp@6.2.1%gcc@12.3.0+cxx build_system=autotools libs=shared,static patches=69ad2e2 arch=linux-rocky8-cascadelake
[+]              ^autoconf@2.69%gcc@12.3.0 build_system=autotools patches=35c4492,7793209,a49dd5b arch=linux-rocky8-cascadelake
[+]              ^automake@1.16.5%gcc@12.3.0 build_system=autotools arch=linux-rocky8-cascadelake
[+]              ^libtool@2.4.7%gcc@12.3.0 build_system=autotools arch=linux-rocky8-cascadelake
[+]          ^m4@1.4.19%gcc@12.3.0+sigsegv build_system=autotools patches=9dc5fbd,bfdffa7 arch=linux-rocky8-cascadelake
[+]              ^diffutils@3.9%gcc@12.3.0 build_system=autotools arch=linux-rocky8-cascadelake
[+]                  ^libiconv@1.17%gcc@12.3.0 build_system=autotools libs=shared,static arch=linux-rocky8-cascadelake
[+]              ^libsigsegv@2.14%gcc@12.3.0 build_system=autotools arch=linux-rocky8-cascadelake
[+]          ^mpfr@4.2.0%gcc@12.3.0 build_system=autotools libs=shared,static arch=linux-rocky8-cascadelake
[+]              ^autoconf-archive@2023.02.20%gcc@12.3.0 build_system=autotools arch=linux-rocky8-cascadelake
[+]              ^texinfo@7.0.3%gcc@12.3.0 build_system=autotools arch=linux-rocky8-cascadelake
[+]                  ^gettext@0.22.3%gcc@12.3.0+bzip2+curses+git~libunistring+libxml2+pic+shared+tar+xz build_system=autotools arch=linux-rocky8-cascadelake
[+]                      ^libxml2@2.10.3%gcc@12.3.0+pic~python+shared build_system=autotools arch=linux-rocky8-cascadelake
[+]                      ^tar@1.34%gcc@12.3.0 build_system=autotools zip=pigz arch=linux-rocky8-cascadelake
[+]                          ^pigz@2.7%gcc@12.3.0 build_system=makefile arch=linux-rocky8-cascadelake
[+]                          ^zstd@1.5.5%gcc@12.3.0+programs build_system=makefile compression=none libs=shared,static arch=linux-rocky8-cascadelake
[+]                      ^xz@5.4.1%gcc@12.3.0~pic build_system=autotools libs=shared,static arch=linux-rocky8-cascadelake
[+]      ^zlib-ng@2.1.4%gcc@12.3.0+compat+opt build_system=autotools arch=linux-rocky8-cascadelake
```


### Error message

<details><summary>Error message </summary>

<pre>
/apps/local/mvapich2/2.3.7-gcc-12.3.0/bin/mpicxx  -O3 -std=c++11 -I/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/mfem-4.6.0-asw22osvuvbo3xby7yi46hcqtcgi6yce/include/mfem -I/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/hypre-2.29.0-qq3fzsaknxqw47jinzla3lhdnzvugsvi/include -I/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/metis-5.1.0-i3c4wzfy4znkaz66pk3pse5seqgpscx6/include  -I/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/suite-sparse-5.13.0-o4eqmwq2r47wzm5aakagniqafdgiakxt/include -I/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/gslib-1.0.7-mbiive76qk3p3fvgc54i3brxnjipyevx/include -I/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/libceed-0.12.0-d3r3oqttmxclym5is2gujqcghnoonyuj/include -I/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/zlib-ng-2.1.4-6ivnz4cpdeb2y2m72zz4ntzwarznxkvv/include/mfem pfindpts.cpp -o pfindpts -L../../miniapps/common -lmfem-common  -rpath,/tmp/pbs.161715.sawtoothpbs/username/spack-stage/spack-stage-mfem-4.6.0-asw22osvuvbo3xby7yi46hcqtcgi6yce/spack-src/miniapps/common -Wl,-rpath,/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/mfem-4.6.0-asw22osvuvbo3xby7yi46hcqtcgi6yce/lib -L/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/mfem-4.6.0-asw22osvuvbo3xby7yi46hcqtcgi6yce/lib -lmfem -Wl,-rpath,/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/hypre-2.29.0-qq3fzsaknxqw47jinzla3lhdnzvugsvi/lib -Wl,-rpath,/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/openblas-0.3.24-6jpembbk7glvgzl5qmc7r43ndp6urdlt/lib -L/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/hypre-2.29.0-qq3fzsaknxqw47jinzla3lhdnzvugsvi/lib -L/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/openblas-0.3.24-6jpembbk7glvgzl5qmc7r43ndp6urdlt/lib -lHYPRE -lopenblas -Wl,-rpath,/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/metis-5.1.0-i3c4wzfy4znkaz66pk3pse5seqgpscx6/lib -L/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/metis-5.1.0-i3c4wzfy4znkaz66pk3pse5seqgpscx6/lib -lmetis -Wl,-rpath,/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/openblas-0.3.24-6jpembbk7glvgzl5qmc7r43ndp6urdlt/lib -L/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/openblas-0.3.24-6jpembbk7glvgzl5qmc7r43ndp6urdlt/lib -lopenblas -Wl,-rpath,/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/suite-sparse-5.13.0-o4eqmwq2r47wzm5aakagniqafdgiakxt/lib -L/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/suite-sparse-5.13.0-o4eqmwq2r47wzm5aakagniqafdgiakxt/lib -lklu -lbtf -lumfpack -lcholmod -lcolamd -lamd -lcamd -lccolamd -lsuitesparseconfig -Wl,-rpath,/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/gslib-1.0.7-mbiive76qk3p3fvgc54i3brxnjipyevx/lib -L/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/gslib-1.0.7-mbiive76qk3p3fvgc54i3brxnjipyevx/lib -lgs -Wl,-rpath,/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/libceed-0.12.0-d3r3oqttmxclym5is2gujqcghnoonyuj/lib -L/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/libceed-0.12.0-d3r3oqttmxclym5is2gujqcghnoonyuj/lib -lceed -lrt -Wl,-rpath,/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/zlib-ng-2.1.4-6ivnz4cpdeb2y2m72zz4ntzwarznxkvv/lib -L/home/username/Repos/spack-0-21/opt/spack/linux-rocky8-cascadelake/gcc-12.3.0/zlib-ng-2.1.4-6ivnz4cpdeb2y2m72zz4ntzwarznxkvv/lib -lz
g++: error: unrecognized command-line option '-rpath,/tmp/pbs.161715.sawtoothpbs/username/spack-stage/spack-stage-mfem-4.6.0-asw22osvuvbo3xby7yi46hcqtcgi6yce/spack-src/miniapps/common'
make[1]: *** [makefile:54: pfindpts] Error 1
make[1]: Leaving directory '/tmp/pbs.161715.sawtoothpbs/username/spack-stage/spack-stage-mfem-4.6.0-asw22osvuvbo3xby7yi46hcqtcgi6yce/spack-src/miniapps/gslib'
make: *** [makefile:464: miniapps/gslib] Error 2
</pre></details>


### Information on your system

* **Spack:** 0.21.0 (65d3221a9c436e77af9e802e543c71bd702ff4e2)
* **Python:** 3.6.8
* **Platform:** linux-rocky8-cascadelake
* **Concretizer:** clingo

### Additional information

The error message shows a snipped of `spack-build-out.txt`. I think the culprit you can see from reading the first line is that `-rpath/.../miniapps/common` rather than  `-Wl,-rpath/.../miniapps/common` is passed to g++ since `-rpath` is a linker command, but I'm not sure why that happens.

The above spec builds if I replace `+gslib` with `~gslib`.

@acfisher  @markcmiller86  @tzanio  @v-dobrev

### 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:

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/mfem/package.py b/var/spack/repos/builtin/packages/mfem/package.py
--- a/var/spack/repos/builtin/packages/mfem/package.py
+++ b/var/spack/repos/builtin/packages/mfem/package.py
@@ -473,6 +473,11 @@ class Mfem(Package, CudaPackage, ROCmPackage):
     patch("mfem-4.0.0-makefile-syntax-fix.patch", when="@4.0.0")
     patch("mfem-4.5.patch", when="@4.5.0")
     patch("mfem-4.6.patch", when="@4.6.0")
+    patch(
+        "https://github.com/mfem/mfem/pull/4005.patch?full_index=1",
+        when="@4.6.0 +gslib+shared+miniapps",
+        sha256="2a31682d876626529e2778a216d403648b83b90997873659a505d982d0e65beb",
+    )
 
     phases = ["configure", "build", "install"]
 


Test patch: