Permalink
Browse files

Use clang as default compiler (⌘R and “Insert Missing Includes”)

Clang is called via ‘xcrun clang’ so it requires that you have Xcode installed.

If you wish to use another compiler you can set ‘TM_GCC’ and ‘TM_GXX’ for C/Objective-C and C++/Objective-C++ respectively. This variable is no longer being “shell escaped” (which is what allows setting it to something like ‘xcrun clang’).
  • Loading branch information...
sorbits committed Mar 24, 2013
1 parent 8da9232 commit 020edc60e128ffef96ca6b489b69c7adf01e88c8
Showing with 16 additions and 11 deletions.
  1. +7 −5 Commands/Run.tmCommand
  2. +5 −2 Support/bin/bootstrap.sh
  3. +4 −4 Support/bin/headers
View
@@ -11,20 +11,22 @@
require "#{ENV['TM_SUPPORT_PATH']}/lib/tm/executor"
require "#{ENV['TM_SUPPORT_PATH']}/lib/tm/save_current_document"
+require "shellwords"
CONFIG = {
- 'source.c' => [ ENV['TM_GCC'] || 'gcc', "-x c #{ENV['TM_C_FLAGS'] || '-Wall -include stdio.h'}", 'c' ],
- 'source.c++' => [ ENV['TM_GXX'] || 'g++', "-x c++ #{ENV['TM_CXX_FLAGS'] || '-Wall -include stdio.h -include iostream'}", 'cc' ],
- 'source.objc' => [ ENV['TM_GCC'] || 'gcc', "-x objective-c #{ENV['TM_OBJC_FLAGS'] || '-Wall -include stdio.h -framework Cocoa'}", 'm' ],
- 'source.objc++' => [ ENV['TM_GXX'] || 'g++', "-x objective-c++ #{ENV['TM_OBJCXX_FLAGS'] || '-Wall -include stdio.h -include iostream -framework Cocoa'}", 'mm' ],
+ 'source.c' => [ ENV['TM_GCC'] || 'xcrun clang', "-x c #{ENV['TM_C_FLAGS'] || '-Wall -include stdio.h'}", 'c' ],
+ 'source.c++' => [ ENV['TM_GXX'] || 'xcrun clang++', "-x c++ #{ENV['TM_CXX_FLAGS'] || '-Wall -include stdio.h -include iostream'}", 'cc' ],
+ 'source.objc' => [ ENV['TM_GCC'] || 'xcrun clang', "-x objective-c #{ENV['TM_OBJC_FLAGS'] || '-Wall -include stdio.h -framework Cocoa'}", 'm' ],
+ 'source.objc++' => [ ENV['TM_GXX'] || 'xcrun clang++', "-x objective-c++ #{ENV['TM_OBJCXX_FLAGS'] || '-Wall -include stdio.h -include iostream -framework Cocoa'}", 'mm' ],
}
cc, flags, ext = *CONFIG['source.objc++'] # default
cc, flags, ext = *CONFIG[$&] if ENV["TM_SCOPE"] =~ /\bsource\.(obj)?c(\+\+)?/
TextMate.save_if_untitled(ext)
TextMate::Executor.make_project_master_current_document
-TextMate::Executor.run([ cc, flags, ENV["TM_FILEPATH"] ], :version_args => ["--version"], :version_regex => /\A([^\n]*) \(GCC\).*/m)
+args = Shellwords.split(cc) << Shellwords.split(flags) << ENV["TM_FILEPATH"]
+TextMate::Executor.run(args, :version_args => ["--version"], :version_regex => /\A([^\n]*) \(GCC\).*/m)
</string>
<key>input</key>
<string>document</string>
View
@@ -1,7 +1,10 @@
#!/bin/bash
-eval '"$1"' "$2" '"$3"' -o '"$3".out'
+A_OUT=$(mktemp -t "${TM_DISPLAYNAME:-untitled}")
+trap 'rm "$A_OUT"' EXIT
+
+"$@" -o "$A_OUT"
if [ $? -eq 0 ]; then
- "$3".out;
+ "$A_OUT"
fi
View
@@ -30,10 +30,10 @@ SYS_HEAD = Regexp.escape "#include <...> search starts here:\n"
FOOTER = Regexp.escape "End of search list."
CONFIG = {
- 'source.c' => "#{ENV['TM_GCC'] || 'gcc'} 2>&1 >/dev/null -E -v -x c #{ENV['TM_C_FLAGS']} /dev/null",
- 'source.c++' => "#{ENV['TM_GXX'] || 'g++'} 2>&1 >/dev/null -E -v -x c++ #{ENV['TM_CXX_FLAGS']} /dev/null",
- 'source.objc' => "#{ENV['TM_GCC'] || 'gcc'} 2>&1 >/dev/null -E -v -x objective-c #{ENV['TM_OBJC_FLAGS']} /dev/null",
- 'source.objc++' => "#{ENV['TM_GXX'] || 'g++'} 2>&1 >/dev/null -E -v -x objective-c++ #{ENV['TM_OBJCXX_FLAGS']} /dev/null",
+ 'source.c' => "#{ENV['TM_GCC'] || 'xcrun clang'} 2>&1 >/dev/null -E -v -x c #{ENV['TM_C_FLAGS']} /dev/null",
+ 'source.c++' => "#{ENV['TM_GXX'] || 'xcrun clang++'} 2>&1 >/dev/null -E -v -x c++ #{ENV['TM_CXX_FLAGS']} /dev/null",
+ 'source.objc' => "#{ENV['TM_GCC'] || 'xcrun clang'} 2>&1 >/dev/null -E -v -x objective-c #{ENV['TM_OBJC_FLAGS']} /dev/null",
+ 'source.objc++' => "#{ENV['TM_GXX'] || 'xcrun clang++'} 2>&1 >/dev/null -E -v -x objective-c++ #{ENV['TM_OBJCXX_FLAGS']} /dev/null",
}
def compiler(scope = ENV['TM_SCOPE'])

0 comments on commit 020edc6

Please sign in to comment.