2012-08-30 09:55:33 -04:00
|
|
|
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby -W0
|
2012-09-03 11:56:29 -04:00
|
|
|
|
2014-04-20 18:00:29 -05:00
|
|
|
require File.expand_path("../libsuperenv", File.dirname(__FILE__))
|
2014-04-20 19:57:01 -05:00
|
|
|
require 'pathname'
|
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
|
|
|
require 'set'
|
2013-11-17 11:53:55 -06:00
|
|
|
require 'stringio'
|
|
|
|
|
|
|
|
class Logger
|
|
|
|
def initialize
|
|
|
|
@io = StringIO.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def puts(*args)
|
|
|
|
@io.puts(*args)
|
|
|
|
end
|
|
|
|
|
|
|
|
def log!
|
|
|
|
return unless ENV.key? 'HOMEBREW_CC_LOG_PATH'
|
|
|
|
path = "#{ENV['HOMEBREW_CC_LOG_PATH']}.cc"
|
|
|
|
|
|
|
|
puts
|
|
|
|
File.open(path, File::WRONLY | File::APPEND | File::CREAT) { |f| f.write(@io.string) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
LOGGER = Logger.new
|
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
|
2013-12-27 13:01:41 -06:00
|
|
|
attr_reader :brewfix, :brewtmp, :sdkroot
|
2013-11-21 14:50:35 -06: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 initialize path, args
|
2013-11-21 14:50:35 -06:00
|
|
|
@arg0 = File.basename(path).freeze
|
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
|
2013-11-21 14:50:35 -06:00
|
|
|
@brewfix = ENV['HOMEBREW_PREFIX']
|
2013-12-27 13:01:41 -06:00
|
|
|
@brewtmp = ENV['HOMEBREW_TEMP']
|
2013-11-21 14:50:35 -06:00
|
|
|
@sdkroot = ENV['HOMEBREW_SDKROOT']
|
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
|
|
|
|
def mode
|
2012-08-31 09:18:05 -04:00
|
|
|
if @arg0 == 'cpp' or @arg0 == 'ld'
|
|
|
|
@arg0.to_sym
|
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
|
|
|
elsif @args.include? '-c'
|
2013-10-07 00:40:32 -07:00
|
|
|
if @arg0 =~ /(?:c|g|clang)\+\+/
|
|
|
|
:cxx
|
|
|
|
else
|
|
|
|
: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
|
|
|
elsif @args.include? '-E'
|
2013-08-31 10:43:23 -05:00
|
|
|
:ccE
|
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
|
2013-10-07 00:40:32 -07:00
|
|
|
if @arg0 =~ /(?:c|g|clang)\+\+/
|
|
|
|
:cxxld
|
|
|
|
else
|
|
|
|
:ccld
|
|
|
|
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
|
|
|
|
def tool
|
2012-09-03 11:56:29 -04:00
|
|
|
@tool ||= case @arg0
|
|
|
|
when 'ld' then 'ld'
|
2013-08-27 18:31:57 -07:00
|
|
|
when 'cpp' then 'cpp'
|
2013-11-08 16:32:48 -08:00
|
|
|
when /\w\+\+(-\d\.\d)?$/
|
2013-05-27 12:54:07 -05:00
|
|
|
case ENV['HOMEBREW_CC']
|
|
|
|
when /clang/
|
|
|
|
'clang++'
|
|
|
|
when /llvm-gcc/
|
2013-06-27 14:56:47 -05:00
|
|
|
'llvm-g++-4.2'
|
2013-06-04 10:18:14 -05:00
|
|
|
when /gcc(-\d\.\d)?$/
|
|
|
|
'g++' + $1.to_s
|
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.
|
|
|
|
ENV['HOMEBREW_CC']
|
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
|
|
|
|
def args
|
2014-03-25 08:15:31 +00:00
|
|
|
if @args.length == 1 and @args[0] == '-v'
|
|
|
|
# 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
|
2014-02-28 20:37:33 -06:00
|
|
|
if !cccfg?("O") || tool == "ld" || configure?
|
|
|
|
args = @args.dup
|
2012-08-31 09:18:05 -04:00
|
|
|
else
|
2014-02-28 20:37:33 -06:00
|
|
|
args = 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
|
2012-08-31 09:18:05 -04:00
|
|
|
if tool != 'ld'
|
2013-11-21 14:50:35 -06:00
|
|
|
args << "--sysroot=#{sdkroot}"
|
2012-08-30 10:03:26 -04:00
|
|
|
else
|
2013-11-21 14:50:35 -06:00
|
|
|
args << "-syslibroot" << sdkroot
|
2012-08-30 10:03:26 -04:00
|
|
|
end if nclt?
|
2013-10-12 05:23:06 -07:00
|
|
|
allflags = 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
|
|
|
|
end.compact
|
2013-11-04 11:02:12 -06:00
|
|
|
make_fuss(allflags)
|
2013-10-12 05:23:06 -07:00
|
|
|
allflags
|
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
|
|
|
|
def refurbished_args
|
2012-09-14 11:55:21 -04:00
|
|
|
lset = Set.new(libpath + syslibpath)
|
|
|
|
iset = Set.new(cpath.flatten)
|
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 = []
|
|
|
|
whittler = @args.each
|
|
|
|
loop do
|
|
|
|
case arg = whittler.next
|
|
|
|
when '-arch', /^-Xarch_/
|
|
|
|
whittler.next
|
2012-12-01 19:42:22 +01:00
|
|
|
when '-m32'
|
|
|
|
# If ENV.m32 was set, we allow the "-m32" flag, but we don't add anything
|
|
|
|
args << '-m32' if cccfg? '3'
|
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 /^-g\d?/, /^-gstabs\d+/, '-gstabs+', /^-ggdb\d?/, '-gdwarf-2',
|
2013-08-28 20:01:58 -07:00
|
|
|
/^-march=.+/, /^-mtune=.+/, /^-mcpu=.+/, '-m64',
|
2013-11-20 15:01:02 -06:00
|
|
|
/^-O[0-9zs]?$/, '-fast', '-no-cpp-precomp',
|
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
|
|
|
'-pedantic', '-pedantic-errors'
|
2014-03-20 23:16:06 -05:00
|
|
|
when '-fopenmp', '-lgomp', '-mno-fused-madd', '-fforce-addr', '-fno-defer-pop',
|
|
|
|
'-mno-dynamic-no-pic', '-fearly-inlining', '-finline-functions-called-once',
|
2014-03-28 14:49:45 -05:00
|
|
|
/^-finline-limit/, /^-f(?:no-)?check-new/, '-fno-delete-null-pointer-checks',
|
2014-04-11 12:29:15 -05:00
|
|
|
'-fcaller-saves', '-fthread-jumps', '-fno-reorder-blocks'
|
2014-03-14 16:46:56 +00:00
|
|
|
# clang doesn't support these flags
|
2012-09-02 11:44:23 -04:00
|
|
|
args << arg if not tool =~ /^clang/
|
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 /^-W.*/
|
2013-11-21 16:44:10 -06:00
|
|
|
args << arg if arg =~ /^-W[alp],/ or arg =~ /^-Wno-/
|
2012-08-29 22:37:57 -04:00
|
|
|
when '-macosx_version_min', '-dylib_install_name'
|
|
|
|
args << "-Wl,#{arg},#{whittler.next}"
|
2014-03-21 13:00:15 -05:00
|
|
|
when '-multiply_definedsuppress'
|
|
|
|
args << "-Wl,-multiply_defined,suppress"
|
|
|
|
when '-undefineddynamic_lookup'
|
|
|
|
args << "-Wl,-undefined,dynamic_lookup"
|
2012-12-14 19:03:12 +01:00
|
|
|
when /^-isysroot/
|
|
|
|
# We set the sysroot
|
|
|
|
whittler.next
|
2012-08-29 22:37:57 -04:00
|
|
|
when '-dylib'
|
|
|
|
args << "-Wl,#{arg}"
|
2013-11-26 21:39:38 -06:00
|
|
|
when /^-I(.+)?/
|
|
|
|
# Support both "-Ifoo" (one argument) and "-I foo" (two arguments)
|
2014-04-20 20:13:53 -05:00
|
|
|
val = $1.chuzzle || whittler.next
|
|
|
|
path = canonical_path(val)
|
|
|
|
args << "-I#{val}" if keep?(path) and iset.add?(path)
|
2013-11-26 21:39:38 -06:00
|
|
|
when /^-L(.+)?/
|
2014-04-20 20:13:53 -05:00
|
|
|
val = $1.chuzzle || whittler.next
|
|
|
|
path = canonical_path(val)
|
|
|
|
args << "-L#{val}" if keep?(path) and lset.add?(path)
|
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
|
|
|
|
args << arg
|
|
|
|
end
|
|
|
|
end
|
|
|
|
args
|
|
|
|
end
|
2013-12-27 15:46:36 -06:00
|
|
|
|
|
|
|
def keep? path
|
2014-04-20 19:57:01 -05:00
|
|
|
case path
|
2013-12-27 15:46:36 -06:00
|
|
|
when %r{^#{Regexp.escape(brewfix)}}, %r{^#{Regexp.escape(brewtmp)}}
|
|
|
|
# maybe homebrew is installed to /sw or /opt/brew
|
|
|
|
true
|
|
|
|
when %r{^/opt}, %r{^/sw}, %r{/usr/X11}
|
|
|
|
false
|
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
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 = []
|
|
|
|
|
2013-11-11 12:14:23 -06:00
|
|
|
return args unless cccfg? 'O' or configure?
|
|
|
|
|
2013-11-10 18:24:49 -06:00
|
|
|
args << '-pipe'
|
|
|
|
args << '-w' unless configure?
|
2013-11-12 12:00:18 -06:00
|
|
|
args.concat(optflags)
|
|
|
|
args.concat(archflags)
|
|
|
|
args << "-std=#{@arg0}" if @arg0 =~ /c[89]9/
|
|
|
|
args
|
|
|
|
end
|
|
|
|
def cxxflags
|
|
|
|
args = cflags
|
|
|
|
args << '-std=c++11' if cccfg? 'x'
|
|
|
|
args << '-stdlib=libc++' if cccfg? 'g'
|
|
|
|
args << '-stdlib=libstdc++' if cccfg? 'h'
|
|
|
|
args
|
|
|
|
end
|
|
|
|
def optflags
|
|
|
|
args = []
|
2013-11-12 12:00:18 -06:00
|
|
|
args << "-#{ENV['HOMEBREW_OPTIMIZATION_LEVEL']}"
|
2013-11-20 12:54:34 -06:00
|
|
|
args.concat ENV['HOMEBREW_OPTFLAGS'].split(' ') if ENV['HOMEBREW_OPTFLAGS']
|
2013-11-10 18:24:49 -06:00
|
|
|
args
|
|
|
|
end
|
2013-11-12 12:00:17 -06:00
|
|
|
def archflags
|
|
|
|
args = []
|
2013-11-20 12:54:34 -06:00
|
|
|
args.concat ENV['HOMEBREW_ARCHFLAGS'].split(' ') if cccfg? 'u'
|
2013-11-12 12:00:17 -06:00
|
|
|
args
|
|
|
|
end
|
2013-11-21 14:50:35 -06:00
|
|
|
def syspath
|
|
|
|
if nclt?
|
2013-11-21 14:50:35 -06:00
|
|
|
%W{#{sdkroot}/usr #{sdkroot}/usr/local}
|
2013-11-21 14:50:35 -06:00
|
|
|
else
|
|
|
|
%W{/usr /usr/local}
|
|
|
|
end
|
|
|
|
end
|
2012-09-03 14:34:42 -04:00
|
|
|
def syslibpath
|
|
|
|
# We reject brew's lib as we explicitly add this as a -L flag, thus it
|
|
|
|
# is given higher priority by cc, so it surpasses the system libpath.
|
|
|
|
# NOTE this only counts if Homebrew is installed at /usr/local
|
2013-11-21 14:50:35 -06:00
|
|
|
syspath.map{|d| "#{d}/lib" }.reject{|d| d == "#{brewfix}/lib" }
|
2012-09-03 14:34:42 -04:00
|
|
|
end
|
|
|
|
def cpath
|
|
|
|
cpath = ENV['CMAKE_PREFIX_PATH'].split(':').map{|d| "#{d}/include" } + ENV['CMAKE_INCLUDE_PATH'].split(':')
|
2013-12-27 13:01:41 -06:00
|
|
|
opt = cpath.grep(%r{^#{Regexp.escape(brewfix)}/opt})
|
2012-09-03 14:34:42 -04:00
|
|
|
sys = cpath - opt
|
|
|
|
[sys, opt]
|
|
|
|
end
|
|
|
|
def libpath
|
|
|
|
ENV['CMAKE_PREFIX_PATH'].split(':').map{|d| "#{d}/lib" } +
|
|
|
|
ENV['CMAKE_LIBRARY_PATH'].split(':') -
|
|
|
|
syslibpath
|
|
|
|
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 ldflags
|
2014-04-20 19:54:32 -05:00
|
|
|
args = path_flags("-L", libpath)
|
2013-08-23 11:36:03 -05:00
|
|
|
case mode
|
|
|
|
when :ld then args << '-headerpad_max_install_names'
|
|
|
|
when :ccld then args << '-Wl,-headerpad_max_install_names'
|
2013-10-07 00:40:32 -07:00
|
|
|
when :cxxld
|
|
|
|
args << '-Wl,-headerpad_max_install_names'
|
|
|
|
args << '-stdlib=libc++' if cccfg? 'g'
|
2013-10-24 00:26:09 -07:00
|
|
|
args << '-stdlib=libstdc++' if cccfg? 'h'
|
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
|
|
|
|
def cppflags
|
2012-09-03 14:34:42 -04:00
|
|
|
sys, opt = cpath
|
|
|
|
# we want our keg-only includes to be found before system includes *and*
|
|
|
|
# before any other includes the build-system adds
|
2014-04-20 19:54:32 -05:00
|
|
|
path_flags("-isystem", sys) + path_flags("-I", opt)
|
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
|
2012-08-30 10:03:26 -04:00
|
|
|
def make_fuss args
|
2013-11-04 11:02:12 -06:00
|
|
|
return unless make_fuss?
|
|
|
|
|
2012-08-30 10:03:26 -04:00
|
|
|
dels = @args - args
|
2012-08-31 12:06:20 -04:00
|
|
|
adds = args - @args
|
2012-09-13 11:28:06 -04:00
|
|
|
dups = dels & args
|
2012-09-11 20:59:59 -04:00
|
|
|
|
2013-11-17 11:53:55 -06:00
|
|
|
LOGGER.puts "superenv removed: #{dels*' '}" unless dels.empty?
|
|
|
|
LOGGER.puts "superenv deduped: #{dups}" unless dups.empty?
|
|
|
|
LOGGER.puts "superenv added: #{adds*' '}" unless adds.empty?
|
2012-08-30 10:03:26 -04:00
|
|
|
end
|
2013-11-04 11:02:12 -06:00
|
|
|
def make_fuss?
|
2013-11-17 19:09:24 -06:00
|
|
|
cccfg? 'O' and not configure?
|
2013-10-12 05:23:06 -07:00
|
|
|
end
|
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
|
|
|
|
ENV.key? 'as_nl'
|
2013-11-04 11:02:12 -06:00
|
|
|
end
|
2013-11-21 14:50:35 -06:00
|
|
|
def nclt?
|
2013-11-21 14:50:35 -06:00
|
|
|
sdkroot != nil
|
2013-11-21 14:50:35 -06:00
|
|
|
end
|
|
|
|
def cccfg? flags
|
|
|
|
flags.split('').all?{|c| ENV['HOMEBREW_CCCFG'].include? c } if ENV['HOMEBREW_CCCFG']
|
|
|
|
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-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
|
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
|
|
|
|
|
2013-03-03 22:11:26 -06:00
|
|
|
if __FILE__ == $PROGRAM_NAME
|
|
|
|
##################################################################### sanity
|
|
|
|
abort "The build-tool has reset ENV. --env=std required." unless ENV['HOMEBREW_BREW_FILE']
|
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
|
|
|
|
2013-03-03 22:11:26 -06:00
|
|
|
case ENV['HOMEBREW_CC'].chuzzle when 'cc', nil
|
|
|
|
# those values are not allowed
|
|
|
|
ENV['HOMEBREW_CC'] = 'clang'
|
|
|
|
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
|
|
|
|
|
|
|
LOGGER.puts "#{File.basename($0)} called with: #{ARGV.join(" ")}"
|
|
|
|
|
2013-03-03 22:11:26 -06:00
|
|
|
cmd = Cmd.new($0, ARGV)
|
2013-11-17 11:53:55 -06:00
|
|
|
tool, args = cmd.tool, cmd.args
|
|
|
|
|
|
|
|
LOGGER.puts "superenv executed: #{tool} #{args.join(" ")}"
|
|
|
|
LOGGER.log!
|
|
|
|
|
|
|
|
exec "xcrun", tool, *args
|
2013-03-03 22:11:26 -06:00
|
|
|
end
|