Sketch compiles
This commit is contained in:
parent
42a7729963
commit
cd62c35719
|
@ -21,15 +21,40 @@ class ASBuilder {
|
|||
task!.currentDirectoryPath = dir.path!
|
||||
task!.launchPath = NSBundle.mainBundle().pathForResource("BuildProject", ofType: "")!
|
||||
|
||||
let fileManager = NSFileManager.defaultManager()
|
||||
let libPath = (ASLibraries.instance().directories as NSArray).componentsJoinedByString(":")
|
||||
var args = [NSString]()
|
||||
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("mcu="+boardProp["build.mcu"])
|
||||
args.append("f_cpu="+boardProp["build.f_cpu"])
|
||||
args.append("core="+boardProp["build.core"])
|
||||
args.append("variant="+boardProp["build.variant"])
|
||||
args.append("libs="+libPath)
|
||||
args.append("core_path="+corePath)
|
||||
if variantPath != nil {
|
||||
args.append("variant_path="+variantPath!)
|
||||
}
|
||||
args.append("--")
|
||||
args += files.paths
|
||||
task!.arguments = args;
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#
|
||||
|
||||
require 'fileutils.rb'
|
||||
require 'rake'
|
||||
|
||||
BUILD = {
|
||||
'board' => 'uno',
|
||||
|
@ -33,9 +34,31 @@ def createBuildDirectory
|
|||
FileUtils::mkdir_p "#{$SKETCH_DIR}", :verbose => true
|
||||
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
|
||||
$LIBPATH = BUILD['libs'].split(':').reverse
|
||||
$LIBRARIES = []
|
||||
$CORES = [BUILD['core_path']]
|
||||
if BUILD['variant_path']
|
||||
$CORES << BUILD['variant_path']
|
||||
end
|
||||
ARGV.each_index do |arg|
|
||||
if ARGV[arg] =~ /\.ino$/
|
||||
outName = "#{$SKETCH_DIR}/"+File.basename(ARGV[arg], '.ino')+".cpp"
|
||||
|
@ -81,25 +104,41 @@ def smashSpaces(s)
|
|||
end
|
||||
|
||||
def addLibrary(header)
|
||||
$LIBPATH.each do |path|
|
||||
Dir.glob("#{path}/*").each do |lib|
|
||||
if File.exists?("#{lib}/#{header}")
|
||||
lib = HEADERMAP[header]
|
||||
if lib && !$LIBRARIES.include?(lib)
|
||||
$LIBRARIES << lib
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
parseArguments
|
||||
createBuildDirectory
|
||||
buildHeaderMap
|
||||
parseInoFiles
|
||||
|
||||
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
|
||||
LIBRARIES=#{$LIBRARIES.join(':')}
|
||||
FILES = [
|
||||
#{ARGV.join('\n')}
|
||||
]
|
||||
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}
|
||||
AR = '/usr/local/CrossPack-AVR/bin/avr-ar crsv'
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user