2020-10-10 14:16:11 +02:00
|
|
|
# typed: true
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-09-28 14:01:09 -07:00
|
|
|
module Homebrew
|
|
|
|
module Install
|
2022-08-25 16:33:14 -07:00
|
|
|
# This is a list of known paths to the host dynamic linker on Linux if
|
|
|
|
# the host glibc is new enough. The symlink_ld_so method will fail if
|
|
|
|
# the host linker cannot be found in this list.
|
|
|
|
DYNAMIC_LINKERS = %w[
|
|
|
|
/lib64/ld-linux-x86-64.so.2
|
|
|
|
/lib64/ld64.so.2
|
|
|
|
/lib/ld-linux.so.3
|
|
|
|
/lib/ld-linux.so.2
|
|
|
|
/lib/ld-linux-aarch64.so.1
|
|
|
|
/lib/ld-linux-armhf.so.3
|
|
|
|
/system/bin/linker64
|
|
|
|
/system/bin/linker
|
2018-09-28 14:01:09 -07:00
|
|
|
].freeze
|
2020-08-17 18:39:55 +02:00
|
|
|
private_constant :DYNAMIC_LINKERS
|
|
|
|
|
2022-08-25 16:33:14 -07:00
|
|
|
# We link GCC runtime libraries that are not specificaly used for Fortran,
|
|
|
|
# which are linked by the GCC formula. We only use the versioned shared libraries
|
|
|
|
# as the other shared and static libraries are only used at build time where
|
|
|
|
# GCC can find its own libraries.
|
|
|
|
GCC_RUNTIME_LIBS = %w[
|
|
|
|
libatomic.so.1
|
|
|
|
libgcc_s.so.1
|
|
|
|
libgomp.so.1
|
|
|
|
libstdc++.so.6
|
|
|
|
].freeze
|
|
|
|
private_constant :GCC_RUNTIME_LIBS
|
|
|
|
|
2023-04-17 10:37:59 -07:00
|
|
|
def self.perform_preinstall_checks(all_fatal: false, cc: nil)
|
2020-08-17 18:39:55 +02:00
|
|
|
generic_perform_preinstall_checks(all_fatal: all_fatal, cc: cc)
|
|
|
|
symlink_ld_so
|
2022-09-15 14:13:09 +01:00
|
|
|
setup_preferred_gcc_libs
|
2020-08-17 18:39:55 +02:00
|
|
|
end
|
2018-09-28 14:01:09 -07:00
|
|
|
|
2023-04-17 10:37:59 -07:00
|
|
|
def self.global_post_install
|
2022-09-09 20:55:59 +01:00
|
|
|
generic_global_post_install
|
|
|
|
symlink_ld_so
|
2022-09-15 14:13:09 +01:00
|
|
|
setup_preferred_gcc_libs
|
2022-09-09 20:55:59 +01:00
|
|
|
end
|
|
|
|
|
2023-04-17 10:37:59 -07:00
|
|
|
def self.check_cpu
|
2020-06-23 14:11:05 +01:00
|
|
|
return if Hardware::CPU.intel? && Hardware::CPU.is_64_bit?
|
|
|
|
return if Hardware::CPU.arm?
|
2020-04-30 16:50:13 +10:00
|
|
|
|
|
|
|
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
|
2020-08-17 18:39:55 +02:00
|
|
|
private_class_method :check_cpu
|
2020-04-30 16:50:13 +10:00
|
|
|
|
2023-04-17 10:37:59 -07:00
|
|
|
def self.symlink_ld_so
|
2018-09-28 14:01:09 -07:00
|
|
|
brew_ld_so = HOMEBREW_PREFIX/"lib/ld.so"
|
|
|
|
|
2022-09-19 03:34:55 +01:00
|
|
|
ld_so = HOMEBREW_PREFIX/"opt/glibc/bin/ld.so"
|
2018-09-28 14:01:09 -07:00
|
|
|
unless ld_so.readable?
|
|
|
|
ld_so = DYNAMIC_LINKERS.find { |s| File.executable? s }
|
2022-09-19 03:34:05 +01:00
|
|
|
if ld_so.blank?
|
|
|
|
raise "Unable to locate the system's dynamic linker" unless brew_ld_so.readable?
|
|
|
|
|
|
|
|
return
|
|
|
|
end
|
2018-09-28 14:01:09 -07:00
|
|
|
end
|
|
|
|
|
2022-09-19 03:34:05 +01:00
|
|
|
return if brew_ld_so.readable? && (brew_ld_so.readlink == ld_so)
|
|
|
|
|
2018-09-28 14:01:09 -07:00
|
|
|
FileUtils.mkdir_p HOMEBREW_PREFIX/"lib"
|
|
|
|
FileUtils.ln_sf ld_so, brew_ld_so
|
|
|
|
end
|
2020-08-17 18:39:55 +02:00
|
|
|
private_class_method :symlink_ld_so
|
2022-08-25 16:33:14 -07:00
|
|
|
|
2023-04-17 10:37:59 -07:00
|
|
|
def self.setup_preferred_gcc_libs
|
2022-09-18 00:58:47 +01:00
|
|
|
gcc_opt_prefix = HOMEBREW_PREFIX/"opt/#{OS::LINUX_PREFERRED_GCC_RUNTIME_FORMULA}"
|
2022-09-19 03:34:55 +01:00
|
|
|
glibc_installed = (HOMEBREW_PREFIX/"opt/glibc/bin/ld.so").readable?
|
2022-09-15 14:13:09 +01:00
|
|
|
|
|
|
|
return unless gcc_opt_prefix.readable?
|
|
|
|
|
|
|
|
if glibc_installed
|
|
|
|
ld_so_conf_d = HOMEBREW_PREFIX/"etc/ld.so.conf.d"
|
|
|
|
unless ld_so_conf_d.exist?
|
|
|
|
ld_so_conf_d.mkpath
|
|
|
|
FileUtils.chmod "go-w", ld_so_conf_d
|
|
|
|
end
|
|
|
|
|
|
|
|
# Add gcc to ld search paths
|
|
|
|
ld_gcc_conf = ld_so_conf_d/"50-homebrew-preferred-gcc.conf"
|
2022-09-22 16:39:31 +08:00
|
|
|
ld_gcc_conf_content = <<~EOS
|
|
|
|
# This file is generated by Homebrew. Do not modify.
|
|
|
|
#{gcc_opt_prefix}/lib/gcc/current
|
|
|
|
EOS
|
|
|
|
|
|
|
|
if !ld_gcc_conf.exist? || (ld_gcc_conf.read != ld_gcc_conf_content)
|
|
|
|
ld_gcc_conf.atomic_write ld_gcc_conf_content
|
2022-09-15 14:13:09 +01:00
|
|
|
FileUtils.chmod "u=rw,go-wx", ld_gcc_conf
|
|
|
|
|
|
|
|
FileUtils.rm_f HOMEBREW_PREFIX/"etc/ld.so.cache"
|
|
|
|
system HOMEBREW_PREFIX/"opt/glibc/sbin/ldconfig"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
odie "#{HOMEBREW_PREFIX}/lib does not exist!" unless (HOMEBREW_PREFIX/"lib").readable?
|
|
|
|
end
|
2022-08-25 16:33:14 -07:00
|
|
|
|
|
|
|
GCC_RUNTIME_LIBS.each do |library|
|
|
|
|
gcc_library_symlink = HOMEBREW_PREFIX/"lib/#{library}"
|
|
|
|
|
2022-09-15 14:13:09 +01:00
|
|
|
if glibc_installed
|
|
|
|
# Remove legacy symlinks
|
|
|
|
FileUtils.rm gcc_library_symlink if gcc_library_symlink.symlink?
|
|
|
|
else
|
2022-09-22 16:39:31 +08:00
|
|
|
gcc_library = gcc_opt_prefix/"lib/gcc/current/#{library}"
|
2022-09-15 14:13:09 +01:00
|
|
|
# Skip if the link target doesn't exist.
|
|
|
|
next unless gcc_library.readable?
|
2022-08-25 16:33:14 -07:00
|
|
|
|
2022-09-15 14:13:09 +01:00
|
|
|
# Also skip if the symlink already exists.
|
|
|
|
next if gcc_library_symlink.readable? && (gcc_library_symlink.readlink == gcc_library)
|
2022-08-25 16:33:14 -07:00
|
|
|
|
2022-09-15 14:13:09 +01:00
|
|
|
FileUtils.ln_sf gcc_library, gcc_library_symlink
|
|
|
|
end
|
2022-08-25 16:33:14 -07:00
|
|
|
end
|
|
|
|
end
|
2022-09-15 14:13:09 +01:00
|
|
|
private_class_method :setup_preferred_gcc_libs
|
2018-09-28 14:01:09 -07:00
|
|
|
end
|
|
|
|
end
|