magica 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1259e052adafafdb1d4552c0352b3bf67553d66f
4
- data.tar.gz: 916a17a280d294aeb52b2f0d1837d661b371bcad
3
+ metadata.gz: c76457397a26e8c8f5530223241085a5de1ed2cd
4
+ data.tar.gz: a00d14e584583a1b50774002f0ebe94ea05c5d0c
5
5
  SHA512:
6
- metadata.gz: 90796306ad23fc5f3afb39479056bc869a282a6fac40f10fd505ee681aec4e4b7855628a1898e4555ce9a6cbb6e27cd0ac1195dcb874e9ec2fa4ea3f7ce66428
7
- data.tar.gz: 554feb338c2ed4bb1c6211c594dddb46f3529c776a670841935739e3567b726a7e403b2fc570a367461268f312c6ad0958906fd21183f5ec32f28a5198e8ce43
6
+ metadata.gz: 7acc35bd25b2c8d3c416097a78ae04a47ff813c85eaad74e7ef921406533947ec58f13ea7e62dd89dd40385ef8bc49d65b74c9aa1e14a2df0303acc5d52c2646
7
+ data.tar.gz: 8518c22efb3a15fbd7834847e1a655b9b05448f25272d0c004e4a5fdc8be0599c091ae569d3b912f00b6bc7094a751f8aa09bc09f80e98b40946af3d48356654
@@ -13,6 +13,11 @@ module Magica
13
13
  @sources = FileList["src/**/*.cpp"]
14
14
  @cxx = Command::Compiler.new(self, %w(.cpp))
15
15
  @linker = Command::Linker.new(self)
16
+ @defines = %w()
17
+ @include_paths = %w()
18
+ @libaries = %w()
19
+ @libary_paths = %w()
20
+ @flags = %w()
16
21
 
17
22
  Magica.targets[@name] = self
18
23
  Magica.targets[@name].instance_eval(&block) unless block.nil?
@@ -20,11 +25,29 @@ module Magica
20
25
  Magica.default_toolchain.setup(self, Magica.toolchain_params) if Magica.default_toolchain
21
26
  end
22
27
 
28
+ def define(name)
29
+ @defines << name.to_s.upcase
30
+ end
31
+
32
+ def include_path(path)
33
+ @include_paths << path.to_s
34
+ end
35
+
36
+ def flag(flag)
37
+ @flags << flag.to_s
38
+ end
39
+
40
+ def library(name, path)
41
+ @libaries << name.to_s
42
+ @libary_paths << path.to_s
43
+ end
44
+
23
45
  def source(path)
24
46
  @sources = FileList[path]
25
47
  end
26
48
 
27
- def filename
49
+ def filename(name)
50
+ '"%s"' % name
28
51
  end
29
52
 
30
53
  def exefile(name)
@@ -54,13 +77,13 @@ module Magica
54
77
 
55
78
  def compile(source)
56
79
  file objfile(source) => source do |t|
57
- @cxx.run t.name, t.prerequisites.first
80
+ @cxx.run t.name, t.prerequisites.first, @defines, @include_paths, @flags
58
81
  end
59
82
  end
60
83
 
61
84
  def link(exec, objects)
62
85
  task "build:#{@name}" => objects do
63
- @linker.run "#{exec}", objects
86
+ @linker.run "#{exec}", objects, @libaries, @libary_paths, @flags
64
87
  end
65
88
  end
66
89
  end
@@ -9,11 +9,22 @@ module Magica
9
9
  @flags = [ENV['CFLAGS'] || []]
10
10
  @source_exts = source_exts
11
11
  @compile_options = "%{flags} -o %{outfile} -c %{infile}"
12
+ @include_paths = ["include"]
13
+ @defines = %w()
14
+
15
+ @option_include_path = "-I%s"
16
+ @option_defines = "-D%s"
17
+ end
18
+
19
+ def combine_flags(_defines = [], _include_paths = [], _flags = [])
20
+ define_flags = [@defines, _defines].flatten.map { |define| @option_defines % define }
21
+ include_path_flags = [@include_paths, _include_paths].flatten.map { |include_path| @option_include_path % filename(include_path) }
22
+ [define_flags, include_path_flags, _flags].flatten.join(' ')
12
23
  end
13
24
 
14
- def run(outfile, infile)
25
+ def run(outfile, infile, _defines = [], _include_paths = [], _flags = [])
15
26
  FileUtils.mkdir_p File.dirname(outfile)
16
- _run @compile_options, { outfile: outfile, infile: infile, flags: "" }
27
+ _run @compile_options, { outfile: outfile, infile: infile, flags: combine_flags(_defines, _include_paths, _flags) }
17
28
  end
18
29
  end
19
30
  end
@@ -7,11 +7,28 @@ module Magica
7
7
 
8
8
  @command = ENV['LD'] || 'ld'
9
9
  @flags = (ENV['LDFLAGS'] || [])
10
- @link_options = "%{flags} -o %{outfile} %{objects}"
10
+ @link_options = "%{flags} -o %{outfile} %{objects} %{libs}"
11
+ @libaries = []
12
+ @libary_paths = []
13
+
14
+ @option_libary = "-l%s"
15
+ @option_libary_path = "-L%s"
16
+ end
17
+
18
+ def combine_flags(_library_paths = [], _flags = [])
19
+ libary_paths = [@libary_paths, _library_paths].flatten.map { |path| @option_libary_path % filename(path) }
20
+ [flags, libary_paths, _flags].flatten.join(" ")
11
21
  end
12
22
 
13
- def run(outfile, objects)
14
- _run @link_options, { outfile: outfile, objects: objects.join(" "), flags: "" }
23
+ def run(outfile, objects, _libaries = [], _library_paths = [], _flags = [])
24
+ libary_flags = [@libaries, _libaries].flatten.map { |library| @option_libary % library }
25
+
26
+ _run @link_options, {
27
+ outfile: outfile,
28
+ objects: objects.join(" "),
29
+ libs: libary_flags.join(" "),
30
+ flags: combine_flags(_library_paths, _flags)
31
+ }
15
32
  end
16
33
  end
17
34
  end
@@ -1,3 +1,3 @@
1
1
  module Magica
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magica
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 蒼時弦也
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-16 00:00:00.000000000 Z
11
+ date: 2016-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake