Module: Superenv

Includes:
SharedEnvExtension
Defined in:
Library/Homebrew/extend/ENV/super.rb,
Library/Homebrew/extend/os/mac/extend/ENV/super.rb

Overview

### Why `superenv`?

  1. Only specify the environment we need (NO LDFLAGS for cmake)

  2. Only apply compiler specific options when we are calling that compiler

  3. Force all incpaths and libpaths into the cc instantiation (less bugs)

  4. Cater toolchain usage to specific Xcode versions

  5. Remove flags that we don't want or that will break builds

  6. Simpler code

  7. Simpler formula that *just work*

  8. Build-system agnostic configuration of the tool-chain

Constant Summary

Constants included from SharedEnvExtension

SharedEnvExtension::CC_FLAG_VARS, SharedEnvExtension::FC_FLAG_VARS, SharedEnvExtension::SANITIZED_VARS

Constants included from CompilerConstants

CompilerConstants::COMPILERS, CompilerConstants::COMPILER_SYMBOL_MAP, CompilerConstants::GNU_GCC_REGEXP, CompilerConstants::GNU_GCC_VERSIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SharedEnvExtension

#append, #append_path, #append_to_cflags, #cc, #cflags, #compiler, #cppflags, #cxx, #cxxflags, #determine_cc, #fc, #fcflags, #fflags, #fortran, #gcc_version_formula, #ld64, #ldflags, #ncurses_define, #no_weak_imports_support?, #permit_weak_imports, #prepend, #prepend_create_path, #prepend_path, #remove, #remove_cc_etc, #remove_from_cflags, #userpaths!, #warn_about_non_apple_gcc

Instance Attribute Details

#depsObject



18
19
20
# File 'Library/Homebrew/extend/ENV/super.rb', line 18

def deps
  @deps
end

#keg_only_depsObject



18
19
20
# File 'Library/Homebrew/extend/ENV/super.rb', line 18

def keg_only_deps
  @keg_only_deps
end

#x11Object Also known as: x11?

Returns the value of attribute x11



19
20
21
# File 'Library/Homebrew/extend/ENV/super.rb', line 19

def x11
  @x11
end

Class Method Details

.binObject



27
# File 'Library/Homebrew/extend/ENV/super.rb', line 27

def self.bin; end

.extended(base) ⇒ Object



21
22
23
24
# File 'Library/Homebrew/extend/ENV/super.rb', line 21

def self.extended(base)
  base.keg_only_deps = []
  base.deps = []
end

Instance Method Details

#cxx11Object



296
297
298
299
300
301
302
303
304
305
# File 'Library/Homebrew/extend/ENV/super.rb', line 296

def cxx11
  if homebrew_cc == "clang"
    append "HOMEBREW_CCCFG", "x", ""
    append "HOMEBREW_CCCFG", "g", ""
  elsif gcc_with_cxx11_support?(homebrew_cc)
    append "HOMEBREW_CCCFG", "x", ""
  else
    raise "The selected compiler doesn't support C++11: #{homebrew_cc}"
  end
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.



252
253
254
255
256
257
258
259
260
261
262
263
# File 'Library/Homebrew/extend/ENV/super.rb', line 252

def deparallelize
  old = delete("MAKEFLAGS")
  if block_given?
    begin
      yield
    ensure
      self["MAKEFLAGS"] = old
    end
  end

  old
end

#determine_cccfgObject



243
244
245
# File 'Library/Homebrew/extend/ENV/super.rb', line 243

def determine_cccfg
  ""
end

#effective_sysrootObject



11
12
13
# File 'Library/Homebrew/extend/os/mac/extend/ENV/super.rb', line 11

def effective_sysroot
  MacOS.sdk_path.to_s if MacOS::Xcode.without_clt?
end

#generic_setup_build_environmentObject

The HOMEBREW_CCCFG ENV variable is used by the ENV/cc tool to control compiler flag stripping. It consists of a string of characters which act as flags. Some of these flags are mutually exclusive.

O - Enables argument refurbishing. Only active under the

make/bsdmake wrappers currently.

x - Enable C++11 mode. g - Enable “-stdlib=libc++” for clang. h - Enable “-stdlib=libstdc++” for clang. K - Don't strip -arch <arch>, -m32, or -m64 w - Pass -no_weak_imports to the linker

On 10.8 and newer, these flags will also be present: s - apply fix for sed's Unicode support a - apply fix for apr-1-config path



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'Library/Homebrew/extend/ENV/super.rb', line 82

