ryb 0.1.3.1 → 0.2.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +36 -47
  3. data/NOTES +0 -0
  4. data/README.md +3 -1
  5. data/TODO +4 -0
  6. data/bin/ryb +2 -42
  7. data/lib/ryb.rb +31 -20
  8. data/lib/ryb/cli.rb +103 -0
  9. data/lib/ryb/code.rb +7 -0
  10. data/lib/ryb/configuration.rb +18 -12
  11. data/lib/ryb/configurations.rb +9 -0
  12. data/lib/ryb/dependencies.rb +7 -0
  13. data/lib/ryb/dependency.rb +30 -0
  14. data/lib/ryb/dsl.rb +280 -0
  15. data/lib/ryb/environment.rb +9 -0
  16. data/lib/ryb/flags.rb +17 -0
  17. data/lib/ryb/gem.rb +58 -0
  18. data/lib/ryb/helpers/defaults.rb +26 -0
  19. data/lib/ryb/helpers/pretty_string.rb +47 -0
  20. data/lib/ryb/languages.rb +13 -0
  21. data/lib/ryb/name.rb +3 -5
  22. data/lib/ryb/ninja.rb +257 -200
  23. data/lib/ryb/paths.rb +7 -0
  24. data/lib/ryb/preprocessor.rb +10 -0
  25. data/lib/ryb/product.rb +31 -0
  26. data/lib/ryb/project.rb +6 -29
  27. data/lib/ryb/source_file.rb +62 -0
  28. data/lib/ryb/visual_studio.rb +93 -57
  29. data/lib/rybfile.rb +30 -10
  30. data/lib/rybfile/walker.rb +202 -0
  31. data/lib/yb.rb +4 -0
  32. data/lib/ybfile.rb +3 -0
  33. data/ryb.gemspec +18 -13
  34. data/ryb.sublime-project +18 -17
  35. metadata +45 -31
  36. data/lib/ryb/application.rb +0 -24
  37. data/lib/ryb/architecture.rb +0 -16
  38. data/lib/ryb/architectures/x86.rb +0 -11
  39. data/lib/ryb/architectures/x86_64.rb +0 -11
  40. data/lib/ryb/library.rb +0 -29
  41. data/lib/ryb/properties.rb +0 -10
  42. data/lib/ryb/properties/architectures.rb +0 -32
  43. data/lib/ryb/properties/configurations.rb +0 -29
  44. data/lib/ryb/properties/defines.rb +0 -31
  45. data/lib/ryb/properties/dependencies.rb +0 -23
  46. data/lib/ryb/properties/files.rb +0 -25
  47. data/lib/ryb/properties/flags.rb +0 -33
  48. data/lib/ryb/properties/named.rb +0 -17
  49. data/lib/ryb/properties/paths.rb +0 -37
  50. data/lib/ryb/properties/suffix.rb +0 -17
  51. data/lib/ryb/properties/targets.rb +0 -36
  52. data/lib/ryb/target.rb +0 -16
  53. data/lib/ryb/targets/linux.rb +0 -11
  54. data/lib/ryb/targets/macosx.rb +0 -33
  55. data/lib/ryb/targets/windows.rb +0 -13
  56. data/lib/ryb/version.rb +0 -11
  57. data/lib/ryb/windows.rb +0 -40
  58. data/lib/ryb/xcode.rb +0 -145
@@ -1,9 +1,7 @@
1
1
  module Ryb
2
- class Name < String
3
- attr_reader :pretty
4
- def initialize(name, pretty)
5
- super(name)
6
- @pretty = pretty
2
+ class Name < Helpers::PrettyString
3
+ def canonicalize
4
+ self.to_s
7
5
  end
8
6
  end
9
7
  end
