Module: Stdenv Private

Extended by:
T::Sig
Includes:
SharedEnvExtension
Defined in:
extend/os/mac/extend/ENV/std.rb,
extend/os/linux/extend/ENV/std.rb,
extend/ENV/std.rb

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

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

#clangvoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



130
131
132
133
134
135
136
137
138
139
# File 'extend/ENV/std.rb', line 130

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

#cxx11void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



142
143
144
145
# File 'extend/ENV/std.rb', line 142

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

#define_cflags(val) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

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

Parameters:



162
163
164
# File 'extend/ENV/std.rb', line 162

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

#deparallelize(&block) ⇒ T.untyped

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

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.

Parameters:

  • block (T.proc.returns(T.untyped))

Returns:

  • (T.untyped)


87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'extend/ENV/std.rb', line 87

def deparallelize(&block)
  old = self["MAKEFLAGS"]
  remove "MAKEFLAGS", /-j\d+/
  if block
    begin
      yield
    ensure
      self["MAKEFLAGS"] = old
    end
  end

  old
end

#determine_pkg_config_libdirPATH?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



74
75
76
77
78
79
80
81
# File 'extend/ENV/std.rb', line 74

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_pathsArray<Pathname>

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:



69
70
71
# File 'extend/ENV/std.rb', line 69

def homebrew_extra_pkg_config_paths
  ["#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}"]
end

#libcxxvoid

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.



148
149
150
# File 'extend/ENV/std.rb', line 148

def libcxx
  append "CXX", "-stdlib=libc++" 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.



90
91
92
93
94
95
96
97
98
# File 'extend/os/mac/extend/ENV/std.rb', line 90

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

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



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'extend/os/mac/extend/ENV/std.rb', line 56

def macosxsdk(version = nil, formula: nil, testing_formula: false)
  # 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 = if formula
    MacOS.sdk_for_formula(formula, version, check_only_runtime_requirements: testing_formula)
  else
    MacOS.sdk(version)
  end
  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_jobsInteger

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Returns:

  • (Integer)


188
189
190
# File 'extend/ENV/std.rb', line 188

def make_jobs
  Homebrew::EnvConfig.make_jobs.to_i
end

#no_weak_importsObject



100
101
102
# File 'extend/os/mac/extend/ENV/std.rb', line 100

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

#remove_macosxsdk(version = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'extend/os/mac/extend/ENV/std.rb', line 33

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