Repository: spack/spack

Issue:
git won't build for me now that it `depends_on('gettext')`
I made a PR for the git package that enables perl and pcre a while back.  Since then another PR has been merged that enables gettext support.

I've rebased my PR and am trying to unsuccessfully to test it, there's a gettext related problem.  I've stepped back to the commit that added gettext support and I have the same problem there.

The symptom is that it's blowing up with it tries to link executables because it can't find an implementation for libintl_gettext().  E.g. lots and lots of:

```
    LINK git-show-index
libgit.a(wrapper.o): In function `_':
/tmp/throgg/spack-stage/spack-stage-d4Tihu/git-git-fdeee3d/gettext.h:54: undefined reference to `libintl_gettext'
/tmp/throgg/spack-stage/spack-stage-d4Tihu/git-git-fdeee3d/gettext.h:54: undefined reference to `libintl_gettext'
/tmp/throgg/spack-stage/spack-stage-d4Tihu/git-git-fdeee3d/gettext.h:54: undefined reference to `libintl_gettext'
/tmp/throgg/spack-stage/spack-stage-d4Tihu/git-git-fdeee3d/gettext.h:54: undefined reference to `libintl_gettext'
/tmp/throgg/spack-stage/spack-stage-d4Tihu/git-git-fdeee3d/gettext.h:54: undefined reference to `libintl_gettext'
```

If I `spack env git bash` and cd into the staging dir and run `make -V=1` and then try to run the "link" command by hand I can replicate the failure.  If I try again with a `-L... -lintl` added, e.g.:

```
-L/home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/gettext-0.19.8.1-dhus6ppmjmb6ze2pfml3yixa6a5o4ufn/lib -lintl
```

Then things link fine.

The `configure` script doesn't seem to have any support for `--with-gettext` so I'm not sure what should be happening.  If I comment the `depends_on('gettext')` out then the build succeeds.

I'm on a fairly sparsely configure CentOS 7 system.

@adamjstewart -- I think that your commit added `depends_on('gettext')` to git.  Did/does it work for you?



Discussion:
@hartzell It worked for me on CentOS 6, weird. You can try adding this to the git package:

``` python
env['LIBS'] = '-lintl'
```

Spack adds the `-L...` stuff automatically.

We can also make gettext an optional dependency if we need to. I think it's a good idea to keep the gettext dependency. From git's `INSTALL` file:

```
        - A gettext library is used by default for localizing Git. The
          primary target is GNU libintl, but the Solaris gettext
          implementation also works.

          We need a gettext.h on the system for C code, gettext.sh (or
          Solaris gettext(1)) for shell scripts, and libintl-perl for Perl
          programs.

          Set NO_GETTEXT to disable localization support and make Git only
          use English. Under autoconf the configure script will do this
          automatically if it can't find libintl on the system.
```

Setting LIBS does not solve my problem.  After reading the configure script, I think that LIBS is only used by configure when it's running and not passed downstream.

This _does_ solve my problem.

```
env['LDFLAGS'] = "-L%s" % spec['gettext'].prefix.lib + " -lintl"
```

and the resulting binary is linked against spack's library:

```
[throgg@tmp spack]$ ldd /home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/git-2.8.1-z253wqlld7majp53v77h2f6v26sfqlld/bin/git
    linux-vdso.so.1 =>  (0x00007ffc0d3a4000)
    libintl.so.8 => /home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/gettext-0.19.8.1-dhus6ppmjmb6ze2pfml3yixa6a5o4ufn/lib/libintl.so.8 (0x00007f9d9632b000)
    libpcre.so.1 => /home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/pcre-8.38-r4qk6wzdnrnb4rlik7t6rbs2imvykd3i/lib/libpcre.so.1 (0x00007f9d96104000)
    libz.so.1 => /home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/zlib-1.2.8-zhq3ij3256qxdwg745afdcdje7zwvsyh/lib/libz.so.1 (0x00007f9d95eeb000)
    libcrypto.so.1.0.0 => /home/throgg/spack/opt/spack/linux-centos7-x86_64/gcc-5.4.0/openssl-1.0.2h-4qgkil2kybucjlidxfh73adcim6yckly/lib/libcrypto.so.1.0.0 (0x00007f9d95a95000)
    librt.so.1 => /lib64/librt.so.1 (0x00007f9d95885000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f9d95669000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f9d952a7000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007f9d950a2000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f9d96538000)
```

