Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OpenPOWER platform detection #7465

Merged
merged 1 commit into from Apr 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 5 additions & 10 deletions Library/Homebrew/extend/os/linux/hardware/cpu.rb
Expand Up @@ -3,17 +3,12 @@
module Hardware
class CPU
class << self
OPTIMIZATION_FLAGS_LINUX = {
native: "-march=#{Homebrew::EnvConfig.arch}",
nehalem: "-march=nehalem",
core2: "-march=core2",
core: "-march=prescott",
armv6: "-march=armv6",
armv8: "-march=armv8-a",
}.freeze

def optimization_flags
OPTIMIZATION_FLAGS_LINUX
@optimization_flags ||= begin
flags = generic_optimization_flags.dup
flags[:native] = arch_flag(Homebrew::EnvConfig.arch)
flags
end
end

def cpuinfo
Expand Down
13 changes: 13 additions & 0 deletions Library/Homebrew/extend/os/linux/install.rb
Expand Up @@ -14,6 +14,19 @@ module Install
"/system/bin/linker",
].freeze

def check_cpu
return if (Hardware::CPU.intel? && Hardware::CPU.is_64_bit?) || Hardware::CPU.arm?

message = "Sorry, Homebrew does not support your computer's CPU architecture!"
if Hardware::CPU.ppc64le?
message += <<~EOS
For OpenPOWER Linux (PPC64LE) support, see:
#{Formatter.url("https://github.com/homebrew-ppc64le/brew")}
EOS
end
abort message
end

def symlink_ld_so
brew_ld_so = HOMEBREW_PREFIX/"lib/ld.so"
return if brew_ld_so.readable?
Expand Down
61 changes: 45 additions & 16 deletions Library/Homebrew/hardware.rb
Expand Up @@ -7,28 +7,29 @@ class CPU
INTEL_32BIT_ARCHS = [:i386].freeze
INTEL_64BIT_ARCHS = [:x86_64].freeze
PPC_32BIT_ARCHS = [:ppc, :ppc32, :ppc7400, :ppc7450, :ppc970].freeze
PPC_64BIT_ARCHS = [:ppc64].freeze
PPC_64BIT_ARCHS = [:ppc64, :ppc64le, :ppc970].freeze

class << self
OPTIMIZATION_FLAGS = {
native: "-march=native",
nehalem: "-march=nehalem",
core2: "-march=core2",
core: "-march=prescott",
armv6: "-march=armv6",
armv8: "-march=armv8-a",
}.freeze

def optimization_flags
OPTIMIZATION_FLAGS
end
@optimization_flags ||= {
native: arch_flag("native"),
nehalem: "-march=nehalem",
core2: "-march=core2",
core: "-march=prescott",
armv6: "-march=armv6",
armv8: "-march=armv8-a",
ppc64: "-mcpu=powerpc64",
ppc64le: "-mcpu=powerpc64le",
}.freeze
end
runlevel5 marked this conversation as resolved.
Show resolved Hide resolved
alias generic_optimization_flags optimization_flags

def arch_32_bit
if arm?
:arm
elsif intel?
:i386
elsif ppc?
elsif ppc32?
:ppc32
else
:dunno
Expand All @@ -40,7 +41,9 @@ def arch_64_bit
:arm64
elsif intel?
:x86_64
elsif ppc?
elsif ppc64le?
:ppc64le
elsif ppc64?
:ppc64
else
:dunno
Expand All @@ -66,7 +69,7 @@ def type
case RUBY_PLATFORM
when /x86_64/, /i\d86/ then :intel
when /arm/, /aarch64/ then :arm
when /ppc\d+/ then :ppc
when /ppc|powerpc/ then :ppc
else :dunno
end
end
Expand All @@ -85,7 +88,7 @@ def cores

def bits
@bits ||= case RUBY_PLATFORM
when /x86_64/, /ppc64/, /aarch64|arm64/ then 64
when /x86_64/, /ppc64|powerpc64/, /aarch64|arm64/ then 64
when /i\d86/, /ppc/, /arm/ then 32
end
end
Expand All @@ -110,17 +113,43 @@ def ppc?
type == :ppc
end

def ppc32?
ppc? && is_32_bit?
end

def ppc64le?
ppc? && is_64_bit? && little_endian?
end

def ppc64?
ppc? && is_64_bit? && big_endian?
end

def arm?
type == :arm
end

def little_endian?
!big_endian?
end

def big_endian?
[1].pack("I") == [1].pack("N")
end

def features
[]
end

def feature?(name)
features.include?(name)
end

def arch_flag(arch)
return "-mcpu=#{arch}" if ppc?

"-march=#{arch}"
end
end
end

Expand Down
12 changes: 7 additions & 5 deletions Library/Homebrew/install.rb
Expand Up @@ -10,14 +10,16 @@ module Install
module_function

def check_cpu
case Hardware::CPU.type
when :ppc
abort <<~EOS
Sorry, Homebrew does not support your computer's CPU architecture.
For PPC support, see:
return if Hardware::CPU.intel? && Hardware::CPU.is_64_bit?

message = "Sorry, Homebrew does not support your computer's CPU architecture!"
if Hardware::CPU.ppc?
message += <<~EOS
For PowerPC Mac (PPC32/PPC64BE) support, see:
#{Formatter.url("https://github.com/mistydemeo/tigerbrew")}
EOS
end
abort message
end

def attempt_directory_creation
Expand Down