Class: Buildrake::Config
- Inherits:
-
Object
- Object
- Buildrake::Config
- Defined in:
- lib/buildrake/config.rb
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
- #c_flag(platform, config, flags) ⇒ Object
- #cxx_flag(platform, config, flags) ⇒ Object
- #execute(name, srcs, libs = []) ⇒ Object
- #help ⇒ Object
-
#initialize(project_name, root_path) ⇒ Config
constructor
A new instance of Config.
- #ld_flag(platform, config, flags) ⇒ Object
- #lib_dir(platform, config, dirs) ⇒ Object
- #library(name, srcs, libs = []) ⇒ Object
- #setup ⇒ Object
Constructor Details
#initialize(project_name, root_path) ⇒ Config
Returns a new instance of Config.
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 |
# File 'lib/buildrake/config.rb', line 28 def initialize( project_name, root_path ) @project_name = project_name @root_path = root_path @inc_dirs = [] @lib_dirs = {} @c_flags = {} @cxx_flags = {} @ld_flags = {} @platforms = [ :macos, :ios, :android, :linux, :windows ] @configs = [ :debug, :release ] @windows_runtimes = [ "MT", "MD" ] @macos_archs = [ "x86_64" ] @ios_archs = [ "armv7", "armv7s", "arm64" ] @android_archs = [ "x86", "armeabi-v7a", "arm64-v8a" ] @android_api_level = 21 @cmake_version = "2.8" @executes = {} @libraries = {} @platforms.each{|platform| @lib_dirs[ platform ] = {} @c_flags[ platform ] = {} @cxx_flags[ platform ] = {} @ld_flags[ platform ] = {} @configs.each{|config| @lib_dirs[ platform ][ config ] = [] @c_flags[ platform ][ config ] = [] @cxx_flags[ platform ][ config ] = [] @ld_flags[ platform ][ config ] = [] case platform when :windows c_flag( platform, config, [ "/W4" ] ) cxx_flag( platform, config, [ "/W4" ] ) else c_flag( platform, config, [ "-g -Wall" ] ) cxx_flag( platform, config, [ "-g -Wall" ] ) case platform when :macos, :ios c_flag( platform, config, [ "-fembed-bitcode" ] ) cxx_flag( platform, config, [ "-fembed-bitcode" ] ) end case platform when :android cxx_flag( platform, config, [ "-fexceptions -frtti" ] ) end end } } end |
Class Method Details
.method_accessor(*names) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/buildrake/config.rb', line 7 def self.method_accessor( *names ) names.each{|name| class_eval <<EOS def #{name}( *args ) args.empty? ? @#{name} : @#{name} = args.first end EOS } end |
.run(argv) ⇒ Object
3 4 5 |
# File 'lib/buildrake/config.rb', line 3 def self.run( argv ) self.new.public_send( argv.shift, *argv ) if ! argv.empty? end |
Instance Method Details
#build ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/buildrake/config.rb', line 118 def build platform = Rush.env( "PLATFORM" ) config = Rush.env( "CONFIG" ) if platform.nil? || config.nil? help else Rush.changed( "build/#{platform}" ){ Rush.sh( "rake build" ) if Rush.file?( "Rakefile" ) } end end |
#c_flag(platform, config, flags) ⇒ Object
94 95 96 |
# File 'lib/buildrake/config.rb', line 94 def c_flag( platform, config, flags ) @c_flags[ platform ][ config ].concat( flags ) end |
#cxx_flag(platform, config, flags) ⇒ Object
98 99 100 |
# File 'lib/buildrake/config.rb', line 98 def cxx_flag( platform, config, flags ) @cxx_flags[ platform ][ config ].concat( flags ) end |
#execute(name, srcs, libs = []) ⇒ Object
106 107 108 |
# File 'lib/buildrake/config.rb', line 106 def execute( name, srcs, libs = [] ) @executes[ name ] = { :srcs => srcs, :libs => libs } end |
#help ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/buildrake/config.rb', line 130 def help puts "rake setup" puts "rake help" @platforms.each{|platform| @configs.each{|config| case platform when :android puts "ANDROID_NDK=/tmp/android-ndk-r10e PLATFORM=#{platform} CONFIG=#{config} rake build" puts "ANDROID_NDK=/tmp/android-ndk-r10e ANDROID_STL=c++_static PLATFORM=#{platform} CONFIG=#{config} rake build" puts "ANDROID_NDK=/tmp/android-ndk-r10e ANDROID_STL=gnustl_static PLATFORM=#{platform} CONFIG=#{config} rake build" when :windows @windows_runtimes.each{|runtime| [ "Win32", "x64" ].each{|arch| puts "WINDOWS_VISUAL_STUDIO_VERSION=2017 WINDOWS_RUNTIME=#{runtime} WINDOWS_ARCH=#{arch} CMAKE_GENERATOR=\"Visual Studio 15 2017\" PLATFORM=#{platform} CONFIG=#{config} rake build" } } else puts "PLATFORM=#{platform} CONFIG=#{config} rake build" end } } end |
#ld_flag(platform, config, flags) ⇒ Object
102 103 104 |
# File 'lib/buildrake/config.rb', line 102 def ld_flag( platform, config, flags ) @ld_flags[ platform ][ config ].concat( flags ) end |
#lib_dir(platform, config, dirs) ⇒ Object
90 91 92 |
# File 'lib/buildrake/config.rb', line 90 def lib_dir( platform, config, dirs ) @lib_dirs[ platform ][ config ].concat( dirs ) end |
#library(name, srcs, libs = []) ⇒ Object
110 111 112 |
# File 'lib/buildrake/config.rb', line 110 def library( name, srcs, libs = [] ) @libraries[ name ] = { :srcs => srcs, :libs => libs } end |
#setup ⇒ Object
114 115 116 |
# File 'lib/buildrake/config.rb', line 114 def setup generate end |