Module: Stdenv

Includes:
SharedEnvExtension
Defined in:
brew/Library/Homebrew/extend/ENV/std.rb,
brew/Library/Homebrew/extend/os/mac/extend/ENV/std.rb,
brew/Library/Homebrew/extend/os/linux/extend/ENV/std.rb

Overview

typed: false frozen_string_literal: true

Instance Method Summary collapse

Methods included from SharedEnvExtension

#append, #append_path, #append_to_cccfg, #append_to_cflags, #cc, #cflags, #compiler, #cppflags, #cxx, #cxxflags, #fc, #fcflags, #fflags, #fortran, #ldflags, #ncurses_define, #no_weak_imports_support?, #permit_arch_flags, #permit_weak_imports, #prepend, #prepend_create_path, #prepend_path, #remove, #remove_cc_etc, #remove_from_cflags

Instance Method Details

#clangObject



113
114
115
116
117
118
119
120
121
122
# File 'brew/Library/Homebrew/extend/ENV/std.rb', line 113

def clang
  super()
  replace_in_cflags(/-Xarch_#{Hardware::CPU.arch_32_bit} (-march=\S*)/, '\1')
  map = Hardware::CPU.optimization_flags.dup
  if DevelopmentTools.clang_build_version < 700
    # Clang mistakenly enables AES-NI on plain Nehalem
    map[:nehalem] = "-march=nehalem -Xclang -target-feature -Xclang -aes"
  end
  set_cpu_cflags(map)
end

#cxx11Object



147
148
149
150
# File 'brew/Library/Homebrew/extend/ENV/std.rb', line 147

def cxx11
  append "CXX", "-std=c++11"
  libcxx
end

#define_cflags(val) ⇒ Object

Convenience method to set all C compiler flags in one shot.



168
169
170
# File 'brew/Library/Homebrew/extend/ENV/std.rb', line 168

def define_cflags(val)
  CC_FLAG_VARS.each { |key| self[key] = val }
end

#deparallelizeObject

Removes the MAKEFLAGS environment variable, causing make to use a single job. This is useful for makefiles with race conditions. When passed a block, MAKEFLAGS is removed only for the duration of the block and is restored after its completion.



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'brew/Library/Homebrew/extend/ENV/std.rb', line 73

def deparallelize
  old = self["MAKEFLAGS"]
  remove "MAKEFLAGS", /-j\d+/
  if block_given?
    begin
      yield
    ensure
      self["MAKEFLAGS"] = old
    end
  end

  old
end

#determine_pkg_config_libdirObject



61
62
63
64
65
66
67
68
# File 'brew/Library/Homebrew/extend/ENV/std.rb', line 61

def determine_pkg_config_libdir
  PATH.new(
    HOMEBREW_PREFIX/"lib/pkgconfig",
    HOMEBREW_PREFIX/"share/pkgconfig",
    homebrew_extra_pkg_config_paths,
    "/usr/lib/pkgconfig",
  ).existing
end

#homebrew_extra_pkg_config_pathsObject



57
58
59
# File 'brew/Library/Homebrew/extend/ENV/std.rb', line 57

def homebrew_extra_pkg_config_paths
  []
end

#libcxxObject



152
153
154
# File 'brew/Library/Homebrew/extend/ENV/std.rb', line 152

def libcxx
  append "CXX", "-stdlib=libc++" if compiler == :clang
end

#libstdcxxObject



156
157
158
# File 'brew/Library/Homebrew/extend/ENV/std.rb', line 156

def libstdcxx
  append "CXX", "-stdlib=libstdc++" if compiler == :clang
end

#libxml2Object

Some configure scripts won’t find libxml2 without help This is a no-op with macOS SDK 10.15.4 and later



106
107
108
109
110
111
112
113
114
# File 'brew/Library/Homebrew/extend/os/mac/extend/ENV/std.rb', line 106

def libxml2
  sdk = self["SDKROOT"] || MacOS.sdk_path_if_needed
  if !sdk
    append "CPPFLAGS", "-I/usr/include/libxml2"
  elsif !Pathname("#{sdk}/usr/include/libxml").directory?
    # Use the includes form the sdk
    append "CPPFLAGS", "-I#{sdk}/usr/include/libxml2"
  end
end

#m32Object



129
130
131
132
# File 'brew/Library/Homebrew/extend/ENV/std.rb', line 129

def m32
  append_to_cflags "-m32"
  append "LDFLAGS", "-arch #{Hardware::CPU.arch_32_bit}"
end

#m64Object



124
125
126
127
# File 'brew/Library/Homebrew/extend/ENV/std.rb', line 124

def m64
  append_to_cflags "-m64"
  append "LDFLAGS", "-arch #{Hardware::CPU.arch_64_bit}"
end

#macosxsdk(version = nil, formula: nil) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'brew/Library/Homebrew/extend/os/mac/extend/ENV/std.rb', line 76

def macosxsdk(version = nil, formula: nil)
  # Sets all needed lib and include dirs to CFLAGS, CPPFLAGS, LDFLAGS.
  remove_macosxsdk
  min_version = version || MacOS.version
  append_to_cflags("-mmacosx-version-min=#{min_version}")
  self["CPATH"] = "#{HOMEBREW_PREFIX}/include"
  prepend "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib"

  sdk = formula ? MacOS.sdk_for_formula(formula, version) : MacOS.sdk(version)
  return if !MacOS.sdk_root_needed? && sdk&.source != :xcode

  Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks)
  sdk = sdk.path

  # Extra setup to support Xcode 4.3+ without CLT.
  self["SDKROOT"] = sdk
  # Tell clang/gcc where system include's are:
  append_path "CPATH", "#{sdk}/usr/include"
  # The -isysroot is needed, too, because of the Frameworks
  append_to_cflags "-isysroot#{sdk}"
  append "CPPFLAGS", "-isysroot#{sdk}"
  # And the linker needs to find sdk/usr/lib
  append "LDFLAGS", "-isysroot#{sdk}"
  # Needed to build cmake itself and perhaps some cmake projects:
  append_path "CMAKE_PREFIX_PATH", "#{sdk}/usr"
  append_path "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks"
