Debian Codegraph @

xcode/iphonestatic.command

raw
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 def latest_sdk()
15 sdks = `xcodebuild -showsdks`.split("\n")
16
17 versions = sdks.map do|elt|
18 # Match only lines with "iphoneos" in them.
19 m = elt.match(/iphoneos(\d\.\d)/)
20 (m ? m.captures[0] : "0.0")
21 end
22
23 return versions.max
24 end
25
26 # Or you can pick a specific version string (ex: "5.1")
27 IOS_SDK_VERSION = latest_sdk()
28
29 log("Building using iOS SDK #{IOS_SDK_VERSION}")
30
31 PROJECT = "Chipmunk7.xcodeproj"
32 VERBOSE = (not ARGV.include?("--quiet"))
33
34 def system(command)
35 log "> #{command}"
36
37 result = Kernel.system(VERBOSE ? "#{command} | tee -a #{BUILD_LOG_PATH}; exit ${PIPESTATUS[0]}" : "#{command} >> #{BUILD_LOG_PATH}")
38 unless $? == 0
39 log "==========================================="
40 log "Command failed with status #{$?}: #{command}"
41 log "Build errors encountered. Aborting build script"
42 log "Check the build log for more information: #{BUILD_LOG_PATH}"
43 raise
44 end
45 end
46
47 def build(target, configuration, simulator)
48 sdk_os = (simulator ? "iphonesimulator" : "iphoneos")
49 sdk = "#{sdk_os}#{IOS_SDK_VERSION}"
50
51 command = "xcodebuild -project #{PROJECT} -sdk #{sdk} -configuration #{configuration} -target #{target}"
52 system command
53
54 return "build/#{configuration}-#{sdk_os}/lib#{target}.a"
55 end
56
57 def build_fat_lib(target, copy_list)
58 iphone_lib = build(target, "Release", false)
59 simulator_lib = build(target, "Debug", true)
60
61 dirname = "#{target}"
62
63 system "rm -rf '#{dirname}'"
64 system "mkdir '#{dirname}'"
65
66 system "lipo #{iphone_lib} #{simulator_lib} -create -output '#{dirname}/lib#{target}.a'"
67
68 copy_list.each{|src| system "rsync -r --exclude='.*' '#{src}' '#{dirname}'"}
69
70 puts "\n#{dirname}/ Succesfully built"
71 end
72
73
74 build_fat_lib( "Chipmunk-iOS", [
75 "../include",
76 ])
77
78 build_fat_lib("ObjectiveChipmunk-iOS", [
79 "../include",
80 "../objectivec/include",
81 ])
82
83 BUILD_LOG.delete