forked from thejustinwalsh/airejdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
229 lines (202 loc) · 8.82 KB
/
Rakefile
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
220
221
222
223
224
225
226
227
228
229
# Copyright (c) 2013 Justin Walsh, http://thejustinwalsh.com/
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
require "yaml"
require "Shellwords"
PROJECT = "airejdb"
ROOT = File.dirname(__FILE__)
$build = []
$config = "debug"
task :default, [:config] => [:build] do |t, args|
end
desc "Bootstrap the environment by copying our template _build.yml to build.yml and prompting the user to edit the file"
task :bootstrap, [:config] do |t, args|
unless File.exists?('config/build.yml')
FileUtils.copy('config/_build.yml', 'config/build.yml')
abort("## Edit config/build.yml to match your environment before continuing!")
end
end
task :load, [:config] => [:bootstrap] do |t, args|
# Default our build configuration to debug
$config = args[:config] || $config;
# Load our build configuration from our yaml file
yaml = YAML::load(File.open('config/build.yml'))
$build = yaml[$config]
end
desc "Build the native extension"
task :build, [:config] => [:load, :swc, :default_swc, :macos, :ios, :android, :windows] do |t, args|
airsdk = "#{Shellwords.escape($build['airsdk'])}"
adt = "#{airsdk}/bin/adt"
ane = "#{ROOT}/bin/airejdb.ane"
xml = "#{ROOT}/src/extension.xml"
swc = "#{ROOT}/bin/#{PROJECT}.swc"
swf_dir = "#{ROOT}/bin/#{PROJECT}"
platforms = {
"default" => {
"target" => "default",
"libdir" => "#{ROOT}/bin/default/#{PROJECT}",
"lib" => "library.swf"
},
"macos" => {
"target" => "MacOS-x86",
"libdir" => "#{ROOT}/platform/macos/bin",
"lib" => "."
},
"ios" => {
"target" => "iPhone-ARM",
"options" => "#{ROOT}/src/platformoptions.xml",
"libdir" => "#{ROOT}/platform/ios/bin/",
"lib" => "libairejdb.a"
},
#"ios-simulator" => {
# "target" => "iPhone-x86",
# "options" => "#{ROOT}/src/platformoptions.xml",
# "libdir" => "#{ROOT}/platform/ios/bin/",
# "lib" => "libairejdb.a"
#},
"windows" => {
"target" => "Windows-x86",
"libdir" => "#{ROOT}/platform/windows/bin",
"lib" => "."
}
}
adt_args = "-package -target ane #{ane} #{xml} -swc #{swc} "
platforms.each_key {|key|
target = platforms[key]["target"]
lib_dir = platforms[key]["libdir"]
lib = platforms[key]["lib"]
options = platforms[key]["options"]
adt_args += "-platform #{target} "
adt_args += "-C #{swf_dir} library.swf " if target != "default"
adt_args += "-C #{lib_dir} #{lib} "
adt_args += "-platformoptions #{options} " if options
}
# Run adt and package our ane
sh "#{adt} #{adt_args}" do |ok, res|
fail "## adt failed with exitstatus #{res.exitstatus}" if !ok
end
end
desc "Build the swc and library.swf files needed for ane packaging"
task :swc, [:config] => [:load] do |t, args|
debug = ($config == "debug" ? "true" : "false")
debug_define = "CONFIG::debug," + ($config == "debug" ? "true" : "false")
airsdk = "#{Shellwords.escape($build['airsdk'])}"
compc = "#{airsdk}/bin/compc"
flexlib = "#{airsdk}/frameworks"
output_dir = "#{ROOT}/bin"
library = "#{output_dir}/#{PROJECT}.swc"
library_dir = "#{output_dir}/#{PROJECT}"
src = "#{ROOT}/src"
# Remove the swc output directory, then build the swc into a directory
rm_rf library_dir if File.directory? library_dir
sh "#{compc} -directory=true -output=#{library_dir} -debug=#{debug} -define=#{debug_define} +flexlib #{flexlib} +configname=air -source-path+=#{src} -include-sources #{src}" do |ok, res|
fail "## compc failed with exitstatus #{res.exitstatus}" if !ok
end
# Build the swc
sh "#{compc} -output=#{library} -debug=#{debug} -define=#{debug_define} +flexlib #{flexlib} +configname=air -source-path+=#{src} -include-sources #{src}" do |ok, res|
fail "## compc failed with exitstatus #{res.exitstatus}" if !ok
end
end
desc "Build the default library for AS only implementations"
task :default_swc, [:config] => [:load] do |t, args|
debug = ($config == "debug" ? "true" : "false")
debug_define = "CONFIG::debug," + ($config == "debug" ? "true" : "false")
airsdk = "#{Shellwords.escape($build['airsdk'])}"
compc = "#{airsdk}/bin/compc"
flexlib = "#{airsdk}/frameworks"
output_dir = "#{ROOT}/bin/default"
library = "#{output_dir}/#{PROJECT}.swc"
library_dir = "#{output_dir}/#{PROJECT}"
src = "#{ROOT}/platform/default"
# Remove the swc output directory, then build the swc into a directory
mkdir output_dir unless File.directory? output_dir
rm_rf library_dir if File.directory? library_dir
sh "#{compc} -directory=true -output=#{library_dir} -debug=#{debug} -define=#{debug_define} +flexlib #{flexlib} +configname=air -source-path+=#{src} -include-sources #{src}" do |ok, res|
fail "## compc failed with exitstatus #{res.exitstatus}" if !ok
end
# Build the swc
sh "#{compc} -output=#{library} -debug=#{debug} -define=#{debug_define} +flexlib #{flexlib} +configname=air -source-path+=#{src} -include-sources #{src}" do |ok, res|
fail "## compc failed with exitstatus #{res.exitstatus}" if !ok
end
end
desc "Build the native library for Mac OS"
task :macos, [:config] => [:load] do |t, args|
next unless which "xcodebuild"
project = "#{ROOT}/platform/macos/AirEJDB.xcodeproj"
target = 'AirEJDB'
airsdk = Shellwords.escape($build['airsdk'])
configuration = $config.capitalize
symroot = "#{ROOT}/platform/macos/build"
# Inform Xcode of the AIR_SDK location so that the build can locate the air framework and header, then build the native library
sh "export AIR_SDK=\"#{airsdk}\"; xcodebuild -project #{project} -configuration #{configuration} -target #{target} build SYMROOT=#{symroot}" do |ok, res|
fail "## xcodebuild failed with exitstatus #{res.exitstatus}" if !ok
end
end
desc "Build the native library for iOS"
task :ios, [:config] => [:load] do |t, args|
next unless which "xcodebuild"
project = "#{ROOT}/platform/ios/AirEJDB.xcodeproj"
target = 'AirEJDB'
airsdk = Shellwords.escape($build['airsdk'])
iossdk = $build['iossdk']
configuration = $config.capitalize
symroot = "#{ROOT}/platform/ios/build"
# Inform Xcode of the AIR_SDK location so that the build can locate the air framework header, then build the native library
sh "export AIR_SDK=\"#{airsdk}\"; xcodebuild -project #{project} -sdk #{iossdk} -configuration #{configuration} -target #{target} build SYMROOT=#{symroot}" do |ok, res|
fail "## xcodebuild failed with exitstatus #{res.exitstatus}" if !ok
end
end
desc "Build the native library for Android"
task :android, [:config] => [:load] do |t, args|
next #unless which "xcodebuild"
project = "#{ROOT}/platform/android/"
target = ''
airsdk = Shellwords.escape($build['airsdk'])
configuration = $config.capitalize
symroot = "#{ROOT}/platform/macos/build"
# Inform Xcode of the AIR_SDK location so that the build can locate the air framework and header, then build the native library
#sh "export AIR_SDK=\"#{airsdk}\"; xcodebuild -project #{project} -configuration #{configuration} -target #{target} build SYMROOT=#{symroot}" do |ok, res|
# fail "## xcodebuild failed with exitstatus #{res.exitstatus}" if !ok
#end
end
desc "Build the native library for Windows"
task :windows, [:config] => [:load] do |t, args|
next #unless which "xcodebuild"
project = "#{ROOT}/platform/windows/"
target = ''
airsdk = Shellwords.escape($build['airsdk'])
configuration = $config.capitalize
symroot = "#{ROOT}/platform/macos/build"
# Inform Xcode of the AIR_SDK location so that the build can locate the air framework and header, then build the native library
#sh "export AIR_SDK=\"#{airsdk}\"; xcodebuild -project #{project} -configuration #{configuration} -target #{target} build SYMROOT=#{symroot}" do |ok, res|
# fail "## xcodebuild failed with exitstatus #{res.exitstatus}" if !ok
#end
end
# http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
def which(cmd)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each { |ext|
exe = File.join(path, "#{cmd}#{ext}")
return exe if File.executable? exe
}
end
return nil
end