Sketch compiles
This commit is contained in:
parent
42a7729963
commit
cd62c35719
|
@ -21,15 +21,40 @@ class ASBuilder {
|
||||||
task!.currentDirectoryPath = dir.path!
|
task!.currentDirectoryPath = dir.path!
|
||||||
task!.launchPath = NSBundle.mainBundle().pathForResource("BuildProject", ofType: "")!
|
task!.launchPath = NSBundle.mainBundle().pathForResource("BuildProject", ofType: "")!
|
||||||
|
|
||||||
|
let fileManager = NSFileManager.defaultManager()
|
||||||
let libPath = (ASLibraries.instance().directories as NSArray).componentsJoinedByString(":")
|
let libPath = (ASLibraries.instance().directories as NSArray).componentsJoinedByString(":")
|
||||||
var args = [NSString]()
|
var args = [NSString]()
|
||||||
let boardProp = ASHardware.instance().boards[board]!
|
let boardProp = ASHardware.instance().boards[board]!
|
||||||
|
var corePath = ""
|
||||||
|
var variantPath : NSString?
|
||||||
|
for hw in ASHardware.instance().directories {
|
||||||
|
corePath = hw+"/cores/"+boardProp["build.core"]
|
||||||
|
if fileManager.fileExistsAtPath(corePath) {
|
||||||
|
if boardProp["build.variant"] != "" {
|
||||||
|
variantPath = hw+"/variants/"+boardProp["build.variant"]
|
||||||
|
if !fileManager.fileExistsAtPath(corePath) {
|
||||||
|
variantPath = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
} else {
|
||||||
|
corePath = ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if corePath == "" {
|
||||||
|
NSLog("Unable to find core %s\n", boardProp["build.core"])
|
||||||
|
return
|
||||||
|
}
|
||||||
args.append("board="+board)
|
args.append("board="+board)
|
||||||
args.append("mcu="+boardProp["build.mcu"])
|
args.append("mcu="+boardProp["build.mcu"])
|
||||||
args.append("f_cpu="+boardProp["build.f_cpu"])
|
args.append("f_cpu="+boardProp["build.f_cpu"])
|
||||||
args.append("core="+boardProp["build.core"])
|
args.append("core="+boardProp["build.core"])
|
||||||
args.append("variant="+boardProp["build.variant"])
|
args.append("variant="+boardProp["build.variant"])
|
||||||
args.append("libs="+libPath)
|
args.append("libs="+libPath)
|
||||||
|
args.append("core_path="+corePath)
|
||||||
|
if variantPath != nil {
|
||||||
|
args.append("variant_path="+variantPath!)
|
||||||
|
}
|
||||||
args.append("--")
|
args.append("--")
|
||||||
args += files.paths
|
args += files.paths
|
||||||
task!.arguments = args;
|
task!.arguments = args;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
require 'fileutils.rb'
|
require 'fileutils.rb'
|
||||||
|
require 'rake'
|
||||||
|
|
||||||
BUILD = {
|
BUILD = {
|
||||||
'board' => 'uno',
|
'board' => 'uno',
|
||||||
|
@ -33,9 +34,31 @@ def createBuildDirectory
|
||||||
FileUtils::mkdir_p "#{$SKETCH_DIR}", :verbose => true
|
FileUtils::mkdir_p "#{$SKETCH_DIR}", :verbose => true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
HEADERMAP = {}
|
||||||
|
def buildHeaderMap
|
||||||
|
paths = Rake::FileList.new(BUILD['libs'].split(':').reverse)
|
||||||
|
paths.each do |path|
|
||||||
|
libs = Rake::FileList.new(path+"/*")
|
||||||
|
libs.each do |lib|
|
||||||
|
headers = Rake::FileList.new(lib+"/**/*.h")
|
||||||
|
headers.each do |h|
|
||||||
|
name = h[lib.length+1..-1]
|
||||||
|
next if name =~ %r|^utility/|
|
||||||
|
if !HEADERMAP[name] or HEADERMAP[name].pathmap('%f') != name.pathmap('%X')
|
||||||
|
HEADERMAP[name] = lib
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
p HEADERMAP
|
||||||
|
end
|
||||||
|
|
||||||
def parseInoFiles
|
def parseInoFiles
|
||||||
$LIBPATH = BUILD['libs'].split(':').reverse
|
|
||||||
$LIBRARIES = []
|
$LIBRARIES = []
|
||||||
|
$CORES = [BUILD['core_path']]
|
||||||
|
if BUILD['variant_path']
|
||||||
|
$CORES << BUILD['variant_path']
|
||||||
|
end
|
||||||
ARGV.each_index do |arg|
|
ARGV.each_index do |arg|
|
||||||
if ARGV[arg] =~ /\.ino$/
|
if ARGV[arg] =~ /\.ino$/
|
||||||
outName = "#{$SKETCH_DIR}/"+File.basename(ARGV[arg], '.ino')+".cpp"
|
outName = "#{$SKETCH_DIR}/"+File.basename(ARGV[arg], '.ino')+".cpp"
|
||||||
|
@ -81,25 +104,41 @@ def smashSpaces(s)
|
||||||
end
|
end
|
||||||
|
|
||||||
def addLibrary(header)
|
def addLibrary(header)
|
||||||
$LIBPATH.each do |path|
|
lib = HEADERMAP[header]
|
||||||
Dir.glob("#{path}/*").each do |lib|
|
if lib && !$LIBRARIES.include?(lib)
|
||||||
if File.exists?("#{lib}/#{header}")
|
$LIBRARIES << lib
|
||||||
$LIBRARIES << lib
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
parseArguments
|
parseArguments
|
||||||
createBuildDirectory
|
createBuildDirectory
|
||||||
|
buildHeaderMap
|
||||||
parseInoFiles
|
parseInoFiles
|
||||||
|
|
||||||
File.open("#{$BUILD_DIR}/Rakefile", 'w') do |rakeFile|
|
File.open("#{$BUILD_DIR}/Rakefile", 'w') do |rakeFile|
|
||||||
|
SOURCES = FileList.new(ARGV).select {|f| f =~ /\.(c|cpp|cp|cxx|S)$/}
|
||||||
|
INCLUDES= ($CORES+$LIBRARIES).map {|l| " +\n \" -I'#{l}'\""}.join('')
|
||||||
rakeFile.print <<END_RAKE
|
rakeFile.print <<END_RAKE
|
||||||
LIBRARIES=#{$LIBRARIES.join(':')}
|
CC = '/usr/local/CrossPack-AVR/bin/avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=#{BUILD['mcu']} -DF_CPU=#{BUILD['f_cpu']} -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 -I ../..'#{INCLUDES}
|
||||||
FILES = [
|
AR = '/usr/local/CrossPack-AVR/bin/avr-ar crsv'
|
||||||
#{ARGV.join('\n')}
|
LIBRARIES = [#{$LIBRARIES.map{|l| "'"+l+"'"}.join(' ')}]
|
||||||
]
|
|
||||||
|
def compile(dest, *src)
|
||||||
|
directory dest
|
||||||
|
archive = dest.ext('.a')
|
||||||
|
sources = Rake::FileList.new(src)
|
||||||
|
objects = sources.pathmap(dest+"/%n.o")
|
||||||
|
objects.each_index do |i|
|
||||||
|
file objects[i] => sources[i] do
|
||||||
|
sh "%s '%s' -o '%s'" % [CC, sources[i], objects[i]]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
file archive => objects do
|
||||||
|
sh ("%s '%s' " % [AR, archive])+objects.map {|o| "'"+o+"'"}.join(" ")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
compile('sketch', #{SOURCES.map{|f| "'../../"+f+"'"}.join(', ')})
|
||||||
END_RAKE
|
END_RAKE
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user