| 
									
										
										
										
											2008-02-22 16:31:23 +00:00
										 |  |  | @REM @file | 
					
						
							|  |  |  | @REM   Windows batch file to setup a WORKSPACE environment | 
					
						
							| 
									
										
										
										
											2006-04-21 22:54:32 +00:00
										 |  |  | @REM | 
					
						
							| 
									
										
											  
											
												BaseTools: Add support for mingw-w64
Adds support for building the C language BaseTools for Windows using
toolchains based on mingw-w64.
Mingw-w64 is a collection of header files, libraries, and tools that
when combined with a compiler enable development of Windows software.
Mingw-w64 is a fork of the original MinGW (Minimalist GNU for Windows).
Most active development on MinGW has ceased and mingw-w64 is now the
actively maintained successor.  Mingw-w64 provides a libc implementation
built on top of Microsoft's UCRT (Universal C Runtime) with all
nessesary compiler bindings needed to support the C++11 feature set.
Modern mingw-w64 development appears to have coalesced around MSYS2,
which produces a distributions of both GCC and LLVM/Clang that use
mingw-w64 to target the Windows OS. This MSYS2 Clang distribution has a
UNIX-like directory layout and includes Windows binaries of GNU Make.
Combined with the open source licensing, MSYS2's Clang distribution is a
highly attractive choice as an alternative Windows SDK for open source
projects such as TianoCore.
If one wishes to use EDK II to build UEFI firmware on the Windows
platform, then the C BaseTools need to be compiled as Windows
applications. This includes the PcdValueInit.exe program, which needs
to be recompiled every time a firmware build is run in order to
regenerate the initial values for structured PCDs. Currently, BaseTools
only supports the Visual C++ toolchain on the Windows platform. The
following new features have been added to enable usage of the toolchains
derived from mingw-w64:
 - Fixes to the BaseTools C source code to support the use of a
   GCC-style compiler on the Windows OS.
 - The GNU Make-style Makefiles for the C BaseTools have been modified
   to support Windows. Both GCC + mingw-w64 and Clang + mingw-w64 have
   been tested and confirmed to build a working BaseTools.
 - BaseTools now supports generating GNU Make-style Makefiles on the
   Windows platform for the purpose of building firmware.
 - edksetup.bat has been modified to optionally build BaseTools via
   mingw-w64. There is no impact to the existing support for Visual C++
   and Visual C++ remains the default toolchain.
Usage Instructions:
For the vast majority of users, the only system setup change nessesary
to use a mingw-w64 toolchain is to set the BASETOOLS_MINGW_PATH to the
directory containing the desired mingw-w64 based toolchain.
A new command line argument has been added to edksetup.bat: Mingw-w64
If this command line argument is set, then the script will set the
BASETOOLS_MINGW_BUILD environment variable. The user can also opt to set
this environment variable manually before running edksetup.bat
If BASETOOLS_MINGW_BUILD is defined, then the BASETOOLS_MINGW_PATH
environment variable must point to the directory containing the
mingw-w64 toolchain.
If CLANG_BIN is not defined and %BASETOOLS_MINGW_PATH%\bin\clang.exe
exists, then edksetup.bat will set CLANG_BIN=%BASETOOLS_MINGW_PATH%\bin\
This removes the requirement to configure the CLANG_BIN environment
variable manually in order to run a CLANGPDB or CLANGDWARF build if one
has the MSYS2 Clang distribution installed. If one wishes to use a
different copy of Clang (for example official LLVM binaries) to build
firmware and only use the MSYS2 Clang to build BaseTools, then one can
continue to set the CLANG_BIN environment variable, same as before. I
have tested the MSYS2 Clang distribution against the official LLVM
distribution and can confirm that if the compiler version is the same
the emitted machine code is identical between the two. Interestingly,
the MSYS2 Clang distribution emits the path to the PDB file using "/" as
the path seperator instead of "\". That appears to be the only
difference in output. Therefore, using the MSYS2 Clang distribution to
compile firmware seems a reasonable choice.
If CLANG_HOST_BIN is not defined and BASETOOLS_MINGW_BUILD is defined
and %BASETOOLS_MINGW_PATH%\bin\mingw32-make.exe exists, then
edksetup.bat will add %BASETOOLS_MINGW_PATH%\bin\ to the PATH and set
CLANG_HOST_BIN=mingw32-
This enable usage of the GNU Make included in the mingw-w64 toolchain
to build firmware in addition to BaseTools. if BASETOOLS_MINGW_BUILD is
not defined, edksetup.bat will continue to set CLANG_HOST_BIN=n, which
uses nmake to build firmware. This behavior can be overridden by
manually setting the value of CLANG_HOST_BIN before executing
edksetup.bat if one wishes to use a specific Make utility for the
CLANGPDB/CLANGDWARF toolchains.
References:
 - https://www.mingw-w64.org/
 - https://www.msys2.org/
