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.
This commit is contained in:
Jack Nagel 2013-11-20 12:54:34 -06:00
parent 78f9b23218
commit e0d2492247
3 changed files with 12 additions and 48 deletions

View File

@ -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

View File

@ -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)

View File

@ -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