From 784234ae8e246680ba77c946c1c348460cd2f145 Mon Sep 17 00:00:00 2001
From: Geoffrey Oxberry <goxberry@gmail.com>
Date: Sun, 28 Jan 2018 06:36:24 -0800
Subject: [PATCH] libtool, binutils: fix darwin linking (#7073)

* libtool: fix linking of libtool on darwin

* binutils, libtool: fix conflicts w/ BSD tools, v2

Fix namespace conflicts with BSD tools in a more elegant fashion,
using a program prefix, similar to Homebrew.
---
 .../repos/builtin/packages/binutils/package.py      |  6 ++++++
 var/spack/repos/builtin/packages/libtool/package.py | 13 ++++++-------
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/var/spack/repos/builtin/packages/binutils/package.py b/var/spack/repos/builtin/packages/binutils/package.py
index fde3810216..8d6777daf3 100644
--- a/var/spack/repos/builtin/packages/binutils/package.py
+++ b/var/spack/repos/builtin/packages/binutils/package.py
@@ -79,4 +79,10 @@ def configure_args(self):
         if '+libiberty' in spec:
             configure_args.append('--enable-install-libiberty')
 
+        # To avoid namespace collisions with Darwin/BSD system tools,
+        # prefix executables with "g", e.g., gar, gnm; see Homebrew
+        # https://github.com/Homebrew/homebrew-core/blob/master/Formula/binutils.rb
+        if spec.satisfies('platform=darwin'):
+            configure_args.append('--program-prefix=g')
+
         return configure_args
diff --git a/var/spack/repos/builtin/packages/libtool/package.py b/var/spack/repos/builtin/packages/libtool/package.py
index 9e9005ccc5..b5d5c9b2b1 100644
--- a/var/spack/repos/builtin/packages/libtool/package.py
+++ b/var/spack/repos/builtin/packages/libtool/package.py
@@ -50,20 +50,19 @@ def setup_dependent_package(self, module, dependent_spec):
         # the tools it provides to the dependent module. Some build
         # systems differentiate between BSD libtool (e.g., Darwin) and
         # GNU libtool, so also add 'glibtool' and 'glibtoolize' to the
-        # list of executables.
+        # list of executables. See Homebrew:
+        # https://github.com/Homebrew/homebrew-core/blob/master/Formula/libtool.rb
         executables = ['libtoolize', 'libtool', 'glibtoolize', 'glibtool']
         for name in executables:
             setattr(module, name, self._make_executable(name))
 
-    @run_after('install')
-    def post_install(self):
+    @when('platform=darwin')
+    def configure_args(self):
         # Some platforms name GNU libtool and GNU libtoolize
         # 'glibtool' and 'glibtoolize', respectively, to differentiate
         # them from BSD libtool and BSD libtoolize. On these BSD
         # platforms, build systems sometimes expect to use the assumed
         # GNU commands glibtool and glibtoolize instead of the BSD
         # variant; this happens frequently, for instance, on Darwin
-        symlink(join_path(self.prefix.bin, 'libtoolize'),
-                join_path(self.prefix.bin, 'glibtoolize'))
-        symlink(join_path(self.prefix.bin, 'libtoolize'),
-                join_path(self.prefix.bin, 'glibtoolize'))
+        args = ['--program-prefix=g']
+        return args
-- 
GitLab