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
|
|
|
|
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
|
|
|
#TODO make it work with homebrew/dupes/gcc
|
|
|
|
|
#TODO? If we find -mmacosx-version-min=10.8, change sdkroot? warn visibly if no such SDK?
|
|
|
|
|
#TODO fix pkg-config files, should point to /usr/local or /usr/local/opt
|
|
|
|
|
#TODO create mechanism to specify build effects like %w{-O0 -O4 vanilla-arg-parsing sdk=10.6} etc.
|
|
|
|
|
|
|
|
|
|
require "#{File.dirname __FILE__}/../libsuperenv"
|
|
|
|
|
require 'set'
|
|
|
|
|
|
|
|
|
|
def cccfg? flags
|
|
|
|
|
flags.split('').all?{|c| ENV['HOMEBREW_CCCFG'].include? c } if ENV['HOMEBREW_CCCFG']
|
|
|
|
|
end
|
|
|
|
|
def nclt?
|
|
|
|
|
$sdkroot != nil
|
|
|
|
|
end
|
|
|
|
|
def cmake_prefixes
|
|
|
|
|
@prefixes ||= ENV['CMAKE_PREFIX_PATH'].split(':').reject do |path|
|
|
|
|
|
case path
|
|
|
|
|
when '/usr', '/', "#$sdkroot/usr" then true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
class Cmd
|
|
|
|
|
def initialize path, args
|
2012-08-31 09:18:05 -04:00
|
|
|
@arg0 = path.basename.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
|
|
|
|
|
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'
|
|
|
|
|
:cc
|
|
|
|
|
elsif @args.include? '-E'
|
|
|
|
|
:cpp
|
|
|
|
|
else
|
|
|
|
|
:ccld
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
def tool
|
2012-09-03 11:56:29 -04:00
|
|
|
@tool ||= case @arg0
|
|
|
|
|
when 'ld' then 'ld'
|
|
|
|
|
when 'cc' then ENV['HOMEBREW_CC']
|
|
|
|
|
when 'c++'
|
|
|
|
|
if ENV['HOMEBREW_CC'] =~ /gcc/
|
2012-08-30 10:03:26 -04:00
|
|
|
'g++'
|
|
|
|
|
else
|
|
|
|
|
'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
|
|
|
end
|
|
|
|
|
else
|
2012-09-03 11:56:29 -04:00
|
|
|
@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
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
def args
|
2012-09-03 11:56:29 -04:00
|
|
|
args = if not cccfg? 'O' or tool == 'ld'
|
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.dup
|
2012-08-31 09:18:05 -04:00
|
|
|
else
|
|
|
|
|
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'
|
2012-08-30 10:03:26 -04:00
|
|
|
args.unshift("--sysroot=#$sdkroot")
|
|
|
|
|
else
|
|
|
|
|
args.unshift($sdkroot).unshift("-syslibroot")
|
|
|
|
|
end if nclt?
|
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
|
|
|
case mode
|
|
|
|
|
when :cpp
|
|
|
|
|
%w{-E} + cppflags + args
|
|
|
|
|
when :ld
|
|
|
|
|
ldflags + args
|
|
|
|
|
when :cc
|
|
|
|
|
cflags + cppflags + args
|
|
|
|
|
when :ccld
|
|
|
|
|
cflags + cppflags + ldflags + args
|
|
|
|
|
end.compact
|
|
|
|
|
end
|
|
|
|
|
def refurbished_args
|
|
|
|
|
iset = Set.new(cmake_prefixes.map{|prefix| "#{prefix}/include" })
|
|
|
|
|
lset = Set.new
|
|
|
|
|
args = []
|
|
|
|
|
whittler = @args.each
|
|
|
|
|
loop do
|
|
|
|
|
case arg = whittler.next
|
|
|
|
|
when '-arch', /^-Xarch_/
|
|
|
|
|
whittler.next
|
|
|
|
|
when /^-g\d?/, /^-gstabs\d+/, '-gstabs+', /^-ggdb\d?/, '-gdwarf-2',
|
|
|
|
|
/^-march=.+/, /^-mtune=.+/, '-m64', '-m32',
|
2012-08-31 10:20:30 -04:00
|
|
|
/^-O[0-9zs]?/, '-fast',
|
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
|
|
|
%r{^-[IL]/opt/local}, %r{^-[IL]/sw}, # no macports/fink
|
|
|
|
|
%r{^-[IL]/usr/X11}, %r{^-[IL]/opt/X11}, # we add X11 ourselves
|
|
|
|
|
'-pedantic', '-pedantic-errors'
|
2012-09-02 11:44:23 -04:00
|
|
|
when '-fopenmp', '-lgomp'
|
|
|
|
|
# clang doesn't support OpenMP
|
|
|
|
|
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.*/
|
|
|
|
|
args << arg if arg =~ /^-Wl,/
|
2012-08-29 22:37:57 -04:00
|
|
|
when '-macosx_version_min', '-dylib_install_name'
|
|
|
|
|
args << "-Wl,#{arg},#{whittler.next}"
|
|
|
|
|
when '-dylib'
|
|
|
|
|
args << "-Wl,#{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
|
|
|
when /^-I(.+)/
|
|
|
|
|
# it is okay to add a space after the -I; so let's support it
|
|
|
|
|
path = $1.chuzzle || whittler.next
|
|
|
|
|
args << "-I#{path}" if iset.add?(path.cleanpath)
|
|
|
|
|
when /^-l(.+)/
|
|
|
|
|
lib = $1.chuzzle || whittler.next
|
|
|
|
|
args << "-l#{lib}" if lset.add?(lib)
|
|
|
|
|
else
|
|
|
|
|
args << arg
|
|
|
|
|
end
|
|
|
|
|
end
|
2012-08-30 10:03:26 -04:00
|
|
|
make_fuss(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
|
|
|
args
|
|
|
|
|
end
|
|
|
|
|
def cflags
|
|
|
|
|
if cccfg? 'Ob'
|
|
|
|
|
%w{-mtune=generic -Oz}
|
|
|
|
|
elsif cccfg? 'O'
|
|
|
|
|
u = '-arch i386 -arch x86_64' if cccfg? 'u'
|
|
|
|
|
c = case tool when 'clang', 'clang++' then '-march=native' end
|
|
|
|
|
%w{-pipe -w -Os} << u << c
|
|
|
|
|
else
|
|
|
|
|
[]
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
def ldflags
|
2012-08-31 14:12:03 -04:00
|
|
|
libs = cmake_prefixes.map{|prefix| "#{prefix}/lib" }
|
|
|
|
|
libs += ENV['CMAKE_LIBRARY_PATH'].split(':')
|
|
|
|
|
libs.to_flags('-L')
|
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
|
|
|
|
|
all = cmake_prefixes.map{|prefix| "#{prefix}/include" }
|
2012-09-03 13:24:38 -04:00
|
|
|
# we need to do this for cppflags and not ldflags as here we use -isystem
|
|
|
|
|
# but with ld we can only set -L.
|
|
|
|
|
all.delete('/usr/local') unless nclt?
|
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
|
|
|
opt = all.select{|prefix| prefix =~ %r{^#$brewfix/opt} }
|
|
|
|
|
sys = all - opt + ENV['CMAKE_INCLUDE_PATH'].split(':')
|
|
|
|
|
# we want our keg-only includes to be found before system includes so that
|
|
|
|
|
# they override the system options.
|
|
|
|
|
sys.to_flags('-isystem') + opt.to_flags('-I')
|
|
|
|
|
end
|
2012-08-30 10:03:26 -04:00
|
|
|
def make_fuss args
|
|
|
|
|
dels = @args - args
|
2012-08-31 12:06:20 -04:00
|
|
|
adds = args - @args
|
|
|
|
|
puts "brew: Superenv removed: #{dels*' '}" unless dels.empty?
|
|
|
|
|
puts "brew: Superenv added: #{adds*' '}" unless adds.empty?
|
2012-08-30 10:03:26 -04: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
|
|
|
|
|
|
|
|
|
|
####################################################################### sanity
|
2012-08-31 09:18:05 -04:00
|
|
|
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
|
|
|
|
2012-09-03 11:56:29 -04:00
|
|
|
case ENV['HOMEBREW_CC'].chuzzle when 'cc', nil
|
|
|
|
|
# those values are not allowed
|
|
|
|
|
ENV['HOMEBREW_CC'] = 'clang'
|
|
|
|
|
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
|
|
|
######################################################################### main
|
|
|
|
|
cmd = Cmd.new($0, ARGV)
|
|
|
|
|
exec "xcrun", cmd.tool, *cmd.args
|