Skip to content
Browse files

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 #10424.
  • Loading branch information...
1 parent 75d33c7 commit a782e953917689c88032e3a4b4855712aaa5b9c1 @Sharpie committed Mar 7, 2012
Showing with 14 additions and 4 deletions.
  1. +14 −4 Library/Homebrew/extend/ENV.rb
View
18 Library/Homebrew/extend/ENV.rb
@@ -176,8 +176,14 @@ def fortran
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 @@ def fortran
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 @@ def ldflags; self['LDFLAGS']; end
def cc_flag_vars
%w{CFLAGS CXXFLAGS OBJCFLAGS OBJCXXFLAGS}
end
+ def fc_flag_vars
+ %w{FCFLAGS FFLAGS}
+ end
def m64
append_to_cflags '-m64'

0 comments on commit a782e95

Please sign in to comment.
Something went wrong with that request. Please try again.