Repository: spack/spack

Issue:
Installation issue: zoltan +parmetis
### Steps to reproduce the issue

```console
spack --env zen2-gcc1130-mpi-nocuda spec -l zoltan
Input spec
--------------------------------
zoltan

Concretized
--------------------------------
47ijwlq  zoltan@3.901%gcc@11.3.0~debug+fortran~int64+mpi+parmetis+shared build_system=autotools arch=linux-rhel8-zen2
yxpydi6      ^autoconf@2.69%gcc@11.3.0 build_system=autotools patches=35c4492,7793209,a49dd5b arch=linux-rhel8-zen2
sve5wjh          ^perl@5.36.0%gcc@11.3.0+cpanm+open+shared+threads build_system=generic arch=linux-rhel8-zen2
nayr6pc              ^berkeley-db@18.1.40%gcc@11.3.0+cxx+docs+stl build_system=autotools patches=26090f4 arch=linux-rhel8-zen2
y2p2gbz              ^bzip2@1.0.8%gcc@11.3.0~debug+pic+shared build_system=generic arch=linux-rhel8-zen2
tspio6g              ^gdbm@1.23%gcc@11.3.0 build_system=autotools arch=linux-rhel8-zen2
boheg7m                  ^readline@8.2%gcc@11.3.0 build_system=autotools patches=bbf97f1 arch=linux-rhel8-zen2
vr5d2na      ^automake@1.16.5%gcc@11.3.0 build_system=autotools arch=linux-rhel8-zen2
2xgh4yr      ^m4@1.4.19%gcc@11.3.0+sigsegv build_system=autotools patches=9dc5fbd,bfdffa7 arch=linux-rhel8-zen2
nbfheoo          ^diffutils@3.9%gcc@11.3.0 build_system=autotools arch=linux-rhel8-zen2
ghqoznx              ^libiconv@1.17%gcc@11.3.0 build_system=autotools libs=shared,static arch=linux-rhel8-zen2
lskfqtb          ^libsigsegv@2.14%gcc@11.3.0 build_system=autotools arch=linux-rhel8-zen2
aphfjo2      ^metis@5.1.0%gcc@11.3.0+gdb~int64+ipo~real64+shared build_system=cmake build_type=RelWithDebInfo generator=make patches=4991da9,93a7903,b1225da arch=linux-rhel8-zen2
simblvj          ^cmake@3.26.3%gcc@11.3.0~doc+ncurses+ownlibs~qt build_system=generic build_type=Release arch=linux-rhel8-zen2
k6m5lie              ^ncurses@6.4%gcc@11.3.0+symlinks+termlib abi=5 build_system=autotools arch=linux-rhel8-zen2
bjvjttn              ^openssl@1.1.1v%gcc@11.3.0~docs+shared build_system=generic certs=system arch=linux-rhel8-zen2
bcadp5n          ^gmake@4.4.1%gcc@11.3.0+guile build_system=autotools arch=linux-rhel8-zen2
fny73jv              ^guile@2.2.6%gcc@11.3.0+readline build_system=autotools threads=none arch=linux-rhel8-zen2
zy5n3jc                  ^bdw-gc@8.2.2%gcc@11.3.0+libatomic-ops build_system=autotools threads=none arch=linux-rhel8-zen2
tkxbqtj                      ^libatomic-ops@7.8.0%gcc@11.3.0 build_system=autotools arch=linux-rhel8-zen2
aym4bs5                  ^gettext@0.21.1%gcc@11.3.0+bzip2+curses+git+libunistring+libxml2+tar+xz build_system=autotools arch=linux-rhel8-zen2
vjlzfma                      ^tar@1.34%gcc@11.3.0 build_system=autotools zip=pigz arch=linux-rhel8-zen2
pnsotvl                          ^pigz@2.7%gcc@11.3.0 build_system=makefile arch=linux-rhel8-zen2
5hgslof                          ^zstd@1.5.5%gcc@11.3.0+programs build_system=makefile compression=lz4,lzma,zlib libs=shared,static arch=linux-rhel8-zen2
qmkbina                              ^lz4@1.9.4%gcc@11.3.0 build_system=makefile libs=shared,static arch=linux-rhel8-zen2
rbqwy2o                  ^gmp@6.2.1%gcc@11.3.0+cxx build_system=autotools libs=shared,static patches=69ad2e2 arch=linux-rhel8-zen2
akxkimj                  ^libffi@3.4.4%gcc@11.3.0 build_system=autotools arch=linux-rhel8-zen2
zra6tcb                  ^libunistring@1.1%gcc@11.3.0 build_system=autotools arch=linux-rhel8-zen2
zw2zshc      ^openmpi@4.1.5%gcc@11.3.0+atomics~cuda+cxx+cxx_exceptions~gpfs~internal-hwloc~java+legacylaunchers~lustre~memchecker+orterunprefix+pmi+romio+rsh~singularity~static~vt+wrapper-rpath build_system=autotools fabrics=ucx schedulers=slurm arch=linux-rhel8-zen2
hyze5je          ^hwloc@2.9.1%gcc@11.3.0~cairo~cuda~gl+libudev+libxml2~netloc~nvml~oneapi-level-zero~opencl+pci~rocm build_system=autotools libs=shared,static arch=linux-rhel8-zen2
qga6koi              ^libpciaccess@0.17%gcc@11.3.0 build_system=autotools arch=linux-rhel8-zen2
5s2rtxx                  ^util-macros@1.19.3%gcc@11.3.0 build_system=autotools arch=linux-rhel8-zen2
hfk7szf              ^libxml2@2.10.3%gcc@11.3.0~python build_system=autotools arch=linux-rhel8-zen2
ranwi3u                  ^xz@5.4.1%gcc@11.3.0+pic build_system=autotools libs=shared,static arch=linux-rhel8-zen2
262ta3t          ^numactl@2.0.14%gcc@11.3.0 build_system=autotools patches=4e1d78c,62fc8a8,ff37630 arch=linux-rhel8-zen2
ovq4gsp              ^libtool@2.4.7%gcc@11.3.0 build_system=autotools arch=linux-rhel8-zen2
r4hghfg          ^openssh@9.3p1%gcc@11.3.0+gssapi build_system=autotools arch=linux-rhel8-zen2
hoxnvw7              ^krb5@1.20.1%gcc@11.3.0+shared build_system=autotools arch=linux-rhel8-zen2
idcnjva                  ^bison@3.8.2%gcc@11.3.0 build_system=autotools arch=linux-rhel8-zen2
egb5eml              ^libedit@3.1-20210216%gcc@11.3.0 build_system=autotools arch=linux-rhel8-zen2
5zyvitn              ^libxcrypt@4.4.33%gcc@11.3.0~obsolete_api build_system=autotools arch=linux-rhel8-zen2
wqtnva5          ^pkg-config@0.29.2%gcc@11.3.0+internal_glib build_system=autotools arch=linux-rhel8-zen2
vxjuhaw          ^pmix@3.2.3%gcc@11.3.0~docs+pmi_backwards_compatibility build_system=autotools arch=linux-rhel8-zen2
l3smejv          ^slurm@system%gcc@11.3.0~gtk~hdf5~hwloc~mariadb~pmix+readline~restd build_system=autotools sysconfdir=/etc/slurm arch=linux-rhel8-zen2
ktl3nrn          ^ucx@1.15.0%gcc@11.3.0~assertions~backtrace_detail+cma~cuda~dc~debug~dm+examples~gdrcopy~gtest~ib_hw_tm~java+knem~logging~mlx5_dv+openmp+optimizations~parameter_checking+pic~rc+rdmacm~rocm+thread_multiple~ucg~ud~verbs~vfs+xpmem build_system=autotools libs=shared opt=3 simd=auto arch=linux-rhel8-zen2
gv2fyi6          ^zlib@1.2.13%gcc@11.3.0+optimize+pic+shared build_system=makefile arch=linux-rhel8-zen2
xgnozun      ^parmetis@4.0.3%gcc@11.3.0+gdb~int64+ipo+shared build_system=cmake build_type=RelWithDebInfo generator=make patches=4f89253,50ed208,704b84f arch=linux-rhel8-zen2

```


