Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
219 lines (191 loc) · 6.29 KB

File metadata and controls

219 lines (191 loc) · 6.29 KB
 
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# ------------------------------------------------------------------------------
# Builds a SDL framework for the iOS
# Copyright (c) 2011 Andrey Nesterov
# See LICENSE for licensing information
# ------------------------------------------------------------------------------
#
# Creates a pseudo-framework which contains a universal library that can be used
# on a iOS and in the iOS simulator
#
# ------------------------------------------------------------------------------
#
# To configure the script, define:
# Conf configuration, symbol (:release or :debug)
# SDK version number of the iOS SDK, symbol (e.g. :"4.3")
# Arch architecture for the device's library, symbol (e.g. :armv6 or :armv7)
#
# ------------------------------------------------------------------------------
# --- Configure ----------------------------------------------------------------
module Configure
Conf = :release
SDK = :"4.3"
Arch = :armv7
end
# --- Constants ----------------------------------------------------------------
module Global
RootDir = Dir.pwd
SourceDir = "#{RootDir}"
BuildDir = "#{RootDir}/build"
end
# --- Common -------------------------------------------------------------------
module Builder
def get_sources(from, to)
refresh_dir to
yield from, to
end
def build_library(project, dest, target, conf, sdk, arch)
print "\n"
dest = library_bundle_path(dest, conf, sdk, arch)
sdk, arch = compute_platform(sdk, arch)
conf = configuration(conf)
refresh_dir dest
refresh_dir "#{dest}.build"
proj_dir, proj_fname = File.split project
cd proj_dir
args = Array.new()
args.push("xcodebuild")
args.push("-project #{proj_fname}")
args.push("-sdk #{sdk}")
args.push("-configuration \"#{conf}\"")
args.push("-target \"#{target}\"")
# NATIVE_ARCH has no effect
#args.push("NATIVE_ARCH=#{arch.to_str}")
args.push("-arch #{arch.to_str}")
args.push("TARGETED_DEVICE_FAMILY=2") # 2 => iPad, 1 => iPhone
args.push("BUILT_PRODUCTS_DIR=\"build\"")
args.push("CONFIGURATION_BUILD_DIR=\"#{dest}\"")
args.push("CONFIGURATION_TEMP_DIR=\"#{dest}.build\"")
cmd = args.join(' ')
#print "\n"
print "#{cmd}\n"
`#{cmd}`
end
def build_framework_library(frameworkLib, deviceLib, simulatorLib)
print "\n"
refresh_dir File.dirname frameworkLib
cmd = "lipo -create #{deviceLib} #{simulatorLib} -o #{frameworkLib}"
print "#{cmd}\n"
`#{cmd}`
end
def build_framework(name, version, identifier, dest, headers, project, target, conf, sdk, arch)
libFileName = "lib#{name}.a";
libFilePath = "#{dest}/universal-#{conf}/#{libFileName}"
build_library(project, dest, target, conf, sdk, arch);
build_library(project, dest, target, conf, sdk, :i386);
build_framework_library(
libFilePath,
"#{library_bundle_path(dest, conf, sdk, arch)}/#{libFileName}",
"#{library_bundle_path(dest, conf, sdk, :i386)}/#{libFileName}"
)
# Static library has version A
create_framework(name, "A", identifier, dest, headers, libFilePath)
end
def create_framework(name, version, identifier, dest, headers, lib)
print "\n"
frameworkVersion = version
frameworkBundle = framework_bundle_path(dest, name)
# creating framework's directories
refresh_dir frameworkBundle
mkdir "#{frameworkBundle}/Versions"
mkdir "#{frameworkBundle}/Versions/#{frameworkVersion}"
mkdir "#{frameworkBundle}/Versions/#{frameworkVersion}/Resources"
mkdir "#{frameworkBundle}/Versions/#{frameworkVersion}/Headers"
mkdir "#{frameworkBundle}/Versions/#{frameworkVersion}/Documentation"
# creating framework's symlinks
`ln -s "#{frameworkVersion}" "#{frameworkBundle}/Versions/Current"`
`ln -s "Versions/Current/Headers" "#{frameworkBundle}/Headers"`
`ln -s "Versions/Current/Resources" "#{frameworkBundle}/Resources"`
`ln -s "Versions/Current/Documentation" "#{frameworkBundle}/Documentation"`
`ln -s "Versions/Current/#{File.basename lib}" "#{frameworkBundle}/#{name}"`
# copying lib
cp lib, "#{frameworkBundle}/Versions/#{frameworkVersion}"
# copying the header files. Copy everything found in the headers directory.
FileList["#{headers}/*.h"].each do |source|
cp source, "#{frameworkBundle}/Headers"
end
# creating plist
File.open("#{frameworkBundle}/Resources/Info.plist", "w") do |f|
f.puts '<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">'
f.puts "\
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>#{name}</string>
<key>CFBundleIdentifier</key>
<string>#{identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>#{version}</string>
</dict>
</plist>"
end
end
def library_bundle_path(path, conf, sdk, arch)
sdk, arch = compute_platform(sdk, arch)
"#{path}/#{sdk}-#{conf}"
end
def framework_bundle_path(path, name)
"#{path}/#{name}.framework"
end
def configuration(conf)
conf.to_s
end
def compute_platform(sdk, arch)
return [sdk, arch] if arch.class == String
[arch == :i386 ? "iphonesimulator" + sdk.to_s : "iphoneos" + sdk.to_s, arch.to_s]
end
def refresh_dir(path)
rm_rf path if FileTest.exists? path
mkdir_p path
end
private :configuration, :compute_platform, :refresh_dir
end
class InstanceBuilder
class Instance
extend Builder
end
def InstanceBuilder.message(text)
tailSize = 75 - text.length;
puts "--- #{text} #{'-' * (tailSize < 0 ? 0 : tailSize)}"
end
end
# --- SDL ----------------------------------------------------------------------
class SDL < InstanceBuilder
SourceDir = "#{Global::SourceDir}"
BuildDir = "#{Global::BuildDir}"
def SDL.build_framework(conf, sdk, arch)
message "Building SDL"
Instance.build_framework(
"SDL",
"1.3",
"org.libsdl",
BuildDir,
"#{SourceDir}/include",
"#{SourceDir}/Xcode-iPhoneOS/SDL/SDLiPhoneOS.xcodeproj",
"libSDL",
conf,
sdk,
arch
)
end
def Instance.configuration(conf)
case conf
when :release
"Release"
when :debug
"Debug"
end
end
end
# --- Tasks --------------------------------------------------------------------
task :default do
SDL.build_framework Configure::Conf, Configure::SDK, Configure::Arch
end