Repository: spack/spack

Issue:
Glib build failure when AutotoolsPackage does not load m4
``` bash
$ spack install glib
==> Installing glib
==> Applied patch no-Werror=format-security.patch
==> Ran patch() for glib
==> Building glib [AutotoolsPackage]
==> Executing phase : 'autoreconf'
==> Error: ProcessError: Command exited with status 1:
/spack/lib/spack/spack/build_systems/autotools.py:229, in autoreconf:
     198      def autoreconf(self, spec, prefix):
     199          """Not needed usually, configure should be already there"""
     200          # If configure exists nothing needs to be done
     201          if os.path.exists(self.configure_abs_path):
     202              return
     203          # Else try to regenerate it
     204          autotools = ['m4', 'autoconf', 'automake', 'libtool']
     205          missing = [x for x in autotools if x not in spec]
     206          if missing:
     207              msg = 'Cannot generate configure: missing dependencies {0}'
     208              raise RuntimeError(msg.format(missing))
     209          tty.msg('Configure script not found: trying to generate it')
     210          tty.warn('*********************************************************')
     211          tty.warn('* If the default procedure fails, consider implementing *')
     212          tty.warn('*        a custom AUTORECONF phase in the package       *')
     213          tty.warn('*********************************************************')
     214          with working_dir(self.configure_directory):
     215              m = inspect.getmodule(self)
     216              # This part should be redundant in principle, but
     217              # won't hurt
     218              m.libtoolize()
     219              m.aclocal()
     220              # This line is what is needed most of the time
     221              # --install, --verbose, --force
     222              autoreconf_args = ['-ivf']
     223              if 'pkg-config' in spec:
     224                  autoreconf_args += [
     225                      '-I',
     226                      join_path(spec['pkg-config'].prefix, 'share', 'aclocal'),
     227                  ]
     228              autoreconf_args += self.autoreconf_extra_args
  >> 229              m.autoreconf(*autoreconf_args)
```

From the build log

```
==> Configure script not found: trying to generate it
==> Warning: *********************************************************
==> Warning: * If the default procedure fails, consider implementing *
==> Warning: *        a custom AUTORECONF phase in the package       *
==> Warning: *********************************************************
==> 'libtool-2.4.6-bcbiddkmbu4gy7wx6ftntmxqe3c5br3z/bin/libtoolize'
libtoolize:   error: One of these is required:
libtoolize:                 gm4 gnum4 m4
libtoolize:   error: Please install GNU M4, or 'export M4=/path/to/gnu/m4'.
```

Which is solved when m4 is added as a dependency

``` python
depends_on('m4', type='build')
```

My deeper question is whether this dependency belongs in the package like the solution above, or if AutotoolsPackage should find this automatically.


Discussion:
> Which is solved when m4 is added as a dependency
> ```python
> depends_on('m4', type='build')
> ```

Want to submit a PR?

> My deeper question is whether this dependency belongs in the package like the solution above, or if AutotoolsPackage should find this automatically.

We've talked about this before, and the general consensus is that we should only add libtool/m4/autoconf/automake dependencies on packages that need to run autoreconf. For the vast majority of AutotoolsPackages, this is not required as they already come with a configure script. Adding those dependencies to every package could cause builds to take longer. If any of those packages can't be built with a certain compiler, it would mean that no AutotoolsPackage could be built anymore.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/flex/package.py b/var/spack/repos/builtin/packages/flex/package.py
--- a/var/spack/repos/builtin/packages/flex/package.py
+++ b/var/spack/repos/builtin/packages/flex/package.py
@@ -44,7 +44,7 @@ class Flex(AutotoolsPackage):
     depends_on('help2man',      type='build')
 
     # Older tarballs don't come with a configure script
-    depends_on('m4',       type='build', when='@:2.6.0')
+    depends_on('m4',       type='build')
     depends_on('autoconf', type='build', when='@:2.6.0')
     depends_on('automake', type='build', when='@:2.6.0')
     depends_on('libtool',  type='build', when='@:2.6.0')
diff --git a/var/spack/repos/builtin/packages/glib/package.py b/var/spack/repos/builtin/packages/glib/package.py
--- a/var/spack/repos/builtin/packages/glib/package.py
+++ b/var/spack/repos/builtin/packages/glib/package.py
@@ -41,6 +41,7 @@ class Glib(AutotoolsPackage):
     depends_on('autoconf', type='build')
     depends_on('automake', type='build')
     depends_on('libtool', type='build')
+    depends_on('m4', type='build')
     depends_on('pkg-config+internal_glib', type='build')
     depends_on('libffi')
     depends_on('zlib')


Test patch: