aboutsummaryrefslogtreecommitdiffstats
path: root/Library/ENV
diff options
context:
space:
mode:
authorMax Howell2012-08-11 12:30:51 -0400
committerMax Howell2012-08-29 12:41:34 -0400
commit65d195dcaaa4304e127e0a264cf97ad7b6a7fd83 (patch)
tree7b8a04d1bdb8676e5e8b978da9824365edac9bae /Library/ENV
parent57df15afd009d11e8d683353a74287e0a22ba57b (diff)
downloadbrew-65d195dcaaa4304e127e0a264cf97ad7b6a7fd83.tar.bz2
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.
Diffstat (limited to 'Library/ENV')
l---------Library/ENV/4.3/c++1
-rwxr-xr-xLibrary/ENV/4.3/cc140
l---------Library/ENV/4.3/clang1
l---------Library/ENV/4.3/clang++1
l---------Library/ENV/4.3/cpp1
l---------Library/ENV/4.3/g++1
l---------Library/ENV/4.3/gcc1
l---------Library/ENV/4.3/i686-apple-darwin11-llvm-g++-4.21
l---------Library/ENV/4.3/i686-apple-darwin11-llvm-gcc-4.21
l---------Library/ENV/4.3/ld1
l---------Library/ENV/4.3/llvm-g++1
l---------Library/ENV/4.3/llvm-g++-4.21
l---------Library/ENV/4.3/llvm-gcc1
l---------Library/ENV/4.3/llvm-gcc-4.21
-rwxr-xr-xLibrary/ENV/4.3/xcrun12
-rw-r--r--Library/ENV/libsuperenv.rb41
16 files changed, 206 insertions, 0 deletions
diff --git a/Library/ENV/4.3/c++ b/Library/ENV/4.3/c++
new file mode 120000
index 000000000..2652f5f42
--- /dev/null
+++ b/Library/ENV/4.3/c++
@@ -0,0 +1 @@
+cc \ No newline at end of file
diff --git a/Library/ENV/4.3/cc b/Library/ENV/4.3/cc
new file mode 100755
index 000000000..8673c7527
--- /dev/null
+++ b/Library/ENV/4.3/cc
@@ -0,0 +1,140 @@
+#!/usr/bin/ruby -W0
+#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 for easier to understand code, don't monkey-patch ENV, just set via a hash from a helper class
+#TODO create mechanism to specify build effects like %w{-O0 -O4 vanilla-arg-parsing sdk=10.6} etc.
+#TODO DSL for lame-env (and rename to typical-env or something better)
+#TODO consider always setting CC to cc and instead having HOMEBREW_CC to force cc choice in end toolchain
+# in verbose mode print out things like "gcc called, but redirecting to clang" if that happens
+#TODO `brew sh`: https://github.com/mxcl/homebrew/issues/14381#issuecomment-8017538
+
+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/local' then !nclt?
+ when '/usr', '/', "#$sdkroot/usr" then true
+ end
+ end
+end
+
+class Cmd
+ def initialize path, args
+ @cmd = path.basename.freeze
+ @args = args.freeze
+ end
+ def mode
+ if @cmd == 'cpp' or @cmd == 'ld'
+ @cmd.to_sym
+ elsif @args.include? '-c'
+ :cc
+ elsif @args.include? '-E'
+ :cpp
+ else
+ :ccld
+ end
+ end
+ def tool
+ case @cmd
+ when /gcc/ then 'gcc'
+ when /g\+\+/ then 'g++'
+ when 'clang', 'clang++'
+ @cmd
+ when 'ld', 'cpp', 'cc'
+ ENV['HOMEBREW_CC'].chuzzle or 'clang'
+ when 'c++'
+ case ENV['HOMEBREW_CC']
+ when /gcc/ then 'g++'
+ else 'clang++'
+ end
+ else
+ abort "Unknown command: #{@cmd}"
+ end
+ end
+ def args
+ args = if cccfg? 'O'
+ refurbished_args
+ else
+ @args.dup
+ end
+ args.unshift("--sysroot=#$sdkroot") if nclt?
+ 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',
+ /^-O[0-9zs]/, '-fast',
+ %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'
+ when /^-W.*/
+ args << arg if arg =~ /^-Wl,/
+ 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
+ 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
+ cmake_prefixes.map{|prefix| "#{prefix}/lib" }.to_flags('-L')
+ end
+ def cppflags
+ all = cmake_prefixes.map{|prefix| "#{prefix}/include" }
+ 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
+end
+
+####################################################################### sanity
+abort "The build-tool has reset ENV. --lame-env required." unless ENV['HOMEBREW_BREW_FILE']
+
+######################################################################### main
+cmd = Cmd.new($0, ARGV)
+exec "xcrun", cmd.tool, *cmd.args
diff --git a/Library/ENV/4.3/clang b/Library/ENV/4.3/clang
new file mode 120000
index 000000000..2652f5f42
--- /dev/null
+++ b/Library/ENV/4.3/clang
@@ -0,0 +1 @@
+cc \ No newline at end of file
diff --git a/Library/ENV/4.3/clang++ b/Library/ENV/4.3/clang++
new file mode 120000
index 000000000..2652f5f42
--- /dev/null
+++ b/Library/ENV/4.3/clang++
@@ -0,0 +1 @@
+cc \ No newline at end of file
diff --git a/Library/ENV/4.3/cpp b/Library/ENV/4.3/cpp
new file mode 120000
index 000000000..2652f5f42
--- /dev/null
+++ b/Library/ENV/4.3/cpp
@@ -0,0 +1 @@
+cc \ No newline at end of file
diff --git a/Library/ENV/4.3/g++ b/Library/ENV/4.3/g++
new file mode 120000
index 000000000..2652f5f42
--- /dev/null
+++ b/Library/ENV/4.3/g++
@@ -0,0 +1 @@
+cc \ No newline at end of file
diff --git a/Library/ENV/4.3/gcc b/Library/ENV/4.3/gcc
new file mode 120000
index 000000000..2652f5f42
--- /dev/null
+++ b/Library/ENV/4.3/gcc
@@ -0,0 +1 @@
+cc \ No newline at end of file
diff --git a/Library/ENV/4.3/i686-apple-darwin11-llvm-g++-4.2 b/Library/ENV/4.3/i686-apple-darwin11-llvm-g++-4.2
new file mode 120000
index 000000000..2652f5f42
--- /dev/null
+++ b/Library/ENV/4.3/i686-apple-darwin11-llvm-g++-4.2
@@ -0,0 +1 @@
+cc \ No newline at end of file
diff --git a/Library/ENV/4.3/i686-apple-darwin11-llvm-gcc-4.2 b/Library/ENV/4.3/i686-apple-darwin11-llvm-gcc-4.2
new file mode 120000
index 000000000..2652f5f42
--- /dev/null
+++ b/Library/ENV/4.3/i686-apple-darwin11-llvm-gcc-4.2
@@ -0,0 +1 @@
+cc \ No newline at end of file
diff --git a/Library/ENV/4.3/ld b/Library/ENV/4.3/ld
new file mode 120000
index 000000000..2652f5f42
--- /dev/null
+++ b/Library/ENV/4.3/ld
@@ -0,0 +1 @@
+cc \ No newline at end of file
diff --git a/Library/ENV/4.3/llvm-g++ b/Library/ENV/4.3/llvm-g++
new file mode 120000
index 000000000..2652f5f42
--- /dev/null
+++ b/Library/ENV/4.3/llvm-g++
@@ -0,0 +1 @@
+cc \ No newline at end of file
diff --git a/Library/ENV/4.3/llvm-g++-4.2 b/Library/ENV/4.3/llvm-g++-4.2
new file mode 120000
index 000000000..2652f5f42
--- /dev/null
+++ b/Library/ENV/4.3/llvm-g++-4.2
@@ -0,0 +1 @@
+cc \ No newline at end of file
diff --git a/Library/ENV/4.3/llvm-gcc b/Library/ENV/4.3/llvm-gcc
new file mode 120000
index 000000000..2652f5f42
--- /dev/null
+++ b/Library/ENV/4.3/llvm-gcc
@@ -0,0 +1 @@
+cc \ No newline at end of file
diff --git a/Library/ENV/4.3/llvm-gcc-4.2 b/Library/ENV/4.3/llvm-gcc-4.2
new file mode 120000
index 000000000..2652f5f42
--- /dev/null
+++ b/Library/ENV/4.3/llvm-gcc-4.2
@@ -0,0 +1 @@
+cc \ No newline at end of file
diff --git a/Library/ENV/4.3/xcrun b/Library/ENV/4.3/xcrun
new file mode 100755
index 000000000..3d2dd642e
--- /dev/null
+++ b/Library/ENV/4.3/xcrun
@@ -0,0 +1,12 @@
+#!/bin/bash
+# This wrapper because 4.3 xcrun doesn't work with CLT-only configurations
+# But many build-systems expect it to work. This fixes that.
+# NOTE only works if they call xcrun without a full-path. Cross your fingers!
+
+if [ $HOMEBREW_SDKROOT ]; then
+ exec /usr/bin/xcrun "$@"
+else
+ cmd="$1"
+ shift
+ exec "/usr/bin/$cmd" "$@"
+fi
diff --git a/Library/ENV/libsuperenv.rb b/Library/ENV/libsuperenv.rb
new file mode 100644
index 000000000..dcd97efce
--- /dev/null
+++ b/Library/ENV/libsuperenv.rb
@@ -0,0 +1,41 @@
+# Yes, a good deal of this could be imported from Homebrew-proper
+# But Homebrew-proper is dog-slow currently, and I didn't want every cc
+# instantiation to be slower be a tangible amount.
+
+class String
+ def directory?; File.directory? self end
+ def basename; File.basename self end
+ def cleanpath; require 'pathname'; Pathname.new(self).realpath.to_s rescue self end
+ def chuzzle; s = chomp; s unless s.empty? end
+ def dirname; File.dirname(self) end
+end
+
+class NilClass
+ def chuzzle; end
+ def directory?; false end
+ def split(x); [] end
+end
+
+class Array
+ def to_flags prefix
+ select{|path| path.directory? }.uniq.map{|path| prefix+path }
+ end
+end
+
+module Kernel extend self
+ alias :_exec :exec
+ def exec *args
+ path = File.expand_path('~/Library/Logs/Homebrew/cc.log')
+ open(path, 'a') do |f|
+ f.print '[', $0
+ f.print " -%s" % ENV['HOMEBREW_CCCFG'] if ENV['HOMEBREW_CCCFG']
+ f.print '] '
+ f.puts args.join(' ')
+ f.puts
+ end
+ _exec *args
+ end
+end if ENV['HOMEBREW_LOG']
+
+$brewfix = "#{__FILE__}/../../../".cleanpath.freeze
+$sdkroot = ENV['HOMEBREW_SDKROOT'].freeze