pretty.build 2.1 KB

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