From 367a625a12c3469420ebab9dea40768de01971cf Mon Sep 17 00:00:00 2001
From: Olivier Martin <olivier.martin@arm.com>
Date: Fri, 17 Jan 2014 19:42:39 +0000
Subject: BaseTools: Added support to use GCC on Windows host (WINGCC)

WINGCC EDK2 toolchain enables building EDK2 with GCC toolchain
on Windows host machine.
It currently only supports ARM and AARCH64 architectures.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>
---
 BaseTools/Conf/build_rule.template | 12 ++---
 BaseTools/Conf/tools_def.template  | 97 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 103 insertions(+), 6 deletions(-)

diff --git a/BaseTools/Conf/build_rule.template b/BaseTools/Conf/build_rule.template
index 1259251..6aec930 100644
--- a/BaseTools/Conf/build_rule.template
+++ b/BaseTools/Conf/build_rule.template
@@ -133,7 +133,7 @@
         "$(CC)" $(CC_FLAGS) -o ${dst} $(INC) ${src}
         "$(SYMRENAME)" $(SYMRENAME_FLAGS) ${dst}
 
-    <Command.ARMGCC, Command.ARMLINUXGCC>
+    <Command.ARMGCC, Command.ARMLINUXGCC, Command.WINGCC>
         "$(CC)" $(CC_FLAGS) -o ${dst} $(INC) ${src}
 
 
@@ -219,7 +219,7 @@
     <Command.RVCT>
         "$(SLINK)" $(SLINK_FLAGS) ${dst} --via $(OBJECT_FILES_LIST)
     
-    <Command.RVCTCYGWIN, Command.ARMGCC, Command.ARMLINUXGCC>
+    <Command.RVCTCYGWIN, Command.ARMGCC, Command.ARMLINUXGCC, Command.WINGCC>
         # $(OBJECT_FILES_LIST) has wrong paths for cygwin
         "$(SLINK)" $(SLINK_FLAGS) ${dst} $(OBJECT_FILES)
 
@@ -243,7 +243,7 @@
         "$(DLINK)" -o ${dst} $(DLINK_FLAGS) --start-group $(DLINK_SPATH) @$(STATIC_LIBRARY_FILES_LIST) --end-group $(DLINK2_FLAGS)
         "$(OBJCOPY)" $(OBJCOPY_FLAGS) ${dst}
 
-    <Command.ARMGCC, Command.ARMLINUXGCC>
+    <Command.ARMGCC, Command.ARMLINUXGCC, Command.WINGCC>
         "$(DLINK)" -o ${dst} $(DLINK_FLAGS) --start-group $(DLINK_SPATH) $(STATIC_LIBRARY_FILES) --end-group $(DLINK2_FLAGS)
 
     <Command.RVCT>
@@ -273,7 +273,7 @@
     <Command.GCC>
         "$(DLINK)" $(DLINK_FLAGS) --start-group $(DLINK_SPATH) @$(STATIC_LIBRARY_FILES_LIST) --end-group $(DLINK2_FLAGS)
 
-    <Command.ARMGCC, Command.ARMLINUXGCC>
+    <Command.ARMGCC, Command.ARMLINUXGCC, Command.WINGCC>
         "$(DLINK)" $(DLINK_FLAGS) --start-group $(DLINK_SPATH) $(STATIC_LIBRARY_FILES) --end-group $(DLINK2_FLAGS)
 
     <Command.RVCT>
@@ -294,7 +294,7 @@
     <OutputFile>
         $(DEBUG_DIR)(+)$(MODULE_NAME).efi
 
-    <Command.MSFT, Command.INTEL, Command.RVCT, Command.ARMGCC, Command.ARMLINUXGCC>  
+    <Command.MSFT, Command.INTEL, Command.RVCT, Command.ARMGCC, Command.ARMLINUXGCC, Command.WINGCC>
         "$(GENFW)" -e $(MODULE_TYPE) -o ${dst} ${src} $(GENFW_FLAGS)
         $(CP) ${dst} $(OUTPUT_DIR)
         $(CP) ${dst} $(BIN_DIR)
@@ -353,7 +353,7 @@
     <Command.MSFT, Command.INTEL>
         Trim --asl-file -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i -i $(INC_LIST) ${src}
         "$(ASLPP)" $(ASLPP_FLAGS) $(INC) /I${s_path} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.i > $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
-        Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii 
+        Trim --source-code -l -o $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iii
         "$(ASL)" $(ASL_FLAGS) $(ASL_OUTFLAGS)${dst} $(OUTPUT_DIR)(+)${s_dir}(+)${s_base}.iiii
 
     <Command.GCC>
diff --git a/BaseTools/Conf/tools_def.template b/BaseTools/Conf/tools_def.template
index 8f5507d..f6a92d4 100644
--- a/BaseTools/Conf/tools_def.template
+++ b/BaseTools/Conf/tools_def.template
@@ -594,6 +594,12 @@ DEFINE SOURCERY_CYGWIN_TOOLS = /cygdrive/c/Program Files/CodeSourcery/Sourcery G
 #                             Required to build platforms or ACPI tables:
 #                               Intel(r) ACPI Compiler v20101013 from
 #                               http://www.acpica.org/downloads/previous_releases.php
+#   WINGCC      -win64-  Requires:
+#                             Windows GCC toolchain
+#                        Optional:
+#                             Required to build platforms or ACPI tables:
+#                               Microsoft ASL ACPI Compiler (asl.exe) v4.0.0 from
+#                                 http://download.microsoft.com/download/2/c/1/2c16c7e0-96c1-40f5-81fc-3e4bf7b65496/microsoft_asl_compiler-v4-0-0.msi
 # * Commented out - All versions of VS2005 use the same standard install directory
 #
 ####################################################################################
@@ -5908,6 +5914,97 @@ RELEASE_ARMLINUXGCC_AARCH64_ASM_FLAGS   = $(ARCHASM_FLAGS) $(PLATFORM_FLAGS)
   DEBUG_ARMLINUXGCC_AARCH64_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_AARCH64_CC_FLAGS) -Wno-address -O0
 RELEASE_ARMLINUXGCC_AARCH64_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_AARCH64_CC_FLAGS) -Wno-address -Wno-unused-but-set-variable
 
+####################################################################################
+#
+# GCC for Windows host
+#
+####################################################################################
+*_WINGCC_*_*_FAMILY          = GCC
+*_WINGCC_*_*_BUILDRULEFAMILY = WINGCC
+
+*_WINGCC_*_MAKE_PATH         = make
+*_WINGCC_*_MAKE_FLAGS        = --no-print-directory
+
+##################
+# ASL definitions
+##################
+*_WINGCC_*_ASL_PATH           = DEF(WIN_IASL_BIN)
+*_WINGCC_*_ASL_FLAGS          = -tc -li
+*_WINGCC_*_ASL_OUTFLAGS       = DEF(DEFAULT_WIN_ASL_OUTFLAGS)
+*_WINGCC_*_ASLPP_FLAGS        = $(ARCHCC_FLAGS)
+*_WINGCC_*_ASLCC_FLAGS        = $(ARCHCC_FLAGS)
+
+##################
+# ARM definitions
+##################
+
+*_WINGCC_ARM_CC_PATH         = ENV(WINGCC_ARM_PREFIX)gcc
+*_WINGCC_ARM_SLINK_PATH      = ENV(WINGCC_ARM_PREFIX)ar
+*_WINGCC_ARM_DLINK_PATH      = ENV(WINGCC_ARM_PREFIX)ld
+*_WINGCC_ARM_ASM_PATH        = ENV(WINGCC_ARM_PREFIX)as
+*_WINGCC_ARM_PP_PATH         = ENV(WINGCC_ARM_PREFIX)gcc
+*_WINGCC_ARM_VFRPP_PATH      = ENV(WINGCC_ARM_PREFIX)gcc
+*_WINGCC_ARM_ASLCC_PATH      = ENV(WINGCC_ARM_PREFIX)gcc
+*_WINGCC_ARM_ASLDLINK_PATH   = ENV(WINGCC_ARM_PREFIX)ld
+*_WINGCC_ARM_ASLPP_PATH      = ENV(WINGCC_ARM_PREFIX)gcc
+
+#
+# Use default values, or override in DSC file
+#
+*_WINGCC_ARM_ARCHCC_FLAGS    = -mthumb
+*_WINGCC_ARM_ARCHASM_FLAGS   =
+*_WINGCC_ARM_ARCHDLINK_FLAGS =
+*_WINGCC_ARM_PLATFORM_FLAGS  = -march=armv7-a
+*_WINGCC_ARM_PP_FLAGS        = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) -E -x assembler-with-cpp -include $(DEST_DIR_DEBUG)/AutoGen.h
+*_WINGCC_ARM_RC_FLAGS        = DEF(GCC_ARM_RC_FLAGS)
+*_WINGCC_ARM_VFRPP_FLAGS     = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_VFRPP_FLAGS)
+*_WINGCC_ARM_SLINK_FLAGS     = -cr
+*_WINGCC_ARM_DLINK_FLAGS     =  $(ARCHDLINK_FLAGS) DEF(GCC_ARM_AARCH64_DLINK_COMMON) --oformat=elf32-littlearm
+*_WINGCC_ARM_ASLDLINK_FLAGS  = DEF(GCC_ARM_AARCH64_DLINK_COMMON) --oformat=elf32-littlearm
+
+  DEBUG_WINGCC_ARM_ASM_FLAGS = $(ARCHASM_FLAGS) $(PLATFORM_FLAGS) -mlittle-endian -g
+RELEASE_WINGCC_ARM_ASM_FLAGS = $(ARCHASM_FLAGS) $(PLATFORM_FLAGS) -mlittle-endian
+
+  DEBUG_WINGCC_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_ARM_CC_FLAGS) -fno-stack-protector -O0 -mno-unaligned-access
+RELEASE_WINGCC_ARM_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_ARM_CC_FLAGS) -fno-stack-protector -Wno-unused-but-set-variable -mno-unaligned-access
+
+######################
+# AArch64 definitions
+######################
+# AARCH64 64bit ARM GNU/Linux GCC (ARM Architecture 64)
+
+*_WINGCC_AARCH64_CC_PATH         = ENV(WINGCC_AARCH64_PREFIX)gcc
+*_WINGCC_AARCH64_SLINK_PATH      = ENV(WINGCC_AARCH64_PREFIX)ar
+*_WINGCC_AARCH64_DLINK_PATH      = ENV(WINGCC_AARCH64_PREFIX)ld
+*_WINGCC_AARCH64_ASM_PATH        = ENV(WINGCC_AARCH64_PREFIX)as
+*_WINGCC_AARCH64_PP_PATH         = ENV(WINGCC_AARCH64_PREFIX)gcc
+*_WINGCC_AARCH64_VFRPP_PATH      = ENV(WINGCC_AARCH64_PREFIX)gcc
+*_WINGCC_AARCH64_ASLCC_PATH      = ENV(WINGCC_AARCH64_PREFIX)gcc
+*_WINGCC_AARCH64_ASLDLINK_PATH   = ENV(WINGCC_AARCH64_PREFIX)ld
+*_WINGCC_AARCH64_ASLPP_PATH      = ENV(WINGCC_AARCH64_PREFIX)gcc
+
+#
+# Use default values, or override in DSC file
+#
+*_WINGCC_AARCH64_ARCHCC_FLAGS    =
+*_WINGCC_AARCH64_ARCHASM_FLAGS   =
+*_WINGCC_AARCH64_ARCHDLINK_FLAGS =
+*_WINGCC_AARCH64_PLATFORM_FLAGS  =
+*_WINGCC_AARCH64_PP_FLAGS        = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) -E -x assembler-with-cpp -include $(DEST_DIR_DEBUG)/AutoGen.h
+*_WINGCC_AARCH64_RC_FLAGS        = DEF(GCC_ARM_RC_FLAGS)
+*_WINGCC_AARCH64_VFRPP_FLAGS     = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_VFRPP_FLAGS)
+*_WINGCC_AARCH64_SLINK_FLAGS     = -cr
+*_WINGCC_AARCH64_DLINK_FLAGS     =  $(ARCHDLINK_FLAGS) DEF(GCC_ARM_AARCH64_DLINK_COMMON) --oformat=elf64-littleaarch64
+*_WINGCC_AARCH64_ASLDLINK_FLAGS  = DEF(GCC_ARM_AARCH64_ASLDLINK_FLAGS)
+
+  DEBUG_WINGCC_AARCH64_ASM_FLAGS = $(ARCHASM_FLAGS) $(PLATFORM_FLAGS) -mlittle-endian -g
+RELEASE_WINGCC_AARCH64_ASM_FLAGS = $(ARCHASM_FLAGS) $(PLATFORM_FLAGS) -mlittle-endian
+
+  DEBUG_WINGCC_AARCH64_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_AARCH64_CC_FLAGS) -O0
+RELEASE_WINGCC_AARCH64_CC_FLAGS = $(ARCHCC_FLAGS) $(PLATFORM_FLAGS) DEF(GCC_AARCH64_CC_FLAGS) -Wno-unused-but-set-variable
+
+
+
 #################
 # ASM 16 linker defintions
 #################
-- 
1.8.5

