From 15e5fe43845c3b5619c66269e9c60cd984a75080 Mon Sep 17 00:00:00 2001 From: Xiyue Deng Date: Thu, 24 Oct 2013 00:26:09 -0700 Subject: [PATCH] Clang standard library selection. * Add new ENV function for selecting stdlib for Clang. - The selection is no-op for non-system-clang compilers. - Both superenv and stdenv are handled. * Add new HOMEBREW_CCCFG flag and ccwrapper handling. --- Library/ENV/4.3/cc | 2 ++ Library/Homebrew/extend/ENV/std.rb | 12 ++++++++++++ Library/Homebrew/extend/ENV/super.rb | 13 +++++++++++++ 3 files changed, 27 insertions(+) diff --git a/Library/ENV/4.3/cc b/Library/ENV/4.3/cc index 102f6c64ec..e8e586da4c 100755 --- a/Library/ENV/4.3/cc +++ b/Library/ENV/4.3/cc @@ -161,6 +161,7 @@ class Cmd if mode == :cxx args << '-std=c++11' if cccfg? 'x' args << '-stdlib=libc++' if cccfg? 'g' + args << '-stdlib=libstdc++' if cccfg? 'h' end return args unless cccfg? 'O' @@ -216,6 +217,7 @@ class Cmd when :cxxld args << '-Wl,-headerpad_max_install_names' args << '-stdlib=libc++' if cccfg? 'g' + args << '-stdlib=libstdc++' if cccfg? 'h' end args end diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index 0d5613256f..92bdfd7943 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -333,6 +333,18 @@ module Stdenv end end + def libcxx + if compiler == :clang + append 'CXX', '-stdlib=libc++' + end + end + + def libstdcxx + if compiler == :clang + append 'CXX', '-stdlib=libstdc++' + end + end + def replace_in_cflags before, after CC_FLAG_VARS.each do |key| self[key] = self[key].sub(before, after) if has_key?(key) diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index 2be8a62d47..169a4200c0 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -99,6 +99,7 @@ module Superenv # make/bsdmake wrappers currently. # x - Enable C++11 mode. # g - Enable "-stdlib=libc++" for clang. + # h - Enable "-stdlib=libstdc++" for clang. # # On 10.8 and newer, these flags will also be present: # s - apply fix for sed's Unicode support @@ -123,6 +124,18 @@ module Superenv end end + def libcxx + if self['HOMEBREW_CC'] == 'clang' + append 'HOMEBREW_CCCFG', "g", '' + end + end + + def libstdcxx + if self['HOMEBREW_CC'] == 'clang' + append 'HOMEBREW_CCCFG', "h", '' + end + end + # m32 on superenv does not add any CC flags. It prevents "-m32" from being erased. def m32 append 'HOMEBREW_CCCFG', "3", ''