Posted to tcl by dbohdan at Sat Apr 25 18:44:58 GMT 2015view raw

  1. #!/usr/bin/env tclsh
  2. # Assemble, a tool for bundling Tcl source files.
  3. # Copyright (C) 2015 Danyil Bohdan
  4. # License: MIT
  5. package require fileutil
  6.  
  7. namespace eval ::assemble {}
  8.  
  9. proc ::assemble::assemble filename {
  10. set main [::fileutil::cat $filename]
  11. set output {}
  12. foreach line [split $main \n] {
  13. if {[regexp {^source\+ (.*)$} $line _ includeFilename]} {
  14. append output "# === $includeFilename begin === \n"
  15. append output [::fileutil::cat $includeFilename]\n
  16. append output "# === $includeFilename end ===\n"
  17. } else {
  18. append output $line\n
  19. }
  20. }
  21. puts $output
  22. }
  23.  
  24. # If this is the main script...
  25. if {[info exists argv0] && ([file tail [info script]] eq [file tail $argv0])} {
  26. ::assemble::assemble {*}$argv
  27. }
  28.