processdsc.c

来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 2,398 行 · 第 1/5 页

C
2,398
字号
/*++

Copyright (c) 2004 - 2006, Intel Corporation                                                         
All rights reserved. This program and the accompanying materials                          
are licensed and made available under the terms and conditions of the BSD License         
which accompanies this distribution.  The full text of the license may be found at        
http://opensource.org/licenses/bsd-license.php                                            
                                                                                          
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             

Module Name:
  
  ProcessDsc.c

Abstract:

  Main module for the ProcessDsc utility.

--*/

#include <windows.h>  // for GetShortPathName()
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>
#include <direct.h>   // for _mkdir()
#include <errno.h>
#include <stdlib.h>   // for getenv()
#include "DSCFile.h"
#include "FWVolume.h"
#include "Exceptions.h"
#include "Common.h"

#include "EfiUtilityMsgs.h"
#include "TianoBind.h"
//
// Disable warning for while(1) code
//
#pragma warning(disable : 4127)
//
// Disable warning for unreferenced function parameters
//
#pragma warning(disable : 4100)

extern int  errno;

#define PROGRAM_NAME  "ProcessDsc"

//
// Common symbol name definitions. For example, the user can reference
// $(BUILD_DIR) in their DSC file and we will expand it for them (usually).
// I've defined the equivalents here in case we want to change the name the
// user references, in which case we just change the string value here and
// our code still works.
//
#define BUILD_DIR                       "BUILD_DIR"
#define EFI_SOURCE                      "EFI_SOURCE"
#define DEST_DIR                        "DEST_DIR"
#define SOURCE_DIR                      "SOURCE_DIR"
#define LIB_DIR                         "LIB_DIR"
#define BIN_DIR                         "BIN_DIR"
#define OUT_DIR                         "OUT_DIR"
#define INF_FILENAME                    "INF_FILENAME"
#define SOURCE_RELATIVE_PATH            "SOURCE_RELATIVE_PATH"
#define SOURCE_BASE_NAME                "SOURCE_BASE_NAME"
#define SOURCE_FILE_NAME                "SOURCE_FILE_NAME"    // c:\FullPath\File.c
#define PROCESSOR                       "PROCESSOR"
#define FV                              "FV"
#define BASE_NAME                       "BASE_NAME"
#define GUID                            "GUID"
#define FILE_GUID                       "FILE_GUID"
#define COMPONENT_TYPE_FILE             "FILE"
#define BUILD_TYPE                      "BUILD_TYPE"
#define FFS_EXT                         "FFS_EXT"             // FV_EXT is deprecated -- extension of FFS file
#define MAKEFILE_NAME                   "MAKEFILE_NAME"       // name of component's output makefile
#define PLATFORM                        "PLATFORM"            // for more granularity
#define PACKAGE_FILENAME                "PACKAGE_FILENAME"
#define PACKAGE                         "PACKAGE"
#define PACKAGE_TAG                     "PACKAGE_TAG"         // alternate name to PACKAGE
#define SHORT_NAMES                     "SHORT_NAMES"         // for 8.3 names of symbols
#define APRIORI                         "APRIORI"             // to add to apriori list
#define OPTIONAL_COMPONENT              "OPTIONAL"            // define as non-zero for optional INF files
#define SOURCE_SELECT                   "SOURCE_SELECT"       // say SOURCE_SELECT=smm,common to select INF sources
#define NONFFS_FV                       "NONFFS_FV"           // for non-FFS FV such as working & spare block FV
#define SKIP_FV_NULL                    "SKIP_FV_NULL"        // define as nonzero to not build components with FV=NULL
#define SOURCE_COMPILE_TYPE             "SOURCE_COMPILE_TYPE" // to build a source using a custom build section in the DSC file
#define SOURCE_FILE_EXTENSION           "SOURCE_FILE_EXTENSION"
#define COMPILE_SELECT                  "COMPILE_SELECT"
#define SOURCE_OVERRIDE_PATH            "SOURCE_OVERRIDE_PATH"  // get source files from here first
#define MAKEFILE_OUT_SECTION_NAME       "makefile.out"
#define COMMON_SECTION_NAME             "common"                // shared files or functionality
#define NMAKE_SECTION_NAME              "nmake"
#define SOURCES_SECTION_NAME            "sources"
#define COMPONENTS_SECTION_NAME         "components"
#define INCLUDE_SECTION_NAME            "includes"
#define DEFINES_SECTION_NAME            "defines"
#define LIBRARIES_SECTION_NAME          "libraries"
#define LIBRARIES_PLATFORM_SECTION_NAME "libraries.platform"
#define MAKEFILE_SECTION_NAME           "makefile"
#define COMPONENT_TYPE                  "component_type"
#define PLATFORM_STR                    "\\platform\\"          // to determine EFI_SOURCE
#define MAKEFILE_OUT_NAME               "makefile.out"          // if not specified on command line
#define MODULE_NAME_FILE                "module.list"           // this file used to record all module names defined in the dsc file.
//
// When a symbol is defined as "NULL", it gets saved in the symbol table as a 0-length
// string. Use this macro to detect if a symbol has been defined this way.
//
#define IS_NULL_SYMBOL_VALUE(var) ((var != NULL) && (strlen (var) == 0))

//
// Defines for file types
//
#define FILETYPE_UNKNOWN  0
#define FILETYPE_C        1
#define FILETYPE_ASM      2 // .asm or .s
#define FILETYPE_DSC      3 // descriptor file
#define FILETYPE_H        4
#define FILETYPE_LIB      5
#define FILETYPE_I        6
#define FILETYPE_SRC      7
#define FILETYPE_VFR      8
#define FILETYPE_UNI      9

typedef struct {
  INT8  *Extension;         // file extension
  INT8  *BuiltExtension;
  INT8  FileFlags;
  int   FileType;
} FILETYPE;

//
// Define masks for the FileFlags field
//
#define FILE_FLAG_INCLUDE 0x01
#define FILE_FLAG_SOURCE  0x02

//
// This table describes a from-to list of files. For
// example, when a ".c" is built, it results in a ".obj" file.
// For unicode (.uni) files, we specify a NULL built file
// extension. This keeps it out of the list of objects in
// the output makefile.
//
static const FILETYPE mFileTypes[] = {
  {
    ".c",
    ".obj",
    FILE_FLAG_SOURCE,
    FILETYPE_C
  },
  {
    ".asm",
    ".obj",
    FILE_FLAG_SOURCE,
    FILETYPE_ASM
  },
  {
    ".s",
    ".obj",
    FILE_FLAG_SOURCE,
    FILETYPE_ASM
  },
  {
    ".dsc",
    "",
    FILE_FLAG_SOURCE,
    FILETYPE_DSC
  },
  {
    ".h",
    "",
    FILE_FLAG_INCLUDE,
    FILETYPE_H
  },
  {
    ".lib",
    "",
    FILE_FLAG_SOURCE,
    FILETYPE_LIB
  },
  {
    ".i",
    ".obj",
    FILE_FLAG_INCLUDE,
    FILETYPE_I
  },
  {
    ".src",
    ".c",
    FILE_FLAG_INCLUDE,
    FILETYPE_SRC
  },
  {
    ".vfr",
    ".obj",
    FILE_FLAG_SOURCE,
    FILETYPE_VFR
  },  // actually *.vfr -> *.c -> *.obj
  {
    ".uni",
    NULL,
    FILE_FLAG_SOURCE,
    FILETYPE_UNI
  },
  //
  //  { ".uni", ".obj", FILE_FLAG_SOURCE,  FILETYPE_UNI },
  //
  {
    NULL,
    NULL,
    0,
    0
  }
};

//
// BUGBUG -- remove when you merge with ExpandMacros() function.
//
int
ExpandMacrosRecursive (
  INT8  *SourceLine,
  INT8  *DestLine,
  int   LineLen,
  int   ExpandMode
  );

//
// Structure to split up a file into its different parts.
//
typedef struct {
  INT8  Drive[3];
  INT8  *Path;
  INT8  *BaseName;
  INT8  *Extension;
  int   ExtensionCode;
} FILE_NAME_PARTS;

//
// Maximum length for any line in any file after macro expansion
//
#define MAX_EXP_LINE_LEN  (MAX_LINE_LEN * 2)

//
// Linked list to keep track of all symbols
//
typedef struct _SYMBOL {
  struct _SYMBOL  *Next;
  int             Type; // local or global symbol
  INT8            *Name;
  INT8            *Value;
} SYMBOL;

//
// Define new SYMBOL list to record all module name used in the platform.dsc file.
//
SYMBOL *gModuleList = NULL;

//
// This structure is used to save globals
//
struct {
  INT8    *DscFilename;
  SYMBOL  *Symbol;
  INT8    MakefileName[MAX_PATH]; // output makefile name
  INT8    XRefFileName[MAX_PATH];
  INT8    GuidDatabaseFileName[MAX_PATH];
  FILE    *MakefileFptr;
  UINT32  Verbose;
} gGlobals;

//
// This gets dumped to the head of makefile.out
//
static const INT8 *MakefileHeader[] = {
  "#/*++",
  "#",
  "#  DO NOT EDIT",
  "#  File auto-generated by build utility",
  "#",
  "#  Module Name:",
  "#",
  "#    makefile",
  "#",
  "#  Abstract:",
  "#",
  "#    Auto-generated makefile for building of EFI components/libraries",
  "#",
  "#--*/ ",
  "",
  NULL
};

//
// Function prototypes
//
static
int
ProcessOptions (
  int  Argc,
  INT8 *Argv[]
  );

static
void
Usage (
  VOID
  );

static
INT8              *
StripLine (
  INT8 *Line
  );

static
STATUS
ParseGuidDatabaseFile (
  INT8 *FileName
  );

#define DSC_SECTION_TYPE_COMPONENTS         0
#define DSC_SECTION_TYPE_LIBRARIES          1
#define DSC_SECTION_TYPE_PLATFORM_LIBRARIES 2

static
int
ProcessSectionComponents (
  DSC_FILE *DscFile,
  int      DscSectionType,
  int      Instance
  );
static
int
ProcessComponentFile (
  DSC_FILE  *DscFile,
  INT8      *Line,
  int       DscSectionType,
  int       Instance
  );
static
int
ProcessIncludeFiles (
  DSC_FILE  *ComponentFile,
  FILE      *MakeFptr
  );
static

int
ProcessIncludeFilesSingle (
  DSC_FILE  *ComponentFile,
  FILE      *MakeFptr,
  INT8      *SectionName
  );

//
// Mode flags for processing source files
//
#define SOURCE_MODE_BUILD_COMMANDS  0x01
#define SOURCE_MODE_SOURCE_FILES    0x02

static
int
ProcessSourceFiles (
  DSC_FILE  *DSCFile,
  DSC_FILE  *ComponentFile,
  FILE      *MakeFptr,
  UINT32    Mode
  );

static
int
ProcessSourceFilesSection (
  DSC_FILE  *DSCFile,
  DSC_FILE  *ComponentFile,
  FILE      *MakeFptr,
  INT8      *SectionName,
  UINT32    Mode
  );

static
int
ProcessObjects (
  DSC_FILE  *ComponentFile,
  FILE      *MakeFptr
  );

static
int
ProcessObjectsSingle (
  DSC_FILE  *ComponentFile,
  FILE      *MakeFptr,
  INT8      *SectionName
  );

static
int
ProcessLibs (
  DSC_FILE  *ComponentFile,
  FILE      *MakeFptr
  );

static
int
ProcessLibsSingle (
  DSC_FILE  *ComponentFile,
  FILE      *MakeFptr,
  INT8      *SectionName
  );

static
int
ProcessIncludesSection (
  DSC_FILE  *ComponentFile,
  FILE      *MakeFptr
  );

static
int
ProcessIncludesSectionSingle (
  DSC_FILE  *ComponentFile,
  FILE      *MakeFptr,
  INT8      *SectionName
  );

static
int
ProcessINFNMakeSection (
  DSC_FILE  *ComponentFile,
  FILE      *MakeFptr
  );

static
int
ProcessINFDefinesSection (
  DSC_FILE  *ComponentFile
  );

static
int
ProcessINFDefinesSectionSingle (
  DSC_FILE  *ComponentFile,
  INT8      *SectionName
  );

static
int
ProcessSectionLibraries (
  DSC_FILE  *DscFile,
  long      Offset
  );

static
int
ProcessDSCDefinesSection (
  DSC_FILE *DscFile
  );

static
int
SetSymbolType (
  INT8  *SymbolName,
  INT8  Type
  );

static
int
RemoveLocalSymbols (
  VOID
  );

static
int
RemoveFileSymbols (
  VOID
  );

static
int
RemoveSymbol (

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?