Repository: spack/spack

Issue:
Installation issue: Flex with gettext
### Steps to reproduce the issue

```console
$ spack install flex # @2.6.4
```

Causes:

```
==> Installing flex
==> Searching for binary cache of flex
==> No binary for flex found: installing from source
==> Fetching https://github.com/westes/flex/releases/download/v2.6.4/flex-2.6.4.tar.gz
==> Fetching https://github.com/westes/flex/commit/24fd0551333e7eded87b64dd36062da3df2f6380.patch
==> Staging archive: /usr/local/var/spack/stage/flex-2.6.4-wybwdtmqdlcpo5fkbun55tatbbdxp652/flex-2.6.4.tar.gz
==> Created stage in /usr/local/var/spack/stage/flex-2.6.4-wybwdtmqdlcpo5fkbun55tatbbdxp652
==> Applied patch https://github.com/westes/flex/commit/24fd0551333e7eded87b64dd36062da3df2f6380.patch
==> Building flex [AutotoolsPackage]
==> Executing phase: 'autoreconf'
==> Executing phase: 'configure'
==> Executing phase: 'build'
==> Error: ProcessError: Command exited with status 2:
    'make' '-j28'

2 errors found in build log:
     396    make[2]: Leaving directory '/tmp/root/spack-stage/spack-stage-QWa6O
            4/flex-2.6.4/examples'
     397    make[1]: Leaving directory '/tmp/root/spack-stage/spack-stage-QWa6O
            4/flex-2.6.4/examples'
     398    Making all in po
     399    make[1]: Entering directory '/tmp/root/spack-stage/spack-stage-QWa6
            O4/flex-2.6.4/po'
     400    *** error: gettext infrastructure mismatch: using a Makefile.in.in 
            from gettext version 0.18 but the autoconf macros are from gettext 
            version 0.19
     401    Makefile:201: recipe for target 'check-macro-version' failed
  >> 402    make[1]: *** [check-macro-version] Error 1
     403    make[1]: Leaving directory '/tmp/root/spack-stage/spack-stage-QWa6O
            4/flex-2.6.4/po'
     404    Makefile:528: recipe for target 'all-recursive' failed
  >> 405    make: *** [all-recursive] Error 1
```

### Platform and user environment

Please report your OS here:
```commandline
# Docker (nvidia/cuda:9.0-base)
https://github.com/ComputationalRadiationPhysics/picongpu/blob/dev/share/picongpu/dockerfiles/ubuntu-1604/Dockerfile

$ lsb_release -d
Description:	Ubuntu 16.04 LTS
``` 
and, if relevant, post or attach:

- `packages.yaml`
```
packages:
  cuda:
    paths:
      cuda@9.0.176%gcc@5.4.0 arch=linux-ubuntu16-x86_64: /usr/local/cuda
    buildable: False
  pkg-config:
    paths:
      pkg-config@0.29.1%gcc@5.4.0 arch=linux-ubuntu16-x86_64: /usr
    buildable: False
  python:
    paths:
      python@2.7.12%gcc@5.4.0 arch=linux-ubuntu16-x86_64: /usr
    buildable: False
  openmpi:
    version: [3.1.3]
    variants: +cuda fabrics=verbs,ucx,libfabric
  hwloc:
    variants: +cuda
  all:
    providers:
      mpi: [openmpi]
```


Discussion:
I tried to reduce the `Dockerfile` in
  https://github.com/ComputationalRadiationPhysics/picongpu/tree/d340812641320d3a61e343a521287fd0720ba55b/share/picongpu/dockerfiles/ubuntu-1604
that  experiences the issue to a more simple example in:
  https://github.com/ax3l/dockerfiles/tree/master/spack/flex

Unfortunately, it doesn't seam to show the issue.

