Skip to content

Commit fdf98e9

Browse files
committed
Changes allow compiling nmatrix on modern g++ versions.
source: SciRuby#632
1 parent beb266e commit fdf98e9

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/nmatrix/mkmf.rb

+18-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,18 @@ def create_conf_h(file) #:nodoc:
2727
end
2828
end
2929

30+
31+
# It checks if the GNU g++ binary with C++0x/C++11 support is available.
32+
# It first checks the major version of g++ and returns true if it is greater than 4. # If the major version is less than 0, it returns false. Otherwise, it checks for specific versions starting from 4.9 down to 4.3.
3033
def find_newer_gplusplus #:nodoc:
3134
print "checking for apparent GNU g++ binary with C++0x/C++11 support... "
35+
major_version = gplusplus_version.split(".").first.to_i
36+
37+
# modern GCC has that
38+
return true if major_version > 4
39+
return false if major_version < 4
40+
41+
# legacy approach, check version 4:
3242
[9,8,7,6,5,4,3].each do |minor|
3343
ver = "4.#{minor}"
3444
gpp = "g++-#{ver}"
@@ -41,6 +51,10 @@ def find_newer_gplusplus #:nodoc:
4151
false
4252
end
4353

54+
# It extracts the major, minor, and patch versions of g++
55+
# by parsing the output of g++ --version command.
56+
# It raises an exception if any of the versions are nil.
57+
# Finally, it returns the version string in the format “major.minor.patch”.
4458
def gplusplus_version
4559
cxxvar = proc { |n| `#{CONFIG['CXX']} -E -dM - <#{File::NULL} | grep #{n}`.chomp.split(' ')[2] }
4660
major = cxxvar.call('__GNUC__')
@@ -49,7 +63,9 @@ def gplusplus_version
4963

5064
raise("unable to determine g++ version (match to get version was nil)") if major.nil? || minor.nil? || patch.nil?
5165

52-
"#{major}.#{minor}.#{patch}"
66+
ver = "#{major}.#{minor}.#{patch}"
67+
puts "g++ version discovered: " + ver
68+
ver
5369
end
5470

5571

@@ -96,5 +112,5 @@ def gplusplus_version
96112
CONFIG['warnflags'].gsub!('-Wdeclaration-after-statement', '')
97113
CONFIG['warnflags'].gsub!('-Wimplicit-function-declaration', '')
98114
end
99-
115+
100116
have_func("rb_array_const_ptr", "ruby.h")

0 commit comments

Comments
 (0)