pretty.build 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/perl -w
  2. #
  3. # Cute little builder for perl
  4. # Total waste of development time...
  5. #
  6. # This will build all the object files and then the archive .a file
  7. # requires GCC, GNU make and a sense of humour.
  8. #
  9. # Tom St Denis
  10. use strict;
  11. my $count = 0;
  12. my $starttime = time;
  13. my $rate = 0;
  14. print "Scanning for source files...\n";
  15. foreach my $filename (glob "*.c") {
  16. if (!($filename =~ "aes_tab.c")) {
  17. if (!($filename =~ "twofish_tab.c")) {
  18. if (!($filename =~ "whirltab.c")) {
  19. if (!($filename =~ "sha224.c")) {
  20. if (!($filename =~ "sha384.c")) {
  21. if (!($filename =~ "dh_sys.c")) {
  22. if (!($filename =~ "ecc_sys.c")) {
  23. ++$count;
  24. }}}}}}}
  25. }
  26. print "Source files to build: $count\nBuilding...\n";
  27. my $i = 0;
  28. my $lines = 0;
  29. my $filesbuilt = 0;
  30. foreach my $filename (glob "*.c") {
  31. if (!($filename =~ "aes_tab.c")) {
  32. if (!($filename =~ "twofish_tab.c")) {
  33. if (!($filename =~ "whirltab.c")) {
  34. if (!($filename =~ "sha224.c")) {
  35. if (!($filename =~ "sha384.c")) {
  36. if (!($filename =~ "dh_sys.c")) {
  37. if (!($filename =~ "ecc_sys.c")) {
  38. printf("Building %3.2f%%, ", (++$i/$count)*100.0);
  39. if ($i % 4 == 0) { print "/, "; }
  40. if ($i % 4 == 1) { print "-, "; }
  41. if ($i % 4 == 2) { print "\\, "; }
  42. if ($i % 4 == 3) { print "|, "; }
  43. if ($rate > 0) {
  44. my $tleft = ($count - $i) / $rate;
  45. my $tsec = $tleft%60;
  46. my $tmin = ($tleft/60)%60;
  47. my $thour = ($tleft/3600)%60;
  48. printf("%2d:%02d:%02d left, ", $thour, $tmin, $tsec);
  49. }
  50. my $cnt = ($i/$count)*30.0;
  51. my $x = 0;
  52. print "[";
  53. for (; $x < $cnt; $x++) { print "#"; }
  54. for (; $x < 30; $x++) { print " "; }
  55. print "]\r";
  56. my $tmp = $filename;
  57. $tmp =~ s/\.c/".o"/ge;
  58. if (open(SRC, "<$tmp")) {
  59. close SRC;
  60. } else {
  61. !system("make $tmp > /dev/null 2>/dev/null") or die "\nERROR: Failed to make $tmp!!!\n";
  62. open( SRC, "<$filename" ) or die "Couldn't open $filename for reading: $!";
  63. ++$lines while (<SRC>);
  64. close SRC or die "Error closing $filename after reading: $!";
  65. ++$filesbuilt;
  66. }
  67. # update timer
  68. if (time != $starttime) {
  69. my $delay = time - $starttime;
  70. $rate = $i/$delay;
  71. }
  72. }}}}}}}
  73. }
  74. # finish building the library
  75. printf("\nFinished building source (%d seconds, %3.2f files per second).\n", time - $starttime, $rate);
  76. print "Compiled approximately $filesbuilt files and $lines lines of code.\n";
  77. print "Doing final make (building archive...)\n";
  78. !system("make > /dev/null 2>/dev/null") or die "\nERROR: Failed to perform last make command!!!\n";
  79. print "done.\n";