Co-authored-by: Sandesh Jain <sandesh.jain@intel.com>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
											
										 
											2025-06-06 16:04:29 -07:00
										 |  |  | @REM Copyright (c) 2006 - 2025, Intel Corporation. All rights reserved.<BR> | 
					
						
							| 
									
										
										
										
											2016-10-19 12:31:36 +08:00
										 |  |  | @REM (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR> | 
					
						
							| 
									
										
										
										
											2019-04-03 16:02:46 -07:00
										 |  |  | @REM SPDX-License-Identifier: BSD-2-Clause-Patent | 
					
						
							| 
									
										
										
										
											2006-04-21 22:54:32 +00:00
										 |  |  | @REM | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-09 06:11:05 +00:00
										 |  |  | @REM set CYGWIN_HOME=C:\cygwin | 
					
						
							| 
									
										
										
										
											2006-04-21 22:54:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-22 14:59:49 -04:00
										 |  |  | @REM usage: | 
					
						
							| 
									
										
										
										
											2008-02-22 16:31:23 +00:00
										 |  |  | @REM   edksetup.bat [--nt32] [AntBuild] [Rebuild] [ForceRebuild] [Reconfig] | 
					
						
							| 
									
										
										
										
											2006-06-09 15:26:28 +00:00
										 |  |  | @REM if the argument, skip is present, only the paths and the | 
					
						
							| 
									
										
										
										
											2017-06-22 14:59:49 -04:00
										 |  |  | @REM test and set of environment settings are performed. | 
					
						
							| 
									
										
										
										
											2006-04-21 22:54:32 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | @REM ############################################################## | 
					
						
							|  |  |  | @REM # You should not have to modify anything below this line | 
					
						
							|  |  |  | @REM # | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @echo off | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-06-22 06:25:37 +00:00
										 |  |  | @REM | 
					
						
							|  |  |  | @REM Set the WORKSPACE to the current working directory | 
					
						
							|  |  |  | @REM | 
					
						
							| 
									
										
										
										
											2007-10-11 08:58:33 +00:00
										 |  |  | pushd . | 
					
						
							|  |  |  | cd %~dp0 | 
					
						
							| 
									
										
										
										
											2010-01-26 02:42:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-26 04:58:56 +00:00
										 |  |  | if not defined WORKSPACE ( | 
					
						
							| 
									
										
										
										
											2014-02-24 14:09:00 +00:00
										 |  |  |   goto SetWorkSpace | 
					
						
							| 
									
										
										
										
											2010-01-26 02:42:37 +00:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-26 04:58:56 +00:00
										 |  |  | if %WORKSPACE% == %CD% ( | 
					
						
							|  |  |  |   @REM Workspace is not changed. | 
					
						
							| 
									
										
										
										
											2014-02-24 14:09:00 +00:00
										 |  |  |   goto ParseArgs | 
					
						
							| 
									
										
										
										
											2010-01-26 04:58:56 +00:00
										 |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | :SetWorkSpace | 
					
						
							| 
									
										
										
										
											2010-01-26 02:42:37 +00:00
										 |  |  | @REM set new workspace | 
					
						
							| 
									
										
										
										
											2015-10-08 09:29:09 +00:00
										 |  |  | if not defined WORKSPACE ( | 
					
						
							|  |  |  |   set WORKSPACE=%CD% | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2007-06-22 06:25:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-26 02:42:37 +00:00
										 |  |  | :ParseArgs | 
					
						
							| 
									
										
										
										
											2014-02-24 14:09:00 +00:00
										 |  |  | if /I "%1"=="-h" goto Usage | 
					
						
							|  |  |  | if /I "%1"=="-help" goto Usage | 
					
						
							|  |  |  | if /I "%1"=="--help" goto Usage | 
					
						
							|  |  |  | if /I "%1"=="/h" goto Usage | 
					
						
							|  |  |  | if /I "%1"=="/?" goto Usage | 
					
						
							|  |  |  | if /I "%1"=="/help" goto Usage | 
					
						
							| 
									
										
										
										
											2008-02-22 16:31:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-24 14:09:00 +00:00
										 |  |  | if /I "%1"=="NewBuild" shift | 
					
						
							| 
									
										
										
										
											2016-04-08 13:32:07 +08:00
										 |  |  | if not defined EDK_TOOLS_PATH ( | 
					
						
							| 
									
										
										
										
											2018-08-07 09:35:33 +08:00
										 |  |  |   goto SetEdkToolsPath | 
					
						
							|  |  |  | ) else ( | 
					
						
							|  |  |  |   goto checkNt32Flag | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | :SetEdkToolsPath | 
					
						
							|  |  |  | if %WORKSPACE:~-1% EQU \ ( | 
					
						
							|  |  |  |   @set EDK_BASETOOLS=%WORKSPACE%BaseTools | 
					
						
							|  |  |  | ) else ( | 
					
						
							|  |  |  |   @set EDK_BASETOOLS=%WORKSPACE%\BaseTools | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | if exist %EDK_BASETOOLS% ( | 
					
						
							|  |  |  |   set EDK_TOOLS_PATH=%EDK_BASETOOLS% | 
					
						
							|  |  |  |   set EDK_BASETOOLS= | 
					
						
							|  |  |  | ) else ( | 
					
						
							|  |  |  |   if defined PACKAGES_PATH ( | 
					
						
							|  |  |  |     for %%i IN (%PACKAGES_PATH%) DO ( | 
					
						
							|  |  |  |       if exist %%~fi\BaseTools ( | 
					
						
							|  |  |  |         set EDK_TOOLS_PATH=%%~fi\BaseTools | 
					
						
							|  |  |  |         goto checkNt32Flag | 
					
						
							| 
									
										
										
										
											2015-10-08 09:29:09 +00:00
										 |  |  |       ) | 
					
						
							|  |  |  |     ) | 
					
						
							| 
									
										
										
										
											2018-08-07 09:35:33 +08:00
										 |  |  |   ) else ( | 
					
						
							|  |  |  |     echo. | 
					
						
							|  |  |  |     echo !!! ERROR !!! Cannot find BaseTools !!! | 
					
						
							|  |  |  |     echo. | 
					
						
							|  |  |  |     goto BadBaseTools | 
					
						
							| 
									
										
										
										
											2015-10-08 09:29:09 +00:00
										 |  |  |   ) | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 12:31:36 +08:00
										 |  |  | :checkNt32Flag | 
					
						
							| 
									
										
										
										
											2016-10-26 11:31:52 +08:00
										 |  |  | if exist %EDK_TOOLS_PATH%\Source set BASE_TOOLS_PATH=%EDK_TOOLS_PATH% | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-08 09:29:09 +00:00
										 |  |  | :checkBaseTools | 
					
						
							| 
									
										
										
										
											2014-02-24 14:09:00 +00:00
										 |  |  | IF NOT EXIST "%EDK_TOOLS_PATH%\toolsetup.bat" goto BadBaseTools | 
					
						
							|  |  |  | call %EDK_TOOLS_PATH%\toolsetup.bat %* | 
					
						
							| 
									
										
										
										
											2023-04-24 11:06:52 -06:00
										 |  |  | if %ERRORLEVEL% NEQ 0 goto end | 
					
						
							| 
									
										
										
										
											2014-02-24 14:09:00 +00:00
										 |  |  | if /I "%1"=="Reconfig" shift | 
					
						
							| 
									
										
										
										
											2016-07-15 17:41:17 +08:00
										 |  |  | goto check_NASM | 
					
						
							| 
									
										
										
										
											2014-02-24 14:09:00 +00:00
										 |  |  | goto check_cygwin | 
					
						
							| 
									
										
										
										
											2008-02-22 16:31:23 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | :BadBaseTools | 
					
						
							|  |  |  |   @REM | 
					
						
							| 
									
										
										
										
											2014-02-24 14:09:00 +00:00
										 |  |  |   REM Need the BaseTools Package in order to build | 
					
						
							| 
									
										
										
										
											2008-02-22 16:31:23 +00:00
										 |  |  |   @REM | 
					
						
							| 
									
										
										
										
											2014-02-24 14:09:00 +00:00
										 |  |  |   @echo. | 
					
						
							|  |  |  |   @echo !!! ERROR !!! The BaseTools Package was not found !!! | 
					
						
							|  |  |  |   @echo. | 
					
						
							|  |  |  |   @echo Set the system environment variable, EDK_TOOLS_PATH to the BaseTools, | 
					
						
							|  |  |  |   @echo For example, | 
					
						
							|  |  |  |   @echo   set EDK_TOOLS_PATH=C:\MyTools\BaseTools | 
					
						
							|  |  |  |   @echo The setup script, toolsetup.bat must reside in this folder. | 
					
						
							|  |  |  |   @echo. | 
					
						
							|  |  |  |   goto end | 
					
						
							| 
									
										
										
										
											2008-02-22 16:31:23 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-15 17:41:17 +08:00
										 |  |  | :check_NASM | 
					
						
							|  |  |  | if not defined NASM_PREFIX ( | 
					
						
							|  |  |  |     @echo. | 
					
						
							|  |  |  |     @echo !!! WARNING !!! NASM_PREFIX environment variable is not set | 
					
						
							|  |  |  |     @if exist "C:\nasm\nasm.exe" @set "NASM_PREFIX=C:\nasm\" | 
					
						
							|  |  |  |     @if exist "C:\nasm\nasm.exe" @echo   Found nasm.exe, setting the environment variable to C:\nasm\ | 
					
						
							|  |  |  |     @if not exist "C:\nasm\nasm.exe" echo   Attempting to build modules that require NASM will fail. | 
					
						
							|  |  |  | ) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-09 06:11:05 +00:00
										 |  |  | :check_cygwin | 
					
						
							| 
									
										
										
										
											2014-02-24 14:14:13 +00:00
										 |  |  | if defined CYGWIN_HOME ( | 
					
						
							|  |  |  |   if not exist "%CYGWIN_HOME%" ( | 
					
						
							|  |  |  |     @echo. | 
					
						
							|  |  |  |     @echo !!! WARNING !!! CYGWIN_HOME not found, gcc build may not be used !!! | 
					
						
							|  |  |  |     @echo. | 
					
						
							|  |  |  |   ) | 
					
						
							|  |  |  | ) else ( | 
					
						
							| 
									
										
										
										
											2014-02-24 14:09:00 +00:00
										 |  |  |   if exist c:\cygwin ( | 
					
						
							|  |  |  |     set CYGWIN_HOME=c:\cygwin | 
					
						
							| 
									
										
										
										
											2008-02-22 16:31:23 +00:00
										 |  |  |   ) else ( | 
					
						
							| 
									
										
										
										
											2008-12-31 16:57:24 +00:00
										 |  |  |     @echo. | 
					
						
							|  |  |  |     @echo !!! WARNING !!! No CYGWIN_HOME set, gcc build may not be used !!! | 
					
						
							|  |  |  |     @echo. | 
					
						
							| 
									
										
										
										
											2008-02-22 16:31:23 +00:00
										 |  |  |   ) | 
					
						
							| 
									
										
										
										
											2014-02-24 14:14:13 +00:00
										 |  |  | ) | 
					
						
							| 
									
										
										
										
											2006-04-21 22:54:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-24 14:14:13 +00:00
										 |  |  | :cygwin_done | 
					
						
							| 
									
										
										
										
											2017-06-22 14:59:49 -04:00
										 |  |  | if /I "%1"=="Rebuild" shift | 
					
						
							|  |  |  | if /I "%1"=="ForceRebuild" shift | 
					
						
							| 
									
										
											  
											
												BaseTools: Add support for mingw-w64
Adds support for building the C language BaseTools for Windows using
toolchains based on mingw-w64.
Mingw-w64 is a collection of header files, libraries, and tools that
when combined with a compiler enable development of Windows software.
Mingw-w64 is a fork of the original MinGW (Minimalist GNU for Windows).
Most active development on MinGW has ceased and mingw-w64 is now the
actively maintained successor.  Mingw-w64 provides a libc implementation
built on top of Microsoft's UCRT (Universal C Runtime) with all
nessesary compiler bindings needed to support the C++11 feature set.
Modern mingw-w64 development appears to have coalesced around MSYS2,
which produces a distributions of both GCC and LLVM/Clang that use
mingw-w64 to target the Windows OS. This MSYS2 Clang distribution has a
UNIX-like directory layout and includes Windows binaries of GNU Make.
Combined with the open source licensing, MSYS2's Clang distribution is a
highly attractive choice as an alternative Windows SDK for open source
projects such as TianoCore.
If one wishes to use EDK II to build UEFI firmware on the Windows
platform, then the C BaseTools need to be compiled as Windows
applications. This includes the PcdValueInit.exe program, which needs
to be recompiled every time a firmware build is run in order to
regenerate the initial values for structured PCDs. Currently, BaseTools
only supports the Visual C++ toolchain on the Windows platform. The
following new features have been added to enable usage of the toolchains
derived from mingw-w64:
 - Fixes to the BaseTools C source code to support the use of a
   GCC-style compiler on the Windows OS.
 - The GNU Make-style Makefiles for the C BaseTools have been modified
   to support Windows. Both GCC + mingw-w64 and Clang + mingw-w64 have
   been tested and confirmed to build a working BaseTools.
 - BaseTools now supports generating GNU Make-style Makefiles on the
   Windows platform for the purpose of building firmware.
 - edksetup.bat has been modified to optionally build BaseTools via
   mingw-w64. There is no impact to the existing support for Visual C++
   and Visual C++ remains the default toolchain.
Usage Instructions:
For the vast majority of users, the only system setup change nessesary
to use a mingw-w64 toolchain is to set the BASETOOLS_MINGW_PATH to the
directory containing the desired mingw-w64 based toolchain.
A new command line argument has been added to edksetup.bat: Mingw-w64
If this command line argument is set, then the script will set the
BASETOOLS_MINGW_BUILD environment variable. The user can also opt to set
this environment variable manually before running edksetup.bat
If BASETOOLS_MINGW_BUILD is defined, then the BASETOOLS_MINGW_PATH
environment variable must point to the directory containing the
mingw-w64 toolchain.
If CLANG_BIN is not defined and %BASETOOLS_MINGW_PATH%\bin\clang.exe
exists, then edksetup.bat will set CLANG_BIN=%BASETOOLS_MINGW_PATH%\bin\
This removes the requirement to configure the CLANG_BIN environment
variable manually in order to run a CLANGPDB or CLANGDWARF build if one
has the MSYS2 Clang distribution installed. If one wishes to use a
different copy of Clang (for example official LLVM binaries) to build
firmware and only use the MSYS2 Clang to build BaseTools, then one can
continue to set the CLANG_BIN environment variable, same as before. I
have tested the MSYS2 Clang distribution against the official LLVM
distribution and can confirm that if the compiler version is the same
the emitted machine code is identical between the two. Interestingly,
the MSYS2 Clang distribution emits the path to the PDB file using "/" as
the path seperator instead of "\". That appears to be the only
difference in output. Therefore, using the MSYS2 Clang distribution to
compile firmware seems a reasonable choice.
If CLANG_HOST_BIN is not defined and BASETOOLS_MINGW_BUILD is defined
and %BASETOOLS_MINGW_PATH%\bin\mingw32-make.exe exists, then
edksetup.bat will add %BASETOOLS_MINGW_PATH%\bin\ to the PATH and set
CLANG_HOST_BIN=mingw32-
This enable usage of the GNU Make included in the mingw-w64 toolchain
to build firmware in addition to BaseTools. if BASETOOLS_MINGW_BUILD is
not defined, edksetup.bat will continue to set CLANG_HOST_BIN=n, which
uses nmake to build firmware. This behavior can be overridden by
manually setting the value of CLANG_HOST_BIN before executing
edksetup.bat if one wishes to use a specific Make utility for the
CLANGPDB/CLANGDWARF toolchains.
References:
 - https://www.mingw-w64.org/
 - https://www.msys2.org/
Co-authored-by: Sandesh Jain <sandesh.jain@intel.com>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
											
										 
											2025-06-06 16:04:29 -07:00
										 |  |  | if /I "%1"=="Mingw-w64" shift | 
					
						
							| 
									
										
										
										
											2024-06-19 21:31:38 -07:00
										 |  |  | if /I "%1"=="VS2022" shift | 
					
						
							| 
									
										
										
										
											2019-09-19 16:52:26 +08:00
										 |  |  | if /I "%1"=="VS2019" shift | 
					
						
							| 
									
										
										
										
											2019-06-12 11:28:46 +08:00
										 |  |  | if /I "%1"=="VS2017" shift | 
					
						
							|  |  |  | if /I "%1"=="VS2015" shift | 
					
						
							| 
									
										
										
										
											2014-02-24 14:14:13 +00:00
										 |  |  | if "%1"=="" goto end | 
					
						
							| 
									
										
										
										
											2006-10-17 07:07:24 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-14 06:46:15 +00:00
										 |  |  | :Usage | 
					
						
							| 
									
										
										
										
											2008-12-31 16:57:24 +00:00
										 |  |  |   @echo. | 
					
						
							| 
									
										
											  
											
												BaseTools: Add support for mingw-w64
Adds support for building the C language BaseTools for Windows using
toolchains based on mingw-w64.
Mingw-w64 is a collection of header files, libraries, and tools that
when combined with a compiler enable development of Windows software.
Mingw-w64 is a fork of the original MinGW (Minimalist GNU for Windows).
Most active development on MinGW has ceased and mingw-w64 is now the
actively maintained successor.  Mingw-w64 provides a libc implementation
built on top of Microsoft's UCRT (Universal C Runtime) with all
nessesary compiler bindings needed to support the C++11 feature set.
Modern mingw-w64 development appears to have coalesced around MSYS2,
which produces a distributions of both GCC and LLVM/Clang that use
mingw-w64 to target the Windows OS. This MSYS2 Clang distribution has a
UNIX-like directory layout and includes Windows binaries of GNU Make.
Combined with the open source licensing, MSYS2's Clang distribution is a
highly attractive choice as an alternative Windows SDK for open source
projects such as TianoCore.
If one wishes to use EDK II to build UEFI firmware on the Windows
platform, then the C BaseTools need to be compiled as Windows
applications. This includes the PcdValueInit.exe program, which needs
to be recompiled every time a firmware build is run in order to
regenerate the initial values for structured PCDs. Currently, BaseTools
only supports the Visual C++ toolchain on the Windows platform. The
following new features have been added to enable usage of the toolchains
derived from mingw-w64:
 - Fixes to the BaseTools C source code to support the use of a
   GCC-style compiler on the Windows OS.
 - The GNU Make-style Makefiles for the C BaseTools have been modified
   to support Windows. Both GCC + mingw-w64 and Clang + mingw-w64 have
   been tested and confirmed to build a working BaseTools.
 - BaseTools now supports generating GNU Make-style Makefiles on the
   Windows platform for the purpose of building firmware.
 - edksetup.bat has been modified to optionally build BaseTools via
   mingw-w64. There is no impact to the existing support for Visual C++
   and Visual C++ remains the default toolchain.
Usage Instructions:
For the vast majority of users, the only system setup change nessesary
to use a mingw-w64 toolchain is to set the BASETOOLS_MINGW_PATH to the
directory containing the desired mingw-w64 based toolchain.
A new command line argument has been added to edksetup.bat: Mingw-w64
If this command line argument is set, then the script will set the
BASETOOLS_MINGW_BUILD environment variable. The user can also opt to set
this environment variable manually before running edksetup.bat
If BASETOOLS_MINGW_BUILD is defined, then the BASETOOLS_MINGW_PATH
environment variable must point to the directory containing the
mingw-w64 toolchain.
If CLANG_BIN is not defined and %BASETOOLS_MINGW_PATH%\bin\clang.exe
exists, then edksetup.bat will set CLANG_BIN=%BASETOOLS_MINGW_PATH%\bin\
This removes the requirement to configure the CLANG_BIN environment
variable manually in order to run a CLANGPDB or CLANGDWARF build if one
has the MSYS2 Clang distribution installed. If one wishes to use a
different copy of Clang (for example official LLVM binaries) to build
firmware and only use the MSYS2 Clang to build BaseTools, then one can
continue to set the CLANG_BIN environment variable, same as before. I
have tested the MSYS2 Clang distribution against the official LLVM
distribution and can confirm that if the compiler version is the same
the emitted machine code is identical between the two. Interestingly,
the MSYS2 Clang distribution emits the path to the PDB file using "/" as
the path seperator instead of "\". That appears to be the only
difference in output. Therefore, using the MSYS2 Clang distribution to
compile firmware seems a reasonable choice.
If CLANG_HOST_BIN is not defined and BASETOOLS_MINGW_BUILD is defined
and %BASETOOLS_MINGW_PATH%\bin\mingw32-make.exe exists, then
edksetup.bat will add %BASETOOLS_MINGW_PATH%\bin\ to the PATH and set
CLANG_HOST_BIN=mingw32-
This enable usage of the GNU Make included in the mingw-w64 toolchain
to build firmware in addition to BaseTools. if BASETOOLS_MINGW_BUILD is
not defined, edksetup.bat will continue to set CLANG_HOST_BIN=n, which
uses nmake to build firmware. This behavior can be overridden by
manually setting the value of CLANG_HOST_BIN before executing
edksetup.bat if one wishes to use a specific Make utility for the
CLANGPDB/CLANGDWARF toolchains.
References:
 - https://www.mingw-w64.org/
 - https://www.msys2.org/
Co-authored-by: Sandesh Jain <sandesh.jain@intel.com>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
											
										 
											2025-06-06 16:04:29 -07:00
										 |  |  |   @echo  Usage: "%0 [-h | -help | --help | /h | /help | /?] [Reconfig] [Rebuild] [ForceRebuild] [Mingw-w64] [VS2022] [VS2019] [VS2017] [VS2015]" | 
					
						
							| 
									
										
										
										
											2008-12-31 16:57:24 +00:00
										 |  |  |   @echo. | 
					
						
							|  |  |  |   @echo         Reconfig       Reinstall target.txt, tools_def.txt and build_rule.txt. | 
					
						
							| 
									
										
										
										
											2017-06-22 14:59:49 -04:00
										 |  |  |   @echo         Rebuild        Perform incremental rebuild of BaseTools binaries. | 
					
						
							|  |  |  |   @echo         ForceRebuild   Force a full rebuild of BaseTools binaries. | 
					
						
							| 
									
										
											  
											
												BaseTools: Add support for mingw-w64
Adds support for building the C language BaseTools for Windows using
toolchains based on mingw-w64.
Mingw-w64 is a collection of header files, libraries, and tools that
when combined with a compiler enable development of Windows software.
Mingw-w64 is a fork of the original MinGW (Minimalist GNU for Windows).
Most active development on MinGW has ceased and mingw-w64 is now the
actively maintained successor.  Mingw-w64 provides a libc implementation
built on top of Microsoft's UCRT (Universal C Runtime) with all
nessesary compiler bindings needed to support the C++11 feature set.
Modern mingw-w64 development appears to have coalesced around MSYS2,
which produces a distributions of both GCC and LLVM/Clang that use
mingw-w64 to target the Windows OS. This MSYS2 Clang distribution has a
UNIX-like directory layout and includes Windows binaries of GNU Make.
Combined with the open source licensing, MSYS2's Clang distribution is a
highly attractive choice as an alternative Windows SDK for open source
projects such as TianoCore.
If one wishes to use EDK II to build UEFI firmware on the Windows
platform, then the C BaseTools need to be compiled as Windows
applications. This includes the PcdValueInit.exe program, which needs
to be recompiled every time a firmware build is run in order to
regenerate the initial values for structured PCDs. Currently, BaseTools
only supports the Visual C++ toolchain on the Windows platform. The
following new features have been added to enable usage of the toolchains
derived from mingw-w64:
 - Fixes to the BaseTools C source code to support the use of a
   GCC-style compiler on the Windows OS.
 - The GNU Make-style Makefiles for the C BaseTools have been modified
   to support Windows. Both GCC + mingw-w64 and Clang + mingw-w64 have
   been tested and confirmed to build a working BaseTools.
 - BaseTools now supports generating GNU Make-style Makefiles on the
   Windows platform for the purpose of building firmware.
 - edksetup.bat has been modified to optionally build BaseTools via
   mingw-w64. There is no impact to the existing support for Visual C++
   and Visual C++ remains the default toolchain.
Usage Instructions:
For the vast majority of users, the only system setup change nessesary
to use a mingw-w64 toolchain is to set the BASETOOLS_MINGW_PATH to the
directory containing the desired mingw-w64 based toolchain.
A new command line argument has been added to edksetup.bat: Mingw-w64
If this command line argument is set, then the script will set the
BASETOOLS_MINGW_BUILD environment variable. The user can also opt to set
this environment variable manually before running edksetup.bat
If BASETOOLS_MINGW_BUILD is defined, then the BASETOOLS_MINGW_PATH
environment variable must point to the directory containing the
mingw-w64 toolchain.
If CLANG_BIN is not defined and %BASETOOLS_MINGW_PATH%\bin\clang.exe
exists, then edksetup.bat will set CLANG_BIN=%BASETOOLS_MINGW_PATH%\bin\
This removes the requirement to configure the CLANG_BIN environment
variable manually in order to run a CLANGPDB or CLANGDWARF build if one
has the MSYS2 Clang distribution installed. If one wishes to use a
different copy of Clang (for example official LLVM binaries) to build
firmware and only use the MSYS2 Clang to build BaseTools, then one can
continue to set the CLANG_BIN environment variable, same as before. I
have tested the MSYS2 Clang distribution against the official LLVM
distribution and can confirm that if the compiler version is the same
the emitted machine code is identical between the two. Interestingly,
the MSYS2 Clang distribution emits the path to the PDB file using "/" as
the path seperator instead of "\". That appears to be the only
difference in output. Therefore, using the MSYS2 Clang distribution to
compile firmware seems a reasonable choice.
If CLANG_HOST_BIN is not defined and BASETOOLS_MINGW_BUILD is defined
and %BASETOOLS_MINGW_PATH%\bin\mingw32-make.exe exists, then
edksetup.bat will add %BASETOOLS_MINGW_PATH%\bin\ to the PATH and set
CLANG_HOST_BIN=mingw32-
This enable usage of the GNU Make included in the mingw-w64 toolchain
to build firmware in addition to BaseTools. if BASETOOLS_MINGW_BUILD is
not defined, edksetup.bat will continue to set CLANG_HOST_BIN=n, which
uses nmake to build firmware. This behavior can be overridden by
manually setting the value of CLANG_HOST_BIN before executing
edksetup.bat if one wishes to use a specific Make utility for the
CLANGPDB/CLANGDWARF toolchains.
References:
 - https://www.mingw-w64.org/
 - https://www.msys2.org/
Co-authored-by: Sandesh Jain <sandesh.jain@intel.com>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
											
										 
											2025-06-06 16:04:29 -07:00
										 |  |  |   @echo         Mingw-w64      Build BaseTools binaries using mingw-w64. | 
					
						
							| 
									
										
										
										
											2019-06-12 11:28:46 +08:00
										 |  |  |   @echo         VS2015         Set the env for VS2015 build. | 
					
						
							|  |  |  |   @echo         VS2017         Set the env for VS2017 build. | 
					
						
							| 
									
										
										
										
											2019-09-19 16:52:26 +08:00
										 |  |  |   @echo         VS2019         Set the env for VS2019 build. | 
					
						
							| 
									
										
										
										
											2024-06-19 21:31:38 -07:00
										 |  |  |   @echo         VS2022         Set the env for VS2022 build. | 
					
						
							| 
									
										
										
										
											2008-12-31 16:57:24 +00:00
										 |  |  |   @echo. | 
					
						
							|  |  |  |   @echo  Note that target.template, tools_def.template and build_rules.template | 
					
						
							| 
									
										
										
										
											2014-02-24 14:14:13 +00:00
										 |  |  |   @echo  will only be copied to target.txt, tools_def.txt and build_rule.txt | 
					
						
							|  |  |  |   @echo  respectively if they do not exist. Use option [Reconfig] to force the copy. | 
					
						
							| 
									
										
										
										
											2008-12-31 16:57:24 +00:00
										 |  |  |   @echo. | 
					
						
							| 
									
										
										
										
											2014-02-24 14:09:00 +00:00
										 |  |  |   goto end | 
					
						
							| 
									
										
										
										
											2007-06-22 06:25:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-04-21 22:54:32 +00:00
										 |  |  | :end | 
					
						
							| 
									
										
										
										
											2014-02-24 14:09:00 +00:00
										 |  |  |   popd |