def setup_build_environment(formula = nil)
  super
  send(compiler)

  self["MAKEFLAGS"] ||= "-j#{determine_make_jobs}"
  self["PATH"] = determine_path
  self["PKG_CONFIG_PATH"] = determine_pkg_config_path
  self["PKG_CONFIG_LIBDIR"] = determine_pkg_config_libdir
  self["HOMEBREW_CCCFG"] = determine_cccfg
  self["HOMEBREW_OPTIMIZATION_LEVEL"] = "Os"
  self["HOMEBREW_BREW_FILE"] = HOMEBREW_BREW_FILE.to_s
  self["HOMEBREW_PREFIX"] = HOMEBREW_PREFIX.to_s
  self["HOMEBREW_CELLAR"] = HOMEBREW_CELLAR.to_s
  self["HOMEBREW_OPT"] = "#{HOMEBREW_PREFIX}/opt"
  self["HOMEBREW_TEMP"] = HOMEBREW_TEMP.to_s
  self["HOMEBREW_OPTFLAGS"] = determine_optflags
  self["HOMEBREW_ARCHFLAGS"] = ""
  self["CMAKE_PREFIX_PATH"] = determine_cmake_prefix_path
  self["CMAKE_FRAMEWORK_PATH"] = determine_cmake_frameworks_path
  self["CMAKE_INCLUDE_PATH"] = determine_cmake_include_path
  self["CMAKE_LIBRARY_PATH"] = determine_cmake_library_path
  self["ACLOCAL_PATH"] = determine_aclocal_path
  self["M4"] = DevelopmentTools.locate("m4") if deps.any? { |d| d.name == "autoconf" }
  self["HOMEBREW_ISYSTEM_PATHS"] = determine_isystem_paths
  self["HOMEBREW_INCLUDE_PATHS"] = determine_include_paths
  self["HOMEBREW_LIBRARY_PATHS"] = determine_library_paths
  self["HOMEBREW_DEPENDENCIES"] = determine_dependencies
  self["HOMEBREW_FORMULA_PREFIX"] = formula.prefix unless formula.nil?

  # The HOMEBREW_CCCFG ENV variable is used by the ENV/cc tool to control
  # compiler flag stripping. It consists of a string of characters which act
  # as flags. Some of these flags are mutually exclusive.
  #
  # O - Enables argument refurbishing. Only active under the
  #     make/bsdmake wrappers currently.
  # x - Enable C++11 mode.
  # g - Enable "-stdlib=libc++" for clang.
  # h - Enable "-stdlib=libstdc++" for clang.
  # K - Don't strip -arch <arch>, -m32, or -m64
  # w - Pass -no_weak_imports to the linker
  #
  # On 10.8 and newer, these flags will also be present:
  # s - apply fix for sed's Unicode support
  # a - apply fix for apr-1-config path
end

#homebrew_extra_aclocal_pathsObject



144
145
146
# File 'Library/Homebrew/extend/ENV/super.rb', line 144

def homebrew_extra_aclocal_paths
  []
end

#homebrew_extra_cmake_frameworks_pathsObject



210
211
212
# File 'Library/Homebrew/extend/ENV/super.rb', line 210

def homebrew_extra_cmake_frameworks_paths
  []
end

#homebrew_extra_cmake_include_pathsObject



194
195
196
# File 'Library/Homebrew/extend/ENV/super.rb', line 194

def homebrew_extra_cmake_include_paths
  []
end

#homebrew_extra_cmake_library_pathsObject



202
203
204
# File 'Library/Homebrew/extend/ENV/super.rb', line 202

def homebrew_extra_cmake_library_paths
  []
end

#homebrew_extra_isystem_pathsObject



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

def homebrew_extra_isystem_paths
  []
end

#homebrew_extra_library_pathsObject



171
172
173
# File 'Library/Homebrew/extend/ENV/super.rb', line 171

def homebrew_extra_library_paths
  []
end

#homebrew_extra_pathsObject



98
99
100
# File 'Library/Homebrew/extend/ENV/super.rb', line 98

def homebrew_extra_paths
  []
end

#homebrew_extra_pkg_config_pathsObject



29
30
31
# File 'Library/Homebrew/extend/os/mac/extend/ENV/super.rb', line 29

def homebrew_extra_pkg_config_paths
  []
end

#libcxxObject



307
308
309
# File 'Library/Homebrew/extend/ENV/super.rb', line 307

def libcxx
  append "HOMEBREW_CCCFG", "g", "" if compiler == :clang
end

#libstdcxxObject



311
312
313
# File 'Library/Homebrew/extend/ENV/super.rb', line 311

def libstdcxx
  append "HOMEBREW_CCCFG", "h", "" if compiler == :clang
end

#m32Object



288
289
290
# File 'Library/Homebrew/extend/ENV/super.rb', line 288

def m32
  append "HOMEBREW_ARCHFLAGS", "-m32"
end

#m64Object



292
293
294
# File 'Library/Homebrew/extend/ENV/super.rb', line 292

def m64
  append "HOMEBREW_ARCHFLAGS", "-m64"
end

#make_jobsObject



265
266
267
268
# File 'Library/Homebrew/extend/ENV/super.rb', line 265

def make_jobs
  self["MAKEFLAGS"] =~ /-\w*j(\d+)/
  [Regexp.last_match(1).to_i, 1].max