### Error message

<details><summary>Error message</summary>
From spack-build-out.txt
<pre>
checking for Fortran libraries of /cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-11.3.0/openmpi-4.1.5-zw2zshcccd6pxn5vbrvety4ak47o3vo3/bin/mpif90...  -L/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-11.3.0/openmpi-4.1.5-zw2zshcccd6pxn5vbrvety4ak47o3vo3/lib -L/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-11.3.0/parmetis-4.0.3-xgnozunlg5yiaqquja6tcz4bj6d5ulek/lib -L/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-11.3.0/hwloc-2.9.1-hyze5jeeavvbjcuua3tw2elw5bvusutx/lib -L/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-x86_64/gcc-rh8-8.5.0/gcc-11.3.0-xcucl3zztfbti6msiha626natoyqgyuu/lib/gcc/x86_64-pc-linux-gnu/11.3.0 -L/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-x86_64/gcc-rh8-8.5.0/gcc-11.3.0-xcucl3zztfbti6msiha626natoyqgyuu/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-x86_64/gcc-rh8-8.5.0/gcc-11.3.0-xcucl3zztfbti6msiha626natoyqgyuu/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../.. -lparmetis -lmetis -lgfortran -lm -lmpi_usempif08 -lmpi_usempi_ignore_tkr -lmpi_mpifh -lmpi -lquadmath -lpthread -lmetis:
checking for dummy main to link with Fortran libraries... unknown
configure: error: in `/tmp/devspackswinst/spack-stage/spack-stage-zoltan-3.901-qz4sa572p5gsmaaei7sgitc6yj6a4r54/spack-src/spack-build':
configure: error: linking to Fortran libraries from C fails
See `config.log' for more details
</pre>