```bash
docker build -t flexspack .
docker run -it flexspack
> spack install flex
# should fail as above
```
FWIW - I'm seeing this exact same error reported by the `flex` build system.  I'm using gcc@8.1.0 on a RHEL7 machine.  Luckily, I can point to a system installed version of _flex_ via `packages.yaml` as a work around.
FWIW. Background Notes:
This `gettext` issue has arisen -- outside of the Spack context -- in cases such as:
- (AMSYNTH) https://github.com/amsynth/amsynth/issues/43
- (GDBM) https://forums.gentoo.org/viewtopic-t-1087200-start-0.html
- (SARG) https://www.linuxhelp.com/questions/sarg-make-1-check-macro-version-error-1
Note that I am not able to reproduce this problem on `rhel7` with `gcc-7.3.0` when installing `flex@2.6.4`.  The build is fetching and installing `gettext 0.20.1`.
I **can** reproduce the error with the container.  

The `spack-src` subdirectory of the stage has an `aclocal.m4` file with the following line:

```
# gettext.m4 serial 67 (gettext-0.19.6)
```

**and**, in the same file:

```
...
# iconv.m4 serial 19 (gettext-0.18.2)
...
# intlmacosx.m4 serial 5 (gettext-0.18.2)
...
# lib-link.m4 serial 26 (gettext-0.18.2)
...
# lib-prefix.m4 serial 7 (gettext-0.18)
...
# nls.m4 serial 5 (gettext-0.18)
...
# progtest.m4 serial 7 (gettext-0.18.2)
...
# po.m4 serial 24 (gettext-0.19)
```

where the `po.m4` entry is probably related to me manually changing `Makefile.in.in` as recommended in the `SARG` link above, especially since 22 of the `m4` files in the `m4` subdirectory all reference `(gettext-0.18)` including `m4/po.m4`.
I just ran into this and deployed this fix. I'll spend some more time looking, but does this fix the issue for anyone else?
```
diff --git a/var/spack/repos/builtin/packages/flex/package.py b/var/spack/repos/builtin/packages/flex/package.py
index 3c9f51a..82a1123 100644
--- a/var/spack/repos/builtin/packages/flex/package.py
+++ b/var/spack/repos/builtin/packages/flex/package.py
@@ -43,6 +43,10 @@ class Flex(AutotoolsPackage):
     # - https://github.com/westes/flex/issues/241
     patch('https://github.com/westes/flex/commit/24fd0551333e7eded87b64dd36062da3df2f6380.patch', sha256='09c22e5c6fef327d3e48eb23f
 
+    def autoreconf(self, spec, prefix):
+        bash = which('bash')
+        bash('./autogen.sh')
+
     @property
     def force_autoreconf(self):
         # The patch for 2.6.4 touches configure

```
The above patch fixes it for me on Ubuntu 18.04 LTS.
Good hunting @aweits :slightly_smiling_face: I think it's relatively safe to assume that autotools packages are *nix only.  Your patch worked for me, I made one small difference though -- instead of `bash` you should do `sh = which('sh')` and `sh('./autogen.sh')`.  Really glad you found it, because I don't think I would have!  My `sh` is `bash` so I haven't really confirmed that it works for `zsh` or others, but "in theory" using `sh` will be OK for other shells.
@aweits awesome, this is valid since there is a patch in `flex` that triggers autoreconf for the latest version.

Do you want to submit your patch as a PR?
The most compact/modern form would be:
```py
    def autoreconf(self, spec, prefix):
        autogen = Executable('./autogen.sh')
        autogen()
```
I think this might be due to #15784 since this causes the gettext aclocal directory to be included (I never had this problem before, but today's rebuild fails). Anyway, @ax3l's snippet fixes the problem.

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
@@ -43,6 +43,11 @@ class Flex(AutotoolsPackage):
     # - https://github.com/westes/flex/issues/241
     patch('https://github.com/westes/flex/commit/24fd0551333e7eded87b64dd36062da3df2f6380.patch', sha256='09c22e5c6fef327d3e48eb23f0d610dcd3a35ab9207f12e0f875701c677978d3', when='@2.6.4')
 
+    @when('@:2.6.0,2.6.4')
+    def autoreconf(self, spec, prefix):
+        autogen = Executable('./autogen.sh')
+        autogen()
+
     @property
     def force_autoreconf(self):
         # The patch for 2.6.4 touches configure


Test patch: