mcbuild 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/mcbuild.rb +133 -0
  3. metadata +47 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 494ccf89b33626d329e3066b8897a912dea14bdf
4
+ data.tar.gz: eb7833418d7da1a1e752656183091125cfd5880e
5
+ SHA512:
6
+ metadata.gz: b04be7fc3ee826b07ecf1659468aa7068abf725c315cdd0887997dc7e764369cec83181e1e160b1ea1bbd9a28d03a2f4af01dea871fbac56219d84ae49b52566
7
+ data.tar.gz: feb2cd7c371fe40e478c3d33569fbb21cc9dc058611ce34bb9df25f187e6cb73f313fdf86e446c77f55a7c2fd9ce9c96f7fa7433b14f1a0b722f69f4a79a8a64
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/ruby
2
+ require 'find'
3
+ require 'fileutils'
4
+
5
+ class MCBuild
6
+ def self.waitArg(arg)
7
+ ARGV.each do |_arg|
8
+ if _arg==arg
9
+ yield
10
+ else
11
+ puts "usage: ./script.rb #{arg}"
12
+ end
13
+ end
14
+ end
15
+
16
+ def remove_slash(str)
17
+ if str=='./'
18
+ @d = '.'
19
+ else
20
+ @d = str
21
+ end
22
+ end
23
+
24
+ def initialize(dir, fext=".c", oext=".o", aext=".a",
25
+ mach="x86_64", std="c99",
26
+ outpath="_build")
27
+
28
+ remove_slash(dir)
29
+
30
+ @fext = fext
31
+ @oext = oext
32
+ @aext = aext
33
+ @mach = mach
34
+ @std = std
35
+ @outpath = outpath
36
+ end
37
+
38
+ def set_arch(arch)
39
+ @mach = arch
40
+ self
41
+ end
42
+
43
+ def info
44
+ puts "Monk-C compiler use settings:"
45
+ puts "--------------------------------"
46
+ puts " CPU Arch -> #{@mach}"
47
+ puts " C standard -> #{@std}"
48
+ puts " filename extension -> #{@fext}"
49
+ puts " output extension -> #{@oext}"
50
+ puts " archive extension -> #{@aext}"
51
+ puts "--------------------------------"
52
+ puts "C compiler infos:"
53
+ puts "--------------------------------"
54
+ system("cc --version")
55
+ puts "--------------------------------"
56
+ end
57
+
58
+ def clean
59
+ begin
60
+ FileUtils.rm_rf("#{@d}/#{@outpath}")
61
+ rescue Exception => e
62
+ puts e
63
+ end
64
+ end
65
+
66
+ def prepare(libpath=[], libs=[])
67
+ @compile_arg = " -I#{@d}/#{@outpath}/archive"
68
+ @link_arg = " -L#{@d}/#{@outpath}/archive"
69
+
70
+ libpath.each { |path|
71
+ @compile_arg += " -I#{path}"
72
+ @link_arg += " -L#{path}"
73
+ }
74
+
75
+ libs.each { |lib|
76
+ @link_arg += " -l#{lib}"
77
+ }
78
+
79
+ @link_arg += @compile_arg
80
+
81
+ begin
82
+ FileUtils.rm_rf("#{@d}/#{@outpath}")
83
+ FileUtils.mkdir_p "#{@d}/#{@outpath}/archive"
84
+ rescue Exception => e
85
+ puts e
86
+ end
87
+ end
88
+
89
+ def prehash(string)
90
+
91
+ end
92
+
93
+ def copy_headers(headers)
94
+ begin
95
+ headers.each { |header|
96
+ puts "copying-> #{@d}/#{header}"
97
+ FileUtils.cp("#{@d}/#{header}", "#{@d}/#{@outpath}/archive")
98
+ }
99
+ rescue Exception => e
100
+ puts e
101
+ end
102
+ end
103
+
104
+ def compile_file(file)
105
+ base = File.basename(file, ".c")
106
+ cmd = "cc -arch #{@mach} -std=#{@std} -c -o #{@d}/#{@outpath}/#{base}#{@oext} #{file} #{@compile_arg}"
107
+ puts(cmd)
108
+ system(cmd)
109
+ end
110
+
111
+ def compile(path=@d)
112
+ Find.find(path) { |file|
113
+ if File.extname(file) == ".c" || File.extname(file) == ".asm"
114
+ compile_file(file)
115
+ end
116
+ }
117
+ end
118
+
119
+ def archive_lib(name)
120
+ cmd = "ar -r #{@d}/#{@outpath}/archive/#{name} #{@d}/#{@outpath}/*#{@oext}"
121
+ puts(cmd)
122
+ system(cmd)
123
+ end
124
+
125
+ def archive_exe(name)
126
+ cmd = "cc -o #{@d}/#{@outpath}/archive/#{name} #{@d}/#{@outpath}/*#{@oext} #{@link_arg}"
127
+ puts(cmd)
128
+ system(cmd)
129
+ end
130
+ end
131
+
132
+
133
+
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mcbuild
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sun Yuli
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-20 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: "create an build.rb file in root of source code\n\t require
14
+ 'mcbuild' at first line. then use MCBuild class\n\t build = MCBuild.new('.')\n\t
15
+ \ build.prepare\n\t build.copy_headers\n\t build.compile\n\t
16
+ \ build.archive_exe"
17
+ email: sunpaq@gmail.com
18
+ executables: []
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - lib/mcbuild.rb
23
+ homepage: https://github.com/sunpaq/mcbuild
24
+ licenses:
25
+ - BSD
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - '>='
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.0.14.1
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: A tool help to build C projects
47
+ test_files: []