Repository: spack/spack

Issue:
Installation issue: plumed "Cannot generate configure: missing dependencies ['m4']"
<!-- Thanks for taking the time to report this build failure. To proceed with the report please:

1. Title the issue "Installation issue: <name-of-the-package>".
2. Provide the information required below.

We encourage you to try, as much as possible, to reduce your problem to the minimal example that still reproduces the issue. That would help us a lot in fixing it quickly and effectively! -->

Plumed being installed as a dependency of cp2k.

Error `RuntimeError: Cannot generate configure: missing dependencies ['m4']` is very odd!

Seems related to #3790, #15488 but no solution available

### Steps to reproduce the issue

<!-- Fill in the exact spec you are trying to build and the relevant part of the error message -->
```console
$ spack spec cp2k@8.1 +openmp +mpi +plumed %gcc@9.3.0 smm=blas ^cray-libsci
Input spec
--------------------------------
cp2k@8.1%gcc@9.3.0+mpi+openmp+plumed smm=blas
    ^cray-libsci

Concretized
--------------------------------
cp2k@8.1%gcc@9.3.0~cosma~cuda~cuda_arch_35_k20x~cuda_blas~cuda_fft~elpa+libint~libvori+libxc+mpi+openmp~pexsi+plumed~sirius~spglib cuda_arch=none lmax=5 smm=blas arch=cray-cnl7-aarch64
    ^cray-libsci@20.06.1%gcc@9.3.0~mpi~openmp+shared arch=cray-cnl7-aarch64
    ^fftw@3.3.9%gcc@9.3.0+mpi+openmp~pfft_patches precision=double,float arch=cray-cnl7-aarch64
    ^libint@2.6.0%gcc@9.3.0+fortran tune=cp2k-lmax-5 arch=cray-cnl7-aarch64
        ^autoconf@2.69%gcc@9.3.0 arch=cray-cnl7-aarch64
        ^automake@1.15.1%gcc@9.3.0 arch=cray-cnl7-aarch64
        ^boost@1.76.0%gcc@9.3.0+atomic+chrono~clanglibcpp~container~context~coroutine+date_time~debug+exception~fiber+filesystem+graph~icu+iostreams+locale+log+math~mpi+multithreaded~numpy~pic+program_options~python+random+regex+serialization+shared+signals~singlethreaded+system~taggedlayout+test+thread+timer~versionedlayout+wave cxxstd=98 patches=57a8401dee8f52b0342e0c8147a5b2db834e8d8f3fbcbbc5950016bd3e9e1ef0 visibility=hidden arch=cray-cnl7-aarch64
            ^bzip2@1.0.6%gcc@9.3.0~debug~pic+shared arch=cray-cnl7-aarch64
            ^zlib@1.2.11%gcc@9.3.0+optimize+pic+shared arch=cray-cnl7-aarch64
        ^gmp@6.2.1%gcc@9.3.0 arch=cray-cnl7-aarch64
            ^libtool@2.4.6%gcc@9.3.0 arch=cray-cnl7-aarch64
            ^m4@1.4.18%gcc@9.3.0+sigsegv patches=3877ab548f88597ab2327a2230ee048d2d07ace1062efe81fc92e91b7f39cd00,fc9b61654a3ba1a8d6cd78ce087e7c96366c290bc8d2c299f09828d793b853c8 arch=cray-cnl7-aarch64
    ^libxc@4.3.4%gcc@9.3.0~cuda+shared cuda_arch=none arch=cray-cnl7-aarch64
        ^perl@5.26.1%gcc@9.3.0~cpanm+shared+threads patches=0eac10ed90aeb0459ad8851f88081d439a4e41978e586ec743069e8b059370ac arch=cray-cnl7-aarch64
    ^mpich@7.7.16%gcc@9.3.0~argobots+fortran+hwloc+hydra+libxml2+pci+romio~slurm~verbs+wrapperrpath device=ch4 netmod=ofi pmi=pmi arch=cray-cnl7-aarch64
    ^pkg-config@0.29.2%gcc@9.3.0+internal_glib arch=cray-cnl7-aarch64
    ^plumed@2.6.2%gcc@9.3.0+gsl+mpi+shared arrayfire=none optional_modules=all arch=cray-cnl7-aarch64
        ^gsl@2.6%gcc@9.3.0~external-cblas arch=cray-cnl7-aarch64
        ^py-cython@0.29.22%gcc@9.3.0 arch=cray-cnl7-aarch64
            ^py-setuptools@50.3.2%gcc@9.3.0 arch=cray-cnl7-aarch64
                ^python@3.6.10%gcc@9.3.0+bz2+ctypes~dbm~debug+libxml2+lzma+nis~optimizations+pic+pyexpat+pythoncmd+readline+shared+sqlite3+ssl~tix~tkinter~ucs4+uuid+zlib patches=ebdca648c9c1d25f586d7e2a495b62e6d91973b55264a13d89eda1beff72ef56 arch=cray-cnl7-aarch64


$ spack install cp2k@8.1 +openmp +mpi +plumed %gcc@9.3.0 smm=blas ^cray-libsci
...
==> Installing plumed-2.6.2-t7wj4ushrqnylshz5yfqnmvmgjajzkea
==> No binary for plumed-2.6.2-t7wj4ushrqnylshz5yfqnmvmgjajzkea found: installing from source
==> Warning: Missing a source id for cray-libsci@20.06.1
==> Warning: Missing a source id for mpich@7.7.16
==> Using cached archive: /lustre/software/aarch64/spack/var/spack/cache/_source-cache/archive/bb/bbc2ef0cb08d404513b8b737c72333b6656389e15effd6a0f9ace2a5758c9a4a.tar.gz
==> Ran patch() for plumed
==> plumed: Executing phase: 'autoreconf'
==> Error: RuntimeError: Cannot generate configure: missing dependencies ['m4']

/lustre/software/aarch64/spack/lib/spack/spack/build_systems/autotools.py:264, in autoreconf:
        261        autotools = ['m4', 'autoconf', 'automake', 'libtool']
        262        missing = [x for x in autotools if x not in spec]
        263        if missing:
  >>    264            msg = 'Cannot generate configure: missing dependencies {0}'
        265            raise RuntimeError(msg.format(missing))
        266        tty.msg('Configure script not found: trying to generate it')
        267        tty.warn('*********************************************************')
...
```

