| 1 |
#! /usr/bin/ruby |
| 2 |
|
| 3 |
Dir.chdir(File.dirname($0)) |
| 4 |
|
| 5 |
require 'Tempfile' |
| 6 |
BUILD_LOG = Tempfile.new("Chipmunk-") |
| 7 |
BUILD_LOG_PATH = BUILD_LOG.path |
| 8 |
|
| 9 |
def log(string) |
| 10 |
puts string |
| 11 |
open(BUILD_LOG_PATH, 'a'){|f| f.puts string} |
| 12 |
end |
| 13 |
|
| 14 |
PROJECT = "Chipmunk7.xcodeproj" |
| 15 |
VERBOSE = (not ARGV.include?("--quiet")) |
| 16 |
|
| 17 |
def system(command) |
| 18 |
log "> #{command}" |
| 19 |
|
| 20 |
result = Kernel.system(VERBOSE ? "#{command} | tee -a #{BUILD_LOG_PATH}; exit ${PIPESTATUS[0]}" : "#{command} >> #{BUILD_LOG_PATH}") |
| 21 |
unless $? == 0 |
| 22 |
log "===========================================" |
| 23 |
log "Command failed with status #{$?}: #{command}" |
| 24 |
log "Build errors encountered. Aborting build script" |
| 25 |
log "Check the build log for more information: #{BUILD_LOG_PATH}" |
| 26 |
raise |
| 27 |
end |
| 28 |
end |
| 29 |
|
| 30 |
def build(target, configuration) |
| 31 |
command = "xcodebuild -project #{PROJECT} -configuration #{configuration} -arch x86_64 -target #{target}" |
| 32 |
system command |
| 33 |
|
| 34 |
return "build/#{configuration}/lib#{target}.a" |
| 35 |
end |
| 36 |
|
| 37 |
def build_lib(target, copy_list) |
| 38 |
debug_lib = build(target, "Debug") |
| 39 |
release_lib = build(target, "Release") |
| 40 |
|
| 41 |
dirname = "#{target}" |
| 42 |
|
| 43 |
system "rm -rf '#{dirname}'" |
| 44 |
system "mkdir '#{dirname}'" |
| 45 |
|
| 46 |
system "cp '#{debug_lib}' '#{dirname}/lib#{target}-Debug.a'" |
| 47 |
system "cp '#{release_lib}' '#{dirname}/lib#{target}.a'" |
| 48 |
|
| 49 |
copy_list.each{|src| system "rsync -r --exclude='.*' '#{src}' '#{dirname}'"} |
| 50 |
end |
| 51 |
|
| 52 |
build_lib("Chipmunk-Mac", [ |
| 53 |
"../include", |
| 54 |
]) |
| 55 |
|
| 56 |
build_lib("ObjectiveChipmunk-Mac", [ |
| 57 |
"../include", |
| 58 |
"../objectivec/include", |
| 59 |
]) |
| 60 |
|
| 61 |
BUILD_LOG.delete |