Looking into config.log, we get the weird error:
<pre>
configure:7171: /cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-11.3.0/openmpi-4.1.5-zw2zshcccd6pxn5vbrvety4ak47o3vo3/bin/mpicc -o conftest -I/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-11.3.0/metis-5.1.0-aphfjo24iaqc7nqgsj5m6skbtfhavn7u/include -O3  -fPIC -g -O2 -I/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-11.3.0/metis-5.1.0-aphfjo24iaqc7nqgsj5m6skbtfhavn7u/include -I/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-11.3.0/parmetis-4.0.3-xgnozunlg5yiaqquja6tcz4bj6d5ulek/include   -I/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-11.3.0/openmpi-4.1.5-zw2zshcccd6pxn5vbrvety4ak47o3vo3/include   -L/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-11.3.0/openmpi-4.1.5-zw2zshcccd6pxn5vbrvety4ak47o3vo3/lib conftest.c -L/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-11.3.0/parmetis-4.0.3-xgnozunlg5yiaqquja6tcz4bj6d5ulek/lib -lparmetis -lmetis   -lgfortran  -lm  -L/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-11.3.0/openmpi-4.1.5-zw2zshcccd6pxn5vbrvety4ak47o3vo3/lib -L/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-11.3.0/parmetis-4.0.3-xgnozunlg5yiaqquja6tcz4bj6d5ulek/lib -L/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-zen2/gcc-11.3.0/hwloc-2.9.1-hyze5jeeavvbjcuua3tw2elw5bvusutx/lib -L/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-x86_64/gcc-rh8-8.5.0/gcc-11.3.0-xcucl3zztfbti6msiha626natoyqgyuu/lib/gcc/x86_64-pc-linux-gnu/11.3.0 -L/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-x86_64/gcc-rh8-8.5.0/gcc-11.3.0-xcucl3zztfbti6msiha626natoyqgyuu/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-x86_64/gcc-rh8-8.5.0/gcc-11.3.0-xcucl3zztfbti6msiha626natoyqgyuu/lib/gcc/x86_64-pc-linux-gnu/11.3.0/../../.. -lparmetis -lmetis -lgfortran -lm -lmpi_usempif08 -lmpi_usempi_ignore_tkr -lmpi_mpifh -lmpi -lquadmath -lpthread -lmetis: >&5
/cvmfs/hpcsw.umd.edu/spack-software/2023.05.30/linux-rhel8-x86_64/gcc-rh8-8.5.0/binutils-2.40-z4s4xiexafvsqqmflqkbxdtnjiw2dssb/bin/ld: cannot find -lmetis:: No such file or directory
</pre>
</details>

The config.log error is weird because is looking for libmetis:.so (note the colon).

Some digging reveals this is because for some reason (I suspect ultimately a autoconf bug, but the internals of configure are a rather black magic as far as I am concerned) configure is parsing the output of a previous compilation command to find arguments, and the previous command had an error complaining about not being able to find library metis, followed by a colon and some details.

But following that thread reveals an issue in the spack recipe for zoltan: it is passing --with-ldflags twice to configure, with different arguments each time.

### Information on your system

```console
$ spack debug report
* **Spack:** 0.21.0.dev0 (84faf5a6cf342efddb976b7432e44aff12f1c985)
* **Python:** 3.6.8
* **Platform:** linux-rhel8-zen2
* **Concretizer:** clingo
```

