Debian Codegraph @

Rakefile.rb

raw symbols SCIP
1 require 'date'
2
3 $target = 'tbprobe'
4 $sources = 'sources.txt'
5
6 #switches_gcc = '-lpthread -lm -Wwrite-strings -Wshadow -Wconversion -W -Wall -Wextra -Wcast-qual -ansi -pedantic -O2 '
7 $switches_gcc = '-lpthread -lm -Wwrite-strings -Wshadow -Wconversion -W -Wall -Wextra -O2 '
8 $switches_icc = '-lpthread -Wall -O2 '
9 #-wd981,593,2259
10
11 $include = []
12 $include << 'sysport/'
13 $include << 'compression/'
14 $include << 'compression/liblzf/'
15 $include << 'compression/zlib/'
16 $include << 'compression/lzma/'
17 $include << 'compression/huffman/'
18
19 $dswitches = []
20 $dswitches << 'Z_PREFIX'
21 $dswitches << 'NDEBUG'
22
23 $profile_data_folder = '/media/bigdisk/profdata/'
24 $benchfile = 'pgo-medium.txt'
25
26 $sync_line = ''
27
28 $windows_destiny = '/home/miguel/Desktop/tbprobe-windows'
29 $version_sensitive = 'tbprobe.o'
30 #------------------------------------------------------------------------------------
31 $errors_comp = 'errors_comp.txt'
32 $errors_link = 'errors_link.txt'
33
34 def build_clist filelist
35 sl = []
36 File.open filelist, "r" do |f|
37 lines = f.readlines
38 lines.each do |line|
39 if line != nil
40 line = line.chomp.strip
41 if line != ''
42 firstchar = line[0,1]
43 if firstchar != ';'
44 sl << line
45 end
46 end
47 end
48 end
49 end
50 return sl
51 end
52
53 def build_c c
54 elements = []
55 elements << $compiler
56 elements << series('-I', $include)
57 elements << series('-D', $dswitches)
58 elements << $switches
59 elements << '-c'
60 elements << c
61 line = glue(elements)
62 end
63
64 def series s, list
65 build = ''
66 list.each do |x|
67 build = build+' '+s+' '+x
68 end
69 build = build.strip
70 end
71
72 def glue list
73 build = ''
74 list.each do |x|
75 build = build+' '+x
76 end
77 build = build.strip
78 end
79
80 #------------------------------------------------------------------------------------
81 def sources_line filelist
82 sources = ''
83 File.open filelist, "r" do |f|
84 lines = f.readlines
85 lines.each do |line|
86 if line != nil
87 line = line.chomp.strip
88 firstchar = line[0,1]
89 if firstchar != ';'
90 sources += line + ' '
91 end
92 end
93 end
94 end
95 sources = sources.strip
96 return sources
97 end
98
99 def rebuild_line
100 elements = []
101 elements << $compiler
102 elements << series('-I', $include)
103 elements << series('-D', $dswitches)
104 elements << $switches
105 elements << '-o'
106 elements << $target
107 elements << sources_line($sources)
108 line = glue(elements)
109 end
110
111 def go_rebuild s
112 tf = 'temporary-output.txt'
113 puts "compiling " + $target + "...\n"
114 # actual compilation
115 ok = system(s)
116 if ok
117 # get version
118 system ('./'+ $target +' -v > ' + tf)
119 out = `cat temporary-output.txt`
120 puts out
121 cleanfile(tf)
122 puts "done\n"
123 else
124 puts 'Compiling errors.'
125 end
126 end
127
128 def cleanfile x
129 if File.exist?(x)
130 system ('rm ' + x)
131 end
132 end
133
134 def cleanlist filelist
135 filelist.each do |f|
136 cleanfile(f)
137 end
138 end
139
140 def cleanpattern p
141 x = Dir[p]
142 cleanlist(x)
143 end
144
145 #--------------#
146 # name target #
147 #--------------#
148
149 task :name do
150 File.open "progname.h", 'w' do |f|
151 f.write '#define PROGRAM_NAME "'+ $target +'"'+"\n"
152 end
153 end
154
155
156 #--------------#
157 # sync #
158 #--------------#
159
160 task :sync do
161 if $sync_line != ''
162 system($sync_line)
163 end
164 end
165
166
167 #--------------#
168 # Clean target #
169 #--------------#
170
171 task :remove_h_sensitive do
172 if (!FileUtils.uptodate?($version_sensitive, 'version.h'))
173 cleanfile($version_sensitive)
174 end
175 end
176
177 task :clean_target => [:remove_h_sensitive] do
178 cleanfile($target)
179 end
180
181 #----------------#
182 # Clean pgo data #
183 #----------------#
184
185 task :clean_pgodata do
186 cleanpattern($profile_data_folder+'*.dyn')
187 cleanpattern($profile_data_folder+'*.dpi')
188 cleanpattern($profile_data_folder+'*.dpi.lock')
189 end
190
191 #--------------#
192 # DEFAULT TASK #
193 #--------------#
194
195 task :default => :gcc2 do
196 puts " "
197 end
198
199 #--------------#
200 # GCC TASK #
201 #--------------#
202
203 task :gcc => [:clean_target, :sync, :name] do
204 $compiler = 'gcc'
205 $switches = $switches_gcc
206 go_rebuild(rebuild_line)
207 end
208
209
210 #--------------#
211 # GCC TASK #
212 #--------------#
213
214 task :gdb => [:clean_target, :sync, :name] do
215 $compiler = 'gcc'
216 $switches = '-g ' + $switches_gcc
217 go_rebuild(rebuild_line)
218 end
219
220 #--------------#
221 # GCC TASK #
222 #--------------#
223
224 task :debug => [:clean_target, :sync, :name] do
225 $compiler = 'gcc'
226 $switches = '-D DEBUG ' + $switches_gcc
227 go_rebuild(rebuild_line)
228 end
229
230 #--------------#
231 # INTEL TASK #
232 #--------------#
233
234 task :intel => [:clean_target, :sync, :name] do
235 $compiler = 'icc'
236 $switches = $switches_icc
237 go_rebuild(rebuild_line)
238 end
239
240
241 #--------------#
242 # PGO BEGIN #
243 #--------------#
244
245 task :pgo_begin => [:clean_target, :clean_pgodata, :sync, :name] do
246
247 $compiler = 'icc'
248 $switches = '-I lzma -D GCCLINUX -lpthread -Wall -wd981,593,2259 -O2 '
249 $switches += '-prof-gen -prof-dir '+$profile_data_folder
250
251 errorfile = 'icc-err-begin.txt'
252 cleanfile(errorfile)
253 li = rebuild_line+' 2> '+errorfile
254 go_rebuild(li)
255 system = ('cat '+errorfile)
256
257 end
258
259
260 #------------#
261 # PGO TEST #
262 #------------#
263
264 task :test => [:pgo_begin] do
265 system ('./'+$target+' < '+$benchfile)
266 end
267
268
269 #------------#
270 # PGO END #
271 #------------#
272
273 task :pgo_end => [:test, :name] do
274
275 $compiler = 'icc'
276 $switches = '-I lzma -D GCCLINUX -lpthread -Wall -wd981,593,2259 -O2 '
277 $switches += '-prof-use -ipo -prof-dir '+$profile_data_folder
278
279 errorfile = 'icc-err-ending.txt'
280 cleanfile(errorfile)
281 li = rebuild_line+' 2> '+errorfile
282 go_rebuild(li)
283 system = ('cat '+errorfile)
284
285 end
286
287 task :pgo => :pgo_end
288
289 #--------------#
290 # GCC SEE #
291 #--------------#
292
293 task :see do
294 $compiler = 'gcc'
295 $switches = $switches_gcc
296 puts rebuild_line
297 end
298
299
300 ###################################################################################
301
302 require 'fileutils.rb'
303
304 def to_obj x
305 newname = File.basename(x, File.extname(x)) + '.o'
306 arr = File.split(x.strip)
307 t = File.join(arr[0],newname)
308 t
309 end
310
311 def build_clist filelist
312 sl = []
313 File.open filelist, "r" do |f|
314 lines = f.readlines
315 lines.each do |line|
316 if line != nil
317 line = line.chomp.strip
318 if line != ''
319 firstchar = line[0,1]
320 if firstchar != ';'
321 sl << line
322 end
323 end
324 end
325 end
326 end
327 return sl
328 end
329
330 def build_olist clist
331 olist = []
332 clist.each do |x|
333 olist << to_obj(x)
334 end
335 return olist
336 end
337
338 def build_objects compiler, switches, clist
339 ok = 1 == 1;
340 clist.each do |src|
341 unless FileUtils.uptodate?(to_obj(src), src)
342 print src + ': '
343 ok = ok && compile_o(compiler,switches,src)
344 if (ok)
345 puts '-> ' + to_obj(src)
346 else
347 puts '=> ERROR'
348 end
349 if (!ok)
350 break
351 end
352 end
353 end
354 return ok
355 end
356
357
358 def compile_line compiler, switches, c
359 elements = []
360 elements << compiler
361 elements << series('-I', $include)
362 elements << series('-D', $dswitches)
363 elements << switches
364 elements << '-c'
365 elements << '-o'
366 elements << to_obj(c)
367 elements << c
368 line = glue(elements)
369 end
370
371 def link_line compiler, switches, target, olist
372 elements = []
373 elements << compiler
374 #elements << series('-I', $include)
375 #elements << series('-D', $dswitches)
376 elements << switches
377 elements << '-o'
378 elements << target
379 elements << glue(olist)
380 line = glue(elements)
381 end
382
383
384 def compile_o compiler,switches, src
385 y = compile_line(compiler,switches,src)
386 system(y + ' 2> ' + $errors_comp)
387 end
388
389 def link compiler,switches,target,olist
390 y = link_line(compiler,switches,target,olist)
391 system(y + ' 2> ' + $errors_link)
392 end
393
394 def clean_objects clist
395 clist.each do |src|
396 o = to_obj(src)
397 cleanfile(o)
398 end
399 end
400
401 def errors2screen
402 if File.exist?('errors_comp.txt')
403 puts `cat errors_comp.txt`
404 end
405 if File.exist?('errors_link.txt')
406 puts `cat errors_link.txt`
407 end
408 end
409
410 #--------------#
411 # gcc2 #
412 #--------------#
413
414 task :gcc2 => [:clean_target, :sync, :name] do
415 $compiler = 'gcc'
416 $switches = $switches_gcc
417 c_array = build_clist($sources)
418 o_array = build_olist(c_array)
419 ok = build_objects($compiler,$switches, c_array)
420 ok = ok && link($compiler,$switches, $target, o_array)
421
422 errors2screen
423
424 if ok
425 # get version
426 tf = 'temporary-output.txt'
427 system ('./'+ $target +' -v > ' + tf)
428 out = `cat temporary-output.txt`
429 puts out
430 cleanfile(tf)
431 puts "done!\n"
432 else
433 puts '*** Compiling errors ***'
434 end
435
436 end
437
438 #--------------#
439 # CLEAN #
440 #--------------#
441
442 task :clean => [:clean_target] do
443 clean_objects(build_clist($sources))
444 end
445
446 task :clobber => [:clean] do
447 list = Dir['*~']
448 list.each do |src|
449 puts(src)
450 cleanfile(src)
451 end
452 list = Dir['errors_*']
453 list.each do |src|
454 puts(src)
455 cleanfile(src)
456 end
457 end
458
459 #--------------#
460 # DEPLOY #
461 #--------------#
462
463 def copyline dpath, name
464 el = []
465 el << 'cp'
466 el << name
467 el << File.join(dpath,name)
468 line = glue(el)
469 return line
470 end
471
472 def uncopyline dpath, name
473 el = []
474 el << 'cp'
475 el << File.join(dpath,name)
476 el << name
477 line = glue(el)
478 return line
479 end
480
481 def cmpline dpath, name
482 el = []
483 el << 'cmp'
484 el << name
485 el << File.join(dpath,name)
486 line = glue(el)
487 return line
488 end
489
490 def diffline dpath, name
491 el = []
492 el << 'diff --ignore-space-change --ignore-blank-lines --ignore-all-space --brief'
493 el << name
494 el << File.join(dpath,name)
495 line = glue(el)
496 return line
497 end
498
499 def xxdiffline dpath, x
500 el = []
501 el << 'xxdiff --ignore-space-change --ignore-blank-lines --ignore-all-space --merge'
502 el << x
503 el << File.join(dpath,x)
504 line = glue(el)
505 end
506
507
508 def uncopy_if_notupdated dpath, x
509 ok = system(cmpline(dpath,x))
510 if (!ok && !FileUtils.uptodate?(x, File.join(dpath,x)))
511 system uncopyline(dpath,x)
512 end
513 end
514
515 def multichomp x
516 y = x
517 z = x.chomp
518 while z != y do
519 y = z
520 z = z.chomp
521 end
522 z
523 end
524
525 $home_dir = '/home/miguel'
526 $current_dir = '/media/bigdisk/gaviotadev/'
527
528 def valid_destination x
529 ok = x != nil && x != '' && x != './' && x != $home_dir && x != ($home_dir+'/')
530 ok
531 end
532
533 def currdir
534 `pwd`.chomp
535 end
536
537 task :get_homedir do
538 $home_dir = `echo $HOME`.chomp
539 end
540
541 task :get_currentdir do
542 $current_dir = `pwd`.chomp + '/'
543 end
544
545 def select_folder default
546 if (File.exist?(default))
547 system 'zenity --file-selection --directory --filename='+default+'> zenityanswer.txt'
548 else
549 owndir = currdir + '/'
550 system 'zenity --file-selection --directory --filename='+owndir+'> zenityanswer.txt'
551 end
552 folder =`cat zenityanswer.txt`
553 folder = multichomp(folder)
554 default = folder
555 default
556 end
557
558 task :select_deploy_destiny => [:get_homedir] do
559 $windows_destiny = select_folder($windows_destiny)
560 end
561
562 task :deploy => [:gcc2, :select_deploy_destiny, :get_homedir, :get_currentdir] do
563
564 if (valid_destination($windows_destiny))
565
566 destiny = $windows_destiny
567 own_location = $current_dir
568
569 rs = []
570 rs << 'rsync'
571 rs << '-vr'
572 rs << '-f"- .git"'
573 rs << '-f"+ */"'
574 rs << '-f"- *"'
575 rs << own_location
576 rs << destiny
577 system glue(rs)
578
579 c_array = build_clist($sources)
580 c_array.each do |x|
581 system copyline(destiny,x)
582 end
583
584 h_array = Dir['*.h']
585 h_array.each do |z|
586 system copyline(destiny,z)
587 end
588
589 i_array = $include
590 i_array.each do |x|
591 pattern = File.join(x,'*.h')
592 h_array = Dir[pattern]
593 h_array.each do |z|
594 system copyline(destiny,z)
595 end
596 end
597
598 puts 'Deployed project to: '+destiny
599
600 else
601 if ($windows_destiny == nil || $windows_destiny.strip == '')
602 puts 'Cancelled deployment'
603 else
604 puts 'Cancelled deployment to: '+$windows_destiny
605 end
606 end
607
608 end
609
610
611 task :inploy => [:select_deploy_destiny, :get_homedir, :get_currentdir] do
612
613 destiny = $windows_destiny
614
615 c_array = build_clist($sources)
616 c_array.each do |x|
617 uncopy_if_notupdated(destiny,x)
618 end
619
620 h_array = Dir['*.h']
621 h_array.each do |z|
622 uncopy_if_notupdated(destiny,z)
623 end
624
625 i_array = $include
626 i_array.each do |x|
627 pattern = File.join(x,'*.h')
628 h_array = Dir[pattern]
629 h_array.each do |z|
630 uncopy_if_notupdated(destiny,z)
631 end
632 end
633
634 puts 'In-ployed project from: '+destiny
635 end
636
637 #--------------#
638 # COMPARE #
639 #--------------#
640
641 def checkdiff dpath,z
642 if (system(diffline(dpath,z)))
643 puts '--------------------------------> '+z+': is ok'
644 else
645 system(xxdiffline(dpath,z))
646 end
647 end
648
649 task :compare => [:select_deploy_destiny, :get_homedir, :get_currentdir] do
650
651 destiny = $windows_destiny
652
653 c_array = build_clist($sources)
654 c_array.each do |z|
655 checkdiff(destiny,z)
656 end
657
658 h_array = Dir['*.h']
659 h_array.each do |z|
660 checkdiff(destiny,z)
661 end
662
663 i_array = $include
664 i_array.each do |x|
665 pattern = File.join(x,'*.h')
666 h_array = Dir[pattern]
667 h_array.each do |z|
668 checkdiff(destiny,z)
669 end
670 end
671
672 puts 'In-ployed project from: '+destiny
673
674 end
675
676 #--------------#
677 # SPLINT #
678 #--------------#
679
680 task :splint do
681 system ('rm splint.txt')
682 c_array = build_clist($sources)
683 c_array.each do |s|
684 system './splintcheck.sh '+s
685 end
686 end
687
688
689 #--------------#
690 # TO WEBFOLDER #
691 #--------------#
692 $webfolder = ''
693
694 task :select_webfolder => [:get_homedir] do
695 $webfolder = select_folder($webfolder)
696 end
697
698 task :to_web => [:intel, :get_homedir, :select_webfolder] do
699 ok = false
700 if (valid_destination($webfolder))
701 ok = system copyline($webfolder, $target)
702 end
703 if (ok)
704 puts 'succesful copy of '+ $target
705 else
706 puts 'failed to copy '+ $target
707 end
708 end
709
710
711
712 #--------------#
713 # DUMMY TASK #
714 #--------------#
715
716 task :dummy do
717 puts "dummy test\n"
718 end
719
720
721
722
723
724
725
726