From e0d24922474f2a10b82b8dede1b54552ed72ebed Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Wed, 20 Nov 2013 12:54:34 -0600 Subject: [PATCH] Move optimization flag selection out of cc wrapper The mapping of architectures to optimization flags is now retrieved from Hardware::CPU and the selected flags are passed as an environmen variable, rather than duplicated in the cc wrapper and re-calculated on every invocation of the compiler. Closes Homebrew/homebrew#24540. --- Library/ENV/4.3/cc | 17 +----------- Library/Homebrew/extend/ENV/std.rb | 2 +- Library/Homebrew/extend/ENV/super.rb | 41 +++++++--------------------- 3 files changed, 12 insertions(+), 48 deletions(-) diff --git a/Library/ENV/4.3/cc b/Library/ENV/4.3/cc index 3839418078..92b09a48c6 100755 --- a/Library/ENV/4.3/cc +++ b/Library/ENV/4.3/cc @@ -184,22 +184,7 @@ class Cmd def optflags args = [] args << "-#{ENV['HOMEBREW_OPTIMIZATION_LEVEL']}" - - # When bottling use the oldest supported CPU type. - if cccfg? 'bc' - # Custom bottle specified during the build - args << ENV['HOMEBREW_ARCHFLAGS'] - elsif cccfg? 'bi6' - args << '-march=core2' - elsif cccfg? 'bi' - args << '-march=prescott' - elsif cccfg? 'bpA' - args << '-mcpu=7400' - elsif cccfg? 'bp' - args << '-mcpu=750' - else - args << '-march=native' if tool =~ /clang/ - end + args.concat ENV['HOMEBREW_OPTFLAGS'].split(' ') if ENV['HOMEBREW_OPTFLAGS'] args end def archflags diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index 633ad90102..1002749d23 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -343,7 +343,7 @@ module Stdenv if ARGV.build_bottle? arch = ARGV.bottle_arch || Hardware.oldest_cpu - append flags, Hardware::CPU.optimization_flags[arch] + append flags, Hardware::CPU.optimization_flags.fetch(arch) else # Don't set -msse3 and older flags because -march does that for us append flags, map.fetch(Hardware::CPU.family, default) diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index 080745e988..9df429f32f 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -76,30 +76,19 @@ module Superenv self['HOMEBREW_SDKROOT'] = "#{MacOS.sdk_path}" if MacOS::Xcode.without_clt? self['HOMEBREW_DEVELOPER_DIR'] = determine_developer_dir # used by our xcrun shim self['HOMEBREW_VERBOSE'] = "1" if ARGV.verbose? + self['HOMEBREW_OPTFLAGS'] = determine_optflags self['CMAKE_PREFIX_PATH'] = determine_cmake_prefix_path self['CMAKE_FRAMEWORK_PATH'] = determine_cmake_frameworks_path self['CMAKE_INCLUDE_PATH'] = determine_cmake_include_path self['CMAKE_LIBRARY_PATH'] = determine_cmake_library_path self['ACLOCAL_PATH'] = determine_aclocal_path - # For custom bottles, need to specify the arch in the environment - # so that the compiler shims have access - if (arch = ARGV.bottle_arch) - self['HOMEBREW_ARCHFLAGS'] = Hardware::CPU.optimization_flags[arch] - end - # The HOMEBREW_CCCFG ENV variable is used by the ENV/cc tool to control # compiler flag stripping. It consists of a string of characters which act # as flags. Some of these flags are mutually exclusive. # # u - A universal build was requested # 3 - A 32-bit build was requested - # b - Installing from a bottle - # c - Installing from a bottle with a custom architecture - # i - Installing from a bottle on Intel - # 6 - Installing from a bottle on 64-bit Intel - # p - Installing from a bottle on PPC - # A - Installing from a bottle on PPC with Altivec # O - Enables argument refurbishing. Only active under the # make/bsdmake wrappers currently. # x - Enable C++11 mode. @@ -214,27 +203,17 @@ module Superenv end end + def determine_optflags + if ARGV.build_bottle? + arch = ARGV.bottle_arch || Hardware.oldest_cpu + Hardware::CPU.optimization_flags.fetch(arch) + elsif compiler == :clang + "-march=native" + end + end + def determine_cccfg s = "" - if ARGV.build_bottle? - s << if ARGV.bottle_arch - 'bc' - elsif Hardware::CPU.type == :intel - if Hardware::CPU.is_64_bit? - 'bi6' - else - 'bi' - end - elsif Hardware::CPU.type == :ppc - if Hardware::CPU.altivec? - 'bpA' - else - 'bp' - end - else - 'b' - end - end # Fix issue with sed barfing on unicode characters on Mountain Lion s << 's' if MacOS.version >= :mountain_lion # Fix issue with >= 10.8 apr-1-config having broken paths