File: iphonestatic.command

package info (click to toggle)
chipmunk 7.0.3-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,968 kB
  • sloc: ansic: 29,265; objc: 4,313; ruby: 409; makefile: 10; sh: 1
file content (83 lines) | stat: -rwxr-xr-x 2,020 bytes parent folder | download | duplicates (3)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /usr/bin/ruby

Dir.chdir(File.dirname($0))

require 'Tempfile'
BUILD_LOG = Tempfile.new("Chipmunk-")
BUILD_LOG_PATH = BUILD_LOG.path

def log(string)
	puts string
	open(BUILD_LOG_PATH, 'a'){|f| f.puts string}
end

def latest_sdk()
	sdks = `xcodebuild -showsdks`.split("\n")
	
	versions = sdks.map do|elt|
		# Match only lines with "iphoneos" in them.
		m = elt.match(/iphoneos(\d\.\d)/)
		(m ? m.captures[0] : "0.0")
	end
	
	return versions.max
end

# Or you can pick a specific version string (ex: "5.1")
IOS_SDK_VERSION = latest_sdk()

log("Building using iOS SDK #{IOS_SDK_VERSION}")

PROJECT = "Chipmunk7.xcodeproj"
VERBOSE = (not ARGV.include?("--quiet"))

def system(command)
	log "> #{command}"
	
	result = Kernel.system(VERBOSE ? "#{command} | tee -a #{BUILD_LOG_PATH}; exit ${PIPESTATUS[0]}" : "#{command} >> #{BUILD_LOG_PATH}")
	unless $? == 0
		log "==========================================="
		log "Command failed with status #{$?}: #{command}"
		log "Build errors encountered. Aborting build script"
		log "Check the build log for more information: #{BUILD_LOG_PATH}"
		raise
	end
end

def build(target, configuration, simulator)
	sdk_os = (simulator ? "iphonesimulator" : "iphoneos")
	sdk = "#{sdk_os}#{IOS_SDK_VERSION}"
	
	command = "xcodebuild -project #{PROJECT} -sdk #{sdk} -configuration #{configuration} -target #{target}"
	system command
	
	return "build/#{configuration}-#{sdk_os}/lib#{target}.a"
end

def build_fat_lib(target, copy_list)
	iphone_lib = build(target, "Release", false)
	simulator_lib = build(target, "Debug", true)
	
	dirname = "#{target}"
	
	system "rm -rf '#{dirname}'"
	system "mkdir '#{dirname}'"
	
	system "lipo #{iphone_lib} #{simulator_lib} -create -output '#{dirname}/lib#{target}.a'"
	
	copy_list.each{|src| system "rsync -r --exclude='.*' '#{src}' '#{dirname}'"}
	
	puts "\n#{dirname}/ Succesfully built"
end


build_fat_lib( "Chipmunk-iOS", [
		"../include",
])

build_fat_lib("ObjectiveChipmunk-iOS", [
	"../include",
	"../objectivec/include",
])

BUILD_LOG.delete