Merge pull request #7465 from runlevel5/ppc64le-arch-detect

Add OpenPOWER platform detection
This commit is contained in:
Mike McQuaid 2020-04-30 15:50:36 +01:00 committed by GitHub
commit 1fc8b8ff5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 30 deletions

View File

@ -3,17 +3,12 @@
module Hardware module Hardware
class CPU class CPU
class << self 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 def optimization_flags
OPTIMIZATION_FLAGS_LINUX @optimization_flags ||= begin
flags = generic_optimization_flags.dup
flags[:native] = arch_flag(Homebrew::EnvConfig.arch)
flags
end
end end
def cpuinfo def cpuinfo

View File

@ -14,6 +14,19 @@ module Homebrew
"/system/bin/linker", "/system/bin/linker",
].freeze ].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 def symlink_ld_so
brew_ld_so = HOMEBREW_PREFIX/"lib/ld.so" brew_ld_so = HOMEBREW_PREFIX/"lib/ld.so"
return if brew_ld_so.readable? return if brew_ld_so.readable?

View File

@ -7,28 +7,29 @@ module Hardware
INTEL_32BIT_ARCHS = [:i386].freeze INTEL_32BIT_ARCHS = [:i386].freeze
INTEL_64BIT_ARCHS = [:x86_64].freeze INTEL_64BIT_ARCHS = [:x86_64].freeze
PPC_32BIT_ARCHS = [:ppc, :ppc32, :ppc7400, :ppc7450, :ppc970].freeze PPC_32BIT_ARCHS = [:ppc, :ppc32, :ppc7400, :ppc7450, :ppc970].freeze
PPC_64BIT_ARCHS = [:ppc64].freeze PPC_64BIT_ARCHS = [:ppc64, :ppc64le, :ppc970].freeze
class << self 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 def optimization_flags
OPTIMIZATION_FLAGS @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 end
alias generic_optimization_flags optimization_flags
def arch_32_bit def arch_32_bit
if arm? if arm?
:arm :arm
elsif intel? elsif intel?
:i386 :i386
elsif ppc? elsif ppc32?
:ppc32 :ppc32
else else
:dunno :dunno
@ -40,7 +41,9 @@ module Hardware
:arm64 :arm64
elsif intel? elsif intel?
:x86_64 :x86_64
elsif ppc? elsif ppc64le?
:ppc64le
elsif ppc64?
:ppc64 :ppc64
else else
:dunno :dunno
@ -66,7 +69,7 @@ module Hardware
case RUBY_PLATFORM case RUBY_PLATFORM
when /x86_64/, /i\d86/ then :intel when /x86_64/, /i\d86/ then :intel
when /arm/, /aarch64/ then :arm when /arm/, /aarch64/ then :arm
when /ppc\d+/ then :ppc when /ppc|powerpc/ then :ppc
else :dunno else :dunno
end end
end end
@ -85,7 +88,7 @@ module Hardware
def bits def bits
@bits ||= case RUBY_PLATFORM @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 when /i\d86/, /ppc/, /arm/ then 32
end end
end end
@ -110,10 +113,30 @@ module Hardware
type == :ppc type == :ppc
end 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? def arm?
type == :arm type == :arm
end end
def little_endian?
!big_endian?
end
def big_endian?
[1].pack("I") == [1].pack("N")
end
def features def features
[] []
end end
@ -121,6 +144,12 @@ module Hardware
def feature?(name) def feature?(name)
features.include?(name) features.include?(name)
end end
def arch_flag(arch)
return "-mcpu=#{arch}" if ppc?
"-march=#{arch}"
end
end end
end end

View File

@ -10,14 +10,16 @@ module Homebrew
module_function module_function
def check_cpu def check_cpu
case Hardware::CPU.type return if Hardware::CPU.intel? && Hardware::CPU.is_64_bit?
when :ppc
abort <<~EOS message = "Sorry, Homebrew does not support your computer's CPU architecture!"
Sorry, Homebrew does not support your computer's CPU architecture. if Hardware::CPU.ppc?
For PPC support, see: message += <<~EOS
For PowerPC Mac (PPC32/PPC64BE) support, see:
#{Formatter.url("https://github.com/mistydemeo/tigerbrew")} #{Formatter.url("https://github.com/mistydemeo/tigerbrew")}
EOS EOS
end end
abort message
end end
def attempt_directory_creation def attempt_directory_creation