2016-01-10 17:33:54 +01:00
|
|
|
#!/bin/sh
|
|
|
|
# Make sure this shim uses the same Ruby interpreter that is used by Homebrew.
|
2021-09-13 20:32:20 +08:00
|
|
|
if [[ -z "${HOMEBREW_RUBY_PATH}" ]]
|
2016-02-04 14:46:31 +01:00
|
|
|
then
|
|
|
|
echo "${0##*/}: The build tool has reset ENV; --env=std required." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-09-13 20:32:20 +08:00
|
|
|
exec "${HOMEBREW_RUBY_PATH}" --enable-frozen-string-literal --disable=gems,did_you_mean,rubyopt -x "$0" "$@"
|
2016-01-10 17:33:54 +01:00
|
|
|
#!/usr/bin/env ruby -W0
|
2012-09-03 11:56:29 -04:00
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
require "pathname"
|
|
|
|
require "set"
|
2021-01-12 13:44:57 -08:00
|
|
|
require "English"
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
|
2018-05-28 11:54:16 -07:00
|
|
|
def mac?
|
|
|
|
RUBY_PLATFORM[/darwin/]
|
|
|
|
end
|
|
|
|
|
2018-09-19 22:39:33 +02:00
|
|
|
def high_sierra_or_later?
|
2018-09-20 13:49:10 +01:00
|
|
|
mac? && ENV["HOMEBREW_MACOS_VERSION_NUMERIC"].to_s.to_i >= 101300
|
2018-09-03 20:49:01 +01:00
|
|
|
end
|
|
|
|
|
2018-05-28 11:54:16 -07:00
|
|
|
def linux?
|
|
|
|
RUBY_PLATFORM[/linux/]
|
|
|
|
end
|
|
|
|
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
class Cmd
|
2021-01-12 13:49:14 -08:00
|
|
|
CXX_REGEX = /(?:c|g|clang)\+\+/.freeze
|
|
|
|
|
2018-12-09 18:27:24 -08:00
|
|
|
attr_reader :config, :prefix, :cellar, :opt, :cachedir, :tmpdir, :sysroot, :deps
|
2016-04-13 02:53:41 -04:00
|
|
|
attr_reader :archflags, :optflags, :keg_regex, :formula_prefix
|
2013-11-21 14:50:35 -06:00
|
|
|
|
2015-02-12 19:13:03 -05:00
|
|
|
def initialize(arg0, args)
|
|
|
|
@arg0 = arg0
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
@args = args.freeze
|
2021-01-08 12:15:55 -08:00
|
|
|
@config = ENV.fetch("HOMEBREW_CCCFG", "")
|
2015-08-03 13:09:07 +01:00
|
|
|
@prefix = ENV["HOMEBREW_PREFIX"]
|
|
|
|
@cellar = ENV["HOMEBREW_CELLAR"]
|
2018-12-09 18:27:24 -08:00
|
|
|
@cachedir = ENV["HOMEBREW_CACHE"]
|
2016-03-24 11:18:30 -07:00
|
|
|
@opt = ENV["HOMEBREW_OPT"]
|
2015-08-03 13:09:07 +01:00
|
|
|
@tmpdir = ENV["HOMEBREW_TEMP"]
|
|
|
|
@sysroot = ENV["HOMEBREW_SDKROOT"]
|
2021-01-08 12:15:55 -08:00
|
|
|
@archflags = ENV.fetch("HOMEBREW_ARCHFLAGS", "").split
|
|
|
|
@optflags = ENV.fetch("HOMEBREW_OPTFLAGS", "").split
|
|
|
|
@deps = Set.new(ENV.fetch("HOMEBREW_DEPENDENCIES", "").split(","))
|
2016-04-13 02:53:41 -04:00
|
|
|
@formula_prefix = ENV["HOMEBREW_FORMULA_PREFIX"]
|
2016-03-24 11:18:30 -07:00
|
|
|
# matches opt or cellar prefix and formula name
|
2021-01-08 12:15:55 -08:00
|
|
|
@keg_regex = %r{(#{Regexp.escape(opt)}|#{Regexp.escape(cellar)})/([\w+-.@]+)}
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
end
|
2014-04-21 00:17:22 -05:00
|
|
|
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
def mode
|
2018-05-28 11:54:16 -07:00
|
|
|
if @arg0 == "cpp"
|
|
|
|
:cpp
|
|
|
|
elsif ["ld", "ld.gold", "gold"].include? @arg0
|
|
|
|
:ld
|
2015-08-03 13:09:07 +01:00
|
|
|
elsif @args.include? "-c"
|
2021-01-12 13:49:14 -08:00
|
|
|
if CXX_REGEX.match?(@arg0)
|
2013-10-07 00:40:32 -07:00
|
|
|
:cxx
|
|
|
|
else
|
|
|
|
:cc
|
|
|
|
end
|
2017-08-09 12:44:41 -07:00
|
|
|
elsif @args.include?("-xc++-header") || @args.each_cons(2).include?(["-x", "c++-header"])
|
|
|
|
:cxx
|
2015-08-03 13:09:07 +01:00
|
|
|
elsif @args.include? "-E"
|
2013-08-31 10:43:23 -05:00
|
|
|
:ccE
|
2021-01-12 13:49:14 -08:00
|
|
|
elsif CXX_REGEX.match?(@arg0)
|
2021-01-08 12:15:55 -08:00
|
|
|
:cxxld
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
else
|
2021-01-08 12:15:55 -08:00
|
|
|
:ccld
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
end
|
|
|
|
end
|
2014-04-21 00:17:22 -05:00
|
|
|
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
def tool
|
2012-09-03 11:56:29 -04:00
|
|
|
@tool ||= case @arg0
|
2015-08-03 13:09:07 +01:00
|
|
|
when "ld" then "ld"
|
2018-05-28 11:54:16 -07:00
|
|
|
when "gold", "ld.gold" then "ld.gold"
|
2015-08-03 13:09:07 +01:00
|
|
|
when "cpp" then "cpp"
|
2016-09-24 23:56:54 -04:00
|
|
|
when /llvm_(clang(\+\+)?)/
|
2021-01-08 12:15:55 -08:00
|
|
|
"#{ENV["HOMEBREW_PREFIX"]}/opt/llvm/bin/#{Regexp.last_match(1)}"
|
2020-05-01 01:31:57 +10:00
|
|
|
when /\w\+\+(-\d+(\.\d)?)?$/
|
2015-08-03 13:09:07 +01:00
|
|
|
case ENV["HOMEBREW_CC"]
|
2013-05-27 12:54:07 -05:00
|
|
|
when /clang/
|
2015-08-03 13:09:07 +01:00
|
|
|
"clang++"
|
2013-05-27 12:54:07 -05:00
|
|
|
when /llvm-gcc/
|
2015-08-03 13:09:07 +01:00
|
|
|
"llvm-g++-4.2"
|
2020-05-01 01:31:57 +10:00
|
|
|
when /(g)?cc(-\d+(\.\d)?)?$/
|
2021-01-08 12:15:55 -08:00
|
|
|
"g++#{Regexp.last_match(2)}"
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
end
|
|
|
|
else
|
2013-10-16 17:53:01 -07:00
|
|
|
# Note that this is a universal fallback, so that we'll always invoke
|
|
|
|
# HOMEBREW_CC regardless of what name under which the tool was invoked.
|
2017-03-08 17:05:25 -08:00
|
|
|
if ENV["HOMEBREW_CC"] == "llvm_clang"
|
|
|
|
"#{ENV["HOMEBREW_PREFIX"]}/opt/llvm/bin/clang"
|
|
|
|
else
|
|
|
|
ENV["HOMEBREW_CC"]
|
|
|
|
end
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
end
|
|
|
|
end
|
2014-04-21 00:17:22 -05:00
|
|
|
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
def args
|
2015-08-06 15:45:52 +08:00
|
|
|
if @args.length == 1 && @args[0] == "-v"
|
2014-03-25 08:15:31 +00:00
|
|
|
# Don't add linker arguments if -v passed as sole option. This stops gcc
|
|
|
|
# -v with no other arguments from outputting a linker error. Some
|
|
|
|
# software uses gcc -v (wrongly) to sniff the GCC version.
|
|
|
|
return @args.dup
|
|
|
|
end
|
2015-02-08 20:04:06 -05:00
|
|
|
|
2021-03-29 01:42:38 +01:00
|
|
|
args = if !refurbish_args? || mode == :ld || configure?
|
2021-01-08 12:15:55 -08:00
|
|
|
@args.dup
|
2012-08-31 09:18:05 -04:00
|
|
|
else
|
2021-01-08 12:15:55 -08:00
|
|
|
refurbished_args
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
end
|
2014-04-21 00:17:22 -05:00
|
|
|
|
2014-05-19 14:18:23 -05:00
|
|
|
if sysroot
|
2014-04-21 00:17:22 -05:00
|
|
|
if tool == "ld"
|
2014-05-19 14:18:23 -05:00
|
|
|
args << "-syslibroot" << sysroot
|
2014-04-21 00:17:22 -05:00
|
|
|
else
|
2019-11-16 15:07:11 +00:00
|
|
|
args << "-isysroot#{sysroot}" << "--sysroot=#{sysroot}"
|
2014-04-21 00:17:22 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-10 20:27:26 -05:00
|
|
|
case mode
|
2013-11-10 18:24:49 -06:00
|
|
|
when :ccld
|
2013-08-31 10:38:18 -05:00
|
|
|
cflags + args + cppflags + ldflags
|
2013-11-10 18:24:49 -06:00
|
|
|
when :cxxld
|
|
|
|
cxxflags + args + cppflags + ldflags
|
|
|
|
when :cc
|
2013-08-31 10:38:18 -05:00
|
|
|
cflags + args + cppflags
|
2013-11-10 18:24:49 -06:00
|
|
|
when :cxx
|
|
|
|
cxxflags + args + cppflags
|
2013-08-31 10:43:23 -05:00
|
|
|
when :ccE
|
2013-08-31 11:14:38 -05:00
|
|
|
args + cppflags
|
2013-08-31 10:43:23 -05:00
|
|
|
when :cpp
|
|
|
|
args + cppflags
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
when :ld
|
|
|
|
ldflags + args
|
2015-02-12 20:09:31 -05:00
|
|
|
end
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
end
|
2014-04-21 00:17:22 -05:00
|
|
|
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
def refurbished_args
|
2014-05-19 14:18:23 -05:00
|
|
|
@lset = Set.new(library_paths + system_library_paths)
|
|
|
|
@iset = Set.new(isystem_paths + include_paths)
|
2012-09-03 14:34:42 -04:00
|
|
|
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
args = []
|
2014-05-06 15:21:01 -05:00
|
|
|
enum = @args.each
|
|
|
|
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
loop do
|
2014-05-06 15:21:01 -05:00
|
|
|
case arg = enum.next
|
|
|
|
when "-arch"
|
2015-02-08 20:04:06 -05:00
|
|
|
if permit_arch_flags?
|
2014-05-14 00:00:59 -05:00
|
|
|
args << arg << enum.next
|
|
|
|
else
|
|
|
|
enum.next
|
|
|
|
end
|
2014-05-22 09:18:34 -05:00
|
|
|
when "-m32", "-m64"
|
2015-02-08 20:04:06 -05:00
|
|
|
args << arg if permit_arch_flags?
|
2014-05-06 15:21:01 -05:00
|
|
|
when /^-Xarch_/
|
|
|
|
refurbished = refurbish_arg(enum.next, enum)
|
|
|
|
unless refurbished.empty?
|
|
|
|
args << arg
|
|
|
|
args += refurbished
|
|
|
|
end
|
|
|
|
else
|
|
|
|
args += refurbish_arg(arg, enum)
|
|
|
|
end
|
2014-05-06 15:21:01 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
args
|
|
|
|
end
|
|
|
|
|
|
|
|
def refurbish_arg(arg, enum)
|
|
|
|
args = []
|
|
|
|
|
|
|
|
case arg
|
2015-12-29 11:56:55 +00:00
|
|
|
when /^-g\d?$/, /^-gstabs\d+/, "-gstabs+", /^-ggdb\d?/,
|
2021-06-27 17:46:50 +01:00
|
|
|
/^-mtune=.+/, /^-mcpu=.+/, /^-O[0-9zs]?$/,
|
|
|
|
"-fast", "-no-cpp-precomp", "-pedantic",
|
|
|
|
"-pedantic-errors", "-Wno-long-double",
|
2015-08-03 13:09:07 +01:00
|
|
|
"-Wno-unused-but-set-variable"
|
2021-06-27 17:46:50 +01:00
|
|
|
when /^-march=.+/
|
|
|
|
args << arg if runtime_cpu_detection?
|
2016-11-21 08:50:01 +00:00
|
|
|
when "-fopenmp", "-lgomp", "-mno-fused-madd", "-fforce-addr", "-fno-defer-pop",
|
2015-08-03 13:09:07 +01:00
|
|
|
"-mno-dynamic-no-pic", "-fearly-inlining", /^-f(?:no-)?inline-functions-called-once/,
|
|
|
|
/^-finline-limit/, /^-f(?:no-)?check-new/, "-fno-delete-null-pointer-checks",
|
|
|
|
"-fcaller-saves", "-fthread-jumps", "-fno-reorder-blocks", "-fcse-skip-blocks",
|
|
|
|
"-frerun-cse-after-loop", "-frerun-loop-opt", "-fcse-follow-jumps",
|
|
|
|
"-fno-regmove", "-fno-for-scope", "-fno-tree-pre", "-fno-tree-dominator-opts",
|
2016-11-13 16:12:57 -05:00
|
|
|
"-fuse-linker-plugin", "-frounding-math"
|
2014-05-06 15:21:01 -05:00
|
|
|
# clang doesn't support these flags
|
2015-08-03 13:09:07 +01:00
|
|
|
args << arg unless tool =~ /^clang/
|
2020-04-24 00:29:02 +01:00
|
|
|
when "-Xpreprocessor", "-Xclang"
|
2019-01-02 14:29:36 +01:00
|
|
|
# used for -Xpreprocessor -fopenmp
|
|
|
|
args << arg << enum.next
|
2020-06-23 17:10:07 +01:00
|
|
|
when /-mmacosx-version-min=(\d+)\.(\d+)/
|
2021-01-08 12:15:55 -08:00
|
|
|
if high_sierra_or_later? && Regexp.last_match(1) == "10" && Regexp.last_match(2).to_i < 9
|
|
|
|
arg = "-mmacosx-version-min=10.9"
|
|
|
|
end
|
2018-09-03 20:49:01 +01:00
|
|
|
args << arg
|
2016-03-29 00:52:52 -07:00
|
|
|
when "--fast-math"
|
2021-01-08 12:15:55 -08:00
|
|
|
arg = "-ffast-math" if /^clang/.match?(tool)
|
2016-03-29 00:52:52 -07:00
|
|
|
args << arg
|
2016-01-11 22:23:33 -04:00
|
|
|
when "-Wno-deprecated-register"
|
|
|
|
# older gccs don't support these flags
|
2016-01-15 22:58:50 -04:00
|
|
|
args << arg unless tool =~ /^g..-4.[02]/
|
2016-11-02 01:21:15 -07:00
|
|
|
when /^-Wl,-z,defs/
|
|
|
|
# -Wl,-undefined,error is already the default
|
2020-04-14 23:17:24 +01:00
|
|
|
when /^-W[alp],/, /^-Wno-/, "-Werror=implicit-function-declaration"
|
2014-05-06 19:29:18 -05:00
|
|
|
args << arg
|
2014-05-06 15:21:01 -05:00
|
|
|
when /^-W.*/
|
2014-05-06 19:29:18 -05:00
|
|
|
# prune warnings
|
2015-08-03 13:09:07 +01:00
|
|
|
when "-macosx_version_min", "-dylib_install_name"
|
2014-05-06 15:21:01 -05:00
|
|
|
args << "-Wl,#{arg},#{enum.next}"
|
2015-08-03 13:09:07 +01:00
|
|
|
when "-multiply_definedsuppress"
|
2014-05-06 15:21:01 -05:00
|
|
|
args << "-Wl,-multiply_defined,suppress"
|
2015-08-03 13:09:07 +01:00
|
|
|
when "-undefineddynamic_lookup"
|
2014-05-06 15:21:01 -05:00
|
|
|
args << "-Wl,-undefined,dynamic_lookup"
|
2021-06-08 00:58:23 +01:00
|
|
|
when /^-isysroot=/, /^--sysroot=/
|
2018-05-28 11:54:16 -07:00
|
|
|
if mac?
|
2021-06-08 00:58:23 +01:00
|
|
|
sdk = arg.split("=")[1..-1].join("=")
|
|
|
|
# We set the sysroot for macOS SDKs
|
|
|
|
args << arg unless sdk.downcase.include? "osx"
|
|
|
|
else
|
|
|
|
args << arg
|
|
|
|
end
|
|
|
|
when /^-isysroot(.+)?/, /^--sysroot(.+)?/
|
|
|
|
# Support both "-isysrootfoo" and "-isysroot foo" (two arguments)
|
|
|
|
sdk = chuzzle(Regexp.last_match(1))
|
|
|
|
if mac?
|
|
|
|
sdk ||= enum.next
|
2018-05-28 11:54:16 -07:00
|
|
|
# We set the sysroot for macOS SDKs
|
2019-11-16 15:07:11 +00:00
|
|
|
args << "-isysroot#{sdk}" unless sdk.downcase.include? "osx"
|
2018-05-28 11:54:16 -07:00
|
|
|
else
|
2021-06-08 00:58:23 +01:00
|
|
|
args << arg
|
|
|
|
args << enum.next unless sdk
|
2018-05-28 11:54:16 -07:00
|
|
|
end
|
2015-08-03 13:09:07 +01:00
|
|
|
when "-dylib"
|
2014-05-06 15:21:01 -05:00
|
|
|
args << "-Wl,#{arg}"
|
|
|
|
when /^-I(.+)?/
|
|
|
|
# Support both "-Ifoo" (one argument) and "-I foo" (two arguments)
|
2021-01-08 12:15:55 -08:00
|
|
|
val = chuzzle(Regexp.last_match(1)) || enum.next
|
2014-05-06 15:21:01 -05:00
|
|
|
path = canonical_path(val)
|
|
|
|
args << "-I#{val}" if keep?(path) && @iset.add?(path)
|
|
|
|
when /^-L(.+)?/
|
2021-01-08 12:15:55 -08:00
|
|
|
val = chuzzle(Regexp.last_match(1)) || enum.next
|
2014-05-06 15:21:01 -05:00
|
|
|
path = canonical_path(val)
|
|
|
|
args << "-L#{val}" if keep?(path) && @lset.add?(path)
|
|
|
|
else
|
|
|
|
args << arg
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
end
|
2014-05-06 15:21:01 -05:00
|
|
|
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
args
|
|
|
|
end
|
2013-12-27 15:46:36 -06:00
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
def keep?(path)
|
2016-04-10 17:49:28 -04:00
|
|
|
# Allow references to self
|
2016-04-13 02:53:41 -04:00
|
|
|
if formula_prefix && path.start_with?("#{formula_prefix}/")
|
2016-04-10 17:49:28 -04:00
|
|
|
true
|
2016-03-24 11:18:30 -07:00
|
|
|
# first two paths: reject references to Cellar or opt paths
|
|
|
|
# for unspecified dependencies
|
2016-04-10 17:49:28 -04:00
|
|
|
elsif path.start_with?(cellar) || path.start_with?(opt)
|
2016-03-24 11:18:30 -07:00
|
|
|
dep = path[keg_regex, 2]
|
|
|
|
dep && @deps.include?(dep)
|
2018-12-09 18:27:24 -08:00
|
|
|
elsif path.start_with?(prefix, cachedir, tmpdir)
|
2016-03-24 11:18:30 -07:00
|
|
|
true
|
2018-05-28 11:54:16 -07:00
|
|
|
elsif path.start_with?("/opt/local", "/opt/boxen/homebrew", "/opt/X11", "/sw", "/usr/X11")
|
2016-04-05 12:25:52 -07:00
|
|
|
# ignore MacPorts, Boxen's Homebrew, X11, fink
|
2018-05-28 11:54:16 -07:00
|
|
|
false
|
2021-01-01 19:02:59 -08:00
|
|
|
elsif prefix != "/usr/local" && path.start_with?("/usr/local")
|
|
|
|
# ignore things in /usr/local if Homebrew is in another prefix;
|
|
|
|
# on macOS, this probably means that the user is on ARM and has an Intel
|
|
|
|
# Homebrew in /usr/local
|
|
|
|
false
|
2018-05-28 11:54:16 -07:00
|
|
|
elsif mac?
|
|
|
|
true
|
|
|
|
else
|
|
|
|
false
|
2016-03-24 11:18:30 -07:00
|
|
|
end
|
2013-12-27 15:46:36 -06:00
|
|
|
end
|
|
|
|
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
def cflags
|
2013-10-07 00:40:32 -07:00
|
|
|
args = []
|
|
|
|
|
2021-01-08 12:15:55 -08:00
|
|
|
return args if !refurbish_args? && !configure?
|
2013-11-11 12:14:23 -06:00
|
|
|
|
2015-08-03 13:09:07 +01:00
|
|
|
args << "-pipe"
|
|
|
|
args << "-w" unless configure?
|
2015-02-08 20:04:07 -05:00
|
|
|
args << "-#{ENV["HOMEBREW_OPTIMIZATION_LEVEL"]}"
|
2021-06-27 17:46:50 +01:00
|
|
|
args.concat(optflags) unless runtime_cpu_detection?
|
2013-11-12 12:00:18 -06:00
|
|
|
args.concat(archflags)
|
2021-01-08 12:15:55 -08:00
|
|
|
args << "-std=#{@arg0}" if /c[89]9/.match?(@arg0)
|
2013-11-12 12:00:18 -06:00
|
|
|
args
|
|
|
|
end
|
2014-04-21 00:17:22 -05:00
|
|
|
|
2013-11-12 12:00:18 -06:00
|
|
|
def cxxflags
|
|
|
|
args = cflags
|
2015-02-08 20:04:06 -05:00
|
|
|
args << "-std=c++11" if cxx11?
|
|
|
|
args << "-stdlib=libc++" if libcxx?
|
|
|
|
args << "-stdlib=libstdc++" if libstdcxx?
|
2013-11-12 12:00:18 -06:00
|
|
|
args
|
|
|
|
end
|
2014-04-21 00:17:22 -05:00
|
|
|
|
2014-05-19 14:18:23 -05:00
|
|
|
def cppflags
|
|
|
|
path_flags("-isystem", isystem_paths) + path_flags("-I", include_paths)
|
2012-09-03 14:34:42 -04:00
|
|
|
end
|
2014-04-21 00:17:22 -05:00
|
|
|
|
2018-05-28 11:54:16 -07:00
|
|
|
def ldflags_mac(args)
|
2013-08-23 11:36:03 -05:00
|
|
|
case mode
|
2014-05-10 17:10:40 -05:00
|
|
|
when :ld
|
|
|
|
args << "-headerpad_max_install_names"
|
2016-08-16 13:48:21 +01:00
|
|
|
args << "-no_weak_imports" if no_weak_imports?
|
2014-05-10 17:10:40 -05:00
|
|
|
when :ccld, :cxxld
|
|
|
|
args << "-Wl,-headerpad_max_install_names"
|
2016-08-16 13:48:21 +01:00
|
|
|
args << "-Wl,-no_weak_imports" if no_weak_imports?
|
2013-08-23 11:36:03 -05:00
|
|
|
end
|
|
|
|
args
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
end
|
2014-04-21 00:17:22 -05:00
|
|
|
|
2018-05-28 11:54:16 -07:00
|
|
|
def ldflags_linux(args)
|
|
|
|
unless mode == :ld
|
|
|
|
wl = "-Wl,"
|
|
|
|
args << "-B#{@opt}/glibc/lib"
|
|
|
|
end
|
|
|
|
args += rpath_flags("#{wl}-rpath=", rpath_paths)
|
|
|
|
args += ["#{wl}--dynamic-linker=#{dynamic_linker_path}"] if dynamic_linker_path
|
|
|
|
args
|
|
|
|
end
|
|
|
|
|
|
|
|
def ldflags
|
|
|
|
args = path_flags("-L", library_paths)
|
|
|
|
if mac?
|
|
|
|
ldflags_mac(args)
|
|
|
|
elsif linux?
|
|
|
|
ldflags_linux(args)
|
|
|
|
else
|
|
|
|
args
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-19 14:18:23 -05:00
|
|
|
def isystem_paths
|
|
|
|
path_split("HOMEBREW_ISYSTEM_PATHS")
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_paths
|
|
|
|
path_split("HOMEBREW_INCLUDE_PATHS")
|
|
|
|
end
|
|
|
|
|
|
|
|
def library_paths
|
|
|
|
path_split("HOMEBREW_LIBRARY_PATHS")
|
|
|
|
end
|
|
|
|
|
2018-05-28 11:54:16 -07:00
|
|
|
def rpath_paths
|
|
|
|
path_split("HOMEBREW_RPATH_PATHS")
|
|
|
|
end
|
|
|
|
|
|
|
|
def dynamic_linker_path
|
|
|
|
chuzzle(ENV["HOMEBREW_DYNAMIC_LINKER"])
|
|
|
|
end
|
|
|
|
|
2014-05-19 14:18:23 -05:00
|
|
|
def system_library_paths
|
2016-08-31 22:38:18 -07:00
|
|
|
paths = ["#{sysroot}/usr/lib"]
|
2021-01-08 12:15:55 -08:00
|
|
|
paths << "/usr/local/lib" if !sysroot && !ENV["SDKROOT"]
|
2016-08-31 22:38:18 -07:00
|
|
|
paths
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
end
|
2014-04-21 00:17:22 -05:00
|
|
|
|
2013-11-04 11:02:12 -06:00
|
|
|
def configure?
|
2013-11-15 00:15:50 -06:00
|
|
|
# configure scripts generated with autoconf 2.61 or later export as_nl
|
2015-08-03 13:09:07 +01:00
|
|
|
ENV.key? "as_nl"
|
2013-11-04 11:02:12 -06:00
|
|
|
end
|
2014-04-21 00:17:22 -05:00
|
|
|
|
2015-02-08 20:04:06 -05:00
|
|
|
def refurbish_args?
|
2015-02-08 20:04:06 -05:00
|
|
|
config.include?("O")
|
2015-02-08 20:04:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def cxx11?
|
2015-02-08 20:04:06 -05:00
|
|
|
config.include?("x")
|
2015-02-08 20:04:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def libcxx?
|
2015-02-08 20:04:06 -05:00
|
|
|
config.include?("g")
|
2015-02-08 20:04:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def libstdcxx?
|
2015-02-08 20:04:06 -05:00
|
|
|
config.include?("h")
|
2015-02-08 20:04:06 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def permit_arch_flags?
|
2015-02-08 20:04:06 -05:00
|
|
|
config.include?("K")
|
2015-02-08 20:04:06 -05:00
|
|
|
end
|
|
|
|
|
2021-06-27 17:46:50 +01:00
|
|
|
def runtime_cpu_detection?
|
|
|
|
config.include?("d")
|
|
|
|
end
|
|
|
|
|
2016-08-16 13:48:21 +01:00
|
|
|
def no_weak_imports?
|
|
|
|
config.include?("w")
|
|
|
|
end
|
|
|
|
|
2014-04-20 19:57:01 -05:00
|
|
|
def canonical_path(path)
|
|
|
|
path = Pathname.new(path)
|
|
|
|
path = path.realpath if path.exist?
|
|
|
|
path.to_s
|
|
|
|
end
|
2014-04-21 00:17:22 -05:00
|
|
|
|
2014-04-20 19:54:32 -05:00
|
|
|
def path_flags(prefix, paths)
|
|
|
|
paths = paths.uniq.select { |path| File.directory?(path) }
|
|
|
|
paths.map! { |path| prefix + path }
|
|
|
|
end
|
2014-04-21 00:17:22 -05:00
|
|
|
|
2020-11-05 17:17:03 -05:00
|
|
|
# Unlike {path_flags}, do not prune non-existent directories.
|
|
|
|
# `formula.lib` for example does not yet exist, but should not be pruned.
|
2018-05-28 11:54:16 -07:00
|
|
|
def rpath_flags(prefix, paths)
|
|
|
|
paths.uniq.map { |path| prefix + path }
|
|
|
|
end
|
|
|
|
|
2014-04-20 22:39:47 -05:00
|
|
|
def path_split(key)
|
2021-01-08 12:15:55 -08:00
|
|
|
ENV.fetch(key, "").split(File::PATH_SEPARATOR)
|
2014-04-20 22:39:47 -05:00
|
|
|
end
|
2014-04-21 00:17:22 -05:00
|
|
|
|
2014-04-20 22:39:47 -05:00
|
|
|
def chuzzle(val)
|
|
|
|
return val if val.nil?
|
2021-01-08 12:15:55 -08:00
|
|
|
|
2014-04-20 22:39:47 -05:00
|
|
|
val = val.chomp
|
|
|
|
return val unless val.empty?
|
|
|
|
end
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
end
|
|
|
|
|
2015-02-10 20:27:26 -05:00
|
|
|
def log(basename, argv, tool, args)
|
|
|
|
return unless ENV.key?("HOMEBREW_CC_LOG_PATH")
|
|
|
|
|
|
|
|
adds = args - argv
|
|
|
|
dels = argv - args
|
|
|
|
|
2019-04-18 17:33:02 +09:00
|
|
|
s = +""
|
2015-02-10 20:27:26 -05:00
|
|
|
s << "#{basename} called with: #{argv.join(" ")}\n"
|
|
|
|
s << "superenv removed: #{dels.join(" ")}\n" unless dels.empty?
|
|
|
|
s << "superenv added: #{adds.join(" ")}\n" unless adds.empty?
|
|
|
|
s << "superenv executed: #{tool} #{args.join(" ")}\n\n"
|
|
|
|
File.open("#{ENV["HOMEBREW_CC_LOG_PATH"]}.cc", "a+") { |f| f.write(s) }
|
|
|
|
end
|
|
|
|
|
2018-05-28 11:54:16 -07:00
|
|
|
def remove_superbin_from_path(paths)
|
|
|
|
superbin = Pathname.new(__FILE__).dirname.realpath
|
|
|
|
paths.reject do |x|
|
|
|
|
path = Pathname.new(x)
|
|
|
|
path.directory? && path.realpath == superbin
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-03-03 22:11:26 -06:00
|
|
|
if __FILE__ == $PROGRAM_NAME
|
|
|
|
##################################################################### sanity
|
superenv: build-environments that just work
1. A minimal build environment, we don't set CFLAGS, CPPFLAGS, LDFLAGS, etc. the rationale being, the less that is set, the less variables we are introducing that can break builds.
2. A set of scripts that replace cc, ld, etc. and inject the -I, -L, etc. flags we need into the args passed to the build-tools.
Because we now have complete control over compiler instantiations we do a variety of clean-up tasks, like removing bad flags, enforcing universal builds and ensuring makefiles don't try to change the order of library and include paths from ones that work to ones that don't.
The previous ENV-system is still available when --env=std is specified.
superenv applies to Xcode >= 4.3 only currently.
2012-08-11 12:30:51 -04:00
|
|
|
|
2014-04-20 22:39:47 -05:00
|
|
|
if (cc = ENV["HOMEBREW_CC"]).nil? || cc.empty? || cc == "cc"
|
2013-03-03 22:11:26 -06:00
|
|
|
# those values are not allowed
|
2015-08-03 13:09:07 +01:00
|
|
|
ENV["HOMEBREW_CC"] = "clang"
|
2013-03-03 22:11:26 -06:00
|
|
|
end
|
2012-09-03 11:56:29 -04:00
|
|
|
|
2013-03-03 22:11:26 -06:00
|
|
|
####################################################################### main
|
2013-11-17 11:53:55 -06:00
|
|
|
|
2021-01-08 12:15:55 -08:00
|
|
|
dirname, basename = File.split($PROGRAM_NAME)
|
2013-11-17 11:53:55 -06:00
|
|
|
|
2015-02-12 19:13:03 -05:00
|
|
|
cmd = Cmd.new(basename, ARGV)
|
2015-08-03 13:09:07 +01:00
|
|
|
tool = cmd.tool
|
|
|
|
args = cmd.args
|
2013-11-17 11:53:55 -06:00
|
|
|
|
2015-02-10 20:27:26 -05:00
|
|
|
log(basename, ARGV, tool, args)
|
2013-11-17 11:53:55 -06:00
|
|
|
|
2021-01-08 12:15:55 -08:00
|
|
|
args << { close_others: false }
|
2018-05-28 11:54:16 -07:00
|
|
|
if mac?
|
|
|
|
exec "#{dirname}/xcrun", tool, *args
|
|
|
|
else
|
|
|
|
paths = ENV["PATH"].split(":")
|
|
|
|
paths = remove_superbin_from_path(paths)
|
|
|
|
paths.unshift "#{ENV["HOMEBREW_PREFIX"]}/bin"
|
|
|
|
ENV["PATH"] = paths.join(":")
|
|
|
|
exec tool, *args
|
|
|
|
end
|
2013-03-03 22:11:26 -06:00
|
|
|
end
|