From 275d22db9ea3f2a260864793009edc8ddfacb1e3 Mon Sep 17 00:00:00 2001 From: Charlie Sharpsteen Date: Wed, 7 Mar 2012 18:38:04 -0800 Subject: [PATCH] ENV.rb: Set GCC-style CPU flags for GFortran GFortran chokes when it is passed CPU flags specific to Clang. This change ensures the environment variables `FCFLAGS` and `FFLAGS` contain the same CPU flags that would be set for the GCC compiler. Fixes Homebrew/homebrew#10424. Fixes Homebrew/homebrew#10744. Closes Homebrew/homebrew#10774. Signed-off-by: Charlie Sharpsteen --- Library/Homebrew/extend/ENV.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Library/Homebrew/extend/ENV.rb b/Library/Homebrew/extend/ENV.rb index c67c93800b..4db3cd5041 100644 --- a/Library/Homebrew/extend/ENV.rb +++ b/Library/Homebrew/extend/ENV.rb @@ -176,8 +176,14 @@ module HomebrewEnvExtension self['F77'] = self['FC'] unless self['F77'] if ARGV.include? '--default-fortran-flags' - self['FCFLAGS'] = self['CFLAGS'] unless self['FCFLAGS'] - self['FFLAGS'] = self['CFLAGS'] unless self['FFLAGS'] + flags_to_set = [] + flags_to_set << 'FCFLAGS' unless self['FCFLAGS'] + flags_to_set << 'FFLAGS' unless self['FFLAGS'] + + flags_to_set.each {|key| self[key] = cflags} + + # Ensure we use architecture optimizations for GCC 4.2.x + set_cpu_flags flags_to_set, 'core2 -msse4', :penryn => 'core2 -msse4.1', :core2 => 'core2', :core => 'prescott', :bottle => 'generic' elsif not self['FCFLAGS'] or self['FFLAGS'] opoo <<-EOS.undent No Fortran optimization information was provided. You may want to consider @@ -197,8 +203,9 @@ module HomebrewEnvExtension self['FC'] = `/usr/bin/which gfortran`.chomp self['F77'] = self['FC'] - self['FCFLAGS'] = self['CFLAGS'] - self['FFLAGS'] = self['CFLAGS'] + fc_flag_vars.each {|key| self[key] = cflags} + # Ensure we use architecture optimizations for GCC 4.2.x + set_cpu_flags fc_flag_vars, 'core2 -msse4', :penryn => 'core2 -msse4.1', :core2 => 'core2', :core => 'prescott', :bottle => 'generic' else onoe <<-EOS @@ -278,6 +285,9 @@ Please take one of the following actions: def cc_flag_vars %w{CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS} end + def fc_flag_vars + %w{FCFLAGS FFLAGS} + end def m64 append_to_cflags '-m64'