end

#no_weak_importsObject



122
123
124
# File 'Library/Homebrew/extend/os/mac/extend/ENV/super.rb', line 122

def no_weak_imports
  append "HOMEBREW_CCCFG", "w" if no_weak_imports_support?
end

#permit_arch_flagsObject



284
285
286
# File 'Library/Homebrew/extend/ENV/super.rb', line 284

def permit_arch_flags
  append "HOMEBREW_CCCFG", "K"
end

#refurbish_argsObject



316
317
318
# File 'Library/Homebrew/extend/ENV/super.rb', line 316

def refurbish_args
  append "HOMEBREW_CCCFG", "O", ""
end

#resetObject



29
30
31
32
33
34
# File 'Library/Homebrew/extend/ENV/super.rb', line 29

def reset
  super
  # Configure scripts generated by autoconf 2.61 or later export as_nl, which
  # we use as a heuristic for running under configure
  delete("as_nl")
end

#set_cpu_flags(_, _ = "", _ = {}) ⇒ Object



328
# File 'Library/Homebrew/extend/ENV/super.rb', line 328

def set_cpu_flags(_, _ = "", _ = {}); end

#set_x11_env_if_installedObject



326
# File 'Library/Homebrew/extend/ENV/super.rb', line 326

def set_x11_env_if_installed; end

#setup_build_environment(formula = nil) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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
# File 'Library/Homebrew/extend/ENV/super.rb', line 37

def setup_build_environment(formula = nil)
  super
  send(compiler)

  self["MAKEFLAGS"] ||= "-j#{determine_make_jobs}"
  self["PATH"] = determine_path
  self["PKG_CONFIG_PATH"] = determine_pkg_config_path
  self["PKG_CONFIG_LIBDIR"] = determine_pkg_config_libdir
  self["HOMEBREW_CCCFG"] = determine_cccfg
  self["HOMEBREW_OPTIMIZATION_LEVEL"] = "Os"
  self["HOMEBREW_BREW_FILE"] = HOMEBREW_BREW_FILE.to_s
  self["HOMEBREW_PREFIX"] = HOMEBREW_PREFIX.to_s
  self["HOMEBREW_CELLAR"] = HOMEBREW_CELLAR.to_s
  self["HOMEBREW_OPT"] = "#{HOMEBREW_PREFIX}/opt"
  self["HOMEBREW_TEMP"] = HOMEBREW_TEMP.to_s
  self["HOMEBREW_OPTFLAGS"] = determine_optflags
  self["HOMEBREW_ARCHFLAGS"] = ""
  self["CMAKE_PREFIX_PATH"] = determine_cmake_prefix_path
  self["CMAKE_FRAMEWORK_PATH"] = determine_cmake_frameworks_path
  self["CMAKE_INCLUDE_PATH"] = determine_cmake_include_path
  self["CMAKE_LIBRARY_PATH"] = determine_cmake_library_path
  self["ACLOCAL_PATH"] = determine_aclocal_path
  self["M4"] = DevelopmentTools.locate("m4") if deps.any? { |d| d.name == "autoconf" }
  self["HOMEBREW_ISYSTEM_PATHS"] = determine_isystem_paths
  self["HOMEBREW_INCLUDE_PATHS"] = determine_include_paths
  self["HOMEBREW_LIBRARY_PATHS"] = determine_library_paths
  self["HOMEBREW_DEPENDENCIES"] = determine_dependencies
  self["HOMEBREW_FORMULA_PREFIX"] = formula.prefix unless formula.nil?

  # The HOMEBREW_CCCFG ENV variable is used by the ENV/cc tool to control
  # compiler flag stripping. It consists of a string of characters which act
  # as flags. Some of these flags are mutually exclusive.
  #
  # O - Enables argument refurbishing. Only active under the
  #     make/bsdmake wrappers currently.
  # x - Enable C++11 mode.
  # g - Enable "-stdlib=libc++" for clang.
  # h - Enable "-stdlib=libstdc++" for clang.
  # K - Don't strip -arch <arch>, -m32, or -m64
  # w - Pass -no_weak_imports to the linker
  #
  # On 10.8 and newer, these flags will also be present:
  # s - apply fix for sed's Unicode support
  # a - apply fix for apr-1-config path
end

#universal_binaryObject



270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'Library/Homebrew/extend/ENV/super.rb', line 270

def universal_binary
  check_for_compiler_universal_support

  self["HOMEBREW_ARCHFLAGS"] = Hardware::CPU.universal_archs.as_arch_flags

  # GCC doesn't accept "-march" for a 32-bit CPU with "-arch x86_64"
  return if compiler == :clang
  return unless Hardware::CPU.is_32_bit?
  self["HOMEBREW_OPTFLAGS"] = self["HOMEBREW_OPTFLAGS"].sub(
    /-march=\S*/,
    "-Xarch_#{Hardware::CPU.arch_32_bit} \\0",
  )
end