### Additional information

[spack-build-env.txt](https://github.com/spack/spack/files/12718028/spack-build-env.txt)
[spack-build-out.txt](https://github.com/spack/spack/files/12718029/spack-build-out.txt)

No maintainers for zoltan

### 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/zoltan/package.py b/var/spack/repos/builtin/packages/zoltan/package.py
--- a/var/spack/repos/builtin/packages/zoltan/package.py
+++ b/var/spack/repos/builtin/packages/zoltan/package.py
@@ -92,6 +92,9 @@ def configure_args(self):
         config_cflags = ["-O0" if "+debug" in spec else "-O3", "-g" if "+debug" in spec else ""]
 
         config_ldflags = []
+        config_libs = []
+        config_incdirs = []
+
         # PGI runtime libraries
         if "%pgi" in spec:
             config_ldflags.append("-pgf90libs")
@@ -102,9 +105,12 @@ def configure_args(self):
             config_args.extend(["RANLIB=echo", "--with-ar=$(CXX) -shared $(LDFLAGS) -o"])
             config_cflags.append(self.compiler.cc_pic_flag)
             if spec.satisfies("%gcc"):
-                config_args.append("--with-libs=-lgfortran")
+                config_libs.append("-lgfortran")
+                # Although adding to config_libs _should_ suffice, it does not
+                # Add to ldflags as well
+                config_ldflags.append("-lgfortran")
             if spec.satisfies("%intel"):
-                config_args.append("--with-libs=-lifcore")
+                config_libs.append("-lifcore")
 
         if "+int64" in spec:
             config_args.append("--with-id-type=ulong")
@@ -116,10 +122,16 @@ def configure_args(self):
                     "--with-parmetis",
                     "--with-parmetis-libdir={0}".format(parmetis_prefix.lib),
                     "--with-parmetis-incdir={0}".format(parmetis_prefix.include),
-                    "--with-incdirs=-I{0}".format(spec["metis"].prefix.include),
-                    "--with-ldflags=-L{0}".format(spec["metis"].prefix.lib),
                 ]
             )
+            config_ldflags.append("-L{0}".format(spec["metis"].prefix.lib))
+            config_incdirs.append("-I{0}".format(spec["metis"].prefix.include))
+            config_libs.append("-lparmetis")
+            config_libs.append("-lmetis")
+            # Although appending to config_libs _should_ suffice, it does not
+            # Add them to ldflags as well
+            config_ldflags.append("-lparmetis")
+            config_ldflags.append("-lmetis")
             if "+int64" in spec["metis"]:
                 config_args.append("--with-id-type=ulong")
             else:
@@ -143,19 +155,26 @@ def configure_args(self):
                 config_args.extend(["FC={0}".format(spec["mpi"].mpifc)])
 
         config_fcflags = config_cflags[:]
+        config_cxxflags = config_cflags[:]
+
         if spec.satisfies("%gcc@10:+fortran"):
             config_fcflags.append("-fallow-argument-mismatch")
+
         # NOTE: Early versions of Zoltan come packaged with a few embedded
         # library packages (e.g. ParMETIS, Scotch), which messes with Spack's
         # ability to descend directly into the package's source directory.
-        config_args.extend(
-            [
-                "--with-cflags={0}".format(" ".join(config_cflags)),
-                "--with-cxxflags={0}".format(" ".join(config_cflags)),
-                "--with-fcflags={0}".format(" ".join(config_fcflags)),
-                "--with-ldflags={0}".format(" ".join(config_ldflags)),
-            ]
-        )
+        if config_cflags:
+            config_args.append("--with-cflags={0}".format(" ".join(config_cflags)))
+        if config_cxxflags:
+            config_args.append("--with-cxxflags={0}".format(" ".join(config_cxxflags)))
+        if config_fcflags:
+            config_args.append("--with-fcflags={0}".format(" ".join(config_fcflags)))
+        if config_ldflags:
+            config_args.append("--with-ldflags={0}".format(" ".join(config_ldflags)))
+        if config_libs:
+            config_args.append("--with-libs={0}".format(" ".join(config_libs)))
+        if config_incdirs:
+            config_args.append("--with-incdirs={0}".format(" ".join(config_incdirs)))
         return config_args
 
     # NOTE: Unfortunately, Zoltan doesn't provide any configuration


Test patch: