toolsetup.bat 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. @REM @file
  2. @REM This stand-alone program is typically called by the edksetup.bat file,
  3. @REM however it may be executed directly from the BaseTools project folder
  4. @REM if the file is not executed within a WORKSPACE\BaseTools folder.
  5. @REM
  6. @REM Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
  7. @REM (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
  8. @REM
  9. @REM SPDX-License-Identifier: BSD-2-Clause-Patent
  10. @REM
  11. @echo off
  12. pushd .
  13. set SCRIPT_ERROR=0
  14. @REM ##############################################################
  15. @REM # You should not have to modify anything below this line
  16. @REM #
  17. if /I "%1"=="-h" goto Usage
  18. if /I "%1"=="-help" goto Usage
  19. if /I "%1"=="--help" goto Usage
  20. if /I "%1"=="/h" goto Usage
  21. if /I "%1"=="/help" goto Usage
  22. if /I "%1"=="/?" goto Usage
  23. :loop
  24. if "%1"=="" goto setup_workspace
  25. if /I "%1"=="Reconfig" (
  26. shift
  27. set RECONFIG=TRUE
  28. goto loop
  29. )
  30. if /I "%1"=="Rebuild" (
  31. shift
  32. set REBUILD=TRUE
  33. goto loop
  34. )
  35. if /I "%1"=="ForceRebuild" (
  36. shift
  37. set FORCE_REBUILD=TRUE
  38. goto loop
  39. )
  40. if /I "%1"=="VS2019" (
  41. shift
  42. set VS2019=TRUE
  43. set VSTool=VS2019
  44. goto loop
  45. )
  46. if /I "%1"=="VS2017" (
  47. shift
  48. set VS2017=TRUE
  49. set VSTool=VS2017
  50. goto loop
  51. )
  52. if /I "%1"=="VS2015" (
  53. shift
  54. set VS2015=TRUE
  55. set VSTool=VS2015
  56. goto loop
  57. )
  58. if /I "%1"=="VS2013" (
  59. shift
  60. set VS2013=TRUE
  61. set VSTool=VS2013
  62. goto loop
  63. )
  64. if /I "%1"=="VS2012" (
  65. shift
  66. set VS2012=TRUE
  67. set VSTool=VS2012
  68. goto loop
  69. )
  70. if "%1"=="" goto setup_workspace
  71. if exist %1 (
  72. if not defined BASE_TOOLS_PATH (
  73. if exist %1\Source set BASE_TOOLS_PATH=%1
  74. shift
  75. goto loop
  76. )
  77. if not defined EDK_TOOLS_PATH (
  78. if exist %1\Bin\Win32 set EDK_TOOLS_PATH=%1
  79. shift
  80. goto loop
  81. )
  82. echo.
  83. echo !!! ERROR !!! Unknown argument, %1 !!!
  84. echo.
  85. goto end
  86. ) else (
  87. echo.
  88. echo !!! ERROR !!! Unknown argument, %1 !!!
  89. echo.
  90. goto end
  91. )
  92. goto loop
  93. @REM
  94. @REM Check the required system environment variables
  95. @REM
  96. :setup_workspace
  97. REM
  98. REM check the EDK_TOOLS_PATH
  99. REM
  100. if not defined EDK_TOOLS_PATH goto no_EDK_TOOLS_PATH
  101. if exist %EDK_TOOLS_PATH% goto set_PATH
  102. :no_EDK_TOOLS_PATH
  103. if not defined WORKSPACE (
  104. if defined BASE_TOOLS_PATH (
  105. set EDK_TOOLS_PATH=%BASE_TOOLS_PATH%
  106. goto set_PATH
  107. ) else (
  108. echo.
  109. echo !!! ERROR !!! Neither BASE_TOOLS_PATH nor EDK_TOOLS_PATH are set. !!!
  110. echo.
  111. goto end
  112. )
  113. ) else (
  114. if exist %WORKSPACE%\BaseTools\Bin (
  115. set EDK_TOOLS_PATH=%WORKSPACE%\BaseTools
  116. goto set_PATH
  117. ) else (
  118. echo.
  119. echo !!! ERROR !!! No tools path available. Please set EDK_TOOLS_PATH !!!
  120. echo.
  121. goto end
  122. )
  123. )
  124. :set_PATH
  125. if defined WORKSPACE_TOOLS_PATH goto check_PATH
  126. if not defined EDK_TOOLS_BIN (
  127. set EDK_TOOLS_BIN=%EDK_TOOLS_PATH%\Bin\Win32
  128. if not exist %EDK_TOOLS_PATH%\Bin\Win32 (
  129. echo.
  130. echo !!! ERROR !!! Cannot find BaseTools Bin Win32!!!
  131. echo Please check the directory %EDK_TOOLS_PATH%\Bin\Win32
  132. echo Or configure EDK_TOOLS_BIN env to point Win32 directory.
  133. echo.
  134. )
  135. )
  136. set PATH=%EDK_TOOLS_BIN%;%PATH%
  137. set WORKSPACE_TOOLS_PATH=%EDK_TOOLS_PATH%
  138. goto PATH_ok
  139. :check_PATH
  140. if "%EDK_TOOLS_PATH%"=="%WORKSPACE_TOOLS_PATH%" goto PATH_ok
  141. if not defined EDK_TOOLS_BIN (
  142. set EDK_TOOLS_BIN=%EDK_TOOLS_PATH%\Bin\Win32
  143. if not exist %EDK_TOOLS_PATH%\Bin\Win32 (
  144. echo.
  145. echo !!! ERROR !!! Cannot find BaseTools Bin Win32!!!
  146. echo Please check the directory %EDK_TOOLS_PATH%\Bin\Win32
  147. echo Or configure EDK_TOOLS_BIN env to point Win32 directory.
  148. echo.
  149. )
  150. )
  151. set PATH=%EDK_TOOLS_BIN%;%PATH%
  152. set WORKSPACE_TOOLS_PATH=%EDK_TOOLS_PATH%
  153. echo Resetting the PATH variable to include the EDK_TOOLS_PATH for this session.
  154. :PATH_ok
  155. REM
  156. REM copy *.template to %CONF_PATH%
  157. REM
  158. if not defined WORKSPACE (
  159. if defined RECONFIG (
  160. echo.
  161. echo !!! WARNING !!! WORKSPACE environment variable was not set, cannot Reconfig !!!
  162. echo.
  163. )
  164. goto skip_reconfig
  165. )
  166. IF NOT exist "%EDK_TOOLS_PATH%\set_vsprefix_envs.bat" (
  167. @echo.
  168. @echo !!! ERROR !!! The set_vsprefix_envs.bat was not found !!!
  169. @echo.
  170. goto end
  171. )
  172. if defined VS2019 (
  173. call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2019
  174. ) else if defined VS2017 (
  175. call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2017
  176. ) else if defined VS2015 (
  177. call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2015
  178. call %EDK_TOOLS_PATH%\get_vsvars.bat VS2015
  179. ) else if defined VS2013 (
  180. call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2013
  181. call %EDK_TOOLS_PATH%\get_vsvars.bat VS2013
  182. ) else if defined VS2012 (
  183. call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2012
  184. call %EDK_TOOLS_PATH%\get_vsvars.bat VS2012
  185. ) else (
  186. call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat
  187. call %EDK_TOOLS_PATH%\get_vsvars.bat
  188. )
  189. if %SCRIPT_ERROR% NEQ 0 (
  190. @echo.
  191. @echo !!! ERROR !!! %VSTool% is not installed !!!
  192. @echo.
  193. goto end
  194. )
  195. if not defined CONF_PATH (
  196. set CONF_PATH=%WORKSPACE%\Conf
  197. )
  198. if NOT exist %CONF_PATH% (
  199. if defined PACKAGES_PATH (
  200. for %%i IN (%PACKAGES_PATH%) DO (
  201. if exist %%~fi\Conf (
  202. set CONF_PATH=%%i\Conf
  203. goto CopyConf
  204. )
  205. )
  206. )
  207. )
  208. :CopyConf
  209. if NOT exist %CONF_PATH% (
  210. mkdir %CONF_PATH%
  211. ) else (
  212. if defined RECONFIG (
  213. echo.
  214. echo Overwriting the files in the CONF_PATH directory
  215. echo using the default template files
  216. echo.
  217. )
  218. )
  219. if NOT exist %CONF_PATH%\target.txt (
  220. echo copying ... target.template to %CONF_PATH%\target.txt
  221. if NOT exist %EDK_TOOLS_PATH%\Conf\target.template (
  222. echo Error: target.template is missing at folder %EDK_TOOLS_PATH%\Conf\
  223. )
  224. copy %EDK_TOOLS_PATH%\Conf\target.template %CONF_PATH%\target.txt > nul
  225. ) else (
  226. if defined RECONFIG echo overwrite ... target.template to %CONF_PATH%\target.txt
  227. if defined RECONFIG copy /Y %EDK_TOOLS_PATH%\Conf\target.template %CONF_PATH%\target.txt > nul
  228. )
  229. if NOT exist %CONF_PATH%\tools_def.txt (
  230. echo copying ... tools_def.template to %CONF_PATH%\tools_def.txt
  231. if NOT exist %EDK_TOOLS_PATH%\Conf\tools_def.template (
  232. echo Error: tools_def.template is missing at folder %EDK_TOOLS_PATH%\Conf\
  233. )
  234. copy %EDK_TOOLS_PATH%\Conf\tools_def.template %CONF_PATH%\tools_def.txt > nul
  235. ) else (
  236. if defined RECONFIG echo overwrite ... tools_def.template to %CONF_PATH%\tools_def.txt
  237. if defined RECONFIG copy /Y %EDK_TOOLS_PATH%\Conf\tools_def.template %CONF_PATH%\tools_def.txt > nul
  238. )
  239. if NOT exist %CONF_PATH%\build_rule.txt (
  240. echo copying ... build_rule.template to %CONF_PATH%\build_rule.txt
  241. if NOT exist %EDK_TOOLS_PATH%\Conf\build_rule.template (
  242. echo Error: build_rule.template is missing at folder %EDK_TOOLS_PATH%\Conf\
  243. )
  244. copy %EDK_TOOLS_PATH%\Conf\build_rule.template %CONF_PATH%\build_rule.txt > nul
  245. ) else (
  246. if defined RECONFIG echo over-write ... build_rule.template to %CONF_PATH%\build_rule.txt
  247. if defined RECONFIG copy /Y %EDK_TOOLS_PATH%\Conf\build_rule.template %CONF_PATH%\build_rule.txt > nul
  248. )
  249. echo PATH = %PATH%
  250. echo.
  251. if defined WORKSPACE (
  252. echo WORKSPACE = %WORKSPACE%
  253. )
  254. if defined PACKAGES_PATH (
  255. echo PACKAGES_PATH = %PACKAGES_PATH%
  256. )
  257. echo EDK_TOOLS_PATH = %EDK_TOOLS_PATH%
  258. if defined BASE_TOOLS_PATH (
  259. echo BASE_TOOLS_PATH = %BASE_TOOLS_PATH%
  260. )
  261. if defined EDK_TOOLS_BIN (
  262. echo EDK_TOOLS_BIN = %EDK_TOOLS_BIN%
  263. )
  264. echo CONF_PATH = %CONF_PATH%
  265. echo.
  266. :skip_reconfig
  267. @REM
  268. @REM Test if we are going to have to do a build
  269. @REM
  270. if defined FORCE_REBUILD goto check_build_environment
  271. if defined REBUILD goto check_build_environment
  272. if not exist "%EDK_TOOLS_PATH%" goto check_build_environment
  273. if not exist "%EDK_TOOLS_BIN%" goto check_build_environment
  274. IF NOT EXIST "%EDK_TOOLS_BIN%\EfiRom.exe" goto check_c_tools
  275. IF NOT EXIST "%EDK_TOOLS_BIN%\GenFfs.exe" goto check_c_tools
  276. IF NOT EXIST "%EDK_TOOLS_BIN%\GenFv.exe" goto check_c_tools
  277. IF NOT EXIST "%EDK_TOOLS_BIN%\GenFw.exe" goto check_c_tools
  278. IF NOT EXIST "%EDK_TOOLS_BIN%\GenSec.exe" goto check_c_tools
  279. IF NOT EXIST "%EDK_TOOLS_BIN%\TianoCompress.exe" goto check_c_tools
  280. IF NOT EXIST "%EDK_TOOLS_BIN%\VfrCompile.exe" goto check_c_tools
  281. IF NOT EXIST "%EDK_TOOLS_BIN%\VolInfo.exe" goto check_c_tools
  282. goto check_build_environment
  283. :check_c_tools
  284. echo.
  285. echo !!! ERROR !!! Binary C tools are missing. They are required to be built from BaseTools Source.
  286. echo.
  287. :check_build_environment
  288. set PYTHONHASHSEED=1
  289. if not defined BASE_TOOLS_PATH (
  290. if not exist "Source\C\Makefile" (
  291. if not exist "%EDK_TOOLS_PATH%\Source\C\Makefile" goto no_source_files
  292. set BASE_TOOLS_PATH=%EDK_TOOLS_PATH%
  293. ) else (
  294. set BASE_TOOLS_PATH=%CD%
  295. )
  296. )
  297. :defined_python
  298. if defined PYTHON_COMMAND if not defined PYTHON3_ENABLE (
  299. goto check_python_available
  300. )
  301. if defined PYTHON3_ENABLE (
  302. if "%PYTHON3_ENABLE%" EQU "TRUE" (
  303. set PYTHON_COMMAND=py -3
  304. goto check_python_available
  305. ) else (
  306. goto check_python2
  307. )
  308. )
  309. if not defined PYTHON_COMMAND if not defined PYTHON3_ENABLE (
  310. set PYTHON_COMMAND=py -3
  311. py -3 %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1
  312. setlocal enabledelayedexpansion
  313. set /p PythonCheck=<"PythonCheck.txt"
  314. del PythonCheck.txt
  315. if "!PythonCheck!" NEQ "TRUE" (
  316. if not defined PYTHON_HOME if not defined PYTHONHOME (
  317. endlocal
  318. set PYTHON_COMMAND=
  319. echo.
  320. echo !!! ERROR !!! Binary python tools are missing.
  321. echo PYTHON_COMMAND, PYTHON3_ENABLE or PYTHON_HOME
  322. echo Environment variable is not set successfully.
  323. echo They is required to build or execute the python tools.
  324. echo.
  325. goto end
  326. ) else (
  327. goto check_python2
  328. )
  329. ) else (
  330. goto check_freezer_path
  331. )
  332. )
  333. :check_python2
  334. endlocal
  335. if defined PYTHON_HOME (
  336. if EXIST "%PYTHON_HOME%" (
  337. set PYTHON_COMMAND=%PYTHON_HOME%\python.exe
  338. goto check_python_available
  339. )
  340. )
  341. if defined PYTHONHOME (
  342. if EXIST "%PYTHONHOME%" (
  343. set PYTHON_HOME=%PYTHONHOME%
  344. set PYTHON_COMMAND=%PYTHON_HOME%\python.exe
  345. goto check_python_available
  346. )
  347. )
  348. echo.
  349. echo !!! ERROR !!! PYTHON_HOME is not defined or The value of this variable does not exist
  350. echo.
  351. goto end
  352. :check_python_available
  353. %PYTHON_COMMAND% %BASE_TOOLS_PATH%\Tests\PythonTest.py >PythonCheck.txt 2>&1
  354. setlocal enabledelayedexpansion
  355. set /p PythonCheck=<"PythonCheck.txt"
  356. del PythonCheck.txt
  357. if "!PythonCheck!" NEQ "TRUE" (
  358. echo.
  359. echo ! ERROR ! "%PYTHON_COMMAND%" is not installed or added to environment variables
  360. echo.
  361. goto end
  362. ) else (
  363. goto check_freezer_path
  364. )
  365. :check_freezer_path
  366. endlocal
  367. %PYTHON_COMMAND% -c "import edk2basetools" >NUL 2>NUL
  368. if %ERRORLEVEL% EQU 0 (
  369. goto use_pip_basetools
  370. ) else (
  371. REM reset ERRORLEVEL
  372. type nul>nul
  373. goto use_builtin_basetools
  374. )
  375. :use_builtin_basetools
  376. @echo Using EDK2 in-source Basetools
  377. if defined BASETOOLS_PYTHON_SOURCE goto print_python_info
  378. set "PATH=%BASE_TOOLS_PATH%\BinWrappers\WindowsLike;%PATH%"
  379. set BASETOOLS_PYTHON_SOURCE=%BASE_TOOLS_PATH%\Source\Python
  380. set PYTHONPATH=%BASETOOLS_PYTHON_SOURCE%;%PYTHONPATH%
  381. goto print_python_info
  382. :use_pip_basetools
  383. @echo Using Pip Basetools
  384. set "PATH=%BASE_TOOLS_PATH%\BinPipWrappers\WindowsLike;%PATH%"
  385. set BASETOOLS_PYTHON_SOURCE=edk2basetools
  386. goto print_python_info
  387. :print_python_info
  388. echo PATH = %PATH%
  389. if defined PYTHON3_ENABLE if "%PYTHON3_ENABLE%" EQU "TRUE" (
  390. echo PYTHON3_ENABLE = %PYTHON3_ENABLE%
  391. echo PYTHON3 = %PYTHON_COMMAND%
  392. ) else (
  393. echo PYTHON3_ENABLE = FALSE
  394. echo PYTHON_COMMAND = %PYTHON_COMMAND%
  395. )
  396. echo PYTHONPATH = %PYTHONPATH%
  397. echo.
  398. :VisualStudioAvailable
  399. if not defined FORCE_REBUILD (
  400. if not defined REBUILD (
  401. goto end
  402. )
  403. )
  404. if not defined VCINSTALLDIR (
  405. @echo.
  406. @echo !!! ERROR !!!! Cannot find Visual Studio, required to build C tools !!!
  407. @echo.
  408. goto end
  409. )
  410. if not defined FORCE_REBUILD goto IncrementalBuild
  411. :CleanAndBuild
  412. pushd .
  413. cd %BASE_TOOLS_PATH%
  414. call nmake cleanall
  415. del /f /q %BASE_TOOLS_PATH%\Bin\Win32\*.*
  416. popd
  417. @REM Let CleanAndBuild fall through to IncrementalBuild
  418. :IncrementalBuild
  419. pushd .
  420. cd %BASE_TOOLS_PATH%
  421. call nmake c
  422. popd
  423. goto end
  424. :no_source_files
  425. echo.
  426. echo !!! ERROR !!! Cannot build BaseTools applications - no source directory located !!!
  427. echo.
  428. goto end
  429. :Usage
  430. @echo.
  431. echo Usage: "%0 [-h | -help | --help | /h | /help | /?] [ Rebuild | ForceRebuild ] [Reconfig] [base_tools_path [edk_tools_path]] [VS2019] [VS2017] [VS2015] [VS2013] [VS2012]"
  432. @echo.
  433. @echo base_tools_path BaseTools project path, BASE_TOOLS_PATH will be set to this path.
  434. @echo edk_tools_path EDK_TOOLS_PATH will be set to this path.
  435. @echo Rebuild If sources are available perform an Incremental build, only
  436. @echo build those updated tools.
  437. @echo ForceRebuild If sources are available, rebuild all tools regardless of
  438. @echo whether they have been updated or not.
  439. @echo Reconfig Reinstall target.txt, tools_def.txt and build_rule.txt.
  440. @echo VS2012 Set the env for VS2012 build.
  441. @echo VS2013 Set the env for VS2013 build.
  442. @echo VS2015 Set the env for VS2015 build.
  443. @echo VS2017 Set the env for VS2017 build.
  444. @echo VS2019 Set the env for VS2019 build.
  445. @echo.
  446. :end
  447. set REBUILD=
  448. set FORCE_REBUILD=
  449. set RECONFIG=
  450. set VS2019=
  451. set VS2017=
  452. set VS2015=
  453. set VS2013=
  454. set VS2012=
  455. set VSTool=
  456. popd