buildrake 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aa798dd479ff68a84f82cb070a2c7de8b65d18e4fd8239f4d866cb30369c8f84
4
+ data.tar.gz: e3dfdbd6959e36d892b390c5e19aed883a7bec5310ba4301aa820ce1e5858af1
5
+ SHA512:
6
+ metadata.gz: 69cd1f2039ad14b8949e2dd4ccd2aa04de6ed26485ad6bfac7cf18a0cb58c6708bc914c3880a264767172da46e84498c372a1c78c528479ab21e5645607cd59c
7
+ data.tar.gz: 893daa378e18bcac3cc82fdac6a79c3178c6801dec018dedf69adbfc228fb0da79199b5698f896559b23c3d1207d90114ba31bd44bcf29806b0acc9b0613177d
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in buildrake.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 mskz-3110
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,41 @@
1
+ # Buildrake
2
+
3
+ Multiplatform build for c
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'buildrake'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install buildrake
20
+
21
+ ## Usage
22
+
23
+ Generate Rakefile:
24
+ ```irb
25
+ require 'buildrake'
26
+ Buildrake::setup
27
+ ```
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at https://github.com/mskz-3110/buildrake/rubygems/buildrake.
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "buildrake"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "buildrake/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "buildrake"
8
+ spec.version = Buildrake::VERSION
9
+ spec.authors = ["mskz-3110"]
10
+ spec.email = ["mskz.saito@gmail.com"]
11
+
12
+ spec.summary = %q{Multiplatform build for c.}
13
+ spec.description = %q{Multiplatform build for c.}
14
+ spec.homepage = "https://github.com/mskz-3110/buildrake/rubygems/buildrake"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.15"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_dependency "nokogiri"
27
+ end
@@ -0,0 +1,85 @@
1
+ require "buildrake/version"
2
+ require "buildrake/rush"
3
+ require "buildrake/config"
4
+ require "buildrake/comment"
5
+ require "buildrake/github"
6
+
7
+ module Buildrake
8
+ def self.setup
9
+ generate_rakefile
10
+ generate_gitignore
11
+ end
12
+
13
+ def self.generate_rakefile
14
+ return if Rush.file?( "Rakefile" )
15
+
16
+ open( "Rakefile", "wb" ){|f|
17
+ f.puts <<EOS
18
+ require "buildrake"
19
+
20
+ class Config < Buildrake::Config
21
+ method_accessor :srcs
22
+
23
+ def initialize( *args )
24
+ super( "", Buildrake::Rush.full_dir_path( Buildrake::Rush.dir_path( __FILE__ ) ) )
25
+
26
+ inc_dirs [ "\#{@root_path}/inc" ]
27
+
28
+ # Library
29
+ @srcs = [ ]
30
+ library( project_name, @srcs )
31
+
32
+ @platforms.each{|platform|
33
+ @configs.each{|config|
34
+ case platform
35
+ when :android
36
+ lib_dirs = [ "\#{@root_path}/lib/android/$(ANDROID_NDK_VERSION)_$(CONFIG)" ]
37
+ else
38
+ lib_dirs = [ "\#{@root_path}/lib/$(PLATFORM_PATH)" ]
39
+ end
40
+ lib_dir( platform, config, lib_dirs )
41
+ }
42
+ }
43
+
44
+ # Execute
45
+ if Buildrake::Rush.windows?
46
+ libs = [ ]
47
+ else
48
+ libs = [ ]
49
+ end
50
+ execute( "", [ ], libs )
51
+ end
52
+ end
53
+
54
+ desc "Setup"
55
+ task :setup do
56
+ Config.run( [ "setup" ] )
57
+ exit( 0 )
58
+ end
59
+
60
+ desc "Show help message"
61
+ task :help do
62
+ Config.run( [ "help" ] )
63
+ exit( 0 )
64
+ end
65
+
66
+ desc "Build"
67
+ task :build do
68
+ Config.run( [ "build" ] )
69
+ exit( 0 )
70
+ end
71
+ EOS
72
+ }
73
+ end
74
+
75
+ def self.generate_gitignore
76
+ return if Rush.file?( ".gitignore" )
77
+
78
+ open( ".gitignore", "wb" ){|f|
79
+ f.puts <<EOS
80
+ /build
81
+ /lib
82
+ EOS
83
+ }
84
+ end
85
+ end
@@ -0,0 +1,160 @@
1
+ module Buildrake
2
+ module Comment
3
+ def self.parse( path, &block )
4
+ open( path, "rb" ){|f|
5
+ head_line = 0
6
+ tail_line = 0
7
+ comments = []
8
+ f.each_line.each{|line|
9
+ line.chomp!
10
+ tail_line = tail_line + 1
11
+ if 0 < head_line
12
+ if /^(.*)\*\/$/ =~ line
13
+ block.call( comments.join( "\n" ), head_line, tail_line ) if ! comments.empty?
14
+ head_line = 0
15
+ comments = []
16
+ else
17
+ comments.push line
18
+ end
19
+ else
20
+ if /\/\/(.*)$/ =~ line
21
+ block.call( $1, tail_line, tail_line ) if ! $1.empty?
22
+ elsif /\/\*(.*)$/ =~ line
23
+ comments.push $1 if ! $1.empty?
24
+ head_line = tail_line
25
+ end
26
+ end
27
+ }
28
+ }
29
+ end
30
+
31
+ def self.parse_class( path, &block )
32
+ class_values = {
33
+ :namespace => "",
34
+ :class_name => "",
35
+ :elements => []
36
+ }
37
+ Comment.parse( path ){|comment, head_line, tail_line|
38
+ next if /\s*\[cc\:(.+?)\]\s*(.*)/m !~ comment
39
+
40
+ type = $1
41
+ value = $2.strip
42
+ case type
43
+ when "namespace"
44
+ class_values[ :namespace ] = value
45
+ when "class_name"
46
+ class_values[ :class_name ] = value
47
+ when "enum_name"
48
+ class_values[ :elements ].push( { :type => :enum, :name => value, :values => [] } )
49
+ when "enum_value"
50
+ class_values[ :elements ].last[ :values ].push value
51
+ when "struct_name"
52
+ class_values[ :elements ].push( { :type => :struct, :name => value, :members => [] } )
53
+ when "struct_member"
54
+ class_values[ :elements ].last[ :members ].push value
55
+ when "api"
56
+ if /(.+)\s(.+)\((.*)\)/ =~ value
57
+ api = {
58
+ :return_type => $1,
59
+ :name => $2,
60
+ :args => $3.strip
61
+ }
62
+ api[ :interface_code ] = "#{api[ :return_type ]} #{api[ :name ]}( #{api[ :args ]} )"
63
+ api[ :class_interface_code ] = "#{api[ :return_type ]} #{Rush.pascal_case( api[ :name ] )}( #{api[ :args ]} )"
64
+ api[ :call_args ] = api[ :args ].split( "," ).map{|v| v.split( /\s/ ).last}.join( ", " )
65
+ api[ :call_code ] = "#{api[ :name ]}( #{api[ :call_args ]} )"
66
+ return_code = ( "void" == api[ :return_type ] ) ? "" : "return "
67
+ api[ :return_call_code ] = "#{return_code}#{api[ :call_code ]}"
68
+ class_values[ :elements ].push( { :type => :api, :value => api } )
69
+ else
70
+ class_values[ :elements ].push( { :type => :api } )
71
+ end
72
+ else
73
+ class_values[ :elements ].push( { :type => type.to_sym, :value => value } )
74
+ end
75
+ }
76
+ block.call( class_values ) if ! class_values[ :class_name ].empty?
77
+ end
78
+
79
+ def self.generate_class_code_type_cs( dll_name, class_values )
80
+ codes = []
81
+ codes.push <<EOS
82
+ #if ! DLL_INTERNAL
83
+ #if ! UNITY_EDITOR && ( UNITY_IOS || UNITY_WEBGL )
84
+ #define DLL_INTERNAL
85
+ #endif
86
+ #endif
87
+
88
+ using System;
89
+ using System.Runtime.InteropServices;
90
+ using System.Diagnostics;
91
+ EOS
92
+
93
+ codes.push "namespace #{class_values[ :namespace ]} {" if ! class_values[ :namespace ].empty?
94
+ codes.push "public class #{class_values[ :class_name ]} {"
95
+ codes.push <<EOS.chomp
96
+ #if DLL_INTERNAL
97
+ public const string DllName = "__Internal";
98
+ #else
99
+ public const string DllName = "#{dll_name}";
100
+ #endif
101
+ EOS
102
+
103
+ class_values[ :elements ].each{|element|
104
+ case element[ :type ]
105
+ when :callback
106
+ codes.push <<EOS.chomp
107
+ public delegate #{element[ :value ]};
108
+
109
+ EOS
110
+ when :api
111
+ codes.push <<EOS.chomp
112
+ [DllImport(DllName, CallingConvention = CallingConvention.Cdecl)]
113
+ EOS
114
+
115
+ if element.key?( :value )
116
+ api = element[ :value ]
117
+ case api[ :return_type ].downcase
118
+ when "string"
119
+ codes.push <<EOS.chomp
120
+ static public extern IntPtr #{api[ :name ]}( #{api[ :args ]} );
121
+ static public #{api[ :class_interface_code ]}{ return Marshal.PtrToStringAnsi( #{api[ :call_code ]} ); }
122
+
123
+ EOS
124
+ else
125
+ codes.push <<EOS.chomp
126
+ static public extern #{api[ :interface_code ]};
127
+ static public #{api[ :class_interface_code ]}{ #{api[ :return_call_code ]}; }
128
+
129
+ EOS
130
+ end
131
+ end
132
+ when :code
133
+ codes.push <<EOS.chomp
134
+ #{element[ :value ]}
135
+
136
+ EOS
137
+ when :enum
138
+ codes.push <<EOS.chomp
139
+ public enum #{element[ :name ]} {
140
+ #{element[ :values ].join( ",\n " )}
141
+ };
142
+
143
+ EOS
144
+ when :struct
145
+ codes.push <<EOS.chomp
146
+ public struct #{element[ :name ]} {
147
+ public #{element[ :members ].join( ";\n public " )};
148
+ };
149
+
150
+ EOS
151
+ end
152
+ }
153
+
154
+ codes.push "}" if ! class_values[ :namespace ].empty?
155
+ codes.push "}"
156
+
157
+ codes.join( "\n" )
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,840 @@
1
+ module Buildrake
2
+ class Config
3
+ def self.run( argv )
4
+ self.new.public_send( argv.shift, *argv ) if ! argv.empty?
5
+ end
6
+
7
+ def self.method_accessor( *names )
8
+ names.each{|name|
9
+ class_eval <<EOS
10
+ def #{name}( *args )
11
+ args.empty? ? @#{name} : @#{name} = args.first
12
+ end
13
+ EOS
14
+ }
15
+ end
16
+
17
+ method_accessor :project_name
18
+ method_accessor :root_path
19
+ method_accessor :inc_dirs
20
+ method_accessor :lib_dirs
21
+ method_accessor :c_flags, :cxx_flags, :ld_flags
22
+ method_accessor :platforms, :configs
23
+ method_accessor :windows_runtimes
24
+ method_accessor :macos_archs, :ios_archs
25
+ method_accessor :android_archs, :android_api_level
26
+ method_accessor :cmake_version
27
+
28
+ def initialize( project_name, root_path )
29
+ @project_name = project_name
30
+
31
+ @root_path = root_path
32
+
33
+ @inc_dirs = []
34
+
35
+ @lib_dirs = {}
36
+
37
+ @c_flags = {}
38
+ @cxx_flags = {}
39
+ @ld_flags = {}
40
+
41
+ @platforms = [ :macos, :ios, :android, :linux, :windows ]
42
+ @configs = [ :debug, :release ]
43
+
44
+ @windows_runtimes = [ "MT", "MD" ]
45
+
46
+ @macos_archs = [ "x86_64" ]
47
+ @ios_archs = [ "armv7", "armv7s", "arm64" ]
48
+
49
+ @android_archs = [ "x86", "armeabi-v7a", "arm64-v8a" ]
50
+ @android_api_level = 21
51
+
52
+ @cmake_version = "2.8"
53
+
54
+ @executes = {}
55
+ @libraries = {}
56
+
57
+ @platforms.each{|platform|
58
+ @lib_dirs[ platform ] = {}
59
+ @c_flags[ platform ] = {}
60
+ @cxx_flags[ platform ] = {}
61
+ @ld_flags[ platform ] = {}
62
+ @configs.each{|config|
63
+ @lib_dirs[ platform ][ config ] = []
64
+ @c_flags[ platform ][ config ] = []
65
+ @cxx_flags[ platform ][ config ] = []
66
+ @ld_flags[ platform ][ config ] = []
67
+ case platform
68
+ when :windows
69
+ c_flag( platform, config, [ "/W4" ] )
70
+ cxx_flag( platform, config, [ "/W4" ] )
71
+ else
72
+ c_flag( platform, config, [ "-g -Wall" ] )
73
+ cxx_flag( platform, config, [ "-g -Wall" ] )
74
+
75
+ case platform
76
+ when :macos, :ios
77
+ c_flag( platform, config, [ "-fembed-bitcode" ] )
78
+ cxx_flag( platform, config, [ "-fembed-bitcode" ] )
79
+ end
80
+
81
+ case platform
82
+ when :android
83
+ cxx_flag( platform, config, [ "-fexceptions -frtti" ] )
84
+ end
85
+ end
86
+ }
87
+ }
88
+ end
89
+
90
+ def lib_dir( platform, config, dirs )
91
+ @lib_dirs[ platform ][ config ].concat( dirs )
92
+ end
93
+
94
+ def c_flag( platform, config, flags )
95
+ @c_flags[ platform ][ config ].concat( flags )
96
+ end
97
+
98
+ def cxx_flag( platform, config, flags )
99
+ @cxx_flags[ platform ][ config ].concat( flags )
100
+ end
101
+
102
+ def ld_flag( platform, config, flags )
103
+ @ld_flags[ platform ][ config ].concat( flags )
104
+ end
105
+
106
+ def execute( name, srcs, libs = [] )
107
+ @executes[ name ] = { :srcs => srcs, :libs => libs }
108
+ end
109
+
110
+ def library( name, srcs, libs = [] )
111
+ @libraries[ name ] = { :srcs => srcs, :libs => libs }
112
+ end
113
+
114
+ def setup
115
+ generate
116
+ end
117
+
118
+ def build
119
+ platform = Rush.env( "PLATFORM" )
120
+ config = Rush.env( "CONFIG" )
121
+ if platform.nil? || config.nil?
122
+ help
123
+ else
124
+ Rush.changed( "build/#{platform}" ){
125
+ Rush.sh( "rake build" ) if Rush.file?( "Rakefile" )
126
+ }
127
+ end
128
+ end
129
+
130
+ def help
131
+ puts "rake setup"
132
+ puts "rake help"
133
+ @platforms.each{|platform|
134
+ @configs.each{|config|
135
+ case platform
136
+ when :android
137
+ puts "ANDROID_NDK=/tmp/android-ndk-r10e PLATFORM=#{platform} CONFIG=#{config} rake build"
138
+ puts "ANDROID_NDK=/tmp/android-ndk-r10e ANDROID_STL=c++_static PLATFORM=#{platform} CONFIG=#{config} rake build"
139
+ puts "ANDROID_NDK=/tmp/android-ndk-r10e ANDROID_STL=gnustl_static PLATFORM=#{platform} CONFIG=#{config} rake build"
140
+ when :windows
141
+ @windows_runtimes.each{|runtime|
142
+ [ "Win32", "x64" ].each{|arch|
143
+ puts "WINDOWS_VISUAL_STUDIO_VERSION=2017 WINDOWS_RUNTIME=#{runtime} WINDOWS_ARCH=#{arch} CMAKE_GENERATOR=\"Visual Studio 15 2017\" PLATFORM=#{platform} CONFIG=#{config} rake build"
144
+ }
145
+ }
146
+ else
147
+ puts "PLATFORM=#{platform} CONFIG=#{config} rake build"
148
+ end
149
+ }
150
+ }
151
+ end
152
+
153
+ private
154
+ def lib_name( name )
155
+ lib_name = name
156
+ if /lib([a-zA-Z0-9_]+)\.a/ =~ name
157
+ lib_name = $1
158
+ end
159
+ lib_name
160
+ end
161
+
162
+ def generate
163
+ Rush.remaked( "build" ){
164
+ generate_common_build_files
165
+ generate_macos_build_files
166
+ generate_ios_build_files
167
+ generate_linux_build_files
168
+ generate_android_build_files
169
+ generate_windows_build_files
170
+ }
171
+ end
172
+
173
+ def generate_common_build_files
174
+ open( "#{@project_name}.cmake", "wb" ){|f|
175
+ f.puts <<EOS
176
+ message(CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE})
177
+ string(TOUPPER #{@project_name.upcase}_LINK_DIRS_${CMAKE_BUILD_TYPE} #{@project_name.upcase}_LINK_DIRS)
178
+ set(#{@project_name.upcase}_LINK_DIRS ${${#{@project_name.upcase}_LINK_DIRS}})
179
+ foreach(link_dir IN LISTS #{@project_name.upcase}_LINK_DIRS)
180
+ message(#{@project_name.upcase}_LINK_DIRS=${link_dir})
181
+ link_directories(${link_dir})
182
+ endforeach()
183
+
184
+ project(#{@project_name})
185
+
186
+ set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${CMAKE_LD_FLAGS_DEBUG}")
187
+ set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} ${CMAKE_LD_FLAGS_DEBUG}")
188
+ set(CMAKE_STATIC_LINKER_FLAGS_DEBUG "${CMAKE_STATIC_LINKER_FLAGS_DEBUG} ${CMAKE_LD_FLAGS_DEBUG}")
189
+
190
+ set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} ${CMAKE_LD_FLAGS_RELEASE}")
191
+ set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} ${CMAKE_LD_FLAGS_RELEASE}")
192
+ set(CMAKE_STATIC_LINKER_FLAGS_RELEASE "${CMAKE_STATIC_LINKER_FLAGS_RELEASE} ${CMAKE_LD_FLAGS_RELEASE}")
193
+
194
+ EOS
195
+
196
+ @inc_dirs.each{|dir|
197
+ dir = "${#{@project_name.upcase}_ROOT_DIR}/#{dir}" if dir =~ /^\./
198
+ f.puts <<EOS
199
+ include_directories(#{dir})
200
+ EOS
201
+ }
202
+
203
+ f.puts ""
204
+
205
+ @executes.each{|name, data|
206
+ f.puts "set(#{@project_name.upcase}_EXE_#{name.upcase}_SRCS)"
207
+ data[ :srcs ].each{|src|
208
+ src = "${#{@project_name.upcase}_ROOT_DIR}/#{src}" if src =~ /^\./
209
+ f.puts "set(#{@project_name.upcase}_EXE_#{name.upcase}_SRCS ${#{@project_name.upcase}_EXE_#{name.upcase}_SRCS} #{src})"
210
+ }
211
+
212
+ link_lib_names = []
213
+ data[ :libs ].each{|name|
214
+ link_lib_names.push name
215
+ }
216
+
217
+ f.puts <<EOS
218
+
219
+ add_executable(#{name} ${#{@project_name.upcase}_EXE_#{name.upcase}_SRCS})
220
+ target_link_libraries(#{name} #{link_lib_names.join( ' ' )})
221
+ EOS
222
+ }
223
+
224
+ @libraries.each{|name, data|
225
+ f.puts "set(#{@project_name.upcase}_LIB_#{name.upcase}_SRCS)"
226
+ data[ :srcs ].each{|src|
227
+ src = "${#{@project_name.upcase}_ROOT_DIR}/#{src}" if src =~ /^\./
228
+ f.puts "set(#{@project_name.upcase}_LIB_#{name.upcase}_SRCS ${#{@project_name.upcase}_LIB_#{name.upcase}_SRCS} #{src})"
229
+ }
230
+
231
+ link_lib_names = []
232
+ data[ :libs ].each{|name|
233
+ link_lib_name = "#{@project_name.upcase}_LIB_#{name.upcase}"
234
+ f.puts <<EOS
235
+ find_library(#{link_lib_name} NAMES lib#{name}.a #{name} PATHS ${#{@project_name.upcase}_LINK_DIRS}})
236
+ message(#{link_lib_name}=${#{link_lib_name}})
237
+ EOS
238
+ link_lib_names.push "${#{link_lib_name}}"
239
+ }
240
+
241
+ f.puts <<EOS
242
+
243
+ add_library(#{name}-shared SHARED ${#{@project_name.upcase}_LIB_#{name.upcase}_SRCS})
244
+ target_link_libraries(#{name}-shared #{link_lib_names.join( ' ' )})
245
+ SET_TARGET_PROPERTIES(#{name}-shared PROPERTIES OUTPUT_NAME #{name})
246
+
247
+ add_library(#{name}-static STATIC ${#{@project_name.upcase}_LIB_#{name.upcase}_SRCS})
248
+ target_link_libraries(#{name}-static #{link_lib_names.join( ' ' )})
249
+ SET_TARGET_PROPERTIES(#{name}-static PROPERTIES OUTPUT_NAME #{name})
250
+ EOS
251
+ }
252
+ }
253
+
254
+ open( "#{@project_name}.rb", "wb" ){|f|
255
+ f.puts <<EOS
256
+ require "buildrake"
257
+
258
+ def lipo_create( input_libraries, output_library )
259
+ input_libraries = input_libraries.join( ' ' ) if input_libraries.kind_of?( Array )
260
+ Buildrake::Rush.sh( "lipo -create \#{input_libraries} -output \#{output_library}" )
261
+ end
262
+
263
+ def lipo_info( library )
264
+ Buildrake::Rush.sh( "lipo -info \#{library}" )
265
+ end
266
+
267
+ def platform_path( platform, config )
268
+ path = ""
269
+ case platform
270
+ when "linux"
271
+ if Buildrake::Rush.file?( "/etc/system-release" )
272
+ line = `head -n 1 /etc/system-release`
273
+ else
274
+ line = "unsupported"
275
+ end
276
+ values = line.split( "\s" )
277
+ linux_name = values.shift.downcase
278
+ values.each{|value|
279
+ if /^([0-9]+)\./ =~ value
280
+ linux_name = "\#{linux_name}\#{$1}"
281
+ break
282
+ end
283
+ }
284
+ path = "linux/\#{linux_name}"
285
+ when "macos"
286
+ path = "macos/\#{\`xcrun --sdk macosx --show-sdk-version\`.chomp}"
287
+ when "ios"
288
+ path = "ios/\#{\`xcrun --sdk iphoneos --show-sdk-version\`.chomp}"
289
+ when "android"
290
+ android_ndk_version = Buildrake::Rush.env( "ANDROID_NDK" ).split( '-' ).last.chomp( '/' )
291
+ Buildrake::Rush.env( "ANDROID_NDK_VERSION", android_ndk_version )
292
+ path = "android/\#{android_ndk_version}"
293
+ path = "\#{path}_\#{Buildrake::Rush.env( 'ANDROID_STL' )}" if Buildrake::Rush.env?( 'ANDROID_STL' ) && ! Buildrake::Rush.env( 'ANDROID_STL' ).empty?
294
+ when "windows"
295
+ windows_visual_studio_version = Buildrake::Rush.env( "WINDOWS_VISUAL_STUDIO_VERSION" )
296
+ windows_runtime = Buildrake::Rush.env( "WINDOWS_RUNTIME" )
297
+ windows_arch = Buildrake::Rush.env( "WINDOWS_ARCH" )
298
+ path = "windows/\#{windows_visual_studio_version}_\#{windows_runtime}_\#{windows_arch}"
299
+ end
300
+ "\#{path}_\#{config}"
301
+ end
302
+
303
+ def cmake_files( prefix = "" )
304
+ [ "CMakeCache.txt", "CMakeFiles", "CMakeScripts", "Makefile", "cmake_install.cmake" ].map{|path| "\#{prefix}\#{path}"}
305
+ end
306
+
307
+ desc "Build"
308
+ task :build do
309
+ Buildrake::Rush.find( cmake_files ){|path|
310
+ Buildrake::Rush.remove( path )
311
+ }
312
+
313
+ build
314
+ end
315
+
316
+ if Buildrake::Rush.env?( "CONFIG" )
317
+ config = Buildrake::Rush.env( "CONFIG", Buildrake::Rush.pascal_case( Buildrake::Rush.env( 'CONFIG' ) ) )
318
+ else
319
+ config = Buildrake::Rush.env( "CONFIG", "Debug" )
320
+ end
321
+ puts "CONFIG=\#{config}"
322
+ Buildrake::Rush.env( "PLATFORM_PATH", "\#{platform_path( Buildrake::Rush.base_name( Buildrake::Rush.full_dir_path ), config )}" ) if ! Buildrake::Rush.env?( "PLATFORM_PATH" )
323
+ puts "PLATFORM_PATH=\#{Buildrake::Rush.env( 'PLATFORM_PATH' )}"
324
+ EOS
325
+ }
326
+ end
327
+
328
+ def generate_macos_build_files
329
+ Rush.maked( "macos" ){
330
+ open( "CMakeLists.txt", "wb" ){|f|
331
+ f.puts <<EOS
332
+ cmake_minimum_required(VERSION #{@cmake_version})
333
+
334
+ project(#{@project_name})
335
+
336
+ if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
337
+ set(CMAKE_MACOSX_RPATH 1)
338
+ endif()
339
+
340
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} #{@c_flags[ :macos ][ :debug ].join( ' ' )}")
341
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} #{@cxx_flags[ :macos ][ :debug ].join( ' ' )}")
342
+ set(CMAKE_LD_FLAGS_DEBUG "${CMAKE_LD_FLAGS_DEBUG} #{@ld_flags[ :macos ][ :debug ].join( ' ' )}")
343
+
344
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} #{@c_flags[ :macos ][ :release ].join( ' ' )}")
345
+ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} #{@cxx_flags[ :macos ][ :release ].join( ' ' )}")
346
+ set(CMAKE_LD_FLAGS_RELEASE "${CMAKE_LD_FLAGS_RELEASE} #{@ld_flags[ :macos ][ :release ].join( ' ' )}")
347
+
348
+ set(#{@project_name.upcase}_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
349
+ set(#{@project_name.upcase}_LINK_DIRS_DEBUG)
350
+ set(#{@project_name.upcase}_LINK_DIRS_RELEASE)
351
+ EOS
352
+
353
+ @lib_dirs[ :macos ][ :debug ].each{|dir|
354
+ dir = "${#{@project_name.upcase}_ROOT_DIR}/#{dir}" if dir =~ /^\./
355
+ f.puts <<EOS
356
+ set(#{@project_name.upcase}_LINK_DIRS_DEBUG ${#{@project_name.upcase}_LINK_DIRS_DEBUG} #{dir})
357
+ EOS
358
+ }
359
+
360
+ @lib_dirs[ :macos ][ :release ].each{|dir|
361
+ dir = "${#{@project_name.upcase}_ROOT_DIR}/#{dir}" if dir =~ /^\./
362
+ f.puts <<EOS
363
+ set(#{@project_name.upcase}_LINK_DIRS_RELEASE ${#{@project_name.upcase}_LINK_DIRS_RELEASE} #{dir})
364
+ EOS
365
+ }
366
+
367
+ f.puts <<EOS
368
+ include(${CMAKE_CURRENT_LIST_DIR}/../#{@project_name}.cmake)
369
+ EOS
370
+ }
371
+
372
+ open( "Rakefile", "wb" ){|f|
373
+ f.puts <<EOS
374
+ require File.expand_path( "../#{@project_name}", File.dirname( __FILE__ ) )
375
+
376
+ def build
377
+ config = Buildrake::Rush.env( "CONFIG" )
378
+ platform_path = platform_path( "macos", config )
379
+ Buildrake::Rush.remaked( Buildrake::Rush.base_name( platform_path ) ){
380
+ #{@macos_archs}.each{|arch|
381
+ Buildrake::Rush.remaked( arch ){
382
+ Buildrake::Rush.sh( "cmake ../.. -DCMAKE_BUILD_TYPE=\#{config} -DCMAKE_OSX_ARCHITECTURES=\#{arch} --no-warn-unused-cli -DPLATFORM=macos -DCONFIG=\#{config} -DPLATFORM_PATH=\#{platform_path}" )
383
+ Buildrake::Rush.sh( "make clean all" )
384
+ }
385
+ }
386
+
387
+ #{@libraries.keys}.each{|name|
388
+ ["lib\#{name}.a", "lib\#{name}.dylib"].each{|library|
389
+ ext_name = Buildrake::Rush.ext_name( library )
390
+ lipo_create( "*/*.\#{ext_name}", library )
391
+ lipo_info( library )
392
+ }
393
+ }
394
+
395
+ src = Buildrake::Rush.full_dir_path
396
+ dst = "\#{src}/../../../lib/\#{platform_path}"
397
+ #{@libraries.keys}.each{|name|
398
+ Buildrake::Rush.find( "lib\#{name}.*" ){|path|
399
+ Buildrake::Rush.maked( dst ){
400
+ Buildrake::Rush.rename( "\#{src}/\#{path}", "." )
401
+ }
402
+ }
403
+ }
404
+ }
405
+ end
406
+ EOS
407
+ }
408
+ }
409
+ end
410
+
411
+ def generate_ios_build_files
412
+ Rush.maked( "ios" ){
413
+ open( "CMakeLists.txt", "wb" ){|f|
414
+ f.puts <<EOS
415
+ cmake_minimum_required(VERSION #{@cmake_version})
416
+
417
+ project(#{@project_name})
418
+
419
+ if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
420
+ set(CMAKE_MACOSX_RPATH 1)
421
+ endif()
422
+
423
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} #{@c_flags[ :ios ][ :debug ].join( ' ' )}")
424
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} #{@cxx_flags[ :ios ][ :debug ].join( ' ' )}")
425
+ set(CMAKE_LD_FLAGS_DEBUG "${CMAKE_LD_FLAGS_DEBUG} #{@ld_flags[ :ios ][ :debug ].join( ' ' )}")
426
+
427
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} #{@c_flags[ :ios ][ :release ].join( ' ' )}")
428
+ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} #{@cxx_flags[ :ios ][ :release ].join( ' ' )}")
429
+ set(CMAKE_LD_FLAGS_RELEASE "${CMAKE_LD_FLAGS_RELEASE} #{@ld_flags[ :ios ][ :release ].join( ' ' )}")
430
+
431
+ set(#{@project_name.upcase}_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
432
+ set(#{@project_name.upcase}_LINK_DIRS_DEBUG)
433
+ set(#{@project_name.upcase}_LINK_DIRS_RELEASE)
434
+ EOS
435
+
436
+ @lib_dirs[ :ios ][ :debug ].each{|dir|
437
+ dir = "${#{@project_name.upcase}_ROOT_DIR}/#{dir}" if dir =~ /^\./
438
+ f.puts <<EOS
439
+ set(#{@project_name.upcase}_LINK_DIRS_DEBUG ${#{@project_name.upcase}_LINK_DIRS_DEBUG} #{dir})
440
+ EOS
441
+ }
442
+
443
+ @lib_dirs[ :ios ][ :release ].each{|dir|
444
+ dir = "${#{@project_name.upcase}_ROOT_DIR}/#{dir}" if dir =~ /^\./
445
+ f.puts <<EOS
446
+ set(#{@project_name.upcase}_LINK_DIRS_RELEASE ${#{@project_name.upcase}_LINK_DIRS_RELEASE} #{dir})
447
+ EOS
448
+ }
449
+
450
+ f.puts <<EOS
451
+ include(${CMAKE_CURRENT_LIST_DIR}/../#{@project_name}.cmake)
452
+ EOS
453
+ }
454
+
455
+ open( "Rakefile", "wb" ){|f|
456
+ f.puts <<EOS
457
+ require File.expand_path( "../#{@project_name}", File.dirname( __FILE__ ) )
458
+
459
+ def build
460
+ config = Buildrake::Rush.env( "CONFIG" )
461
+ platform_path = platform_path( "ios", config )
462
+ Buildrake::Rush.remaked( Buildrake::Rush.base_name( platform_path ) ){
463
+ #{@macos_archs}.each{|arch|
464
+ Buildrake::Rush.remaked( arch ){
465
+ Buildrake::Rush.sh( "cmake ../.. -DCMAKE_BUILD_TYPE=\#{config} -DCMAKE_OSX_ARCHITECTURES=\#{arch} -DCMAKE_OSX_SYSROOT=iphonesimulator --no-warn-unused-cli -DPLATFORM=ios -DCONFIG=\#{config} -DPLATFORM_PATH=\#{platform_path}" )
466
+ Buildrake::Rush.sh( "make clean all" )
467
+ }
468
+ }
469
+
470
+ #{@ios_archs}.each{|arch|
471
+ Buildrake::Rush.remaked( arch ){
472
+ Buildrake::Rush.sh( "cmake ../.. -DCMAKE_BUILD_TYPE=\#{config} -DCMAKE_OSX_ARCHITECTURES=\#{arch} -DCMAKE_OSX_SYSROOT=iphoneos --no-warn-unused-cli -DPLATFORM=ios -DCONFIG=\#{config} -DPLATFORM_PATH=\#{platform_path}" )
473
+ Buildrake::Rush.sh( "make clean all" )
474
+ }
475
+ }
476
+
477
+ #{@libraries.keys}.each{|name|
478
+ ["lib\#{name}.a", "lib\#{name}.dylib"].each{|library|
479
+ ext_name = Buildrake::Rush.ext_name( library )
480
+ lipo_create( "*/*.\#{ext_name}", library )
481
+ lipo_info( library )
482
+ }
483
+ }
484
+
485
+ src = Buildrake::Rush.full_dir_path
486
+ dst = "\#{src}/../../../lib/\#{platform_path}"
487
+ #{@libraries.keys}.each{|name|
488
+ Buildrake::Rush.find( "lib\#{name}.*" ){|path|
489
+ Buildrake::Rush.maked( dst ){
490
+ Buildrake::Rush.rename( "\#{src}/\#{path}", "." )
491
+ }
492
+ }
493
+ }
494
+ }
495
+ end
496
+ EOS
497
+ }
498
+ }
499
+ end
500
+
501
+ def generate_linux_build_files
502
+ Rush.maked( "linux" ){
503
+ open( "CMakeLists.txt", "wb" ){|f|
504
+ f.puts <<EOS
505
+ cmake_minimum_required(VERSION #{@cmake_version})
506
+
507
+ project(#{@project_name})
508
+
509
+ if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
510
+ set(CMAKE_MACOSX_RPATH 1)
511
+ endif()
512
+
513
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} #{@c_flags[ :linux ][ :debug ].join( ' ' )}")
514
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} #{@cxx_flags[ :linux ][ :debug ].join( ' ' )}")
515
+ set(CMAKE_LD_FLAGS_DEBUG "${CMAKE_LD_FLAGS_DEBUG} #{@ld_flags[ :linux ][ :debug ].join( ' ' )}")
516
+
517
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} #{@c_flags[ :linux ][ :release ].join( ' ' )}")
518
+ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} #{@cxx_flags[ :linux ][ :release ].join( ' ' )}")
519
+ set(CMAKE_LD_FLAGS_RELEASE "${CMAKE_LD_FLAGS_RELEASE} #{@ld_flags[ :linux ][ :release ].join( ' ' )}")
520
+
521
+ set(#{@project_name.upcase}_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
522
+ set(#{@project_name.upcase}_LINK_DIRS_DEBUG)
523
+ set(#{@project_name.upcase}_LINK_DIRS_RELEASE)
524
+ EOS
525
+
526
+ @lib_dirs[ :linux ][ :debug ].each{|dir|
527
+ dir = "${#{@project_name.upcase}_ROOT_DIR}/#{dir}" if dir =~ /^\./
528
+ f.puts <<EOS
529
+ set(#{@project_name.upcase}_LINK_DIRS_DEBUG ${#{@project_name.upcase}_LINK_DIRS_DEBUG} #{dir})
530
+ EOS
531
+ }
532
+
533
+ @lib_dirs[ :linux ][ :release ].each{|dir|
534
+ dir = "${#{@project_name.upcase}_ROOT_DIR}/#{dir}" if dir =~ /^\./
535
+ f.puts <<EOS
536
+ set(#{@project_name.upcase}_LINK_DIRS_RELEASE ${#{@project_name.upcase}_LINK_DIRS_RELEASE} #{dir})
537
+ EOS
538
+ }
539
+
540
+ f.puts <<EOS
541
+ include(${CMAKE_CURRENT_LIST_DIR}/../#{@project_name}.cmake)
542
+ EOS
543
+ }
544
+
545
+ open( "Rakefile", "wb" ){|f|
546
+ f.puts <<EOS
547
+ require File.expand_path( "../#{@project_name}", File.dirname( __FILE__ ) )
548
+
549
+ def build
550
+ config = Buildrake::Rush.env( "CONFIG" )
551
+ platform_path = platform_path( "linux", config )
552
+ Buildrake::Rush.remaked( Buildrake::Rush.base_name( platform_path ) ){
553
+ Buildrake::Rush.sh( "cmake .. -DCMAKE_BUILD_TYPE=\#{config} --no-warn-unused-cli -DPLATFORM=linux -DCONFIG=\#{config} -DPLATFORM_PATH=\#{platform_path}" )
554
+ Buildrake::Rush.sh( "make clean all" )
555
+
556
+ src = Buildrake::Rush.full_dir_path
557
+ dst = "\#{src}/../../../lib/\#{platform_path}"
558
+ #{@libraries.keys}.each{|name|
559
+ Buildrake::Rush.find( "lib\#{name}.*" ){|path|
560
+ Buildrake::Rush.maked( dst ){
561
+ Buildrake::Rush.rename( "\#{src}/\#{path}", "." )
562
+ }
563
+ }
564
+ }
565
+ }
566
+ end
567
+ EOS
568
+ }
569
+ }
570
+ end
571
+
572
+ def generate_android_build_files
573
+ project_name = @project_name.upcase
574
+ Rush.maked( "android" ){
575
+ Rush.maked( "jni" ){
576
+ open( "Application.mk", "wb" ){|f|
577
+ modules = []
578
+ @executes.each{|name, data|
579
+ modules.push name
580
+ }
581
+ @libraries.each{|name, data|
582
+ modules.push "#{name}-static #{name}-shared"
583
+ }
584
+
585
+ f.puts <<EOS
586
+ APP_MODULES := #{modules.join( ' ' )}
587
+ APP_PLATFORM := android-#{@android_api_level}
588
+ APP_ABI := #{@android_archs.join( ' ' )}
589
+ ifeq ($(APP_OPTIM),debug)
590
+ APP_CFLAGS := #{@c_flags[ :android ][ :debug ].join( ' ' )}
591
+ APP_CPPFLAGS := #{@cxx_flags[ :android ][ :debug ].join( ' ' )}
592
+ APP_LDFLAGS := #{@ld_flags[ :android ][ :debug ].join( ' ' )}
593
+ else
594
+ APP_CFLAGS := #{@c_flags[ :android ][ :release ].join( ' ' )}
595
+ APP_CPPFLAGS := #{@cxx_flags[ :android ][ :release ].join( ' ' )}
596
+ APP_LDFLAGS := #{@ld_flags[ :android ][ :release ].join( ' ' )}
597
+ endif
598
+ EOS
599
+ }
600
+
601
+ open( "Android.mk", "wb" ){|f|
602
+ f.puts <<EOS
603
+ LOCAL_PATH := $(call my-dir)/..
604
+
605
+ #{@project_name.upcase}_ROOT_DIR := $(LOCAL_PATH)/../..
606
+
607
+ EOS
608
+
609
+ local_settings = [
610
+ "LOCAL_CFLAGS := ",
611
+ "LOCAL_CXXFLAGS := ",
612
+ "LOCAL_LDLIBS := ",
613
+ ]
614
+
615
+ @inc_dirs.each{|dir|
616
+ dir = "$(#{@project_name.upcase}_ROOT_DIR)/#{dir}" if dir =~ /^\./
617
+ local_settings.push "LOCAL_CFLAGS += -I#{dir}"
618
+ local_settings.push "LOCAL_CXXFLAGS += -I#{dir}"
619
+ }
620
+
621
+ local_settings.push "ifeq ($(APP_OPTIM),debug)"
622
+ @lib_dirs[ :android ][ :debug ].each{|dir|
623
+ dir = "$(#{@project_name.upcase}_ROOT_DIR)/#{dir}" if dir =~ /^\./
624
+ local_settings.push " LOCAL_LDLIBS += -L#{dir}/libs/$(TARGET_ARCH_ABI)"
625
+ }
626
+ local_settings.push "else"
627
+ @lib_dirs[ :android ][ :release ].each{|dir|
628
+ dir = "$(#{@project_name.upcase}_ROOT_DIR)/#{dir}" if dir =~ /^\./
629
+ local_settings.push " LOCAL_LDLIBS += -L#{dir}/libs/$(TARGET_ARCH_ABI)"
630
+ }
631
+ local_settings.push "endif"
632
+
633
+ @executes.each{|name, data|
634
+ f.puts "#{@project_name.upcase}_EXE_#{name.upcase}_SRCS :="
635
+ data[ :srcs ].each{|src|
636
+ src = "$(#{@project_name.upcase}_ROOT_DIR)/#{src}" if src =~ /^\./
637
+ f.puts "#{@project_name.upcase}_EXE_#{name.upcase}_SRCS += #{src}"
638
+ }
639
+
640
+ ld_libs = []
641
+ data[ :libs ].each{|lib|
642
+ case Rush.ext_name( lib )
643
+ when "a"
644
+ ld_libs.push "LOCAL_LDLIBS += -l#{lib_name( lib )}"
645
+ else
646
+ ld_libs.push "LOCAL_LDLIBS += -l#{lib}"
647
+ end
648
+ }
649
+
650
+ f.puts <<EOS
651
+ include $(CLEAR_VARS)
652
+ LOCAL_MODULE := #{name}
653
+ LOCAL_SRC_FILES := $(#{@project_name.upcase}_EXE_#{name.upcase}_SRCS)
654
+ #{local_settings.join( "\n" )}
655
+ #{ld_libs.join( "\n" )}
656
+ $(info LOCAL_CFLAGS=$(LOCAL_CFLAGS))
657
+ $(info LOCAL_CXXFLAGS=$(LOCAL_CXXFLAGS))
658
+ $(info LOCAL_LDLIBS=$(LOCAL_LDLIBS))
659
+ include $(BUILD_EXECUTABLE)
660
+ EOS
661
+ }
662
+
663
+ @libraries.each{|name, data|
664
+ f.puts "#{@project_name.upcase}_LIB_#{name.upcase}_SRCS :="
665
+ data[ :srcs ].each{|src|
666
+ src = "$(#{@project_name.upcase}_ROOT_DIR)/#{src}" if src =~ /^\./
667
+ f.puts "#{@project_name.upcase}_LIB_#{name.upcase}_SRCS += #{src}"
668
+ }
669
+
670
+ ld_libs = []
671
+ data[ :libs ].each{|lib|
672
+ case Rush.ext_name( lib )
673
+ when "a"
674
+ ld_libs.push "LOCAL_LDLIBS += -l#{lib_name( lib )}"
675
+ else
676
+ ld_libs.push "LOCAL_LDLIBS += -l#{lib}"
677
+ end
678
+ }
679
+
680
+ f.puts <<EOS
681
+ include $(CLEAR_VARS)
682
+ LOCAL_MODULE := #{name}-static
683
+ LOCAL_MODULE_FILENAME := lib#{name}
684
+ LOCAL_SRC_FILES := $(#{@project_name.upcase}_LIB_#{name.upcase}_SRCS)
685
+ #{local_settings.join( "\n" )}
686
+ #{ld_libs.join( "\n" )}
687
+ $(info LOCAL_CFLAGS=$(LOCAL_CFLAGS))
688
+ $(info LOCAL_CXXFLAGS=$(LOCAL_CXXFLAGS))
689
+ $(info LOCAL_LDLIBS=$(LOCAL_LDLIBS))
690
+ include $(BUILD_STATIC_LIBRARY)
691
+
692
+ include $(CLEAR_VARS)
693
+ LOCAL_MODULE := #{name}-shared
694
+ LOCAL_MODULE_FILENAME := lib#{name}
695
+ LOCAL_SRC_FILES := $(#{@project_name.upcase}_LIB_#{name.upcase}_SRCS)
696
+ #{local_settings.join( "\n" )}
697
+ #{ld_libs.join( "\n" )}
698
+ $(info LOCAL_CFLAGS=$(LOCAL_CFLAGS))
699
+ $(info LOCAL_CXXFLAGS=$(LOCAL_CXXFLAGS))
700
+ $(info LOCAL_LDLIBS=$(LOCAL_LDLIBS))
701
+ include $(BUILD_SHARED_LIBRARY)
702
+ EOS
703
+ }
704
+ }
705
+ }
706
+
707
+ open( "Rakefile", "wb" ){|f|
708
+ f.puts <<EOS
709
+ require File.expand_path( "../#{@project_name}", File.dirname( __FILE__ ) )
710
+
711
+ def build
712
+ android_ndk = Buildrake::Rush.env( "ANDROID_NDK" )
713
+ abort( "Not found ANDROID_NDK: \#{android_ndk}" ) if android_ndk.nil? || ! Buildrake::Rush.dir?( android_ndk )
714
+ android_stl = Buildrake::Rush.env( "ANDROID_STL" )
715
+ puts "ANDROID_NDK=\#{android_ndk}"
716
+ puts "ANDROID_STL=\#{android_stl}"
717
+ config = Buildrake::Rush.env( "CONFIG" )
718
+ app_optim = config.downcase
719
+ puts "APP_OPTIM=\#{app_optim}"
720
+ platform_path = platform_path( "android", config )
721
+ Buildrake::Rush.remaked( Buildrake::Rush.base_name( platform_path ) ){
722
+ ndk_out_dir = "./ndk_out"
723
+ ndk_build = "\#{android_ndk}/ndk-build -B NDK_APP_DST_DIR='\#{ndk_out_dir}/${TARGET_ARCH_ABI}' NDK_OUT='\#{ndk_out_dir}' APP_OPTIM=\#{app_optim} PLATFORM=android CONFIG=\#{config} PLATFORM_PATH=\#{platform_path} ANDROID_NDK_VERSION=\#{Buildrake::Rush.env( 'ANDROID_NDK_VERSION' )}"
724
+ ndk_build = "\#{ndk_build} APP_STL=\#{android_stl}" if ! android_stl.nil? && ! android_stl.empty?
725
+ Buildrake::Rush.sh( ndk_build )
726
+
727
+ src = Buildrake::Rush.full_dir_path
728
+ dst = "\#{src}/../../../lib/\#{platform_path}/libs"
729
+ #{@libraries.keys}.each{|name|
730
+ Buildrake::Rush.find( "\#{src}/\#{ndk_out_dir}/local/*/lib\#{name}.*" ){|path|
731
+ arch = Buildrake::Rush.base_name( Buildrake::Rush.dir_path( path ) )
732
+ Buildrake::Rush.maked( "\#{dst}/\#{arch}" ){
733
+ Buildrake::Rush.rename( path, "." )
734
+ }
735
+ }
736
+ }
737
+ }
738
+ end
739
+ EOS
740
+ }
741
+ }
742
+ end
743
+
744
+ def generate_windows_build_files
745
+ Rush.maked( "windows" ){
746
+ open( "windows.cmake", "wb" ){|f|
747
+ f.puts <<EOS
748
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} #{@c_flags[ :windows ][ :debug ].join( ' ' )}")
749
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} #{@cxx_flags[ :windows ][ :debug ].join( ' ' )}")
750
+ set(CMAKE_LD_FLAGS_DEBUG "${CMAKE_LD_FLAGS_DEBUG} #{@ld_flags[ :windows ][ :debug ].join( ' ' )}")
751
+
752
+ set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} #{@c_flags[ :windows ][ :release ].join( ' ' )}")
753
+ set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} #{@cxx_flags[ :windows ][ :release ].join( ' ' )}")
754
+ set(CMAKE_LD_FLAGS_RELEASE "${CMAKE_LD_FLAGS_RELEASE} #{@ld_flags[ :windows ][ :release ].join( ' ' )}")
755
+
756
+ set(#{@project_name.upcase}_ROOT_DIR ${CMAKE_CURRENT_LIST_DIR}/../..)
757
+ set(#{@project_name.upcase}_LINK_DIRS_DEBUG)
758
+ set(#{@project_name.upcase}_LINK_DIRS_RELEASE)
759
+ EOS
760
+
761
+ @lib_dirs[ :windows ][ :debug ].each{|dir|
762
+ dir = "${#{@project_name.upcase}_ROOT_DIR}/#{dir}" if dir =~ /^\./
763
+ f.puts <<EOS
764
+ set(#{@project_name.upcase}_LINK_DIRS_DEBUG ${#{@project_name.upcase}_LINK_DIRS_DEBUG} #{dir})
765
+ EOS
766
+ }
767
+
768
+ @lib_dirs[ :windows ][ :release ].each{|dir|
769
+ dir = "${#{@project_name.upcase}_ROOT_DIR}/#{dir}" if dir =~ /^\./
770
+ f.puts <<EOS
771
+ set(#{@project_name.upcase}_LINK_DIRS_RELEASE ${#{@project_name.upcase}_LINK_DIRS_RELEASE} #{dir})
772
+ EOS
773
+ }
774
+
775
+ f.puts <<EOS
776
+ include(${CMAKE_CURRENT_LIST_DIR}/../#{@project_name}.cmake)
777
+ EOS
778
+ }
779
+
780
+ @windows_runtimes.each{|runtime|
781
+ Rush.maked( "#{runtime}" ){
782
+ open( "CMakeLists.txt", "wb" ){|f|
783
+ f.puts <<EOS
784
+ cmake_minimum_required(VERSION #{@cmake_version})
785
+
786
+ project(#{@project_name})
787
+
788
+ include(${CMAKE_CURRENT_LIST_DIR}/../windows.cmake)
789
+
790
+ set(Flags
791
+ CMAKE_C_FLAGS
792
+ CMAKE_C_FLAGS_DEBUG
793
+ CMAKE_C_FLAGS_RELEASE
794
+ CMAKE_CXX_FLAGS
795
+ CMAKE_CXX_FLAGS_DEBUG
796
+ CMAKE_CXX_FLAGS_RELEASE
797
+ )
798
+ foreach(Flag ${Flags})
799
+ string(REPLACE "/MD" "/#{runtime}" ${Flag} "${${Flag}}")
800
+ string(REGEX REPLACE "/Z[i|I]" "/Z7" ${Flag} "${${Flag}}")
801
+ endforeach()
802
+ EOS
803
+ }
804
+ }
805
+ }
806
+
807
+ open( "Rakefile", "wb" ){|f|
808
+ f.puts <<EOS
809
+ require File.expand_path( "../#{@project_name}", File.dirname( __FILE__ ) )
810
+
811
+ def build
812
+ config = Buildrake::Rush.env( "CONFIG" )
813
+ windows_visual_studio_version = Buildrake::Rush.env( "WINDOWS_VISUAL_STUDIO_VERSION" )
814
+ windows_runtime = Buildrake::Rush.env( "WINDOWS_RUNTIME" )
815
+ windows_arch = Buildrake::Rush.env( "WINDOWS_ARCH" )
816
+ cmake_generator = Buildrake::Rush.env( "CMAKE_GENERATOR" )
817
+ platform_path = platform_path( "windows", config )
818
+ Buildrake::Rush.remaked( Buildrake::Rush.base_name( platform_path ) ){
819
+ Buildrake::Rush.sh( "cmake ../\#{windows_runtime} -DCMAKE_CONFIGURATION_TYPES=\#{config} -DCMAKE_BUILD_TYPE=\#{config} -G\\"\#{cmake_generator}\\" -A\\"\#{windows_arch}\\" --no-warn-unused-cli -DPLATFORM=windows -DCONFIG=\#{config} -DPLATFORM_PATH=\#{platform_path}" )
820
+ Buildrake::Rush.sh( "msbuild #{@project_name}.sln /m /t:Rebuild /p:Configuration=\#{config} /p:Platform=\\"\#{windows_arch}\\"" )
821
+
822
+ built_files = []
823
+ Buildrake::Rush.changed( config ){
824
+ Buildrake::Rush.find( "\#{Buildrake::Rush.full_dir_path}/*" ){|path|
825
+ built_files.push path
826
+ }
827
+ }
828
+ Buildrake::Rush.maked( "../../../lib/\#{platform_path}" ){
829
+ built_files.each{|built_file|
830
+ Buildrake::Rush.rename( built_file, "." )
831
+ }
832
+ }
833
+ }
834
+ end
835
+ EOS
836
+ }
837
+ }
838
+ end
839
+ end
840
+ end