Repository: spack/spack

Issue:
binutils fails on MacOS
Error message:
```sh
libtool: link: <path>/spack/lib/spack/env/clang/clang -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -I./../zlib -fPIC -Wl,-no_pie -o .libs/objdump objdump.o dwarf.o prdbg.o rddbg.o debug.o stabs.o ieee.o rdcoff.o bucomm.o version.o filemode.o elfcomm.o od-macho.o od-xcoff.o  ../opcodes/.libs/libopcodes.dylib -L/private/var/folders/lc/b4bjrtcn69d279m6rf4f42y00000gn/T/<user>/spack-stage/spack-stage-kNzi_m/binutils-2.27/opcodes/../libiberty/pic ../bfd/.libs/libbfd.dylib -L/private/var/folders/lc/b4bjrtcn69d279m6rf4f42y00000gn/T/<user>/spack-stage/spack-stage-kNzi_m/binutils-2.27/bfd/../libiberty/pic -L/private/var/folders/lc/b4bjrtcn69d279m6rf4f42y00000gn/T/<user>/spack-stage/spack-stage-kNzi_m/binutils-2.27/zlib -liberty -ldl -lz ../libiberty/libiberty.a ./../intl/libintl.a -liconv
Undefined symbols for architecture x86_64:
  "_libintl_setlocale", referenced from:
      _main in ar.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[4]: *** [ranlib] Error 1
```

This may be related to [this comment](https://github.com/LLNL/spack/issues/2613#issuecomment-269574542). As per the suggestion, it was fixed by adding
```
depends_on('gettext')
```
to list of dependencies. However, I don't know whether this is only a MacOS issue or not.


Discussion:
that could be already fixed in the current `develop` branch:
```
==> Installing binutils
==> flex is already installed in /Users/davydden/spack/opt/spack/darwin-sierra-x86_64/clang-8.0.0-apple/flex-2.6.3-wf3qneuehsmdx6oytyraeqetycn3pdmp
==> bison is already installed in /Users/davydden/spack/opt/spack/darwin-sierra-x86_64/clang-8.0.0-apple/bison-3.0.4-fhzg7v6o2ckiouklulx6fpff3clrbcse
==> m4 is already installed in /Users/davydden/spack/opt/spack/darwin-sierra-x86_64/clang-8.0.0-apple/m4-1.4.18-sy22bcagnzogtp3lalro3aahx4vuhwwd
==> Using cached archive: /Users/davydden/spack/var/spack/cache/binutils/binutils-2.27.tar.bz2
==> Staging archive: /Users/davydden/spack/var/spack/stage/binutils-2.27-3dotjifbhja6vkduaqjqtyiveyhsntlj/binutils-2.27.tar.bz2
==> Created stage in /Users/davydden/spack/var/spack/stage/binutils-2.27-3dotjifbhja6vkduaqjqtyiveyhsntlj
==> Applied patch cr16.patch
==> Building binutils [Package]
==> Executing phase : 'install'
==> Successfully installed binutils
  Fetch: 0.12s.  Build: 19m 50.91s.  Total: 19m 51.03s.
```
but it does NOT have `gettext` as a dependency at the moment.
Ah, ok thanks. I keep on forgetting that my few weeks old version of spack is far too old :-)
So, I got the same error on Yosemite (10.10.5) on develop.
```
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[4]: *** [size] Error 1
make[4]: *** Waiting for unfinished jobs....
libtool: link: /Users/Marco/Projects/HackIllinois17/spack/lib/spack/env/clang/clang -W -Wall -Wstrict-p\
rototypes -Wmissing-prototypes -Wshadow -I./../zlib -g -O2 -Wl,-no_pie -o .libs/objdump objdump.o dwarf\
.o prdbg.o rddbg.o debug.o stabs.o ieee.o rdcoff.o bucomm.o version.o filemode.o elfcomm.o od-macho.o o\
d-xcoff.o  ../opcodes/.libs/libopcodes.dylib -L/private/var/folders/fr/qj8h1c917rz1kdng225dgy180000gn/T\
/Marco/spack-stage/spack-stage-jMZYaZ/binutils-2.27/opcodes/../libiberty/pic ../bfd/.libs/libbfd.dylib \
-L/private/var/folders/fr/qj8h1c917rz1kdng225dgy180000gn/T/Marco/spack-stage/spack-stage-jMZYaZ/binutil\
s-2.27/bfd/../libiberty/pic -L/private/var/folders/fr/qj8h1c917rz1kdng225dgy180000gn/T/Marco/spack-stag\
e/spack-stage-jMZYaZ/binutils-2.27/zlib -liberty -ldl -lz ../libiberty/libiberty.a ./../intl/libintl.a \
-liconv
Undefined symbols for architecture x86_64:
  "_libintl_setlocale", referenced from:
      _main in ar.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[4]: *** [ar] Error 1
Undefined symbols for architecture x86_64:
  "_libintl_setlocale", referenced from:
      _main in objdump.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[4]: *** [objdump] Error 1
make[3]: *** [all-recursive] Error 1
make[2]: *** [all] Error 2
make[1]: *** [all-binutils] Error 2
make: *** [all] Error 2
```

I encountered this problem as well. As described above,
```
depends_on('gettext')
```
corrects it for me. I suggest to use this as official resolution.

Resolving patch:
diff --git a/var/spack/repos/builtin/packages/binutils/package.py b/var/spack/repos/builtin/packages/binutils/package.py
--- a/var/spack/repos/builtin/packages/binutils/package.py
+++ b/var/spack/repos/builtin/packages/binutils/package.py
@@ -41,6 +41,7 @@ class Binutils(Package):
     depends_on('m4', type='build')
     depends_on('flex', type='build')
     depends_on('bison', type='build')
+    depends_on('gettext')
 
     # Add a patch that creates binutils libiberty_pic.a which is preferred by
     # OpenSpeedShop and cbtf-krell


Test patch: