public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [2021-gsoc-llvm-gnumake]: proposal for building using llvm/gnumake
@ 2021-08-12  1:51 Yuqi Chen
  2021-08-13  1:18 ` 回复: [edk2-devel] " gaoliming
  0 siblings, 1 reply; 5+ messages in thread
From: Yuqi Chen @ 2021-08-12  1:51 UTC (permalink / raw)
  To: devel@edk2.groups.io


[-- Attachment #1.1.1: Type: text/plain, Size: 493 bytes --]

Hi,

I want to push my change to my codes to edk2-staging, yet it seems like I don’t have permission to do so:
[cid:image002.png@01D78EF8.2F469F30]

My mentor and I have enabled edk2 building using llvm+make and gnumake+clang in windows command prompt. The attached patch indicates changes we made to make this happen.

I also attach the readme file to go through the steps to build Basetools.

Please review our codes and thank you very much for your time.

Best regards,
Yuqi


[-- Attachment #1.1.2: Type: text/html, Size: 2805 bytes --]

[-- Attachment #1.2: B82CC5DBF47F4DCDA429C90EA2DDFCE5.png --]
[-- Type: image/png, Size: 76041 bytes --]

[-- Attachment #2: gsoc-llvm-gnumake.patch --]
[-- Type: application/octet-stream, Size: 30049 bytes --]

From 9c7ea0c8487bbb7077d069a2c449ed25152345f7 Mon Sep 17 00:00:00 2001
From: "steven.shi@intel.com" <steven.shi@intel.com>
Date: Tue, 10 Aug 2021 23:15:57 +0800
Subject: [PATCH] clang + gnumake build in windows

---
 BaseTools/Source/C/BrotliCompress/GNUmakefile |  8 +-
 BaseTools/Source/C/Common/CommonLib.h         |  9 ++
 BaseTools/Source/C/Common/MyAlloc.c           |  4 +-
 BaseTools/Source/C/Common/MyAlloc.h           |  4 +-
 BaseTools/Source/C/DevicePath/GNUmakefile     |  6 +-
 BaseTools/Source/C/EfiRom/GNUmakefile         |  6 +-
 BaseTools/Source/C/GNUmakefile                | 74 +++++++++-------
 BaseTools/Source/C/GenCrc32/GNUmakefile       |  6 +-
 BaseTools/Source/C/GenFfs/GNUmakefile         |  6 +-
 BaseTools/Source/C/GenFv/GNUmakefile          |  6 +-
 BaseTools/Source/C/GenFw/GNUmakefile          |  6 +-
 BaseTools/Source/C/GenSec/GNUmakefile         |  6 +-
 BaseTools/Source/C/LzmaCompress/GNUmakefile   |  6 +-
 BaseTools/Source/C/Makefiles/app.makefile     |  5 +-
 BaseTools/Source/C/Makefiles/header.makefile  | 84 ++++++++++++++-----
 BaseTools/Source/C/Makefiles/lib.makefile     |  6 +-
 BaseTools/Source/C/Makefiles/ms.app           |  2 +-
 BaseTools/Source/C/Makefiles/ms.common        |  9 ++
 BaseTools/Source/C/TianoCompress/GNUmakefile  |  6 +-
 BaseTools/Source/C/VfrCompile/GNUmakefile     | 29 ++++++-
 .../C/VfrCompile/Pccts/antlr/AntlrMS.mak      |  9 +-
 .../Source/C/VfrCompile/Pccts/antlr/makefile  |  7 ++
 .../Source/C/VfrCompile/Pccts/dlg/DlgMS.mak   |  9 +-
 .../Source/C/VfrCompile/Pccts/dlg/makefile    |  7 ++
 BaseTools/Source/C/VolInfo/GNUmakefile        |  6 +-
 BaseTools/Tests/GNUmakefile                   | 17 ++--
 BaseTools/Tests/TestTools.py                  |  2 +-
 BaseTools/Tests/TianoCompress.py              |  5 +-
 BaseTools/toolsetup.bat                       | 14 +++-
 edksetup.bat                                  |  7 +-
 30 files changed, 286 insertions(+), 85 deletions(-)

diff --git a/BaseTools/Source/C/BrotliCompress/GNUmakefile b/BaseTools/Source/C/BrotliCompress/GNUmakefile
index b150e5dd2b..aefada57c0 100644
--- a/BaseTools/Source/C/BrotliCompress/GNUmakefile
+++ b/BaseTools/Source/C/BrotliCompress/GNUmakefile
@@ -6,7 +6,11 @@
 #
 MAKEROOT ?= ..
 
-APPNAME = BrotliCompress
+ifeq ($(OS),Windows_NT)
+  APPNAME = BrotliCompress.exe
+else
+  APPNAME = BrotliCompress
+endif
 
 OBJECTS = \
   BrotliCompress.o \
@@ -38,4 +42,6 @@ OBJECTS = \
 include $(MAKEROOT)/Makefiles/app.makefile
 
 TOOL_INCLUDE = -I ./brotli/c/include
+ifneq ($(OS),Windows_NT)
 LIBS += -lm
+endif
\ No newline at end of file
diff --git a/BaseTools/Source/C/Common/CommonLib.h b/BaseTools/Source/C/Common/CommonLib.h
index 0f05d88db2..13b640e1cf 100644
--- a/BaseTools/Source/C/Common/CommonLib.h
+++ b/BaseTools/Source/C/Common/CommonLib.h
@@ -443,6 +443,15 @@ Returns:
 }
 #endif
 
+#ifndef __GNUC__
+#include <stdio.h>
+#include <sys/stat.h>
+#define stricmp _stricmp // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stricmp-wcsicmp
+#define getcwd _getcwd //https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/getcwd
+#define access _access //https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/access-crt
+#define fileno _fileno //https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/posix-fileno
+#endif
+
 #ifdef __GNUC__
 #include <stdio.h>
 #include <sys/stat.h>
diff --git a/BaseTools/Source/C/Common/MyAlloc.c b/BaseTools/Source/C/Common/MyAlloc.c
index d104795d46..0a1b5d9c85 100644
--- a/BaseTools/Source/C/Common/MyAlloc.c
+++ b/BaseTools/Source/C/Common/MyAlloc.c
@@ -159,7 +159,7 @@ MyCheck (
 // ////////////////////////////////////////////////////////////////////////////
 //
 //
-VOID *
+static VOID *
 MyAlloc (
   UINTN      Size,
   UINT8 File[],
@@ -402,7 +402,7 @@ MyRealloc (
 // ////////////////////////////////////////////////////////////////////////////
 //
 //
-VOID
+static VOID
 MyFree (
   VOID       *Ptr,
   UINT8 File[],
diff --git a/BaseTools/Source/C/Common/MyAlloc.h b/BaseTools/Source/C/Common/MyAlloc.h
index aff29d05ab..c4ed79ee8f 100644
--- a/BaseTools/Source/C/Common/MyAlloc.h
+++ b/BaseTools/Source/C/Common/MyAlloc.h
@@ -103,7 +103,7 @@ MyCheck (
 //
 // --*/
 //
-VOID  *
+static VOID  *
 MyAlloc (
   UINTN      Size,
   UINT8      File[],
@@ -167,7 +167,7 @@ MyRealloc (
 //
 // --*/
 //
-VOID
+static VOID
 MyFree (
   VOID       *Ptr,
   UINT8      File[],
diff --git a/BaseTools/Source/C/DevicePath/GNUmakefile b/BaseTools/Source/C/DevicePath/GNUmakefile
index 7ca08af966..b67861a3a7 100644
--- a/BaseTools/Source/C/DevicePath/GNUmakefile
+++ b/BaseTools/Source/C/DevicePath/GNUmakefile
@@ -7,7 +7,11 @@
 ARCH ?= IA32
 MAKEROOT ?= ..
 
-APPNAME = DevicePath
+ifeq ($(OS),Windows_NT)
+  APPNAME = DevicePath.exe
+else
+  APPNAME = DevicePath
+endif
 
 OBJECTS = DevicePath.o UefiDevicePathLib.o DevicePathFromText.o  DevicePathUtilities.o
 
diff --git a/BaseTools/Source/C/EfiRom/GNUmakefile b/BaseTools/Source/C/EfiRom/GNUmakefile
index 7220b2ae44..2d6b23db67 100644
--- a/BaseTools/Source/C/EfiRom/GNUmakefile
+++ b/BaseTools/Source/C/EfiRom/GNUmakefile
@@ -6,7 +6,11 @@
 #
 MAKEROOT ?= ..
 
-APPNAME = EfiRom
+ifeq ($(OS),Windows_NT)
+  APPNAME = EfiRom.exe
+else
+  APPNAME = EfiRom
+endif
 
 LIBS = -lCommon
 
diff --git a/BaseTools/Source/C/GNUmakefile b/BaseTools/Source/C/GNUmakefile
index 8c191e0c38..b4b90d017d 100644
--- a/BaseTools/Source/C/GNUmakefile
+++ b/BaseTools/Source/C/GNUmakefile
@@ -7,35 +7,47 @@
 #
 
 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
+  ifeq ($(OS),Windows_NT)
+      set_pro = $(shell set pro)
+      $(info Attempting to detect HOST_ARCH from 'set pro': $(set_pro))
+      ifneq (,$(strip $(filter (x86) %AMD64, $(set_pro))))
+        HOST_ARCH=X64
+        $(info the HOST_ARCH is X64)
+      endif
+      ifeq ($(patsubst i%86,IA32,$(uname_m)),IA32)
+        HOST_ARCH=IA32
+        $(info the HOST_ARCH is IA32)
+      endif
+  else
+      #
+      # 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
+      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.)
+    endif
   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
-  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.)
-endif
-
 export HOST_ARCH
 
 MAKEROOT = .
@@ -66,9 +78,13 @@ SUBDIRS := $(LIBRARIES) $(APPLICATIONS)
 $(LIBRARIES): $(MAKEROOT)/libs
 $(APPLICATIONS): $(LIBRARIES) $(MAKEROOT)/bin $(VFRAUTOGEN)
 
+ifeq ($(OS),Windows_NT)
+  $(APPLICATIONS): $(BASE_TOOLS_PATH)\Bin\Win32
+endif
+
 .PHONY: outputdirs
 makerootdir:
-	-mkdir -p $(MAKEROOT)
+	-$(MKDIR) $(MAKEROOT)
 
 .PHONY: subdirs $(SUBDIRS)
 subdirs: $(SUBDIRS)
diff --git a/BaseTools/Source/C/GenCrc32/GNUmakefile b/BaseTools/Source/C/GenCrc32/GNUmakefile
index fe4575d5fc..a72a1c988a 100644
--- a/BaseTools/Source/C/GenCrc32/GNUmakefile
+++ b/BaseTools/Source/C/GenCrc32/GNUmakefile
@@ -6,7 +6,11 @@
 #
 MAKEROOT ?= ..
 
-APPNAME = GenCrc32
+ifeq ($(OS),Windows_NT)
+  APPNAME = GenCrc32.exe
+else
+  APPNAME = GenCrc32
+endif
 
 LIBS = -lCommon
 
diff --git a/BaseTools/Source/C/GenFfs/GNUmakefile b/BaseTools/Source/C/GenFfs/GNUmakefile
index 3d41a5855f..4099e74260 100644
--- a/BaseTools/Source/C/GenFfs/GNUmakefile
+++ b/BaseTools/Source/C/GenFfs/GNUmakefile
@@ -6,7 +6,11 @@
 #
 MAKEROOT ?= ..
 
-APPNAME = GenFfs
+ifeq ($(OS),Windows_NT)
+  APPNAME = GenFfs.exe
+else
+  APPNAME = GenFfs
+endif
 
 OBJECTS = GenFfs.o
 
diff --git a/BaseTools/Source/C/GenFv/GNUmakefile b/BaseTools/Source/C/GenFv/GNUmakefile
index 7c7b95ba1b..eb4e9722cc 100644
--- a/BaseTools/Source/C/GenFv/GNUmakefile
+++ b/BaseTools/Source/C/GenFv/GNUmakefile
@@ -6,7 +6,11 @@
 #
 MAKEROOT ?= ..
 
-APPNAME = GenFv
+ifeq ($(OS),Windows_NT)
+  APPNAME = GenFv.exe
+else
+  APPNAME = GenFv
+endif
 
 OBJECTS = GenFv.o GenFvInternalLib.o
 
diff --git a/BaseTools/Source/C/GenFw/GNUmakefile b/BaseTools/Source/C/GenFw/GNUmakefile
index 76cda7e7a3..ce0f3684ac 100644
--- a/BaseTools/Source/C/GenFw/GNUmakefile
+++ b/BaseTools/Source/C/GenFw/GNUmakefile
@@ -6,7 +6,11 @@
 #
 MAKEROOT ?= ..
 
-APPNAME = GenFw
+ifeq ($(OS),Windows_NT)
+  APPNAME = GenFw.exe
+else
+  APPNAME = GenFw
+endif
 
 OBJECTS = GenFw.o ElfConvert.o Elf32Convert.o Elf64Convert.o
 
diff --git a/BaseTools/Source/C/GenSec/GNUmakefile b/BaseTools/Source/C/GenSec/GNUmakefile
index 9f0844c1b8..f528ed6f91 100644
--- a/BaseTools/Source/C/GenSec/GNUmakefile
+++ b/BaseTools/Source/C/GenSec/GNUmakefile
@@ -6,7 +6,11 @@
 #
 MAKEROOT ?= ..
 
-APPNAME = GenSec
+ifeq ($(OS),Windows_NT)
+  APPNAME = GenSec.exe
+else
+  APPNAME = GenSec
+endif
 
 OBJECTS = GenSec.o
 
diff --git a/BaseTools/Source/C/LzmaCompress/GNUmakefile b/BaseTools/Source/C/LzmaCompress/GNUmakefile
index c837e77823..1c7d24545e 100644
--- a/BaseTools/Source/C/LzmaCompress/GNUmakefile
+++ b/BaseTools/Source/C/LzmaCompress/GNUmakefile
@@ -6,7 +6,11 @@
 #
 MAKEROOT ?= ..
 
-APPNAME = LzmaCompress
+ifeq ($(OS),Windows_NT)
+  APPNAME = LzmaCompress.exe
+else
+  APPNAME = LzmaCompress
+endif
 
 LIBS = -lCommon
 
diff --git a/BaseTools/Source/C/Makefiles/app.makefile b/BaseTools/Source/C/Makefiles/app.makefile
index 6a2a8f5e8a..e433f6cb33 100644
--- a/BaseTools/Source/C/Makefiles/app.makefile
+++ b/BaseTools/Source/C/Makefiles/app.makefile
@@ -9,13 +9,16 @@ MAKEROOT ?= ../..
 
 include $(MAKEROOT)/Makefiles/header.makefile
 
-APPLICATION = $(MAKEROOT)/bin/$(APPNAME)
+APPLICATION = $(MAKEROOT)$(SEP)bin$(SEP)$(APPNAME)
 
 .PHONY:all
 all: $(MAKEROOT)/bin $(APPLICATION)
 
 $(APPLICATION): $(OBJECTS)
 	$(LINKER) -o $(APPLICATION) $(BUILD_LFLAGS) $(OBJECTS) -L$(MAKEROOT)/libs $(LIBS)
+ifeq ($(OS),Windows_NT)
+	$(CP) $(APPLICATION) $(EDK_TOOLS_PATH)\Bin\Win32
+endif
 
 $(OBJECTS): $(MAKEROOT)/Include/Common/BuildVersion.h
 
diff --git a/BaseTools/Source/C/Makefiles/header.makefile b/BaseTools/Source/C/Makefiles/header.makefile
index 0df728f327..e02f479476 100644
--- a/BaseTools/Source/C/Makefiles/header.makefile
+++ b/BaseTools/Source/C/Makefiles/header.makefile
@@ -8,6 +8,24 @@
 # Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
 # SPDX-License-Identifier: BSD-2-Clause-Patent
 
+ifeq ($(OS),Windows_NT)
+  SEP :=$(subst /,\,/)
+  EXE_EXT := .exe
+  MKDIR := mkdir
+  MV    := move /Y
+  RM    := del /F /S
+  CP    := copy /y
+else
+  SEP :=/
+  EXE_EXT :=
+  MKDIR := mkdir -p
+  MV    := mv -f
+  RM    := rm -f
+  CP    := cp -f
+  SED   := sed
+  TEST  := test
+endif
+
 ifndef HOST_ARCH
   #
   # If HOST_ARCH is not defined, then we use 'uname -m' to attempt
@@ -38,9 +56,12 @@ ifndef HOST_ARCH
   $(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))
+ifneq ($(OS),Windows_NT)
+  CYGWIN:=$(findstring CYGWIN, $(shell uname -s))
+  LINUX:=$(findstring Linux, $(shell uname -s))
+  DARWIN:=$(findstring Darwin, $(shell uname -s))
+endif
+
 ifeq ($(CXX), llvm)
 BUILD_CC ?= $(CLANG_BIN)clang
 BUILD_CXX ?= $(CLANG_BIN)clang++
@@ -74,32 +95,44 @@ else
 $(error Bad HOST_ARCH)
 endif
 
-INCLUDE = $(TOOL_INCLUDE) -I $(MAKEROOT) -I $(MAKEROOT)/Include/Common -I $(MAKEROOT)/Include/ -I $(MAKEROOT)/Include/IndustryStandard -I $(MAKEROOT)/Common/ -I .. -I . $(ARCH_INCLUDE)
-BUILD_CPPFLAGS = $(INCLUDE)
+INCLUDES = $(TOOL_INCLUDE) -I $(MAKEROOT) -I $(MAKEROOT)/Include/Common -I $(MAKEROOT)/Include/ -I $(MAKEROOT)/Include/IndustryStandard -I $(MAKEROOT)/Common/ -I .. -I . $(ARCH_INCLUDE) -I "$(INCLUDE)"
+BUILD_CPPFLAGS = $(INCLUDES)
 
 # keep EXTRA_OPTFLAGS last
 BUILD_OPTFLAGS = -O2 $(EXTRA_OPTFLAGS)
 
 ifeq ($(DARWIN),Darwin)
-# assume clang or clang compatible flags on OS X
-BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror \
--Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -g
-else
-ifeq ($(CXX), llvm)
-BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -fwrapv \
--fno-delete-null-pointer-checks -Wall -Werror \
--Wno-deprecated-declarations -Wno-self-assign \
--Wno-unused-result -nostdlib -g
+  # assume clang or clang compatible flags on OS X
+  BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -Wall -Werror \
+  -Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -g
 else
-BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -fwrapv \
--fno-delete-null-pointer-checks -Wall -Werror \
--Wno-deprecated-declarations -Wno-stringop-truncation -Wno-restrict \
--Wno-unused-result -nostdlib -g
-endif
+  ifeq ($(CXX), llvm)
+    ifeq ($(OS),Windows_NT)
+      BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -fwrapv \
+      -fno-delete-null-pointer-checks -Wall -Werror \
+      -Wno-deprecated-declarations -Wno-self-assign \
+      -Wno-unused-result -nostdlib -Wno-unused-function -g -m32
+    else
+      BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -fwrapv \
+      -fno-delete-null-pointer-checks -Wall -Werror \
+      -Wno-deprecated-declarations -Wno-self-assign \
+      -Wno-unused-result -nostdlib -g
+    endif
+  else
+    BUILD_CFLAGS = -MD -fshort-wchar -fno-strict-aliasing -fwrapv \
+    -fno-delete-null-pointer-checks -Wall -Werror \
+    -Wno-deprecated-declarations -Wno-stringop-truncation -Wno-restrict \
+    -Wno-unused-result -nostdlib -g
+  endif
 endif
 ifeq ($(CXX), llvm)
-BUILD_LFLAGS =
-BUILD_CXXFLAGS = -Wno-deprecated-register -Wno-unused-result
+  ifeq ($(OS),Windows_NT)
+    BUILD_LFLAGS = -m32
+    BUILD_CXXFLAGS = -Wno-deprecated-register -Wno-unused-result -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -m32
+  else
+    BUILD_LFLAGS =
+    BUILD_CXXFLAGS = -Wno-deprecated-register -Wno-unused-result
+  endif
 else
 BUILD_LFLAGS =
 BUILD_CXXFLAGS = -Wno-unused-result
@@ -131,7 +164,12 @@ BUILD_LFLAGS += $(EXTRA_LDFLAGS)
 all:
 
 $(MAKEROOT)/libs:
-	mkdir $(MAKEROOT)/libs
+	$(MKDIR) $(MAKEROOT)$(SEP)libs
 
 $(MAKEROOT)/bin:
-	mkdir $(MAKEROOT)/bin
+	$(MKDIR) $(MAKEROOT)$(SEP)bin
+
+ifeq ($(OS),Windows_NT)
+  $(BASE_TOOLS_PATH)\Bin\Win32:
+		-$(MKDIR) $(BASE_TOOLS_PATH)\Bin\Win32
+endif
diff --git a/BaseTools/Source/C/Makefiles/lib.makefile b/BaseTools/Source/C/Makefiles/lib.makefile
index 2577c15380..28aaab5bed 100644
--- a/BaseTools/Source/C/Makefiles/lib.makefile
+++ b/BaseTools/Source/C/Makefiles/lib.makefile
@@ -7,7 +7,11 @@
 
 include $(MAKEROOT)/Makefiles/header.makefile
 
-LIBRARY = $(MAKEROOT)/libs/lib$(LIBNAME).a
+ifeq ($(OS),Windows_NT)
+  LIBRARY = $(MAKEROOT)/libs/$(LIBNAME).lib
+else
+  LIBRARY = $(MAKEROOT)/libs/lib$(LIBNAME).a
+endif
 
 all: $(MAKEROOT)/libs $(LIBRARY)
 
diff --git a/BaseTools/Source/C/Makefiles/ms.app b/BaseTools/Source/C/Makefiles/ms.app
index aecae37396..0dd0daf6f7 100644
--- a/BaseTools/Source/C/Makefiles/ms.app
+++ b/BaseTools/Source/C/Makefiles/ms.app
@@ -13,7 +13,7 @@ $(APPLICATION) : $(OBJECTS)
 	-@if not exist $(BIN_PATH) mkdir $(BIN_PATH)
 	$(LD) /nologo /debug /OPT:REF /OPT:ICF=10 /incremental:no /nodefaultlib:libc.lib /out:$@ $(LIBS) $**
 
-$(OBJECTS) : $(SOURCE_PATH)\Include\Common\BuildVersion.h
+#$(OBJECTS) : $(SOURCE_PATH)\Include\Common\BuildVersion.h
 
 .PHONY:clean
 .PHONY:cleanall
diff --git a/BaseTools/Source/C/Makefiles/ms.common b/BaseTools/Source/C/Makefiles/ms.common
index b2dbcf376c..ef58303189 100644
--- a/BaseTools/Source/C/Makefiles/ms.common
+++ b/BaseTools/Source/C/Makefiles/ms.common
@@ -60,3 +60,12 @@ INC = $(INC) -I . -I $(SOURCE_PATH)\Include -I $(ARCH_INCLUDE) -I $(SOURCE_PATH)
 CFLAGS = $(CFLAGS) /nologo /Zi /c /O2 /MT /W4 /WX /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE
 CPPFLAGS = $(CPPFLAGS) /EHsc /nologo /Zi /c /O2 /MT /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE
 
+!IF "$(CLANG_BUILD)"=="TRUE"
+CC = "$(CLANG_BIN)\clang-cl.exe"
+CXX = "$(CLANG_BIN)\clang-cl.exe"
+AR = "$(CLANG_BIN)\llvm-lib.exe"
+LD = "$(CLANG_BIN)\lld-link.exe"
+
+CFLAGS = $(CFLAGS) /nologo /Zi /c /O2 /MT /W4 /WX /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /w -m32
+CPPFLAGS = $(CPPFLAGS) /EHsc /nologo /Zi /c /O2 /MT /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /w -m32
+!ENDIF
diff --git a/BaseTools/Source/C/TianoCompress/GNUmakefile b/BaseTools/Source/C/TianoCompress/GNUmakefile
index d164d37b3d..07cb4b4119 100644
--- a/BaseTools/Source/C/TianoCompress/GNUmakefile
+++ b/BaseTools/Source/C/TianoCompress/GNUmakefile
@@ -6,7 +6,11 @@
 #
 MAKEROOT ?= ..
 
-APPNAME = TianoCompress
+ifeq ($(OS),Windows_NT)
+  APPNAME = TianoCompress.exe
+else
+  APPNAME = TianoCompress
+endif
 
 LIBS = -lCommon
 
diff --git a/BaseTools/Source/C/VfrCompile/GNUmakefile b/BaseTools/Source/C/VfrCompile/GNUmakefile
index fc329944b9..d663f50e84 100644
--- a/BaseTools/Source/C/VfrCompile/GNUmakefile
+++ b/BaseTools/Source/C/VfrCompile/GNUmakefile
@@ -7,7 +7,11 @@
 
 MAKEROOT ?= ..
 
-APPNAME = VfrCompile
+ifeq ($(OS),Windows_NT)
+  APPNAME = VfrCompile.exe
+else
+  APPNAME = VfrCompile
+endif
 
 LIBS = -lCommon
 
@@ -17,7 +21,11 @@ TOOL_INCLUDE = -I Pccts/h
 OBJECTS = AParser.o DLexerBase.o ATokenBuffer.o EfiVfrParser.o VfrLexer.o VfrSyntax.o \
           VfrFormPkg.o VfrError.o VfrUtilityLib.o VfrCompiler.o
 ifeq ($(CXX), llvm)
-VFR_CPPFLAGS = -Wno-deprecated-register -DPCCTS_USE_NAMESPACE_STD $(BUILD_CPPFLAGS)
+  ifeq ($(OS),Windows_NT)
+    VFR_CPPFLAGS = -Wno-deprecated-register -DPCCTS_USE_NAMESPACE_STD $(BUILD_CPPFLAGS) -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -m32
+  else
+    VFR_CPPFLAGS = -Wno-deprecated-register -DPCCTS_USE_NAMESPACE_STD $(BUILD_CPPFLAGS)
+  endif
 else
 VFR_CPPFLAGS = -DPCCTS_USE_NAMESPACE_STD $(BUILD_CPPFLAGS)
 endif
@@ -25,7 +33,11 @@ endif
 VFR_CXXFLAGS = $(BUILD_OPTFLAGS)
 
 # keep EXTRA_LDFLAGS last
+ifeq ($(OS),Windows_NT)
+VFR_LFLAGS = $(EXTRA_LDFLAGS) -m32
+else
 VFR_LFLAGS = $(EXTRA_LDFLAGS)
+endif
 
 LINKER = $(BUILD_CXX)
 
@@ -35,13 +47,16 @@ MAKEROOT ?= ../..
 
 include $(MAKEROOT)/Makefiles/header.makefile
 
-APPLICATION = $(MAKEROOT)/bin/$(APPNAME)
+APPLICATION = $(MAKEROOT)$(SEP)bin$(SEP)$(APPNAME)
 
 .PHONY:all
 all: $(MAKEROOT)/bin $(APPLICATION)
 
 $(APPLICATION): $(OBJECTS)
 	$(LINKER) -o $(APPLICATION) $(VFR_LFLAGS) $(OBJECTS) -L$(MAKEROOT)/libs $(LIBS)
+ifeq ($(OS),Windows_NT)
+	$(CP) $(APPLICATION) $(EDK_TOOLS_PATH)\Bin\Win32
+endif
 
 VfrCompiler.o: ../Include/Common/BuildVersion.h
 
@@ -54,10 +69,18 @@ VfrLexer.cpp VfrLexer.h: Pccts/dlg/dlg VfrParser.dlg
 	Pccts/dlg/dlg -C2 -i -CC -cl VfrLexer -o . VfrParser.dlg
 
 Pccts/antlr/antlr:
+ifeq ($(OS),Windows_NT)
+	set BIN_DIR='.'&& $(MAKE) -C Pccts/antlr
+else
 	BIN_DIR='.' $(MAKE) -C Pccts/antlr
+endif
 
 Pccts/dlg/dlg:
+ifeq ($(OS),Windows_NT)
+	set BIN_DIR='.'&& $(MAKE) -C Pccts/dlg
+else
 	BIN_DIR='.' $(MAKE) -C Pccts/dlg
+endif
 
 ATokenBuffer.o: Pccts/h/ATokenBuffer.cpp
 	$(BUILD_CXX) -c $(VFR_CPPFLAGS) $(INC) $(VFR_CXXFLAGS) $? -o $@
diff --git a/BaseTools/Source/C/VfrCompile/Pccts/antlr/AntlrMS.mak b/BaseTools/Source/C/VfrCompile/Pccts/antlr/AntlrMS.mak
index b30a73bb74..51ccb446dc 100644
--- a/BaseTools/Source/C/VfrCompile/Pccts/antlr/AntlrMS.mak
+++ b/BaseTools/Source/C/VfrCompile/Pccts/antlr/AntlrMS.mak
@@ -17,7 +17,14 @@ SET=$(PCCTS_HOME)\support\set
 CC = cl
 CFLAGS = /nologo -I "." -I "$(PCCTS_H)" -I "$(SET)" -D "USER_ZZSYN" -D "PC" \
         -D "ZZLEXBUFSIZE=65536"  /D "LONGFILENAMES" /Zi /W3 -D__USE_PROTOS /wd4700 \
-         /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE 
+         /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE
+
+!IF "$(CLANG_BUILD)"=="TRUE"
+CC = "$(CLANG_BIN)\clang-cl.exe"
+CFLAGS = /nologo -I "." -I "$(PCCTS_H)" -I "$(SET)" -D "USER_ZZSYN" -D "PC" \
+        -D "ZZLEXBUFSIZE=65536"  /D "LONGFILENAMES" /Zi /W3 -D__USE_PROTOS /wd4700 \
+         /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE  /w -m32
+!ENDIF
 
 ANTLR_OBJS = antlr.obj scan.obj err.obj bits.obj build.obj fset2.obj \
             fset.obj gen.obj globals.obj hash.obj lex.obj main.obj \
diff --git a/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile b/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
index 559b1c99f1..6751e06961 100644
--- a/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
+++ b/BaseTools/Source/C/VfrCompile/Pccts/antlr/makefile
@@ -174,7 +174,14 @@ ANTLR=${BIN_DIR}/antlr
 DLG=${BIN_DIR}/dlg
 OBJ_EXT=o
 OUT_OBJ = -o
+
+ifeq ($(OS),Windows_NT)
+BUILD_CFLAGS= $(COPT) -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN $(COTHER) -DZZLEXBUFSIZE=65536 \
+        -D__USE_PROTOS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DPCCTS_USE_STDARG -m32
+else
 BUILD_CFLAGS= $(COPT) -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN $(COTHER) -DZZLEXBUFSIZE=65536
+endif
+
 BUILD_CPPFLAGS=
 #
 # SGI Users, use this CFLAGS
diff --git a/BaseTools/Source/C/VfrCompile/Pccts/dlg/DlgMS.mak b/BaseTools/Source/C/VfrCompile/Pccts/dlg/DlgMS.mak
index 2714308d4f..fe9724ff96 100644
--- a/BaseTools/Source/C/VfrCompile/Pccts/dlg/DlgMS.mak
+++ b/BaseTools/Source/C/VfrCompile/Pccts/dlg/DlgMS.mak
@@ -17,7 +17,14 @@ SET=$(PCCTS_HOME)\support\set
 CC = cl
 CFLAGS = /nologo -I "." -I "$(PCCTS_H)" -I "$(SET)" -D "USER_ZZSYN" -D "PC" \
         -D "ZZLEXBUFSIZE=65536"  /D "LONGFILENAMES" /W3 /Zi \
-        /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE 
+        /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE
+
+!IF "$(CLANG_BUILD)"=="TRUE"
+CC = "$(CLANG_BIN)\clang-cl.exe"
+CFLAGS = /nologo -I "." -I "$(PCCTS_H)" -I "$(SET)" -D "USER_ZZSYN" -D "PC" \
+        -D "ZZLEXBUFSIZE=65536"  /D "LONGFILENAMES" /W3 /Zi \
+        /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D PCCTS_USE_STDARG /w -m32
+!ENDIF
 
 DLG_OBJS = dlg_p.obj dlg_a.obj main.obj err.obj support.obj \
            output.obj relabel.obj automata.obj
diff --git a/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile b/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
index 5a3561edec..8e6616a5b4 100644
--- a/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
+++ b/BaseTools/Source/C/VfrCompile/Pccts/dlg/makefile
@@ -122,7 +122,14 @@ endif
 COPT=-O
 ANTLR=${BIN_DIR}/antlr
 DLG=${BIN_DIR}/dlg
+
+ifeq ($(OS),Windows_NT)
+BUILD_CFLAGS= $(COPT) -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN -DZZLEXBUFSIZE=65536 \
+        -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DPCCTS_USE_STDARG -m32
+else
 BUILD_CFLAGS= $(COPT) -I. -I$(SET) -I$(PCCTS_H) -DUSER_ZZSYN -DZZLEXBUFSIZE=65536
+endif
+
 BUILD_CPPFLAGS=
 OBJ_EXT=o
 OUT_OBJ = -o
diff --git a/BaseTools/Source/C/VolInfo/GNUmakefile b/BaseTools/Source/C/VolInfo/GNUmakefile
index 9795b28add..c80f1d5e51 100644
--- a/BaseTools/Source/C/VolInfo/GNUmakefile
+++ b/BaseTools/Source/C/VolInfo/GNUmakefile
@@ -6,7 +6,11 @@
 #
 MAKEROOT ?= ..
 
-APPNAME = VolInfo
+ifeq ($(OS),Windows_NT)
+  APPNAME = VolInfo.exe
+else
+  APPNAME = VolInfo
+endif
 
 OBJECTS = VolInfo.o
 
diff --git a/BaseTools/Tests/GNUmakefile b/BaseTools/Tests/GNUmakefile
index 1cb77f84b1..870f1d73a8 100644
--- a/BaseTools/Tests/GNUmakefile
+++ b/BaseTools/Tests/GNUmakefile
@@ -7,9 +7,14 @@
 
 all: test
 
-test:
-	@if command -v $(PYTHON_COMMAND) >/dev/null 1; then $(PYTHON_COMMAND) RunTests.py; else python RunTests.py; fi
-
-clean:
-	find . -name '*.pyc' -exec rm '{}' ';'
-
+ifeq ($(OS),Windows_NT)
+  test:
+		python RunTests.py
+  clean:
+		echo ToDo
+else
+  test:
+		@if command -v $(PYTHON_COMMAND) >/dev/null 1; then $(PYTHON_COMMAND) RunTests.py; else python RunTests.py; fi
+  clean:
+		find . -name '*.pyc' -exec rm '{}' ';'
+endif
\ No newline at end of file
diff --git a/BaseTools/Tests/TestTools.py b/BaseTools/Tests/TestTools.py
index 1099fd4eea..5cad2b0150 100644
--- a/BaseTools/Tests/TestTools.py
+++ b/BaseTools/Tests/TestTools.py
@@ -135,7 +135,7 @@ class BaseToolsTest(unittest.TestCase):
         return open(os.path.join(self.testDir, fileName), mode)
 
     def ReadTmpFile(self, fileName):
-        f = open(self.GetTmpFilePath(fileName), 'r')
+        f = open(self.GetTmpFilePath(fileName), 'r', encoding="utf8")
         data = f.read()
         f.close()
         return data
diff --git a/BaseTools/Tests/TianoCompress.py b/BaseTools/Tests/TianoCompress.py
index 685968b18f..2b592a9106 100644
--- a/BaseTools/Tests/TianoCompress.py
+++ b/BaseTools/Tests/TianoCompress.py
@@ -21,7 +21,10 @@ class Tests(TestTools.BaseToolsTest):
 
     def setUp(self):
         TestTools.BaseToolsTest.setUp(self)
-        self.toolName = 'TianoCompress'
+        if sys.platform in ('win32', 'win64'):
+            self.toolName = 'TianoCompress.exe'
+        else:
+            self.toolName = 'TianoCompress'
 
     def testHelp(self):
         result = self.RunTool('--help', logFile='help')
diff --git a/BaseTools/toolsetup.bat b/BaseTools/toolsetup.bat
index 58fd26a4b5..cacd41d3e0 100755
--- a/BaseTools/toolsetup.bat
+++ b/BaseTools/toolsetup.bat
@@ -72,6 +72,11 @@ if /I "%1"=="/?" goto Usage
     set VSTool=VS2012
     goto loop
   )
+  if /I "%1"=="clang" (
+    shift
+    set CLANG_BUILD=TRUE
+    goto loop
+  )
   if "%1"=="" goto setup_workspace
   if exist %1 (
     if not defined BASE_TOOLS_PATH (
@@ -195,6 +200,11 @@ if defined VS2019 (
 ) else if defined VS2012 (
   call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat VS2012
   call %EDK_TOOLS_PATH%\get_vsvars.bat VS2012
+) else if defined CLANG_BUILD (
+    @if exist "C:\Program Files\LLVM\bin\clang.exe" (
+        @set "CLANG_BIN=C:\Program Files\LLVM\bin\"
+        @echo   Found LLVM, setting CLANG_BIN environment variable to C:\Program Files\LLVM\bin\
+    )
 ) else (
   call %EDK_TOOLS_PATH%\set_vsprefix_envs.bat
   call %EDK_TOOLS_PATH%\get_vsvars.bat
@@ -472,7 +482,7 @@ goto end
 
 :Usage
   @echo.
-  echo  Usage: "%0 [-h | -help | --help | /h | /help | /?] [ Rebuild | ForceRebuild ] [Reconfig] [base_tools_path [edk_tools_path]] [VS2019] [VS2017] [VS2015] [VS2013] [VS2012]"
+  echo  Usage: "%0 [-h | -help | --help | /h | /help | /?] [ Rebuild | ForceRebuild ] [Reconfig] [base_tools_path [edk_tools_path]] [VS2019] [VS2017] [VS2015] [VS2013] [VS2012] [clang]"
   @echo.
   @echo         base_tools_path   BaseTools project path, BASE_TOOLS_PATH will be set to this path.
   @echo         edk_tools_path    EDK_TOOLS_PATH will be set to this path.
@@ -486,6 +496,7 @@ goto end
   @echo         VS2015            Set the env for VS2015 build.
   @echo         VS2017            Set the env for VS2017 build.
   @echo         VS2019            Set the env for VS2019 build.
+  @echo         clang             Set the env for clang-cl build.
   @echo.
 
 :end
@@ -498,5 +509,6 @@ set VS2015=
 set VS2013=
 set VS2012=
 set VSTool=
+set CLANG_BUILD=
 popd
 
diff --git a/edksetup.bat b/edksetup.bat
index 7ad137bb3e..537d1f7733 100755
--- a/edksetup.bat
+++ b/edksetup.bat
@@ -150,11 +150,12 @@ if /I "%1"=="VS2017" shift
 if /I "%1"=="VS2015" shift
 if /I "%1"=="VS2013" shift
 if /I "%1"=="VS2012" shift
+if /I "%1"=="clang" shift
 if "%1"=="" goto end
 
 :Usage
   @echo.
-  @echo  Usage: "%0 [-h | -help | --help | /h | /help | /?] [Reconfig] [Rebuild] [ForceRebuild] [VS2019] [VS2017] [VS2015] [VS2013] [VS2012]"
+  @echo  Usage: "%0 [-h | -help | --help | /h | /help | /?] [Reconfig] [Rebuild] [ForceRebuild] [VS2019] [VS2017] [VS2015] [VS2013] [VS2012] [clang]"
   @echo.
   @echo         Reconfig       Reinstall target.txt, tools_def.txt and build_rule.txt.
   @echo         Rebuild        Perform incremental rebuild of BaseTools binaries.
@@ -164,6 +165,10 @@ if "%1"=="" goto end
   @echo         VS2015         Set the env for VS2015 build.
   @echo         VS2017         Set the env for VS2017 build.
   @echo         VS2019         Set the env for VS2019 build.
+  @echo         clang          Set the env for clang-cl build.
+  @echo.
+  @echo  Unix-like Usage: "gnumake.exe -C BaseTools CXX=llvm"
+  @echo         Use clang + gunmake build base tools in windows.
   @echo.
   @echo  Note that target.template, tools_def.template and build_rules.template
   @echo  will only be copied to target.txt, tools_def.txt and build_rule.txt
-- 
2.28.0


[-- Attachment #3: readme.txt --]
[-- Type: text/plain, Size: 9388 bytes --]

ReadME:

Summary:
1.	Building .exes for the C-language BaseTools using LLVM/Clang.
2.	Switching from nmake to make for LLVM/Clang based builds.

Owner: tianocroe

timeline:
2021/06 - 2021/07: building .exes for the C-language BaseTools using LLVM/Clang
2021/07 - 2021/08: Switching from nmake to make for LLVM/Clang based builds.

links to related materials: 
none

Steps to use:
*********************************************************************************************************************************************************************************************
In windows:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Clang + make in windows command prompt:
Setup:
1.	Download and install LLVM 11 from https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/LLVM-11.0.0-win64.exe. After install, please verify the clang version is 11.0.0. as below.
	C:\>"C:\Program Files\LLVM\bin\clang.exe" -v
	clang version 11.0.0
	Target: x86_64-pc-windows-msvc
	Thread model: posix
	InstalledDir: C:\Program Files\LLVM\bin

2.	Download and install nasm and iasl:
		Download nasm compiler http://www.nasm.us/, copy nasm.exe to C:\nasm\ directory.
		Download iasl compiler https://acpica.org/downloads, copy iasl.exe to C:\ASL directory.

3.	Download the latest version Python from https://www.python.org/downloads/ and install it

4.	Download Visual Studio 2015 or 2017 or 2019 and install it, make sure nmake.exe, cl.exe, lib.exe and link.exe be ready.

5.	In windows command prompt: (please replace %USERNAME% with username in your computer)
	Can directly download the windows version gnumake binary from conan center. Below are the download steps:
	C:\Users\%USERNAME%\edk2>C:\Python38\python.exe -m pip install conan
	C:\Users\%USERNAME%\edk2>set PATH=%PATH%;C:\Python38\Scripts\
	C:\Users\%USERNAME%\edk2>conan download make/4.2.1:0a420ff5c47119e668867cdb51baff0eca1fdb68
	C:\Users\%USERNAME%\edk2>C:\Users\%USERNAME%\.conan\data\make\4.2.1\_\_\package\0a420ff5c47119e668867cdb51baff0eca1fdb68\bin\gnumake.exe --version
	GNU Make 4.2.1
	Built for Windows32
	(please check the version)

6.	In windows command prompt: (please replace %USERNAME% with username in your computer)
	C:\Users\%USERNAME%>git clone https://github.com/tianocore/edk2.git edk2
	C:\Users\%USERNAME%\edk2>git submodule update --init
	C:\Users\%USERNAME%\edk2>git submodule update --recursive
	C:\Users\%USERNAME%\edk2>git submodule sync --recursive

To Use:
	C:\Users\%USERNAME%\edk2>git clean -dfx (use this command if you have download it before, else please ignore thie command)
	C:\Users\%USERNAME%\edk2>edksetup.bat
	C:\Users\%USERNAME%\edk2>C:\Users\%USERNAME%\.conan\data\make\4.2.1\_\_\package\0a420ff5c47119e668867cdb51baff0eca1fdb68\bin\gnumake.exe -w -C BaseTools CXX=llvm
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Clang + nmake in windows command prompt:
Setup:
1.	Download and install LLVM 11 from https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/LLVM-11.0.0-win64.exe. After install, please verify the clang version is 11.0.0. as below.
	C:\>"C:\Program Files\LLVM\bin\clang.exe" -v
	clang version 11.0.0
	Target: x86_64-pc-windows-msvc
	Thread model: posix
	InstalledDir: C:\Program Files\LLVM\bin

2.	Download and install nasm and iasl:
		Download nasm compiler http://www.nasm.us/, copy nasm.exe to C:\nasm\ directory.
		Download iasl compiler https://acpica.org/downloads, copy iasl.exe to C:\ASL directory.

3.	Download the latest version Python from https://www.python.org/downloads/ and install it

4.	Download Visual Studio 2015 or 2017 or 2019 and install it, make sure nmake.exe, cl.exe, lib.exe and link.exe be ready.

5.	In windows command prompt: (please replace %USERNAME% with username in your computer)
	C:\Users\%USERNAME%>git clone https://github.com/tianocore/edk2.git edk2
	C:\Users\%USERNAME%\edk2>git submodule update --init
	C:\Users\%USERNAME%\edk2>git submodule update --recursive
	C:\Users\%USERNAME%\edk2>git submodule sync --recursive

To Use:
	C:\Users\%USERNAME%\edk2>git clean -dfx (use this command if you have download it before, else please ignore thie command)
	C:\Users\%USERNAME%\edk2>edksetup.bat ForceRebuild clang
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# MSVC + nmake in windows command prompt:
Setup:
1.	Download and install LLVM 11 from https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/LLVM-11.0.0-win64.exe. After install, please verify the clang version is 11.0.0. as below.
	C:\>"C:\Program Files\LLVM\bin\clang.exe" -v
	clang version 11.0.0
	Target: x86_64-pc-windows-msvc
	Thread model: posix
	InstalledDir: C:\Program Files\LLVM\bin

2.	Download and install nasm and iasl:
		Download nasm compiler http://www.nasm.us/, copy nasm.exe to C:\nasm\ directory.
		Download iasl compiler https://acpica.org/downloads, copy iasl.exe to C:\ASL directory.

3.	Download the latest version Python from https://www.python.org/downloads/ and install it

4.	Download Visual Studio 2015 or 2017 or 2019 and install it, make sure nmake.exe, cl.exe, lib.exe and link.exe be ready.

5.	In windows command prompt: (please replace %USERNAME% with username in your computer)
	C:\Users\%USERNAME%>git clone https://github.com/tianocore/edk2.git edk2
	C:\Users\%USERNAME%\edk2>git submodule update --init
	C:\Users\%USERNAME%\edk2>git submodule update --recursive
	C:\Users\%USERNAME%\edk2>git submodule sync --recursive

To Use:
	C:\Users\%USERNAME%\edk2>git clean -dfx (use this command if you have download it before, else please ignore thie command)
	C:\Users\%USERNAME%\edk2>edksetup.bat ForceRebuild

*********************************************************************************************************************************************************************************************
In Linux:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# GCC + make:
Setup:
1.	Download and install LLVM 11:
		Create a folder called llvm and open it,
		%username%:~/llvm$ wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz
		%username%:~/llvm$ tar -xvf clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz
		%username%:~/llvm$ ./clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04/bin/clang -v
			clang version 11.0.0 (https://github.com/llvm/llvm-project.git 0160ad802e899c2922bc9b29564080c22eb0908c)
			Target: x86_64-unknown-linux-gnu
			Thread model: posix

2.	Download and install nasm and iasl:
		%username%:~/edk2-3$ sudo apt-get install build-essential git uuid-dev iasl nasm

3.	Download the latest version Python from https://www.python.org/downloads/ and install it

4.	Init:
	%USERNAME%:~$ git clone https://github.com/tianocore/edk2.git edk2
	%USERNAME%:~/edk2$ git submodule update --init
	%USERNAME%:~/edk2$ git submodule update --recursive
	%USERNAME%:~/edk2$ git submodule sync --recursive

To Use:
	%USERNAME%:~/edk2$ git clean -dfx	(use this command if you have download it before, else please ignore thie command)
	%USERNAME%:~/edk2$ source edksetup.sh
	%USERNAME%:~/edk2$ make -C BaseTools/ 
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
# Clang + make:
Setup:
1.	Download and install LLVM 11:
		Create a folder called llvm and open it,
		%username%:~/llvm$ wget https://github.com/llvm/llvm-project/releases/download/llvmorg-11.0.0/clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz
		%username%:~/llvm$ tar -xvf clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04.tar.xz
		%username%:~/llvm$ ./clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04/bin/clang -v
			clang version 11.0.0 (https://github.com/llvm/llvm-project.git 0160ad802e899c2922bc9b29564080c22eb0908c)
			Target: x86_64-unknown-linux-gnu
			Thread model: posix

2.	Download and install nasm and iasl:
		%username%:~/edk2-3$ sudo apt-get install build-essential git uuid-dev iasl nasm

3.	Download the latest version Python from https://www.python.org/downloads/ and install it

4.	Init:
	%USERNAME%:~$ git clone https://github.com/tianocore/edk2.git edk2
	%USERNAME%:~/edk2$ git submodule update --init
	%USERNAME%:~/edk2$ git submodule update --recursive
	%USERNAME%:~/edk2$ git submodule sync --recursive

To Use:
	Open file edk2
	%USERNAME%:~/edk2$ git clean -dfx	(use this command if you have download it before, else please ignore thie command)
	%USERNAME%:~/edk2$ export CLANG_BIN=~/llvm/clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04/bin/ 
	%USERNAME%:~/edk2$ source edksetup.sh
	%USERNAME%:~/edk2$ make -C BaseTools/ CXX=llvm
	







		


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* 回复: [edk2-devel] [2021-gsoc-llvm-gnumake]: proposal for building using llvm/gnumake
  2021-08-12  1:51 [2021-gsoc-llvm-gnumake]: proposal for building using llvm/gnumake Yuqi Chen
@ 2021-08-13  1:18 ` gaoliming
  2021-08-13 13:33   ` Steven Shi
  0 siblings, 1 reply; 5+ messages in thread
From: gaoliming @ 2021-08-13  1:18 UTC (permalink / raw)
  To: devel, yuqi.chen


[-- Attachment #1.1: Type: text/plain, Size: 983 bytes --]

Yuqi:

 On Windows, can Clang + make combination drop the dependency of Visual
studio? If I don’t install Visual studio 2015 or 2017, I only install LLVM,
can I fully compile BaseTools and Edk2 code?

 

Thanks

Liming

发件人: devel@edk2.groups.io <devel@edk2.groups.io> 代表 Yuqi Chen
发送时间: 2021年8月12日 9:52
收件人: devel@edk2.groups.io
主题: [edk2-devel] [2021-gsoc-llvm-gnumake]: proposal for building using
llvm/gnumake

 


Hi,


 


I want to push my change to my codes to edk2-staging, yet it seems like I
don’t have permission to do so:





 


My mentor and I have enabled edk2 building using llvm+make and gnumake+clang
in windows command prompt. The attached patch indicates changes we made to
make this happen.


 


I also attach the readme file to go through the steps to build Basetools.


 


Please review our codes and thank you very much for your time.


 


Best regards,


Yuqi


 




[-- Attachment #1.2: Type: text/html, Size: 6328 bytes --]

[-- Attachment #2: image001.png --]
[-- Type: image/png, Size: 76041 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [edk2-devel] [2021-gsoc-llvm-gnumake]: proposal for building using llvm/gnumake
  2021-08-13  1:18 ` 回复: [edk2-devel] " gaoliming
