summaryrefslogtreecommitdiff
path: root/BaseTools/Source
diff options
context:
space:
mode:
authorNate DeSimone <nathaniel.l.desimone@intel.com>2025-06-06 16:04:29 -0700
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2025-06-07 17:56:04 +0000
commitc0ef2b017855177903d87937ac4cdaec5c7851db (patch)
tree11193ca2285edd90815d1914d97a53fbbbf7e3f2 /BaseTools/Source
parent18fdec11b1ab6475d1c3f328953f225547983dd5 (diff)
downloadedk2-c0ef2b017855177903d87937ac4cdaec5c7851db.zip
edk2-c0ef2b017855177903d87937ac4cdaec5c7851db.tar.gz
edk2-c0ef2b017855177903d87937ac4cdaec5c7851db.tar.bz2
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>
Diffstat (limited to 'BaseTools/Source')
-rw-r--r--BaseTools/Source/C/BrotliCompress/BrotliCompress.c3
-rw-r--r--BaseTools/Source/C/Common/CommonLib.c4
-rw-r--r--BaseTools/Source/C/Common/CommonLib.h9
-rw-r--r--BaseTools/Source/C/DevicePath/GNUmakefile11
-rw-r--r--BaseTools/Source/C/GNUmakefile51
-rw-r--r--BaseTools/Source/C/GenFv/GenFvInternalLib.c4
-rw-r--r--BaseTools/Source/C/Makefiles/GnuMakeUtils.py291
-rw-r--r--BaseTools/Source/C/Makefiles/app.makefile12
-rw-r--r--BaseTools/Source/C/Makefiles/footer.makefile8
-rw-r--r--BaseTools/Source/C/Makefiles/header.makefile132
-rw-r--r--BaseTools/Source/C/VfrCompile/GNUmakefile24
-rw-r--r--BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile13
-rw-r--r--BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile12
-rw-r--r--BaseTools/Source/Python/Workspace/DscBuildData.py50
14 files changed, 518 insertions, 106 deletions
diff --git a/BaseTools/Source/C/BrotliCompress/BrotliCompress.c b/BaseTools/Source/C/BrotliCompress/BrotliCompress.c
index 62a6aed..c6b0189 100644
--- a/BaseTools/Source/C/BrotliCompress/BrotliCompress.c
+++ b/BaseTools/Source/C/BrotliCompress/BrotliCompress.c
@@ -2,6 +2,7 @@
BrotliCompress Compress/Decompress tool (BrotliCompress)
Copyright (c) 2020, ByoSoft Corporation. All rights reserved.<BR>
+ Copyright (c) 2025, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -52,12 +53,14 @@ static FILE* ms_fopen(const char* FileName, const char* Mode) {
return Result;
}
+#if !defined(__MINGW32__)
static int ms_open(const char* FileName, int Oflag, int Pmode) {
int Result;
Result = -1;
_sopen_s(&Result, FileName, Oflag | O_BINARY, _SH_DENYNO, Pmode);
return Result;
}
+#endif
#endif /* WIN32 */
diff --git a/BaseTools/Source/C/Common/CommonLib.c b/BaseTools/Source/C/Common/CommonLib.c
index b2cde6d..5830cc1 100644
--- a/BaseTools/Source/C/Common/CommonLib.c
+++ b/BaseTools/Source/C/Common/CommonLib.c
@@ -1,7 +1,7 @@
/** @file
Common basic Library Functions
-Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2025, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -469,6 +469,7 @@ PrintGuidToBuffer (
#ifdef __GNUC__
+#ifndef _WIN32
size_t _filelength(int fd)
{
struct stat stat_buf;
@@ -487,6 +488,7 @@ char *strlwr(char *s)
}
#endif
#endif
+#endif
#define WINDOWS_EXTENSION_PATH "\\\\?\\"
#define WINDOWS_UNC_EXTENSION_PATH "\\\\?\\UNC"
diff --git a/BaseTools/Source/C/Common/CommonLib.h b/BaseTools/Source/C/Common/CommonLib.h
index a841029..f554de1 100644
--- a/BaseTools/Source/C/Common/CommonLib.h
+++ b/BaseTools/Source/C/Common/CommonLib.h
@@ -1,7 +1,7 @@
/** @file
Common library assistance routines.
-Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2025, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -450,12 +450,17 @@ Returns:
#define _stricmp strcasecmp
#define strnicmp strncasecmp
#define strcmpi strcasecmp
-size_t _filelength(int fd);
#ifndef __CYGWIN__
char *strlwr(char *s);
#endif
#endif
+#ifdef _WIN32
+#include <io.h> // io.h provides the declaration of _filelength on Windows
+#else
+size_t _filelength(int fd); // Only declare this on non-Windows systems
+#endif
+
//
// On windows, mkdir only has one parameter.
// On unix, it has two parameters
diff --git a/BaseTools/Source/C/DevicePath/GNUmakefile b/BaseTools/Source/C/DevicePath/GNUmakefile
index 26ae14c..40cf277 100644
--- a/BaseTools/Source/C/DevicePath/GNUmakefile
+++ b/BaseTools/Source/C/DevicePath/GNUmakefile
@@ -1,7 +1,7 @@
## @file
# GNU/Linux makefile for 'DevicePath' module build.
#
-# Copyright (c) 2017, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2017 - 2025, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
ARCH ?= IA32
@@ -13,8 +13,13 @@ OBJECTS = DevicePath.o UefiDevicePathLib.o DevicePathFromText.o DevicePathUtili
include $(MAKEROOT)/Makefiles/app.makefile
-GCCVERSION = $(shell $(CC) -dumpversion | awk -F'.' '{print $$1}')
-CLANG := $(shell $(CC) --version | grep clang)
+ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
+GCCVERSION := $(shell for /f "tokens=1 delims=." %%a in ("$(shell $(CC) -dumpversion)") do echo %%a)
+else
+GCCVERSION := $(shell $(CC) -dumpversion | awk -F'.' '{print $$1}')
+endif
+CLANG := $(findstring clang,$(shell $(CC) --version))
+
ifneq ("$(GCCVERSION)", "5")
ifeq ($(CLANG),)
ifneq ($(DARWIN),Darwin)
diff --git a/BaseTools/Source/C/GNUmakefile b/BaseTools/Source/C/GNUmakefile
index 5275f65..0ea314e 100644
--- a/BaseTools/Source/C/GNUmakefile
+++ b/BaseTools/Source/C/GNUmakefile
@@ -1,50 +1,23 @@
## @file
# GNU/Linux makefile for C tools build.
#
-# Copyright (c) 2007 - 2017, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2025, Intel Corporation. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
-ifndef HOST_ARCH
- #
- # If HOST_ARCH is not defined, then we use 'uname -m' to attempt
- # try to figure out the appropriate HOST_ARCH.
- #
- uname_m = $(shell uname -m)
- $(info Attempting to detect HOST_ARCH from 'uname -m': $(uname_m))
- ifneq (,$(strip $(filter $(uname_m), x86_64 amd64)))
- HOST_ARCH=X64
- endif
- ifeq ($(patsubst i%86,IA32,$(uname_m)),IA32)
- HOST_ARCH=IA32
- endif
- ifneq (,$(findstring aarch64,$(uname_m)))
- HOST_ARCH=AARCH64
- else ifneq (,$(findstring arm64,$(uname_m)))
- HOST_ARCH=AARCH64
- else ifneq (,$(findstring arm,$(uname_m)))
- HOST_ARCH=ARM
- endif
- ifneq (,$(findstring riscv64,$(uname_m)))
- HOST_ARCH=RISCV64
- endif
- ifneq (,$(findstring loongarch64,$(uname_m)))
- HOST_ARCH=LOONGARCH64
- endif
- ifndef HOST_ARCH
- $(info Could not detected HOST_ARCH from uname results)
- $(error HOST_ARCH is not defined!)
- endif
- $(info Detected HOST_ARCH of $(HOST_ARCH) using uname.)
+ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
+ SHELL := cmd.exe
+ MAKEROOT := $(shell echo %CD%)
+else
+ MAKEROOT := .
endif
-export HOST_ARCH
-
-MAKEROOT = .
-
include Makefiles/header.makefile
+export PYTHON_COMMAND
+export HOST_ARCH
+
all: makerootdir subdirs
@echo Finished building BaseTools C Tools with HOST_ARCH=$(HOST_ARCH)
@@ -71,7 +44,7 @@ $(APPLICATIONS): $(LIBRARIES) $(MAKEROOT)/bin $(VFRAUTOGEN)
.PHONY: outputdirs
makerootdir:
- -mkdir -p $(MAKEROOT)
+ -$(MD) $(MAKEROOT)
.PHONY: subdirs $(SUBDIRS)
subdirs: $(SUBDIRS)
@@ -90,7 +63,7 @@ clean: $(patsubst %,%-clean,$(sort $(SUBDIRS)))
clean: localClean
localClean:
- rm -f $(MAKEROOT)/bin/*
- -rmdir $(MAKEROOT)/libs $(MAKEROOT)/bin
+ $(RM) $(MAKEROOT)/bin/*
+ -$(RD) $(MAKEROOT)/libs $(MAKEROOT)/bin
include Makefiles/footer.makefile
diff --git a/BaseTools/Source/C/GenFv/GenFvInternalLib.c b/BaseTools/Source/C/GenFv/GenFvInternalLib.c
index 44be413..e4f4090 100644
--- a/BaseTools/Source/C/GenFv/GenFvInternalLib.c
+++ b/BaseTools/Source/C/GenFv/GenFvInternalLib.c
@@ -1,7 +1,7 @@
/** @file
This file contains the internal functions required to generate a Firmware Volume.
-Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (c) 2004 - 2025, Intel Corporation. All rights reserved.<BR>
Portions Copyright (c) 2011 - 2013, ARM Ltd. All rights reserved.<BR>
Portions Copyright (c) 2016 HP Development Company, L.P.<BR>
Portions Copyright (c) 2020, Hewlett Packard Enterprise Development LP. All rights reserved.<BR>
@@ -16,7 +16,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#if defined(__FreeBSD__)
#include <uuid.h>
-#elif defined(__GNUC__)
+#elif defined(__GNUC__) && !defined(_WIN32)
#if !defined(__CROSS_LIB_UUID__)
#include <uuid/uuid.h>
#else
diff --git a/BaseTools/Source/C/Makefiles/GnuMakeUtils.py b/BaseTools/Source/C/Makefiles/GnuMakeUtils.py
new file mode 100644
index 0000000..3924311
--- /dev/null
+++ b/BaseTools/Source/C/Makefiles/GnuMakeUtils.py
@@ -0,0 +1,291 @@
+#!/usr/bin/env python3
+#
+## @file GnuMakeUtils.py
+#
+#
+# Copyright (c) 2025, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+from collections import namedtuple
+import glob
+import os
+import re
+import shutil
+import subprocess
+import sys
+import traceback
+if sys.platform == 'win32':
+ from ctypes import windll, POINTER, byref, GetLastError, Structure, WinError
+ from ctypes import c_void_p, c_ushort, c_int, c_long, c_ulong, c_wchar, sizeof
+
+ARCH_UNKNOWN = 'Unknown'
+ARCH_IA32 = 'IA32'
+ARCH_X64 = 'X64'
+ARCH_AARCH64 = 'AARCH64'
+ARCH_ARM = 'ARM'
+ARCH_RISCV64 = 'RISCV64'
+ARCH_LOONGARCH64 = 'LOONGARCH64'
+_Process = namedtuple('Process', ['process_id', 'parent_process_id', 'exe_filename'])
+
+def _get_win32_process_architecture(pid):
+ IMAGE_FILE_MACHINE_I386 = 0x014c
+ IMAGE_FILE_MACHINE_AMD64 = 0x8664
+ IMAGE_FILE_MACHINE_ARM64 = 0xAA64
+ def _get_machine_type(machine_id):
+ if machine_id == IMAGE_FILE_MACHINE_I386:
+ return ARCH_IA32
+ elif machine_id == IMAGE_FILE_MACHINE_AMD64:
+ return ARCH_X64
+ elif machine_id == IMAGE_FILE_MACHINE_ARM64:
+ return ARCH_AARCH64
+ return ARCH_UNKNOWN
+ PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
+ kernel32 = windll.kernel32
+ OpenProcess = kernel32.OpenProcess
+ OpenProcess.argtypes = [c_ulong, c_int, c_ulong]
+ OpenProcess.restype = c_void_p
+ CloseHandle = kernel32.CloseHandle
+ CloseHandle.argtypes = [c_void_p]
+ CloseHandle.restype = c_int
+
+ IsWow64Process2 = None
+ IMAGE_FILE_MACHINE_UNKNOWN = 0
+ try:
+ #IsWow64Process2() is only available on Win10 TH2 or later
+ IsWow64Process2 = kernel32.IsWow64Process2
+ except AttributeError:
+ IsWow64Process2 = None
+ if IsWow64Process2 is not None:
+ IsWow64Process2.argtypes = [c_void_p, POINTER(c_ushort), POINTER(c_ushort)]
+ IsWow64Process2.restype = c_int
+ ProcessMachine = c_ushort(1)
+ NativeMachine = c_ushort(1)
+ hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, pid)
+ if hProcess == c_void_p(0):
+ raise WinError(GetLastError())
+ if IsWow64Process2(hProcess, byref(ProcessMachine), byref(NativeMachine)) != 0:
+ CloseHandle(hProcess)
+ if ProcessMachine.value == IMAGE_FILE_MACHINE_UNKNOWN:
+ return _get_machine_type(NativeMachine.value)
+ else:
+ return _get_machine_type(ProcessMachine.value)
+ else:
+ CloseHandle(hProcess)
+ raise WinError(GetLastError())
+ else:
+ #Graceful fallback for older OSes
+ PROCESSOR_ARCHITECTURE_INTEL = 0
+ PROCESSOR_ARCHITECTURE_AMD64 = 9
+ class _SYSTEM_INFO(Structure):
+ _fields_ = [('wProcessorArchitecture', c_ushort),
+ ('wReserved', c_ushort),
+ ('dwPageSize', c_ulong),
+ ('lpMinimumApplicationAddress', c_void_p),
+ ('lpMaximumApplicationAddress', c_void_p),
+ ('dwActiveProcessorMask', c_void_p),
+ ('dwNumberOfProcessors', c_ulong),
+ ('dwProcessorType', c_ulong),
+ ('dwAllocationGranularity', c_ulong),
+ ('wProcessorLevel', c_ushort),
+ ('wProcessorRevision', c_ushort)]
+ GetNativeSystemInfo = kernel32.GetNativeSystemInfo
+ GetNativeSystemInfo.argtypes = [POINTER(_SYSTEM_INFO)]
+ systemInfo = _SYSTEM_INFO()
+ GetNativeSystemInfo(byref(systemInfo))
+ if systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64:
+ hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, 0, pid)
+ if hProcess == c_void_p(0):
+ raise WinError(GetLastError())
+ IsWow64Process = kernel32.IsWow64Process
+ IsWow64Process.argtypes = [c_void_p, POINTER(c_int)]
+ IsWow64Process.restype = c_int
+ is_wow64 = c_int(0)
+ if IsWow64Process(hProcess, byref(is_wow64)) != 0:
+ CloseHandle(hProcess)
+ if is_wow64.value != 0:
+ return ARCH_IA32
+ else:
+ return ARCH_X64
+ else:
+ CloseHandle(hProcess)
+ raise WinError(GetLastError())
+ elif systemInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL:
+ return ARCH_IA32
+ return ARCH_UNKNOWN
+
+def _get_win32_process_list():
+ class _PROCESSENTRY32W(Structure):
+ _fields_ = [('dwSize', c_ulong),
+ ('cntUsage', c_ulong),
+ ('th32ProcessID', c_ulong),
+ ('th32DefaultHeapID', c_void_p),
+ ('th32ModuleID', c_ulong),
+ ('cntThreads', c_ulong),
+ ('th32ParentProcessID', c_ulong),
+ ('pcPriClassBase', c_long),
+ ('dwFlags', c_ulong),
+ ('szExeFile', (c_wchar * 260))]
+ INVALID_HANDLE_VALUE = c_void_p(-1)
+ TH32CS_SNAPPROCESS = 2
+ ERROR_NO_MORE_FILES = 18
+ kernel32 = windll.kernel32
+ CreateToolhelp32Snapshot = kernel32.CreateToolhelp32Snapshot
+ CreateToolhelp32Snapshot.argtypes = [c_ulong, c_ulong]
+ CreateToolhelp32Snapshot.restype = c_void_p
+ Process32First = kernel32.Process32FirstW
+ Process32First.argtypes = [c_void_p, POINTER(_PROCESSENTRY32W)]
+ Process32First.restype = c_int
+ Process32Next = kernel32.Process32NextW
+ Process32Next.argtypes = [c_void_p, POINTER(_PROCESSENTRY32W)]
+ Process32Next.restype = c_int
+ CloseHandle = kernel32.CloseHandle
+ CloseHandle.argtypes = [c_void_p]
+ CloseHandle.restype = c_int
+
+ hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
+ if hSnapshot == INVALID_HANDLE_VALUE.value:
+ raise WinError(GetLastError())
+ process_list = []
+ processEntry = _PROCESSENTRY32W()
+ processEntry.dwSize = sizeof(processEntry)
+ more_processes = True
+ if Process32First(hSnapshot, byref(processEntry)) == 0:
+ raise WinError(GetLastError())
+ while more_processes:
+ process_list.append(_Process(processEntry.th32ProcessID, processEntry.th32ParentProcessID, processEntry.szExeFile))
+ if Process32Next(hSnapshot, byref(processEntry)) == 0:
+ status = GetLastError()
+ if status == ERROR_NO_MORE_FILES:
+ more_processes = False
+ else:
+ raise WinError(status)
+ CloseHandle(hSnapshot)
+ return process_list
+
+def _get_win32_parent_processes():
+ kernel32 = windll.kernel32
+ GetCurrentProcessId = kernel32.GetCurrentProcessId
+ GetCurrentProcessId.argtypes = []
+ GetCurrentProcessId.restype = c_ulong
+
+ process_list = _get_win32_process_list()
+ pid = GetCurrentProcessId()
+ parent_processes = []
+ found_parent = True
+ while found_parent:
+ found_parent = False
+ for process in process_list:
+ if process.process_id == pid:
+ found_parent = True
+ parent_processes.append(process)
+ pid = process.parent_process_id
+ break
+ return parent_processes
+
+def _get_mingw_target_architecture():
+ parent_processes = _get_win32_parent_processes()
+ for process in parent_processes:
+ if 'make' in process.exe_filename.lower():
+ return _get_win32_process_architecture(process.process_id)
+ return ARCH_UNKNOWN
+
+def get_host_arch():
+ if sys.platform == 'win32':
+ host_arch = _get_mingw_target_architecture()
+ else:
+ result = subprocess.run('uname -m', universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True, check=True)
+ uname_m = result.stdout.strip()
+ ia32_regex = re.compile(r".*i[8]?[0-9]86.*")
+ ia32_match = ia32_regex.match(uname_m)
+ if 'x86_64' in uname_m or 'amd64' in uname_m:
+ host_arch = ARCH_X64
+ elif ia32_match:
+ host_arch = ARCH_IA32
+ elif 'aarch64' in uname_m or 'arm64' in uname_m:
+ host_arch = ARCH_AARCH64
+ elif 'arm' in uname_m:
+ host_arch = ARCH_ARM
+ elif 'riscv64' in uname_m:
+ host_arch = ARCH_RISCV64
+ elif 'loongarch64' in uname_m:
+ host_arch = ARCH_LOONGARCH64
+ # There is a corner case for the Raspberry Pi. Sometimes it has a 64-bit
+ # kernel paired with an exclusively 32-bit user mode. Check for this case.
+ if shutil.which("lsb_release") is not None:
+ res = subprocess.run(["lsb_release", "-i"], universal_newlines=True,
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
+ check=True)
+ distributor = res.stdout.strip()
+ if distributor == "Distributor ID:\tRaspbian":
+ host_arch = ARCH_ARM
+ print(host_arch)
+ return 0
+
+def main():
+ if sys.argv[1] == 'get_host_arch':
+ return get_host_arch()
+ elif sys.argv[1] == 'cp':
+ shutil.copy(os.path.normpath(sys.argv[2]), os.path.normpath(sys.argv[3]))
+ elif sys.argv[1] == 'mv':
+ shutil.move(os.path.normpath(sys.argv[2]), os.path.normpath(sys.argv[3]))
+ elif sys.argv[1] == 'rm':
+ paths = [os.path.normpath(x) for x in sys.argv[2:]]
+ files = []
+ for path in paths:
+ if '*' in path:
+ files.extend(glob.glob(path))
+ else:
+ files.append(path)
+ for file in files:
+ if os.path.exists(file):
+ if os.path.isfile(file):
+ os.remove(file)
+ else:
+ sys.stderr.writelines(['{} is not a file.'.format(file)])
+ else:
+ sys.stderr.writelines(['File {} does not exist.'.format(file)])
+ elif sys.argv[1] == 'md':
+ path = os.path.normpath(sys.argv[2])
+ if not os.path.exists(path):
+ os.makedirs(path)
+ else:
+ if os.path.isdir(path):
+ sys.stderr.writelines(['Directory {} already exists.'.format(path)])
+ else:
+ sys.stderr.writelines(['{} is a file.'.format(path)])
+ return 1
+ elif sys.argv[1] == 'rd':
+ paths = [os.path.normpath(x) for x in sys.argv[2:]]
+ for path in paths:
+ if os.path.exists(path):
+ if os.path.isdir(path):
+ shutil.rmtree(path)
+ else:
+ sys.stderr.writelines(['{} is not a directory.'.format(path)])
+ else:
+ sys.stderr.writelines(['Directory {} does not exist.'.format(path)])
+ elif sys.argv[1] == 'rm_pyc_files':
+ path = os.path.normpath(sys.argv[2])
+ files = glob.glob(os.path.join(path, '*.pyc'))
+ for file in files:
+ if os.path.exists(file):
+ if os.path.isfile(file):
+ os.remove(file)
+ else:
+ sys.stderr.writelines(['{} is not a file.'.format(file)])
+ else:
+ sys.stderr.writelines(['File {} does not exist.'.format(file)])
+ py_cache = os.path.join(path, '__pycache__')
+ if os.path.isdir(py_cache):
+ shutil.rmtree(py_cache)
+ else:
+ sys.stderr.writelines(['Unsupported command.'])
+ return 1
+ return 0
+
+if __name__ == '__main__':
+ try:
+ sys.exit(main())
+ except Exception as e:
+ traceback.print_exc()
+ sys.exit(1)
diff --git a/BaseTools/Source/C/Makefiles/app.makefile b/BaseTools/Source/C/Makefiles/app.makefile
index 506343a..0ad1378 100644
--- a/BaseTools/Source/C/Makefiles/app.makefile
+++ b/BaseTools/Source/C/Makefiles/app.makefile
@@ -1,7 +1,7 @@
## @file
# Makefiles
#
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2025, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -16,7 +16,17 @@ all: $(MAKEROOT)/bin $(APPLICATION)
$(APPLICATION): $(OBJECTS)
$(LINKER) -o $(APPLICATION) $(LDFLAGS) $(OBJECTS) -L$(MAKEROOT)/libs $(LIBS)
+ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
+ $(CP) $(APPLICATION).exe $(BIN_PATH)
+endif
$(OBJECTS): $(MAKEROOT)/Include/Common/BuildVersion.h
+clean: appClean
+
+appClean:
+ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
+ $(RM) $(BIN_PATH)/$(APPNAME).exe
+endif
+
include $(MAKEROOT)/Makefiles/footer.makefile
diff --git a/BaseTools/Source/C/Makefiles/footer.makefile b/BaseTools/Source/C/Makefiles/footer.makefile
index 7546da8..9a3dfcd 100644
--- a/BaseTools/Source/C/Makefiles/footer.makefile
+++ b/BaseTools/Source/C/Makefiles/footer.makefile
@@ -1,18 +1,18 @@
## @file
# Makefile
#
-# Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2025, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
DEPFILES = $(OBJECTS:%.o=%.d)
$(MAKEROOT)/libs-$(HOST_ARCH):
- mkdir -p $(MAKEROOT)/libs-$(HOST_ARCH)
+ $(MD) $(MAKEROOT)/libs-$(HOST_ARCH)
.PHONY: install
install: $(MAKEROOT)/libs-$(HOST_ARCH) $(LIBRARY)
- cp $(LIBRARY) $(MAKEROOT)/libs-$(HOST_ARCH)
+ $(CP) $(LIBRARY) $(MAKEROOT)/libs-$(HOST_ARCH)
$(LIBRARY): $(OBJECTS)
$(AR) crs $@ $^
@@ -25,6 +25,6 @@ $(LIBRARY): $(OBJECTS)
.PHONY: clean
clean:
- @rm -f $(OBJECTS) $(LIBRARY) $(DEPFILES)
+ $(RM) $(OBJECTS) $(LIBRARY) $(DEPFILES)
-include $(DEPFILES)
diff --git a/BaseTools/Source/C/Makefiles/header.makefile b/BaseTools/Source/C/Makefiles/header.makefile
index f16b329..55a7307 100644
--- a/BaseTools/Source/C/Makefiles/header.makefile
+++ b/BaseTools/Source/C/Makefiles/header.makefile
@@ -5,48 +5,117 @@
# HOST_ARCH = ia32 or IA32 for IA32 build
# HOST_ARCH = Arm or ARM for ARM build
#
-# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2007 - 2025, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
+# Set SEP to the platform specific path seperator
+ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
+ SHELL := cmd.exe
+ SEP:=$(shell echo \)
+else
+ SEP:=/
+endif
+
EDK2_PATH ?= $(MAKEROOT)/../../..
+ifndef PYTHON_COMMAND
+ ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
+ #
+ # Try using the Python Launcher for Windows to find an interperter.
+ #
+ CHECK_PY := $(shell where py.exe || echo NotFound)
+ ifeq ($(CHECK_PY),NotFound)
+ #
+ # PYTHON_HOME is the old method of specifying a Python interperter on Windows.
+ # Check if an interperter can be found using PYTHON_HOME.
+ #
+ ifdef PYTHON_HOME
+ ifndef (,$(wildcard $(PYTHON_HOME)$(SEP)python.exe)) # Make sure the file exists
+ PYTHON_COMMAND := $(PYTHON_HOME)$(SEP)python.exe
+ else
+ $(error Unable to find a Python interperter, if one is installed, set the PYTHON_COMMAND environment variable!)
+ endif
+ endif
+ else
+ PYTHON_COMMAND := $(shell py -3 -c "import sys; print(sys.executable)")
+ ifdef (,$(wildcard $(PYTHON_COMMAND))) # Make sure the file exists
+ $(error Unable to find a Python interperter, if one is installed, set the PYTHON_COMMAND environment variable!)
+ endif
+ endif
+ undefine CHECK_PY
+ else # UNIX
+ PYTHON_COMMAND := $(shell /usr/bin/env python3 -c "import sys; print(sys.executable)")
+ ifdef (,$(wildcard $(PYTHON_COMMAND))) # Make sure the file exists
+ PYTHON_COMMAND := $(shell /usr/bin/env python -c "import sys; print(sys.executable)")
+ ifdef (,$(wildcard $(PYTHON_COMMAND))) # Make sure the file exists
+ undefine PYTHON_COMMAND
+ endif
+ endif
+ ifndef PYTHON_COMMAND
+ $(error Unable to find a Python interpreter, if one is installed, set the PYTHON_COMMAND environment variable!)
+ endif
+ endif
+ export PYTHON_COMMAND
+endif
+
+# GnuMakeUtils.py is able to handle forward slashes in file paths on Windows systems
+GNU_MAKE_UTILS_PY := $(PYTHON_COMMAND) $(MAKEROOT)$(SEP)Makefiles$(SEP)GnuMakeUtils.py
+CP := $(GNU_MAKE_UTILS_PY) cp
+MV := $(GNU_MAKE_UTILS_PY) mv
+RM := $(GNU_MAKE_UTILS_PY) rm
+MD := $(GNU_MAKE_UTILS_PY) md
+RD := $(GNU_MAKE_UTILS_PY) rd
ifndef HOST_ARCH
#
- # If HOST_ARCH is not defined, then we use 'uname -m' to attempt
+ # If HOST_ARCH is not defined, then we use 'GnuMakeUtils.py' to attempt
# try to figure out the appropriate HOST_ARCH.
#
- uname_m = $(shell uname -m)
- $(info Attempting to detect HOST_ARCH from 'uname -m': $(uname_m))
- ifneq (,$(strip $(filter $(uname_m), x86_64 amd64)))
- HOST_ARCH=X64
- endif
- ifeq ($(patsubst i%86,IA32,$(uname_m)),IA32)
- HOST_ARCH=IA32
- endif
- ifneq (,$(findstring aarch64,$(uname_m)))
- HOST_ARCH=AARCH64
- else ifneq (,$(findstring arm64,$(uname_m)))
- HOST_ARCH=AARCH64
- else ifneq (,$(findstring arm,$(uname_m)))
- HOST_ARCH=ARM
+ GET_GNU_HOST_ARCH_PY:=$(MAKEROOT)$(SEP)Makefiles$(SEP)GnuMakeUtils.py get_host_arch
+ ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
+ HOST_ARCH:=$(shell if defined PYTHON_COMMAND $(PYTHON_COMMAND) $(GET_GNU_HOST_ARCH_PY))
+ else
+ HOST_ARCH:=$(shell if command -v $(PYTHON_COMMAND) >/dev/null 1; then $(PYTHON_COMMAND) $(GET_GNU_HOST_ARCH_PY); else python $(GET_GNU_HOST_ARCH_PY); fi)
endif
- ifneq (,$(findstring riscv64,$(uname_m)))
- HOST_ARCH=RISCV64
+ ifeq ($(HOST_ARCH),)
+ $(info HOST_ARCH detection failed.)
+ undefine HOST_ARCH
endif
- ifneq (,$(findstring loongarch64,$(uname_m)))
- HOST_ARCH=LOONGARCH64
+ ifeq ($(HOST_ARCH),Unknown)
+ $(info HOST_ARCH detection failed.)
+ undefine HOST_ARCH
endif
- ifndef HOST_ARCH
- $(info Could not detected HOST_ARCH from uname results)
- $(error HOST_ARCH is not defined!)
+endif
+ifndef HOST_ARCH
+ $(error HOST_ARCH is not defined!)
+endif
+
+#Set up BaseTools binary path for Windows builds
+ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
+ ifndef BIN_PATH
+ BIN_PATH_BASE=$(MAKEROOT)/../../Bin
+ ifeq ($(HOST_ARCH),X64)
+ BIN_PATH=$(BIN_PATH_BASE)/Win64
+ else
+ ifeq ($(HOST_ARCH),AARCH64)
+ BIN_PATH=$(BIN_PATH_BASE)/Win64
+ else
+ BIN_PATH=$(BIN_PATH_BASE)/Win32
+ endif
+ endif
endif
- $(info Detected HOST_ARCH of $(HOST_ARCH) using uname.)
endif
-CYGWIN:=$(findstring CYGWIN, $(shell uname -s))
-LINUX:=$(findstring Linux, $(shell uname -s))
-DARWIN:=$(findstring Darwin, $(shell uname -s))
-CLANG:=$(shell $(CC) --version | grep clang)
+ifneq ($(findstring cmd,$(SHELL)),cmd)
+ CYGWIN:=$(findstring CYGWIN, $(shell uname -s))
+ LINUX:=$(findstring Linux, $(shell uname -s))
+ DARWIN:=$(findstring Darwin, $(shell uname -s))
+else
+ #Don't use uname on Windows
+ CYGWIN:=
+ LINUX:=
+ DARWIN:=
+endif
+CLANG := $(findstring clang,$(shell $(CC) --version))
ifneq ($(CLANG),)
CC ?= $(CLANG_BIN)clang
CXX ?= $(CLANG_BIN)clang++
@@ -141,7 +210,10 @@ LDFLAGS += $(EXTRA_LDFLAGS)
all:
$(MAKEROOT)/libs:
- mkdir $(MAKEROOT)/libs
+ $(MD) $(MAKEROOT)/libs
$(MAKEROOT)/bin:
- mkdir $(MAKEROOT)/bin
+ $(MD) $(MAKEROOT)/bin
+ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
+ $(MD) $(BIN_PATH)
+endif
diff --git a/BaseTools/Source/C/VfrCompile/GNUmakefile b/BaseTools/Source/C/VfrCompile/GNUmakefile
index 7d59766..ad6c350 100644
--- a/BaseTools/Source/C/VfrCompile/GNUmakefile
+++ b/BaseTools/Source/C/VfrCompile/GNUmakefile
@@ -1,7 +1,7 @@
## @file
# GNU/Linux makefile for 'VfrCompile' module build.
#
-# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2008 - 2025, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -16,7 +16,7 @@ TOOL_INCLUDE = -I Pccts/h
#OBJECTS = VfrSyntax.o VfrServices.o DLGLexer.o EfiVfrParser.o ATokenBuffer.o DLexerBase.o AParser.o
OBJECTS = AParser.o DLexerBase.o ATokenBuffer.o EfiVfrParser.o VfrLexer.o VfrSyntax.o \
VfrFormPkg.o VfrError.o VfrUtilityLib.o VfrCompiler.o
-CLANG:=$(shell $(CC) --version | grep clang)
+CLANG := $(findstring clang,$(shell $(CC) --version))
ifneq ($(CLANG),)
VFR_CPPFLAGS = -Wno-deprecated-register -std=c++14 -DPCCTS_USE_NAMESPACE_STD $(CPPFLAGS)
else
@@ -38,11 +38,17 @@ include $(MAKEROOT)/Makefiles/header.makefile
APPLICATION = $(MAKEROOT)/bin/$(APPNAME)
+BIN_DIR=.
+export BIN_DIR
+
.PHONY:all
all: $(MAKEROOT)/bin $(APPLICATION)
$(APPLICATION): $(OBJECTS)
$(LINKER) -o $(APPLICATION) $(VFR_LFLAGS) $(OBJECTS) -L$(MAKEROOT)/libs $(LIBS)
+ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
+ $(CP) $(APPLICATION).exe $(BIN_PATH)
+endif
VfrCompiler.o: ../Include/Common/BuildVersion.h
@@ -55,10 +61,10 @@ VfrLexer.cpp VfrLexer.h: Pccts/dlg/dlg VfrParser.dlg
Pccts/dlg/dlg -C2 -i -CC -cl VfrLexer -o . VfrParser.dlg
Pccts/antlr/antlr:
- BIN_DIR='.' $(MAKE) -C Pccts/antlr
+ $(MAKE) -C Pccts/antlr
Pccts/dlg/dlg:
- BIN_DIR='.' $(MAKE) -C Pccts/dlg
+ $(MAKE) -C Pccts/dlg
ATokenBuffer.o: Pccts/h/ATokenBuffer.cpp
$(CXX) -c $(VFR_CPPFLAGS) $(INC) $(VFR_CXXFLAGS) $? -o $@
@@ -75,7 +81,9 @@ VfrSyntax.o: VfrSyntax.cpp
clean: localClean
localClean:
- BIN_DIR='.' $(MAKE) -C Pccts/antlr clean
- BIN_DIR='.' $(MAKE) -C Pccts/dlg clean
- rm -f $(EXTRA_CLEAN_OBJECTS)
-
+ $(MAKE) -C Pccts/antlr clean
+ $(MAKE) -C Pccts/dlg clean
+ $(RM) $(EXTRA_CLEAN_OBJECTS)
+ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
+ $(RM) $(BIN_PATH)/$(APPNAME).exe
+endif
diff --git a/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile b/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
index b47c8a3..87eedf3 100644
--- a/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
+++ b/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
@@ -159,7 +159,14 @@ PCCTS_H=../h
#set.$(OBJ_EXT): $(SET)/set.c
# $(CC) $(CFLAGS) -c $(OUT_OBJ)set.$(OBJ_EXT) $(SET)/set.c
-
+ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
+ SHELL := cmd.exe
+ SEP := $(shell echo \)
+ RM := del /f /q
+else
+ SEP :=/
+ RM := rm -f
+endif
#
# UNIX (default)
@@ -213,8 +220,8 @@ set.o : $(SET)/set.c
#clean up all the intermediate files
clean:
- rm -f $(BIN_DIR)/antlr *.$(OBJ_EXT) core
+ $(RM) $(BIN_DIR)$(SEP)antlr *.$(OBJ_EXT) core
#remove everything in clean plus the PCCTS files generated
scrub:
- rm -f $(PCCTS_GEN) *.$(OBJ_EXT) core
+ $(RM) $(PCCTS_GEN) *.$(OBJ_EXT) core
diff --git a/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile b/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
index d72bee3..e56b690 100644
--- a/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
+++ b/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
@@ -114,7 +114,15 @@ PCCTS_H=../h
#
# UNIX
#
-CLANG:=$(shell $(CC) --version | grep clang)
+ifeq (Windows, $(findstring Windows,$(MAKE_HOST)))
+ SHELL := cmd.exe
+ SEP := $(shell echo \)
+ RM := del /f /q
+else
+ SEP :=/
+ RM := rm -f
+endif
+CLANG := $(findstring clang,$(shell $(CC) --version))
ifneq ($(CLANG),)
CC?=$(CLANG_BIN)clang
else ifeq ($(origin CC),default)
@@ -162,4 +170,4 @@ lint:
#clean up all the intermediate files
clean:
- rm -f $(BIN_DIR)/dlg *.$(OBJ_EXT) core
+ $(RM) $(BIN_DIR)$(SEP)dlg *.$(OBJ_EXT) core
diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py
index 5df184f..894cf2f 100644
--- a/BaseTools/Source/Python/Workspace/DscBuildData.py
+++ b/BaseTools/Source/Python/Workspace/DscBuildData.py
@@ -1,7 +1,7 @@
## @file
# This file is used to create a database used by build tool
#
-# Copyright (c) 2008 - 2020, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2008 - 2025, Intel Corporation. All rights reserved.<BR>
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
@@ -38,7 +38,9 @@ from Common.Misc import SaveFileOnChange
from Workspace.BuildClassObject import PlatformBuildClassObject, StructurePcd, PcdClassObject, ModuleBuildClassObject
from collections import OrderedDict, defaultdict
import json
+import os
import shutil
+import sys
def _IsFieldValueAnArray (Value):
Value = Value.strip()
@@ -106,9 +108,9 @@ $(APPFILE): $(APPLICATION)
'''
PcdGccMakefile = '''
-MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
+MAKEROOT ?= $(EDK_TOOLS_PATH)%sSource%sC
LIBS = -lCommon
-'''
+'''%(os.sep, os.sep)
variablePattern = re.compile(r'[\t\s]*0[xX][a-fA-F0-9]+$')
SkuIdPattern = re.compile(r'^[a-zA-Z_][a-zA-Z0-9_]*$')
@@ -231,6 +233,21 @@ class DscBuildData(PlatformBuildClassObject):
self._Clear()
self.WorkspaceDir = os.getenv("WORKSPACE") if os.getenv("WORKSPACE") else ""
self.DefaultStores = None
+ MingwBaseToolsBuild = None
+ if sys.platform == 'win32':
+ MingwBaseToolsBuild = os.getenv("BASETOOLS_MINGW_BUILD")
+ if MingwBaseToolsBuild is not None:
+ try:
+ MingwBaseToolsBuild = int(MingwBaseToolsBuild)
+ except:
+ pass
+ try:
+ MingwBaseToolsBuild = bool(MingwBaseToolsBuild)
+ except:
+ pass
+ if not isinstance(MingwBaseToolsBuild, bool):
+ MingwBaseToolsBuild = False
+ self._MingwBaseToolsBuild = MingwBaseToolsBuild
self.SkuIdMgr = SkuClass(self.SkuName, self.SkuIds)
self.UpdatePcdTypeDict()
@property
@@ -2772,7 +2789,7 @@ class DscBuildData(PlatformBuildClassObject):
def GetBuildOptionsValueList(self):
CC_FLAGS = LinuxCFLAGS
- if sys.platform == "win32":
+ if sys.platform == "win32" and not self._MingwBaseToolsBuild:
CC_FLAGS = WindowsCFLAGS
BuildOptions = OrderedDict()
for Options in self.BuildOptions:
@@ -2957,12 +2974,13 @@ class DscBuildData(PlatformBuildClassObject):
# start generating makefile
MakeApp = PcdMakefileHeader
- if sys.platform == "win32":
+ if sys.platform == "win32" and not self._MingwBaseToolsBuild:
MakeApp = MakeApp + 'APPFILE = %s\\%s.exe\n' % (self.OutputPath, PcdValueInitName) + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s\\%s.obj %s.obj\n' % (self.OutputPath, PcdValueInitName, os.path.join(self.OutputPath, PcdValueCommonName)) + 'INC = '
else:
+ AppSuffix = '.exe' if sys.platform == "win32" else ''
MakeApp = MakeApp + PcdGccMakefile
- MakeApp = MakeApp + 'APPFILE = %s/%s\n' % (self.OutputPath, PcdValueInitName) + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s/%s.o %s.o\n' % (self.OutputPath, PcdValueInitName, os.path.join(self.OutputPath, PcdValueCommonName)) + \
- 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'TOOL_INCLUDE +='
+ MakeApp = MakeApp + 'APPFILE = %s%s%s%s\n' % (self.OutputPath, os.sep, PcdValueInitName, AppSuffix) + 'APPNAME = %s\n' % (PcdValueInitName) + 'OBJECTS = %s/%s.o %s.o\n' % (self.OutputPath, PcdValueInitName, os.path.join(self.OutputPath, PcdValueCommonName)) + \
+ 'include $(MAKEROOT)/Makefiles/app.makefile\n' + 'TOOL_INCLUDE +='
IncSearchList = []
PlatformInc = OrderedDict()
@@ -3010,11 +3028,12 @@ class DscBuildData(PlatformBuildClassObject):
MakeApp += CC_FLAGS
- if sys.platform == "win32":
+ if sys.platform == "win32" and not self._MingwBaseToolsBuild:
MakeApp = MakeApp + PcdMakefileEnd
MakeApp = MakeApp + AppTarget % ("""\tcopy $(APPLICATION) $(APPFILE) /y """)
else:
- MakeApp = MakeApp + AppTarget % ("""\tcp -p $(APPLICATION) $(APPFILE) """)
+ AppSuffix = '.exe' if sys.platform == "win32" else ''
+ MakeApp = MakeApp + AppTarget % ("""\t$(CP) $(APPLICATION)%s $(APPFILE)"""%(AppSuffix))
MakeApp = MakeApp + '\n'
IncludeFileFullPaths = []
for includefile in IncludeFiles:
@@ -3057,12 +3076,21 @@ class DscBuildData(PlatformBuildClassObject):
#start building the structure pcd value tool
Messages = ''
- if sys.platform == "win32":
+ if sys.platform == "win32" and not self._MingwBaseToolsBuild:
MakeCommand = 'nmake -f %s' % (MakeFileName)
returncode, StdOut, StdErr = DscBuildData.ExecuteCommand (MakeCommand)
Messages = StdOut
else:
- MakeCommand = 'make -f %s' % (MakeFileName)
+ if sys.platform == "win32" and self._MingwBaseToolsBuild:
+ if shutil.which('mingw32-make.exe') is not None:
+ MakeCommand = 'mingw32-make -f %s' % (MakeFileName)
+ else:
+ if self._Toolchain in ('CLANGPDB', 'CLANGDWARF') and 'CLANG_HOST_BIN' in os.environ:
+ MakeCommand = '%smake -f %s' % (os.environ.get('CLANG_HOST_BIN'), MakeFileName)
+ else:
+ MakeCommand = 'make -f %s' % (MakeFileName)
+ else:
+ MakeCommand = 'make -f %s' % (MakeFileName)
returncode, StdOut, StdErr = DscBuildData.ExecuteCommand (MakeCommand)
Messages = StdErr