GetTclKit.bat 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. @ECHO OFF
  2. ::
  3. :: GetTclKit.bat --
  4. ::
  5. :: TclKit Download Tool
  6. ::
  7. SETLOCAL
  8. REM SET __ECHO=ECHO
  9. REM SET __ECHO2=ECHO
  10. REM SET __ECHO3=ECHO
  11. IF NOT DEFINED _AECHO (SET _AECHO=REM)
  12. IF NOT DEFINED _CECHO (SET _CECHO=REM)
  13. IF NOT DEFINED _CECHO2 (SET _CECHO2=REM)
  14. IF NOT DEFINED _CECHO3 (SET _CECHO3=REM)
  15. IF NOT DEFINED _VECHO (SET _VECHO=REM)
  16. SET OVERWRITE=^>
  17. IF DEFINED __ECHO SET OVERWRITE=^^^>
  18. SET APPEND=^>^>
  19. IF DEFINED __ECHO SET APPEND=^^^>^^^>
  20. SET PROCESSOR=%1
  21. IF DEFINED PROCESSOR (
  22. CALL :fn_UnquoteVariable PROCESSOR
  23. ) ELSE (
  24. GOTO usage
  25. )
  26. SET PROCESSOR=%PROCESSOR:AMD64=x64%
  27. %_VECHO% Processor = '%PROCESSOR%'
  28. SET DUMMY2=%2
  29. IF DEFINED DUMMY2 (
  30. GOTO usage
  31. )
  32. IF NOT DEFINED ENVDIR (
  33. SET ENVDIR=%CD%
  34. )
  35. %_VECHO% EnvDir = '%ENVDIR%'
  36. SET TOOLS=%~dp0
  37. SET TOOLS=%TOOLS:~0,-1%
  38. %_VECHO% Tools = '%TOOLS%'
  39. IF NOT DEFINED windir (
  40. ECHO The windir environment variable must be set first.
  41. GOTO errors
  42. )
  43. %_VECHO% WinDir = '%windir%'
  44. IF NOT DEFINED TEMP (
  45. ECHO The TEMP environment variable must be set first.
  46. GOTO errors
  47. )
  48. %_VECHO% Temp = '%TEMP%'
  49. IF NOT DEFINED TCLKIT_URI (
  50. SET TCLKIT_URI=https://urn.to/r/tclsh/
  51. )
  52. %_VECHO% TclKitUri = '%TCLKIT_URI%'
  53. IF NOT DEFINED TCLKIT_PATCHLEVEL (
  54. SET TCLKIT_PATCHLEVEL=8.6.6
  55. )
  56. %_VECHO% TclKitPatchLevel = '%TCLKIT_PATCHLEVEL%'
  57. IF NOT DEFINED TCLKIT_EXE_PATCHLEVEL (
  58. SET TCLKIT_EXE_PATCHLEVEL=8.6.4
  59. )
  60. %_VECHO% TclKitExePatchLevel = '%TCLKIT_EXE_PATCHLEVEL%'
  61. IF /I "%PROCESSOR%" == "x86" (
  62. CALL :fn_TclKitX86Variables
  63. IF ERRORLEVEL 1 (
  64. GOTO errors
  65. )
  66. ) ELSE IF /I "%PROCESSOR%" == "x64" (
  67. CALL :fn_TclKitX64Variables
  68. IF ERRORLEVEL 1 (
  69. GOTO errors
  70. )
  71. ) ELSE (
  72. GOTO usage
  73. )
  74. %_VECHO% TclKitVersion = '%TCLKIT_VERSION%'
  75. %_VECHO% TclKitPatchLevel = '%TCLKIT_PATCHLEVEL%'
  76. %_VECHO% TclKitExePatchLevel = '%TCLKIT_EXE_PATCHLEVEL%'
  77. %_VECHO% TclKitNoEnv = '%TCLKIT_NOENV%'
  78. %_VECHO% TclKitNoSdk = '%TCLKIT_NOSDK%'
  79. %_VECHO% TclKitExe = '%TCLKIT_EXE%'
  80. %_VECHO% TclKitLib = '%TCLKIT_LIB%'
  81. %_VECHO% TclKitLibStub = '%TCLKIT_LIB_STUB%'
  82. %_VECHO% TclKitSdk = '%TCLKIT_SDK%'
  83. %_VECHO% TclKitSdkZip = '%TCLKIT_SDK_ZIP%'
  84. %_VECHO% TclKitFiles = '%TCLKIT_FILES%'
  85. CALL :fn_ResetErrorLevel
  86. FOR %%T IN (csc.exe) DO (
  87. SET %%T_PATH=%%~dp$PATH:T
  88. )
  89. %_VECHO% Csc.exe_PATH = '%csc.exe_PATH%'
  90. IF DEFINED csc.exe_PATH (
  91. GOTO skip_addToPath
  92. )
  93. IF DEFINED FRAMEWORKDIR (
  94. REM Use the existing .NET Framework directory...
  95. ) ELSE IF EXIST "%windir%\Microsoft.NET\Framework64\v2.0.50727" (
  96. SET FRAMEWORKDIR=%windir%\Microsoft.NET\Framework64\v2.0.50727
  97. ) ELSE IF EXIST "%windir%\Microsoft.NET\Framework64\v3.5" (
  98. SET FRAMEWORKDIR=%windir%\Microsoft.NET\Framework64\v3.5
  99. ) ELSE IF EXIST "%windir%\Microsoft.NET\Framework64\v4.0.30319" (
  100. SET FRAMEWORKDIR=%windir%\Microsoft.NET\Framework64\v4.0.30319
  101. ) ELSE IF EXIST "%windir%\Microsoft.NET\Framework\v2.0.50727" (
  102. SET FRAMEWORKDIR=%windir%\Microsoft.NET\Framework\v2.0.50727
  103. ) ELSE IF EXIST "%windir%\Microsoft.NET\Framework\v3.5" (
  104. SET FRAMEWORKDIR=%windir%\Microsoft.NET\Framework\v3.5
  105. ) ELSE IF EXIST "%windir%\Microsoft.NET\Framework\v4.0.30319" (
  106. SET FRAMEWORKDIR=%windir%\Microsoft.NET\Framework\v4.0.30319
  107. ) ELSE (
  108. ECHO No suitable version of the .NET Framework appears to be installed.
  109. GOTO errors
  110. )
  111. %_VECHO% FrameworkDir = '%FRAMEWORKDIR%'
  112. IF NOT EXIST "%FRAMEWORKDIR%\csc.exe" (
  113. ECHO The file "%FRAMEWORKDIR%\csc.exe" is missing.
  114. GOTO errors
  115. )
  116. CALL :fn_PrependToPath FRAMEWORKDIR
  117. :skip_addToPath
  118. IF NOT EXIST "%TEMP%\GetFile.exe" (
  119. %__ECHO% csc.exe "/out:%TEMP%\GetFile.exe" /target:exe "%TOOLS%\GetFile.cs"
  120. IF ERRORLEVEL 1 (
  121. ECHO Compilation of "%TOOLS%\GetFile.cs" failed.
  122. GOTO errors
  123. )
  124. )
  125. FOR %%F IN (%TCLKIT_FILES%) DO (
  126. IF NOT EXIST "%TEMP%\%%F" (
  127. %__ECHO% "%TEMP%\GetFile.exe" "%TCLKIT_URI%%%F"
  128. IF ERRORLEVEL 1 (
  129. ECHO Download of "%%F" from "%TCLKIT_URI%" failed.
  130. GOTO errors
  131. )
  132. )
  133. )
  134. IF DEFINED TCLKIT_NOENV GOTO skip_sdkUnZip
  135. IF DEFINED TCLKIT_NOSDK GOTO skip_sdkUnZip
  136. IF NOT EXIST "%TEMP%\%TCLKIT_SDK%" (
  137. %__ECHO% MKDIR "%TEMP%\%TCLKIT_SDK%"
  138. IF ERRORLEVEL 1 (
  139. ECHO Could not create directory "%TEMP%\%TCLKIT_SDK%".
  140. GOTO errors
  141. )
  142. )
  143. %__ECHO% "%TEMP%\unzip.exe" -n "%TEMP%\%TCLKIT_SDK_ZIP%" -d "%TEMP%\%TCLKIT_SDK%"
  144. IF ERRORLEVEL 1 (
  145. ECHO Could not unzip "%TEMP%\%TCLKIT_SDK_ZIP%" to "%TEMP%\%TCLKIT_SDK%".
  146. GOTO errors
  147. )
  148. :skip_sdkUnZip
  149. IF DEFINED TCLKIT_NOENV GOTO skip_sdkEnvironment
  150. %__ECHO% ECHO SET TCLSH_CMD=%TEMP%\%TCLKIT_EXE%%OVERWRITE%"%ENVDIR%\SetTclKitEnv.bat"
  151. IF DEFINED TCLKIT_NOSDK GOTO skip_sdkVariables
  152. %__ECHO% ECHO SET TCLINCDIR=%TEMP%\%TCLKIT_SDK%\include%APPEND%"%ENVDIR%\SetTclKitEnv.bat"
  153. %__ECHO% ECHO SET TCLLIBDIR=%TEMP%\%TCLKIT_SDK%\lib%APPEND%"%ENVDIR%\SetTclKitEnv.bat"
  154. %__ECHO% ECHO SET LIBTCLPATH=%TEMP%\%TCLKIT_SDK%\lib%APPEND%"%ENVDIR%\SetTclKitEnv.bat"
  155. %__ECHO% ECHO SET LIBTCL=%TCLKIT_LIB%%APPEND%"%ENVDIR%\SetTclKitEnv.bat"
  156. %__ECHO% ECHO SET LIBTCLSTUB=%TCLKIT_LIB_STUB%%APPEND%"%ENVDIR%\SetTclKitEnv.bat"
  157. :skip_sdkVariables
  158. ECHO.
  159. ECHO Wrote "%ENVDIR%\SetTclKitEnv.bat".
  160. ECHO Please run it to set the necessary Tcl environment variables.
  161. ECHO.
  162. :skip_sdkEnvironment
  163. GOTO no_errors
  164. :fn_TclKitX86Variables
  165. REM
  166. REM NOTE: By default, use latest available version of the TclKit SDK
  167. REM for x86. However, the "default" TclKit executable for x86
  168. REM is still used here because it is the only one "well-known"
  169. REM to be available for download.
  170. REM
  171. IF NOT DEFINED TCLKIT_PATCHLEVEL (
  172. ECHO The TCLKIT_PATCHLEVEL environment variable must be set first.
  173. CALL :fn_SetErrorLevel
  174. GOTO :EOF
  175. )
  176. SET TCLKIT_VERSION=%TCLKIT_PATCHLEVEL:.=%
  177. SET TCLKIT_VERSION=%TCLKIT_VERSION:~0,2%
  178. IF DEFINED TCLKIT_EXE_PATCHLEVEL (
  179. SET TCLKIT_EXE=tclkit-%TCLKIT_EXE_PATCHLEVEL%.exe
  180. ) ELSE (
  181. SET TCLKIT_EXE=tclkit-%TCLKIT_PATCHLEVEL%.exe
  182. )
  183. SET TCLKIT_LIB=libtclkit%TCLKIT_PATCHLEVEL:.=%.lib
  184. SET TCLKIT_LIB_STUB=libtclstub%TCLKIT_VERSION:.=%.a
  185. SET TCLKIT_SDK=libtclkit-sdk-x86-%TCLKIT_PATCHLEVEL%
  186. SET TCLKIT_SDK_ZIP=%TCLKIT_SDK%.zip
  187. SET TCLKIT_FILES=%TCLKIT_EXE%
  188. IF NOT DEFINED TCLKIT_NOENV IF NOT DEFINED TCLKIT_NOSDK (
  189. SET TCLKIT_FILES=%TCLKIT_FILES% unzip.exe %TCLKIT_SDK_ZIP%
  190. )
  191. GOTO :EOF
  192. :fn_TclKitX64Variables
  193. REM
  194. REM NOTE: By default, use latest available version of the TclKit SDK
  195. REM for x64. However, the "default" TclKit executable for x86
  196. REM is still used here because it is the only one "well-known"
  197. REM to be available for download.
  198. REM
  199. IF NOT DEFINED TCLKIT_PATCHLEVEL (
  200. ECHO The TCLKIT_PATCHLEVEL environment variable must be set first.
  201. CALL :fn_SetErrorLevel
  202. GOTO :EOF
  203. )
  204. SET TCLKIT_VERSION=%TCLKIT_PATCHLEVEL:.=%
  205. SET TCLKIT_VERSION=%TCLKIT_VERSION:~0,2%
  206. IF DEFINED TCLKIT_EXE_PATCHLEVEL (
  207. SET TCLKIT_EXE=tclkit-%TCLKIT_EXE_PATCHLEVEL%.exe
  208. ) ELSE (
  209. SET TCLKIT_EXE=tclkit-%TCLKIT_PATCHLEVEL%.exe
  210. )
  211. SET TCLKIT_LIB=libtclkit%TCLKIT_PATCHLEVEL:.=%.lib
  212. SET TCLKIT_LIB_STUB=libtclstub%TCLKIT_VERSION:.=%.a
  213. SET TCLKIT_SDK=libtclkit-sdk-x64-%TCLKIT_PATCHLEVEL%
  214. SET TCLKIT_SDK_ZIP=%TCLKIT_SDK%.zip
  215. SET TCLKIT_FILES=%TCLKIT_EXE%
  216. IF NOT DEFINED TCLKIT_NOENV IF NOT DEFINED TCLKIT_NOSDK (
  217. SET TCLKIT_FILES=%TCLKIT_FILES% unzip.exe %TCLKIT_SDK_ZIP%
  218. )
  219. GOTO :EOF
  220. :fn_UnquoteVariable
  221. IF NOT DEFINED %1 GOTO :EOF
  222. SETLOCAL
  223. SET __ECHO_CMD=ECHO %%%1%%
  224. FOR /F "delims=" %%V IN ('%__ECHO_CMD%') DO (
  225. SET VALUE=%%V
  226. )
  227. SET VALUE=%VALUE:"=%
  228. REM "
  229. ENDLOCAL && SET %1=%VALUE%
  230. GOTO :EOF
  231. :fn_PrependToPath
  232. IF NOT DEFINED %1 GOTO :EOF
  233. SETLOCAL
  234. SET __ECHO_CMD=ECHO %%%1%%
  235. FOR /F "delims=" %%V IN ('%__ECHO_CMD%') DO (
  236. SET VALUE=%%V
  237. )
  238. SET VALUE=%VALUE:"=%
  239. REM "
  240. ENDLOCAL && SET PATH=%VALUE%;%PATH%
  241. GOTO :EOF
  242. :fn_ResetErrorLevel
  243. VERIFY > NUL
  244. GOTO :EOF
  245. :fn_SetErrorLevel
  246. VERIFY MAYBE 2> NUL
  247. GOTO :EOF
  248. :usage
  249. ECHO.
  250. ECHO Usage: %~nx0 ^<processor^>
  251. ECHO.
  252. ECHO The only supported values for processor are "x86" and "x64".
  253. GOTO errors
  254. :errors
  255. CALL :fn_SetErrorLevel
  256. ENDLOCAL
  257. ECHO.
  258. ECHO Failure, errors were encountered.
  259. GOTO end_of_file
  260. :no_errors
  261. CALL :fn_ResetErrorLevel
  262. ENDLOCAL
  263. ECHO.
  264. ECHO Success, no errors were encountered.
  265. GOTO end_of_file
  266. :end_of_file
  267. %__ECHO% EXIT /B %ERRORLEVEL%