RMake 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: add970aa42674956ce691231882aa64b04d6ab37
4
+ data.tar.gz: c37f2f22362c043864e155bf0bc25aece4b40c12
5
+ SHA512:
6
+ metadata.gz: 85401f8cada9dba25a34c53feec0ecfe4b6382368135cae8ca335ed54a5880d5eef17a62361f181d823aa78b0eb91d18c3f95f870b7b9e9efc150a014c4fb24c
7
+ data.tar.gz: 86423e86fdcc490c262cacfc36e76b05757c8921ddbb63c35c3ab81d8ea8a27c71364b951ea193fef2d51e767582537de258dde55bc2a3ce8bb187b67c3e2367
data/bin/rmake ADDED
@@ -0,0 +1,38 @@
1
+ #! /usr/bin/env ruby
2
+ # encoding: utf-8
3
+ $: << '.'
4
+
5
+ require 'rubygems'
6
+ require 'bundler/setup'
7
+ require "rmake"
8
+ require "thor"
9
+
10
+ def require_project_file file
11
+ require file if File.file?(file)
12
+ end
13
+
14
+
15
+ class RMake < Thor
16
+ class_option :pfile, type: :string, default: 'project.rb'
17
+
18
+
19
+ desc 'build NAME', 'build the NAME project'
20
+ def build name
21
+ require_project_file options[:pfile]
22
+ Project.do name
23
+ end
24
+
25
+ desc 'build_all', 'build all project'
26
+ def build_all
27
+ require_project_file options[:pfile]
28
+ Project.do_all
29
+ end
30
+
31
+ desc 'list', 'list all project'
32
+ def list
33
+ require_project_file options[:pfile]
34
+ puts Project.all.join("\n")
35
+ end
36
+ end
37
+
38
+ RMake.start(ARGV)
data/lib/rmake.rb ADDED
@@ -0,0 +1,104 @@
1
+ require "erb"
2
+
3
+ $projects = {}
4
+
5
+ def project name = File.basename(Dir.getwd)
6
+ if $projects.has_key?(name)
7
+ puts "project's name(#{name}) is exists"
8
+ return
9
+ end
10
+ p = Project.new(target: name)
11
+ yield p
12
+ $projects[name] = p
13
+ end
14
+
15
+ class Project
16
+ def self.do_all
17
+ $projects.values.each{|p| p.create_makefile_and_make }
18
+ end
19
+
20
+ def self.do name
21
+ $projects[name].create_makefile_and_make if $projects.has_key?(name)
22
+ end
23
+
24
+ def self.all
25
+ $projects.keys
26
+ end
27
+
28
+ def initialize(options = {})
29
+ @options = {
30
+ makefile: 'Makefile',
31
+ obj_files: 'build/tmp/objects',
32
+ source_files: [],
33
+ include_path: ['include', 'inc', './'],
34
+ libs: [],
35
+ ld_library_path: [],
36
+ type: 'app',
37
+ host: '',
38
+ target: '',
39
+ build_dir: 'build'
40
+ }.merge(options)
41
+ end
42
+
43
+ def include_info
44
+ @options[:include_path].find_all{|path| File.directory?(path) }.map{|path| "-I" + path }.join(" ")
45
+ end
46
+
47
+ def ld_info
48
+ @options[:ld_library_path].find_all{|path| File.directory?(path) }.map{|path| "-L" + path }.join(" ")
49
+ end
50
+
51
+ def lib_info
52
+ @options[:libs].map{|path| "-l" + path }.join(" ")
53
+ end
54
+
55
+ def gcc
56
+ return @options[:host] + '-g++' if @options[:host] != ''
57
+ return 'g++'
58
+ end
59
+
60
+ def source_files
61
+ source_files = @options[:source_files].size == 0 ? Dir["*/**/*.cpp"] + Dir["*/**/*.c"] : @options[:source_files]
62
+ end
63
+
64
+ def chanage_source_to_obj file
65
+ File.join(@options[:build_dir], 'obj', file.gsub(File.extname(file), '.o'))
66
+ end
67
+
68
+ def obj_files
69
+ source_files.map{|file| chanage_source_to_obj(file) }
70
+ end
71
+
72
+ def create_makefile_and_make
73
+ open @options[:makefile], 'w' do |f|
74
+ f << ERB.new(IO.read(File.join(__dir__, "../resources/makefile.#{@options[:type]}.erb"))).result(binding)
75
+ end
76
+ system("make")
77
+ end
78
+
79
+ # set options
80
+ def host platform
81
+ @options[:host] = platform
82
+ end
83
+
84
+ def set key, value
85
+ @options[key] = value
86
+ end
87
+
88
+ def add_sources files
89
+ @options[:source_files].concat files
90
+ end
91
+
92
+ def add_include_path paths
93
+ @options[:include_path].concat paths
94
+ end
95
+
96
+ def add_ld_library_path paths
97
+ @options[:ld_library_path].concat paths
98
+ end
99
+
100
+ def add_libs libs
101
+ @options[:libs].concat libs
102
+ end
103
+
104
+ end
@@ -0,0 +1,17 @@
1
+
2
+ <%= File.join(@options[:build_dir], 'bin', @options[:target])%>: <%= obj_files.join(' ') %>
3
+ mkdir -p <%= File.join(@options[:build_dir], 'bin') %>
4
+ <%= gcc %> -g -o <%= File.join(@options[:build_dir], 'bin', @options[:target]) %> <%= obj_files.join(' ') %> <%= ld_info %> <%= lib_info %>
5
+
6
+ <% source_files.each do |source_file| %>
7
+ <%= chanage_source_to_obj(source_file) %>: <%= source_file %>
8
+ mkdir -p <%= File.dirname(chanage_source_to_obj(source_file)) %>
9
+ <%= gcc %> -g -c <%= source_file %> <%= include_info %> -o <%= chanage_source_to_obj(source_file) %>
10
+ <% end %>
11
+
12
+ .PHONY: clean
13
+
14
+ clean:
15
+ -rm -f <%= @options[:target] %>
16
+ -rm -rf <%= @options[:build_dir] %>
17
+
@@ -0,0 +1,17 @@
1
+
2
+ <%= File.join(@options[:build_dir], 'lib', 'lib' + @options[:target])%>.so: <%= obj_files.join(' ') %>
3
+ mkdir -p <%= File.join(@options[:build_dir], 'lib') %>
4
+ <%= gcc %> -shared -o <%= File.join(@options[:build_dir], 'lib', 'lib' + @options[:target]) %>.so <%= obj_files.join(' ') %> <%= ld_info %> <%= lib_info %>
5
+
6
+ <% source_files.each do |source_file| %>
7
+ <%= chanage_source_to_obj(source_file) %>: <%= source_file %>
8
+ mkdir -p <%= File.dirname(chanage_source_to_obj(source_file)) %>
9
+ <%= gcc %> -g -fPIC -c <%= source_file %> <%= include_info %> -o <%= chanage_source_to_obj(source_file) %>
10
+ <% end %>
11
+
12
+ .PHONY: clean
13
+
14
+ clean:
15
+ -rm -f lib<%= @options[:target] %>.so
16
+ -rm -rf <%= @options[:build_dir] %>
17
+
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: RMake
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - jimxl
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2012-03-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description: use ruby to create c/c++ project's makefile
28
+ email: tianxiaxl@gmail.com
29
+ executables:
30
+ - rmake
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/rmake.rb
35
+ - resources/makefile.app.erb
36
+ - resources/makefile.lib.erb
37
+ - bin/rmake
38
+ homepage: http://code.dreamcoder.info
39
+ licenses:
40
+ - MIT
41
+ metadata: {}
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubyforge_project:
58
+ rubygems_version: 2.0.0
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: RMake
62
+ test_files: []