mcbuild 0.0.25 → 0.0.52
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 +4 -4
- data/lib/mcbuild.rb +124 -40
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b0e9049641038a3a2ca906a09b1f6d3e75a4be3
|
4
|
+
data.tar.gz: d3adf0843b7fa7014b32384b410b9c85af8b0bde
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e727b31fdeef73ce45052210c391e2d7dec3c29c441ef24e9f9141b97956f95d1ab23ed2ac9b27bdbd10e8865c0c16877e05385278e3052495f979a167dccaf
|
7
|
+
data.tar.gz: be9a6df9bc027a23d3ec6bb393aee0cfae67b3c7288977d140e55beb90ce8f6d4a82c533210a809e1c891afc20606241a30e63c7b2ea1f92e7404fad4f0b83de
|
data/lib/mcbuild.rb
CHANGED
@@ -118,29 +118,42 @@ class MCBuild
|
|
118
118
|
end
|
119
119
|
|
120
120
|
def initialize(dir)
|
121
|
+
@compiler = "cc"
|
122
|
+
@sysroot = ''
|
121
123
|
@target = ''
|
122
124
|
@mach = ''
|
125
|
+
@position_independent_code = false
|
123
126
|
@flags = MCBuild.detect_machine_macro
|
124
127
|
|
128
|
+
@archiver = "ar"
|
129
|
+
|
125
130
|
@d = remove_slash(dir)
|
126
131
|
|
127
132
|
@name = "mcdefault"
|
133
|
+
|
128
134
|
@fext = ".c"
|
129
135
|
@oext = ".o"
|
130
136
|
@aext = ".a"
|
131
137
|
@std = "c99"
|
132
138
|
@outpath = "_build"
|
133
139
|
|
134
|
-
@headers
|
135
|
-
@excludes
|
140
|
+
@headers = []
|
141
|
+
@excludes = []
|
136
142
|
@dependency = []
|
137
143
|
|
138
|
-
@
|
139
|
-
@
|
144
|
+
@include_path = "#{@d}/#{@outpath}/archive/include"
|
145
|
+
@lib_path = "#{@d}/#{@outpath}/archive/lib"
|
146
|
+
|
147
|
+
@compile_arg = " -I#{self.export_include_path}"
|
148
|
+
@link_arg = " -L#{self.export_lib_path}"
|
140
149
|
end
|
141
150
|
|
142
|
-
def
|
143
|
-
|
151
|
+
def export_include_path
|
152
|
+
@include_path
|
153
|
+
end
|
154
|
+
|
155
|
+
def export_lib_path
|
156
|
+
@lib_path
|
144
157
|
end
|
145
158
|
|
146
159
|
def name
|
@@ -155,6 +168,36 @@ class MCBuild
|
|
155
168
|
@excludes
|
156
169
|
end
|
157
170
|
|
171
|
+
def set_export_include_path(incpath)
|
172
|
+
@include_path = incpath
|
173
|
+
self
|
174
|
+
end
|
175
|
+
|
176
|
+
def set_export_lib_path(libpath)
|
177
|
+
@lib_path = libpath
|
178
|
+
self
|
179
|
+
end
|
180
|
+
|
181
|
+
def set_compiler(compiler)
|
182
|
+
@compiler = compiler
|
183
|
+
self
|
184
|
+
end
|
185
|
+
|
186
|
+
def set_archiver(archiver)
|
187
|
+
@archiver = archiver
|
188
|
+
self
|
189
|
+
end
|
190
|
+
|
191
|
+
def set_sysroot(root)
|
192
|
+
@sysroot = root
|
193
|
+
self
|
194
|
+
end
|
195
|
+
|
196
|
+
def set_position_independent_code(pic)
|
197
|
+
@position_independent_code = pic
|
198
|
+
self
|
199
|
+
end
|
200
|
+
|
158
201
|
def set_headers(headers)
|
159
202
|
@headers = headers
|
160
203
|
self
|
@@ -163,7 +206,7 @@ class MCBuild
|
|
163
206
|
def set_name(name)
|
164
207
|
@name = name
|
165
208
|
self
|
166
|
-
end
|
209
|
+
end
|
167
210
|
|
168
211
|
def set_fext(fext)
|
169
212
|
@fext = fext
|
@@ -216,17 +259,17 @@ class MCBuild
|
|
216
259
|
puts " CPU target -> #{@target}"
|
217
260
|
puts " C standard -> #{@std}"
|
218
261
|
puts " name -> #{@name}"
|
262
|
+
puts " compiler -> #{@compiler}"
|
219
263
|
puts " filename extension -> #{@fext}"
|
220
264
|
puts " output extension -> #{@oext}"
|
221
265
|
puts " archive extension -> #{@aext}"
|
222
266
|
puts " compile flags -> #{@flags}"
|
223
267
|
puts " source dir -> #{@d}"
|
224
|
-
puts " export dir -> #{self.export_path}"
|
225
268
|
puts " excludes -> #{self.excludes}"
|
226
269
|
puts "--------------------------------"
|
227
270
|
puts "C compiler infos:"
|
228
271
|
puts "--------------------------------"
|
229
|
-
system("
|
272
|
+
system("#{@compiler} --version")
|
230
273
|
puts "--------------------------------"
|
231
274
|
self
|
232
275
|
end
|
@@ -238,8 +281,9 @@ class MCBuild
|
|
238
281
|
|
239
282
|
def prepare
|
240
283
|
begin
|
241
|
-
FileUtils.rm_rf
|
242
|
-
FileUtils.mkdir_p "#{@d}/#{@outpath}/archive"
|
284
|
+
FileUtils.rm_rf "#{@d}/#{@outpath}"
|
285
|
+
FileUtils.mkdir_p "#{@d}/#{@outpath}/archive/include"
|
286
|
+
FileUtils.mkdir_p "#{@d}/#{@outpath}/archive/lib"
|
243
287
|
if @headers.count != 0
|
244
288
|
self.copy_headers
|
245
289
|
else
|
@@ -253,14 +297,9 @@ class MCBuild
|
|
253
297
|
|
254
298
|
def set_dependency(libs=[])
|
255
299
|
libs.each { |lib|
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
@compile_arg += " -I#{path}"
|
260
|
-
@link_arg += " -L#{path}"
|
261
|
-
@link_arg += " -l#{name}"
|
300
|
+
@compile_arg += " -I#{lib.export_include_path} -L#{lib.export_lib_path} -l#{lib.name}"
|
301
|
+
@link_arg += " -I#{lib.export_include_path} -L#{lib.export_lib_path} -l#{lib.name}"
|
262
302
|
}
|
263
|
-
@link_arg += @compile_arg
|
264
303
|
self
|
265
304
|
end
|
266
305
|
|
@@ -274,7 +313,7 @@ class MCBuild
|
|
274
313
|
base = File.basename(header)
|
275
314
|
if @headers.include? base
|
276
315
|
puts "copying-> #{header}"
|
277
|
-
FileUtils.cp("#{header}", "#{@d}/#{@outpath}/archive")
|
316
|
+
FileUtils.cp("#{header}", "#{@d}/#{@outpath}/archive/include")
|
278
317
|
end
|
279
318
|
}
|
280
319
|
rescue Exception => e
|
@@ -288,12 +327,12 @@ class MCBuild
|
|
288
327
|
Find.find(@d) { |header|
|
289
328
|
ext = File.extname(header)
|
290
329
|
base = File.basename(header)
|
291
|
-
if (ext == ".h") && (!header.include? self.
|
330
|
+
if (ext == ".h") && (!header.include? self.export_include_path)
|
292
331
|
if (except != nil) && (except.include? base)
|
293
332
|
puts "except: #{base}"
|
294
333
|
else
|
295
334
|
puts "copying-> #{header}"
|
296
|
-
FileUtils.cp("#{header}", self.
|
335
|
+
FileUtils.cp("#{header}", self.export_include_path)
|
297
336
|
end
|
298
337
|
end
|
299
338
|
}
|
@@ -304,36 +343,48 @@ class MCBuild
|
|
304
343
|
end
|
305
344
|
|
306
345
|
def compiler_command
|
307
|
-
cmd =
|
346
|
+
cmd = @compiler
|
347
|
+
cmd += " -std=#{@std}"
|
348
|
+
if @sysroot != ''
|
349
|
+
cmd += " --sysroot #{@sysroot}"
|
350
|
+
end
|
308
351
|
if @target != ''
|
309
352
|
cmd += " -target #{@target}"
|
310
353
|
end
|
311
354
|
if @mach != ''
|
312
355
|
cmd += " -arch #{@mach}"
|
313
356
|
end
|
314
|
-
|
357
|
+
if @position_independent_code
|
358
|
+
cmd += " -fPIC"
|
359
|
+
end
|
315
360
|
cmd += " #{@flags}"
|
316
361
|
cmd
|
317
362
|
end
|
318
363
|
|
319
364
|
def linker_command
|
320
|
-
cmd =
|
365
|
+
cmd = @compiler
|
366
|
+
if @sysroot != ''
|
367
|
+
cmd += " --sysroot #{@sysroot}"
|
368
|
+
end
|
321
369
|
if @target != ''
|
322
370
|
cmd += " -target #{@target}"
|
323
371
|
end
|
324
372
|
if @mach != ''
|
325
373
|
cmd += " -arch #{@mach}"
|
326
374
|
end
|
327
|
-
#cmd += " -std=#{@std}"
|
328
|
-
#cmd += " #{@flags}"
|
329
375
|
cmd
|
330
376
|
end
|
331
377
|
|
378
|
+
def archiver_command
|
379
|
+
cmd = @archiver
|
380
|
+
end
|
381
|
+
|
332
382
|
def compile_file(file)
|
333
|
-
|
383
|
+
ext = File.extname(file)
|
384
|
+
base = File.basename(file, ext)
|
334
385
|
cmd = compiler_command
|
335
386
|
cmd += " -c -o #{@d}/#{@outpath}/#{base}#{@oext} #{file} #{@compile_arg}"
|
336
|
-
puts(cmd)
|
387
|
+
#puts(cmd)
|
337
388
|
system(cmd)
|
338
389
|
self
|
339
390
|
end
|
@@ -344,7 +395,7 @@ class MCBuild
|
|
344
395
|
begin
|
345
396
|
Find.find(@d) { |file|
|
346
397
|
ext = File.extname(file)
|
347
|
-
base = File.basename(file)
|
398
|
+
base = File.basename(file, ext)
|
348
399
|
if ext == ".c" || ext == ".asm" || ext == ".S"
|
349
400
|
if (@excludes != nil) && (@excludes.include? base)
|
350
401
|
puts "exclude: #{base}"
|
@@ -360,48 +411,81 @@ class MCBuild
|
|
360
411
|
end
|
361
412
|
|
362
413
|
def archive_lib
|
363
|
-
cmd = "
|
364
|
-
puts(cmd)
|
414
|
+
cmd = "#{self.archiver_command} -r #{self.export_lib_path}/lib#{@name}#{@aext} #{@d}/#{@outpath}/*#{@oext}"
|
415
|
+
#puts(cmd)
|
365
416
|
system(cmd)
|
366
417
|
self
|
367
418
|
end
|
368
419
|
|
420
|
+
def archive_so
|
421
|
+
if @position_independent_code
|
422
|
+
cmd = "#{self.compiler_command} -shared -Wl,-soname,lib#{@name}.so"
|
423
|
+
cmd += " -o #{self.export_lib_path}/lib#{@name}.so #{@d}/#{@outpath}/*#{@oext}"
|
424
|
+
cmd += " -Wl,--whole-archive #{@link_arg} -Wl,--no-whole-archive"
|
425
|
+
#puts(cmd)
|
426
|
+
system(cmd)
|
427
|
+
self
|
428
|
+
else
|
429
|
+
puts "Error[#{@d}]: please use set_shared(true) before archive so"
|
430
|
+
nil
|
431
|
+
end
|
432
|
+
end
|
433
|
+
|
369
434
|
def archive_exe
|
370
|
-
cmd = linker_command
|
371
|
-
cmd
|
372
|
-
puts(cmd)
|
435
|
+
cmd = "#{self.linker_command} -o #{self.export_lib_path}/#{@name} #{@d}/#{@outpath}/*#{@oext} #{@link_arg}"
|
436
|
+
#puts(cmd)
|
373
437
|
system(cmd)
|
374
438
|
self
|
375
439
|
end
|
376
440
|
|
441
|
+
def copy_lib_to(path)
|
442
|
+
begin
|
443
|
+
FileUtils.mkdir_p("#{@d}/#{path}")
|
444
|
+
FileUtils.cp("#{self.export_lib_path}/lib#{@name}#{@aext}", "#{@d}/#{path}")
|
445
|
+
rescue Exception => e
|
446
|
+
puts "Error[#{@d}]: " + e.to_s
|
447
|
+
end
|
448
|
+
self
|
449
|
+
end
|
450
|
+
|
451
|
+
def copy_so_to(path)
|
452
|
+
begin
|
453
|
+
FileUtils.mkdir_p("#{@d}/#{path}")
|
454
|
+
FileUtils.cp("#{self.export_lib_path}/lib#{@name}.so", "#{@d}/#{path}")
|
455
|
+
rescue Exception => e
|
456
|
+
puts "Error[#{@d}]: " + e.to_s
|
457
|
+
end
|
458
|
+
self
|
459
|
+
end
|
460
|
+
|
377
461
|
def run
|
378
|
-
system("#{self.
|
462
|
+
system("#{self.export_lib_path}/#{name}")
|
379
463
|
end
|
380
464
|
|
381
465
|
def done
|
382
466
|
puts "---------- build finished ----------"
|
383
|
-
puts "#{self.
|
467
|
+
puts "#{self.export_lib_path}/#{name}"
|
384
468
|
end
|
385
469
|
end
|
386
470
|
|
387
471
|
#test area
|
388
472
|
=begin
|
389
|
-
runt = MCBuild.new('../../../mcruntime')
|
473
|
+
runt = MCBuild.new('../../../monkc1/monkc1/mcruntime')
|
390
474
|
.set_name("monkc")
|
391
475
|
.set_headers(["monkc.h"])
|
392
|
-
.set_excludes(["MCNonLock
|
476
|
+
.set_excludes(["MCNonLock"])
|
393
477
|
.info
|
394
478
|
.compile
|
395
479
|
.archive_lib
|
396
480
|
|
397
|
-
lmt = MCBuild.new('../../../lemontea')
|
481
|
+
lmt = MCBuild.new('../../../monkc1/monkc1/lemontea')
|
398
482
|
.set_name("lemontea")
|
399
483
|
.set_dependency([runt])
|
400
484
|
.info
|
401
485
|
.compile
|
402
486
|
.archive_lib
|
403
487
|
|
404
|
-
exp = MCBuild.new('../../../example')
|
488
|
+
exp = MCBuild.new('../../../monkc1/monkc1/example')
|
405
489
|
.set_name("exp")
|
406
490
|
.set_dependency([runt, lmt])
|
407
491
|
.info
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mcbuild
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.52
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sun Yuli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: sunpaq@gmail.com
|