@@ -1,200 +1,257 @@
1
- require 'ryb/project'
2
- require 'ryb/windows'
3
- require 'ryb/visual_studio'
4
-
5
- module Ryb
6
- module Ninja
7
- def self.generate_build_file_for(project, opts={})
8
- case Ryb.platform
9
- when :windows
10
- raise 'Unable to find Windows SDK.' unless Ryb::Windows.sdk?
11
- raise 'Unable to find Visual Studio.' unless Ryb::VisualStudio.installed?
12
-
13
- puts "Generating build.ninja..."
14
- ::Ninja::File.new "#{opts[:root]}/build.ninja" do
15
- variable 'root', opts[:root]
16
- variable 'built', opts[:built]
17
-
18
- # TODO(mtwilliams): Respect project.targets[:windows].sdk.
19
- variable 'WindowsSdkDir', Ryb::Windows.sdk
20
- variable 'VCInstallDir', Ryb::VisualStudio.install
21
-
22
- variable 'cl', "cl.exe"
23
- variable 'lib', "lib.exe"
24
- variable 'link', "link.exe"
25
-
26
- project.configurations.each do |_, config|
27
- [:windows].map{|target| project.targets[target]}.compact.each do |target|
28
- [:x86, :x86_64].map{|arch| project.architectures[arch]}.compact.each do |arch|
29
- triplet = "#{config.name}_#{target.name}_#{arch.name}"
30
- (project.applications+project.libraries).each do |buildable|
31
- name = "#{buildable.name.pretty||buildable.name.capitalize} (#{config.name.pretty||config.name.capitalize}) for #{target.name.pretty||target.name.capitalize} (#{arch.name.pretty||arch.name.capitalize})"
32
- puts " Adding '#{name}'..."
33
- quadruplet = "#{buildable.name}_#{triplet}"
34
- variable "#{quadruplet}_name", name
35
- variable "#{quadruplet}_suffix",
36
- "#{config.suffix||''}#{target.suffix||''}#{arch.suffix||''}"
37
- defines = {}
38
- flags = {}
39
- if buildable.configurations[config.name]
40
- defines = buildable.defines.merge(buildable.configurations[config.name].defines)
41
- flags = buildable.flags.merge(buildable.configurations[config.name].flags)
42
- else
43
- defines = buildable.defines
44
- flags = buildable.flags
45
- end
46
- defines = project.defines.merge(arch.defines.merge(target.defines.merge(config.defines.merge(defines))))
47
- flags = arch.flags.merge(target.flags.merge(config.flags.merge(flags)))
48
- # TODO(mtwilliams): Union paths after expansion.
49
- paths = {:includes => project.paths[:includes] | buildable.paths[:includes],
50
- :libraries => project.paths[:libraries] | buildable.paths[:libraries],
51
- :binaries => project.paths[:binaries] | buildable.paths[:binaries]}
52
- expand_path_variables = lambda {|path| path.gsub(/\$built/i, "${built}")}
53
- includes = paths[:includes].map(&expand_path_variables).map{|path| File.expand_path(path)}
54
- libraries = paths[:libraries].map(&expand_path_variables).map{|path| File.expand_path(path)}
55
- binaries = paths[:binaries].map(&expand_path_variables).map{|path| File.expand_path(path)}
56
- variable "#{quadruplet}_defines", defines.map{|name, value| "/D#{name}=#{value}"}.join(' ')
57
- cflags = []
58
- cflags.push("/I\"${WindowsSdkDir}/Include\" /I\"${VCInstallDir}/include\"")
59
- cflags.push('/arch:IA32') if arch.name == 'x86'
60
- if flags[:generate_debug_symbols]
61
- cflags.push('/MDd /Zi')
62
- else
63
- cflags.push('/MD')
64
- end
65
- cflags.push({:none => '/Od /RTCsu /fp:precise /fp:except',
66
- :size => '/O1 /fp:fast /fp:except-',
67
- :speed => '/Ox /fp:fast /fp:except-'}[flags[:optimization]||:none])
68
- includes.each{|includes_search_dir| cflags.push("/I\"#{includes_search_dir}\"")}
69
- ldflags = []
70
- if arch.name == 'x86'
71
- ldflags.push('/machine:X86')
72
- ldflags.push("/LIBPATH:\"${WindowsSdkDir}/Lib\" /LIBPATH:\"${VCInstallDir}/Lib\"")
73
- elsif arch.name == 'x86_64'
74
- ldflags.push('/machine:X64')
75
- ldflags.push("/LIBPATH:\"${WindowsSdkDir}/Lib/x64\" /LIBPATH:\"${VCInstallDir}/Lib/amd64\"")
76
- end
77
- ldflags.push('/DEBUG') if flags[:generate_debug_symbols]
78
- libraries.each{|libraries_search_dir| ldflags.push("/LIBPATH:\"#{libraries_search_dir}\"")}
79
- binaries.each{|binaries_search_dir| ldflags.push("/LIBPATH:\"#{binaries_search_dir}\"")}
80
- variable "#{quadruplet}_cflags", cflags.join(' ')
81
- variable "#{quadruplet}_ldflags", ldflags.join(' ')
82
- arflags = []
83
- variable "#{quadruplet}_arflags", arflags.join(' ')
84
- # TODO(mtwilliams): Refactor into cc, ld, and ar rules, using variables under build(s) for uncommonalities.
85
- rule "cc_#{quadruplet}",
86
- "${cl} /nologo /c /showIncludes /favor:blend /GF /GR- /W4 ${#{quadruplet}_cflags} ${#{quadruplet}_defines} /Fo$out $in",
87
- :dependencies => :msvc
88
- rule "ld_#{quadruplet}",
89
- "${link} /nologo /manifest:no ${#{quadruplet}_ldflags} /OUT:$out $in"
90
- rule "ar_#{quadruplet}",
91
- "${lib} /nologo ${#{quadruplet}_arflags} /OUT:$out $in"
92
- sources = buildable.files[:source].select{|file| /\.(c|cc|cpp)\z/.match(file)}
93
- outputs_to_inputs = Hash[sources.map{|source| ["${built}/obj/#{source.gsub(/\.[^.]+\z/,'')}.#{triplet}.obj", "${root}/#{source}"]}]
94
- build "cc_#{quadruplet}", outputs_to_inputs
95
- output = "#{buildable.name}${#{quadruplet}_suffix}"
96
- inputs = outputs_to_inputs.map{|object,_| object}
97
- dependencies = []
98
- buildable.dependencies.each do |dependency|
99
- as_buildable = (project.libraries.select{|buildable| buildable.name == dependency}).first
100
- if as_buildable
101
- case as_buildable.linkage
102
- when :static
103
- dependencies.push("${built}/lib/#{as_buildable.name}${#{as_buildable.name}_#{triplet}_suffix}.lib")
104
- when :dynamic
105
- # TODO(mtwilliams): Move import libraries to ${built}/lib.
106
- dependencies.push("${built}/bin/#{as_buildable.name}${#{as_buildable.name}_#{triplet}_suffix}.lib")
107
- end
108
- else
109
- # TODO(mtwilliams): Check search paths for the existence of the library.
110
- dependencies.push(dependency)
111
- end
112
- end
113
- if buildable.is_a? Ryb::Application
114
- build "ld_#{quadruplet}", "${built}/bin/#{output}.exe" => inputs+dependencies
115
- defaults "${built}/bin/#{output}.exe"
116
- elsif buildable.is_a? Ryb::Library
117
- case buildable.linkage
118
- when :static
119
- build "ar_#{quadruplet}", "${built}/lib/#{output}.lib" => inputs
120
- when :dynamic
121
- # TODO(mtwilliams): Specify -DLL.
122
- build "ld_#{quadruplet}", "${built}/bin/#{output}.dll" => inputs+dependencies
123
- end
124
- end
125
- end
126
- end
127
- end
128
- end
129
- end
130
-
131
- # TODO(mtwilliams): Generate shell and batch scripts, instead.
132
- puts "Generating Makefile..."
133
- ::File.open("#{opts[:root]}/Makefile", 'w') do |f|
134
- f.write "# This file was auto-generated by \"#{::File.basename($PROGRAM_NAME, ::File.extname($0))}\".\n"
135
- f.write "# Do not modify! Instead, modify the aforementioned program.\n\n"
136
-
137
- f.write "WindowsSdkDir := /#{Ryb::Windows.sdk.gsub(/\\/,'/').gsub(/\:/,'')}\n\n"
138
- f.write "VCInstallDir := /#{Ryb::VisualStudio.install.gsub(/\\/,'/').gsub(/\:/,'')}\n"
139
-
140
- f.write "# HACK: The Common7/IDE path might not exist in older versions of Microsoft Visual Studio.\n"
141
- f.write "CommonTools := $(shell readlink -f \"$(VCInstallDir)/../Common7\")\n\n"
142
-
143
- targets = []
144
- project.configurations.each do |_, config|
145
- [:windows].map{|target| project.targets[target]}.compact.each do |target|
146
- [:x86, :x86_64].map{|arch| project.architectures[arch]}.compact.each do |arch|
147
- triplet = "#{config.name}-#{target.name}-#{arch.name}"
148
- (project.applications + project.libraries).each do |buildable|
149
- quadruplet = "#{buildable.name}-#{triplet}"
150
- targets.push(quadruplet)
151
- end
152
- end
153
- end
154
- end
155
-
156
- f.write ".PHONY: all clean #{targets.join(' ')}\n"
157
- f.write "all: #{targets.join(' ')}\n\n"
158
- f.write "clean: \n"
159
- f.write "\t@rm -rf #{opts[:built]}\n\n"
160
-
161
- project.configurations.each do |_, config|
162
- [:windows].map{|target| project.targets[target]}.compact.each do |target|
163
- [:x86, :x86_64].map{|arch| project.architectures[arch]}.compact.each do |arch|
164
- triplet = [config.name, target.name, arch.name]
165
- (project.applications + project.libraries).each do |buildable|
166
- quadruplet = [buildable.name, triplet]
167
- case arch.name
168
- when 'x86'
169
- f.write "#{quadruplet.join('-')}: export PATH := $(WindowsSdkDir)/bin:$(CommonTools)/IDE:$(VCInstallDir)/bin:$(PATH)\n"
170
- when 'x86_64'
171
- f.write "#{quadruplet.join('-')}: export PATH := $(WindowsSdkDir)/bin/x64:$(CommonTools)/IDE:$(VCInstallDir)/bin/x86_amd64:$(VCInstallDir)/bin:$(PATH)\n"
172
- end
173
- f.write "#{quadruplet.join('-')}:\n"
174
- suffix = "#{config.suffix||''}#{target.suffix||''}#{arch.suffix||''}"
175
- if buildable.is_a? Ryb::Application
176
- f.write "\t@ninja #{opts[:built]}/bin/#{buildable.name}#{suffix}.exe\n\n"
177
- elsif buildable.is_a? Ryb::Library
178
- case buildable.linkage
179
- when :static
180
- f.write "\t@ninja #{opts[:built]}/lib/#{buildable.name}#{suffix}.lib\n\n"
181
- when :dynamic
182
- f.write "\t@ninja #{opts[:built]}/bin/#{buildable.name}#{suffix}.dll\n\n"
183
- end
184
- end
185
- end
186
- end
187
- end
188
- end
189
- end
190
-
191
- puts "Done."
192
- # when :macosx
193
- # when :linux
194
- # when :bsd
195
- else
196
- raise 'Unsupported platform!'
197
- end
198
- end
199
- end
200
- end
1
+ module Ryb
2
+ module Ninja
3
+ class Generator
4
+ def initialize(rybfile, opts)
5
+ @rybfile = rybfile
6
+ @root = opts.fetch(:root, '.')
7
+ @build = opts.fetch(:build, '_build')
8
+ @ninjafile = ::Ninja::File.new
9
+ @path = opts.fetch(:ninjafile, "#{@root}/build.ninja")
10
+
11
+ # HACK(mtwilliams): Create directory structure.
12
+ require 'fileutils'
13
+ FileUtils.mkdir_p(["#@build/bin", "#@build/lib", "#@build/obj"])
14
+
15
+ # HACK(mtwilliams): Assume VisualStudio.
16
+ @vs = ::VisualStudio.latest
17
+ @vc = @vs.products[:c_and_cpp]
18
+ end
19
+
20
+ def generate
21
+ @ninjafile.save(@path)
22
+ end
23
+
24
+ # TODO(mtwilliams): Generate phony commands that proxy to all triplets.
25
+ def on_project(project)
26
+ puts "=> #{project.name.pretty || project.name}"
27
+ end
28
+
29
+ def on_product(project, product)
30
+ puts " -> Generating for #{product.name.pretty || product.name}"
31
+ end
32
+
33
+ def on_project_triplet(project, tripletised)
34
+ end
35
+
36
+ def on_product_triplet(project, product, tripletised)
37
+ tripletised = tripletised.()
38
+
39
+ config = tripletised.configuration.name.to_sym
40
+ platform = tripletised.platform.name.to_sym
41
+ arch = tripletised.architecture.name.to_sym
42
+
43
+ puts " ~> #{config} for #{platform} (#{arch})"
44
+
45
+ name = product.name.canonicalize
46
+ namespace = "#{name}_#{tripletised.triplet.join('_')}"
47
+
48
+ sdk = @vc.sdks[:windows].select{|sdk| sdk.version == '7.1'}.first
49
+ sys_include_paths = @vc.includes + sdk.includes
50
+ sys_lib_paths = @vc.libraries[arch] + sdk.libraries[arch]
51
+
52
+ @ninjafile.variable "#{namespace}_cflags_sys", VisualStudio::Compiler.include_paths_to_flags(sys_include_paths).join(' ')
53
+ @ninjafile.variable "#{namespace}_ldflags_sys", VisualStudio::Linker.library_paths_to_flags(sys_lib_paths).join(' ')
54
+
55
+ cflags = cflags_for_product(project, product, tripletised)
56
+ arflags = arflags_for_product(project, product, tripletised)
57
+ ldflags = ldflags_for_product(project, product, tripletised)
58
+
59
+ @ninjafile.variable "#{namespace}_cflags", cflags.join(' ')
60
+ @ninjafile.variable "#{namespace}_cxxflags", "$#{namespace}_cflags"
61
+ @ninjafile.variable "#{namespace}_arflags", arflags.join(' ')
62
+ @ninjafile.variable "#{namespace}_ldflags", ldflags.join(' ')
63
+
64
+ sources = sources_for_product(product, tripletised)
65
+ @ninjafile.variable "#{namespace}_sources", sources.map{|src| "#@root/#{src.path}"}.join(' ')
66
+
67
+ deps = deps_for_product(product, tripletised)
68
+ @ninjafile.variable "#{namespace}_deps", deps.join(' ')
69
+
70
+ artifacts = artifacts_for_product(product, tripletised)
71
+ @ninjafile.variable "#{namespace}_artifacts", artifacts.join(' ')
72
+ @ninjafile.variable("#{namespace}_as_linkable", artifacts[0]) if product.is_a? Ryb::Library
73
+ @ninjafile.variable "#{namespace}_symbols", artifacts[0].gsub(/\.(exe|lib|dll)/, ".pdb")
74
+
75
+ # https://github.com/ninja-build/ninja/blob/d1763746b65cc7349d4ed9478befdb651aa24589/src/msvc_helper_main-win32.cc#L38
76
+ # ninja -t msvc -e _build/#{namespace}.env -- cl.exe ...
77
+ env_block = "#@build/#{namespace}.env_block"
78
+ env = @vc.environment(target: {platform: :windows, architecture: arch})
79
+ # "PATH=#{(@vc.binaries[arch] + sdk.binaries[arch]).join(';')}\0"
80
+ File.write(env_block, env.map{|env_var, value| "#{env_var}=#{value}"}.join("\0"))
81
+
82
+ @ninjafile.rule(
83
+ "cc_#{namespace}",
84
+ "ninja -t msvc -e #{env_block} -- cl.exe $#{namespace}_cflags_sys $#{namespace}_cflags /Fd$#{namespace}_symbols /Fo$out /Tc$in"
85
+ )
86
+
87
+ @ninjafile.rule(
88
+ "cxx_#{namespace}",
89
+ "ninja -t msvc -e #{env_block} -- cl.exe $#{namespace}_cxxflags_sys $#{namespace}_cxxflags /Fd$#{namespace}_symbols /Fo$out /Tp$in"
90
+ )
91
+
92
+ @ninjafile.rule(
93
+ "ar_#{namespace}",
94
+ "ninja -t msvc -e #{env_block} -- lib.exe $#{namespace}_arflags /OUT:$out $in"
95
+ )
96
+
97
+ @ninjafile.rule(
98
+ "ld_#{namespace}",
99
+ "ninja -t msvc -e #{env_block} -- link.exe $#{namespace}_ldflags_sys $#{namespace}_ldflags /OUT:$out $#{namespace}_deps $in"
100
+ )
101
+
102
+ @ninjafile.rule(
103
+ "so_#{namespace}",
104
+ "ninja -t msvc -e #{env_block} -- link.exe $#{namespace}_ldflags_sys $#{namespace}_ldflags /DLL /OUT:$out $#{namespace}_deps $in"
105
+ )
106
+
107
+ c_sources = sources.select{|src| src.language == :c}.map(&:path).map{|src| "#@root/#{src}"}
108
+ c_objects = c_sources.map{|src| src.gsub(/\.(c)/, ".#{namespace}.obj")}.map{|obj| "#@build/obj/#{obj}"}
109
+ cxx_sources = sources.select{|src| src.language == :cpp}.map(&:path).map{|src| "#@root/#{src}"}
110
+ cxx_objects = cxx_sources.map{|src| src.gsub(/\.(cc|cpp|cxx|c++)/, ".#{namespace}.obj")}.map{|obj| "#@build/obj/#{obj}"}
111
+
112
+ @ninjafile.build "cc_#{namespace}", Hash[c_objects.zip(c_sources)]
113
+ @ninjafile.build "cxx_#{namespace}", Hash[cxx_objects.zip(cxx_sources)]
114
+
115
+ case product
116
+ when Ryb::Application
117
+ @ninjafile.build "ld_#{namespace}", {artifacts[0] => c_objects + cxx_objects}
118
+ when Ryb::Library
119
+ case product.linkage
120
+ when :static
121
+ @ninjafile.build "ar_#{namespace}", {artifacts[0] => c_objects + cxx_objects}
122
+ when :dynamic
123
+ @ninjafile.build "so_#{namespace}", {artifacts[1] => c_objects + cxx_objects}
124
+ end
125
+ end
126
+ end
127
+
128
+ private
129
+ def sources_for_product(product, tripletised)
130
+ sources = [*product.sources] |
131
+ [*tripletised.configuration.sources] |
132
+ [*tripletised.platform.sources] |
133
+ [*tripletised.architecture.sources]
134
+ sources.reject{|src| src.inconsequential}.compact.uniq
135
+ end
136
+
137
+ def deps_for_product(product, tripletised)
138
+ deps = [*product.dependencies] |
139
+ [*tripletised.configuration.dependencies] |
140
+ [*tripletised.platform.dependencies] |
141
+ [*tripletised.architecture.dependencies]
142
+ deps.map do |dep|
143
+ case dep
144
+ when Ryb::InternalDependency
145
+ "${#{dep.product}_#{tripletised.triplet.join('_')}_as_linkable}"
146
+ when Ryb::ExternalDependency
147
+ dep.lib_or_framework
148
+ end
149
+ end
150
+ end
151
+
152
+ def artifacts_for_product(product, tripletised)
153
+ name = product.name.canonicalize
154
+ config_suffix = tripletised.configuration.suffix || "_#{tripletised.configuration.name}"
155
+ platform_suffix = tripletised.platform.suffix || "_#{tripletised.platform.name}"
156
+ arch_suffix = tripletised.architecture.suffix || "_#{tripletised.architecture.name}"
157
+ suffix = [config_suffix, platform_suffix, arch_suffix].join('')
158
+
159
+ if product.is_a? Ryb::Application
160
+ ["#@build/bin/#{name}#{suffix}.exe"]
161
+ elsif product.is_a? Ryb::Library
162
+ case product.linkage
163
+ when :static
164
+ ["#@build/lib/#{name}#{suffix}.lib"]
165
+ when :dynamic
166
+ ["#@build/lib/#{name}#{suffix}.lib", "#@build/bin/#{name}#{suffix}.dll"]
167
+ end
168
+ end
169
+ end
170
+
171
+ private
172
+ def cflags_for_product(project, product, tripletised)
173
+ flags = VisualStudio::Compiler::STANDARD_FLAGS +
174
+ cflags_for_configuration(tripletised.configuration) +
175
+ cflags_for_platform(tripletised.platform) +
176
+ cflags_for_architecture(tripletised.architecture)
177
+ flags += VisualStudio::Compiler.include_paths_to_flags(product.paths.includes) if product.paths
178
+ flags += VisualStudio::Compiler.defines_to_flags(project.defines)
179
+ flags += VisualStudio::Compiler.architecture_to_flags(tripletised.architecture.name.to_sym)
180
+ flags
181
+ end
182
+
183
+ def arflags_for_product(_project, _product, _tripletised)
184
+ %w{/nologo}
185
+ end
186
+
187
+ def ldflags_for_product(_project, product, tripletised)
188
+ flags = VisualStudio::Linker::STANDARD_FLAGS +
189
+ ldflags_for_configuration(tripletised.configuration) +
190
+ ldflags_for_platform(tripletised.platform) +
191
+ ldflags_for_architecture(tripletised.architecture)
192
+ flags += VisualStudio::Linker.architecture_to_flags(tripletised.architecture.name.to_sym)
193
+ # TODO: Linkage.
194
+ flags
195
+ end
196
+
197
+ private
198
+ def cflags_for_configuration(config)
199
+ flags = []
200
+ # TODO(mtwilliams): @toolchains.for(target)
201
+ flags += VisualStudio::Compiler.include_paths_to_flags(config.paths.includes) if config.paths
202
+ flags += VisualStudio::Compiler.defines_to_flags(config.defines)
203
+ flags += VisualStudio::Compiler.treat_warnings_as_errors_to_flag(config.treat_warnings_as_errors)
204
+ flags += VisualStudio::Compiler.generate_debug_symbols_to_flag(config.generate_debug_symbols)
205
+ flags += VisualStudio::Compiler.optimization_to_flags(config.optimize)
206
+ flags
207
+ end
208
+
209
+ def cflags_for_platform(platform)
210
+ flags = []
211
+ # TODO(mtwilliams): @toolchains.for(target)
212
+ flags += VisualStudio::Compiler.include_paths_to_flags(platform.paths.includes) if platform.paths
213
+ flags += VisualStudio::Compiler.defines_to_flags(platform.defines)
214
+ flags
215
+ end
216
+
217
+ def cflags_for_architecture(arch)
218
+ flags = []
219
+ # TODO(mtwilliams): @toolchains.for(target)
220
+ flags += VisualStudio::Compiler.architecture_to_flags(arch.name.canonicalize.to_sym)
221
+ flags += VisualStudio::Compiler.include_paths_to_flags(arch.paths.includes) if arch.paths
222
+ flags += VisualStudio::Compiler.defines_to_flags(arch.defines)
223
+ flags
224
+ end
225
+
226
+ def ldflags_for_configuration(config)
227
+ flags = []
228
+ # TODO(mtwilliams): @toolchains.for(target)
229
+ flags += VisualStudio::Linker.library_paths_to_flags(config.paths.libraries) if config.paths
230
+ flags += VisualStudio::Linker.generate_debug_symbols_to_flag(config.generate_debug_symbols)
231
+ flags
232
+ end
233
+
234
+ def ldflags_for_platform(platform)
235
+ flags = []
236
+ # TODO(mtwilliams): @toolchains.for(target)
237
+ flags += VisualStudio::Linker.library_paths_to_flags(platform.paths.libraries) if platform.paths
238
+ flags
239
+ end
240
+
241
+ def ldflags_for_architecture(arch)
242
+ flags = []
243
+ # TODO(mtwilliams): @toolchains.for(target)
244
+ flags += VisualStudio::Linker.library_paths_to_flags(arch.paths.libraries) if arch.paths
245
+ flags
246
+ end
247
+ end
248
+
249
+ def self.generate_from(rybfile, opts={})
250
+ puts "Generating..."
251
+ generator = ::Ryb::Ninja::Generator.new(rybfile, opts)
252
+ ::Rybfile::Walker.new(generator, rybfile, opts).walk
253
+ generator.generate
254
+ puts "Done!"
255
+ end
256
+ end
257
+ end