utils.tcl 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. #!/usr/bin/env tclsh
  2. #
  3. # Helper functions for the build environment.
  4. #
  5. # Copyright 2015-2017 OpenIndex.de.
  6. # Distributed under the MIT License.
  7. # See accompanying LICENSE.txt file or at http://opensource.org/licenses/MIT
  8. #
  9. proc get_machine {} {
  10. global tcl_platform
  11. set machine $::tcl_platform(machine)
  12. if {$machine == "x86_64" || $machine == "amd64"} {
  13. return "amd64"
  14. }
  15. if {$machine == "i686" || $machine == "i586" || $machine == "i386"} {
  16. return "i386"
  17. }
  18. return
  19. }
  20. proc get_tclkit {} {
  21. global TCLKIT_LINUX_AMD64
  22. global TCLKIT_LINUX_I386
  23. global TCLKIT_MAC
  24. global TCLKIT_WINDOWS
  25. if {[is_darwin]} {
  26. return $TCLKIT_MAC
  27. }
  28. if {[is_linux]} {
  29. set machine [get_machine]
  30. if {$machine == "amd64"} {
  31. return $TCLKIT_LINUX_AMD64
  32. }
  33. if {$machine == "i386"} {
  34. return $TCLKIT_LINUX_I386
  35. }
  36. }
  37. if {[is_windows]} {
  38. return $TCLKIT_WINDOWS
  39. }
  40. error "There is no tclkit available for your operating system!"
  41. }
  42. proc is_darwin {} {
  43. global tcl_platform
  44. set os [string tolower $tcl_platform(os)]
  45. return [string match "darwin*" $os]
  46. }
  47. proc is_linux {} {
  48. global tcl_platform
  49. set os [string tolower $tcl_platform(os)]
  50. return [string match "linux*" $os]
  51. }
  52. proc is_windows {} {
  53. global tcl_platform
  54. set os [string tolower $tcl_platform(os)]
  55. return [string match "windows*" $os]
  56. }
  57. proc targz {dir archive} {
  58. cd [file dirname $dir]
  59. set name [file tail $dir]
  60. #package require tar
  61. #set chan [open $archive a]
  62. #zlib push gzip $chan
  63. #tar::create $chan {*}[glob -nocomplain "$name/*"] -chan
  64. #::tar::contents new.tar
  65. #close $chan
  66. if {[is_darwin] || [is_linux]} {
  67. global TAR
  68. if {[catch {exec $TAR cfz $archive $name} result]} {
  69. puts "ERROR: Can't create TAR.GZ archive!"
  70. if {$result != ""} { puts $result }
  71. puts $::errorInfo
  72. }
  73. return
  74. }
  75. if {[is_windows]} {
  76. global SEVENZIP
  77. #Archive test1.txt and test2.txt into test.tar
  78. # 7z a -ttar test.tar test1.txt test2.txt
  79. #Compress test.tar to test.tgz
  80. # 7z a -tgzip test.tgz test.tar
  81. set temp "$name.tar"
  82. if {[catch {exec $SEVENZIP a -ttar $temp $name} result]} {
  83. puts "ERROR: Can't create TAR archive!"
  84. if {$result != ""} { puts $result }
  85. puts $::errorInfo
  86. }
  87. if {[catch {exec $SEVENZIP a -tgzip $archive $temp} result]} {
  88. puts "ERROR: Can't create TAR.GZ archive!"
  89. if {$result != ""} { puts $result }
  90. puts $::errorInfo
  91. }
  92. return
  93. }
  94. error "The targz method is not implemented for your operating system!"
  95. }
  96. proc touch {path} {
  97. if {[is_darwin] || [is_linux]} {
  98. if {[catch {exec touch $path} result]} {
  99. puts "ERROR: Can't execute touch!"
  100. if {$result != ""} { puts $result }
  101. puts $::errorInfo
  102. }
  103. return
  104. }
  105. if {[is_windows]} {
  106. global UTILS_DIR
  107. if {[catch {exec [file nativename [file join $UTILS_DIR touch.bat]] [file nativename $path]} result]} {
  108. puts "ERROR: Can't execute touch!"
  109. if {$result != ""} { puts $result }
  110. puts $::errorInfo
  111. }
  112. return
  113. }
  114. error "The touch method is not implemented for your operating system!"
  115. }
  116. proc which {command} {
  117. if {[is_darwin] || [is_linux]} {
  118. if {[catch {exec which $command} result]} {
  119. puts "WARNING: Can't find the \"$command\" application!"
  120. #if {$result != ""} { puts $result }
  121. #puts $::errorInfo
  122. return
  123. }
  124. return $result
  125. }
  126. if {[is_windows]} {
  127. if {[catch {exec where $command} result]} {
  128. puts "WARNING: Can't find the \"$command\" application!"
  129. #if {$result != ""} { puts $result }
  130. #puts $::errorInfo
  131. return
  132. }
  133. return $result
  134. }
  135. error "The which method is not implemented for your operating system!"
  136. }