I'm not clear is something like this is generally safe, or?

@adamjstewart -- What `libintl` does your git end up linked with?

Oops, I guess I never actually tried building git with gettext. It fails for me too. I've installed it and uninstalled it on so many different branches that I've lost track. @tgamblin @hartzell What do you think we should do here? Add:

``` python
env['LDFLAGS'] = "-L%s" % spec['gettext'].prefix.lib + " -lintl"
```

or just remove the gettext dependency and let it pick up the system one if it exists? Other users are starting to see problems on macOS (#1446) so I'm inclined to just remove the dependency.

This behaves for me now.

I had the same problem again on an Ubuntu 14.04 (git: 8dc056130cb25990408464d55f1011175e27087e) and removed `gettext` completely from the deps to get `git` compiled:
```diff
diff --git a/var/spack/repos/builtin/packages/git/package.py b/var/spack/repos/builtin/packages/git/package.py
index c7b239e..1a19c1f 100644
--- a/var/spack/repos/builtin/packages/git/package.py
+++ b/var/spack/repos/builtin/packages/git/package.py
@@ -59,7 +59,7 @@ class Git(Package):
     depends_on("autoconf", type='build')
     depends_on("curl")
     depends_on("expat")
-    depends_on("gettext")
+    #depends_on("gettext")
     depends_on("libiconv")
     depends_on("openssl")
     depends_on("pcre")
@@ -67,7 +67,7 @@ class Git(Package):
     depends_on("zlib")
 
     def install(self, spec, prefix):
-        env['LDFLAGS'] = "-L%s" % spec['gettext'].prefix.lib + " -lintl"
+        #env['LDFLAGS'] = "-L%s" % spec['gettext'].prefix.lib + " -lintl"
         configure_args = [
             "--prefix=%s" % prefix,
             "--with-curl=%s" % spec['curl'].prefix,
```

Probably took the sys gettext now...

I'm on Ubuntu 16.04.2 and had this same problem (spack checkout from 2017/07/11).  I had to comment all references to gettext in the manner described by @ax3l before git would build.
I'm not overly familiar with building git, so I'm uploading my `build.out` and `build.env` files to help anyone who is trying to resolve this issue.  One thing I notice is that when `autoreconf` is running during the git build, I see the message:

```
autoreconf: configure.ac: not using Gettext
```

I don't know if that message applies to autoreconf itself or to the configuration of the git build directory. Anyway, here are the files:

[git-spack-build.out.txt](https://github.com/LLNL/spack/files/1151116/git-spack-build.out.txt)
[git-spack-build.env.txt](https://github.com/LLNL/spack/files/1151117/git-spack-build.env.txt)


Resolving patch:
diff --git a/var/spack/repos/builtin/packages/git/package.py b/var/spack/repos/builtin/packages/git/package.py
--- a/var/spack/repos/builtin/packages/git/package.py
+++ b/var/spack/repos/builtin/packages/git/package.py
@@ -165,13 +165,29 @@ class Git(AutotoolsPackage):
     depends_on('libtool',  type='build')
     depends_on('m4',       type='build')
 
+    # See the comment in setup_environment re EXTLIBS.
+    def patch(self):
+        filter_file(r'^EXTLIBS =$',
+                    '#EXTLIBS =',
+                    'Makefile')
+
     def setup_environment(self, spack_env, run_env):
-        # This is done to avoid failures when git is an external package.
+        # We use EXTLIBS rather than LDFLAGS so that git's Makefile
+        # inserts the information into the proper place in the link commands
+        # (alongside the # other libraries/paths that configure discovers).
+        # LDFLAGS is inserted *before* libgit.a, which requires libintl.
+        # EXTFLAGS is inserted *after* libgit.a.
+        # This depends on the patch method above, which keeps the Makefile
+        # from stepping on the value that we pass in via the environment.
+        #
+        # The test avoids failures when git is an external package.
         # In that case the node in the DAG gets truncated and git DOES NOT
         # have a gettext dependency.
         if 'gettext' in self.spec:
-            spack_env.append_flags('LDFLAGS', '-L{0} -lintl'.format(
+            spack_env.append_flags('EXTLIBS', '-L{0} -lintl'.format(
                 self.spec['gettext'].prefix.lib))
+            spack_env.append_flags('CFLAGS', '-I{0}'.format(
+                self.spec['gettext'].prefix.include))
 
     def configure_args(self):
         spec = self.spec


Test patch: