diff --git a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb index 29ff410094..125ee9244b 100644 --- a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb @@ -46,8 +46,8 @@ module Superenv def homebrew_extra_isystem_paths paths = [] - # Add paths for GCC headers when building against glibc@2.13 because we have to use -nostdinc. - if deps.any? { |d| d.name == "glibc@2.13" } + # Add paths for GCC headers when building against versioned glibc because we have to use -nostdinc. + if deps.any? { |d| d.name.match?(/^glibc@.+$/) } gcc_include_dir = Utils.safe_popen_read(cc, "--print-file-name=include").chomp gcc_include_fixed_dir = Utils.safe_popen_read(cc, "--print-file-name=include-fixed").chomp paths << gcc_include_dir << gcc_include_fixed_dir diff --git a/Library/Homebrew/shims/super/cc b/Library/Homebrew/shims/super/cc index 038eb59e0d..16d12d3fb0 100755 --- a/Library/Homebrew/shims/super/cc +++ b/Library/Homebrew/shims/super/cc @@ -326,8 +326,8 @@ class Cmd def cppflags args = [] args += path_flags("-isystem", isystem_paths) + path_flags("-I", include_paths) - # Add -nostdinc when building against glibc@2.13 to avoid mixing system and brewed glibc headers. - args << "-nostdinc" if @deps.include?("glibc@2.13") + # Add -nostdinc when building against versioned glibc to avoid mixing system and brewed glibc headers. + args << "-nostdinc" if @deps.any? { |dep| dep.match?(/^glibc@.+$/) } # Ideally this would be -ffile-prefix-map, but that requires a minimum of GCC 8, LLVM Clang 10 or Apple Clang 12 # and detecting the version dynamically based on what `HOMEBREW_CC` may have been rewritten to point to is awkward args << "-fdebug-prefix-map=#{formula_buildpath}=." if formula_buildpath && !debug_symbols? @@ -353,19 +353,20 @@ class Cmd end def ldflags_linux(args) + versioned_glibc_dep = @deps.find { |dep| dep.match?(/^glibc@.+$/) } unless mode == :ld wl = "-Wl," - if @deps.include?("glibc@2.13") - args << "-B#{@opt}/glibc@2.13/lib" + if versioned_glibc_dep + args << "-B#{@opt}/#{versioned_glibc_dep}/lib" else args << "-B#{@opt}/glibc/lib" end end args += rpath_flags("#{wl}-rpath=", rpath_paths) args += ["#{wl}--dynamic-linker=#{dynamic_linker_path}"] if dynamic_linker_path - # Use -rpath-link to make sure linker uses glibc@2.13 rather than the system glibc for indirect + # Use -rpath-link to make sure linker uses versioned glibc rather than the system glibc for indirect # dependencies because -L will only handle direct dependencies. - args << "#{wl}-rpath-link=#{@opt}/glibc@2.13/lib" if @deps.include?("glibc@2.13") + args << "#{wl}-rpath-link=#{@opt}/#{versioned_glibc_dep}/lib" if versioned_glibc_dep args end