aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/extend/os/linux
diff options
context:
space:
mode:
authorMike McQuaid2016-04-25 18:00:01 +0100
committerMike McQuaid2016-05-08 16:51:22 +0100
commit8d995e961f549e555f405d2567235dab53f6baad (patch)
tree0ea44eeab57c1432de44a167091faa45f59df1eb /Library/Homebrew/extend/os/linux
parent8a582f2bd976ce7044c3b2dc6eef701f94b9ace5 (diff)
downloadbrew-8d995e961f549e555f405d2567235dab53f6baad.tar.bz2
Make hardware code cross-platform.
Diffstat (limited to 'Library/Homebrew/extend/os/linux')
-rw-r--r--Library/Homebrew/extend/os/linux/hardware/cpu.rb67
1 files changed, 67 insertions, 0 deletions
diff --git a/Library/Homebrew/extend/os/linux/hardware/cpu.rb b/Library/Homebrew/extend/os/linux/hardware/cpu.rb
new file mode 100644
index 000000000..ef25aabfc
--- /dev/null
+++ b/Library/Homebrew/extend/os/linux/hardware/cpu.rb
@@ -0,0 +1,67 @@
+module Hardware
+ class CPU
+ extend self
+
+ OPTIMIZATION_FLAGS = {
+ :penryn => "-march=core2 -msse4.1",
+ :core2 => "-march=core2",
+ :core => "-march=prescott"
+ }.freeze
+ def optimization_flags
+ OPTIMIZATION_FLAGS
+ end
+
+ # Linux supports x86 only, and universal archs do not apply
+ def arch_32_bit
+ :i386
+ end
+
+ def arch_64_bit
+ :x86_64
+ end
+
+ def universal_archs
+ [].extend ArchitectureListExtension
+ end
+
+ def cpuinfo
+ @cpuinfo ||= File.read("/proc/cpuinfo")
+ end
+
+ def type
+ @type ||= if cpuinfo =~ /Intel|AMD/
+ :intel
+ else
+ :dunno
+ end
+ end
+
+ def family
+ cpuinfo[/^cpu family\s*: ([0-9]+)/, 1].to_i
+ end
+ alias_method :intel_family, :family
+
+ def cores
+ cpuinfo.scan(/^processor/).size
+ end
+
+ def flags
+ @flags ||= cpuinfo[/^flags.*/, 0].split
+ end
+
+ # Compatibility with Mac method, which returns lowercase symbols
+ # instead of strings
+ def features
+ @features ||= flags[1..-1].map(&:intern)
+ end
+
+ %w[aes altivec avx avx2 lm sse3 ssse3 sse4 sse4_2].each do |flag|
+ define_method(flag + "?") { flags.include? flag }
+ end
+ alias_method :is_64_bit?, :lm?
+
+ def bits
+ is_64_bit? ? 64 : 32
+ end
+ end
+end