--- /dev/null
+/*++\r
+\r
+Copyright (c) 2004 - 2007, Intel Corporation \r
+All rights reserved. This program and the accompanying materials \r
+are licensed and made available under the terms and conditions of the BSD License \r
+which accompanies this distribution. The full text of the license may be found at \r
+http://opensource.org/licenses/bsd-license.php \r
+ \r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
+\r
+Module Name:\r
+ \r
+ ProcessDsc.c\r
+\r
+Abstract:\r
+\r
+ Main module for the ProcessDsc utility.\r
+\r
+--*/\r
+\r
+#include <windows.h> // for GetShortPathName()\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include <ctype.h>\r
+#include <stdarg.h>\r
+#include <direct.h> // for _mkdir()\r
+#include <errno.h>\r
+#include <stdlib.h> // for getenv()\r
+#include "DSCFile.h"\r
+#include "FWVolume.h"\r
+#include "Exceptions.h"\r
+#include "Common.h"\r
+\r
+#include "EfiUtilityMsgs.h"\r
+#include "TianoBind.h"\r
+//\r
+// Disable warning for while(1) code\r
+//\r
+#pragma warning(disable : 4127)\r
+//\r
+// Disable warning for unreferenced function parameters\r
+//\r
+#pragma warning(disable : 4100)\r
+\r
+extern int errno;\r
+\r
+#define PROGRAM_NAME "ProcessDsc"\r
+\r
+//\r
+// Common symbol name definitions. For example, the user can reference\r
+// $(BUILD_DIR) in their DSC file and we will expand it for them (usually).\r
+// I've defined the equivalents here in case we want to change the name the\r
+// user references, in which case we just change the string value here and\r
+// our code still works.\r
+//\r
+#define BUILD_DIR "BUILD_DIR"\r
+#define EFI_SOURCE "EFI_SOURCE"\r
+#define DEST_DIR "DEST_DIR"\r
+#define SOURCE_DIR "SOURCE_DIR"\r
+#define LIB_DIR "LIB_DIR"\r
+#define BIN_DIR "BIN_DIR"\r
+#define OUT_DIR "OUT_DIR"\r
+#define INF_FILENAME "INF_FILENAME"\r
+#define SOURCE_RELATIVE_PATH "SOURCE_RELATIVE_PATH"\r
+#define SOURCE_BASE_NAME "SOURCE_BASE_NAME"\r
+#define SOURCE_FILE_NAME "SOURCE_FILE_NAME" // c:\FullPath\File.c\r
+#define PROCESSOR "PROCESSOR"\r
+#define FV "FV"\r
+#define BASE_NAME "BASE_NAME"\r
+#define GUID "GUID"\r
+#define FILE_GUID "FILE_GUID"\r
+#define COMPONENT_TYPE_FILE "FILE"\r
+#define BUILD_TYPE "BUILD_TYPE"\r
+#define FFS_EXT "FFS_EXT" // FV_EXT is deprecated -- extension of FFS file\r
+#define MAKEFILE_NAME "MAKEFILE_NAME" // name of component's output makefile\r
+#define PLATFORM "PLATFORM" // for more granularity\r
+#define PACKAGE_FILENAME "PACKAGE_FILENAME"\r
+#define PACKAGE "PACKAGE"\r
+#define PACKAGE_TAG "PACKAGE_TAG" // alternate name to PACKAGE\r
+#define SHORT_NAMES "SHORT_NAMES" // for 8.3 names of symbols\r
+#define APRIORI "APRIORI" // to add to apriori list\r
+#define OPTIONAL_COMPONENT "OPTIONAL" // define as non-zero for optional INF files\r
+#define SOURCE_SELECT "SOURCE_SELECT" // say SOURCE_SELECT=smm,common to select INF sources\r
+#define NONFFS_FV "NONFFS_FV" // for non-FFS FV such as working & spare block FV\r
+#define SKIP_FV_NULL "SKIP_FV_NULL" // define as nonzero to not build components with FV=NULL\r
+#define SOURCE_COMPILE_TYPE "SOURCE_COMPILE_TYPE" // to build a source using a custom build section in the DSC file\r
+#define SOURCE_FILE_EXTENSION "SOURCE_FILE_EXTENSION"\r
+#define COMPILE_SELECT "COMPILE_SELECT"\r
+#define SOURCE_OVERRIDE_PATH "SOURCE_OVERRIDE_PATH" // get source files from here first\r
+#define MAKEFILE_OUT_SECTION_NAME "makefile.out"\r
+#define COMMON_SECTION_NAME "common" // shared files or functionality\r
+#define NMAKE_SECTION_NAME "nmake"\r
+#define SOURCES_SECTION_NAME "sources"\r
+#define COMPONENTS_SECTION_NAME "components"\r
+#define INCLUDE_SECTION_NAME "includes"\r
+#define DEFINES_SECTION_NAME "defines"\r
+#define LIBRARIES_SECTION_NAME "libraries"\r
+#define LIBRARIES_PLATFORM_SECTION_NAME "libraries.platform"\r
+#define MAKEFILE_SECTION_NAME "makefile"\r
+#define COMPONENT_TYPE "component_type"\r
+#define PLATFORM_STR "\\platform\\" // to determine EFI_SOURCE\r
+#define MAKEFILE_OUT_NAME "makefile.out" // if not specified on command line\r
+#define MODULE_MAKEFILE_NAME "module.mak" // record all module makefile targets\r
+#define MODULE_NAME_FILE "module.list" // record all module names defined in the dsc file\r
+#define GLOBAL_LINK_LIB_NAME "CompilerStub" // Lib added in link option, maybe removed in the future\r
+#define MODULE_BASE_NAME_WIDTH 25 // Width for module name output\r
+\r
+//\r
+// When a symbol is defined as "NULL", it gets saved in the symbol table as a 0-length\r
+// string. Use this macro to detect if a symbol has been defined this way.\r
+//\r
+#define IS_NULL_SYMBOL_VALUE(var) ((var != NULL) && (strlen (var) == 0))\r
+\r
+//\r
+// Defines for file types\r
+//\r
+#define FILETYPE_UNKNOWN 0\r
+#define FILETYPE_C 1\r
+#define FILETYPE_ASM 2\r
+#define FILETYPE_S 3\r
+#define FILETYPE_VFR 4\r
+#define FILETYPE_INC 5\r
+#define FILETYPE_H 6\r
+#define FILETYPE_I 7\r
+\r
+\r
+typedef struct {\r
+ INT8 *Extension; // file extension\r
+ INT8 *BuiltExtension;\r
+ INT8 FileFlags;\r
+ int FileType;\r
+} FILETYPE;\r
+\r
+//\r
+// Define masks for the FileFlags field\r
+//\r
+#define FILE_FLAG_INCLUDE 0x01\r
+#define FILE_FLAG_SOURCE 0x02\r
+\r
+//\r
+// This table describes a from-to list of files. For\r
+// example, when a ".c" is built, it results in a ".obj" file.\r
+//\r
+static const FILETYPE mFileTypes[] = {\r
+ {\r
+ ".c",\r
+ ".obj",\r
+ FILE_FLAG_SOURCE,\r
+ FILETYPE_C\r
+ },\r
+ {\r
+ ".asm",\r
+ ".obj",\r
+ FILE_FLAG_SOURCE,\r
+ FILETYPE_ASM\r
+ },\r
+ {\r
+ ".s",\r
+ ".obj",\r
+ FILE_FLAG_SOURCE,\r
+ FILETYPE_S\r
+ },\r
+ {\r
+ ".vfr",\r
+ ".obj",\r
+ FILE_FLAG_SOURCE,\r
+ FILETYPE_VFR\r
+ }, // actually *.vfr -> *.c -> *.obj\r
+ {\r
+ ".h",\r
+ NULL,\r
+ FILE_FLAG_INCLUDE,\r
+ FILETYPE_H\r
+ },\r
+ {\r
+ ".inc",\r
+ NULL,\r
+ FILE_FLAG_INCLUDE,\r
+ FILETYPE_INC\r
+ },\r
+ {\r
+ ".i",\r
+ NULL,\r
+ FILE_FLAG_INCLUDE,\r
+ FILETYPE_I\r
+ },\r
+ {\r
+ NULL,\r
+ NULL,\r
+ 0,\r
+ 0\r
+ }\r
+};\r
+\r
+//\r
+// Structure to split up a file into its different parts.\r
+//\r
+typedef struct {\r
+ INT8 Drive[3];\r
+ INT8 *Path;\r
+ INT8 *BaseName;\r
+ INT8 *Extension;\r
+ int ExtensionCode;\r
+} FILE_NAME_PARTS;\r
+\r
+//\r
+// Maximum length for any line in any file after symbol expansion\r
+//\r
+#define MAX_EXP_LINE_LEN (MAX_LINE_LEN * 2)\r
+\r
+//\r
+// Linked list to keep track of all symbols\r
+//\r
+typedef struct _SYMBOL {\r
+ struct _SYMBOL *Next;\r
+ int Type; // local or global symbol\r
+ INT8 *Name;\r
+ INT8 *Value;\r
+} SYMBOL;\r
+\r
+//\r
+// Define new SYMBOL list to record all module name used in the platform.dsc file.\r
+//\r
+SYMBOL *gModuleList = NULL;\r
+\r
+//\r
+// This structure is used to save globals\r
+//\r
+struct {\r
+ INT8 *DscFilename;\r
+ SYMBOL *Symbol;\r
+ INT8 MakefileName[MAX_PATH]; // output makefile name\r
+ INT8 XRefFileName[MAX_PATH];\r
+ INT8 GuidDatabaseFileName[MAX_PATH];\r
+ INT8 ModuleMakefileName[MAX_PATH];\r
+ FILE *MakefileFptr;\r
+ FILE *ModuleMakefileFptr;\r
+ SYMBOL *ModuleList;\r
+ SYMBOL *OutdirList;\r
+ UINT32 Verbose;\r
+} gGlobals;\r
+\r
+//\r
+// This gets dumped to the head of makefile.out\r
+//\r
+static const INT8 *MakefileHeader[] = {\r
+ "#/*++",\r
+ "#",\r
+ "# DO NOT EDIT",\r
+ "# File auto-generated by build utility",\r
+ "#",\r
+ "# Module Name:",\r
+ "#",\r
+ "# makefile",\r
+ "#",\r
+ "# Abstract:",\r
+ "#",\r
+ "# Auto-generated makefile for building of EFI components/libraries",\r
+ "#",\r
+ "#--*/",\r
+ "",\r
+ NULL\r
+};\r
+\r
+//\r
+// Function prototypes\r
+//\r
+static\r
+int\r
+ProcessOptions (\r
+ int Argc,\r
+ INT8 *Argv[]\r
+ );\r
+\r
+static\r
+void\r
+Usage (\r
+ VOID\r
+ );\r
+\r
+static\r
+INT8 *\r
+StripLine (\r
+ INT8 *Line\r
+ );\r
+\r
+static\r
+STATUS\r
+ParseGuidDatabaseFile (\r
+ INT8 *FileName\r
+ );\r
+\r
+#define DSC_SECTION_TYPE_COMPONENTS 0\r
+#define DSC_SECTION_TYPE_LIBRARIES 1\r
+#define DSC_SECTION_TYPE_PLATFORM_LIBRARIES 2\r
+\r
+static\r
+int\r
+ProcessSectionComponents (\r
+ DSC_FILE *DscFile,\r
+ int DscSectionType,\r
+ int Instance\r
+ );\r
+static\r
+int\r
+ProcessComponentFile (\r
+ DSC_FILE *DscFile,\r
+ INT8 *Line,\r
+ int DscSectionType,\r
+ int Instance\r
+ );\r
+static\r
+int\r
+ProcessIncludeFiles (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr\r
+ );\r
+static\r
+\r
+int\r
+ProcessIncludeFilesSingle (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr,\r
+ INT8 *SectionName\r
+ );\r
+\r
+//\r
+// Mode flags for processing source files\r
+//\r
+#define SOURCE_MODE_BUILD_COMMANDS 0x01\r
+#define SOURCE_MODE_SOURCE_FILES 0x02\r
+\r
+static\r
+int\r
+ProcessSourceFiles (\r
+ DSC_FILE *DSCFile,\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr,\r
+ UINT32 Mode\r
+ );\r
+\r
+static\r
+int\r
+ProcessSourceFilesSection (\r
+ DSC_FILE *DSCFile,\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr,\r
+ INT8 *SectionName,\r
+ UINT32 Mode\r
+ );\r
+\r
+static\r
+int\r
+ProcessObjects (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr\r
+ );\r
+\r
+static\r
+int\r
+ProcessObjectsSingle (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr,\r
+ INT8 *SectionName\r
+ );\r
+\r
+static\r
+int\r
+ProcessLibs (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr\r
+ );\r
+\r
+static\r
+int\r
+ProcessLibsSingle (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr,\r
+ INT8 *SectionName\r
+ );\r
+\r
+static\r
+int\r
+ProcessIncludesSection (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr\r
+ );\r
+\r
+static\r
+int\r
+ProcessIncludesSectionSingle (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr,\r
+ INT8 *SectionName\r
+ );\r
+\r
+static\r
+int\r
+ProcessINFNMakeSection (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr\r
+ );\r
+\r
+static\r
+int\r
+ProcessINFDefinesSection (\r
+ DSC_FILE *ComponentFile\r
+ );\r
+\r
+static\r
+int\r
+ProcessINFDefinesSectionSingle (\r
+ DSC_FILE *ComponentFile,\r
+ INT8 *SectionName\r
+ );\r
+\r
+static\r
+int\r
+ProcessSectionLibraries (\r
+ DSC_FILE *DscFile,\r
+ long Offset\r
+ );\r
+\r
+static\r
+int\r
+ProcessDSCDefinesSection (\r
+ DSC_FILE *DscFile\r
+ );\r
+\r
+static\r
+int\r
+SetSymbolType (\r
+ INT8 *SymbolName,\r
+ INT8 Type\r
+ );\r
+\r
+static\r
+int\r
+RemoveLocalSymbols (\r
+ VOID\r
+ );\r
+\r
+static\r
+int\r
+RemoveFileSymbols (\r
+ VOID\r
+ );\r
+\r
+static\r
+int\r
+RemoveSymbol (\r
+ INT8 *Name,\r
+ INT8 SymbolType\r
+ );\r
+\r
+static\r
+int\r
+SetFileExtension (\r
+ INT8 *FileName,\r
+ INT8 *Extension\r
+ );\r
+\r
+static\r
+int\r
+GetSourceFileType (\r
+ INT8 *FileName\r
+ );\r
+\r
+static\r
+int\r
+IsIncludeFile (\r
+ INT8 *FileName\r
+ );\r
+\r
+static\r
+int\r
+WriteCompileCommands (\r
+ DSC_FILE *DscFile,\r
+ FILE *MakeFptr,\r
+ INT8 *FileName,\r
+ INT8 *Processor\r
+ );\r
+\r
+static\r
+int\r
+WriteCommonMakefile (\r
+ DSC_FILE *DscFile,\r
+ FILE *MakeFptr,\r
+ INT8 *Processor\r
+ );\r
+\r
+static\r
+int\r
+WriteComponentTypeBuildCommands (\r
+ DSC_FILE *DscFile,\r
+ FILE *MakeFptr,\r
+ INT8 *SectionName\r
+ );\r
+\r
+static\r
+void\r
+StripTrailingSpaces (\r
+ INT8 *Str\r
+ );\r
+\r
+static\r
+void\r
+FreeFileParts (\r
+ FILE_NAME_PARTS *FP\r
+ );\r
+\r
+static\r
+FILE_NAME_PARTS *\r
+GetFileParts (\r
+ INT8 *FileName\r
+ );\r
+\r
+static\r
+SYMBOL *\r
+FreeSymbols (\r
+ SYMBOL *Syms\r
+ );\r
+\r
+static\r
+int\r
+GetEfiSource (\r
+ VOID\r
+ );\r
+\r
+static\r
+int\r
+CreatePackageFile (\r
+ DSC_FILE *DSCFile\r
+ );\r
+\r
+static\r
+INT8 *\r
+BuiltFileExtension (\r
+ INT8 *SourceFileName\r
+ );\r
+\r
+static\r
+void\r
+SmartFree (\r
+ SMART_FILE *SmartFile\r
+ );\r
+\r
+static \r
+int\r
+AddModuleName (\r
+ SYMBOL **SymbolList,\r
+ INT8 *ModuleName,\r
+ INT8 *InfName\r
+ );\r
+\r
+/*****************************************************************************/\r
+int\r
+main (\r
+ int Argc,\r
+ INT8 *Argv[]\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ \r
+ Main utility entry point.\r
+\r
+Arguments:\r
+\r
+ Argc - Standard app entry point args.\r
+ Argv - Standard app entry point args.\r
+\r
+Returns:\r
+\r
+ 0 if successful\r
+ non-zero otherwise\r
+\r
+--*/\r
+{\r
+ int i;\r
+ DSC_FILE DSCFile;\r
+ SECTION *Sect;\r
+ INT8 Line[MAX_LINE_LEN];\r
+ INT8 ExpLine[MAX_LINE_LEN];\r
+ INT8 *EMsg;\r
+ FILE *FpModule;\r
+ SYMBOL *TempSymbol;\r
+\r
+ SetUtilityName (PROGRAM_NAME);\r
+\r
+ InitExceptions ();\r
+\r
+ DSCFileInit (&DSCFile);\r
+ //\r
+ // Initialize the firmware volume data\r
+ //\r
+ CFVConstructor ();\r
+ //\r
+ // Exception handling for this block of code.\r
+ //\r
+ TryException ();\r
+ //\r
+ // Process command-line options.\r
+ //\r
+ if (ProcessOptions (Argc, Argv)) {\r
+ EMsg = CatchException ();\r
+ if (EMsg != NULL) {\r
+ fprintf (stderr, "%s\n", EMsg);\r
+ }\r
+\r
+ return STATUS_ERROR;\r
+ }\r
+ //\r
+ // Parse the GUID database file if specified\r
+ //\r
+ if (gGlobals.GuidDatabaseFileName[0] != 0) {\r
+ ParseGuidDatabaseFile (gGlobals.GuidDatabaseFileName);\r
+ }\r
+ //\r
+ // Set the output cross-reference file if applicable\r
+ //\r
+ if (gGlobals.XRefFileName[0]) {\r
+ CFVSetXRefFileName (gGlobals.XRefFileName);\r
+ }\r
+\r
+ //\r
+ // Now get the EFI_SOURCE directory which we use everywhere.\r
+ //\r
+ if (GetEfiSource ()) {\r
+ return STATUS_ERROR;\r
+ }\r
+ \r
+ //\r
+ // Pre-process the DSC file to get section info.\r
+ //\r
+ if (DSCFileSetFile (&DSCFile, gGlobals.DscFilename) != 0) {\r
+ goto ProcessingError;\r
+ }\r
+\r
+ //\r
+ // Set output makefile name for single module build \r
+ //\r
+ strcpy (gGlobals.ModuleMakefileName, MODULE_MAKEFILE_NAME);\r
+\r
+ //\r
+ // Try to open all final output makefiles\r
+ //\r
+ if ((gGlobals.MakefileFptr = fopen (gGlobals.MakefileName, "w")) == NULL) {\r
+ Error (NULL, 0, 0, gGlobals.MakefileName, "failed to open output makefile for writing");\r
+ goto ProcessingError;\r
+ }\r
+ if ((gGlobals.ModuleMakefileFptr = fopen (gGlobals.ModuleMakefileName, "w")) == NULL) {\r
+ Error (NULL, 0, 0, gGlobals.ModuleMakefileName, "failed to open output makefile for writing");\r
+ goto ProcessingError;\r
+ }\r
+ \r
+ //\r
+ // Write the header out to the makefiles\r
+ //\r
+ for (i = 0; MakefileHeader[i] != NULL; i++) {\r
+ fprintf (gGlobals.MakefileFptr, "%s\n", MakefileHeader[i]);\r
+ fprintf (gGlobals.ModuleMakefileFptr, "%s\n", MakefileHeader[i]);\r
+ }\r
+\r
+ //\r
+ // Init global potint = NULL\r
+ //\r
+ gGlobals.ModuleList = NULL;\r
+ gGlobals.OutdirList = NULL;\r
+ \r
+ //\r
+ // Process the [defines] section in the DSC file to get any defines we need\r
+ // elsewhere\r
+ //\r
+ ProcessDSCDefinesSection (&DSCFile);\r
+ if (ExceptionThrown ()) {\r
+ goto ProcessingError;\r
+ }\r
+ //\r
+ // Write out the [makefile.out] section data to the output makefiles\r
+ //\r
+ Sect = DSCFileFindSection (&DSCFile, MAKEFILE_OUT_SECTION_NAME);\r
+ if (Sect != NULL) {\r
+ while (DSCFileGetLine (&DSCFile, Line, sizeof (Line)) != NULL) {\r
+ ExpandSymbols (Line, ExpLine, sizeof (ExpLine), 0);\r
+ //\r
+ // Write the line to the output makefiles\r
+ //\r
+ fprintf (gGlobals.MakefileFptr, ExpLine);\r
+ fprintf (gGlobals.ModuleMakefileFptr, ExpLine);\r
+ }\r
+ }\r
+ \r
+ //\r
+ // Add a pseudo target for GLOBAL_LINK_LIB_NAME to avoid single module build \r
+ // failure when this lib is not used.\r
+ //\r
+ fprintf (gGlobals.ModuleMakefileFptr, "%sbuild ::\n\n", GLOBAL_LINK_LIB_NAME);\r
+\r
+ fprintf (gGlobals.MakefileFptr, "libraries : \n");\r
+ //\r
+ // Process [libraries] section in the DSC file\r
+ //\r
+ Sect = DSCFileFindSection (&DSCFile, LIBRARIES_SECTION_NAME);\r
+ if (Sect != NULL) {\r
+ ProcessSectionComponents (&DSCFile, DSC_SECTION_TYPE_LIBRARIES, 0);\r
+ }\r
+\r
+ if (ExceptionThrown ()) {\r
+ goto ProcessingError;\r
+ }\r
+ //\r
+ // Process [libraries.platform] section in the DSC file\r
+ //\r
+ Sect = DSCFileFindSection (&DSCFile, LIBRARIES_PLATFORM_SECTION_NAME);\r
+ if (Sect != NULL) {\r
+ ProcessSectionComponents (&DSCFile, DSC_SECTION_TYPE_PLATFORM_LIBRARIES, 0);\r
+ }\r
+\r
+ fprintf (gGlobals.MakefileFptr, "\n");\r
+ if (ExceptionThrown ()) {\r
+ goto ProcessingError;\r
+ }\r
+ \r
+ //\r
+ // Process [components] section in the DSC file\r
+ //\r
+ Sect = DSCFileFindSection (&DSCFile, COMPONENTS_SECTION_NAME);\r
+ if (Sect != NULL) {\r
+ fprintf (gGlobals.MakefileFptr, "components_0 : \n");\r
+ ProcessSectionComponents (&DSCFile, DSC_SECTION_TYPE_COMPONENTS, 0);\r
+ fprintf (gGlobals.MakefileFptr, "\n");\r
+ }\r
+\r
+ if (ExceptionThrown ()) {\r
+ goto ProcessingError;\r
+ }\r
+ //\r
+ // Now cycle through all [components.1], [components.2], ....[components.n].\r
+ // This is necessary to support building of firmware volumes that may contain\r
+ // other encapsulated firmware volumes (ala capsules).\r
+ //\r
+ i = 1;\r
+ while (1) {\r
+ RemoveSymbol (FV, SYM_GLOBAL);\r
+ sprintf (Line, "%s.%d", COMPONENTS_SECTION_NAME, i);\r
+ Sect = DSCFileFindSection (&DSCFile, Line);\r
+ if (Sect != NULL) {\r
+ fprintf (gGlobals.MakefileFptr, "components_%d : \n", i);\r
+ ProcessSectionComponents (&DSCFile, DSC_SECTION_TYPE_COMPONENTS, i);\r
+ fprintf (gGlobals.MakefileFptr, "\n");\r
+ } else {\r
+ break;\r
+ }\r
+\r
+ if (ExceptionThrown ()) {\r
+ goto ProcessingError;\r
+ }\r
+\r
+ i++;\r
+ }\r
+\r
+ProcessingError:\r
+ EMsg = CatchException ();\r
+ if (EMsg != NULL) {\r
+ fprintf (stderr, "%s\n", EMsg);\r
+ fprintf (stderr, "Processing aborted\n");\r
+ }\r
+\r
+ TryException ();\r
+ //\r
+ // Create the FV files if no fatal errors or errors\r
+ //\r
+ if (GetUtilityStatus () < STATUS_ERROR) {\r
+ CFVWriteInfFiles (&DSCFile, gGlobals.MakefileFptr);\r
+ }\r
+\r
+ //\r
+ // Write all module name into MODULE_NAME_FILE file.\r
+ //\r
+ if ((FpModule = fopen (MODULE_NAME_FILE, "w")) != NULL) {\r
+ TempSymbol = gGlobals.ModuleList;\r
+ while (TempSymbol != NULL) {\r
+ fprintf (FpModule, " %-*s %s \n", MODULE_BASE_NAME_WIDTH, TempSymbol->Name, TempSymbol->Value);\r
+ TempSymbol = TempSymbol->Next;\r
+ }\r
+ fclose (FpModule);\r
+ FpModule = NULL;\r
+ }\r
+\r
+ //\r
+ // Close the all the output makefiles\r
+ //\r
+ if (gGlobals.MakefileFptr != NULL) {\r
+ fclose (gGlobals.MakefileFptr);\r
+ gGlobals.MakefileFptr = NULL;\r
+ }\r
+\r
+ if (gGlobals.ModuleMakefileFptr != NULL) {\r
+ fclose (gGlobals.ModuleMakefileFptr);\r
+ gGlobals.ModuleMakefileFptr = NULL;\r
+ }\r
+ \r
+ //\r
+ // Clean up\r
+ //\r
+ FreeSymbols (gGlobals.ModuleList);\r
+ FreeSymbols (gGlobals.OutdirList);\r
+ FreeSymbols (gGlobals.Symbol);\r
+ gGlobals.Symbol = NULL;\r
+ CFVDestructor ();\r
+ DSCFileDestroy (&DSCFile);\r
+\r
+ EMsg = CatchException ();\r
+ if (EMsg != NULL) {\r
+ fprintf (stderr, "%s\n", EMsg);\r
+ fprintf (stderr, "Processing aborted\n");\r
+ }\r
+\r
+ return GetUtilityStatus ();\r
+}\r
+\r
+static\r
+int\r
+ProcessSectionComponents (\r
+ DSC_FILE *DSCFile,\r
+ int DscSectionType,\r
+ int Instance\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ \r
+ Process the [components] or [libraries] section in the description file. We\r
+ use this function for both since they're very similar. Here we just\r
+ read each line from the section, and if it's valid, call a function to\r
+ do the actual processing of the component description file.\r
+\r
+Arguments:\r
+\r
+ DSCFile - structure containing section info on the description file\r
+ DscSectionType - type of description section\r
+\r
+Returns:\r
+\r
+ 0 if successful\r
+\r
+--*/\r
+{\r
+ INT8 Line[MAX_LINE_LEN];\r
+ INT8 Line2[MAX_EXP_LINE_LEN];\r
+ INT8 *Cptr;\r
+\r
+ //\r
+ // Read lines while they're valid\r
+ //\r
+ while (DSCFileGetLine (DSCFile, Line, sizeof (Line)) != NULL) {\r
+ //\r
+ // Expand symbols on the line\r
+ //\r
+ if (ExpandSymbols (Line, Line2, sizeof (Line2), 0)) {\r
+ return STATUS_ERROR;\r
+ }\r
+ //\r
+ // Strip the line\r
+ //\r
+ Cptr = StripLine (Line2);\r
+ if (*Cptr) {\r
+ Message (2, "Processing component line: %s", Line2);\r
+ if (ProcessComponentFile (DSCFile, Line2, DscSectionType, Instance) != 0) {\r
+ return STATUS_ERROR;\r
+ }\r
+ }\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+static\r
+int\r
+ProcessComponentFile (\r
+ DSC_FILE *DSCFile,\r
+ INT8 *ArgLine,\r
+ int DscSectionType,\r
+ int Instance\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ \r
+ Given a line from the [components] or [libraries] section of the description\r
+ file, process the line to extract the component's INF filename and \r
+ parameters. Then open the INF file and process it to create a corresponding\r
+ makefile.\r
+\r
+Arguments:\r
+\r
+ DSCFile The project DSC file info structure.\r
+ Libs Indicates whether we're processing the [components]\r
+ section or the [libraries] section.\r
+ ArgLine The actual line from the DSC file. Looks something like\r
+ one of the following:\r
+\r
+ dxe\drivers\vm\vm.dsc PROCESSOR=IA32 DEST_DIR=$(DEST_DIR)\xxx FV=FV1,FV2\r
+ $(BUILD_DIR).\FvVariable.ffs COMPONENT_TYPE=FILE\r
+ .\FvVariable.ffs COMPONENT_TYPE=FILE\r
+ define VAR1=value1 VAR2=value2\r
+\r
+Returns:\r
+\r
+ 0 if successful\r
+\r
+--*/\r
+{\r
+ FILE *MakeFptr;\r
+ FILE *TempFptr;\r
+ INT8 *Cptr;\r
+ INT8 *name;\r
+ INT8 *End;\r
+ INT8 *TempCptr;\r
+ INT8 FileName[MAX_PATH];\r
+ INT8 ComponentFilePath[MAX_PATH];\r
+ INT8 InLine[MAX_LINE_LEN];\r
+ INT8 Line[MAX_LINE_LEN];\r
+ INT8 *Processor;\r
+ INT8 SymType;\r
+ int Len;\r
+ int ComponentCreated;\r
+ int ComponentFilePathAbsolute;\r
+ int DefineLine;\r
+ DSC_FILE ComponentFile;\r
+ INT8 ComponentMakefileName[MAX_PATH];\r
+ BOOLEAN IsForFv;\r
+\r
+ //\r
+ // Now remove all local symbols\r
+ //\r
+ RemoveLocalSymbols ();\r
+ //\r
+ // Null out the file pointer in case we take an exception somewhere\r
+ // and we need to close it only if we opened it.\r
+ //\r
+ MakeFptr = NULL;\r
+ ComponentFilePathAbsolute = 0;\r
+ ComponentCreated = 0;\r
+ //\r
+ // Skip preceeding spaces on the line\r
+ //\r
+ while (isspace (*ArgLine) && (*ArgLine)) {\r
+ ArgLine++;\r
+ }\r
+ //\r
+ // Find the end of the component's filename and truncate the line at that\r
+ // point. From here on out ArgLine is the name of the component filename.\r
+ //\r
+ Cptr = ArgLine;\r
+ while (!isspace (*Cptr) && *Cptr) {\r
+ Cptr++;\r
+ }\r
+\r
+ End = Cptr;\r
+ if (*Cptr) {\r
+ End++;\r
+ *Cptr = 0;\r
+ }\r
+ //\r
+ // Exception-handle processing of this component description file\r
+ //\r
+ TryException ();\r
+\r
+ //\r
+ // We also allow a component line format for defines of global symbols\r
+ // instead of a component filename. In this case, the line looks like:\r
+ // defines x=abc y=yyy. Be nice and accept "define" and "defines" in a\r
+ // case-insensitive manner. If it's defines, then make the symbols global.\r
+ //\r
+ if ((_stricmp (ArgLine, "define") == 0) || (_stricmp (ArgLine, "defines") == 0)) {\r
+ SymType = SYM_OVERWRITE | SYM_GLOBAL;\r
+ DefineLine = 1;\r
+ } else {\r
+ SymType = SYM_OVERWRITE | SYM_LOCAL;\r
+ DefineLine = 0;\r
+ }\r
+ //\r
+ // The rest of the component line from the DSC file should be defines\r
+ //\r
+ while (*End) {\r
+ End = StripLine (End);\r
+ if (*End) {\r
+ //\r
+ // If we're processing a "define abc=1 xyz=2" line, then set symbols\r
+ // as globals per the SymType set above.\r
+ //\r
+ Len = AddSymbol (End, NULL, SymType);\r
+ if (Len > 0) {\r
+ End += Len;\r
+ } else {\r
+ Warning (NULL, 0, 0, ArgLine, "unrecognized option in description file");\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
+ //\r
+ // If DEBUG_BREAK or EFI_BREAKPOINT is defined, then do a debug breakpoint.\r
+ //\r
+ if ((GetSymbolValue ("DEBUG_BREAK") != NULL) || (GetSymbolValue ("EFI_BREAKPOINT") != NULL)) {\r
+ EFI_BREAKPOINT ();\r
+ }\r
+ \r
+ //\r
+ // If it's a define line, then we're done\r
+ //\r
+ if (DefineLine) {\r
+ //\r
+ // If there is NonFFS_FV, create the FVxxx.inf file\r
+ // and include it in makefile.out. Remove the symbol\r
+ // in order not to process it again next time\r
+ //\r
+ Cptr = GetSymbolValue (NONFFS_FV);\r
+ if (Cptr != NULL) {\r
+ NonFFSFVWriteInfFiles (DSCFile, Cptr);\r
+ RemoveSymbol (NONFFS_FV, SYM_GLOBAL);\r
+ }\r
+\r
+ goto ComponentDone;\r
+ }\r
+\r
+ //\r
+ // Expand symbols in the component description filename to expand the newly \r
+ // added local symbols\r
+ //\r
+ ExpandSymbols (ArgLine, Line, sizeof (Line), EXPANDMODE_NO_UNDEFS);\r
+\r
+ //\r
+ // If we have "c:\path\filename"\r
+ //\r
+ if (IsAbsolutePath (Line)) {\r
+ ComponentFilePathAbsolute = 1;\r
+ } else if (Line[0] == '.') {\r
+ //\r
+ // or if the path starts with ".", then it's build-dir relative.\r
+ // Prepend $(BUILD_DIR) on the file name\r
+ //\r
+ sprintf (InLine, "%s\\%s", GetSymbolValue (BUILD_DIR), Line);\r
+ strcpy (Line, InLine);\r
+ ComponentFilePathAbsolute = 1;\r
+ }\r
+ \r
+ //\r
+ // Save the path from the component name for later. It may be relative or\r
+ // absolute.\r
+ //\r
+ strcpy (ComponentFilePath, Line);\r
+ Cptr = ComponentFilePath + strlen (ComponentFilePath) - 1;\r
+ while ((*Cptr != '\\') && (*Cptr != '/') && (Cptr != ComponentFilePath)) {\r
+ Cptr--;\r
+ }\r
+ //\r
+ // Terminate the path.\r
+ //\r
+ *Cptr = 0;\r
+ \r
+ //\r
+ // Typically the given line is a component description filename. However we\r
+ // also allow a FV filename (fvvariable.ffs COMPONENT_TYPE=FILE). If the\r
+ // component type is "FILE", then add it to the FV list, create a package\r
+ // file, and we're done.\r
+ //\r
+ Cptr = GetSymbolValue (COMPONENT_TYPE);\r
+ if ((Cptr != NULL) && (strncmp (\r
+ Cptr,\r
+ COMPONENT_TYPE_FILE,\r
+ strlen (COMPONENT_TYPE_FILE)\r
+ ) == 0)) {\r
+ if (ComponentFilePathAbsolute) {\r
+ strcpy (InLine, Line);\r
+ } else {\r
+ sprintf (InLine, "%s\\%s", GetSymbolValue (EFI_SOURCE), Line);\r
+ }\r
+ CFVAddFVFile (\r
+ InLine,\r
+ Cptr,\r
+ GetSymbolValue (FV),\r
+ Instance,\r
+ NULL,\r
+ NULL,\r
+ GetSymbolValue (APRIORI),\r
+ NULL,\r
+ NULL\r
+ );\r
+ goto ComponentDone;\r
+ }\r
+\r
+ //\r
+ // Better have defined processor by this point.\r
+ //\r
+ Processor = GetSymbolValue (PROCESSOR);\r
+ if (Processor == NULL) {\r
+ Error (NULL, 0, 0, NULL, "PROCESSOR not defined for component %s", Line);\r
+ return STATUS_ERROR;\r
+ }\r
+\r
+ //\r
+ // The bin, out, and lib dirs are now = $(BUILD_DIR)/$(PROCESSOR). Set them.\r
+ // Don't flag them as file paths (required for short 8.3 filenames) since\r
+ // they're defined using the BUILD_DIR macro.\r
+ //\r
+ sprintf (InLine, "$(BUILD_DIR)\\%s", Processor);\r
+ AddSymbol (BIN_DIR, InLine, SYM_LOCAL);\r
+ AddSymbol (OUT_DIR, InLine, SYM_LOCAL);\r
+ AddSymbol (LIB_DIR, InLine, SYM_LOCAL);\r
+ //\r
+ // See if it's been destined for an FV. It's possible to not be in an\r
+ // FV if they just want to build it.\r
+ //\r
+ Cptr = GetSymbolValue (FV);\r
+ if ((Cptr != NULL) && !IS_NULL_SYMBOL_VALUE (Cptr)) {\r
+ IsForFv = TRUE;\r
+ } else {\r
+ IsForFv = FALSE;\r
+ }\r
+ //\r
+ // As an optimization, if they've defined SKIP_FV_NULL as non-zero, and\r
+ // the component is not destined for an FV, then skip it.\r
+ // Since libraries are never intended for firmware volumes, we have to\r
+ // build all of them.\r
+ //\r
+ if ((DscSectionType == DSC_SECTION_TYPE_COMPONENTS) && (IsForFv == FALSE)) {\r
+ if ((GetSymbolValue (SKIP_FV_NULL) != NULL) && (atoi (GetSymbolValue (SKIP_FV_NULL)) != 0)) {\r
+ Message (0, "%s not being built (FV=NULL)", FileName);\r
+ goto ComponentDone;\r
+ }\r
+ }\r
+ //\r
+ // Prepend EFI_SOURCE to the component description file to get the\r
+ // full path. Only do this if the path is not a full path already.\r
+ //\r
+ if (ComponentFilePathAbsolute == 0) {\r
+ name = GetSymbolValue (EFI_SOURCE);\r
+ sprintf (FileName, "%s\\%s", name, Line);\r
+ } else {\r
+ strcpy (FileName, Line);\r
+ }\r
+ //\r
+ // Print a message, depending on verbose level.\r
+ //\r
+ if (DscSectionType == DSC_SECTION_TYPE_COMPONENTS) {\r
+ Message (1, "Processing component %s", FileName);\r
+ } else {\r
+ Message (1, "Processing library %s", FileName);\r
+ }\r
+ //\r
+ // Open the component's description file and get the sections. If we fail\r
+ // to open it, see if they defined "OPTIONAL=1, in which case we'll just\r
+ // ignore the component.\r
+ //\r
+ TempFptr = fopen (FileName, "r");\r
+ if (TempFptr == NULL) {\r
+ //\r
+ // Better have defined OPTIONAL\r
+ //\r
+ if (GetSymbolValue (OPTIONAL_COMPONENT) != NULL) {\r
+ if (atoi (GetSymbolValue (OPTIONAL_COMPONENT)) != 0) {\r
+ Message (0, "Optional component '%s' not found", FileName);\r
+ goto ComponentDone;\r
+ }\r
+ }\r
+\r
+ ParserError (0, FileName, "failed to open component file");\r
+ return STATUS_ERROR;\r
+ } else {\r
+ fclose (TempFptr);\r
+ }\r
+\r
+ DSCFileInit (&ComponentFile);\r
+ ComponentCreated = 1;\r
+ if (DSCFileSetFile (&ComponentFile, FileName)) {\r
+ Error (NULL, 0, 0, NULL, "failed to preprocess component file '%s'", FileName);\r
+ return STATUS_ERROR;\r
+ }\r
+ //\r
+ // Add a symbol for the INF filename so users can create dependencies\r
+ // in makefiles.\r
+ //\r
+ AddSymbol (INF_FILENAME, FileName, SYM_OVERWRITE | SYM_LOCAL | SYM_FILENAME);\r
+ //\r
+ // Process the [defines], [defines.$(PROCESSOR)], and [defines.$(PROCESSOR).$(PLATFORM)]\r
+ // sections in the INF file\r
+ //\r
+ ProcessINFDefinesSection (&ComponentFile);\r
+ //\r
+ // Better have defined FILE_GUID if not a library\r
+ //\r
+ if ((GetSymbolValue (GUID) == NULL) &&\r
+ (GetSymbolValue (FILE_GUID) == NULL) &&\r
+ (DscSectionType == DSC_SECTION_TYPE_COMPONENTS)\r
+ ) {\r
+ Error (GetSymbolValue (INF_FILENAME), 1, 0, NULL, "missing FILE_GUID definition in component file");\r
+ DSCFileDestroy (&ComponentFile);\r
+ return STATUS_ERROR;\r
+ }\r
+ //\r
+ // Better have defined base name\r
+ //\r
+ if (GetSymbolValue (BASE_NAME) == NULL) {\r
+ Error (GetSymbolValue (INF_FILENAME), 1, 0, NULL, "missing BASE_NAME definition in INF file");\r
+ DSCFileDestroy (&ComponentFile);\r
+ return STATUS_ERROR;\r
+ }\r
+ //\r
+ // Better have defined COMPONENT_TYPE, since it's used to find named sections.\r
+ //\r
+ if (GetSymbolValue (COMPONENT_TYPE) == NULL) {\r
+ Error (GetSymbolValue (INF_FILENAME), 1, 0, NULL, "missing COMPONENT_TYPE definition in INF file");\r
+ DSCFileDestroy (&ComponentFile);\r
+ return STATUS_ERROR;\r
+ }\r
+\r
+ //\r
+ // Create the source directory path from the component file's path. If the component\r
+ // file's path is absolute, we may have problems here. Try to account for it though.\r
+ //\r
+ if (ComponentFilePathAbsolute == 0) {\r
+ sprintf (\r
+ FileName,\r
+ "%s\\%s",\r
+ GetSymbolValue (EFI_SOURCE),\r
+ ComponentFilePath\r
+ );\r
+ } else {\r
+ strcpy (FileName, ComponentFilePath);\r
+ }\r
+ AddSymbol (SOURCE_DIR, FileName, SYM_OVERWRITE | SYM_LOCAL | SYM_FILEPATH);\r
+\r
+ //\r
+ // Create the destination path. \r
+ // They may have defined DEST_DIR on the component INF line, so it's already\r
+ // been defined, If that's the case, then don't set it to the path of this file.\r
+ //\r
+ if (GetSymbolValue (DEST_DIR) == NULL) {\r
+ if (ComponentFilePathAbsolute == 0) {\r
+ //\r
+ // The destination path is $(BUILD_DIR)\$(PROCESSOR)\component_path\r
+ //\r
+ sprintf (\r
+ FileName,\r
+ "%s\\%s\\%s",\r
+ GetSymbolValue (BUILD_DIR),\r
+ Processor,\r
+ ComponentFilePath\r
+ );\r
+ } else {\r
+ //\r
+ // The destination path is $(BUILD_DIR)\$(PROCESSOR)\$(BASE_NAME)\r
+ //\r
+ sprintf (\r
+ FileName,\r
+ "%s\\%s\\%s",\r
+ GetSymbolValue (BUILD_DIR),\r
+ Processor,\r
+ GetSymbolValue (BASE_NAME)\r
+ );\r
+ }\r
+ AddSymbol (DEST_DIR, FileName, SYM_OVERWRITE | SYM_LOCAL | SYM_FILEPATH);\r
+ }\r
+ \r
+ //\r
+ // Create the output directory, then open the output component's makefile\r
+ // we're going to create. Allow them to override the makefile name.\r
+ //\r
+ TempCptr = GetSymbolValue (MAKEFILE_NAME);\r
+ if (TempCptr != NULL) {\r
+ ExpandSymbols (TempCptr, ComponentMakefileName, sizeof (ComponentMakefileName), EXPANDMODE_NO_UNDEFS);\r
+ TempCptr = ComponentMakefileName;\r
+ } else {\r
+ TempCptr = "makefile";\r
+ }\r
+\r
+ sprintf (FileName, "%s\\%s", GetSymbolValue (DEST_DIR), TempCptr);\r
+ //\r
+ // Save it now with path info\r
+ //\r
+ AddSymbol (MAKEFILE_NAME, FileName, SYM_OVERWRITE | SYM_LOCAL | SYM_FILENAME);\r
+\r
+ if (MakeFilePath (FileName)) {\r
+ return STATUS_ERROR;\r
+ }\r
+\r
+ if ((MakeFptr = fopen (FileName, "w")) == NULL) {\r
+ Error (NULL, 0, 0, FileName, "could not create makefile");\r
+ return STATUS_ERROR;\r
+ }\r
+ //\r
+ // At this point we should have all the info we need to create a package\r
+ // file if setup to do so. Libraries don't use package files, so\r
+ // don't do this for libs.\r
+ //\r
+ if (DscSectionType == DSC_SECTION_TYPE_COMPONENTS) {\r
+ CreatePackageFile (DSCFile);\r
+ }\r
+\r
+ //\r
+ // Add Module name to the global module list\r
+ //\r
+ AddModuleName (&gGlobals.ModuleList, GetSymbolValue (BASE_NAME), GetSymbolValue (INF_FILENAME));\r
+ //\r
+ // Write an nmake line to makefile.out\r
+ //\r
+ fprintf (gGlobals.MakefileFptr, " @cd %s\n", Processor);\r
+ fprintf (gGlobals.MakefileFptr, " $(MAKE) -f %s all\n", FileName);\r
+ fprintf (gGlobals.MakefileFptr, " @cd ..\n");\r
+\r
+ //\r
+ // Copy the common makefile section from the description file to\r
+ // the component's makefile\r
+ //\r
+ WriteCommonMakefile (DSCFile, MakeFptr, Processor);\r
+ //\r
+ // Process the component's [nmake.common] and [nmake.$(PROCESSOR)] sections\r
+ //\r
+ ProcessINFNMakeSection (&ComponentFile, MakeFptr);\r
+ //\r
+ // Create the SOURCE_FILES macro that includes the names of all source\r
+ // files in this component. This macro can then be used elsewhere to\r
+ // process all the files making up the component. Required for scanning\r
+ // files for string localization.\r
+ //\r
+ ProcessSourceFiles (DSCFile, &ComponentFile, MakeFptr, SOURCE_MODE_SOURCE_FILES);\r
+ //\r
+ // Create the include paths. Process [includes.common] and\r
+ // [includes.$(PROCESSOR)] and [includes.$(PROCESSOR).$(PLATFORM)] sections.\r
+ //\r
+ ProcessIncludesSection (&ComponentFile, MakeFptr);\r
+ //\r
+ // Process all include source files to create a dependency list that can\r
+ // be used in the makefile.\r
+ //\r
+ ProcessIncludeFiles (&ComponentFile, MakeFptr);\r
+ //\r
+ // Process the [sources.common], [sources.$(PROCESSOR)], and\r
+ // [sources.$(PROCESSOR).$(PLATFORM)] files and emit their build commands\r
+ //\r
+ ProcessSourceFiles (DSCFile, &ComponentFile, MakeFptr, SOURCE_MODE_BUILD_COMMANDS);\r
+ //\r
+ // Process sources again to create an OBJECTS macro\r
+ //\r
+ ProcessObjects (&ComponentFile, MakeFptr);\r
+\r
+ //\r
+ // Add Single Module target : build and clean in top level makefile\r
+ //\r
+ fprintf (gGlobals.ModuleMakefileFptr, "%sbuild ::", GetSymbolValue (BASE_NAME));\r
+ if (DscSectionType == DSC_SECTION_TYPE_COMPONENTS) {\r
+ fprintf (gGlobals.ModuleMakefileFptr, " %sbuild", GLOBAL_LINK_LIB_NAME);\r
+ }\r
+ \r
+ //\r
+ // Process all the libraries to define "LIBS = x.lib y.lib..."\r
+ // Be generous and append ".lib" if they forgot.\r
+ // Make a macro definition: LIBS = $(LIBS) xlib.lib ylib.lib...\r
+ // Also add libs dependency for single module build: basenamebuild :: xlibbuild ylibbuild ...\r
+ //\r
+ ProcessLibs (&ComponentFile, MakeFptr);\r
+\r
+ fprintf (gGlobals.ModuleMakefileFptr, "\n");\r
+ \r
+ fprintf (gGlobals.ModuleMakefileFptr, " @cd %s\n", Processor);\r
+ fprintf (gGlobals.ModuleMakefileFptr, " $(MAKE) -f %s all\n", FileName);\r
+ fprintf (gGlobals.ModuleMakefileFptr, " @cd ..\n\n");\r
+\r
+ fprintf (gGlobals.ModuleMakefileFptr, "%sclean ::\n", GetSymbolValue (BASE_NAME));\r
+ fprintf (gGlobals.ModuleMakefileFptr, " $(MAKE) -f %s clean\n\n", FileName);\r
+ \r
+ //\r
+ // Emit commands to create the component. These are simply copied from\r
+ // the description file to the component's makefile. First look for\r
+ // [build.$(PROCESSOR).$(BUILD_TYPE)]. If not found, then look for if\r
+ // find a [build.$(PROCESSOR).$(COMPONENT_TYPE)] line.\r
+ //\r
+ Cptr = GetSymbolValue (BUILD_TYPE);\r
+ if (Cptr != NULL) {\r
+ sprintf (InLine, "build.%s.%s", Processor, Cptr);\r
+ WriteComponentTypeBuildCommands (DSCFile, MakeFptr, InLine);\r
+ } else {\r
+ sprintf (InLine, "build.%s.%s", Processor, GetSymbolValue (COMPONENT_TYPE));\r
+ WriteComponentTypeBuildCommands (DSCFile, MakeFptr, InLine);\r
+ }\r
+ //\r
+ // Add it to the FV if not a library\r
+ //\r
+ if (DscSectionType == DSC_SECTION_TYPE_COMPONENTS) {\r
+ //\r
+ // Create the FV filename and add it to the FV.\r
+ // By this point we know it's in FV.\r
+ //\r
+ Cptr = GetSymbolValue (FILE_GUID);\r
+ if (Cptr == NULL) {\r
+ Cptr = GetSymbolValue (GUID);\r
+ }\r
+\r
+ sprintf (InLine, "%s-%s", Cptr, GetSymbolValue (BASE_NAME));\r
+ //\r
+ // We've deprecated FV_EXT, which should be FFS_EXT, the extension\r
+ // of the FFS file generated by GenFFSFile.\r
+ //\r
+ TempCptr = GetSymbolValue (FFS_EXT);\r
+ if (TempCptr == NULL) {\r
+ TempCptr = GetSymbolValue ("FV_EXT");\r
+ }\r
+\r
+ CFVAddFVFile (\r
+ InLine,\r
+ GetSymbolValue (COMPONENT_TYPE),\r
+ GetSymbolValue (FV),\r
+ Instance,\r
+ TempCptr,\r
+ Processor,\r
+ GetSymbolValue (APRIORI),\r
+ GetSymbolValue (BASE_NAME),\r
+ Cptr\r
+ );\r
+ }\r
+ //\r
+ // Catch any failures and print the name of the component file\r
+ // being processed to assist debugging.\r
+ //\r
+ComponentDone:\r
+\r
+ Cptr = CatchException ();\r
+ if (Cptr != NULL) {\r
+ fprintf (stderr, "%s\n", Cptr);\r
+ sprintf (InLine, "Processing of component %s failed", ArgLine);\r
+ ThrowException (InLine);\r
+ }\r
+\r
+ if (MakeFptr != NULL) {\r
+ fclose (MakeFptr);\r
+ }\r
+\r
+ if (ComponentCreated) {\r
+ DSCFileDestroy (&ComponentFile);\r
+ }\r
+\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+static\r
+int\r
+CreatePackageFile (\r
+ DSC_FILE *DSCFile\r
+ )\r
+{\r
+ INT8 *Package;\r
+ SECTION *TempSect;\r
+ INT8 Str[MAX_LINE_LEN];\r
+ INT8 StrExpanded[MAX_LINE_LEN];\r
+ SMART_FILE *PkgFptr;\r
+ int Status;\r
+\r
+ PkgFptr = NULL;\r
+\r
+ //\r
+ // First find out if PACKAGE_FILENAME or PACKAGE is defined. PACKAGE_FILENAME\r
+ // is used to specify the exact package file to use. PACKAGE is used to\r
+ // specify the package section name.\r
+ //\r
+ Package = GetSymbolValue (PACKAGE_FILENAME);\r
+ if (Package != NULL) {\r
+ //\r
+ // Use existing file. We're done.\r
+ //\r
+ return STATUS_SUCCESS;\r
+ }\r
+ //\r
+ // See if PACKAGE or PACKAGE_TAG is defined\r
+ //\r
+ Package = GetSymbolValue (PACKAGE);\r
+ if (Package == NULL) {\r
+ Package = GetSymbolValue (PACKAGE_TAG);\r
+ }\r
+\r
+ if (Package == NULL) {\r
+ //\r
+ // Not defined either. Assume they are not using the package functionality\r
+ // of this utility. However define the PACKAGE_FILENAME macro to the\r
+ // best-guess value.\r
+ //\r
+ sprintf (\r
+ Str,\r
+ "%s\\%s.pkg",\r
+ GetSymbolValue (SOURCE_DIR),\r
+ GetSymbolValue (BASE_NAME)\r
+ );\r
+ \r
+ //\r
+ // Expand symbols in the package filename\r
+ //\r
+ ExpandSymbols (Str, StrExpanded, sizeof (StrExpanded), EXPANDMODE_NO_UNDEFS); \r
+ \r
+ AddSymbol (PACKAGE_FILENAME, StrExpanded, SYM_LOCAL | SYM_FILENAME);\r
+ return STATUS_SUCCESS;\r
+ }\r
+ //\r
+ // Save the position in the DSC file.\r
+ // Find the [package.$(COMPONENT_TYPE).$(PACKAGE)] section in the DSC file\r
+ //\r
+ Status = STATUS_SUCCESS;\r
+ DSCFileSavePosition (DSCFile);\r
+ sprintf (Str, "%s.%s.%s", PACKAGE, GetSymbolValue (COMPONENT_TYPE), Package);\r
+ TempSect = DSCFileFindSection (DSCFile, Str);\r
+ if (TempSect != NULL) {\r
+ //\r
+ // So far so good. Create the name of the package file, then open it up\r
+ // for writing. File name is c:\...\oem\platform\nt32\ia32\...\BaseName.pkg.\r
+ //\r
+ sprintf (\r
+ Str,\r
+ "%s\\%s.pkg",\r
+ GetSymbolValue (DEST_DIR),\r
+ GetSymbolValue (BASE_NAME)\r
+ );\r
+ \r
+ //\r
+ // Expand symbols in the package filename\r
+ //\r
+ ExpandSymbols (Str, StrExpanded, sizeof (StrExpanded), EXPANDMODE_NO_UNDEFS); \r
+ \r
+ //\r
+ // Try to open the file, then save the file name as the PACKAGE_FILENAME\r
+ // symbol for use elsewhere.\r
+ //\r
+ if ((PkgFptr = SmartOpen (StrExpanded)) == NULL) {\r
+ Error (NULL, 0, 0, Str, "could not open package file for writing");\r
+ Status = STATUS_ERROR;\r
+ goto Finish;\r
+ }\r
+\r
+ AddSymbol (PACKAGE_FILENAME, StrExpanded, SYM_LOCAL | SYM_FILENAME);\r
+ //\r
+ // Now read lines in from the DSC file and write them back out to the\r
+ // package file (with string substitution).\r
+ //\r
+ while (DSCFileGetLine (DSCFile, Str, sizeof (Str)) != NULL) {\r
+ //\r
+ // Expand symbols, then write the line out to the package file\r
+ //\r
+ ExpandSymbols (Str, StrExpanded, sizeof (StrExpanded), EXPANDMODE_RECURSIVE);\r
+ SmartWrite (PkgFptr, StrExpanded);\r
+ }\r
+ } else {\r
+ Warning (\r
+ NULL,\r
+ 0,\r
+ 0,\r
+ NULL,\r
+ "cannot locate package section [%s] in DSC file for %s",\r
+ Str,\r
+ GetSymbolValue (INF_FILENAME)\r
+ );\r
+ Status = STATUS_WARNING;\r
+ goto Finish;\r
+ }\r
+\r
+ if (PkgFptr != NULL) {\r
+ SmartClose (PkgFptr);\r
+ }\r
+\r
+Finish:\r
+ //\r
+ // Restore the position in the DSC file\r
+ //\r
+ DSCFileRestorePosition (DSCFile);\r
+\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+static\r
+int\r
+ProcessINFDefinesSection (\r
+ DSC_FILE *ComponentFile\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Process the [defines.xxx] sections of the component description file. Process\r
+ platform first, then processor. In this way, if a platform wants and override,\r
+ that one gets parsed first, and later assignments do not overwrite the value.\r
+ \r
+Arguments:\r
+\r
+ ComponentFile - section info on the component file being processed\r
+\r
+Returns:\r
+\r
+ \r
+--*/\r
+{\r
+ INT8 *Cptr;\r
+ INT8 Str[MAX_LINE_LEN];\r
+\r
+ //\r
+ // Find a [defines.$(PROCESSOR).$(PLATFORM)] section and process it\r
+ //\r
+ Cptr = GetSymbolValue (PLATFORM);\r
+ if (Cptr != NULL) {\r
+ sprintf (\r
+ Str,\r
+ "%s.%s.%s",\r
+ DEFINES_SECTION_NAME,\r
+ GetSymbolValue (PROCESSOR),\r
+ Cptr\r
+ );\r
+ ProcessINFDefinesSectionSingle (ComponentFile, Str);\r
+ }\r
+ //\r
+ // Find a [defines.$(PROCESSOR)] section and process it\r
+ //\r
+ sprintf (Str, "%s.%s", DEFINES_SECTION_NAME, GetSymbolValue (PROCESSOR));\r
+ ProcessINFDefinesSectionSingle (ComponentFile, Str);\r
+\r
+ //\r
+ // Find a [defines] section and process it\r
+ //\r
+ if (ProcessINFDefinesSectionSingle (ComponentFile, DEFINES_SECTION_NAME) != STATUS_SUCCESS) {\r
+ Error (NULL, 0, 0, NULL, "missing [defines] section in component file %s", GetSymbolValue (INF_FILENAME));\r
+ return STATUS_ERROR;\r
+ }\r
+\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+static\r
+int\r
+ProcessINFDefinesSectionSingle (\r
+ DSC_FILE *ComponentFile,\r
+ INT8 *SectionName\r
+ )\r
+{\r
+ INT8 *Cptr;\r
+ INT8 Str[MAX_LINE_LEN];\r
+ INT8 ExpandedLine[MAX_LINE_LEN];\r
+ SECTION *TempSect;\r
+\r
+ TempSect = DSCFileFindSection (ComponentFile, SectionName);\r
+ if (TempSect != NULL) {\r
+ while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r
+ ExpandSymbols (Str, ExpandedLine, sizeof (ExpandedLine), 0);\r
+ Cptr = StripLine (ExpandedLine);\r
+ //\r
+ // Don't process blank lines.\r
+ //\r
+ if (*Cptr) {\r
+ //\r
+ // Add without overwriting macros specified on the component line\r
+ // in the description file\r
+ //\r
+ AddSymbol (Cptr, NULL, SYM_LOCAL);\r
+ }\r
+ }\r
+ } else {\r
+ return STATUS_WARNING;\r
+ }\r
+\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+static\r
+int\r
+ProcessINFNMakeSection (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Process the [nmake.common] and [nmake.$(PROCESSOR)] sections of the component\r
+ description file and write and copy them to the component's makefile.\r
+ \r
+Arguments:\r
+\r
+ ComponentFile - section info on the component file being processed\r
+ MakeFptr - file pointer to the component' makefile we're creating\r
+\r
+Returns:\r
+\r
+ Always STATUS_SUCCESS right now, since the sections are optional.\r
+ \r
+--*/\r
+{\r
+ INT8 *Cptr;\r
+ INT8 Str[MAX_LINE_LEN];\r
+ INT8 ExpandedLine[MAX_LINE_LEN];\r
+ SECTION *TempSect;\r
+\r
+ //\r
+ // Copy the [nmake.common] and [nmake.$(PROCESSOR)] sections from the\r
+ // component file directly to the output file.\r
+ // The line will be stripped and don't print blank lines\r
+ //\r
+ sprintf (Str, "%s.%s", NMAKE_SECTION_NAME, COMMON_SECTION_NAME);\r
+ TempSect = DSCFileFindSection (ComponentFile, Str);\r
+ if (TempSect != NULL) {\r
+ while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r
+ ExpandSymbols (\r
+ Str,\r
+ ExpandedLine,\r
+ sizeof (ExpandedLine),\r
+ EXPANDMODE_NO_DESTDIR | EXPANDMODE_NO_SOURCEDIR\r
+ );\r
+ Cptr = StripLine (ExpandedLine);\r
+ if (*Cptr) {\r
+ fprintf (MakeFptr, "%s\n", Cptr);\r
+ }\r
+ }\r
+\r
+ fprintf (MakeFptr, "\n");\r
+ } else {\r
+ Error (GetSymbolValue (INF_FILENAME), 1, 0, Str, "section not found in component INF file");\r
+ }\r
+\r
+ sprintf (Str, "%s.%s", NMAKE_SECTION_NAME, GetSymbolValue (PROCESSOR));\r
+ TempSect = DSCFileFindSection (ComponentFile, Str);\r
+ if (TempSect != NULL) {\r
+ while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r
+ ExpandSymbols (\r
+ Str,\r
+ ExpandedLine,\r
+ sizeof (ExpandedLine),\r
+ EXPANDMODE_NO_DESTDIR | EXPANDMODE_NO_SOURCEDIR\r
+ );\r
+ Cptr = StripLine (ExpandedLine);\r
+ if (*Cptr) {\r
+ fprintf (MakeFptr, "%s\n", Cptr);\r
+ }\r
+ }\r
+\r
+ fprintf (MakeFptr, "\n");\r
+ }\r
+ //\r
+ // Do the same for [nmake.$(PROCESSOR).$(PLATFORM)]\r
+ //\r
+ Cptr = GetSymbolValue (PLATFORM);\r
+ if (Cptr != NULL) {\r
+ sprintf (Str, "%s.%s.%s", NMAKE_SECTION_NAME, GetSymbolValue (PROCESSOR), Cptr);\r
+ TempSect = DSCFileFindSection (ComponentFile, Str);\r
+ if (TempSect != NULL) {\r
+ while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r
+ ExpandSymbols (\r
+ Str,\r
+ ExpandedLine,\r
+ sizeof (ExpandedLine),\r
+ EXPANDMODE_NO_DESTDIR | EXPANDMODE_NO_SOURCEDIR\r
+ );\r
+ Cptr = StripLine (ExpandedLine);\r
+ if (*Cptr) {\r
+ fprintf (MakeFptr, "%s\n", Cptr);\r
+ }\r
+ }\r
+\r
+ fprintf (MakeFptr, "\n");\r
+ }\r
+ }\r
+\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+static\r
+int\r
+ProcessIncludesSection (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Process the [includes.common], [includes.processor], and \r
+ [includes.processor.platform] section of the component description file \r
+ and write the appropriate macros to the component's makefile.\r
+\r
+ Process in reverse order to allow overrides on platform basis.\r
+ \r
+Arguments:\r
+\r
+ ComponentFile - section info on the component file being processed\r
+ MakeFptr - file pointer to the component' makefile we're creating\r
+\r
+Returns:\r
+\r
+ Always STATUS_SUCCESS right now, since the sections are optional.\r
+ \r
+--*/\r
+{\r
+ INT8 *Cptr;\r
+ INT8 Str[MAX_LINE_LEN];\r
+ INT8 *Processor;\r
+ INT8 *OverridePath;\r
+\r
+ //\r
+ // Write a useful comment to the output makefile so the user knows where\r
+ // the data came from.\r
+ //\r
+ fprintf (MakeFptr, "#\n# Tool-generated list of include paths that are created\n");\r
+ fprintf (MakeFptr, "# from the list of include paths in the [includes.*] sections\n");\r
+ fprintf (MakeFptr, "# of the component INF file.\n#\n");\r
+\r
+ //\r
+ // We use this a lot here, so get the value only once.\r
+ //\r
+ Processor = GetSymbolValue (PROCESSOR);\r
+ //\r
+ // If they're using an override source path, then add OverridePath and\r
+ // OverridePath\$(PROCESSOR) to the list of include paths.\r
+ //\r
+ OverridePath = GetSymbolValue (SOURCE_OVERRIDE_PATH);\r
+ if (OverridePath != NULL) {\r
+ fprintf (MakeFptr, "INC = $(INC) -I %s\n", OverridePath);\r
+ fprintf (MakeFptr, "INC = $(INC) -I %s\\%s \n", OverridePath, Processor);\r
+ }\r
+ //\r
+ // Try for an [includes.$(PROCESSOR).$(PLATFORM)]\r
+ //\r
+ Cptr = GetSymbolValue (PLATFORM);\r
+ if (Cptr != NULL) {\r
+ sprintf (Str, "%s.%s.%s", INCLUDE_SECTION_NAME, Processor, Cptr);\r
+ ProcessIncludesSectionSingle (ComponentFile, MakeFptr, Str);\r
+ }\r
+ //\r
+ // Now the [includes.$(PROCESSOR)] section\r
+ //\r
+ sprintf (Str, "%s.%s", INCLUDE_SECTION_NAME, Processor);\r
+ ProcessIncludesSectionSingle (ComponentFile, MakeFptr, Str);\r
+\r
+ //\r
+ // Now the [includes.common] section\r
+ //\r
+ sprintf (Str, "%s.%s", INCLUDE_SECTION_NAME, COMMON_SECTION_NAME);\r
+ ProcessIncludesSectionSingle (ComponentFile, MakeFptr, Str);\r
+\r
+ //\r
+ // Done\r
+ //\r
+ fprintf (MakeFptr, "\n");\r
+ return STATUS_SUCCESS;\r
+}\r
+//\r
+// Process one of the [includes.xxx] sections to create a list of all\r
+// the include paths.\r
+//\r
+static\r
+int\r
+ProcessIncludesSectionSingle (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr,\r
+ INT8 *SectionName\r
+ )\r
+{\r
+ INT8 *Cptr;\r
+ SECTION *TempSect;\r
+ INT8 Str[MAX_LINE_LEN];\r
+ INT8 ExpandedLine[MAX_LINE_LEN];\r
+ INT8 *Processor;\r
+\r
+ TempSect = DSCFileFindSection (ComponentFile, SectionName);\r
+ if (TempSect != NULL) {\r
+ //\r
+ // Add processor subdirectory on every include path\r
+ //\r
+ Processor = GetSymbolValue (PROCESSOR);\r
+ //\r
+ // Copy lines directly\r
+ //\r
+ while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r
+ ExpandSymbols (Str, ExpandedLine, sizeof (ExpandedLine), 0);\r
+ Cptr = StripLine (ExpandedLine);\r
+ //\r
+ // Don't process blank lines\r
+ //\r
+ if (*Cptr) {\r
+ //\r
+ // Strip off trailing slash\r
+ //\r
+ if (Cptr[strlen (Cptr) - 1] == '\\') {\r
+ Cptr[strlen (Cptr) - 1] = 0;\r
+ }\r
+ //\r
+ // Special case of ".". Replace it with source path\r
+ // and the rest of the line (for .\$(PROCESSOR))\r
+ //\r
+ if (*Cptr == '.') {\r
+ //\r
+ // Handle case of just a "."\r
+ //\r
+ if (Cptr[1] == 0) {\r
+ fprintf (MakeFptr, "INC = $(INC) -I $(SOURCE_DIR)\n");\r
+ fprintf (\r
+ MakeFptr,\r
+ "INC = $(INC) -I $(SOURCE_DIR)\\%s \n",\r
+ Processor\r
+ );\r
+ } else {\r
+ //\r
+ // Handle case of ".\path\path\path" or "..\path\path\path"\r
+ //\r
+ fprintf (\r
+ MakeFptr,\r
+ "INC = $(INC) -I $(SOURCE_DIR)\\%s \n",\r
+ Cptr\r
+ );\r
+ fprintf (\r
+ MakeFptr,\r
+ "INC = $(INC) -I $(SOURCE_DIR)\\%s\\%s \n",\r
+ Cptr,\r
+ Processor\r
+ );\r
+ }\r
+ } else if ((Cptr[1] != ':') && isalpha (*Cptr)) {\r
+ fprintf (MakeFptr, "INC = $(INC) -I $(EFI_SOURCE)\\%s \n", Cptr);\r
+ fprintf (\r
+ MakeFptr,\r
+ "INC = $(INC) -I $(EFI_SOURCE)\\%s\\%s \n",\r
+ Cptr,\r
+ Processor\r
+ );\r
+ } else {\r
+ //\r
+ // The line is something like: $(EFI_SOURCE)\dxe\include. Add it to\r
+ // the existing $(INC) definition. Add user includes before any\r
+ // other existing paths.\r
+ //\r
+ fprintf (MakeFptr, "INC = $(INC) -I %s \n", Cptr);\r
+ fprintf (MakeFptr, "INC = $(INC) -I %s\\%s \n", Cptr, Processor);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+static\r
+int\r
+ProcessSourceFiles (\r
+ DSC_FILE *DSCFile,\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr,\r
+ UINT32 Mode\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+\r
+ Process the [sources.common], [sources.$(PROCESSOR)], and \r
+ [sources.$(PROCESSOR).$(PLATFORM] sections of the component\r
+ description file and write the appropriate build commands out to the \r
+ component's makefile. If $(SOURCE_SELECT) is defined, then it overrides\r
+ the source selections. We use this functionality for SMM.\r
+ \r
+Arguments:\r
+\r
+ ComponentFile - section info on the component file being processed\r
+ MakeFptr - file pointer to the component' makefile we're creating\r
+ DSCFile - section info on the description file we're processing\r
+ Mode - to write build commands, or just create a list\r
+ of sources.\r
+\r
+Returns:\r
+\r
+ Always STATUS_SUCCESS right now, since the sections are optional.\r
+ \r
+--*/\r
+{\r
+ INT8 Str[MAX_LINE_LEN];\r
+ INT8 *Processor;\r
+ INT8 *Platform;\r
+ INT8 *SourceSelect;\r
+ INT8 *CStart;\r
+ INT8 *CEnd;\r
+ INT8 CSave;\r
+ INT8 *CopySourceSelect;\r
+\r
+ if (Mode & SOURCE_MODE_SOURCE_FILES) {\r
+ //\r
+ // Write a useful comment to the output makefile so the user knows where\r
+ // the data came from.\r
+ //\r
+ fprintf (MakeFptr, "#\n# Tool-generated list of source files that are created\n");\r
+ fprintf (MakeFptr, "# from the list of source files in the [sources.*] sections\n");\r
+ fprintf (MakeFptr, "# of the component INF file.\n#\n");\r
+ }\r
+ \r
+ //\r
+ // We use this a lot here, so get the value only once.\r
+ //\r
+ Processor = GetSymbolValue (PROCESSOR);\r
+ //\r
+ // See if they defined SOURCE_SELECT=xxx,yyy in which case we'll\r
+ // select each [sources.xxx] and [sources.yyy] files and process\r
+ // them.\r
+ //\r
+ SourceSelect = GetSymbolValue (SOURCE_SELECT);\r
+\r
+ if (SourceSelect != NULL) {\r
+ //\r
+ // Make a copy of the string and break it up (comma-separated) and\r
+ // select each [sources.*] file from the INF.\r
+ //\r
+ CopySourceSelect = (INT8 *) malloc (strlen (SourceSelect) + 1);\r
+ if (CopySourceSelect == NULL) {\r
+ Error (NULL, 0, 0, NULL, "failed to allocate memory");\r
+ return STATUS_ERROR;\r
+ }\r
+\r
+ strcpy (CopySourceSelect, SourceSelect);\r
+ CStart = CopySourceSelect;\r
+ CEnd = CStart;\r
+ while (*CStart) {\r
+ CEnd = CStart + 1;\r
+ while (*CEnd && *CEnd != ',') {\r
+ CEnd++;\r
+ }\r
+\r
+ CSave = *CEnd;\r
+ *CEnd = 0;\r
+ sprintf (Str, "%s.%s", SOURCES_SECTION_NAME, CStart);\r
+ ProcessSourceFilesSection (DSCFile, ComponentFile, MakeFptr, Str, Mode);\r
+ //\r
+ // Restore the terminator and advance\r
+ //\r
+ *CEnd = CSave;\r
+ CStart = CEnd;\r
+ if (*CStart) {\r
+ CStart++;\r
+ }\r
+ }\r
+\r
+ free (CopySourceSelect);\r
+\r
+ } else {\r
+ //\r
+ // Process all the [sources.common] source files to make them build\r
+ //\r
+ sprintf (Str, "%s.%s", SOURCES_SECTION_NAME, COMMON_SECTION_NAME);\r
+ ProcessSourceFilesSection (DSCFile, ComponentFile, MakeFptr, Str, Mode);\r
+ //\r
+ // Now process the [sources.$(PROCESSOR)] files.\r
+ //\r
+ sprintf (Str, "sources.%s", Processor);\r
+ ProcessSourceFilesSection (DSCFile, ComponentFile, MakeFptr, Str, Mode);\r
+ //\r
+ // Now process the [sources.$(PROCESSOR).$(PLATFORM)] files.\r
+ //\r
+ Platform = GetSymbolValue (PLATFORM);\r
+ if (Platform != NULL) {\r
+ sprintf (Str, "sources.%s.%s", Processor, Platform);\r
+ ProcessSourceFilesSection (DSCFile, ComponentFile, MakeFptr, Str, Mode);\r
+ }\r
+ }\r
+\r
+ fprintf (MakeFptr, "\n");\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+/*++\r
+\r
+Routine Description:\r
+ Given a source file line from an INF file, parse it to see if there are\r
+ any defines on it. If so, then add them to the symbol table.\r
+ Also, terminate the line after the file name.\r
+ \r
+Arguments:\r
+ SourceFileLine - a line from a [sources.?] section of the INF file. Likely\r
+ something like:\r
+ \r
+ MySourceFile.c BUILT_NAME=$(BUILD_DIR)\MySourceFile.obj\r
+\r
+Returns:\r
+ Nothing.\r
+ \r
+--*/\r
+static\r
+void\r
+AddFileSymbols (\r
+ INT8 *SourceFileLine\r
+ )\r
+{\r
+ int Len;\r
+ //\r
+ // Skip spaces\r
+ //\r
+ for (; *SourceFileLine && isspace (*SourceFileLine); SourceFileLine++)\r
+ ;\r
+ for (; *SourceFileLine && !isspace (*SourceFileLine); SourceFileLine++)\r
+ ;\r
+ if (*SourceFileLine) {\r
+ *SourceFileLine = 0;\r
+ SourceFileLine++;\r
+ //\r
+ // AddSymbol() will parse it for us, and return the length. Keep calling\r
+ // it until it reports an error or is done.\r
+ //\r
+ do {\r
+ Len = AddSymbol (SourceFileLine, NULL, SYM_FILE);\r
+ SourceFileLine += Len;\r
+ } while (Len > 0);\r
+ }\r
+}\r
+//\r
+// Process a single section of source files in the component INF file\r
+//\r
+static\r
+int\r
+ProcessSourceFilesSection (\r
+ DSC_FILE *DSCFile,\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr,\r
+ INT8 *SectionName,\r
+ UINT32 Mode\r
+ )\r
+{\r
+ INT8 *Cptr;\r
+ INT8 FileName[MAX_EXP_LINE_LEN];\r
+ INT8 FilePath[MAX_PATH];\r
+ INT8 TempFileName[MAX_PATH];\r
+ SECTION *TempSect;\r
+ INT8 Str[MAX_LINE_LEN];\r
+ INT8 *Processor;\r
+ INT8 *OverridePath;\r
+ FILE *FPtr;\r
+\r
+ TempSect = DSCFileFindSection (ComponentFile, SectionName);\r
+ if (TempSect != NULL) {\r
+ Processor = GetSymbolValue (PROCESSOR);\r
+ while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r
+ Cptr = StripLine (Str);\r
+ //\r
+ // Don't process blank lines\r
+ //\r
+ if (*Cptr) {\r
+ //\r
+ // Expand symbols in the filename, then parse the line for symbol\r
+ // definitions. AddFileSymbols() will null-terminate the line\r
+ // after the file name. Save a copy for override purposes, in which\r
+ // case we'll need to know the file name and path (in case it's in\r
+ // a subdirectory).\r
+ //\r
+ ExpandSymbols (Cptr, FileName, sizeof (FileName), 0);\r
+ AddFileSymbols (FileName);\r
+ //\r
+ // Set the SOURCE_FILE_NAME symbol. What we have now is the name of\r
+ // the file, relative to the location of the INF file. So prepend\r
+ // $(SOURCE_DIR) to it first.\r
+ //\r
+ if (IsAbsolutePath (FileName)) {\r
+ strcpy (TempFileName, FileName);\r
+ } else {\r
+ strcpy (TempFileName, "$(SOURCE_DIR)\\");\r
+ strcat (TempFileName, FileName);\r
+ }\r
+ AddSymbol (SOURCE_FILE_NAME, TempFileName, SYM_FILE | SYM_OVERWRITE);\r
+ //\r
+ // Extract path information from the source file and set internal\r
+ // variable SOURCE_RELATIVE_PATH. Only do this if the path\r
+ // contains a backslash.\r
+ //\r
+ strcpy (FilePath, FileName);\r
+ for (Cptr = FilePath + strlen (FilePath) - 1; (Cptr > FilePath) && (*Cptr != '\\'); Cptr--)\r
+ ;\r
+ if (*Cptr == '\\') {\r
+ *(Cptr + 1) = 0;\r
+ AddSymbol (SOURCE_RELATIVE_PATH, FilePath, SYM_FILE);\r
+ }\r
+ //\r
+ // Define another internal symbol for the name of the file without\r
+ // the path and extension.\r
+ //\r
+ for (Cptr = FileName + strlen (FileName) - 1; (Cptr > FileName) && (*Cptr != '\\'); Cptr--)\r
+ ;\r
+ if (*Cptr == '\\') {\r
+ Cptr++;\r
+ }\r
+\r
+ strcpy (FilePath, Cptr);\r
+ //\r
+ // We now have a file name with no path information. Before we do anything else,\r
+ // see if OVERRIDE_PATH is set, and if so, see if file $(OVERRIDE_PATH)FileName\r
+ // exists. If it does, then recursive call this function to use the override file\r
+ // instead of the one from the INF file.\r
+ //\r
+ if (IsAbsolutePath (FileName)) {\r
+ OverridePath = NULL;\r
+ } else {\r
+ OverridePath = GetSymbolValue (SOURCE_OVERRIDE_PATH);\r
+ }\r
+ if (OverridePath != NULL) {\r
+ //\r
+ // See if the file exists. If it does, reset the SOURCE_FILE_NAME symbol.\r
+ //\r
+ strcpy (TempFileName, OverridePath);\r
+ strcat (TempFileName, "\\");\r
+ strcat (TempFileName, FileName);\r
+ if ((FPtr = fopen (TempFileName, "rb")) != NULL) {\r
+ fclose (FPtr);\r
+ AddSymbol (SOURCE_FILE_NAME, TempFileName, SYM_FILE | SYM_OVERWRITE);\r
+ //\r
+ // Print a message. This function is called to create build commands\r
+ // for source files, and to create a macro of all source files. Therefore\r
+ // do this check so we don't print the override message multiple times.\r
+ //\r
+ if (Mode & SOURCE_MODE_BUILD_COMMANDS) {\r
+ fprintf (stdout, "Override: %s\n", TempFileName);\r
+ }\r
+ } else {\r
+ //\r
+ // Set override path to null to use as a flag below\r
+ //\r
+ OverridePath = NULL;\r
+ }\r
+ }\r
+\r
+ //\r
+ // Start at the end and work back\r
+ //\r
+ for (Cptr = FilePath + strlen (FilePath) - 1; (Cptr > FilePath) && (*Cptr != '\\') && (*Cptr != '.'); Cptr--)\r
+ ;\r
+ if (*Cptr == '.') {\r
+ *Cptr = 0;\r
+ AddSymbol (SOURCE_FILE_EXTENSION, Cptr + 1, SYM_FILE);\r
+ }\r
+\r
+ AddSymbol (SOURCE_BASE_NAME, FilePath, SYM_FILE);\r
+ //\r
+ // If we're just creating the SOURCE_FILES macro, then write the\r
+ // file name out to the makefile.\r
+ //\r
+ if (Mode & SOURCE_MODE_SOURCE_FILES) {\r
+ //\r
+ // If we're processing an override file, then use the file name as-is\r
+ //\r
+ if (OverridePath != NULL) {\r
+ //\r
+ // SOURCE_FILES = $(SOURCE_FILES) c:\Path\ThisFile.c\r
+ //\r
+ fprintf (MakeFptr, "SOURCE_FILES = $(SOURCE_FILES) %s\n", TempFileName);\r
+ } else if (IsAbsolutePath (FileName)) {\r
+ //\r
+ // For Absolute path, don't print $(SOURCE_FILE) directory.\r
+ //\r
+ fprintf (MakeFptr, "SOURCE_FILES = $(SOURCE_FILES) %s\n", FileName);\r
+ } else {\r
+ //\r
+ // SOURCE_FILES = $(SOURCE_FILES) $(SOURCE_DIR)\ThisFile.c\r
+ //\r
+ fprintf (MakeFptr, "SOURCE_FILES = $(SOURCE_FILES) $(SOURCE_DIR)\\%s\n", FileName);\r
+ }\r
+ } else if (Mode & SOURCE_MODE_BUILD_COMMANDS) {\r
+ //\r
+ // Write the build commands for this file per the build commands\r
+ // for this file type as defined in the description file.\r
+ // Also create the directory for it in the build path.\r
+ //\r
+ WriteCompileCommands (DSCFile, MakeFptr, FileName, Processor);\r
+ if (!IsAbsolutePath (FileName)) {\r
+ sprintf (Str, "%s\\%s", GetSymbolValue (DEST_DIR), FileName);\r
+ MakeFilePath (Str);\r
+ //\r
+ // Get all output directory for build output files.\r
+ //\r
+ Cptr = FileName + strlen (FileName) - 1;\r
+ for (; (Cptr > FileName) && (*Cptr != '\\'); Cptr--);\r
+ if (*Cptr == '\\') {\r
+ *Cptr = '\0';\r
+ AddModuleName (&gGlobals.OutdirList, FileName, NULL);\r
+ }\r
+ }\r
+ }\r
+ //\r
+ // Remove file-level symbols\r
+ //\r
+ RemoveFileSymbols ();\r
+ }\r
+ }\r
+ }\r
+\r
+ return STATUS_SUCCESS;\r
+}\r
+//\r
+// Process the INF [sources.*] sections and emit the OBJECTS = .....\r
+// lines to the component's makefile.\r
+//\r
+static\r
+int\r
+ProcessObjects (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr\r
+ )\r
+{\r
+ INT8 Str[MAX_LINE_LEN];\r
+ INT8 *Processor;\r
+ INT8 *Platform;\r
+ INT8 *SourceSelect;\r
+ INT8 *CStart;\r
+ INT8 *CEnd;\r
+ INT8 CSave;\r
+ INT8 *CopySourceSelect;\r
+ SYMBOL *TempSymbol;\r
+\r
+ //\r
+ // Write a useful comment to the output makefile so the user knows where\r
+ // the data came from.\r
+ //\r
+ fprintf (MakeFptr, "#\n# Tool-generated list of object files that are created\n");\r
+ fprintf (MakeFptr, "# from the list of source files in the [sources.*] sections\n");\r
+ fprintf (MakeFptr, "# of the component INF file.\n#\n");\r
+ //\r
+ // We use this a lot here, so get the value only once.\r
+ //\r
+ Processor = GetSymbolValue (PROCESSOR);\r
+ //\r
+ // Now define the OBJECTS variable and assign it to be all the object files we're going\r
+ // to create. Afterwards create a pseudo-target objects to let the user quickly just compile\r
+ // the source files. This means we need to process all the common objects and\r
+ // processor-specific objects again.\r
+ //\r
+ fprintf (MakeFptr, "OBJECTS = $(OBJECTS) ");\r
+ //\r
+ // See if they defined SOURCE_SELECT=xxx,yyy in which case well\r
+ // select each [sources.xxx] and [sources.yyy] files and process\r
+ // them.\r
+ //\r
+ SourceSelect = GetSymbolValue (SOURCE_SELECT);\r
+\r
+ if (SourceSelect != NULL) {\r
+ //\r
+ // Make a copy of the string and break it up (comma-separated) and\r
+ // select each [sources.*] file from the INF.\r
+ //\r
+ CopySourceSelect = (INT8 *) malloc (strlen (SourceSelect) + 1);\r
+ if (CopySourceSelect == NULL) {\r
+ Error (NULL, 0, 0, NULL, "failed to allocate memory");\r
+ return STATUS_ERROR;\r
+ }\r
+\r
+ strcpy (CopySourceSelect, SourceSelect);\r
+ CStart = CopySourceSelect;\r
+ CEnd = CStart;\r
+ while (*CStart) {\r
+ CEnd = CStart + 1;\r
+ while (*CEnd && *CEnd != ',') {\r
+ CEnd++;\r
+ }\r
+\r
+ CSave = *CEnd;\r
+ *CEnd = 0;\r
+ sprintf (Str, "%s.%s", SOURCES_SECTION_NAME, CStart);\r
+ ProcessObjectsSingle (ComponentFile, MakeFptr, Str);\r
+ //\r
+ // Restore the terminator and advance\r
+ //\r
+ *CEnd = CSave;\r
+ CStart = CEnd;\r
+ if (*CStart) {\r
+ CStart++;\r
+ }\r
+ }\r
+\r
+ free (CopySourceSelect);\r
+ \r
+ } else {\r
+ //\r
+ // Now process all the [sources.common] files and emit build commands for them\r
+ //\r
+ sprintf (Str, "%s.%s", SOURCES_SECTION_NAME, COMMON_SECTION_NAME);\r
+ if (ProcessObjectsSingle (ComponentFile, MakeFptr, Str) != STATUS_SUCCESS) {\r
+ Warning (GetSymbolValue (INF_FILENAME), 1, 0, NULL, "no [%s] section found in component description", Str);\r
+ }\r
+ //\r
+ // Now process any processor-specific source files in [sources.$(PROCESSOR)]\r
+ //\r
+ sprintf (Str, "%s.%s", SOURCES_SECTION_NAME, Processor);\r
+ ProcessObjectsSingle (ComponentFile, MakeFptr, Str);\r
+\r
+ //\r
+ // Now process any [sources.$(PROCESSOR).$(PLATFORM)] files\r
+ //\r
+ Platform = GetSymbolValue (PLATFORM);\r
+ if (Platform != NULL) {\r
+ sprintf (Str, "sources.%s.%s", Processor, Platform);\r
+ ProcessObjectsSingle (ComponentFile, MakeFptr, Str);\r
+ }\r
+ }\r
+\r
+ fprintf (MakeFptr, "\n\n");\r
+\r
+ //\r
+ // Write a useful comment to the output makefile so the user knows where\r
+ // the data came from.\r
+ //\r
+ fprintf (MakeFptr, "#\n# Tool-generated list of dest output dirs that are created\n");\r
+ fprintf (MakeFptr, "# from the list of source files in the [sources.*] sections\n");\r
+ fprintf (MakeFptr, "# of the component INF file.\n#\n");\r
+ //\r
+ // Create output directory list \r
+ // for clean target to delete all build output files.\r
+ //\r
+ fprintf (MakeFptr, "DEST_OUTPUT_DIRS = $(%s) ", DEST_DIR);\r
+\r
+ TempSymbol = gGlobals.OutdirList;\r
+ while (TempSymbol != NULL) {\r
+ fprintf (MakeFptr, "\\\n $(%s)\\%s ", \r
+ DEST_DIR, TempSymbol->Name);\r
+ TempSymbol = TempSymbol->Next;\r
+ }\r
+ fprintf (MakeFptr, "\n\n");\r
+ \r
+ //\r
+ // clean up for the next module\r
+ //\r
+ FreeSymbols (gGlobals.OutdirList);\r
+ gGlobals.OutdirList = NULL;\r
+\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+static\r
+INT8 *\r
+BuiltFileExtension (\r
+ INT8 *SourceFileName\r
+ )\r
+{\r
+ int i;\r
+ INT8 *Cptr;\r
+ //\r
+ // Find the dot in the filename extension\r
+ //\r
+ for (Cptr = SourceFileName + strlen (SourceFileName) - 1;\r
+ (Cptr > SourceFileName) && (*Cptr != '\\') && (*Cptr != '.');\r
+ Cptr--\r
+ ) {\r
+ //\r
+ // Do nothing\r
+ //\r
+ }\r
+\r
+ if (*Cptr != '.') {\r
+ return NULL;\r
+ }\r
+ //\r
+ // Look through our list of known file types and return a pointer to\r
+ // its built file extension.\r
+ //\r
+ for (i = 0; mFileTypes[i].Extension != NULL; i++) {\r
+ if (_stricmp (Cptr, mFileTypes[i].Extension) == 0) {\r
+ return mFileTypes[i].BuiltExtension;\r
+ }\r
+ }\r
+\r
+ return NULL;\r
+}\r
+\r
+int\r
+ProcessObjectsSingle (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr,\r
+ INT8 *SectionName\r
+ )\r
+{\r
+ INT8 *Cptr;\r
+ INT8 *Cptr2;\r
+ INT8 Str[MAX_LINE_LEN];\r
+ INT8 FileName[MAX_EXP_LINE_LEN];\r
+ SECTION *TempSect;\r
+\r
+ TempSect = DSCFileFindSection (ComponentFile, SectionName);\r
+ if (TempSect != NULL) {\r
+ while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r
+ Cptr = StripLine (Str);\r
+ //\r
+ // Don't process blank lines\r
+ //\r
+ if (*Cptr) {\r
+ //\r
+ // Expand symbols then create the output filename. We'll do a lookup\r
+ // on the source file's extension to determine what the extension of\r
+ // the built version of the file is. For example, .c -> .obj.\r
+ //\r
+ if (!IsIncludeFile (Cptr)) {\r
+ ExpandSymbols (Cptr, FileName, sizeof (FileName), 0);\r
+ Cptr2 = BuiltFileExtension (FileName);\r
+ if (Cptr2 != NULL) {\r
+ SetFileExtension (FileName, Cptr2);\r
+ if (!IsAbsolutePath (FileName)) {\r
+ fprintf (MakeFptr, "\\\n $(%s)\\%s ", DEST_DIR, FileName);\r
+ } else {\r
+ fprintf (MakeFptr, "\\\n %s ", FileName);\r
+ }\r
+ }\r
+ }\r
+ }\r
+ }\r
+ } else {\r
+ return STATUS_WARNING;\r
+ }\r
+\r
+ return STATUS_SUCCESS;\r
+}\r
+//\r
+// Process all [libraries.*] sections in the component INF file to create a\r
+// macro to the component's output makefile: LIBS = Lib1 Lib2, ...\r
+//\r
+static\r
+int\r
+ProcessLibs (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr\r
+ )\r
+{\r
+ INT8 Str[MAX_LINE_LEN];\r
+ INT8 *Processor;\r
+ INT8 *Platform;\r
+\r
+ //\r
+ // Print a useful comment to the component's makefile so the user knows\r
+ // where the data came from.\r
+ //\r
+ fprintf (MakeFptr, "#\n# Tool-generated list of libraries that are generated\n");\r
+ fprintf (MakeFptr, "# from the list of libraries listed in the [libraries.*] sections\n");\r
+ fprintf (MakeFptr, "# of the component INF file.\n#\n");\r
+ \r
+ fprintf (MakeFptr, "LIBS = $(LIBS) ");\r
+ \r
+ Processor = GetSymbolValue (PROCESSOR);\r
+ //\r
+ // Process [libraries.common] files\r
+ //\r
+ sprintf (Str, "%s.%s", LIBRARIES_SECTION_NAME, COMMON_SECTION_NAME);\r
+ ProcessLibsSingle (ComponentFile, MakeFptr, Str);\r
+ //\r
+ // Process the [libraries.$(PROCESSOR)] libraries to define "LIBS = x.lib y.lib..."\r
+ //\r
+ sprintf (Str, "%s.%s", LIBRARIES_SECTION_NAME, Processor);\r
+ ProcessLibsSingle (ComponentFile, MakeFptr, Str);\r
+ //\r
+ // Now process any [libraries.$(PROCESSOR).$(PLATFORM)] files\r
+ //\r
+ Platform = GetSymbolValue (PLATFORM);\r
+ if (Platform != NULL) {\r
+ sprintf (Str, "%s.%s.%s", LIBRARIES_SECTION_NAME, Processor, Platform);\r
+ ProcessLibsSingle (ComponentFile, MakeFptr, Str);\r
+ }\r
+ //\r
+ // Process any [libraries.platform] files\r
+ //\r
+ ProcessLibsSingle (ComponentFile, MakeFptr, LIBRARIES_PLATFORM_SECTION_NAME);\r
+\r
+ fprintf (MakeFptr, "\n\n");\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+static\r
+int\r
+ProcessLibsSingle (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr,\r
+ INT8 *SectionName\r
+ )\r
+{\r
+ INT8 *Cptr;\r
+ INT8 Str[MAX_LINE_LEN];\r
+ INT8 ExpandedLine[MAX_LINE_LEN];\r
+ SECTION *TempSect;\r
+\r
+ TempSect = DSCFileFindSection (ComponentFile, SectionName);\r
+ if (TempSect != NULL) {\r
+ while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r
+ ExpandSymbols (Str, ExpandedLine, sizeof (ExpandedLine), 0);\r
+ Cptr = StripLine (ExpandedLine);\r
+ //\r
+ // Don't process blank lines\r
+ //\r
+ if (*Cptr) {\r
+ if (Cptr[strlen (Cptr) - 4] != '.') {\r
+ fprintf (MakeFptr, " \\\n $(LIB_DIR)\\%s.lib", Cptr);\r
+ //\r
+ // Add lib dependency for single module build\r
+ //\r
+ fprintf (gGlobals.ModuleMakefileFptr, " %sbuild", Cptr);\r
+ } else {\r
+ fprintf (MakeFptr, " \\\n $(LIB_DIR)\\%s", Cptr);\r
+ //\r
+ // Add lib dependency for single module build\r
+ //\r
+ Cptr[strlen (Cptr) - 4] = 0;\r
+ fprintf (gGlobals.ModuleMakefileFptr, " %sbuild", Cptr);\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+static\r
+int\r
+ProcessIncludeFiles (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr\r
+ )\r
+{\r
+ INT8 Str[MAX_LINE_LEN];\r
+ INT8 *Processor;\r
+ INT8 *Platform;\r
+ INT8 *SourceSelect;\r
+ INT8 *CStart;\r
+ INT8 *CEnd;\r
+ INT8 CSave;\r
+ INT8 *CopySourceSelect;\r
+\r
+ //\r
+ // Print a useful comment to the output makefile so the user knows where\r
+ // the info came from\r
+ //\r
+ //fprintf (MakeFptr, "#\n# Tool-generated include dependencies from any include files in the\n");\r
+ //fprintf (MakeFptr, "# [sources.*] sections of the component INF file\n#\n");\r
+\r
+ Processor = GetSymbolValue (PROCESSOR);\r
+ \r
+ //\r
+ // See if they defined SOURCE_SELECT=xxx,yyy in which case we'll\r
+ // select each [sources.xxx] and [sources.yyy] files and process\r
+ // them.\r
+ //\r
+ SourceSelect = GetSymbolValue (SOURCE_SELECT);\r
+\r
+ if (SourceSelect != NULL) {\r
+ //\r
+ // Make a copy of the string and break it up (comma-separated) and\r
+ // select each [sources.*] file from the INF.\r
+ //\r
+ CopySourceSelect = (INT8 *) malloc (strlen (SourceSelect) + 1);\r
+ if (CopySourceSelect == NULL) {\r
+ Error (NULL, 0, 0, NULL, "failed to allocate memory");\r
+ return STATUS_ERROR;\r
+ }\r
+\r
+ strcpy (CopySourceSelect, SourceSelect);\r
+ CStart = CopySourceSelect;\r
+ CEnd = CStart;\r
+ while (*CStart) {\r
+ CEnd = CStart + 1;\r
+ while (*CEnd && *CEnd != ',') {\r
+ CEnd++;\r
+ }\r
+\r
+ CSave = *CEnd;\r
+ *CEnd = 0;\r
+ sprintf (Str, "%s.%s", SOURCES_SECTION_NAME, CStart);\r
+ ProcessIncludeFilesSingle (ComponentFile, MakeFptr, Str);\r
+ //\r
+ // Restore the terminator and advance\r
+ //\r
+ *CEnd = CSave;\r
+ CStart = CEnd;\r
+ if (*CStart) {\r
+ CStart++;\r
+ }\r
+ }\r
+\r
+ free (CopySourceSelect);\r
+\r
+ } else {\r
+ //\r
+ // Find all the include files in the [sources.common] sections.\r
+ //\r
+ sprintf (Str, "%s.%s", SOURCES_SECTION_NAME, COMMON_SECTION_NAME);\r
+ ProcessIncludeFilesSingle (ComponentFile, MakeFptr, Str);\r
+ //\r
+ // Now process the [sources.$(PROCESSOR)] files.\r
+ //\r
+ sprintf (Str, "%s.%s", SOURCES_SECTION_NAME, Processor);\r
+ ProcessIncludeFilesSingle (ComponentFile, MakeFptr, Str);\r
+ //\r
+ // Now process the [sources.$(PROCESSOR).$(PLATFORM)] files.\r
+ //\r
+ Platform = GetSymbolValue (PLATFORM);\r
+ if (Platform != NULL) {\r
+ sprintf (Str, "sources.%s.%s", Processor, Platform);\r
+ ProcessIncludeFilesSingle (ComponentFile, MakeFptr, Str);\r
+ }\r
+ }\r
+ \r
+ fprintf (MakeFptr, "\n");\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+int\r
+ProcessIncludeFilesSingle (\r
+ DSC_FILE *ComponentFile,\r
+ FILE *MakeFptr,\r
+ INT8 *SectionName\r
+ )\r
+{\r
+ INT8 *Cptr;\r
+ INT8 FileName[MAX_EXP_LINE_LEN];\r
+ INT8 TempFileName[MAX_PATH];\r
+ SECTION *TempSect;\r
+ INT8 Str[MAX_LINE_LEN];\r
+ INT8 *OverridePath;\r
+ FILE *FPtr;\r
+\r
+ TempSect = DSCFileFindSection (ComponentFile, SectionName);\r
+ if (TempSect != NULL) {\r
+ //\r
+ // See if the SOURCE_OVERRIDE_PATH has been set. If it has, and\r
+ // they have an include file that is overridden, then add the path\r
+ // to it to the list of include paths (prepend).\r
+ //\r
+ OverridePath = GetSymbolValue (SOURCE_OVERRIDE_PATH);\r
+ while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r
+ Cptr = StripLine (Str);\r
+ //\r
+ // Don't process blank lines\r
+ //\r
+ if (*Cptr) {\r
+ //\r
+ // Expand symbols in the filename, then get its parts\r
+ //\r
+ ExpandSymbols (Cptr, FileName, sizeof (FileName), 0);\r
+ AddFileSymbols (FileName);\r
+ if (IsIncludeFile (FileName)) {\r
+ if ((OverridePath != NULL) && (!IsAbsolutePath (FileName))) {\r
+ strcpy (TempFileName, OverridePath);\r
+ strcat (TempFileName, "\\");\r
+ strcat (TempFileName, FileName);\r
+ if ((FPtr = fopen (TempFileName, "rb")) != NULL) {\r
+ fclose (FPtr);\r
+ //\r
+ // Null-terminate the file name at the last backslash and add that\r
+ // to the beginning of the list of include paths.\r
+ //\r
+ for (Cptr = TempFileName + strlen (TempFileName) - 1;\r
+ (Cptr >= TempFileName) && (*Cptr != '\\') && (*Cptr != '/');\r
+ Cptr--\r
+ )\r
+ ;\r
+ if (Cptr >= TempFileName) {\r
+ *Cptr = 0;\r
+ }\r
+\r
+ fprintf (MakeFptr, "INC = -I %s $(INC)\n", TempFileName);\r
+ }\r
+ }\r
+ //\r
+ // If absolute path already, don't prepend source directory\r
+ //\r
+ // if (IsAbsolutePath (FileName)) {\r
+ // fprintf (MakeFptr, "INC_DEPS = $(INC_DEPS) %s\n", FileName);\r
+ // } else {\r
+ // fprintf (MakeFptr, "INC_DEPS = $(INC_DEPS) $(SOURCE_DIR)\\%s\n", FileName);\r
+ // }\r
+ }\r
+\r
+ RemoveFileSymbols ();\r
+ }\r
+ }\r
+ }\r
+\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+static\r
+void\r
+FreeFileParts (\r
+ FILE_NAME_PARTS *FP\r
+ )\r
+{\r
+ if (FP != NULL) {\r
+ if (FP->Path != NULL) {\r
+ free (FP->Path);\r
+ }\r
+\r
+ if (FP->BaseName != NULL) {\r
+ free (FP->BaseName);\r
+ }\r
+\r
+ if (FP->Extension != NULL) {\r
+ free (FP->Extension);\r
+ }\r
+ }\r
+}\r
+\r
+static\r
+FILE_NAME_PARTS *\r
+GetFileParts (\r
+ INT8 *FileName\r
+ )\r
+{\r
+ FILE_NAME_PARTS *FP;\r
+ INT8 *Cptr;\r
+ INT8 CopyFileName[MAX_PATH];\r
+ INT8 *FileNamePtr;\r
+\r
+ strcpy (CopyFileName, FileName);\r
+ FP = (FILE_NAME_PARTS *) malloc (sizeof (FILE_NAME_PARTS));\r
+ if (FP == NULL) {\r
+ Error (NULL, 0, 0, NULL, "failed to allocate memory");\r
+ return NULL;\r
+ }\r
+\r
+ memset ((INT8 *) FP, 0, sizeof (FILE_NAME_PARTS));\r
+ //\r
+ // Get extension code\r
+ //\r
+ FP->ExtensionCode = GetSourceFileType (CopyFileName);\r
+ //\r
+ // Get drive if there\r
+ //\r
+ FileNamePtr = CopyFileName;\r
+ if (FileNamePtr[1] == ':') {\r
+ FP->Drive[0] = FileNamePtr[0];\r
+ FP->Drive[1] = ':';\r
+ FileNamePtr += 2;\r
+ }\r
+ //\r
+ // Start at the end and work back\r
+ //\r
+ for (Cptr = FileNamePtr + strlen (FileNamePtr) - 1; (Cptr > FileNamePtr) && (*Cptr != '.'); Cptr--)\r
+ ;\r
+\r
+ if (*Cptr == '.') {\r
+ //\r
+ // Don't copy the dot\r
+ //\r
+ FP->Extension = (char *) malloc (strlen (Cptr));\r
+ strcpy (FP->Extension, Cptr + 1);\r
+ *Cptr = 0;\r
+ Cptr--;\r
+ StripTrailingSpaces (FP->Extension);\r
+ } else {\r
+ //\r
+ // Create empty string for extension\r
+ //\r
+ FP->Extension = (char *) malloc (1);\r
+ FP->Extension[0] = 0;\r
+ }\r
+ //\r
+ // Now back up and get the base name (include the preceding '\' or '/')\r
+ //\r
+ for (; (Cptr > FileNamePtr) && (*Cptr != '\\') && (*Cptr != '/'); Cptr--)\r
+ ;\r
+ FP->BaseName = (char *) malloc (strlen (Cptr) + 1);\r
+ strcpy (FP->BaseName, Cptr);\r
+ *Cptr = 0;\r
+ Cptr--;\r
+ //\r
+ // Rest is path\r
+ //\r
+ if (Cptr >= FileNamePtr) {\r
+ Cptr = FileNamePtr;\r
+ FP->Path = (char *) malloc (strlen (Cptr) + 1);\r
+ strcpy (FP->Path, Cptr);\r
+ } else {\r
+ FP->Path = (char *) malloc (1);\r
+ FP->Path[0] = 0;\r
+ }\r
+\r
+ return FP;\r
+}\r
+\r
+/*****************************************************************************\r
+******************************************************************************/\r
+static\r
+int\r
+WriteCommonMakefile (\r
+ DSC_FILE *DSCFile,\r
+ FILE *MakeFptr,\r
+ INT8 *Processor\r
+ )\r
+{\r
+ INT8 InLine[MAX_LINE_LEN];\r
+ INT8 OutLine[MAX_EXP_LINE_LEN];\r
+ SECTION *Sect;\r
+ INT8 *Sym;\r
+ int i;\r
+ //\r
+ // Don't mess up the original file pointer, since we're processing it at a higher\r
+ // level.\r
+ //\r
+ DSCFileSavePosition (DSCFile);\r
+ //\r
+ // Write the header to the file\r
+ //\r
+ for (i = 0; MakefileHeader[i] != NULL; i++) {\r
+ fprintf (MakeFptr, "%s\n", MakefileHeader[i]);\r
+ }\r
+\r
+ fprintf (MakeFptr, "#\n# Hard-coded defines output by the tool\n#\n");\r
+ //\r
+ // First write the basics to the component's makefile. These includes\r
+ // EFI_SOURCE, BIN_DIR, OUT_DIR, LIB_DIR, SOURCE_DIR, DEST_DIR.\r
+ //\r
+ Sym = GetSymbolValue (EFI_SOURCE);\r
+ fprintf (MakeFptr, "%s = %s\n", EFI_SOURCE, Sym);\r
+ Sym = GetSymbolValue (BUILD_DIR);\r
+ fprintf (MakeFptr, "%s = %s\n", BUILD_DIR, Sym);\r
+ Sym = GetSymbolValue (BIN_DIR);\r
+ fprintf (MakeFptr, "%s = %s\n", BIN_DIR, Sym);\r
+ Sym = GetSymbolValue (OUT_DIR);\r
+ fprintf (MakeFptr, "%s = %s\n", OUT_DIR, Sym);\r
+ Sym = GetSymbolValue (LIB_DIR);\r
+ fprintf (MakeFptr, "%s = %s\n", LIB_DIR, Sym);\r
+ Sym = GetSymbolValue (SOURCE_DIR);\r
+ fprintf (MakeFptr, "%s = %s\n", SOURCE_DIR, Sym);\r
+ Sym = GetSymbolValue (DEST_DIR);\r
+ fprintf (MakeFptr, "%s = %s\n", DEST_DIR, Sym);\r
+ fprintf (MakeFptr, "\n");\r
+ //\r
+ // If there was a [makefile.common] section in the description file,\r
+ // copy it (after symbol expansion) to the output file.\r
+ //\r
+ sprintf (InLine, "%s.%s", MAKEFILE_SECTION_NAME, COMMON_SECTION_NAME);\r
+ Sect = DSCFileFindSection (DSCFile, InLine);\r
+ if (Sect != NULL) {\r
+ //\r
+ // fprintf (MakeFptr, "# From the [makefile.common] section of the DSC file\n");\r
+ // Read lines, expand, then dump out\r
+ //\r
+ while (DSCFileGetLine (DSCFile, InLine, sizeof (InLine)) != NULL) {\r
+ //\r
+ // Replace symbols\r
+ //\r
+ ExpandSymbols (InLine, OutLine, sizeof (OutLine), EXPANDMODE_RECURSIVE);\r
+ fprintf (MakeFptr, OutLine);\r
+ }\r
+ }\r
+ //\r
+ // If there was a [makefile.platform] section in the description file,\r
+ // copy it (after symbol expansion) to the output file.\r
+ //\r
+ sprintf (InLine, "%s.%s", MAKEFILE_SECTION_NAME, "Platform");\r
+ Sect = DSCFileFindSection (DSCFile, InLine);\r
+ if (Sect != NULL) {\r
+ //\r
+ // Read lines, expand, then dump out\r
+ //\r
+ while (DSCFileGetLine (DSCFile, InLine, sizeof (InLine)) != NULL) {\r
+ //\r
+ // Replace symbols\r
+ //\r
+ ExpandSymbols (InLine, OutLine, sizeof (OutLine), EXPANDMODE_RECURSIVE);\r
+ fprintf (MakeFptr, OutLine);\r
+ }\r
+ }\r
+ //\r
+ // Do the same for any [makefile.$(PROCESSOR)]\r
+ //\r
+ sprintf (InLine, "%s.%s", MAKEFILE_SECTION_NAME, Processor);\r
+ Sect = DSCFileFindSection (DSCFile, InLine);\r
+ if (Sect != NULL) {\r
+ //\r
+ // Read lines, expand, then dump out\r
+ //\r
+ while (DSCFileGetLine (DSCFile, InLine, sizeof (InLine)) != NULL) {\r
+ ExpandSymbols (InLine, OutLine, sizeof (OutLine), EXPANDMODE_RECURSIVE);\r
+ fprintf (MakeFptr, OutLine);\r
+ }\r
+ }\r
+ //\r
+ // Same thing for [makefile.$(PROCESSOR).$(PLATFORM)]\r
+ //\r
+ Sym = GetSymbolValue (PLATFORM);\r
+ if (Sym != NULL) {\r
+ sprintf (InLine, "%s.%s.%s", MAKEFILE_SECTION_NAME, Processor, Sym);\r
+ Sect = DSCFileFindSection (DSCFile, InLine);\r
+ if (Sect != NULL) {\r
+ //\r
+ // Read lines, expand, then dump out\r
+ //\r
+ while (DSCFileGetLine (DSCFile, InLine, sizeof (InLine)) != NULL) {\r
+ ExpandSymbols (InLine, OutLine, sizeof (OutLine), EXPANDMODE_RECURSIVE);\r
+ fprintf (MakeFptr, OutLine);\r
+ }\r
+ }\r
+ }\r
+ \r
+ fprintf (MakeFptr, "\n");\r
+ DSCFileRestorePosition (DSCFile);\r
+ return 0;\r
+}\r
+\r
+static\r
+int\r
+WriteComponentTypeBuildCommands (\r
+ DSC_FILE *DSCFile,\r
+ FILE *MakeFptr,\r
+ INT8 *SectionName\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ \r
+ Given a section name such as [build.ia32.library], find the section in\r
+ the description file and copy the build commands.\r
+\r
+Arguments:\r
+\r
+ DSCFile - section information on the main description file\r
+ MakeFptr - file pointer to the makefile we're writing to\r
+ SectionName - name of the section we're to copy out to the makefile.\r
+\r
+Returns:\r
+\r
+ Always successful, since the section may be optional.\r
+\r
+--*/\r
+{\r
+ SECTION *Sect;\r
+ INT8 InLine[MAX_LINE_LEN];\r
+ INT8 OutLine[MAX_EXP_LINE_LEN];\r
+ \r
+ //\r
+ // Don't mess up the original file pointer, since we're processing it at a higher\r
+ // level.\r
+ //\r
+ DSCFileSavePosition (DSCFile);\r
+ Sect = DSCFileFindSection (DSCFile, SectionName);\r
+ if (Sect != NULL) {\r
+ //\r
+ // Read lines, expand, then dump out\r
+ //\r
+ while (DSCFileGetLine (DSCFile, InLine, sizeof (InLine)) != NULL) {\r
+ ExpandSymbols (\r
+ InLine, \r
+ OutLine, \r
+ sizeof(OutLine), \r
+ EXPANDMODE_NO_DESTDIR | EXPANDMODE_NO_SOURCEDIR\r
+ );\r
+ fprintf (MakeFptr, OutLine);\r
+ }\r
+ } else {\r
+ Warning (\r
+ NULL,\r
+ 0,\r
+ 0,\r
+ GetSymbolValue (INF_FILENAME),\r
+ "no [%s] build commands found in DSC file for component",\r
+ SectionName\r
+ );\r
+ }\r
+\r
+ DSCFileRestorePosition (DSCFile);\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+/*****************************************************************************\r
+\r
+******************************************************************************/\r
+static\r
+int\r
+WriteCompileCommands (\r
+ DSC_FILE *DscFile,\r
+ FILE *MakeFptr,\r
+ INT8 *FileName,\r
+ INT8 *Processor\r
+ )\r
+{\r
+ FILE_NAME_PARTS *File;\r
+ SECTION *Sect;\r
+ INT8 BuildSectionName[40];\r
+ INT8 InLine[MAX_LINE_LEN];\r
+ INT8 OutLine[MAX_EXP_LINE_LEN];\r
+ INT8 *SourceCompileType;\r
+ char *CPtr;\r
+ char *CPtr2;\r
+ //\r
+ // Determine the filename, then chop it up into its parts\r
+ //\r
+ File = GetFileParts (FileName);\r
+ if (File != NULL) {\r
+ //\r
+ // Don't mess up the original file pointer, since we're processing it at a higher\r
+ // level.\r
+ //\r
+ DSCFileSavePosition (DscFile);\r
+ //\r
+ // Option 1: SOURCE_COMPILE_TYPE=MyCompileSection\r
+ // Find a section of that name from which to get the compile\r
+ // commands for this source file. \r
+ // Look for [compile.$(PROCESSOR).$(SOURCE_COMPILE_TYPE]\r
+ // Option 2: COMPILE_SELECT=.c=MyCCompile,.asm=MyAsm\r
+ // Find a [compile.$(PROCESSOR).MyCompile] section from which to\r
+ // get the compile commands for this source file. \r
+ // Look for [compile.$(PROCESSOR).MyCompile]\r
+ // Option 3: Look for standard section types to compile the file by extension.\r
+ // Look for [compile.$(PROCESSOR).<extension>]\r
+ //\r
+ Sect = NULL;\r
+ //\r
+ // Option 1 - use SOURCE_COMPILE_TYPE variable\r
+ //\r
+ SourceCompileType = GetSymbolValue (SOURCE_COMPILE_TYPE);\r
+ if (SourceCompileType != NULL) {\r
+ sprintf (BuildSectionName, "compile.%s.%s", Processor, SourceCompileType);\r
+ Sect = DSCFileFindSection (DscFile, BuildSectionName);\r
+ }\r
+ //\r
+ // Option 2 - use COMPILE_SELECT variable\r
+ //\r
+ if (Sect == NULL) {\r
+ SourceCompileType = GetSymbolValue (COMPILE_SELECT);\r
+ if (SourceCompileType != NULL) {\r
+ //\r
+ // Parse the variable, which looks like COMPILE_SELECT=.c=MyCCompiler;.asm=MyAsm;\r
+ // to find an entry with a matching file name extension. If you find one,\r
+ // then use that name to find the section name.\r
+ //\r
+ CPtr = SourceCompileType;\r
+ while (*CPtr && (Sect == NULL)) {\r
+ //\r
+ // See if we found a match with this source file name extension. File->Extension\r
+ // does not include the dot, so skip the dot in the COMPILE_SELECT variable if there\r
+ // is one.\r
+ //\r
+ if (*CPtr == '.') {\r
+ CPtr++;\r
+ }\r
+\r
+ if (_strnicmp (CPtr, File->Extension, strlen (File->Extension)) == 0) {\r
+ //\r
+ // Found a file name extension match -- extract the name from the variable, for\r
+ // example "MyCCompiler"\r
+ //\r
+ while (*CPtr && (*CPtr != '=')) {\r
+ CPtr++;\r
+ }\r
+\r
+ if ((*CPtr != '=') || (CPtr[1] == 0)) {\r
+ Error (NULL, 0, 0, SourceCompileType, "malformed COMPILE_SELECT variable");\r
+ break;\r
+ }\r
+\r
+ CPtr++;\r
+ sprintf (BuildSectionName, "compile.%s.", Processor);\r
+ for (CPtr2 = BuildSectionName + strlen (BuildSectionName);\r
+ *CPtr && (*CPtr != ',') && (*CPtr != ';');\r
+ CPtr++\r
+ ) {\r
+ *CPtr2 = *CPtr;\r
+ CPtr2++;\r
+ }\r
+\r
+ *CPtr2 = 0;\r
+ Sect = DSCFileFindSection (DscFile, BuildSectionName);\r
+ if (Sect == NULL) {\r
+ ParserError (\r
+ 0,\r
+ BuildSectionName,\r
+ "could not find section in DSC file - selected by COMPILE_SELECT variable"\r
+ );\r
+ }\r
+ }\r
+\r
+ //\r
+ // Skip to next file name extension in the COMPILE_SELECT variable\r
+ //\r
+ while (*CPtr && (*CPtr != ';') && (*CPtr != ',')) {\r
+ CPtr++;\r
+ }\r
+\r
+ if (*CPtr) {\r
+ CPtr++;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ //\r
+ // Option 3 - use "Compile.$(PROCESSOR).<Extension>" section\r
+ //\r
+ if (Sect == NULL) {\r
+ sprintf (BuildSectionName, "compile.%s.%s", Processor, File->Extension);\r
+ Sect = DSCFileFindSection (DscFile, BuildSectionName);\r
+ }\r
+ //\r
+ // Should have found something by now unless it's an include (.h) file\r
+ //\r
+ if (Sect != NULL) {\r
+ //\r
+ // Temporarily add a FILE variable to the global symbol table. Omit the\r
+ // extension.\r
+ //\r
+ sprintf (InLine, "%s%s%s", File->Drive, File->Path, File->BaseName);\r
+ AddSymbol ("FILE", InLine, SYM_OVERWRITE | SYM_LOCAL | SYM_FILENAME);\r
+ //\r
+ // Read lines, expand (except SOURCE_DIR and DEST_DIR), then dump out\r
+ //\r
+ while (DSCFileGetLine (DscFile, InLine, sizeof (InLine)) != NULL) {\r
+ ExpandSymbols (\r
+ InLine,\r
+ OutLine,\r
+ sizeof (OutLine),\r
+ EXPANDMODE_NO_DESTDIR | EXPANDMODE_NO_SOURCEDIR\r
+ );\r
+ fprintf (MakeFptr, OutLine);\r
+ }\r
+ fprintf (MakeFptr, "\n");\r
+ } else {\r
+ //\r
+ // Be nice and ignore include files\r
+ //\r
+ if (!IsIncludeFile (FileName)) {\r
+ Error (\r
+ NULL,\r
+ 0,\r
+ 0,\r
+ NULL,\r
+ "no compile commands section [%s] found in DSC file for %s",\r
+ BuildSectionName,\r
+ FileName\r
+ );\r
+ }\r
+ }\r
+\r
+ DSCFileRestorePosition (DscFile);\r
+ FreeFileParts (File);\r
+ }\r
+\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+/*****************************************************************************\r
+******************************************************************************/\r
+static\r
+int\r
+SetFileExtension (\r
+ INT8 *FileName,\r
+ INT8 *Extension\r
+ )\r
+{\r
+ INT8 *Cptr;\r
+\r
+ Cptr = FileName + strlen (FileName) - 1;\r
+ while ((Cptr > FileName) && (*Cptr != '.')) {\r
+ Cptr--;\r
+\r
+ }\r
+ //\r
+ // Better be a dot\r
+ //\r
+ if (*Cptr != '.') {\r
+ Message (2, "Missing filename extension: %s", FileName);\r
+ return STATUS_WARNING;\r
+ }\r
+\r
+ Cptr++;\r
+ if (*Extension == '.') {\r
+ Extension++;\r
+ }\r
+\r
+ strcpy (Cptr, Extension);\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+/*****************************************************************************\r
+******************************************************************************/\r
+int\r
+MakeFilePath (\r
+ INT8 *FileName\r
+ )\r
+{\r
+ INT8 *Cptr;\r
+ INT8 SavedChar;\r
+ INT8 BuildDir[MAX_PATH];\r
+ INT8 CopyFileName[MAX_PATH];\r
+\r
+ //\r
+ // Expand symbols in the filename\r
+ //\r
+ if (ExpandSymbols (FileName, CopyFileName, sizeof (CopyFileName), EXPANDMODE_NO_UNDEFS)) {\r
+ Error (NULL, 0, 0, NULL, "undefined symbols in file path: %s", FileName);\r
+ return STATUS_ERROR;\r
+ }\r
+ //\r
+ // Copy it back\r
+ //\r
+ strcpy (FileName, CopyFileName);\r
+ //\r
+ // To avoid creating $(BUILD_DIR) path, see if this path is the same as\r
+ // $(BUILD_DIR), and if it is, see if build dir exists and skip over that\r
+ // portion if it does\r
+ //\r
+ Cptr = GetSymbolValue (BUILD_DIR);\r
+ if (Cptr != NULL) {\r
+ if (_strnicmp (Cptr, FileName, strlen (Cptr)) == 0) {\r
+ //\r
+ // BUILD_DIR path. See if it exists\r
+ //\r
+ strcpy (BuildDir, FileName);\r
+ BuildDir[strlen (Cptr)] = 0;\r
+ if ((_mkdir (BuildDir) != 0) && (errno != EEXIST)) {\r
+ Cptr = FileName;\r
+ } else {\r
+ //\r
+ // Already done. Shortcut. Skip to next path so that we don't create\r
+ // the BUILD_DIR as well.\r
+ //\r
+ Cptr = FileName + strlen (Cptr);\r
+ if (*Cptr == '\\') {\r
+ Cptr++;\r
+ }\r
+ }\r
+ } else {\r
+ //\r
+ // Not build dir\r
+ //\r
+ Cptr = FileName;\r
+ }\r
+ } else {\r
+ Cptr = FileName;\r
+ }\r
+ //\r
+ // Create directories until done. Skip over "c:\" in the path if it exists\r
+ //\r
+ if (*Cptr && (*(Cptr + 1) == ':') && (*(Cptr + 2) == '\\')) {\r
+ Cptr += 3;\r
+ }\r
+\r
+ for (;;) {\r
+ for (; *Cptr && (*Cptr != '/') && (*Cptr != '\\'); Cptr++)\r
+ ;\r
+ if (*Cptr) {\r
+ SavedChar = *Cptr;\r
+ *Cptr = 0;\r
+ if ((_mkdir (FileName) != 0)) {\r
+ //\r
+ // Error (NULL, 0, 0, FileName, "failed to create directory");\r
+ // return 1;\r
+ //\r
+ }\r
+\r
+ *Cptr = SavedChar;\r
+ Cptr++;\r
+ } else {\r
+ break;\r
+ }\r
+ }\r
+\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+/*****************************************************************************\r
+******************************************************************************/\r
+int\r
+ExpandSymbols (\r
+ INT8 *SourceLine,\r
+ INT8 *DestLine,\r
+ int LineLen,\r
+ int ExpandMode\r
+ )\r
+{\r
+ static int NestDepth = 0;\r
+ INT8 *FromPtr;\r
+ INT8 *ToPtr;\r
+ INT8 *SaveStart;\r
+ INT8 *Cptr;\r
+ INT8 *value;\r
+ int Expanded;\r
+ int ExpandedCount;\r
+ INT8 *LocalDestLine;\r
+ STATUS Status;\r
+ int LocalLineLen;\r
+\r
+ NestDepth++;\r
+ Status = STATUS_SUCCESS;\r
+ LocalDestLine = (INT8 *) malloc (LineLen);\r
+ if (LocalDestLine == NULL) {\r
+ Error (__FILE__, __LINE__, 0, "application error", "memory allocation failed");\r
+ NestDepth = 0;\r
+ return STATUS_ERROR;\r
+ }\r
+\r
+ FromPtr = SourceLine;\r
+ ToPtr = LocalDestLine;\r
+ //\r
+ // Walk the entire line, replacing $(SYMBOL_NAME).\r
+ //\r
+ LocalLineLen = LineLen;\r
+ ExpandedCount = 0;\r
+ while (*FromPtr && (LocalLineLen > 0)) {\r
+ if ((*FromPtr == '$') && (*(FromPtr + 1) == '(')) {\r
+ //\r
+ // Save the start in case it's undefined, in which case we copy it as-is.\r
+ //\r
+ SaveStart = FromPtr;\r
+ Expanded = 0;\r
+ //\r
+ // Symbol expansion time. Find the end (no spaces allowed)\r
+ //\r
+ FromPtr += 2;\r
+ for (Cptr = FromPtr; *Cptr && (*Cptr != ')'); Cptr++)\r
+ ;\r
+ if (*Cptr) {\r
+ //\r
+ // Truncate the string at the closing parenthesis for ease-of-use.\r
+ // Then copy the string directly to the destination line in case we don't find\r
+ // a definition for it.\r
+ //\r
+ *Cptr = 0;\r
+ strcpy (ToPtr, SaveStart);\r
+ if ((_stricmp (SOURCE_DIR, FromPtr) == 0) && (ExpandMode & EXPANDMODE_NO_SOURCEDIR)) {\r
+ //\r
+ // excluded this expansion\r
+ //\r
+ } else if ((_stricmp (DEST_DIR, FromPtr) == 0) && (ExpandMode & EXPANDMODE_NO_DESTDIR)) {\r
+ //\r
+ // excluded this expansion\r
+ //\r
+ } else if ((value = GetSymbolValue (FromPtr)) != NULL) {\r
+ strcpy (ToPtr, value);\r
+ LocalLineLen -= strlen (value);\r
+ ToPtr += strlen (value);\r
+ Expanded = 1;\r
+ ExpandedCount++;\r
+ } else if (ExpandMode & EXPANDMODE_NO_UNDEFS) {\r
+ Error (NULL, 0, 0, "undefined symbol", "$(%s)", FromPtr);\r
+ Status = STATUS_ERROR;\r
+ goto Done;\r
+ }\r
+ \r
+ //\r
+ // Restore closing parenthesis, and advance to next character\r
+ //\r
+ *Cptr = ')';\r
+ if (!Expanded) {\r
+ FromPtr = SaveStart + 1;\r
+ ToPtr++;\r
+ } else {\r
+ FromPtr = Cptr + 1;\r
+ }\r
+ } else {\r
+ Error (NULL, 0, 0, SourceLine, "missing closing parenthesis on symbol");\r
+ strcpy (ToPtr, FromPtr);\r
+ Status = STATUS_WARNING;\r
+ goto Done;\r
+ }\r
+ } else {\r
+ *ToPtr = *FromPtr;\r
+ FromPtr++;\r
+ ToPtr++;\r
+ LocalLineLen--;\r
+ }\r
+ }\r
+\r
+ if (*FromPtr == 0) {\r
+ *ToPtr = 0;\r
+ }\r
+\r
+ //\r
+ // If we're in recursive mode, and we expanded at least one string successfully,\r
+ // then make a recursive call to try again.\r
+ //\r
+ if ((ExpandedCount != 0) && (Status == STATUS_SUCCESS) && (ExpandMode & EXPANDMODE_RECURSIVE) && (NestDepth < 2)) {\r
+ Status = ExpandSymbols (LocalDestLine, DestLine, LineLen, ExpandMode);\r
+ free (LocalDestLine);\r
+ NestDepth = 0;\r
+ return Status;\r
+ }\r
+\r
+Done:\r
+ if (Status != STATUS_ERROR) {\r
+ strcpy (DestLine, LocalDestLine);\r
+ }\r
+\r
+ NestDepth = 0;\r
+ free (LocalDestLine);\r
+ return Status;\r
+}\r
+\r
+INT8 *\r
+GetSymbolValue (\r
+ INT8 *SymbolName\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ \r
+ Look up a symbol in our symbol table.\r
+\r
+Arguments:\r
+\r
+ SymbolName - The name of symbol.\r
+\r
+Returns:\r
+\r
+ Pointer to the value of the symbol if found\r
+ NULL if the symbol is not found\r
+\r
+--*/\r
+{\r
+ SYMBOL *Symbol;\r
+\r
+ //\r
+ // Scan once for file-level symbols\r
+ //\r
+ Symbol = gGlobals.Symbol;\r
+ while (Symbol) {\r
+ if ((_stricmp (SymbolName, Symbol->Name) == 0) && (Symbol->Type & SYM_FILE)) {\r
+ return Symbol->Value;\r
+ }\r
+\r
+ Symbol = Symbol->Next;\r
+ }\r
+ //\r
+ // Scan once for local symbols\r
+ //\r
+ Symbol = gGlobals.Symbol;\r
+ while (Symbol) {\r
+ if ((_stricmp (SymbolName, Symbol->Name) == 0) && (Symbol->Type & SYM_LOCAL)) {\r
+ return Symbol->Value;\r
+ }\r
+\r
+ Symbol = Symbol->Next;\r
+ }\r
+ //\r
+ // No local value found. Scan for globals.\r
+ //\r
+ Symbol = gGlobals.Symbol;\r
+ while (Symbol) {\r
+ if ((_stricmp (SymbolName, Symbol->Name) == 0) && (Symbol->Type & SYM_GLOBAL)) {\r
+ return Symbol->Value;\r
+ }\r
+\r
+ Symbol = Symbol->Next;\r
+ }\r
+ //\r
+ // For backwards-compatibility, if it's "GUID", return FILE_GUID value\r
+ //\r
+ if (_stricmp (SymbolName, GUID) == 0) {\r
+ return GetSymbolValue (FILE_GUID);\r
+ }\r
+\r
+ return NULL;\r
+}\r
+\r
+static\r
+int\r
+RemoveLocalSymbols (\r
+ VOID\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ \r
+ Remove all local symbols from the symbol table. Local symbols are those\r
+ that are defined typically by the component's INF file.\r
+\r
+Arguments:\r
+\r
+ None.\r
+\r
+Returns:\r
+\r
+ Right now, never fails.\r
+\r
+--*/\r
+{\r
+ SYMBOL *Sym;\r
+ int FoundOne;\r
+\r
+ do {\r
+ FoundOne = 0;\r
+ Sym = gGlobals.Symbol;\r
+ while (Sym) {\r
+ if (Sym->Type & SYM_LOCAL) {\r
+ //\r
+ // Going to delete it out from under ourselves, so break and restart\r
+ //\r
+ FoundOne = 1;\r
+ RemoveSymbol (Sym->Name, SYM_LOCAL);\r
+ break;\r
+ }\r
+\r
+ Sym = Sym->Next;\r
+ }\r
+ } while (FoundOne);\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+static\r
+int\r
+RemoveFileSymbols (\r
+ VOID\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ \r
+ Remove all file-level symbols from the symbol table. File-level symbols are \r
+ those that are defined on a source file line in an INF file.\r
+\r
+Arguments:\r
+\r
+ None.\r
+\r
+Returns:\r
+\r
+ Right now, never fails.\r
+\r
+--*/\r
+{\r
+ SYMBOL *Sym;\r
+ int FoundOne;\r
+\r
+ do {\r
+ FoundOne = 0;\r
+ Sym = gGlobals.Symbol;\r
+ while (Sym) {\r
+ if (Sym->Type & SYM_FILE) {\r
+ //\r
+ // Going to delete it out from under ourselves, so break and restart\r
+ //\r
+ FoundOne = 1;\r
+ RemoveSymbol (Sym->Name, SYM_FILE);\r
+ break;\r
+ }\r
+\r
+ Sym = Sym->Next;\r
+ }\r
+ } while (FoundOne);\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+static\r
+STATUS\r
+ParseGuidDatabaseFile (\r
+ INT8 *FileName\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ This function parses a GUID-to-basename text file (perhaps output by\r
+ the GuidChk utility) to define additional symbols. The format of the \r
+ file should be:\r
+\r
+ 7BB28B99-61BB-11D5-9A5D-0090273FC14D EFI_DEFAULT_BMP_LOGO_GUID gEfiDefaultBmpLogoGuid\r
+ \r
+ This function parses the line and defines global symbol:\r
+\r
+ EFI_DEFAULT_BMP_LOGO_GUID=7BB28B99-61BB-11D5-9A5D-0090273FC14D \r
+ \r
+ This symbol (rather than the actual GUID) can then be used in INF files to \r
+ fix duplicate GUIDs\r
+\r
+Arguments:\r
+ FileName - the name of the file to parse.\r
+\r
+Returns:\r
+ STATUS_ERROR - could not open FileName\r
+ STATUS_SUCCESS - we opened the file\r
+\r
+--*/\r
+{\r
+ FILE *Fptr;\r
+ INT8 Line[100];\r
+ INT8 Guid[100];\r
+ INT8 DefineName[80];\r
+\r
+ Fptr = fopen (FileName, "r");\r
+ if (Fptr == NULL) {\r
+ Error (NULL, 0, 0, FileName, "failed to open input GUID database input file");\r
+ return STATUS_ERROR;\r
+ }\r
+\r
+ while (fgets (Line, sizeof (Line), Fptr) != NULL) {\r
+ //\r
+ // Get the GUID string, skip the defined name (EFI_XXX_GUID), and get the\r
+ // variable name (gWhateverProtocolGuid)\r
+ //\r
+ if (sscanf (Line, "%s %s %*s", Guid, DefineName) == 2) {\r
+ AddSymbol (DefineName, Guid, SYM_GLOBAL);\r
+ }\r
+ }\r
+\r
+ fclose (Fptr);\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+/*****************************************************************************\r
+\r
+ Returns:\r
+ 0 if successful standard add\r
+ length of the parsed string if passed in " name = value "\r
+ < 0 on error\r
+\r
+******************************************************************************/\r
+int\r
+AddSymbol (\r
+ INT8 *Name,\r
+ INT8 *Value,\r
+ int Mode\r
+ )\r
+{\r
+ SYMBOL *Symbol;\r
+ SYMBOL *NewSymbol;\r
+ int Len;\r
+ INT8 *Start;\r
+ INT8 *Cptr;\r
+ INT8 CSave1;\r
+ INT8 *SaveCptr1;\r
+ INT8 CSave2;\r
+ INT8 *SaveCptr2;\r
+ INT8 ShortName[MAX_PATH];\r
+\r
+ Len = 0;\r
+ SaveCptr1 = NULL;\r
+ CSave1 = 0;\r
+ SaveCptr2 = NULL;\r
+ CSave2 = 0;\r
+\r
+ ShortName[0] = 0;\r
+ //\r
+ // Mode better be local or global symbol\r
+ //\r
+ if ((Mode & (SYM_LOCAL | SYM_GLOBAL | SYM_FILE)) == 0) {\r
+ Error (NULL, 0, 0, "APP ERROR", "adding symbol '%s' that is not local, global, nor file level", Name);\r
+ return -1;\r
+ }\r
+ //\r
+ // If value pointer is null, then they passed us a line something like:\r
+ // varname = value, or simply var =\r
+ //\r
+ if (Value == NULL) {\r
+ Start = Name;\r
+ while (*Name && isspace (*Name)) {\r
+ Name++;\r
+\r
+ }\r
+\r
+ if (!*Name) {\r
+ return -1;\r
+ }\r
+ //\r
+ // Find the end of the name. Either space or a '='.\r
+ //\r
+ for (Value = Name; *Value && !isspace (*Value) && (*Value != '='); Value++)\r
+ ;\r
+ if (!*Value) {\r
+ return -1;\r
+ }\r
+ //\r
+ // Look for the '='\r
+ //\r
+ Cptr = Value;\r
+ while (*Value && (*Value != '=')) {\r
+ Value++;\r
+ }\r
+\r
+ if (!*Value) {\r
+ return -1;\r
+ }\r
+\r
+ //\r
+ // Now truncate the name\r
+ //\r
+ CSave1 = *Cptr;\r
+ SaveCptr1 = Cptr;\r
+ *Cptr = 0; \r
+\r
+ //\r
+ // Skip over the = and then any spaces\r
+ //\r
+ Value++;\r
+ while (*Value && isspace (*Value)) {\r
+ Value++;\r
+\r
+ }\r
+ //\r
+ // Find end of string, checking for quoted string\r
+ //\r
+ if (*Value == '\"') {\r
+ Value++;\r
+ for (Cptr = Value; *Cptr && *Cptr != '\"'; Cptr++)\r
+ ;\r
+ } else {\r
+ for (Cptr = Value; *Cptr && !isspace (*Cptr); Cptr++)\r
+ ;\r
+ }\r
+ //\r
+ // Null terminate the value string\r
+ //\r
+ if (*Cptr) {\r
+ Len = (int) (Cptr - Start) + 1;\r
+ CSave2 = *Cptr;\r
+ SaveCptr2 = Cptr;\r
+ *Cptr = 0;\r
+ } else {\r
+ Len = (int) (Cptr - Start);\r
+ }\r
+ }\r
+\r
+ //\r
+ // If file name or file path, and we're shortening, then print it\r
+ //\r
+ if ((Mode & (SYM_FILEPATH | SYM_FILENAME)) && (GetSymbolValue (SHORT_NAMES) != NULL)) {\r
+ if (GetShortPathName (Value, ShortName, sizeof (ShortName)) > 0) {\r
+ //\r
+ // fprintf (stdout, "String value '%s' shortened to '%s'\n",\r
+ // Value, ShortName);\r
+ //\r
+ Value = ShortName;\r
+ } else {\r
+ //\r
+ // fprintf (stdout, "WARNING: Failed to get short name for %s\n", Value);\r
+ //\r
+ }\r
+ }\r
+ //\r
+ // We now have a symbol name and a value. Look for an existing variable of\r
+ // the same type (global or local) and overwrite it.\r
+ //\r
+ Symbol = gGlobals.Symbol;\r
+ while (Symbol) {\r
+ //\r
+ // Check for symbol name match\r
+ //\r
+ if (_stricmp (Name, Symbol->Name) == 0) {\r
+ //\r
+ // See if this symbol is of the same type (global or local) as what\r
+ // they're requesting\r
+ //\r
+ if ((Symbol->Type & (SYM_LOCAL | SYM_GLOBAL)) == (Mode & (SYM_LOCAL | SYM_GLOBAL))) {\r
+ //\r
+ // Did they say we could overwrite it?\r
+ //\r
+ if (Mode & SYM_OVERWRITE) {\r
+ free (Symbol->Value);\r
+ Symbol->Value = (INT8 *) malloc (strlen (Value) + 1);\r
+ if (Symbol->Value == NULL) {\r
+ Error (NULL, 0, 0, NULL, "failed to allocate memory");\r
+ return -1;\r
+ }\r
+\r
+ strcpy (Symbol->Value, Value);\r
+ //\r
+ // If value == "NULL", then make it a 0-length string\r
+ //\r
+ if (_stricmp (Symbol->Value, "NULL") == 0) {\r
+ Symbol->Value[0] = 0;\r
+ }\r
+\r
+ return Len;\r
+ } else {\r
+ return STATUS_ERROR;\r
+ }\r
+ }\r
+ }\r
+\r
+ Symbol = Symbol->Next;\r
+ }\r
+ //\r
+ // Does not exist, create a new one\r
+ //\r
+ NewSymbol = (SYMBOL *) malloc (sizeof (SYMBOL));\r
+ if (NewSymbol == NULL) {\r
+ Error (NULL, 0, 0, NULL, "failed to allocate memory");\r
+ return -1;\r
+ }\r
+\r
+ memset ((INT8 *) NewSymbol, 0, sizeof (SYMBOL));\r
+ NewSymbol->Name = (INT8 *) malloc (strlen (Name) + 1);\r
+ NewSymbol->Value = (INT8 *) malloc (strlen (Value) + 1);\r
+ //\r
+ // Simply use the mode bits as the type.\r
+ //\r
+ NewSymbol->Type = Mode;\r
+ if ((NewSymbol->Name == NULL) || (NewSymbol->Value == NULL)) {\r
+ Error (NULL, 0, 0, NULL, "failed to allocate memory");\r
+ return -1;\r
+ }\r
+\r
+ strcpy (NewSymbol->Name, Name);\r
+ strcpy (NewSymbol->Value, Value);\r
+ //\r
+ // Remove trailing spaces\r
+ //\r
+ Cptr = NewSymbol->Value + strlen (NewSymbol->Value) - 1;\r
+ while (Cptr > NewSymbol->Value) {\r
+ if (isspace (*Cptr)) {\r
+ *Cptr = 0;\r
+ Cptr--;\r
+ } else {\r
+ break;\r
+ }\r
+ }\r
+ //\r
+ // Add it to the head of the list.\r
+ //\r
+ NewSymbol->Next = gGlobals.Symbol;\r
+ gGlobals.Symbol = NewSymbol;\r
+ //\r
+ // If value == "NULL", then make it a 0-length string\r
+ //\r
+ if (_stricmp (NewSymbol->Value, "NULL") == 0) {\r
+ NewSymbol->Value[0] = 0;\r
+ }\r
+ //\r
+ // Restore the terminator we inserted if they passed in var=value\r
+ //\r
+ if (SaveCptr1 != NULL) {\r
+ *SaveCptr1 = CSave1;\r
+ }\r
+ if (SaveCptr2 != NULL) {\r
+ *SaveCptr2 = CSave2;\r
+ }\r
+\r
+ return Len;\r
+}\r
+\r
+/*****************************************************************************\r
+******************************************************************************/\r
+static\r
+int\r
+RemoveSymbol (\r
+ INT8 *Name,\r
+ INT8 SymbolType\r
+ )\r
+{\r
+ SYMBOL *Symbol;\r
+ SYMBOL *PrevSymbol;\r
+\r
+ PrevSymbol = NULL;\r
+ Symbol = gGlobals.Symbol;\r
+ while (Symbol) {\r
+ if ((_stricmp (Name, Symbol->Name) == 0) && (Symbol->Type & SymbolType)) {\r
+ if (Symbol->Value) {\r
+ free (Symbol->Value);\r
+ }\r
+\r
+ free (Symbol->Name);\r
+ if (PrevSymbol) {\r
+ PrevSymbol->Next = Symbol->Next;\r
+ } else {\r
+ gGlobals.Symbol = Symbol->Next;\r
+ }\r
+\r
+ free (Symbol);\r
+ return STATUS_SUCCESS;\r
+ }\r
+\r
+ PrevSymbol = Symbol;\r
+ Symbol = Symbol->Next;\r
+ }\r
+\r
+ return STATUS_WARNING;\r
+}\r
+\r
+#if 0\r
+\r
+/*****************************************************************************\r
+******************************************************************************/\r
+static\r
+void\r
+FreeSections (\r
+ SECTION *Sect\r
+ )\r
+{\r
+ SECTION *Next;\r
+\r
+ while (Sect != NULL) {\r
+ Next = Sect->Next;\r
+ if (Sect->Name != NULL) {\r
+ delete[] Sect->Name;\r
+ }\r
+\r
+ delete Sect;\r
+ Sect = Next;\r
+ }\r
+}\r
+#endif\r
+\r
+/*****************************************************************************\r
+******************************************************************************/\r
+static\r
+INT8 *\r
+StripLine (\r
+ INT8 *Line\r
+ )\r
+{\r
+ INT8 *Cptr;\r
+ int Len;\r
+\r
+ Cptr = Line;\r
+ //\r
+ // Look for '#' comments in first character of line\r
+ //\r
+ if (*Cptr == '#') {\r
+ *Cptr = 0;\r
+ return Cptr;\r
+ }\r
+\r
+ while (isspace (*Cptr)) {\r
+ Cptr++;\r
+ }\r
+ //\r
+ // Hack off newlines\r
+ //\r
+ Len = strlen (Cptr);\r
+ if ((Len > 0) && (Cptr[Len - 1] == '\n')) {\r
+ Cptr[Len - 1] = 0;\r
+ }\r
+ //\r
+ // Hack off trailing spaces\r
+ //\r
+ StripTrailingSpaces (Cptr);\r
+ return Cptr;\r
+}\r
+\r
+/*****************************************************************************\r
+ FUNCTION: ProcessOptions()\r
+ \r
+ DESCRIPTION: Process the command-line options. \r
+******************************************************************************/\r
+static\r
+int\r
+ProcessOptions (\r
+ int Argc,\r
+ INT8 *Argv[]\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ \r
+ Process the command line options to this utility.\r
+\r
+Arguments:\r
+\r
+ Argc - Standard Argc.\r
+ Argv[] - Standard Argv.\r
+\r
+Returns:\r
+\r
+--*/\r
+{\r
+ INT8 *Cptr;\r
+ int FreeCwd;\r
+\r
+ //\r
+ // Clear out the options\r
+ //\r
+ memset ((INT8 *) &gGlobals, 0, sizeof (gGlobals));\r
+\r
+ Argc--;\r
+ Argv++;\r
+\r
+ if (Argc == 0) {\r
+ Usage ();\r
+ return STATUS_ERROR;\r
+ }\r
+ //\r
+ // Now process the arguments\r
+ //\r
+ while (Argc > 0) {\r
+\r
+ if ((Argv[0][0] == '-') || (Argv[0][0] == '/')) {\r
+ switch (Argv[0][1]) {\r
+ //\r
+ // -? or -h help option\r
+ //\r
+ case '?':\r
+ case 'h':\r
+ case 'H':\r
+ Usage ();\r
+ return STATUS_ERROR;\r
+\r
+ //\r
+ // /d symbol=name\r
+ //\r
+ case 'd':\r
+ case 'D':\r
+ //\r
+ // Skip to next arg\r
+ //\r
+ Argc--;\r
+ Argv++;\r
+ if (Argc == 0) {\r
+ Argv--;\r
+ Error (NULL, 0, 0, NULL, "missing symbol definition with %c%c", Argv[0][0], Argv[0][1]);\r
+ return STATUS_ERROR;\r
+ } else {\r
+ if (AddSymbol (Argv[0], NULL, SYM_OVERWRITE | SYM_GLOBAL) <= 0) {\r
+ Warning (NULL, 0, 0, Argv[0], "failed to add symbol: %s");\r
+ }\r
+ }\r
+ break;\r
+\r
+ //\r
+ // output makefile name\r
+ //\r
+ case 'm':\r
+ case 'M':\r
+ //\r
+ // Skip to next arg\r
+ //\r
+ Argc--;\r
+ Argv++;\r
+ if (Argc == 0) {\r
+ Argv--;\r
+ Error (NULL, 0, 0, Argv[0], "missing output makefile name with option");\r
+ Usage ();\r
+ return STATUS_ERROR;\r
+ } else {\r
+ strcpy (gGlobals.MakefileName, Argv[0]);\r
+ }\r
+ break;\r
+\r
+ //\r
+ // Print a cross-reference file containing guid/basename/processor\r
+ //\r
+ case 'x':\r
+ case 'X':\r
+ //\r
+ // Skip to next arg\r
+ //\r
+ Argc--;\r
+ Argv++;\r
+ if (Argc == 0) {\r
+ Argv--;\r
+ Error (NULL, 0, 0, Argv[0], "missing cross-reference output filename with option");\r
+ Usage ();\r
+ return STATUS_ERROR;\r
+ } else {\r
+ strcpy (gGlobals.XRefFileName, Argv[0]);\r
+ }\r
+ break;\r
+\r
+ //\r
+ // GUID database file to preparse\r
+ //\r
+ case 'g':\r
+ case 'G':\r
+ //\r
+ // Skip to next arg\r
+ //\r
+ Argc--;\r
+ Argv++;\r
+ if (Argc == 0) {\r
+ Argv--;\r
+ Error (NULL, 0, 0, Argv[0], "missing input GUID database filename with option");\r
+ Usage ();\r
+ return STATUS_ERROR;\r
+ } else {\r
+ strcpy (gGlobals.GuidDatabaseFileName, Argv[0]);\r
+ }\r
+ break;\r
+\r
+ case 'v':\r
+ case 'V':\r
+ gGlobals.Verbose = 1;\r
+ break;\r
+\r
+ default:\r
+ Error (NULL, 0, 0, Argv[0], "unrecognized option");\r
+ return STATUS_ERROR;\r
+ }\r
+ } else {\r
+ break;\r
+ }\r
+\r
+ Argc--;\r
+ Argv++;\r
+ }\r
+ //\r
+ // Must be at least one arg left\r
+ //\r
+ if (Argc > 0) {\r
+ gGlobals.DscFilename = Argv[0];\r
+ }\r
+\r
+ if (gGlobals.DscFilename == NULL) {\r
+ Error (NULL, 0, 0, NULL, "must specify DSC filename on command line");\r
+ return STATUS_ERROR;\r
+ }\r
+ //\r
+ // Make a global symbol for the DSC filename\r
+ //\r
+ AddSymbol (DSC_FILENAME, gGlobals.DscFilename, SYM_GLOBAL | SYM_FILENAME);\r
+ //\r
+ // If no output makefile specified, take the default\r
+ //\r
+ if (gGlobals.MakefileName[0] == 0) {\r
+ strcpy (gGlobals.MakefileName, MAKEFILE_OUT_NAME);\r
+ }\r
+ //\r
+ // Get the current working directory and use it for the build directory.\r
+ // Only do this if they have not defined it on the command line. Do the\r
+ // same for the bin dir, output dir, and library directory.\r
+ //\r
+ Cptr = GetSymbolValue (BUILD_DIR);\r
+ if (Cptr == NULL) {\r
+ Cptr = _getcwd (NULL, 0);\r
+ FreeCwd = 1;\r
+ AddSymbol (BUILD_DIR, Cptr, SYM_OVERWRITE | SYM_GLOBAL | SYM_FILEPATH);\r
+ } else {\r
+ FreeCwd = 0;\r
+ }\r
+\r
+ if (FreeCwd) {\r
+ free (Cptr);\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+/*****************************************************************************\r
+******************************************************************************/\r
+static\r
+SYMBOL *\r
+FreeSymbols (\r
+ SYMBOL *Syms\r
+ )\r
+{\r
+ SYMBOL *Next;\r
+ while (Syms) {\r
+\r
+ if (Syms->Name != NULL) {\r
+ free (Syms->Name);\r
+ }\r
+\r
+ if (Syms->Value != NULL) {\r
+ free (Syms->Value);\r
+ }\r
+\r
+ Next = Syms->Next;\r
+ free (Syms);\r
+ Syms = Next;\r
+ }\r
+\r
+ return Syms;\r
+}\r
+\r
+/*****************************************************************************\r
+******************************************************************************/\r
+static\r
+int\r
+GetSourceFileType (\r
+ INT8 *FileName\r
+ )\r
+{\r
+ INT8 *Cptr;\r
+ int len;\r
+ int i;\r
+\r
+ len = strlen (FileName);\r
+ if (len == 0) {\r
+ return FILETYPE_UNKNOWN;\r
+\r
+ }\r
+\r
+ Cptr = FileName + len - 1;\r
+ while ((*Cptr != '.') && (Cptr >= FileName)) {\r
+ Cptr--;\r
+\r
+ }\r
+\r
+ if (*Cptr == '.') {\r
+\r
+ for (i = 0; mFileTypes[i].Extension != NULL; i++) {\r
+ len = strlen (mFileTypes[i].Extension);\r
+ if (_strnicmp (mFileTypes[i].Extension, Cptr, len) == 0) {\r
+ if ((*(Cptr + len) == 0) || isspace (*(Cptr + len))) {\r
+ return mFileTypes[i].FileType;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ return FILETYPE_UNKNOWN;\r
+}\r
+//\r
+// Determine if a given file is a standard include file. If we don't know,\r
+// then assume it's not.\r
+//\r
+static\r
+int\r
+IsIncludeFile (\r
+ INT8 *FileName\r
+ )\r
+{\r
+ INT8 *Cptr;\r
+ int len;\r
+ int i;\r
+\r
+ len = strlen (FileName);\r
+ if (len == 0) {\r
+ return 0;\r
+ }\r
+\r
+ Cptr = FileName + len - 1;\r
+ while ((*Cptr != '.') && (Cptr >= FileName)) {\r
+ Cptr--;\r
+ }\r
+\r
+ if (*Cptr == '.') {\r
+ //\r
+ // Now go through the list of filename extensions and try to find\r
+ // a match for this file extension.\r
+ //\r
+ for (i = 0; mFileTypes[i].Extension != NULL; i++) {\r
+ len = strlen (mFileTypes[i].Extension);\r
+ if (_strnicmp (mFileTypes[i].Extension, Cptr, len) == 0) {\r
+ //\r
+ // Make sure that's all there is to the filename extension.\r
+ //\r
+ if ((*(Cptr + len) == 0) || isspace (*(Cptr + len))) {\r
+ return mFileTypes[i].FileFlags & FILE_FLAG_INCLUDE;\r
+ }\r
+ }\r
+ }\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+/*****************************************************************************\r
+******************************************************************************/\r
+static\r
+void\r
+StripTrailingSpaces (\r
+ INT8 *Str\r
+ )\r
+{\r
+ INT8 *Cptr;\r
+ Cptr = Str + strlen (Str) - 1;\r
+ while (Cptr > Str) {\r
+ if (isspace (*Cptr)) {\r
+ *Cptr = 0;\r
+ Cptr--;\r
+ } else {\r
+ break;\r
+ }\r
+ }\r
+}\r
+\r
+/*****************************************************************************\r
+******************************************************************************/\r
+static\r
+int\r
+GetEfiSource (\r
+ VOID\r
+ )\r
+{\r
+ INT8 *EfiSource;\r
+\r
+ //\r
+ // Don't set it if the user specified it on the command line.\r
+ //\r
+ EfiSource = GetSymbolValue (EFI_SOURCE);\r
+ if ( EfiSource != NULL) {\r
+ if (EfiSource[strlen (EfiSource) - 1] == '\\') {\r
+ EfiSource[strlen (EfiSource) - 1] = 0;\r
+ } \r
+ return STATUS_SUCCESS;\r
+ }\r
+\r
+ //\r
+ // Get the environmental variable setting of EFI_SOURCE. \r
+ //\r
+ EfiSource = getenv (EFI_SOURCE);\r
+ if (EfiSource != NULL) {\r
+ if (EfiSource[strlen (EfiSource) - 1] == '\\') {\r
+ EfiSource[strlen (EfiSource) - 1] = 0;\r
+ }\r
+ AddSymbol (EFI_SOURCE, EfiSource, SYM_GLOBAL | SYM_FILEPATH); \r
+ return STATUS_SUCCESS;\r
+ }\r
+\r
+ Error (NULL, 0, 0, NULL, "could not determine EFI_SOURCE");\r
+ return STATUS_ERROR;\r
+}\r
+\r
+void\r
+Message (\r
+ UINT32 PrintMask,\r
+ INT8 *Fmt,\r
+ ...\r
+ )\r
+{\r
+ INT8 Line[MAX_LINE_LEN];\r
+ va_list List;\r
+\r
+ va_start (List, Fmt);\r
+ vsprintf (Line, Fmt, List);\r
+ if (PrintMask & gGlobals.Verbose) {\r
+ fprintf (stdout, "%s\n", Line);\r
+ }\r
+\r
+ va_end (List);\r
+}\r
+\r
+static\r
+void\r
+Usage (\r
+ VOID\r
+ )\r
+{\r
+ int i;\r
+ static const INT8 *Help[] = {\r
+ "Usage: ProcessDsc {options} [Dsc Filename]",\r
+ " Options:",\r
+ " -d var=value to define symbol 'var' to 'value'",\r
+ " -v for verbose mode",\r
+ " -g filename to preparse GUID listing file",\r
+ " -x filename to create a cross-reference file",\r
+ NULL\r
+ };\r
+ for (i = 0; Help[i] != NULL; i++) {\r
+ fprintf (stdout, "%s\n", Help[i]);\r
+ }\r
+}\r
+\r
+/*++\r
+\r
+Routine Description:\r
+ \r
+ Process the [defines] section in the DSC file.\r
+\r
+Arguments:\r
+\r
+ DscFile - pointer to the DSCFile class that contains the relevant info.\r
+\r
+Returns:\r
+\r
+ 0 if not necessarily an absolute path\r
+ 1 otherwise\r
+\r
+--*/\r
+static\r
+int\r
+ProcessDSCDefinesSection (\r
+ DSC_FILE *DscFile\r
+ )\r
+{\r
+ INT8 Line[MAX_LINE_LEN];\r
+ INT8 Line2[MAX_EXP_LINE_LEN];\r
+ INT8 *Cptr;\r
+ SECTION *Sect;\r
+\r
+ //\r
+ // Look for a [defines] section and process it\r
+ //\r
+ Sect = DSCFileFindSection (DscFile, DEFINES_SECTION_NAME);\r
+ if (Sect == NULL) {\r
+ return STATUS_ERROR;\r
+ }\r
+ //\r
+ // Read lines while they're valid\r
+ //\r
+ while (DSCFileGetLine (DscFile, Line, sizeof (Line)) != NULL) {\r
+ //\r
+ // Expand symbols on the line\r
+ //\r
+ if (ExpandSymbols (Line, Line2, sizeof (Line2), 0)) {\r
+ return STATUS_ERROR;\r
+ }\r
+ //\r
+ // Strip the line\r
+ //\r
+ Cptr = StripLine (Line2);\r
+ if (*Cptr) {\r
+ //\r
+ // Make the assignment\r
+ //\r
+ AddSymbol (Line2, NULL, SYM_OVERWRITE | SYM_GLOBAL);\r
+ }\r
+ }\r
+\r
+ return STATUS_SUCCESS;\r
+}\r
+\r
+int\r
+IsAbsolutePath (\r
+ char *FileName\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ \r
+ Determine if a given filename contains the full path information.\r
+\r
+Arguments:\r
+\r
+ FileName - the name of the file, with symbol expanded.\r
+\r
+Returns:\r
+\r
+ 0 if not necessarily an absolute path\r
+ 1 otherwise\r
+\r
+--*/\r
+{\r
+ //\r
+ // If the first character is a-z, and the second character is a colon, then\r
+ // it is an absolute path.\r
+ //\r
+ if (isalpha (FileName[0]) && (FileName[1] == ':')) {\r
+ return 1;\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+SMART_FILE *\r
+SmartOpen (\r
+ char *FileName\r
+ )\r
+{\r
+ SMART_FILE *SmartFile;\r
+ FILE *Fptr;\r
+ int FileSize;\r
+ \r
+ SmartFile = malloc (sizeof (SMART_FILE));\r
+ if (SmartFile == NULL) { \r
+ return NULL;\r
+ }\r
+ memset (SmartFile, 0, sizeof (SMART_FILE));\r
+ \r
+ SmartFile->FileName = malloc (strlen (FileName) + 1);\r
+ if (SmartFile->FileName == NULL){\r
+ SmartFree (SmartFile); \r
+ return NULL;\r
+ }\r
+ strcpy (SmartFile->FileName, FileName);\r
+\r
+ if ((Fptr = fopen (FileName, "r")) != NULL) {\r
+ fseek (Fptr, 0, SEEK_END);\r
+ FileSize = ftell (Fptr);\r
+ fseek (Fptr, 0, SEEK_SET);\r
+ SmartFile->FileContent = malloc (FileSize + 1);\r
+ if (SmartFile->FileContent != NULL) {\r
+ memset (SmartFile->FileContent, 0, FileSize + 1);\r
+ //\r
+ // Usually FileLength < FileSize, because in text mode, carriage return¨Clinefeed\r
+ // combinations are translated into single linefeeds on input\r
+ // \r
+ SmartFile->FileLength = fread (SmartFile->FileContent, sizeof(char), FileSize, Fptr);\r
+ }\r
+ fclose (Fptr);\r
+ }\r
+ \r
+ //\r
+ // No previous output file content, re-create the file\r
+ //\r
+ if (SmartFile->FileContent == NULL) {\r
+ if ((SmartFile->FilePtr = fopen (FileName, "w")) == NULL) {\r
+ SmartFree (SmartFile);\r
+ return NULL;\r
+ } \r
+ }\r
+ \r
+ return SmartFile;\r
+}\r
+\r
+int\r
+SmartWrite (\r
+ SMART_FILE *SmartFile,\r
+ char *String\r
+ )\r
+{\r
+ int StrLen;\r
+ \r
+ if (SmartFile->FilePtr != NULL) {\r
+ return fprintf (SmartFile->FilePtr, "%s", String);\r
+ } else {\r
+ StrLen = strlen (String);\r
+ if ((StrLen > SmartFile->FileLength - SmartFile->FilePosition) || \r
+ (_strnicmp (&SmartFile->FileContent[SmartFile->FilePosition], String, StrLen) != 0)) {\r
+ //\r
+ // file changed, need to re-create.\r
+ //\r
+ if ((SmartFile->FilePtr = fopen (SmartFile->FileName, "w")) == NULL) {\r
+ Error (NULL, 0, 0, SmartFile->FileName, "could not open file for writing when SmartWrite");\r
+ return -1;\r
+ } else {\r
+ SmartFile->FileContent[SmartFile->FilePosition] = 0;\r
+ fprintf (SmartFile->FilePtr, "%s%s", SmartFile->FileContent, String);\r
+ return StrLen;\r
+ } \r
+ } else {\r
+ SmartFile->FilePosition += StrLen;\r
+ return StrLen;\r
+ }\r
+ }\r
+}\r
+\r
+void\r
+SmartClose (\r
+ SMART_FILE *SmartFile\r
+ )\r
+{\r
+ if ((SmartFile->FilePtr == NULL) && (SmartFile->FilePosition < SmartFile->FileLength)) {\r
+ //\r
+ // The new file is smaller than before, re-create it.\r
+ //\r
+ if ((SmartFile->FilePtr = fopen (SmartFile->FileName, "w")) == NULL) {\r
+ Error (NULL, 0, 0, SmartFile->FileName, "could not open file for writing when SmartClose");\r
+ } else {\r
+ SmartFile->FileContent[SmartFile->FilePosition] = 0;\r
+ fprintf (SmartFile->FilePtr, "%s", SmartFile->FileContent);\r
+ }\r
+ }\r
+ \r
+ SmartFree(SmartFile);\r
+}\r
+ \r
+static\r
+void\r
+SmartFree (\r
+ SMART_FILE *SmartFile\r
+ )\r
+{\r
+ if (SmartFile == NULL) {\r
+ return;\r
+ }\r
+ \r
+ if (SmartFile->FileName != NULL ) {\r
+ free (SmartFile->FileName);\r
+ }\r
+ \r
+ if (SmartFile->FileContent != NULL ) {\r
+ free (SmartFile->FileContent);\r
+ }\r
+\r
+ if (SmartFile->FilePtr != NULL ) {\r
+ fclose (SmartFile->FilePtr);\r
+ } \r
+\r
+ free (SmartFile);\r
+ \r
+ return;\r
+}\r
+\r
+static \r
+int\r
+AddModuleName (\r
+ SYMBOL **SymbolList,\r
+ INT8 *ModuleName,\r
+ INT8 *InfName\r
+ )\r
+/*++\r
+\r
+Routine Description:\r
+ \r
+ Add module name in the global module list. \r
+ For the same module names, it is only added once.\r
+\r
+Arguments:\r
+ SymbolList : add name into this list\r
+ ModuleName : point to one module name char string.\r
+ InfName : point to this module inf file name with path.\r
+\r
+Returns:\r
+\r
+ 0 : Successfully add input name into the global list.\r
+ other value : allocate memory failed.\r
+\r
+--*/\r
+{\r
+ SYMBOL *CurrentSymbol;\r
+ SYMBOL *LastSymbol;\r
+ \r
+ //\r
+ // Get the global module list.\r
+ //\r
+ CurrentSymbol = *SymbolList;\r
+ LastSymbol = *SymbolList;\r
+ \r
+ //\r
+ // Search whether this module name has been added into the global list.\r
+ //\r
+ while (CurrentSymbol != NULL) {\r
+ if (_stricmp (CurrentSymbol->Name, ModuleName) == 0) {\r
+ if ((CurrentSymbol->Value == NULL) && (InfName == NULL)) {\r
+ break;\r
+ } else if ((CurrentSymbol->Value != NULL) && (InfName != NULL) && \\r
+ (_stricmp (CurrentSymbol->Value, InfName) == 0)) {\r
+ break;\r
+ }\r
+ }\r
+ LastSymbol = CurrentSymbol;\r
+ CurrentSymbol = CurrentSymbol->Next;\r
+ }\r
+ \r
+ //\r
+ // Add new module name in list.\r
+ //\r
+ if (CurrentSymbol == NULL) {\r
+ CurrentSymbol = (SYMBOL *) malloc (sizeof (SYMBOL));\r
+ if (CurrentSymbol == NULL) {\r
+ Error (NULL, 0, 0, NULL, "failed to allocate memory");\r
+ return -1;\r
+ }\r
+ memset ((INT8 *) CurrentSymbol, 0, sizeof (SYMBOL));\r
+\r
+ if (ModuleName != NULL) {\r
+ CurrentSymbol->Name = (INT8 *) malloc (strlen (ModuleName) + 1);\r
+ strcpy (CurrentSymbol->Name, ModuleName);\r
+ }\r
+\r
+ if (InfName != NULL) {\r
+ CurrentSymbol->Value = (INT8 *) malloc (strlen (InfName) + 1);\r
+ strcpy (CurrentSymbol->Value, InfName);\r
+ }\r
+ \r
+ if (LastSymbol == NULL) { \r
+ *SymbolList = CurrentSymbol;\r
+ } else {\r
+ LastSymbol->Next = CurrentSymbol;\r
+ }\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r