I'm writing a code in C++ with the support of the GNU Scientific Libraries. I've properly installed them and in order to compile them from the Terminal I just have to write the following:
g++ $(gsl-config --cflags) filename.cpp $(gsl-config --libs)
Now, I'm a TextMate user, and I would like to modify the standard Run command from the C bundle in order to compile my cpp files with the right gsl options. The problem is the TextMate.Executor function, that I totally ignore and for which I haven't found any exhaustive reference.
Here's what I have tried:
#!/usr/bin/env ruby
require ENV["TM_SUPPORT_PATH"] + "/lib/tm/executor"
require ENV["TM_SUPPORT_PATH"] + "/lib/tm/save_current_document"
mode = ENV["TM_SCOPE"].slice(/.*?\bsource\.((?:obj)?c(\+\+)?)/, 1)
case mode
when "c"
g = "GCC"
env = "C"
ext = "c"
lang = "c"
when "c++"
g = "GXX"
env = "CXX"
ext = "cc"
lang = "c++"
when "objc"
g = "GCC"
env = "OBJC"
ext = "m"
lang = "objective-c"
when "objc++"
g = "GXX"
env = "OBJCXX"
ext = "mm"
lang = "objective-c++"
end
TextMate.save_current_document(ext)
TextMate::Executor.make_project_master_current_document
flags = ENV["TM_#{en开发者_高级运维v}_FLAGS"] || "-Wall -include stdio.h $(gsl-config --cflags) "
args = [ENV["TM_#{g}"] || g.downcase.gsub("x", "+"), flags + " -x #{lang}", ENV["TM_FILEPATH"]+" $(gsl-config --libs)"]
TextMate::Executor.run(args, :version_args => ["--version"])
This doesn't quite answer your question, but might instead be a more preferable thing to do (and, arguably the more recommended thing to do?)
Create a Makefile for your code. Here's a stripped-down version of mine:
CC = g++
CFLAGS = -g -Wall -L/opt/local/lib -I/opt/local/include -I$(SRC_DIR)
GSLFLAGS = -lgsl -lgslcblas -lm -I/opt/local/include/gsl
EXEC = mRVM
SRC_DIR = ./src
OUTPUT_DIR = ./bin
all: $(EXEC)
clean:
-rm $(OUTPUT_DIR)/test
-rm $(OUTPUT_DIR)/*.exe
$(EXEC):
$(CC) $(CFLAGS) $(GSLFLAGS) -o $(OUTPUT_DIR)/$(EXEC) $(SRC_DIR)/main.cc
Now in your "project," navigate to the Makefile and press ⌘+M
精彩评论