Module: OS::Mac::Stdenv Private

Extended by:
T::Helpers
Included in:
Stdenv
Defined in:
extend/os/mac/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

Instance Method Details

#libxml2void

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.

Some configure scripts won't find libxml2 without help. This is a no-op with all supported macOS SDKs.



110
111
112
113
114
115
# File 'extend/os/mac/extend/ENV/std.rb', line 110

def libxml2
  super
  sdk = self["SDKROOT"] || MacOS.sdk_path
  # Use the includes from the sdk
  append "CPPFLAGS", "-I#{sdk}/usr/include/libxml2" unless Pathname("#{sdk}/usr/include/libxml").directory?
end

#macosxsdk(version = nil, formula: nil, testing_formula: false) ⇒ 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.

Parameters:

  • version (MacOSVersion, nil) (defaults to: nil)
  • formula (Formula, nil) (defaults to: nil)
  • testing_formula (Boolean) (defaults to: false)


74
75
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
103
104
105
# File 'extend/os/mac/extend/ENV/std.rb', line 74

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

  Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks)
  raise "No macOS SDK found. Install Xcode or the Command Line Tools." if sdk.nil?

  sdk = sdk.path

  # Extra setup to support Xcode 4.3+ without CLT.
  self["SDKROOT"] = sdk.to_s
  # 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

#no_fixup_chainsvoid

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.



124
125
126
127
# File 'extend/os/mac/extend/ENV/std.rb', line 124

def no_fixup_chains
  odisabled "ENV.no_fixup_chains", "the default linker behaviour"
  append "LDFLAGS", "-Wl,-no_fixup_chains" if no_fixup_chains_support?
end

#no_weak_importsvoid

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.



118
119
120
121
# File 'extend/os/mac/extend/ENV/std.rb', line 118

def no_weak_imports
  odisabled "ENV.no_weak_imports", "passing `-Wl,-no_weak_imports` to the linker"
  append "LDFLAGS", "-Wl,-no_weak_imports" if no_weak_imports_support?
end

#remove_macosxsdk(version = nil) ⇒ 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.

Parameters:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'extend/os/mac/extend/ENV/std.rb', line 50

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(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

#setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil, testing_formula: false, debug_symbols: false) ⇒ 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.

Parameters:

  • formula (Formula, nil) (defaults to: nil)
  • cc (String, nil) (defaults to: nil)
  • build_bottle (Boolean, nil) (defaults to: false)
  • bottle_arch (String, nil) (defaults to: nil)
  • testing_formula (Boolean) (defaults to: false)
  • debug_symbols (Boolean, nil) (defaults to: false)


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'extend/os/mac/extend/ENV/std.rb', line 30

def setup_build_environment(formula: nil, cc: nil, build_bottle: false, bottle_arch: nil,
                            testing_formula: false, debug_symbols: false)
  super

  append "LDFLAGS", "-Wl,-headerpad_max_install_names"

  # `sed` is strict and errors out when it encounters files with mixed character sets.
  delete("LC_ALL")
  self["LC_CTYPE"] = "C"

  # Add `lib` and `include` etc. from the current `macosxsdk` to compiler flags:
  macosxsdk(formula:, testing_formula:)

  return unless MacOS::Xcode.without_clt?

  append_path "PATH", "#{MacOS::Xcode.prefix}/usr/bin"
  append_path "PATH", "#{MacOS::Xcode.toolchain_path}/usr/bin"
end