2
0

pretty.build 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. if (!($filename =~ "sober128tab.c")) {
  24. ++$count;
  25. }}}}}}}}
  26. }
  27. print "Source files to build: $count\nBuilding...\n";
  28. my $i = 0;
  29. my $lines = 0;
  30. my $filesbuilt = 0;
  31. foreach my $filename (glob "*.c") {
  32. if (!($filename =~ "aes_tab.c")) {
  33. if (!($filename =~ "twofish_tab.c")) {
  34. if (!($filename =~ "whirltab.c")) {
  35. if (!($filename =~ "sha224.c")) {
  36. if (!($filename =~ "sha384.c")) {
  37. if (!($filename =~ "dh_sys.c")) {
  38. if (!($filename =~ "ecc_sys.c")) {
  39. if (!($filename =~ "sober128tab.c")) {
  40. printf("Building %3.2f%%, ", (++$i/$count)*100.0);
  41. if ($i % 4 == 0) { print "/, "; }
  42. if ($i % 4 == 1) { print "-, "; }
  43. if ($i % 4 == 2) { print "\\, "; }
  44. if ($i % 4 == 3) { print "|, "; }
  45. if ($rate > 0) {
  46. my $tleft = ($count - $i) / $rate;
  47. my $tsec = $tleft%60;
  48. my $tmin = ($tleft/60)%60;
  49. my $thour = ($tleft/3600)%60;
  50. printf("%2d:%02d:%02d left, ", $thour, $tmin, $tsec);
  51. }
  52. my $cnt = ($i/$count)*30.0;
  53. my $x = 0;
  54. print "[";
  55. for (; $x < $cnt; $x++) { print "#"; }
  56. for (; $x < 30; $x++) { print " "; }
  57. print "]\r";
  58. my $tmp = $filename;
  59. $tmp =~ s/\.c/".o"/ge;
  60. if (open(SRC, "<$tmp")) {
  61. close SRC;
  62. } else {
  63. !system("make $tmp > /dev/null 2>/dev/null") or die "\nERROR: Failed to make $tmp!!!\n";
  64. open( SRC, "<$filename" ) or die "Couldn't open $filename for reading: $!";
  65. ++$lines while (<SRC>);
  66. close SRC or die "Error closing $filename after reading: $!";
  67. ++$filesbuilt;
  68. }
  69. # update timer
  70. if (time != $starttime) {
  71. my $delay = time - $starttime;
  72. $rate = $i/$delay;
  73. }
  74. }}}}}}}}
  75. }
  76. # finish building the library
  77. printf("\nFinished building source (%d seconds, %3.2f files per second).\n", time - $starttime, $rate);
  78. print "Compiled approximately $filesbuilt files and $lines lines of code.\n";
  79. print "Doing final make (building archive...)\n";
  80. !system("make > /dev/null 2>/dev/null") or die "\nERROR: Failed to perform last make command!!!\n";
  81. print "done.\n";