diff --git a/Library/Homebrew/extend/os/linux/hardware/cpu.rb b/Library/Homebrew/extend/os/linux/hardware/cpu.rb index 99ede69a0b..67dd402a1c 100644 --- a/Library/Homebrew/extend/os/linux/hardware/cpu.rb +++ b/Library/Homebrew/extend/os/linux/hardware/cpu.rb @@ -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 diff --git a/Library/Homebrew/extend/os/linux/install.rb b/Library/Homebrew/extend/os/linux/install.rb index 7efbff87da..694e2a5cc5 100644 --- a/Library/Homebrew/extend/os/linux/install.rb +++ b/Library/Homebrew/extend/os/linux/install.rb @@ -14,6 +14,19 @@ module Homebrew "/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? diff --git a/Library/Homebrew/hardware.rb b/Library/Homebrew/hardware.rb index 9c9c00ce0d..9bee7f7d9c 100644 --- a/Library/Homebrew/hardware.rb +++ b/Library/Homebrew/hardware.rb @@ -7,28 +7,29 @@ module Hardware 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 + @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 + alias generic_optimization_flags optimization_flags def arch_32_bit if arm? :arm elsif intel? :i386 - elsif ppc? + elsif ppc32? :ppc32 else :dunno @@ -40,7 +41,9 @@ module Hardware :arm64 elsif intel? :x86_64 - elsif ppc? + elsif ppc64le? + :ppc64le + elsif ppc64? :ppc64 else :dunno @@ -66,7 +69,7 @@ module Hardware 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 @@ -85,7 +88,7 @@ module Hardware 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 @@ -110,10 +113,30 @@ module Hardware 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 @@ -121,6 +144,12 @@ module Hardware def feature?(name) features.include?(name) end + + def arch_flag(arch) + return "-mcpu=#{arch}" if ppc? + + "-march=#{arch}" + end end end diff --git a/Library/Homebrew/install.rb b/Library/Homebrew/install.rb index 86d63161f3..4a3f031327 100644 --- a/Library/Homebrew/install.rb +++ b/Library/Homebrew/install.rb @@ -10,14 +10,16 @@ module Homebrew 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