2020-10-10 14:16:11 +02:00
|
|
|
# typed: false
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-12 11:39:39 +01:00
|
|
|
module Stdenv
|
|
|
|
# @private
|
2018-04-07 20:28:56 +01:00
|
|
|
|
2020-12-15 14:19:45 +00:00
|
|
|
undef homebrew_extra_pkg_config_paths
|
2020-04-10 21:47:54 +01:00
|
|
|
|
|
|
|
def homebrew_extra_pkg_config_paths
|
2020-12-24 15:23:23 +00:00
|
|
|
["#{HOMEBREW_LIBRARY}/Homebrew/os/mac/pkgconfig/#{MacOS.version}"]
|
2020-04-10 21:47:54 +01:00
|
|
|
end
|
2018-04-07 20:28:56 +01:00
|
|
|
|
2022-07-26 17:18:01 +01:00
|
|
|
def setup_build_environment(
|
|
|
|
formula: nil,
|
|
|
|
cc: nil,
|
|
|
|
build_bottle: false,
|
|
|
|
bottle_arch: nil,
|
|
|
|
testing_formula: false,
|
|
|
|
debug_symbols: false
|
|
|
|
)
|
2021-02-26 05:10:32 +00:00
|
|
|
generic_setup_build_environment(
|
|
|
|
formula: formula, cc: cc, build_bottle: build_bottle,
|
2022-07-26 17:18:01 +01:00
|
|
|
bottle_arch: bottle_arch, testing_formula: testing_formula,
|
|
|
|
debug_symbols: debug_symbols,
|
2021-02-26 05:10:32 +00:00
|
|
|
)
|
2016-07-12 11:39:39 +01:00
|
|
|
|
2021-11-09 20:38:26 -08:00
|
|
|
append "LDFLAGS", "-Wl,-headerpad_max_install_names"
|
|
|
|
|
2019-01-26 17:13:14 +00:00
|
|
|
# sed is strict, and errors out when it encounters files with
|
|
|
|
# mixed character sets
|
|
|
|
delete("LC_ALL")
|
|
|
|
self["LC_CTYPE"] = "C"
|
2016-07-12 11:39:39 +01:00
|
|
|
|
|
|
|
# Add lib and include etc. from the current macosxsdk to compiler flags:
|
2020-12-17 18:30:03 -05:00
|
|
|
macosxsdk(formula: @formula, testing_formula: testing_formula)
|
2016-07-12 11:39:39 +01:00
|
|
|
|
2019-01-26 17:13:14 +00:00
|
|
|
return unless MacOS::Xcode.without_clt?
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2019-01-26 17:13:14 +00:00
|
|
|
append_path "PATH", "#{MacOS::Xcode.prefix}/usr/bin"
|
|
|
|
append_path "PATH", "#{MacOS::Xcode.toolchain_path}/usr/bin"
|
2016-07-12 11:39:39 +01:00
|
|
|
end
|
|
|
|
|
2020-04-23 13:03:44 +01:00
|
|
|
def remove_macosxsdk(version = nil)
|
2016-07-12 11:39:39 +01:00
|
|
|
# Clear all lib and include dirs from CFLAGS, CPPFLAGS, LDFLAGS that were
|
|
|
|
# previously added by macosxsdk
|
2020-06-23 17:10:07 +01:00
|
|
|
remove_from_cflags(/ ?-mmacosx-version-min=\d+\.\d+/)
|
2016-07-12 11:39:39 +01:00
|
|
|
delete("CPATH")
|
|
|
|
remove "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib"
|
|
|
|
|
2020-04-23 13:03:44 +01:00
|
|
|
sdk = self["SDKROOT"] || MacOS.sdk_path_if_needed(version)
|
|
|
|
return unless sdk
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2016-09-23 22:02:23 +02:00
|
|
|
delete("SDKROOT")
|
2020-04-12 14:51:21 +01:00
|
|
|
remove_from_cflags "-isysroot#{sdk}"
|
|
|
|
remove "CPPFLAGS", "-isysroot#{sdk}"
|
|
|
|
remove "LDFLAGS", "-isysroot#{sdk}"
|
2016-09-23 22:02:23 +02:00
|
|
|
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
|
2016-07-12 11:39:39 +01:00
|
|
|
end
|
2016-09-23 22:02:23 +02:00
|
|
|
remove "CMAKE_FRAMEWORK_PATH", "#{sdk}/System/Library/Frameworks"
|
2016-07-12 11:39:39 +01:00
|
|
|
end
|
|
|
|
|
2020-12-17 18:30:03 -05:00
|
|
|
def macosxsdk(version = nil, formula: nil, testing_formula: false)
|
2016-07-12 11:39:39 +01:00
|
|
|
# Sets all needed lib and include dirs to CFLAGS, CPPFLAGS, LDFLAGS.
|
|
|
|
remove_macosxsdk
|
2020-04-23 13:03:44 +01:00
|
|
|
min_version = version || MacOS.version
|
|
|
|
append_to_cflags("-mmacosx-version-min=#{min_version}")
|
2016-07-12 11:39:39 +01:00
|
|
|
self["CPATH"] = "#{HOMEBREW_PREFIX}/include"
|
|
|
|
prepend "LDFLAGS", "-L#{HOMEBREW_PREFIX}/lib"
|
|
|
|
|
2020-12-17 18:30:03 -05:00
|
|
|
sdk = if formula
|
|
|
|
MacOS.sdk_for_formula(formula, version, check_only_runtime_requirements: testing_formula)
|
|
|
|
else
|
|
|
|
MacOS.sdk(version)
|
|
|
|
end
|
2020-06-04 16:35:52 -07:00
|
|
|
return if !MacOS.sdk_root_needed? && sdk&.source != :xcode
|
2020-04-23 13:03:44 +01:00
|
|
|
|
2020-09-11 12:05:22 +01:00
|
|
|
Homebrew::Diagnostic.checks(:fatal_setup_build_environment_checks)
|
2020-04-23 13:03:44 +01:00
|
|
|
sdk = sdk.path
|
2018-09-17 02:45:00 +02:00
|
|
|
|
2016-09-23 22:02:23 +02:00
|
|
|
# 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
|
2020-04-12 14:51:21 +01:00
|
|
|
append_to_cflags "-isysroot#{sdk}"
|
|
|
|
append "CPPFLAGS", "-isysroot#{sdk}"
|
2016-09-23 22:02:23 +02:00
|
|
|
# And the linker needs to find sdk/usr/lib
|
2020-04-12 14:51:21 +01:00
|
|
|
append "LDFLAGS", "-isysroot#{sdk}"
|
2016-09-23 22:02:23 +02:00
|
|
|
# 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"
|
2016-07-12 11:39:39 +01:00
|
|
|
end
|
|
|
|
|
2020-11-05 17:17:03 -05:00
|
|
|
# Some configure scripts won't find libxml2 without help.
|
|
|
|
# This is a no-op with macOS SDK 10.15.4 and later.
|
2016-07-12 11:39:39 +01:00
|
|
|
def libxml2
|
2020-04-23 13:03:44 +01:00
|
|
|
sdk = self["SDKROOT"] || MacOS.sdk_path_if_needed
|
2020-04-04 21:41:41 +01:00
|
|
|
if !sdk
|
2016-07-12 11:39:39 +01:00
|
|
|
append "CPPFLAGS", "-I/usr/include/libxml2"
|
2020-04-23 13:03:44 +01:00
|
|
|
elsif !Pathname("#{sdk}/usr/include/libxml").directory?
|
2016-07-12 11:39:39 +01:00
|
|
|
# Use the includes form the sdk
|
2020-04-04 21:41:41 +01:00
|
|
|
append "CPPFLAGS", "-I#{sdk}/usr/include/libxml2"
|
2016-07-12 11:39:39 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-08-22 10:39:38 +01:00
|
|
|
def no_weak_imports
|
2016-09-17 08:29:47 -07:00
|
|
|
append "LDFLAGS", "-Wl,-no_weak_imports" if no_weak_imports_support?
|
2016-08-17 22:55:16 -07:00
|
|
|
end
|
2016-07-12 11:39:39 +01:00
|
|
|
end
|