### Information on your system

<!-- Please include the output of `spack debug report` -->
* **Spack:** 0.16.2-2867-2b78b04dc5
* **Python:** 3.6.10
* **Platform:** cray-sles15-thunderx2
* **Concretizer:** original

<!-- If you have any relevant configuration detail (custom `packages.yaml` or `modules.yaml`, etc.) you can add that here as well. -->

`packages.yaml` changes:
```
  mpi:
    externals:
    - spec: "mpich@7.7.16"
      modules:
      - cray-mpich/7.7.16
    buildable: False
  openblas:
    externals:
    - spec: "openblas@0.3.15"
      modules:
      - apps/openblas/0.3.15
  fftw:
    externals:
    - spec: "fftw+openmp"
      modules:
      - cray-fftw
  cray-libsci:
    externals:
    - spec: "cray-libsci"
      modules:
      - cray-libsci
 ```

### Additional information

<!-- Please upload the following files. They should be present in the stage directory of the failing build. Also upload any config.log or similar file if one exists. -->

spack-build-out.txt
```
==> plumed: Executing phase: 'autoreconf'
==> [2021-05-27-11:13:49.517838] FILTER FILE: configure.ac [replacing "-lgslcblas"]
```
[spack-build-env-20210527.txt](https://github.com/spack/spack/files/6553568/spack-build-env-20210527.txt)

<!-- Some packages have maintainers who have volunteered to debug build failures. Run `spack maintainers <name-of-the-package>` and @mention them here if they exist. -->

@tgamblin, @alalazo, @RemiLacroix-IDRIS - Mentioned authors of plumed's package.py as no official maintainer is listed

### General information

<!-- These boxes can be checked by replacing [ ] with [x] or by clicking them after submitting the issue. -->
- [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:
Same result on
* **Spack:** 0.16.2-2821-d46e49ef7a
* **Python:** 3.6.8
* **Platform:** cray-rhel8-zen2
* **Concretizer:** original

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/plumed/package.py b/var/spack/repos/builtin/packages/plumed/package.py
--- a/var/spack/repos/builtin/packages/plumed/package.py
+++ b/var/spack/repos/builtin/packages/plumed/package.py
@@ -79,6 +79,7 @@ class Plumed(AutotoolsPackage):
     depends_on('autoconf', type='build')
     depends_on('automake', type='build')
     depends_on('libtool', type='build')
+    depends_on('m4', type='build')
     depends_on('py-cython', type='build', when='@2.5:')
 
     force_autoreconf = True


Test patch: