bake 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Bake
2
- VERSION = [ 0, 1, 0 ]
2
+ VERSION = [ 0, 1, 1 ]
3
3
  VERSION_STRING = VERSION.join('.')
4
4
  end
5
5
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: bake
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2007-04-19 00:00:00 -04:00
6
+ version: 0.1.1
7
+ date: 2007-05-02 00:00:00 -04:00
8
8
  summary: Project-based build utility
9
9
  require_paths:
10
10
  - lib
@@ -32,17 +32,27 @@ files:
32
32
  - lib/bake
33
33
  - lib/bake.rb
34
34
  - lib/bake_version.rb
35
- - lib/bake/common_scheme.rb
35
+ - lib/bake/addon.rb
36
36
  - lib/bake/configuration.rb
37
37
  - lib/bake/context.rb
38
- - lib/bake/cpp_scheme.rb
38
+ - lib/bake/file_target.rb
39
+ - lib/bake/plugin.rb
40
+ - lib/bake/plugins
41
+ - lib/bake/project.rb
39
42
  - lib/bake/project_loader.rb
40
- - lib/bake/qt_scheme.rb
41
- - lib/bake/scheme.rb
42
- - lib/bake/scheme_loader.rb
43
43
  - lib/bake/string_utils.rb
44
44
  - lib/bake/target.rb
45
45
  - lib/bake/toolset.rb
46
+ - lib/bake/plugins/cpp
47
+ - lib/bake/plugins/cpp.rb
48
+ - lib/bake/plugins/macro.rb
49
+ - lib/bake/plugins/system.rb
50
+ - lib/bake/plugins/cpp/darwin.rb
51
+ - lib/bake/plugins/cpp/gcc.rb
52
+ - lib/bake/plugins/cpp/gcc_toolset_base.rb
53
+ - lib/bake/plugins/cpp/msvc.rb
54
+ - lib/bake/plugins/cpp/qt.rb
55
+ - lib/bake/plugins/cpp/toolset_base.rb
46
56
  - test/bake_test.rb
47
57
  - test/configuration_test.rb
48
58
  - test/context_test.rb
@@ -53,6 +63,7 @@ files:
53
63
  - TUTORIAL
54
64
  - CONCEPTS
55
65
  - REFERENCE
66
+ - CHANGELOG
56
67
  test_files: []
57
68
 
58
69
  rdoc_options:
@@ -66,6 +77,7 @@ extra_rdoc_files:
66
77
  - TUTORIAL
67
78
  - CONCEPTS
68
79
  - REFERENCE
80
+ - CHANGELOG
69
81
  executables:
70
82
  - bake
71
83
  extensions: []
@@ -1,42 +0,0 @@
1
- require 'bake/toolset'
2
- require 'bake/target'
3
-
4
- module Common
5
- class Default < Bake::Toolset
6
- def build(target)
7
- if target.is_a?(Directory)
8
- make_dir(target)
9
- elsif target.is_a?(FileClone)
10
- copy(target)
11
- else
12
- raise "unrecognized target of class '#{target.class}'"
13
- end
14
- end
15
-
16
- def clean(target)
17
- end
18
-
19
- private
20
- def make_dir(target)
21
- puts "building directory '#{target.name}'"
22
- end
23
-
24
- def copy(target)
25
- puts "building copy '#{target.name}'"
26
- end
27
- end
28
-
29
- class Directory < Bake::Target
30
- ACCESSORS = :dir
31
-
32
- def initialize(name, parent)
33
- super(parent)
34
- @name = name
35
- end
36
- end
37
-
38
- class FileClone < Bake::Target
39
- ACCESSORS = [ :copy, :clone ]
40
- end
41
- end
42
-
@@ -1,460 +0,0 @@
1
- require 'bake/toolset'
2
- require 'bake/target'
3
- require 'fileutils'
4
- require 'set'
5
-
6
- class CppToolsetBase < Bake::Toolset
7
- def build(target)
8
- if stale?(target)
9
- FileUtils.mkdir_p(target[:outdir])
10
- if target.is_a?(Cpp::Object)
11
- compile(target)
12
- # refresh the .includes file
13
- includes = target.includes
14
- filename = "#{target[:outdir]}/#{target.src.basename}.includes"
15
- File.open(filename, "w") do |file|
16
- includes.each { |inc| file.puts(inc) }
17
- end
18
- elsif target.is_a?(Cpp::Library)
19
- ar(target)
20
- elsif target.is_a?(Cpp::Executable)
21
- link(target)
22
- elsif target.is_a?(Cpp::Runner)
23
- run(target)
24
- else
25
- raise "unknown Cpp target of class '#{target.class}"
26
- end
27
- end
28
- end
29
-
30
- def stale?(target)
31
- t = Time.now
32
- output_files(target).each do |out|
33
- return true if !File.exists?(out)
34
- out_time = File.mtime(out)
35
- t = out_time if out_time < t
36
- end
37
- if target.is_a?(Cpp::Object)
38
- return true if File.mtime(target.src) > t
39
- target.includes.each { |file| return true if File.mtime(file) > t }
40
- elsif target.is_a?(Cpp::Runner)
41
- return File.mtime(output_files(target.deps[0])[0]) > t
42
- else
43
- is_linked = target.is_a?(Cpp::Executable) ||
44
- (target.is_a?(Cpp::Library) && target[:libtype] == 'dynamic')
45
- target.children.each do |child|
46
- output_files(child).each do |file|
47
- return true if File.mtime(file) > t
48
- end
49
- end
50
- target.deps.each do |dep|
51
- if is_linked && dep.is_a?(Cpp::Library) &&
52
- dep[:libtype] != 'dynamic'
53
- output_files(dep).each do |file|
54
- return true if File.mtime(file) > t
55
- end
56
- end
57
- end
58
- end
59
- return false
60
- end
61
-
62
- def clean(target)
63
- output_files(target).each { |file| FileUtils.rm_f(file) }
64
- if target.is_a?(Cpp::Object)
65
- filename = "#{target[:outdir]}/#{target.src.basename}.includes"
66
- FileUtils.rm_f(filename)
67
- end
68
- end
69
-
70
- def output_files(target)
71
- out = output(target)
72
- return [] if !out
73
- return out.to_a if out.respond_to?(:to_a)
74
- return [ out ]
75
- end
76
- end
77
-
78
- class GccToolsetBase < CppToolsetBase
79
- def output(target)
80
- if target.is_a?(Cpp::Object)
81
- return obj_fn(target)
82
- elsif target.is_a?(Cpp::Library)
83
- return lib_fn(target)
84
- elsif target.is_a?(Cpp::Executable)
85
- return exe_fn(target)
86
- elsif target.is_a?(Cpp::Runner)
87
- return runner_fn(target)
88
- end
89
- return nil
90
- end
91
-
92
- def compile(obj)
93
- src = obj.src
94
- output = obj_fn(obj)
95
- flags = build_flags('-I', obj[:incdirs] + obj[:sysincdirs]) +
96
- build_flags('-D', obj[:defines])
97
- flags += obj[:cflags].join(' ')
98
- flags += ' -fno-rtti' if !obj[:rtti?]
99
- flags += ' -O3' if obj[:optimizations?]
100
- flags += ' -g' if obj[:debug_symbols?]
101
- sh("g++ -c -o #{output} #{flags} #{src}")
102
- end
103
-
104
- def ar(lib)
105
- obj_str, lib_str, flags = process_inputs(lib)
106
-
107
- output = lib_fn(lib)
108
- if lib[:libtype] == 'dynamic'
109
- sh("g++ #{flags} -shared -Wl,-soname,#{output} -o #{output} #{obj_str} #{lib_str}")
110
- else
111
- sh("ar rcs #{output} #{obj_str}")
112
- end
113
- end
114
-
115
- def link(exe)
116
- obj_str, lib_str, flags = process_inputs(exe)
117
-
118
- output = exe_fn(exe)
119
- sh("g++ #{flags} -o #{output} #{obj_str} #{lib_str}")
120
- end
121
-
122
- def run(runner)
123
- sh(exe_fn(runner.deps.first))
124
- FileUtils.touch(runner_fn(runner))
125
- end
126
-
127
- private
128
- def build_flags(flag, args)
129
- return args.inject('') { |str, arg| str + "#{flag}#{arg} " }
130
- end
131
-
132
- def obj_fn(obj)
133
- src = obj.src
134
- basename = File.basename(src, File.extname(src)) + '.o'
135
- return File.join(obj[:outdir], basename)
136
- end
137
-
138
- def lib_fn(lib)
139
- if lib[:libtype] == 'dynamic'
140
- return File.join(lib[:outdir], "#{lib.name}.so")
141
- end
142
- return File.join(lib[:outdir], "lib#{lib.name}.a")
143
- end
144
-
145
- def exe_fn(exe)
146
- return File.join(exe[:outdir], exe.name)
147
- end
148
-
149
- def runner_fn(runner)
150
- return "#{exe_fn(runner.deps.first)}.success"
151
- end
152
-
153
- def process_inputs(target)
154
- output = output(target)
155
- obj_str = ''
156
- lib_str = ''
157
- libdirs = []
158
- (target.children + target.deps).each do |input|
159
- if input.is_a?(Cpp::Object)
160
- fn = obj_fn(input)
161
- obj_str += fn + ' '
162
- elsif input.is_a?(Cpp::SystemLibrary)
163
- lib_str += '-l' + input.file + ' '
164
- elsif input.is_a?(Cpp::Library)
165
- fn = lib_fn(input)
166
- if input[:libtype] == 'dynamic'
167
- obj_str += fn + ' '
168
- else
169
- lib_str += '-l' + input.name + ' '
170
- libdir = File.dirname(fn)
171
- libdirs << libdir if !libdirs.include?(libdir)
172
- end
173
- end
174
- end
175
-
176
- libdirs.concat(target[:libdirs])
177
- flags = build_flags('-L', libdirs)
178
-
179
- return [ obj_str, lib_str, flags ]
180
- end
181
- end
182
-
183
- module Cpp
184
- class Darwin < GccToolsetBase
185
- def ar(lib)
186
- obj_str, lib_str, flags = process_inputs(lib)
187
-
188
- output = lib_fn(lib)
189
- if lib[:libtype] == 'dynamic'
190
- sh("g++ #{flags} -dynamiclib -o #{output} #{obj_str} #{lib_str}")
191
- else
192
- sh("ar rcs #{output} #{obj_str}")
193
- end
194
- end
195
-
196
- private
197
- def lib_fn(lib)
198
- if lib[:libtype] == 'dynamic'
199
- return File.join(lib[:outdir], "#{lib.name}.dylib")
200
- end
201
- return File.join(lib[:outdir], "lib#{lib.name}.a")
202
- end
203
- end
204
-
205
- class Gcc < GccToolsetBase
206
- end
207
-
208
- class Msvc6 < CppToolsetBase
209
- def output(target)
210
- if target.is_a?(Object)
211
- return obj_fn(target)
212
- elsif target.is_a?(Library)
213
- return lib_fn(target)
214
- elsif target.is_a?(Executable)
215
- return exe_fn(target)
216
- end
217
- return nil
218
- end
219
-
220
- def compile(obj)
221
- src = obj.src
222
- output = obj_fn(obj)
223
- flags = build_flags('/I', obj[:incdirs] + obj[:sysincdirs]) +
224
- build_flags('/D', obj[:defines])
225
- flags += obj[:cflags].join(' ')
226
- flags += ' /MD'
227
- flags += ' /EHsc' if obj[:exceptions?]
228
- flags += ' /GR' if obj[:rtti?]
229
- flags += obj[:optimizations?] ? ' /O2' : ' /Od'
230
- flags += ' /Z7' if obj[:debug_symbols?]
231
- sh("cl /nologo #{flags} /c /Fo#{output} /Tp#{src}")
232
- end
233
-
234
- def ar(lib)
235
- obj_str, flags = process_inputs(lib)
236
-
237
- output = lib_fn(lib)
238
- if lib[:libtype] == 'dynamic'
239
- flags += ' /debug' if lib[:debug_symbols?]
240
- sh("link /nologo /dll #{flags} /out:#{output[1]} #{obj_str}")
241
- else
242
- sh("lib /nologo /out:#{output} #{obj_str}")
243
- end
244
- end
245
-
246
- def link(exe)
247
- obj_str, flags = process_inputs(exe)
248
-
249
- output = exe_fn(exe)
250
- flags += ' /debug' if exe[:debug_symbols?]
251
- sh("link /nologo /subsystem:console #{flags} /out:#{output} #{obj_str}")
252
- end
253
-
254
- def run(runner)
255
- sh(exe_fn(runner.deps.first))
256
- FileUtils.touch(runner_fn(runner))
257
- end
258
-
259
- private
260
- def build_flags(flag, args)
261
- return args.inject('') { |str, arg| str + "#{flag}#{arg} " }
262
- end
263
-
264
- def obj_fn(obj)
265
- src = obj.src
266
- basename = File.basename(src, File.extname(src)) + '.obj'
267
- return File.join(obj[:outdir], basename)
268
- end
269
-
270
- def lib_fn(lib)
271
- if lib[:libtype] == 'dynamic'
272
- return [File.join(lib[:outdir], "#{lib.name}.lib"),
273
- File.join(lib[:outdir], "#{lib.name}.dll"),
274
- File.join(lib[:outdir], "#{lib.name}.exp")]
275
- end
276
- return File.join(lib[:outdir], "#{lib.name}.lib")
277
- end
278
-
279
- def exe_fn(exe)
280
- return File.join(exe[:outdir], exe.name + '.exe')
281
- end
282
-
283
- def runner_fn(runner)
284
- return "#{exe_fn(runner.deps.first)}.success"
285
- end
286
-
287
- def process_inputs(target)
288
- output = output(target)
289
- obj_str = ''
290
- libdirs = []
291
- static_lib = target.is_a?(Library) && target[:libtype] == 'static'
292
- (target.children + target.deps).each do |input|
293
- if input.is_a?(Object)
294
- fn = obj_fn(input)
295
- obj_str += fn + ' '
296
- elsif input.is_a?(SystemLibrary)
297
- if !static_lib
298
- obj_str += input.file + '.lib '
299
- end
300
- elsif input.is_a?(Library)
301
- if !static_lib
302
- if input[:libtype] == 'dynamic'
303
- fn = lib_fn(input)[0]
304
- else
305
- fn = lib_fn(input)
306
- end
307
- libdir = File.dirname(fn)
308
- libdirs << libdir if !libdirs.include?(libdir)
309
- obj_str += File.basename(fn) + ' '
310
- end
311
- end
312
- end
313
-
314
- if !static_lib
315
- target[:libs].each { |lib| obj_str += lib + '.lib ' }
316
- end
317
- libdirs.concat(target[:libdirs])
318
- flags = build_flags('/LIBPATH:', libdirs)
319
-
320
- return [ obj_str, flags ]
321
- end
322
- end
323
-
324
- class Library < Bake::Target
325
- ACCESSORS = :lib
326
-
327
- def initialize(parent, name)
328
- super(parent)
329
- @name = name
330
- default(:libtype => 'static')
331
- default(:debug_symbols? => false)
332
- end
333
-
334
- def src(*args)
335
- return args.flatten.collect { |file| Cpp::Object.new(self, file) }
336
- end
337
- end
338
-
339
- class SystemLibrary < Bake::Target
340
- ACCESSORS = :syslib
341
-
342
- attr_reader :file
343
-
344
- def initialize(parent, name, file)
345
- super(parent)
346
- @name = name
347
- @file = file
348
- opt(:built? => true)
349
- end
350
- end
351
-
352
- class Executable < Bake::Target
353
- ACCESSORS = :exe
354
-
355
- def initialize(parent, name)
356
- super(parent)
357
- @name = name
358
- default(:debug_symbols? => false)
359
- end
360
-
361
- def src(*args)
362
- return args.flatten.collect { |file| Cpp::Object.new(self, file) }
363
- end
364
- end
365
-
366
- class Source < Bake::Target
367
- attr_reader :output
368
-
369
- def initialize(parent, src)
370
- super(parent)
371
- @output = src
372
- opt(:built? => true)
373
- end
374
- end
375
-
376
- class Object < Bake::Target
377
- ACCESSORS = :obj
378
-
379
- def initialize(parent, src = nil)
380
- super(parent)
381
- return if !src
382
- if src.instance_of?(String)
383
- children << Source.new(self, src)
384
- else
385
- children << src
386
- end
387
- default(:exceptions? => true)
388
- default(:rtti? => true)
389
- default(:optimizations? => false)
390
- default(:multithreaded? => true)
391
- end
392
-
393
- def src
394
- return children.first.output
395
- end
396
-
397
- def includes(recalc = false)
398
- incfile = "#{get(:outdir)}/#{src}.includes"
399
- if !@includes || recalc
400
- if File.exists?(incfile)
401
- @includes = load_includes(incfile)
402
- else
403
- @includes = calc_includes(src, Set.new)
404
- end
405
- end
406
- return @includes
407
- end
408
-
409
- private
410
- def load_includes(incfile)
411
- includes = Set.new
412
- file = File.open(incfile)
413
- while line = file.gets
414
- line.chomp!
415
- includes << line if !line.empty?
416
- end
417
- file.close
418
- return includes
419
- end
420
-
421
- def calc_includes(filename, include_fns)
422
- new_include_fns = Set.new
423
- File.open(filename) do |file|
424
- incdirs = get(:incdirs)
425
- while line = file.gets
426
- if line =~ /\s*#\s*include\s+("|<)([^"]+)("|>)/
427
- inc = $2
428
- incdirs.each do |include_dir|
429
- fn = File.join(include_dir, inc)
430
- break if include_fns.include?(fn)
431
- if File.exists?(fn)
432
- new_include_fns << fn
433
- include_fns << fn
434
- break
435
- end
436
- end
437
- end
438
- end
439
- end
440
-
441
- new_include_fns.each do |inc|
442
- calc_includes(inc, include_fns)
443
- end
444
- return include_fns
445
- end
446
- end
447
-
448
- class Runner < Bake::Target
449
- ACCESSORS = :run
450
-
451
- def initialize(parent, exe)
452
- super(parent)
453
- target = dep(exe)[0]
454
- if !target.is_a?(Executable)
455
- raise "target '#{target.name}' is not an executable"
456
- end
457
- end
458
- end
459
- end
460
-