build.tcl 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #!/usr/bin/env tclsh
  2. #
  3. # Build application bundles.
  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. # initialization
  10. source [file join [file normalize [file dirname $argv0]] init.tcl]
  11. puts ""
  12. puts "========================================================================="
  13. puts " $PROJECT $VERSION: build application bundles"
  14. puts "========================================================================="
  15. puts ""
  16. # Create a binary package, that contains tclkit and application sources.
  17. proc create_package {output tclkit arch {archTarget ""}} {
  18. global BUILD_DIR
  19. global BUILD_SRC_DIR
  20. global BUILD_TCLKIT
  21. global SRC_DIR
  22. global TCLKIT
  23. global SDX
  24. if {$archTarget == ""} {
  25. set archTarget $arch
  26. }
  27. set tclkit_temp [file join $BUILD_DIR [file tail $tclkit]]
  28. file copy -force $tclkit $tclkit_temp
  29. file copy -force [file join $SRC_DIR "data" $arch] [file join $BUILD_SRC_DIR "data" $archTarget]
  30. if { [catch {exec $BUILD_TCLKIT $SDX wrap $output -vfs $BUILD_SRC_DIR -runtime $tclkit_temp} result] } {
  31. puts "ERROR: Can't create binary package!"
  32. puts $::errorInfo
  33. }
  34. file delete -force [file join $BUILD_SRC_DIR "data" $archTarget]
  35. }
  36. # Modify resources of the created EXE file.
  37. proc postprocess_exe {dir} {
  38. global RESHACK
  39. set rc [file join $dir "application.rc"]
  40. set script [file join $dir "reshack.script"]
  41. cd $dir
  42. if {[is_windows]} {
  43. # Execute ResourceHacker.exe directly on Windows systems.
  44. if {$rc != "" && [file isfile $rc]} {
  45. if { [catch {exec $RESHACK -open application.rc -save application.res -action compile -log CONSOLE} result] } {
  46. puts "ERROR: Can't compile resources in windows binary!"
  47. puts $::errorInfo
  48. }
  49. #puts "ResourceHacker: $result"
  50. }
  51. if {$script != "" && [file isfile $script]} {
  52. if { [catch {exec $RESHACK -script "reshack.script"} result] } {
  53. puts "ERROR: Can't modify resources in windows binary!"
  54. puts $::errorInfo
  55. }
  56. #puts "ResourceHacker: $result"
  57. }
  58. } else {
  59. # Execute ResourceHacker.exe through WINE on non-Windows systems.
  60. global WINE
  61. if {$WINE == "" || ![file executable $WINE]} {
  62. puts "ERROR: Can't find a WINE installation!"
  63. puts "Therefore we can't replace icons and resources of the created EXE file."
  64. puts "The created EXE file is still usable but it will contain a TK icon and references to the TK authors."
  65. puts "Install WINE on your system or build the application on a Windows system in order to get an EXE file with correct resources."
  66. return
  67. }
  68. if {$rc != "" && [file isfile $rc]} {
  69. if { [catch {exec $WINE $RESHACK -open application.rc -save application.res -action compile -log CONSOLE} result] } {
  70. puts "ERROR: Can't compile resources in windows binary!"
  71. puts $::errorInfo
  72. }
  73. #puts "ResourceHacker: $result"
  74. }
  75. if {$script != "" && [file isfile $script]} {
  76. if { [catch {exec $WINE $RESHACK -script "reshack.script"} result] } {
  77. puts "ERROR: Can't modify resources in windows binary!"
  78. puts $::errorInfo
  79. }
  80. #puts "ResourceHacker: $result"
  81. }
  82. }
  83. return [file join $dir "application-modified.exe"]
  84. }
  85. set BUILD_SRC_DIR [file join $BUILD_DIR "$PROJECT.vfs"]
  86. if {[is_windows]} {
  87. # Use tclkitsh binary on windows system for packaging.
  88. set BUILD_TCLKIT $TCLKITSH_WINDOWS
  89. } else {
  90. # Use tclkit binary on other systems for packaging.
  91. set BUILD_TCLKIT $TCLKIT
  92. }
  93. puts "cleanup"
  94. if {[file exists $BUILD_DIR]} {
  95. file delete -force $BUILD_DIR
  96. }
  97. if {[file exists $TARGET_DIR]} {
  98. file delete -force $TARGET_DIR
  99. }
  100. file mkdir $BUILD_DIR
  101. file mkdir $TARGET_DIR
  102. puts "prepare build"
  103. file copy $SRC_DIR $BUILD_SRC_DIR
  104. foreach log [glob -nocomplain -directory $BUILD_SRC_DIR -type f "*.log"] {
  105. file delete $log
  106. }
  107. puts "create $PROJECT-$VERSION.kit"
  108. if { [catch {exec $BUILD_TCLKIT $SDX wrap [file join $TARGET_DIR "$PROJECT-$VERSION.kit"] -vfs $BUILD_SRC_DIR} result] } {
  109. puts "ERROR: Can't starkit bundle!"
  110. puts $::errorInfo
  111. }
  112. puts "prepare binary builds"
  113. foreach dir [glob -nocomplain -directory [file join $BUILD_SRC_DIR "data"] -type d "*"] {
  114. file delete -force $dir
  115. }
  116. puts "create $PROJECT-$VERSION-linux-amd64"
  117. create_package [file join $TARGET_DIR "$PROJECT-$VERSION-linux-amd64"] $TCLKIT_LINUX_AMD64 "linux-amd64"
  118. puts "create $PROJECT-$VERSION-linux-i386"
  119. create_package [file join $TARGET_DIR "$PROJECT-$VERSION-linux-i386"] $TCLKIT_LINUX_I386 "linux-i386"
  120. puts "create $PROJECT-$VERSION-macosx"
  121. create_package [file join $TARGET_DIR "$PROJECT-$VERSION-macosx"] $TCLKIT_MAC "darwin"
  122. puts "create $PROJECT-$VERSION.app"
  123. set BUILD_BUNDLE [file join $BUILD_DIR "darwin" "$PROJECT-$VERSION.app"]
  124. file mkdir $BUILD_BUNDLE
  125. file mkdir [file join $BUILD_BUNDLE "Contents"]
  126. file mkdir [file join $BUILD_BUNDLE "Contents" "Framework"]
  127. file mkdir [file join $BUILD_BUNDLE "Contents" "MacOS"]
  128. file mkdir [file join $BUILD_BUNDLE "Contents" "Resources"]
  129. file copy [file join $BASE_DIR "misc" "darwin" "Info.plist"] [file join $BUILD_BUNDLE "Contents"]
  130. file copy [file join $BASE_DIR "misc" "darwin" "application.icns"] [file join $BUILD_BUNDLE "Contents" "Resources"]
  131. file copy [file join $TARGET_DIR "$PROJECT-$VERSION-macosx"] [file join $BUILD_BUNDLE "Contents" "MacOS" "application"]
  132. targz $BUILD_BUNDLE [file join $TARGET_DIR "$PROJECT-$VERSION-macosx.app.tar.gz"]
  133. puts "create $PROJECT-$VERSION.exe"
  134. set BUILD_WINDOWS_DIR [file join $BUILD_DIR "windows"]
  135. file mkdir $BUILD_WINDOWS_DIR
  136. create_package [file join $BUILD_WINDOWS_DIR "application.exe"] $TCLKIT_WINDOWS "windows"
  137. puts "post processing $PROJECT-$VERSION.exe"
  138. file copy [file join $BASE_DIR "misc" "windows" "application.ico"] [file join $BUILD_WINDOWS_DIR "application.ico"]
  139. file copy [file join $BASE_DIR "misc" "windows" "application.rc"] [file join $BUILD_WINDOWS_DIR "application.rc"]
  140. file copy [file join $BASE_DIR "misc" "windows" "reshack.script"] [file join $BUILD_WINDOWS_DIR "reshack.script"]
  141. set modifiedExe [postprocess_exe $BUILD_WINDOWS_DIR]
  142. if {$modifiedExe != "" && [file isfile $modifiedExe]} {
  143. file copy [file join $BUILD_WINDOWS_DIR "application-modified.exe"] [file join $TARGET_DIR "$PROJECT-$VERSION.exe"]
  144. } else {
  145. file copy [file join $BUILD_WINDOWS_DIR "application.exe"] [file join $TARGET_DIR "$PROJECT-$VERSION.exe"]
  146. }
  147. puts "create $PROJECT-$VERSION-xp.exe"
  148. set BUILD_WINDOWS_DIR [file join $BUILD_DIR "windows-xp"]
  149. file mkdir $BUILD_WINDOWS_DIR
  150. create_package [file join $BUILD_WINDOWS_DIR "application.exe"] $TCLKIT_WINDOWS "windows-xp" "windows"
  151. puts "post processing $PROJECT-$VERSION-xp.exe"
  152. file copy [file join $BASE_DIR "misc" "windows" "application.ico"] [file join $BUILD_WINDOWS_DIR "application.ico"]
  153. file copy [file join $BASE_DIR "misc" "windows" "application.rc"] [file join $BUILD_WINDOWS_DIR "application.rc"]
  154. file copy [file join $BASE_DIR "misc" "windows" "reshack.script"] [file join $BUILD_WINDOWS_DIR "reshack.script"]
  155. set modifiedExe [postprocess_exe $BUILD_WINDOWS_DIR]
  156. if {$modifiedExe != "" && [file isfile $modifiedExe]} {
  157. file copy [file join $BUILD_WINDOWS_DIR "application-modified.exe"] [file join $TARGET_DIR "$PROJECT-$VERSION-xp.exe"]
  158. } else {
  159. file copy [file join $BUILD_WINDOWS_DIR "application.exe"] [file join $TARGET_DIR "$PROJECT-$VERSION-xp.exe"]
  160. }
  161. # On Windows systems there is an unusable bat file written into the target folder.
  162. # To avoid any confusions we're deleting this file.
  163. foreach f [glob -nocomplain -directory $TARGET_DIR -type f "*.bat"] {
  164. file delete $f
  165. }