@ 2021-08-13 13:33   ` Steven Shi
  2021-08-13 19:50     ` Pedro Falcato
  0 siblings, 1 reply; 5+ messages in thread
From: Steven Shi @ 2021-08-13 13:33 UTC (permalink / raw)
  To: devel@edk2.groups.io, gaoliming@byosoft.com.cn,
	yuqi.chen@mail.utoronto.ca


[-- Attachment #1.1: Type: text/plain, Size: 4555 bytes --]

Liming,
The MSVC is required only because the Windows SDK Universal C runtime (UCRT) library depends on the MSVC.  Please see the dependency description here: “When you install Visual C++, Visual Studio setup installs the subset of the Windows 10 SDK required to use the UCRT.” https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-160.

If the MSVC is not installed, the ucrt will complain cannot find the msvc header files. Below is an example:
C:\Program Files\LLVM\bin\clang  -c  -I .. -I ../Include/Common -I ../Include/ -I ../Include/IndustryStandard -I ../Common/ -I .. -I . -I ../Include/X64/ -I "" -MD -fshort-wchar -fno-strict-aliasing -fwrapv -fno-delete-null-pointer-checks -Wall -Werror -Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -Wno-unused-function -g -m32 -O2  BasePeCoff.c -o BasePeCoff.o
In file included from BasePeCoff.c:13:
In file included from ../Common\CommonLib.h:14:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\assert.h:12:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt.h:10:10: fatal error: 'vcruntime.h' file not
      found
#include <vcruntime.h>
         ^~~~~~~~~~~~~
1 error generated.



BTW, the compiler dependency requirement also exists in Linux side. Below is the Linux GCC CRT library example. Although I build with clang, it still needs link the crt libraries in GCC installation. Below is an example:
$ /home/jshi19/llvm/clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04/bin/clang -o ../bin/LzmaCompress   LzmaCompress.o Sdk/C/Alloc.o Sdk/C/LzFind.o Sdk/C/LzmaDec.o Sdk/C/LzmaEnc.o Sdk/C/7zFile.o Sdk/C/7zStream.o Sdk/C/Bra86.o -L../libs -lCommon -###
clang version 11.0.0 (https://github.com/llvm/llvm-project.git 0160ad802e899c2922bc9b29564080c22eb0908c)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/jshi19/llvm/clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04/bin
"/usr/bin/ld" "-z" "relro" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf_x86_64" "-dynamic-linker" "/lib64/ld-linux-x86-64.so.2" "-o" "../bin/LzmaCompress" "/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o" "/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crti.o" "/usr/lib/gcc/x86_64-linux-gnu/10/crtbegin.o" "-L../libs" "-L/usr/lib/gcc/x86_64-linux-gnu/10" "-L/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/lib/../lib64" "-L/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu" "-L/lib/x86_64-linux-gnu" "-L/lib/../lib64" "-L/usr/lib/x86_64-linux-gnu" "-L/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/lib" "-L/usr/lib/gcc/x86_64-linux-gnu/10/../../.." "-L/home/jshi19/llvm/clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04/bin/../lib" "-L/lib" "-L/usr/lib" "LzmaCompress.o" "Sdk/C/Alloc.o" "Sdk/C/LzFind.o" "Sdk/C/LzmaDec.o" "Sdk/C/LzmaEnc.o" "Sdk/C/7zFile.o" "Sdk/C/7zStream.o" "Sdk/C/Bra86.o" "-lCommon" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/usr/lib/gcc/x86_64-linux-gnu/10/crtend.o" "/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crtn.o"




Thanks

Steven Shi
Intel\SATG\SFP\FIA (Firmware Infrastructure Automation)


From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of gaoliming
Sent: Friday, August 13, 2021 9:18 AM
To: devel@edk2.groups.io; yuqi.chen@mail.utoronto.ca
Subject: 回复: [edk2-devel] [2021-gsoc-llvm-gnumake]: proposal for building using llvm/gnumake

Yuqi:
 On Windows, can Clang + make combination drop the dependency of Visual studio? If I don’t install Visual studio 2015 or 2017, I only install LLVM, can I fully compile BaseTools and Edk2 code?

Thanks
Liming
发件人: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io<mailto:devel@edk2.groups.io>> 代表 Yuqi Chen
发送时间: 2021年8月12日 9:52
收件人: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
主题: [edk2-devel] [2021-gsoc-llvm-gnumake]: proposal for building using llvm/gnumake

Hi,

I want to push my change to my codes to edk2-staging, yet it seems like I don’t have permission to do so:
[cid:image001.png@01D79030.EEE25800]

My mentor and I have enabled edk2 building using llvm+make and gnumake+clang in windows command prompt. The attached patch indicates changes we made to make this happen.

I also attach the readme file to go through the steps to build Basetools.

Please review our codes and thank you very much for your time.

Best regards,
Yuqi



[-- Attachment #1.2: Type: text/html, Size: 12674 bytes --]

[-- Attachment #2: image001.png --]
[-- Type: image/png, Size: 76041 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [edk2-devel] [2021-gsoc-llvm-gnumake]: proposal for building using llvm/gnumake
  2021-08-13 13:33   ` Steven Shi
@ 2021-08-13 19:50     ` Pedro Falcato
  2021-08-17 14:04       ` Steven Shi
  0 siblings, 1 reply; 5+ messages in thread
From: Pedro Falcato @ 2021-08-13 19:50 UTC (permalink / raw)
  To: edk2-devel-groups-io, steven.shi
  Cc: gaoliming@byosoft.com.cn, yuqi.chen@mail.utoronto.ca


[-- Attachment #1.1: Type: text/plain, Size: 5265 bytes --]

Hi Steven,

Have you considered using the --rtlib switch? It would eliminate the
dependency on the system's libgcc, crtbegin/end.o and crti/o.o, for most
systems. I don't know exactly how the build system works but I assume
there's some way to force a compiler flag.

Best regards,

Pedro

On Fri, 13 Aug 2021 at 14:34, Steven Shi <steven.shi@intel.com> wrote:

> Liming,
>
> The MSVC is required only because the Windows SDK Universal C runtime
> (UCRT) library depends on the MSVC.  Please see the dependency description
> here: “When you install Visual C++, Visual Studio setup installs the subset
> of the Windows 10 SDK required to use the UCRT.”
> https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-160.
>
>
>
>
> If the MSVC is not installed, the ucrt will complain cannot find the msvc
> header files. Below is an example:
>
> C:\Program Files\LLVM\bin\clang  -c  -I .. -I ../Include/Common -I
> ../Include/ -I ../Include/IndustryStandard -I ../Common/ -I .. -I . -I
> ../Include/X64/ -I "" -MD -fshort-wchar -fno-strict-aliasing -fwrapv
> -fno-delete-null-pointer-checks -Wall -Werror -Wno-deprecated-declarations
> -Wno-self-assign -Wno-unused-result -nostdlib -Wno-unused-function -g -m32
> -O2  BasePeCoff.c -o BasePeCoff.o
>
> In file included from BasePeCoff.c:13:
>
> In file included from ../Common\CommonLib.h:14:
>
> In file included from C:\Program Files (x86)\Windows
> Kits\10\Include\10.0.10240.0\ucrt\assert.h:12:
>
> C:\Program Files (x86)\Windows
> Kits\10\Include\10.0.10240.0\ucrt\corecrt.h:10:10: fatal error:
> 'vcruntime.h' file not
>
>       found
>
> #include <vcruntime.h>
>
>          ^~~~~~~~~~~~~
>
> 1 error generated.
>
>
>
>
>
>
>
> BTW, the compiler dependency requirement also exists in Linux side. Below
> is the Linux GCC CRT library example. Although I build with clang, it still
> needs link the crt libraries in GCC installation. Below is an example:
>
> $
> /home/jshi19/llvm/clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04/bin/clang
> -o ../bin/LzmaCompress   LzmaCompress.o Sdk/C/Alloc.o Sdk/C/LzFind.o
> Sdk/C/LzmaDec.o Sdk/C/LzmaEnc.o Sdk/C/7zFile.o Sdk/C/7zStream.o
> Sdk/C/Bra86.o -L../libs -lCommon -###
>
> clang version 11.0.0 (https://github.com/llvm/llvm-project.git
> 0160ad802e899c2922bc9b29564080c22eb0908c)
>
> Target: x86_64-unknown-linux-gnu
>
> Thread model: posix
>
> InstalledDir:
> /home/jshi19/llvm/clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04/bin
>
> "/usr/bin/ld" "-z" "relro" "--hash-style=gnu" "--eh-frame-hdr" "-m"
> "elf_x86_64" "-dynamic-linker" "/lib64/ld-linux-x86-64.so.2" "-o"
> "../bin/LzmaCompress"
> "/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o"
> "/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crti.o"
> "/usr/lib/gcc/x86_64-linux-gnu/10/crtbegin.o" "-L../libs"
> "-L/usr/lib/gcc/x86_64-linux-gnu/10"
> "-L/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/lib/../lib64"
> "-L/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu"
> "-L/lib/x86_64-linux-gnu" "-L/lib/../lib64" "-L/usr/lib/x86_64-linux-gnu"
> "-L/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/lib"
> "-L/usr/lib/gcc/x86_64-linux-gnu/10/../../.."
> "-L/home/jshi19/llvm/clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04/bin/../lib"
> "-L/lib" "-L/usr/lib" "LzmaCompress.o" "Sdk/C/Alloc.o" "Sdk/C/LzFind.o"
> "Sdk/C/LzmaDec.o" "Sdk/C/LzmaEnc.o" "Sdk/C/7zFile.o" "Sdk/C/7zStream.o"
> "Sdk/C/Bra86.o" "-lCommon" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
> "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed"
> "/usr/lib/gcc/x86_64-linux-gnu/10/crtend.o"
> "/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crtn.o"
>
>
>
>
>
>
>
>
>
> Thanks
>
>
>
> *Steven Shi*
>
> *Intel\SATG\SFP\FIA (Firmware Infrastructure Automation)*
>
>
>
>
>
> *From:* devel@edk2.groups.io <devel@edk2.groups.io> * On Behalf Of *
> gaoliming
> *Sent:* Friday, August 13, 2021 9:18 AM
> *To:* devel@edk2.groups.io; yuqi.chen@mail.utoronto.ca
> *Subject:* 回复: [edk2-devel] [2021-gsoc-llvm-gnumake]: proposal for
> building using llvm/gnumake
>
>
>
> Yuqi:
>
>  On Windows, can Clang + make combination drop the dependency of Visual
> studio? If I don’t install Visual studio 2015 or 2017, I only install
> LLVM, can I fully compile BaseTools and Edk2 code?
>
>
>
> Thanks
>
> Liming
>
> *发件人**:* devel@edk2.groups.io <devel@edk2.groups.io> *代表 *Yuqi Chen
> *发送时间:* 2021年8月12日 9:52
> *收件人:* devel@edk2.groups.io
> *主题:* [edk2-devel] [2021-gsoc-llvm-gnumake]: proposal for building using
> llvm/gnumake
>
>
> *Hi,*   *I want to push my change to my codes to edk2-staging, yet it
> seems like I don’t have permission to do so:*
>
>   *My mentor and I have enabled edk2 building using llvm+make and
> gnumake+clang in windows command prompt. The attached patch indicates
> changes we made to make this happen.*
>
>
> I also attach the readme file to go through the steps to build Basetools.
>   *Please review our codes and thank you very much for your time.*   Best
> regards, Yuqi
>
>
>
> 
>
>

-- 
Pedro Falcato

[-- Attachment #1.2: Type: text/html, Size: 11536 bytes --]

[-- Attachment #2: image001.png --]
[-- Type: image/png, Size: 76041 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [edk2-devel] [2021-gsoc-llvm-gnumake]: proposal for building using llvm/gnumake
  2021-08-13 19:50     ` Pedro Falcato
@ 2021-08-17 14:04       ` Steven Shi
  0 siblings, 0 replies; 5+ messages in thread
From: Steven Shi @ 2021-08-17 14:04 UTC (permalink / raw)
  To: Pedro Falcato, edk2-devel-groups-io
  Cc: gaoliming@byosoft.com.cn, yuqi.chen@mail.utoronto.ca


[-- Attachment #1.1: Type: text/plain, Size: 6074 bytes --]

Hi Pedro,
Your suggestion is interesting. We will try to enhance the clang Linux build and remove the libgcc dependency in the future.

This patch change is for a project of Google Summer of Code 2021, which is to build BaseTools with clang + gnu make in windows. We hope to focus the windows part only in this project. The project’s code check-in deadline is August 24th.  We plan to only check-in to edk2-staging right now because of edk2-stable202108 release code freezing. Yuqi will send out another version code review soon.



Thanks

Steven Shi
Intel\SATG\SFP\FIA (Firmware Infrastructure Automation)


From: Pedro Falcato <pedro.falcato@gmail.com>
Sent: Saturday, August 14, 2021 3:50 AM
To: edk2-devel-groups-io <devel@edk2.groups.io>; Shi, Steven <steven.shi@intel.com>
Cc: gaoliming@byosoft.com.cn; yuqi.chen@mail.utoronto.ca
Subject: Re: [edk2-devel] [2021-gsoc-llvm-gnumake]: proposal for building using llvm/gnumake

Hi Steven,

Have you considered using the --rtlib switch? It would eliminate the dependency on the system's libgcc, crtbegin/end.o and crti/o.o, for most systems. I don't know exactly how the build system works but I assume there's some way to force a compiler flag.

Best regards,

Pedro

On Fri, 13 Aug 2021 at 14:34, Steven Shi <steven.shi@intel.com<mailto:steven.shi@intel.com>> wrote:
Liming,
The MSVC is required only because the Windows SDK Universal C runtime (UCRT) library depends on the MSVC.  Please see the dependency description here: “When you install Visual C++, Visual Studio setup installs the subset of the Windows 10 SDK required to use the UCRT.” https://docs.microsoft.com/en-us/cpp/c-runtime-library/crt-library-features?view=msvc-160.

If the MSVC is not installed, the ucrt will complain cannot find the msvc header files. Below is an example:
C:\Program Files\LLVM\bin\clang  -c  -I .. -I ../Include/Common -I ../Include/ -I ../Include/IndustryStandard -I ../Common/ -I .. -I . -I ../Include/X64/ -I "" -MD -fshort-wchar -fno-strict-aliasing -fwrapv -fno-delete-null-pointer-checks -Wall -Werror -Wno-deprecated-declarations -Wno-self-assign -Wno-unused-result -nostdlib -Wno-unused-function -g -m32 -O2  BasePeCoff.c -o BasePeCoff.o
In file included from BasePeCoff.c:13:
In file included from ../Common\CommonLib.h:14:
In file included from C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\assert.h:12:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt\corecrt.h:10:10: fatal error: 'vcruntime.h' file not
      found
#include <vcruntime.h>
         ^~~~~~~~~~~~~
1 error generated.



BTW, the compiler dependency requirement also exists in Linux side. Below is the Linux GCC CRT library example. Although I build with clang, it still needs link the crt libraries in GCC installation. Below is an example:
$ /home/jshi19/llvm/clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04/bin/clang -o ../bin/LzmaCompress   LzmaCompress.o Sdk/C/Alloc.o Sdk/C/LzFind.o Sdk/C/LzmaDec.o Sdk/C/LzmaEnc.o Sdk/C/7zFile.o Sdk/C/7zStream.o Sdk/C/Bra86.o -L../libs -lCommon -###
clang version 11.0.0 (https://github.com/llvm/llvm-project.git 0160ad802e899c2922bc9b29564080c22eb0908c)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/jshi19/llvm/clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04/bin
"/usr/bin/ld" "-z" "relro" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf_x86_64" "-dynamic-linker" "/lib64/ld-linux-x86-64.so.2" "-o" "../bin/LzmaCompress" "/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o" "/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crti.o" "/usr/lib/gcc/x86_64-linux-gnu/10/crtbegin.o" "-L../libs" "-L/usr/lib/gcc/x86_64-linux-gnu/10" "-L/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/lib/../lib64" "-L/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu" "-L/lib/x86_64-linux-gnu" "-L/lib/../lib64" "-L/usr/lib/x86_64-linux-gnu" "-L/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/lib" "-L/usr/lib/gcc/x86_64-linux-gnu/10/../../.." "-L/home/jshi19/llvm/clang+llvm-11.0.0-x86_64-linux-gnu-ubuntu-20.04/bin/../lib" "-L/lib" "-L/usr/lib" "LzmaCompress.o" "Sdk/C/Alloc.o" "Sdk/C/LzFind.o" "Sdk/C/LzmaDec.o" "Sdk/C/LzmaEnc.o" "Sdk/C/7zFile.o" "Sdk/C/7zStream.o" "Sdk/C/Bra86.o" "-lCommon" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/usr/lib/gcc/x86_64-linux-gnu/10/crtend.o" "/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crtn.o"




Thanks

Steven Shi
Intel\SATG\SFP\FIA (Firmware Infrastructure Automation)


From: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io<mailto:devel@edk2.groups.io>> On Behalf Of gaoliming
Sent: Friday, August 13, 2021 9:18 AM
To: devel@edk2.groups.io<mailto:devel@edk2.groups.io>; yuqi.chen@mail.utoronto.ca<mailto:yuqi.chen@mail.utoronto.ca>
Subject: 回复: [edk2-devel] [2021-gsoc-llvm-gnumake]: proposal for building using llvm/gnumake

Yuqi:
 On Windows, can Clang + make combination drop the dependency of Visual studio? If I don’t install Visual studio 2015 or 2017, I only install LLVM, can I fully compile BaseTools and Edk2 code?

Thanks
Liming
发件人: devel@edk2.groups.io<mailto:devel@edk2.groups.io> <devel@edk2.groups.io<mailto:devel@edk2.groups.io>> 代表 Yuqi Chen
发送时间: 2021年8月12日 9:52
收件人: devel@edk2.groups.io<mailto:devel@edk2.groups.io>
主题: [edk2-devel] [2021-gsoc-llvm-gnumake]: proposal for building using llvm/gnumake

Hi,

I want to push my change to my codes to edk2-staging, yet it seems like I don’t have permission to do so:
[cid:image001.png@01D793B1.43CD2010]

My mentor and I have enabled edk2 building using llvm+make and gnumake+clang in windows command prompt. The attached patch indicates changes we made to make this happen.

I also attach the readme file to go through the steps to build Basetools.

Please review our codes and thank you very much for your time.

Best regards,
Yuqi




--
Pedro Falcato

[-- Attachment #1.2: Type: text/html, Size: 18909 bytes --]

[-- Attachment #2: image001.png --]
[-- Type: image/png, Size: 76041 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-08-17 14:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-12  1:51 [2021-gsoc-llvm-gnumake]: proposal for building using llvm/gnumake Yuqi Chen
2021-08-13  1:18 ` 回复: [edk2-devel] " gaoliming
2021-08-13 13:33   ` Steven Shi
2021-08-13 19:50     ` Pedro Falcato
2021-08-17 14:04       ` Steven Shi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox