2
0

setup_win.bat 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. @echo off
  2. REM Expect the script at /path/to/wolfssl/IDE/Espressif/ESP-IDF/
  3. ::******************************************************************************************************
  4. ::******************************************************************************************************
  5. echo;
  6. echo wolfSSL Windows Setup. Version 1.0a
  7. echo;
  8. echo This utility will copy a static snapshot of wolfSSL files to the ESP32-IDF component directory.
  9. echo;
  10. echo If you wish to keep your component library fresh with git pull, consider hard link with mklink.
  11. echo;
  12. echo "mklink [[/d] | [/h] | [/j]] <link> <target>"
  13. echo;
  14. ::******************************************************************************************************
  15. ::******************************************************************************************************
  16. SET COPYERROR=false
  17. :: if there's a setup.sh, we are probably starting in the right place.
  18. if NOT EXIST "setup.sh" (
  19. echo Please run this script at /path/to/wolfssl/IDE/Espressif/ESP-IDF/
  20. goto :ERR
  21. )
  22. :: if there's also a default user_settings.h, we are very likely starting in the right place.
  23. if NOT EXIST "user_settings.h" (
  24. echo Please run this script at /path/to/wolfssl/IDE/Espressif/ESP-IDF/
  25. goto :ERR
  26. )
  27. :: see if there was a parameter passed for a specific EDP-IDF directory
  28. :: this may be different than the standard ESP-IDF environment (e.g. VisualGDB)
  29. if not "%1" == "" (
  30. if not exist "%1" (
  31. echo "ERROR: optional directory was specified, but not found: %1"
  32. goto :ERR
  33. )
  34. SET IDF_PATH=%1
  35. echo Using specified IDF_PATH: %IDF_PATH%
  36. )
  37. :: if no IDF_PATH is found, we don't know what to do. Go exit with error.
  38. if "%IDF_PATH%" == "" (
  39. echo Please launch the script from ESP-IDF command prompt,
  40. echo or set your desired IDF_PATH environment variable,
  41. echo or pass a parameter to your directory, such as for VisualGDB with ESP-IDF 4.4:
  42. echo;
  43. echo .\setup_win.bat C:\SysGCC\esp32\esp-idf\v4.4
  44. echo;
  45. goto :ERR
  46. )
  47. :: Here we go!
  48. :: setup some path variables
  49. echo;
  50. set SCRIPTDIR=%CD%
  51. set BASEDIR=%SCRIPTDIR%\..\..\..
  52. set WOLFSSL_ESPIDFDIR=%BASEDIR%\IDE\Espressif\ESP-IDF
  53. set WOLFSSLLIB_TRG_DIR=%IDF_PATH%\components\wolfssl
  54. set WOLFSSLEXP_TRG_DIR=%IDF_PATH%\examples\protocols
  55. echo Using SCRIPTDIR = %SCRIPTDIR%
  56. echo Using BASEDIR = %BASEDIR%
  57. echo Using WOLFSSL_ESPIDFDIR = %WOLFSSL_ESPIDFDIR%
  58. echo Using WOLFSSLLIB_TRG_DIR = %WOLFSSLLIB_TRG_DIR%
  59. echo Using WOLFSSLEXP_TRG_DIR = %WOLFSSLEXP_TRG_DIR%
  60. echo;
  61. echo Equivalalent destination path:
  62. dir %WOLFSSL_ESPIDFDIR%\*.xyzzy 2> nul | findstr \
  63. echo;
  64. echo Equivalalent source directory paths:
  65. :: show the path of the equivalent %VALUE% (search for files that don't exist, suppress error, and look for string with "\")
  66. dir %BASEDIR%\*.xyzzy 2> nul | findstr \
  67. dir %WOLFSSLLIB_TRG_DIR%\*.xyzzy 2> nul | findstr \
  68. dir %WOLFSSLEXP_TRG_DIR%\*.xyzzy 2> nul | findstr \
  69. :: set the FileStamp variable to the current date: YYMMYY_HHMMSS
  70. :: the simplest method, to use existing TIME ad DATE variables:
  71. :: date = Thu 09/17/2015
  72. :: time = 11:13:15.47
  73. :: 012345678901234567890
  74. ::
  75. :: There is no leading zero for single digit hours (e.g. 9:00am), so we need to manually include the zero
  76. :: here |
  77. if "%TIME:~0,1%" == " " set FileStamp=%DATE:~12,2%%DATE:~7,2%%DATE:~4,2%_0%TIME:~1,1%%TIME:~3,2%%TIME:~6,2%
  78. :: otherwise, if a space not found before the digit, it is a 2 digit hour, so no extract zero is needed
  79. if NOT "%TIME:~0,1%" == " " set FileStamp=%DATE:~12,2%%DATE:~7,2%%DATE:~4,2%_%TIME:~0,2%%TIME:~3,2%%TIME:~6,2%
  80. :: Backup existing user settings
  81. if exist %WOLFSSLLIB_TRG_DIR%\include\config.h (
  82. echo;
  83. echo Saving: %WOLFSSLLIB_TRG_DIR%\include\config.h
  84. echo to: %SCRIPTDIR%\config_h_%FileStamp%.bak
  85. copy %WOLFSSLLIB_TRG_DIR%\include\config.h %SCRIPTDIR%\config_h_%FileStamp%.bak
  86. echo;
  87. )
  88. if exist %WOLFSSL_ESPIDFDIR%\user_settings.h (
  89. echo Saving: %WOLFSSLLIB_TRG_DIR%\include\user_settings.h
  90. echo to: %SCRIPTDIR%\user_settings_h_%FileStamp%.bak
  91. copy %WOLFSSLLIB_TRG_DIR%\include\user_settings.h %SCRIPTDIR%\user_settings_h_%FileStamp%.bak
  92. echo;
  93. )
  94. ::******************************************************************************************************
  95. :: check if there's already an existing %WOLFSSLLIB_TRG_DIR% and confirm removal
  96. ::******************************************************************************************************
  97. if exist %WOLFSSLLIB_TRG_DIR% (
  98. echo;
  99. echo WARNING: Existing files found in %WOLFSSLLIB_TRG_DIR%
  100. echo;
  101. :: clear any prior errorlevel
  102. call;
  103. choice /c YN /m "Delete files and proceed with install in %WOLFSSLLIB_TRG_DIR% "
  104. if errorlevel 2 GOTO :NODELETE
  105. GOTO :PURGE
  106. echo;
  107. echo Ready to copy files into %IDF_PATH%
  108. ::******************************************************************************************************
  109. :NODELETE
  110. ::******************************************************************************************************
  111. :: clear any prior errorlevel
  112. echo;
  113. call;
  114. choice /c YN /m "Refresh files %WOLFSSLLIB_TRG_DIR% (there will be a prompt to keep or overwrite user_settings and config) "
  115. if errorlevel 2 GOTO :NOCOPY
  116. GOTO :REFRESH
  117. )
  118. ::******************************************************************************************************
  119. :PURGE
  120. ::******************************************************************************************************
  121. :: purge existing directory
  122. if exist %WOLFSSLLIB_TRG_DIR% (
  123. echo;
  124. echo Removing %WOLFSSLLIB_TRG_DIR%
  125. rmdir %WOLFSSLLIB_TRG_DIR% /S /Q
  126. if exist %WOLFSSLLIB_TRG_DIR% (
  127. SET COPYERROR=true
  128. echo;
  129. echo WARNING: Failed to remove %WOLFSSLLIB_TRG_DIR%
  130. echo;
  131. echo Check permissions, open files, read-only attributes, etc.
  132. echo;
  133. )
  134. echo;
  135. ) else (
  136. echo;
  137. echo Prior %WOLFSSLLIB_TRG_DIR% not found, installing fresh.
  138. echo;
  139. )
  140. ::******************************************************************************************************
  141. :REFRESH
  142. ::******************************************************************************************************
  143. if not exist %WOLFSSLLIB_TRG_DIR% mkdir %WOLFSSLLIB_TRG_DIR%
  144. if not exist %WOLFSSLLIB_TRG_DIR%\src mkdir %WOLFSSLLIB_TRG_DIR%\src
  145. if not exist %WOLFSSLLIB_TRG_DIR%\wolfcrypt\src mkdir %WOLFSSLLIB_TRG_DIR%\wolfcrypt\src
  146. if not exist %WOLFSSLLIB_TRG_DIR%\wolfssl mkdir %WOLFSSLLIB_TRG_DIR%\wolfssl
  147. if not exist %WOLFSSLLIB_TRG_DIR%\wolfssl\openssl mkdir %WOLFSSLLIB_TRG_DIR%\wolfssl\openssl
  148. if not exist %WOLFSSLLIB_TRG_DIR%\test mkdir %WOLFSSLLIB_TRG_DIR%\test
  149. if not exist %WOLFSSLLIB_TRG_DIR%\include mkdir %WOLFSSLLIB_TRG_DIR%\include
  150. rem copying ... files in src/ into $WOLFSSLLIB_TRG_DIR%/src
  151. echo;
  152. echo Copying files to %WOLFSSLLIB_TRG_DIR%\src\
  153. xcopy %BASEDIR%\src\*.c %WOLFSSLLIB_TRG_DIR%\src\ /S /E /Q /Y
  154. if %errorlevel% NEQ 0 SET COPYERROR=true
  155. echo;
  156. echo Copying src\*.c files to %WOLFSSLLIB_TRG_DIR%\wolfcrypt\src
  157. xcopy %BASEDIR%\wolfcrypt\src\*.c %WOLFSSLLIB_TRG_DIR%\wolfcrypt\src /S /E /Q /Y
  158. if %errorlevel% NEQ 0 SET COPYERROR=true
  159. echo;
  160. echo Copying src\*.i files to %WOLFSSLLIB_TRG_DIR%\wolfcrypt\src
  161. xcopy %BASEDIR%\wolfcrypt\src\*.i %WOLFSSLLIB_TRG_DIR%\wolfcrypt\src /S /E /Q /Y
  162. if %errorlevel% NEQ 0 SET COPYERROR=true
  163. echo;
  164. echo Copying files to %WOLFSSLLIB_TRG_DIR%\wolfcrypt\src\port\
  165. xcopy %BASEDIR%\wolfcrypt\src\port %WOLFSSLLIB_TRG_DIR%\wolfcrypt\src\port\ /S /E /Q /Y
  166. if %errorlevel% NEQ 0 SET COPYERROR=true
  167. echo;
  168. echo Copying files to %WOLFSSLLIB_TRG_DIR%\wolfcrypt\test\
  169. xcopy %BASEDIR%\wolfcrypt\test %WOLFSSLLIB_TRG_DIR%\wolfcrypt\test\ /S /E /Q /Y
  170. if %errorlevel% NEQ 0 SET COPYERROR=true
  171. :: Copy dummy test_paths.h to handle the case configure hasn't yet executed
  172. echo;
  173. echo Copying dummy_test_paths.h to %WOLFSSLLIB_TRG_DIR%\wolfcrypt\test\test_paths.h
  174. echo new config > %WOLFSSLLIB_TRG_DIR%\wolfcrypt\test\test_paths.h
  175. if %errorlevel% NEQ 0 SET COPYERROR=true
  176. xcopy %WOLFSSL_ESPIDFDIR%\dummy_test_paths.h %WOLFSSLLIB_TRG_DIR%\wolfcrypt\test\test_paths.h /S /E /Y
  177. if %errorlevel% NEQ 0 SET COPYERROR=true
  178. echo;
  179. echo Copying files to %WOLFSSLLIB_TRG_DIR%\wolfcrypt\benchmark\
  180. xcopy %BASEDIR%\wolfcrypt\benchmark %WOLFSSLLIB_TRG_DIR%\wolfcrypt\benchmark\ /S /E /Q /Y
  181. if %errorlevel% NEQ 0 SET COPYERROR=true
  182. echo;
  183. echo Copying files to %WOLFSSLLIB_TRG_DIR%\wolfssl\
  184. xcopy %BASEDIR%\wolfssl\*.h %WOLFSSLLIB_TRG_DIR%\wolfssl\ /S /E /Q /Y
  185. if %errorlevel% NEQ 0 SET COPYERROR=true
  186. echo;
  187. echo Copying files to%WOLFSSLLIB_TRG_DIR%\wolfssl\openssl\
  188. xcopy %BASEDIR%\wolfssl\openssl\*.h %WOLFSSLLIB_TRG_DIR%\wolfssl\openssl\ /S /E /Q /Y
  189. if %errorlevel% NEQ 0 SET COPYERROR=true
  190. echo;
  191. echo Copying files to %WOLFSSLLIB_TRG_DIR%\wolfssl\wolfcrypt\
  192. xcopy %BASEDIR%\wolfssl\wolfcrypt %WOLFSSLLIB_TRG_DIR%\wolfssl\wolfcrypt\ /S /E /Q /Y
  193. if %errorlevel% NEQ 0 SET COPYERROR=true
  194. ::******************************************************************************************************
  195. :: user_settings and config defaults
  196. ::******************************************************************************************************
  197. :: user_settings.h (default, may be overwritten by prior file)
  198. echo;
  199. echo Copying default user_settings.h to %WOLFSSLLIB_TRG_DIR%\include\
  200. xcopy %WOLFSSL_ESPIDFDIR%\user_settings.h %WOLFSSLLIB_TRG_DIR%\include\ /F
  201. if %errorlevel% NEQ 0 SET COPYERROR=true
  202. :: echo Creating new config file: %WOLFSSLLIB_TRG_DIR%\include\config.h (default, may be overwritten by prior file)
  203. echo new config > %WOLFSSLLIB_TRG_DIR%\include\config.h
  204. xcopy %WOLFSSL_ESPIDFDIR%\dummy_config_h. %WOLFSSLLIB_TRG_DIR%\include\config.h /F /Y
  205. if %errorlevel% NEQ 0 SET COPYERROR=true
  206. :: Check if operator wants to keep prior config.h
  207. if EXIST config_h_%FileStamp%.bak (
  208. echo;
  209. :: clear any prior errorlevel
  210. call;
  211. choice /c YN /m "Use your prior config.h "
  212. if errorlevel 2 GOTO :NO_CONFIG_RESTORE
  213. xcopy config_h_%FileStamp%.bak %WOLFSSLLIB_TRG_DIR%\include\config.h /Y
  214. if %errorlevel% NEQ 0 SET COPYERROR=true
  215. ) else (
  216. echo;
  217. echo Prior config.h not found. Using default file.
  218. )
  219. ::******************************************************************************************************
  220. :NO_CONFIG_RESTORE
  221. ::******************************************************************************************************
  222. :: Check if operator wants to keep prior config.h
  223. if EXIST user_settings_h_%FileStamp%.bak (
  224. echo;
  225. :: clear any prior errorlevel
  226. call;
  227. choice /c YN /m "User your prior user_settings.h "
  228. if errorlevel 2 GOTO :NO_USER_SETTINGS_RESTORE
  229. xcopy user_settings_h_%FileStamp%.bak %WOLFSSLLIB_TRG_DIR%\include\user_settings.h /Y
  230. if %errorlevel% NEQ 0 SET COPYERROR=true
  231. ) else (
  232. echo;
  233. echo Prior user_settings.h not found. Using default file.
  234. )
  235. ::******************************************************************************************************
  236. :NO_USER_SETTINGS_RESTORE
  237. ::******************************************************************************************************
  238. :: unit test app
  239. echo;
  240. echo Copying unit files to %WOLFSSLLIB_TRG_DIR%\test\
  241. xcopy %WOLFSSL_ESPIDFDIR%\test %WOLFSSLLIB_TRG_DIR%\test\ /S /E /Q /Y
  242. if %errorlevel% NEQ 0 GOTO :COPYERR
  243. echo;
  244. echo Copying CMakeLists.txt to %WOLFSSLLIB_TRG_DIR%\
  245. xcopy %WOLFSSL_ESPIDFDIR%\libs\CMakeLists.txt %WOLFSSLLIB_TRG_DIR%\ /F
  246. if %errorlevel% NEQ 0 GOTO :COPYERR
  247. echo;
  248. echo Copying component.mk to %WOLFSSLLIB_TRG_DIR%\
  249. xcopy %WOLFSSL_ESPIDFDIR%\libs\component.mk %WOLFSSLLIB_TRG_DIR%\ /F
  250. if %errorlevel% NEQ 0 GOTO :COPYERR
  251. :: Benchmark program
  252. echo;
  253. echo Removing %WOLFSSLEXP_TRG_DIR%\wolfssl_benchmark\
  254. rmdir %WOLFSSLEXP_TRG_DIR%\wolfssl_benchmark\ /S /Q
  255. if %errorlevel% NEQ 0 GOTO :COPYERR
  256. echo;
  257. echo Copying %WOLFSSLEXP_TRG_DIR%\wolfssl_benchmark\main\
  258. mkdir %WOLFSSLEXP_TRG_DIR%\wolfssl_benchmark\main\
  259. xcopy %BASEDIR%\wolfcrypt\benchmark\benchmark.c %WOLFSSLEXP_TRG_DIR%\wolfssl_benchmark\main\ /F /Y
  260. if %errorlevel% NEQ 0 GOTO :COPYERR
  261. xcopy %WOLFSSL_ESPIDFDIR%\examples\wolfssl_benchmark %WOLFSSLEXP_TRG_DIR%\wolfssl_benchmark\ /Q /Y
  262. if %errorlevel% NEQ 0 GOTO :COPYERR
  263. :: Crypt Test program
  264. echo;
  265. echo Copying %WOLFSSLEXP_TRG_DIR%\wolfssl_test\
  266. rmdir %WOLFSSLEXP_TRG_DIR%\wolfssl_test\ /S /Q
  267. mkdir %WOLFSSLEXP_TRG_DIR%\wolfssl_test\main\
  268. xcopy %BASEDIR%\wolfcrypt\test\test.c %WOLFSSLEXP_TRG_DIR%\wolfssl_test\main\ /S /E /Q /Y
  269. if %errorlevel% NEQ 0 GOTO :COPYERR
  270. xcopy %WOLFSSL_ESPIDFDIR%\examples\wolfssl_test %WOLFSSLEXP_TRG_DIR%\wolfssl_test\ /S /E /Q /Y
  271. if %errorlevel% NEQ 0 GOTO :COPYERR
  272. :: TLS Client program
  273. echo;
  274. echo Copying %WOLFSSLEXP_TRG_DIR%\wolfssl_client\
  275. rmdir %WOLFSSLEXP_TRG_DIR%\wolfssl_client\ /S /Q
  276. mkdir %WOLFSSLEXP_TRG_DIR%\wolfssl_client\main\
  277. xcopy %WOLFSSL_ESPIDFDIR%\examples\wolfssl_client %WOLFSSLEXP_TRG_DIR%\wolfssl_client\ /S /E /Q /Y
  278. if %errorlevel% NEQ 0 GOTO :COPYERR
  279. :: TLS Server program
  280. echo;
  281. echo Copying %WOLFSSLEXP_TRG_DIR%\wolfssl_server\
  282. rmdir %WOLFSSLEXP_TRG_DIR%\wolfssl_server\ /S /Q
  283. mkdir %WOLFSSLEXP_TRG_DIR%\wolfssl_server\main\
  284. xcopy %WOLFSSL_ESPIDFDIR%\examples\wolfssl_server %WOLFSSLEXP_TRG_DIR%\wolfssl_server\ /S /E /Q /Y
  285. if %errorlevel% NEQ 0 GOTO :COPYERR
  286. goto :DONE
  287. :: error during copy encountered
  288. ::******************************************************************************************************
  289. :COPYERR
  290. ::******************************************************************************************************
  291. echo;
  292. echo Error during copy.
  293. echo
  294. echo Please ensure none of the target files are flagged as read-only, open, etc.
  295. goto :ERR
  296. :: abort at user request
  297. ::******************************************************************************************************
  298. :NOCOPY
  299. ::******************************************************************************************************
  300. echo;
  301. echo Setup did not copy any files.
  302. goto :ERR
  303. :: ERROR
  304. ::******************************************************************************************************
  305. :ERR
  306. ::******************************************************************************************************
  307. exit /B 1
  308. :: Success
  309. ::******************************************************************************************************
  310. :DONE
  311. ::******************************************************************************************************
  312. echo;
  313. echo;
  314. echo Edit config file in "%WOLFSSLLIB_TRG_DIR%\include\user_settings.h" before trying to compile.
  315. echo;
  316. echo See Component files for wolfSSL in %WOLFSSLLIB_TRG_DIR%
  317. echo;
  318. echo See additional examples at https://github.com/wolfSSL/wolfssl-examples
  319. echo;
  320. echo REMINDER: Ensure any wolfSSL #include definitions occur BEFORE include files in your source code.
  321. echo;
  322. if "%COPYERROR%" == "true" (
  323. echo;
  324. echo WARNING: Copy completed with errors! Check for files in use, permissions, symbolic links, etc.
  325. echo;
  326. )
  327. echo setup_win.bat for ESP-IDF completed.