1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
require 'rubygems'
require 'net/ssh'
require 'open3'

CC = "arm-apple-darwin-cc"
LD = CC
CFLAGS = ""
CPPFLAGS = ""
LDFLAGS = "-lobjc -framework CoreFoundation -framework Foundation -framework UIKit -framework LayerKit -L/Developer/SDKs/iPhone/lib"

TARGET = Dir.pwd[/[^\/]+$/]

task :default => [:build_install_and_test]

task :clean do
  puts "Deleting #{TARGET}"
  File.delete(TARGET) if File.exists?(TARGET)
  `rm *.o`
end

task :build do
  puts "Building..."
  FileList["*.m"].to_a.each { |m| %x{#{CC} -c #{CFLAGS} #{CPPFLAGS} #{m} -o #{m.gsub(/m$/,'o')}} }
  %x{#{LD} #{LDFLAGS} -o #{TARGET} #{Dir["*.o"].join " "}}
end

task :package do
  `cp #{TARGET} #{TARGET}.app/`
end

task :copy_to_iphone do
  Open3.popen3("expect") do |sin, sout, serr|
    sin.puts "spawn scp -rp #{TARGET}.app iphone:/Applications"
    sin.puts %q|expect "password:" {send "dottie\n"}|
    sin.puts "expect #"
    puts sout.read
  end
end

task :build_install_and_test => [:clean, :build, :package, :copy_to_iphone]