end

#make_jobsObject



193
194
195
# File 'brew/Library/Homebrew/extend/ENV/std.rb', line 193

def make_jobs
  Homebrew::EnvConfig.make_jobs.to_i
end

#no_weak_importsObject



116
117
118
# File 'brew/Library/Homebrew/extend/os/mac/extend/ENV/std.rb', line 116

def no_weak_imports
  append "LDFLAGS", "-Wl,-no_weak_imports" if no_weak_imports_support?
end

#remove_macosxsdk(version = nil) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'brew/Library/Homebrew/extend/os/mac/extend/ENV/std.rb', line 53

def remove_macosxsdk(version = nil)
  # Clear all lib and include dirs from CFLAGS, CPPFLAGS, LDFLAGS that were
  # previously added by macosxsdk
  remove_from_cflags(/ ?-mmacosx-version-min=\d+\.\d+/)
  delete("CPATH")
  remove "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib"

  sdk = self["SDKROOT"] || MacOS.sdk_path_if_needed(version)
  return unless sdk

  delete("SDKROOT")
  remove_from_cflags "-isysroot#{sdk}"
  remove "CPPFLAGS", "-isysroot#{sdk}"
  remove "LDFLAGS", "-isysroot#{sdk}"
  if HOMEBREW_PREFIX.to_s == "/usr/local"
    delete("CMAKE_PREFIX_PATH")
  else
    # It was set in setup_build_environment, so we have to restore it here.
    self["CMAKE_PREFIX_PATH"] = HOMEBREW_PREFIX.to_s
  end
  remove "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks"
end

#universal_binaryObject



134
135
136
137
138
139
140
141
142
143
144
145
# File 'brew/Library/Homebrew/extend/ENV/std.rb', line 134

def universal_binary
  check_for_compiler_universal_support

  append_to_cflags Hardware::CPU.universal_archs.as_arch_flags
  append "LDFLAGS", Hardware::CPU.universal_archs.as_arch_flags

  return if compiler_any_clang?
  return unless Hardware.is_32_bit?

  # Can't mix "-march" for a 32-bit CPU with "-arch x86_64"
  replace_in_cflags(/-march=\S*/, "-Xarch_#{Hardware::CPU.arch_32_bit} \\0")
end

#x11Object



186
# File 'brew/Library/Homebrew/extend/ENV/std.rb', line 186

def x11; end