cpp_engine 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/cppengine +12 -0
- data/lib/cpp_engine/compiler.rb +64 -0
- data/lib/cpp_engine/dsl_loader.rb +18 -0
- data/lib/cpp_engine.rb +32 -0
- metadata +49 -0
data/bin/cppengine
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
class CppEngine::Compiler
|
2
|
+
|
3
|
+
attr_accessor :flags,:obj_dir,:header_dirs,:lib_dirs,:libs,:product, :source_files
|
4
|
+
def initialize params={}
|
5
|
+
self.flags = params[:flags] || []
|
6
|
+
self.header_dirs = params[:header_dirs] || []
|
7
|
+
self.lib_dirs = params[:lib_dirs] || []
|
8
|
+
self.libs = params[:libs] || []
|
9
|
+
self.product = params[:product] || "executable"
|
10
|
+
end
|
11
|
+
|
12
|
+
def execute command
|
13
|
+
puts command
|
14
|
+
system command
|
15
|
+
end
|
16
|
+
|
17
|
+
def compile
|
18
|
+
@objs=[]
|
19
|
+
source_files.each{|source_file|
|
20
|
+
@objs<<get_obj_path(source_file)
|
21
|
+
if outdated? source_file
|
22
|
+
execute compile_command(source_file)
|
23
|
+
end
|
24
|
+
}
|
25
|
+
end
|
26
|
+
|
27
|
+
def link
|
28
|
+
execute link_command(@objs,@product)
|
29
|
+
end
|
30
|
+
|
31
|
+
def compile_command source_file
|
32
|
+
header_dirs_flags=header_dirs.map{|dir| "-I#{dir}"}
|
33
|
+
return "g++ -c #{(flags+header_dirs_flags).join(" ")} #{source_file}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def link_command objs, product
|
37
|
+
lib_dirs_flags = lib_dirs.map{|dir| "-L#{dir}"}
|
38
|
+
lib_flags = libs.map{|lib| "-l#{lib}"}
|
39
|
+
return "g++ #{(flags+lib_dirs_flags+lib_flags).join(" ")} #{objs.join(" ")} -o #{product}"
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
def outdated? source_path
|
45
|
+
obj=get_obj_path source_path
|
46
|
+
return true if !File.exists?(obj)
|
47
|
+
return true if File.mtime(source_path)>File.mtime(obj)
|
48
|
+
dependent_headers(source_path).each{|header|
|
49
|
+
return true if File.mtime(header)>File.mtime(obj)
|
50
|
+
}
|
51
|
+
|
52
|
+
return false
|
53
|
+
end
|
54
|
+
|
55
|
+
def dependent_headers source_path
|
56
|
+
result= `g++ -MM #{source_path}`
|
57
|
+
return result.gsub(/\w+\.o:\s+/,"").gsub(/(\n)|(\\)/,"").split(/\s+/).select{|f| f=~/(\.h$)|(.hpp$)/}
|
58
|
+
end
|
59
|
+
|
60
|
+
def get_obj_path source_path
|
61
|
+
return source_path.sub(".cpp",".o")
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class CppEngine
|
2
|
+
module DslLoader
|
3
|
+
|
4
|
+
def load dsl_file
|
5
|
+
|
6
|
+
self.instance_eval(File.read(dsl_file))
|
7
|
+
end
|
8
|
+
|
9
|
+
def compile source_patterns,&block
|
10
|
+
compiler=Compiler.new
|
11
|
+
block.call compiler
|
12
|
+
compiler.source_files=grep_cpp_files source_patterns
|
13
|
+
@compilers<<compiler
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
include DslLoader
|
18
|
+
end
|
data/lib/cpp_engine.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
class CppEngine
|
2
|
+
OBJ_DIR="build/objs"
|
3
|
+
def initialize root_path="."
|
4
|
+
@root_path=root_path
|
5
|
+
@compilers=[]
|
6
|
+
end
|
7
|
+
|
8
|
+
def run
|
9
|
+
@compilers.each{|compiler|
|
10
|
+
compiler.compile
|
11
|
+
compiler.link
|
12
|
+
}
|
13
|
+
|
14
|
+
# compiler=Compiler.new
|
15
|
+
# compiler.compile @cpp_files
|
16
|
+
# compiler.link
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def grep_cpp_files source_patterns
|
21
|
+
@cpp_files=[]
|
22
|
+
|
23
|
+
source_patterns.each{|pattern|
|
24
|
+
@cpp_files+=Dir[pattern]
|
25
|
+
}
|
26
|
+
return @cpp_files
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
require 'cpp_engine/compiler'
|
32
|
+
require 'cpp_engine/dsl_loader'
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cpp_engine
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- tsdeng
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-24 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: cpp engine
|
15
|
+
email: tianshuo@me.com
|
16
|
+
executables:
|
17
|
+
- cppengine
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/cpp_engine/compiler.rb
|
22
|
+
- lib/cpp_engine/dsl_loader.rb
|
23
|
+
- lib/cpp_engine.rb
|
24
|
+
- bin/cppengine
|
25
|
+
homepage:
|
26
|
+
licenses: []
|
27
|
+
post_install_message:
|
28
|
+
rdoc_options: []
|
29
|
+
require_paths:
|
30
|
+
- lib
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
none: false
|
33
|
+
requirements:
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 1.8.15
|
46
|
+
signing_key:
|
47
|
+
specification_version: 3
|
48
|
+
summary: streamlined build system for C++ development
|
49
|
+
test_files: []
|