]>
Commit | Line | Data |
---|---|---|
3eb9473e | 1 | /*++\r |
2 | \r | |
3e99020d | 3 | Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>\r |
4b1e1121 | 4 | This program and the accompanying materials \r |
3eb9473e | 5 | are licensed and made available under the terms and conditions of the BSD License \r |
6 | which accompanies this distribution. The full text of the license may be found at \r | |
7 | http://opensource.org/licenses/bsd-license.php \r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
11 | \r | |
12 | Module Name:\r | |
13 | \r | |
14 | ProcessDsc.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Main module for the ProcessDsc utility.\r | |
19 | \r | |
20 | --*/\r | |
21 | \r | |
22 | #include <windows.h> // for GetShortPathName()\r | |
23 | #include <stdio.h>\r | |
24 | #include <string.h>\r | |
25 | #include <ctype.h>\r | |
26 | #include <stdarg.h>\r | |
27 | #include <direct.h> // for _mkdir()\r | |
28 | #include <errno.h>\r | |
29 | #include <stdlib.h> // for getenv()\r | |
3e99020d | 30 | #include <shlwapi.h> // for PathCanonicalize()\r |
3eb9473e | 31 | #include "DSCFile.h"\r |
3e99020d | 32 | #include "MultiThread.h"\r |
3eb9473e | 33 | #include "FWVolume.h"\r |
34 | #include "Exceptions.h"\r | |
35 | #include "Common.h"\r | |
36 | \r | |
37 | #include "EfiUtilityMsgs.h"\r | |
38 | #include "TianoBind.h"\r | |
3eb9473e | 39 | \r |
3e99020d LG |
40 | #define UTILITY_NAME "ProcessDsc"\r |
41 | #define UTILITY_VERSION "v1.0"\r | |
3eb9473e | 42 | \r |
43 | //\r | |
44 | // Common symbol name definitions. For example, the user can reference\r | |
45 | // $(BUILD_DIR) in their DSC file and we will expand it for them (usually).\r | |
46 | // I've defined the equivalents here in case we want to change the name the\r | |
47 | // user references, in which case we just change the string value here and\r | |
48 | // our code still works.\r | |
49 | //\r | |
50 | #define BUILD_DIR "BUILD_DIR"\r | |
51 | #define EFI_SOURCE "EFI_SOURCE"\r | |
52 | #define DEST_DIR "DEST_DIR"\r | |
53 | #define SOURCE_DIR "SOURCE_DIR"\r | |
54 | #define LIB_DIR "LIB_DIR"\r | |
55 | #define BIN_DIR "BIN_DIR"\r | |
56 | #define OUT_DIR "OUT_DIR"\r | |
57 | #define INF_FILENAME "INF_FILENAME"\r | |
58 | #define SOURCE_RELATIVE_PATH "SOURCE_RELATIVE_PATH"\r | |
59 | #define SOURCE_BASE_NAME "SOURCE_BASE_NAME"\r | |
60 | #define SOURCE_FILE_NAME "SOURCE_FILE_NAME" // c:\FullPath\File.c\r | |
61 | #define PROCESSOR "PROCESSOR"\r | |
62 | #define FV "FV"\r | |
63 | #define BASE_NAME "BASE_NAME"\r | |
64 | #define GUID "GUID"\r | |
65 | #define FILE_GUID "FILE_GUID"\r | |
66 | #define COMPONENT_TYPE_FILE "FILE"\r | |
67 | #define BUILD_TYPE "BUILD_TYPE"\r | |
68 | #define FFS_EXT "FFS_EXT" // FV_EXT is deprecated -- extension of FFS file\r | |
69 | #define MAKEFILE_NAME "MAKEFILE_NAME" // name of component's output makefile\r | |
70 | #define PLATFORM "PLATFORM" // for more granularity\r | |
71 | #define PACKAGE_FILENAME "PACKAGE_FILENAME"\r | |
72 | #define PACKAGE "PACKAGE"\r | |
73 | #define PACKAGE_TAG "PACKAGE_TAG" // alternate name to PACKAGE\r | |
74 | #define SHORT_NAMES "SHORT_NAMES" // for 8.3 names of symbols\r | |
75 | #define APRIORI "APRIORI" // to add to apriori list\r | |
76 | #define OPTIONAL_COMPONENT "OPTIONAL" // define as non-zero for optional INF files\r | |
77 | #define SOURCE_SELECT "SOURCE_SELECT" // say SOURCE_SELECT=smm,common to select INF sources\r | |
78 | #define NONFFS_FV "NONFFS_FV" // for non-FFS FV such as working & spare block FV\r | |
79 | #define SKIP_FV_NULL "SKIP_FV_NULL" // define as nonzero to not build components with FV=NULL\r | |
80 | #define SOURCE_COMPILE_TYPE "SOURCE_COMPILE_TYPE" // to build a source using a custom build section in the DSC file\r | |
81 | #define SOURCE_FILE_EXTENSION "SOURCE_FILE_EXTENSION"\r | |
82 | #define COMPILE_SELECT "COMPILE_SELECT"\r | |
83 | #define SOURCE_OVERRIDE_PATH "SOURCE_OVERRIDE_PATH" // get source files from here first\r | |
84 | #define MAKEFILE_OUT_SECTION_NAME "makefile.out"\r | |
85 | #define COMMON_SECTION_NAME "common" // shared files or functionality\r | |
86 | #define NMAKE_SECTION_NAME "nmake"\r | |
87 | #define SOURCES_SECTION_NAME "sources"\r | |
88 | #define COMPONENTS_SECTION_NAME "components"\r | |
89 | #define INCLUDE_SECTION_NAME "includes"\r | |
90 | #define DEFINES_SECTION_NAME "defines"\r | |
91 | #define LIBRARIES_SECTION_NAME "libraries"\r | |
92 | #define LIBRARIES_PLATFORM_SECTION_NAME "libraries.platform"\r | |
93 | #define MAKEFILE_SECTION_NAME "makefile"\r | |
94 | #define COMPONENT_TYPE "component_type"\r | |
95 | #define PLATFORM_STR "\\platform\\" // to determine EFI_SOURCE\r | |
96 | #define MAKEFILE_OUT_NAME "makefile.out" // if not specified on command line\r | |
97 | #define MODULE_MAKEFILE_NAME "module.mak" // record all module makefile targets\r | |
98 | #define MODULE_NAME_FILE "module.list" // record all module names defined in the dsc file\r | |
99 | #define GLOBAL_LINK_LIB_NAME "CompilerStub" // Lib added in link option, maybe removed in the future\r | |
100 | #define MODULE_BASE_NAME_WIDTH 25 // Width for module name output\r | |
101 | \r | |
102 | //\r | |
103 | // When a symbol is defined as "NULL", it gets saved in the symbol table as a 0-length\r | |
104 | // string. Use this macro to detect if a symbol has been defined this way.\r | |
105 | //\r | |
106 | #define IS_NULL_SYMBOL_VALUE(var) ((var != NULL) && (strlen (var) == 0))\r | |
107 | \r | |
108 | //\r | |
109 | // Defines for file types\r | |
110 | //\r | |
111 | #define FILETYPE_UNKNOWN 0\r | |
112 | #define FILETYPE_C 1\r | |
113 | #define FILETYPE_ASM 2\r | |
114 | #define FILETYPE_S 3\r | |
115 | #define FILETYPE_VFR 4\r | |
116 | #define FILETYPE_INC 5\r | |
117 | #define FILETYPE_H 6\r | |
118 | #define FILETYPE_I 7\r | |
119 | \r | |
120 | \r | |
121 | typedef struct {\r | |
122 | INT8 *Extension; // file extension\r | |
123 | INT8 *BuiltExtension;\r | |
124 | INT8 FileFlags;\r | |
125 | int FileType;\r | |
126 | } FILETYPE;\r | |
127 | \r | |
128 | //\r | |
129 | // Define masks for the FileFlags field\r | |
130 | //\r | |
131 | #define FILE_FLAG_INCLUDE 0x01\r | |
132 | #define FILE_FLAG_SOURCE 0x02\r | |
133 | \r | |
134 | //\r | |
135 | // This table describes a from-to list of files. For\r | |
136 | // example, when a ".c" is built, it results in a ".obj" file.\r | |
137 | //\r | |
138 | static const FILETYPE mFileTypes[] = {\r | |
139 | {\r | |
140 | ".c",\r | |
141 | ".obj",\r | |
142 | FILE_FLAG_SOURCE,\r | |
143 | FILETYPE_C\r | |
144 | },\r | |
145 | {\r | |
146 | ".asm",\r | |
147 | ".obj",\r | |
148 | FILE_FLAG_SOURCE,\r | |
149 | FILETYPE_ASM\r | |
150 | },\r | |
151 | {\r | |
152 | ".s",\r | |
153 | ".obj",\r | |
154 | FILE_FLAG_SOURCE,\r | |
155 | FILETYPE_S\r | |
156 | },\r | |
157 | {\r | |
158 | ".vfr",\r | |
159 | ".obj",\r | |
160 | FILE_FLAG_SOURCE,\r | |
161 | FILETYPE_VFR\r | |
162 | }, // actually *.vfr -> *.c -> *.obj\r | |
163 | {\r | |
164 | ".h",\r | |
165 | NULL,\r | |
166 | FILE_FLAG_INCLUDE,\r | |
167 | FILETYPE_H\r | |
168 | },\r | |
169 | {\r | |
170 | ".inc",\r | |
171 | NULL,\r | |
172 | FILE_FLAG_INCLUDE,\r | |
173 | FILETYPE_INC\r | |
174 | },\r | |
175 | {\r | |
176 | ".i",\r | |
177 | NULL,\r | |
178 | FILE_FLAG_INCLUDE,\r | |
179 | FILETYPE_I\r | |
180 | },\r | |
181 | {\r | |
182 | NULL,\r | |
183 | NULL,\r | |
184 | 0,\r | |
185 | 0\r | |
186 | }\r | |
187 | };\r | |
188 | \r | |
189 | //\r | |
190 | // Structure to split up a file into its different parts.\r | |
191 | //\r | |
192 | typedef struct {\r | |
193 | INT8 Drive[3];\r | |
194 | INT8 *Path;\r | |
195 | INT8 *BaseName;\r | |
196 | INT8 *Extension;\r | |
197 | int ExtensionCode;\r | |
198 | } FILE_NAME_PARTS;\r | |
199 | \r | |
200 | //\r | |
201 | // Maximum length for any line in any file after symbol expansion\r | |
202 | //\r | |
203 | #define MAX_EXP_LINE_LEN (MAX_LINE_LEN * 2)\r | |
204 | \r | |
205 | //\r | |
206 | // Linked list to keep track of all symbols\r | |
207 | //\r | |
208 | typedef struct _SYMBOL {\r | |
209 | struct _SYMBOL *Next;\r | |
210 | int Type; // local or global symbol\r | |
211 | INT8 *Name;\r | |
212 | INT8 *Value;\r | |
213 | } SYMBOL;\r | |
214 | \r | |
215 | //\r | |
3e99020d | 216 | // Module globals for multi-thread build\r |
3eb9473e | 217 | //\r |
3e99020d LG |
218 | static BUILD_ITEM **mCurrentBuildList; // build list currently handling\r |
219 | static BUILD_ITEM *mCurrentBuildItem; // build item currently handling\r | |
220 | \r | |
221 | //\r | |
222 | // Define masks for the build targets\r | |
223 | //\r | |
224 | #define BUILD_TARGET_COMPONENTS 0x01\r | |
225 | #define BUILD_TARGET_LIBRARIES 0x02\r | |
226 | #define BUILD_TARGET_FVS 0x04\r | |
227 | #define BUILD_TARGET_ALL 0xff\r | |
228 | \r | |
3eb9473e | 229 | \r |
230 | //\r | |
231 | // This structure is used to save globals\r | |
232 | //\r | |
233 | struct {\r | |
3e99020d LG |
234 | INT8 *DscFilename;\r |
235 | SYMBOL *Symbol;\r | |
236 | INT8 MakefileName[MAX_PATH]; // output makefile name\r | |
237 | INT8 XRefFileName[MAX_PATH];\r | |
238 | INT8 GuidDatabaseFileName[MAX_PATH];\r | |
239 | INT8 ModuleMakefileName[MAX_PATH];\r | |
240 | FILE *MakefileFptr;\r | |
241 | FILE *ModuleMakefileFptr;\r | |
242 | SYMBOL *ModuleList;\r | |
243 | SYMBOL *OutdirList;\r | |
244 | UINT32 Verbose;\r | |
245 | UINT32 ThreadNumber;\r | |
246 | UINT32 BuildTarget;\r | |
247 | BUILD_ITEM *LibraryList;\r | |
248 | COMPONENTS_ITEM *ComponentsList;\r | |
3eb9473e | 249 | } gGlobals;\r |
250 | \r | |
251 | //\r | |
252 | // This gets dumped to the head of makefile.out\r | |
253 | //\r | |
254 | static const INT8 *MakefileHeader[] = {\r | |
255 | "#/*++",\r | |
256 | "#",\r | |
257 | "# DO NOT EDIT",\r | |
258 | "# File auto-generated by build utility",\r | |
259 | "#",\r | |
260 | "# Module Name:",\r | |
261 | "#",\r | |
262 | "# makefile",\r | |
263 | "#",\r | |
264 | "# Abstract:",\r | |
265 | "#",\r | |
266 | "# Auto-generated makefile for building of EFI components/libraries",\r | |
267 | "#",\r | |
268 | "#--*/",\r | |
269 | "",\r | |
270 | NULL\r | |
271 | };\r | |
272 | \r | |
273 | //\r | |
274 | // Function prototypes\r | |
275 | //\r | |
276 | static\r | |
277 | int\r | |
278 | ProcessOptions (\r | |
279 | int Argc,\r | |
280 | INT8 *Argv[]\r | |
281 | );\r | |
282 | \r | |
283 | static\r | |
284 | void\r | |
285 | Usage (\r | |
286 | VOID\r | |
287 | );\r | |
288 | \r | |
289 | static\r | |
290 | INT8 *\r | |
291 | StripLine (\r | |
292 | INT8 *Line\r | |
293 | );\r | |
294 | \r | |
295 | static\r | |
296 | STATUS\r | |
297 | ParseGuidDatabaseFile (\r | |
298 | INT8 *FileName\r | |
299 | );\r | |
300 | \r | |
301 | #define DSC_SECTION_TYPE_COMPONENTS 0\r | |
302 | #define DSC_SECTION_TYPE_LIBRARIES 1\r | |
303 | #define DSC_SECTION_TYPE_PLATFORM_LIBRARIES 2\r | |
304 | \r | |
305 | static\r | |
306 | int\r | |
307 | ProcessSectionComponents (\r | |
308 | DSC_FILE *DscFile,\r | |
309 | int DscSectionType,\r | |
310 | int Instance\r | |
311 | );\r | |
312 | static\r | |
313 | int\r | |
314 | ProcessComponentFile (\r | |
315 | DSC_FILE *DscFile,\r | |
316 | INT8 *Line,\r | |
317 | int DscSectionType,\r | |
318 | int Instance\r | |
319 | );\r | |
320 | static\r | |
321 | int\r | |
322 | ProcessIncludeFiles (\r | |
323 | DSC_FILE *ComponentFile,\r | |
324 | FILE *MakeFptr\r | |
325 | );\r | |
326 | static\r | |
327 | \r | |
328 | int\r | |
329 | ProcessIncludeFilesSingle (\r | |
330 | DSC_FILE *ComponentFile,\r | |
331 | FILE *MakeFptr,\r | |
332 | INT8 *SectionName\r | |
333 | );\r | |
334 | \r | |
335 | //\r | |
336 | // Mode flags for processing source files\r | |
337 | //\r | |
338 | #define SOURCE_MODE_BUILD_COMMANDS 0x01\r | |
339 | #define SOURCE_MODE_SOURCE_FILES 0x02\r | |
340 | \r | |
341 | static\r | |
342 | int\r | |
343 | ProcessSourceFiles (\r | |
344 | DSC_FILE *DSCFile,\r | |
345 | DSC_FILE *ComponentFile,\r | |
346 | FILE *MakeFptr,\r | |
347 | UINT32 Mode\r | |
348 | );\r | |
349 | \r | |
350 | static\r | |
351 | int\r | |
352 | ProcessSourceFilesSection (\r | |
353 | DSC_FILE *DSCFile,\r | |
354 | DSC_FILE *ComponentFile,\r | |
355 | FILE *MakeFptr,\r | |
356 | INT8 *SectionName,\r | |
357 | UINT32 Mode\r | |
358 | );\r | |
359 | \r | |
360 | static\r | |
361 | int\r | |
362 | ProcessObjects (\r | |
363 | DSC_FILE *ComponentFile,\r | |
364 | FILE *MakeFptr\r | |
365 | );\r | |
366 | \r | |
367 | static\r | |
368 | int\r | |
369 | ProcessObjectsSingle (\r | |
370 | DSC_FILE *ComponentFile,\r | |
371 | FILE *MakeFptr,\r | |
372 | INT8 *SectionName\r | |
373 | );\r | |
374 | \r | |
375 | static\r | |
376 | int\r | |
377 | ProcessLibs (\r | |
378 | DSC_FILE *ComponentFile,\r | |
379 | FILE *MakeFptr\r | |
380 | );\r | |
381 | \r | |
382 | static\r | |
383 | int\r | |
384 | ProcessLibsSingle (\r | |
385 | DSC_FILE *ComponentFile,\r | |
386 | FILE *MakeFptr,\r | |
387 | INT8 *SectionName\r | |
388 | );\r | |
389 | \r | |
390 | static\r | |
391 | int\r | |
392 | ProcessIncludesSection (\r | |
393 | DSC_FILE *ComponentFile,\r | |
394 | FILE *MakeFptr\r | |
395 | );\r | |
396 | \r | |
397 | static\r | |
398 | int\r | |
399 | ProcessIncludesSectionSingle (\r | |
400 | DSC_FILE *ComponentFile,\r | |
401 | FILE *MakeFptr,\r | |
402 | INT8 *SectionName\r | |
403 | );\r | |
404 | \r | |
405 | static\r | |
406 | int\r | |
407 | ProcessINFNMakeSection (\r | |
408 | DSC_FILE *ComponentFile,\r | |
409 | FILE *MakeFptr\r | |
410 | );\r | |
411 | \r | |
412 | static\r | |
413 | int\r | |
414 | ProcessINFDefinesSection (\r | |
415 | DSC_FILE *ComponentFile\r | |
416 | );\r | |
417 | \r | |
418 | static\r | |
419 | int\r | |
420 | ProcessINFDefinesSectionSingle (\r | |
421 | DSC_FILE *ComponentFile,\r | |
422 | INT8 *SectionName\r | |
423 | );\r | |
424 | \r | |
425 | static\r | |
426 | int\r | |
427 | ProcessSectionLibraries (\r | |
428 | DSC_FILE *DscFile,\r | |
429 | long Offset\r | |
430 | );\r | |
431 | \r | |
432 | static\r | |
433 | int\r | |
434 | ProcessDSCDefinesSection (\r | |
435 | DSC_FILE *DscFile\r | |
436 | );\r | |
437 | \r | |
438 | static\r | |
439 | int\r | |
440 | SetSymbolType (\r | |
441 | INT8 *SymbolName,\r | |
442 | INT8 Type\r | |
443 | );\r | |
444 | \r | |
445 | static\r | |
446 | int\r | |
447 | RemoveLocalSymbols (\r | |
448 | VOID\r | |
449 | );\r | |
450 | \r | |
451 | static\r | |
452 | int\r | |
453 | RemoveFileSymbols (\r | |
454 | VOID\r | |
455 | );\r | |
456 | \r | |
457 | static\r | |
458 | int\r | |
459 | RemoveSymbol (\r | |
460 | INT8 *Name,\r | |
461 | INT8 SymbolType\r | |
462 | );\r | |
463 | \r | |
464 | static\r | |
465 | int\r | |
466 | SetFileExtension (\r | |
467 | INT8 *FileName,\r | |
468 | INT8 *Extension\r | |
469 | );\r | |
470 | \r | |
471 | static\r | |
472 | int\r | |
473 | GetSourceFileType (\r | |
474 | INT8 *FileName\r | |
475 | );\r | |
476 | \r | |
477 | static\r | |
478 | int\r | |
479 | IsIncludeFile (\r | |
480 | INT8 *FileName\r | |
481 | );\r | |
482 | \r | |
483 | static\r | |
484 | int\r | |
485 | WriteCompileCommands (\r | |
486 | DSC_FILE *DscFile,\r | |
487 | FILE *MakeFptr,\r | |
488 | INT8 *FileName,\r | |
489 | INT8 *Processor\r | |
490 | );\r | |
491 | \r | |
492 | static\r | |
493 | int\r | |
494 | WriteCommonMakefile (\r | |
495 | DSC_FILE *DscFile,\r | |
496 | FILE *MakeFptr,\r | |
497 | INT8 *Processor\r | |
498 | );\r | |
499 | \r | |
500 | static\r | |
501 | int\r | |
502 | WriteComponentTypeBuildCommands (\r | |
503 | DSC_FILE *DscFile,\r | |
504 | FILE *MakeFptr,\r | |
505 | INT8 *SectionName\r | |
506 | );\r | |
507 | \r | |
508 | static\r | |
509 | void\r | |
510 | StripTrailingSpaces (\r | |
511 | INT8 *Str\r | |
512 | );\r | |
513 | \r | |
514 | static\r | |
515 | void\r | |
516 | FreeFileParts (\r | |
517 | FILE_NAME_PARTS *FP\r | |
518 | );\r | |
519 | \r | |
520 | static\r | |
521 | FILE_NAME_PARTS *\r | |
522 | GetFileParts (\r | |
523 | INT8 *FileName\r | |
524 | );\r | |
525 | \r | |
526 | static\r | |
527 | SYMBOL *\r | |
528 | FreeSymbols (\r | |
529 | SYMBOL *Syms\r | |
530 | );\r | |
531 | \r | |
532 | static\r | |
533 | int\r | |
534 | GetEfiSource (\r | |
535 | VOID\r | |
536 | );\r | |
537 | \r | |
538 | static\r | |
539 | int\r | |
540 | CreatePackageFile (\r | |
541 | DSC_FILE *DSCFile\r | |
542 | );\r | |
543 | \r | |
544 | static\r | |
545 | INT8 *\r | |
546 | BuiltFileExtension (\r | |
547 | INT8 *SourceFileName\r | |
548 | );\r | |
549 | \r | |
550 | static\r | |
551 | void\r | |
552 | SmartFree (\r | |
553 | SMART_FILE *SmartFile\r | |
554 | );\r | |
555 | \r | |
556 | static \r | |
557 | int\r | |
558 | AddModuleName (\r | |
559 | SYMBOL **SymbolList,\r | |
560 | INT8 *ModuleName,\r | |
561 | INT8 *InfName\r | |
562 | );\r | |
563 | \r | |
95d675b5 | 564 | static \r |
565 | void\r | |
566 | ReplaceSlash (\r | |
567 | INT8 *Path\r | |
568 | );\r | |
569 | \r | |
3eb9473e | 570 | /*****************************************************************************/\r |
571 | int\r | |
572 | main (\r | |
573 | int Argc,\r | |
574 | INT8 *Argv[]\r | |
575 | )\r | |
576 | /*++\r | |
577 | \r | |
578 | Routine Description:\r | |
579 | \r | |
580 | Main utility entry point.\r | |
581 | \r | |
582 | Arguments:\r | |
583 | \r | |
584 | Argc - Standard app entry point args.\r | |
585 | Argv - Standard app entry point args.\r | |
586 | \r | |
587 | Returns:\r | |
588 | \r | |
589 | 0 if successful\r | |
590 | non-zero otherwise\r | |
591 | \r | |
592 | --*/\r | |
593 | {\r | |
3e99020d LG |
594 | int i;\r |
595 | DSC_FILE DSCFile;\r | |
596 | SECTION *Sect;\r | |
597 | INT8 Line[MAX_LINE_LEN];\r | |
598 | INT8 ExpLine[MAX_LINE_LEN];\r | |
599 | INT8 *BuildDir;\r | |
600 | INT8 *EMsg;\r | |
601 | FILE *FpModule;\r | |
602 | SYMBOL *TempSymbol;\r | |
603 | COMPONENTS_ITEM *TempComponents;\r | |
604 | \r | |
605 | SetUtilityName (UTILITY_NAME);\r | |
3eb9473e | 606 | \r |
607 | InitExceptions ();\r | |
608 | \r | |
609 | DSCFileInit (&DSCFile);\r | |
610 | //\r | |
611 | // Initialize the firmware volume data\r | |
612 | //\r | |
613 | CFVConstructor ();\r | |
614 | //\r | |
615 | // Exception handling for this block of code.\r | |
616 | //\r | |
617 | TryException ();\r | |
618 | //\r | |
619 | // Process command-line options.\r | |
620 | //\r | |
621 | if (ProcessOptions (Argc, Argv)) {\r | |
622 | EMsg = CatchException ();\r | |
623 | if (EMsg != NULL) {\r | |
624 | fprintf (stderr, "%s\n", EMsg);\r | |
625 | }\r | |
626 | \r | |
627 | return STATUS_ERROR;\r | |
628 | }\r | |
629 | //\r | |
630 | // Parse the GUID database file if specified\r | |
631 | //\r | |
632 | if (gGlobals.GuidDatabaseFileName[0] != 0) {\r | |
633 | ParseGuidDatabaseFile (gGlobals.GuidDatabaseFileName);\r | |
634 | }\r | |
635 | //\r | |
636 | // Set the output cross-reference file if applicable\r | |
637 | //\r | |
638 | if (gGlobals.XRefFileName[0]) {\r | |
639 | CFVSetXRefFileName (gGlobals.XRefFileName);\r | |
640 | }\r | |
641 | \r | |
642 | //\r | |
643 | // Now get the EFI_SOURCE directory which we use everywhere.\r | |
644 | //\r | |
645 | if (GetEfiSource ()) {\r | |
646 | return STATUS_ERROR;\r | |
647 | }\r | |
648 | \r | |
649 | //\r | |
650 | // Pre-process the DSC file to get section info.\r | |
651 | //\r | |
652 | if (DSCFileSetFile (&DSCFile, gGlobals.DscFilename) != 0) {\r | |
653 | goto ProcessingError;\r | |
654 | }\r | |
655 | \r | |
656 | //\r | |
657 | // Set output makefile name for single module build \r | |
658 | //\r | |
659 | strcpy (gGlobals.ModuleMakefileName, MODULE_MAKEFILE_NAME);\r | |
660 | \r | |
661 | //\r | |
662 | // Try to open all final output makefiles\r | |
663 | //\r | |
664 | if ((gGlobals.MakefileFptr = fopen (gGlobals.MakefileName, "w")) == NULL) {\r | |
665 | Error (NULL, 0, 0, gGlobals.MakefileName, "failed to open output makefile for writing");\r | |
666 | goto ProcessingError;\r | |
667 | }\r | |
668 | if ((gGlobals.ModuleMakefileFptr = fopen (gGlobals.ModuleMakefileName, "w")) == NULL) {\r | |
669 | Error (NULL, 0, 0, gGlobals.ModuleMakefileName, "failed to open output makefile for writing");\r | |
670 | goto ProcessingError;\r | |
671 | }\r | |
672 | \r | |
673 | //\r | |
674 | // Write the header out to the makefiles\r | |
675 | //\r | |
676 | for (i = 0; MakefileHeader[i] != NULL; i++) {\r | |
677 | fprintf (gGlobals.MakefileFptr, "%s\n", MakefileHeader[i]);\r | |
678 | fprintf (gGlobals.ModuleMakefileFptr, "%s\n", MakefileHeader[i]);\r | |
679 | }\r | |
680 | \r | |
681 | //\r | |
682 | // Init global potint = NULL\r | |
683 | //\r | |
684 | gGlobals.ModuleList = NULL;\r | |
685 | gGlobals.OutdirList = NULL;\r | |
686 | \r | |
687 | //\r | |
688 | // Process the [defines] section in the DSC file to get any defines we need\r | |
689 | // elsewhere\r | |
690 | //\r | |
691 | ProcessDSCDefinesSection (&DSCFile);\r | |
692 | if (ExceptionThrown ()) {\r | |
693 | goto ProcessingError;\r | |
694 | }\r | |
695 | //\r | |
696 | // Write out the [makefile.out] section data to the output makefiles\r | |
697 | //\r | |
698 | Sect = DSCFileFindSection (&DSCFile, MAKEFILE_OUT_SECTION_NAME);\r | |
699 | if (Sect != NULL) {\r | |
700 | while (DSCFileGetLine (&DSCFile, Line, sizeof (Line)) != NULL) {\r | |
701 | ExpandSymbols (Line, ExpLine, sizeof (ExpLine), 0);\r | |
702 | //\r | |
703 | // Write the line to the output makefiles\r | |
704 | //\r | |
705 | fprintf (gGlobals.MakefileFptr, ExpLine);\r | |
706 | fprintf (gGlobals.ModuleMakefileFptr, ExpLine);\r | |
707 | }\r | |
708 | }\r | |
709 | \r | |
710 | //\r | |
711 | // Add a pseudo target for GLOBAL_LINK_LIB_NAME to avoid single module build \r | |
712 | // failure when this lib is not used.\r | |
713 | //\r | |
714 | fprintf (gGlobals.ModuleMakefileFptr, "%sbuild ::\n\n", GLOBAL_LINK_LIB_NAME);\r | |
715 | \r | |
716 | fprintf (gGlobals.MakefileFptr, "libraries : \n");\r | |
717 | //\r | |
718 | // Process [libraries] section in the DSC file\r | |
719 | //\r | |
720 | Sect = DSCFileFindSection (&DSCFile, LIBRARIES_SECTION_NAME);\r | |
721 | if (Sect != NULL) {\r | |
3e99020d | 722 | mCurrentBuildList = &gGlobals.LibraryList;\r |
3eb9473e | 723 | ProcessSectionComponents (&DSCFile, DSC_SECTION_TYPE_LIBRARIES, 0);\r |
724 | }\r | |
725 | \r | |
726 | if (ExceptionThrown ()) {\r | |
727 | goto ProcessingError;\r | |
728 | }\r | |
729 | //\r | |
730 | // Process [libraries.platform] section in the DSC file\r | |
731 | //\r | |
732 | Sect = DSCFileFindSection (&DSCFile, LIBRARIES_PLATFORM_SECTION_NAME);\r | |
733 | if (Sect != NULL) {\r | |
3e99020d | 734 | mCurrentBuildList = &gGlobals.LibraryList;\r |
3eb9473e | 735 | ProcessSectionComponents (&DSCFile, DSC_SECTION_TYPE_PLATFORM_LIBRARIES, 0);\r |
736 | }\r | |
737 | \r | |
738 | fprintf (gGlobals.MakefileFptr, "\n");\r | |
739 | if (ExceptionThrown ()) {\r | |
740 | goto ProcessingError;\r | |
741 | }\r | |
742 | \r | |
743 | //\r | |
744 | // Process [components] section in the DSC file\r | |
745 | //\r | |
746 | Sect = DSCFileFindSection (&DSCFile, COMPONENTS_SECTION_NAME);\r | |
747 | if (Sect != NULL) {\r | |
748 | fprintf (gGlobals.MakefileFptr, "components_0 : \n");\r | |
3e99020d LG |
749 | TempComponents = AddComponentsItem (&gGlobals.ComponentsList);\r |
750 | mCurrentBuildList = &TempComponents->BuildList;\r | |
3eb9473e | 751 | ProcessSectionComponents (&DSCFile, DSC_SECTION_TYPE_COMPONENTS, 0);\r |
752 | fprintf (gGlobals.MakefileFptr, "\n");\r | |
753 | }\r | |
754 | \r | |
755 | if (ExceptionThrown ()) {\r | |
756 | goto ProcessingError;\r | |
757 | }\r | |
758 | //\r | |
759 | // Now cycle through all [components.1], [components.2], ....[components.n].\r | |
760 | // This is necessary to support building of firmware volumes that may contain\r | |
761 | // other encapsulated firmware volumes (ala capsules).\r | |
762 | //\r | |
763 | i = 1;\r | |
764 | while (1) {\r | |
765 | RemoveSymbol (FV, SYM_GLOBAL);\r | |
766 | sprintf (Line, "%s.%d", COMPONENTS_SECTION_NAME, i);\r | |
767 | Sect = DSCFileFindSection (&DSCFile, Line);\r | |
768 | if (Sect != NULL) {\r | |
769 | fprintf (gGlobals.MakefileFptr, "components_%d : \n", i);\r | |
3e99020d LG |
770 | TempComponents = AddComponentsItem (&gGlobals.ComponentsList);\r |
771 | mCurrentBuildList = &TempComponents->BuildList;\r | |
3eb9473e | 772 | ProcessSectionComponents (&DSCFile, DSC_SECTION_TYPE_COMPONENTS, i);\r |
773 | fprintf (gGlobals.MakefileFptr, "\n");\r | |
774 | } else {\r | |
775 | break;\r | |
776 | }\r | |
777 | \r | |
778 | if (ExceptionThrown ()) {\r | |
779 | goto ProcessingError;\r | |
780 | }\r | |
781 | \r | |
782 | i++;\r | |
783 | }\r | |
784 | \r | |
785 | ProcessingError:\r | |
786 | EMsg = CatchException ();\r | |
787 | if (EMsg != NULL) {\r | |
788 | fprintf (stderr, "%s\n", EMsg);\r | |
789 | fprintf (stderr, "Processing aborted\n");\r | |
790 | }\r | |
791 | \r | |
792 | TryException ();\r | |
793 | //\r | |
794 | // Create the FV files if no fatal errors or errors\r | |
795 | //\r | |
796 | if (GetUtilityStatus () < STATUS_ERROR) {\r | |
797 | CFVWriteInfFiles (&DSCFile, gGlobals.MakefileFptr);\r | |
798 | }\r | |
799 | \r | |
800 | //\r | |
801 | // Write all module name into MODULE_NAME_FILE file.\r | |
802 | //\r | |
803 | if ((FpModule = fopen (MODULE_NAME_FILE, "w")) != NULL) {\r | |
804 | TempSymbol = gGlobals.ModuleList;\r | |
805 | while (TempSymbol != NULL) {\r | |
806 | fprintf (FpModule, " %-*s %s \n", MODULE_BASE_NAME_WIDTH, TempSymbol->Name, TempSymbol->Value);\r | |
807 | TempSymbol = TempSymbol->Next;\r | |
808 | }\r | |
809 | fclose (FpModule);\r | |
810 | FpModule = NULL;\r | |
811 | }\r | |
812 | \r | |
813 | //\r | |
814 | // Close the all the output makefiles\r | |
815 | //\r | |
816 | if (gGlobals.MakefileFptr != NULL) {\r | |
817 | fclose (gGlobals.MakefileFptr);\r | |
818 | gGlobals.MakefileFptr = NULL;\r | |
819 | }\r | |
820 | \r | |
821 | if (gGlobals.ModuleMakefileFptr != NULL) {\r | |
822 | fclose (gGlobals.ModuleMakefileFptr);\r | |
823 | gGlobals.ModuleMakefileFptr = NULL;\r | |
824 | }\r | |
3e99020d LG |
825 | \r |
826 | //\r | |
827 | // Start multi-thread build if ThreadNumber is specified and no error status\r | |
828 | //\r | |
829 | if ((gGlobals.ThreadNumber != 0) && (GetUtilityStatus () < STATUS_ERROR)) {\r | |
830 | BuildDir = GetSymbolValue (BUILD_DIR);\r | |
831 | if (gGlobals.BuildTarget & BUILD_TARGET_LIBRARIES) {\r | |
832 | if (StartMultiThreadBuild (&gGlobals.LibraryList, gGlobals.ThreadNumber, BuildDir) != 0) {\r | |
833 | Error (NULL, 0, 0, NULL, "Multi-thread build libraries failure");\r | |
834 | goto Cleanup;\r | |
835 | }\r | |
836 | }\r | |
837 | i = 0;\r | |
838 | TempComponents = gGlobals.ComponentsList;\r | |
839 | while (TempComponents != NULL) {\r | |
840 | if (gGlobals.BuildTarget & BUILD_TARGET_COMPONENTS) {\r | |
841 | if (StartMultiThreadBuild (&TempComponents->BuildList, gGlobals.ThreadNumber, BuildDir) != 0) {\r | |
842 | Error (NULL, 0, 0, NULL, "Multi-thread build components %d failure", i);\r | |
843 | goto Cleanup;\r | |
844 | }\r | |
845 | }\r | |
846 | if (gGlobals.BuildTarget & BUILD_TARGET_FVS) {\r | |
847 | sprintf (ExpLine, "nmake -nologo -f %s fvs_%d", gGlobals.MakefileName, i);\r | |
848 | _flushall ();\r | |
849 | if (system (ExpLine)) {\r | |
850 | Error (NULL, 0, 0, NULL, "Build FVs for components %d failure", i);\r | |
851 | goto Cleanup;\r | |
852 | }\r | |
853 | }\r | |
854 | i++;\r | |
855 | TempComponents = TempComponents->Next;\r | |
856 | }\r | |
857 | }\r | |
858 | \r | |
859 | Cleanup: \r | |
3eb9473e | 860 | //\r |
861 | // Clean up\r | |
862 | //\r | |
3e99020d LG |
863 | FreeBuildList (gGlobals.LibraryList);\r |
864 | gGlobals.LibraryList = NULL;\r | |
865 | FreeComponentsList (gGlobals.ComponentsList);\r | |
866 | gGlobals.ComponentsList = NULL;\r | |
3eb9473e | 867 | FreeSymbols (gGlobals.ModuleList);\r |
3e99020d | 868 | gGlobals.ModuleList = NULL;\r |
3eb9473e | 869 | FreeSymbols (gGlobals.OutdirList);\r |
3e99020d | 870 | gGlobals.OutdirList = NULL;\r |
3eb9473e | 871 | FreeSymbols (gGlobals.Symbol);\r |
872 | gGlobals.Symbol = NULL;\r | |
873 | CFVDestructor ();\r | |
874 | DSCFileDestroy (&DSCFile);\r | |
875 | \r | |
876 | EMsg = CatchException ();\r | |
877 | if (EMsg != NULL) {\r | |
878 | fprintf (stderr, "%s\n", EMsg);\r | |
879 | fprintf (stderr, "Processing aborted\n");\r | |
880 | }\r | |
881 | \r | |
882 | return GetUtilityStatus ();\r | |
883 | }\r | |
884 | \r | |
885 | static\r | |
886 | int\r | |
887 | ProcessSectionComponents (\r | |
888 | DSC_FILE *DSCFile,\r | |
889 | int DscSectionType,\r | |
890 | int Instance\r | |
891 | )\r | |
892 | /*++\r | |
893 | \r | |
894 | Routine Description:\r | |
895 | \r | |
896 | Process the [components] or [libraries] section in the description file. We\r | |
897 | use this function for both since they're very similar. Here we just\r | |
898 | read each line from the section, and if it's valid, call a function to\r | |
899 | do the actual processing of the component description file.\r | |
900 | \r | |
901 | Arguments:\r | |
902 | \r | |
903 | DSCFile - structure containing section info on the description file\r | |
904 | DscSectionType - type of description section\r | |
905 | \r | |
906 | Returns:\r | |
907 | \r | |
908 | 0 if successful\r | |
909 | \r | |
910 | --*/\r | |
911 | {\r | |
912 | INT8 Line[MAX_LINE_LEN];\r | |
913 | INT8 Line2[MAX_EXP_LINE_LEN];\r | |
914 | INT8 *Cptr;\r | |
915 | \r | |
916 | //\r | |
917 | // Read lines while they're valid\r | |
918 | //\r | |
919 | while (DSCFileGetLine (DSCFile, Line, sizeof (Line)) != NULL) {\r | |
920 | //\r | |
921 | // Expand symbols on the line\r | |
922 | //\r | |
923 | if (ExpandSymbols (Line, Line2, sizeof (Line2), 0)) {\r | |
924 | return STATUS_ERROR;\r | |
925 | }\r | |
926 | //\r | |
927 | // Strip the line\r | |
928 | //\r | |
929 | Cptr = StripLine (Line2);\r | |
930 | if (*Cptr) {\r | |
931 | Message (2, "Processing component line: %s", Line2);\r | |
932 | if (ProcessComponentFile (DSCFile, Line2, DscSectionType, Instance) != 0) {\r | |
933 | return STATUS_ERROR;\r | |
934 | }\r | |
935 | }\r | |
936 | }\r | |
937 | \r | |
938 | return 0;\r | |
939 | }\r | |
940 | \r | |
941 | static\r | |
942 | int\r | |
943 | ProcessComponentFile (\r | |
944 | DSC_FILE *DSCFile,\r | |
945 | INT8 *ArgLine,\r | |
946 | int DscSectionType,\r | |
947 | int Instance\r | |
948 | )\r | |
949 | /*++\r | |
950 | \r | |
951 | Routine Description:\r | |
952 | \r | |
953 | Given a line from the [components] or [libraries] section of the description\r | |
954 | file, process the line to extract the component's INF filename and \r | |
955 | parameters. Then open the INF file and process it to create a corresponding\r | |
956 | makefile.\r | |
957 | \r | |
958 | Arguments:\r | |
959 | \r | |
960 | DSCFile The project DSC file info structure.\r | |
961 | Libs Indicates whether we're processing the [components]\r | |
962 | section or the [libraries] section.\r | |
963 | ArgLine The actual line from the DSC file. Looks something like\r | |
964 | one of the following:\r | |
965 | \r | |
966 | dxe\drivers\vm\vm.dsc PROCESSOR=IA32 DEST_DIR=$(DEST_DIR)\xxx FV=FV1,FV2\r | |
967 | $(BUILD_DIR).\FvVariable.ffs COMPONENT_TYPE=FILE\r | |
968 | .\FvVariable.ffs COMPONENT_TYPE=FILE\r | |
969 | define VAR1=value1 VAR2=value2\r | |
970 | \r | |
971 | Returns:\r | |
972 | \r | |
973 | 0 if successful\r | |
974 | \r | |
975 | --*/\r | |
976 | {\r | |
977 | FILE *MakeFptr;\r | |
978 | FILE *TempFptr;\r | |
979 | INT8 *Cptr;\r | |
980 | INT8 *name;\r | |
981 | INT8 *End;\r | |
982 | INT8 *TempCptr;\r | |
983 | INT8 FileName[MAX_PATH];\r | |
984 | INT8 ComponentFilePath[MAX_PATH];\r | |
985 | INT8 InLine[MAX_LINE_LEN];\r | |
986 | INT8 Line[MAX_LINE_LEN];\r | |
987 | INT8 *Processor;\r | |
988 | INT8 SymType;\r | |
989 | int Len;\r | |
990 | int ComponentCreated;\r | |
991 | int ComponentFilePathAbsolute;\r | |
992 | int DefineLine;\r | |
993 | DSC_FILE ComponentFile;\r | |
994 | INT8 ComponentMakefileName[MAX_PATH];\r | |
995 | BOOLEAN IsForFv;\r | |
996 | \r | |
997 | //\r | |
998 | // Now remove all local symbols\r | |
999 | //\r | |
1000 | RemoveLocalSymbols ();\r | |
1001 | //\r | |
1002 | // Null out the file pointer in case we take an exception somewhere\r | |
1003 | // and we need to close it only if we opened it.\r | |
1004 | //\r | |
1005 | MakeFptr = NULL;\r | |
1006 | ComponentFilePathAbsolute = 0;\r | |
1007 | ComponentCreated = 0;\r | |
1008 | //\r | |
1009 | // Skip preceeding spaces on the line\r | |
1010 | //\r | |
1011 | while (isspace (*ArgLine) && (*ArgLine)) {\r | |
1012 | ArgLine++;\r | |
1013 | }\r | |
1014 | //\r | |
1015 | // Find the end of the component's filename and truncate the line at that\r | |
1016 | // point. From here on out ArgLine is the name of the component filename.\r | |
1017 | //\r | |
1018 | Cptr = ArgLine;\r | |
1019 | while (!isspace (*Cptr) && *Cptr) {\r | |
1020 | Cptr++;\r | |
1021 | }\r | |
1022 | \r | |
1023 | End = Cptr;\r | |
1024 | if (*Cptr) {\r | |
1025 | End++;\r | |
1026 | *Cptr = 0;\r | |
1027 | }\r | |
1028 | //\r | |
1029 | // Exception-handle processing of this component description file\r | |
1030 | //\r | |
1031 | TryException ();\r | |
1032 | \r | |
1033 | //\r | |
1034 | // We also allow a component line format for defines of global symbols\r | |
1035 | // instead of a component filename. In this case, the line looks like:\r | |
1036 | // defines x=abc y=yyy. Be nice and accept "define" and "defines" in a\r | |
1037 | // case-insensitive manner. If it's defines, then make the symbols global.\r | |
1038 | //\r | |
1039 | if ((_stricmp (ArgLine, "define") == 0) || (_stricmp (ArgLine, "defines") == 0)) {\r | |
1040 | SymType = SYM_OVERWRITE | SYM_GLOBAL;\r | |
1041 | DefineLine = 1;\r | |
1042 | } else {\r | |
1043 | SymType = SYM_OVERWRITE | SYM_LOCAL;\r | |
1044 | DefineLine = 0;\r | |
1045 | }\r | |
1046 | //\r | |
1047 | // The rest of the component line from the DSC file should be defines\r | |
1048 | //\r | |
1049 | while (*End) {\r | |
1050 | End = StripLine (End);\r | |
1051 | if (*End) {\r | |
1052 | //\r | |
1053 | // If we're processing a "define abc=1 xyz=2" line, then set symbols\r | |
1054 | // as globals per the SymType set above.\r | |
1055 | //\r | |
1056 | Len = AddSymbol (End, NULL, SymType);\r | |
1057 | if (Len > 0) {\r | |
1058 | End += Len;\r | |
1059 | } else {\r | |
1060 | Warning (NULL, 0, 0, ArgLine, "unrecognized option in description file");\r | |
1061 | break;\r | |
1062 | }\r | |
1063 | }\r | |
1064 | }\r | |
1065 | \r | |
1066 | //\r | |
1067 | // If DEBUG_BREAK or EFI_BREAKPOINT is defined, then do a debug breakpoint.\r | |
1068 | //\r | |
1069 | if ((GetSymbolValue ("DEBUG_BREAK") != NULL) || (GetSymbolValue ("EFI_BREAKPOINT") != NULL)) {\r | |
1070 | EFI_BREAKPOINT ();\r | |
1071 | }\r | |
1072 | \r | |
1073 | //\r | |
1074 | // If it's a define line, then we're done\r | |
1075 | //\r | |
1076 | if (DefineLine) {\r | |
1077 | //\r | |
1078 | // If there is NonFFS_FV, create the FVxxx.inf file\r | |
1079 | // and include it in makefile.out. Remove the symbol\r | |
1080 | // in order not to process it again next time\r | |
1081 | //\r | |
1082 | Cptr = GetSymbolValue (NONFFS_FV);\r | |
1083 | if (Cptr != NULL) {\r | |
1084 | NonFFSFVWriteInfFiles (DSCFile, Cptr);\r | |
1085 | RemoveSymbol (NONFFS_FV, SYM_GLOBAL);\r | |
1086 | }\r | |
1087 | \r | |
1088 | goto ComponentDone;\r | |
1089 | }\r | |
1090 | \r | |
1091 | //\r | |
1092 | // Expand symbols in the component description filename to expand the newly \r | |
1093 | // added local symbols\r | |
1094 | //\r | |
1095 | ExpandSymbols (ArgLine, Line, sizeof (Line), EXPANDMODE_NO_UNDEFS);\r | |
95d675b5 | 1096 | \r |
3eb9473e | 1097 | //\r |
1098 | // If we have "c:\path\filename"\r | |
1099 | //\r | |
95d675b5 | 1100 | ReplaceSlash (Line);\r |
3eb9473e | 1101 | if (IsAbsolutePath (Line)) {\r |
1102 | ComponentFilePathAbsolute = 1;\r | |
1103 | } else if (Line[0] == '.') {\r | |
1104 | //\r | |
1105 | // or if the path starts with ".", then it's build-dir relative.\r | |
1106 | // Prepend $(BUILD_DIR) on the file name\r | |
1107 | //\r | |
1108 | sprintf (InLine, "%s\\%s", GetSymbolValue (BUILD_DIR), Line);\r | |
1109 | strcpy (Line, InLine);\r | |
1110 | ComponentFilePathAbsolute = 1;\r | |
1111 | }\r | |
1112 | \r | |
1113 | //\r | |
1114 | // Save the path from the component name for later. It may be relative or\r | |
1115 | // absolute.\r | |
1116 | //\r | |
1117 | strcpy (ComponentFilePath, Line);\r | |
1118 | Cptr = ComponentFilePath + strlen (ComponentFilePath) - 1;\r | |
95d675b5 | 1119 | while ((*Cptr != '\\') && (Cptr != ComponentFilePath)) {\r |
3eb9473e | 1120 | Cptr--;\r |
1121 | }\r | |
1122 | //\r | |
1123 | // Terminate the path.\r | |
1124 | //\r | |
1125 | *Cptr = 0;\r | |
1126 | \r | |
1127 | //\r | |
1128 | // Typically the given line is a component description filename. However we\r | |
1129 | // also allow a FV filename (fvvariable.ffs COMPONENT_TYPE=FILE). If the\r | |
1130 | // component type is "FILE", then add it to the FV list, create a package\r | |
1131 | // file, and we're done.\r | |
1132 | //\r | |
1133 | Cptr = GetSymbolValue (COMPONENT_TYPE);\r | |
1134 | if ((Cptr != NULL) && (strncmp (\r | |
1135 | Cptr,\r | |
1136 | COMPONENT_TYPE_FILE,\r | |
1137 | strlen (COMPONENT_TYPE_FILE)\r | |
1138 | ) == 0)) {\r | |
1139 | if (ComponentFilePathAbsolute) {\r | |
1140 | strcpy (InLine, Line);\r | |
1141 | } else {\r | |
1142 | sprintf (InLine, "%s\\%s", GetSymbolValue (EFI_SOURCE), Line);\r | |
1143 | }\r | |
1144 | CFVAddFVFile (\r | |
1145 | InLine,\r | |
1146 | Cptr,\r | |
1147 | GetSymbolValue (FV),\r | |
1148 | Instance,\r | |
1149 | NULL,\r | |
1150 | NULL,\r | |
1151 | GetSymbolValue (APRIORI),\r | |
1152 | NULL,\r | |
1153 | NULL\r | |
1154 | );\r | |
1155 | goto ComponentDone;\r | |
1156 | }\r | |
1157 | \r | |
1158 | //\r | |
1159 | // Better have defined processor by this point.\r | |
1160 | //\r | |
1161 | Processor = GetSymbolValue (PROCESSOR);\r | |
1162 | if (Processor == NULL) {\r | |
1163 | Error (NULL, 0, 0, NULL, "PROCESSOR not defined for component %s", Line);\r | |
1164 | return STATUS_ERROR;\r | |
1165 | }\r | |
1166 | \r | |
1167 | //\r | |
1168 | // The bin, out, and lib dirs are now = $(BUILD_DIR)/$(PROCESSOR). Set them.\r | |
1169 | // Don't flag them as file paths (required for short 8.3 filenames) since\r | |
1170 | // they're defined using the BUILD_DIR macro.\r | |
1171 | //\r | |
1172 | sprintf (InLine, "$(BUILD_DIR)\\%s", Processor);\r | |
1173 | AddSymbol (BIN_DIR, InLine, SYM_LOCAL);\r | |
1174 | AddSymbol (OUT_DIR, InLine, SYM_LOCAL);\r | |
1175 | AddSymbol (LIB_DIR, InLine, SYM_LOCAL);\r | |
1176 | //\r | |
1177 | // See if it's been destined for an FV. It's possible to not be in an\r | |
1178 | // FV if they just want to build it.\r | |
1179 | //\r | |
1180 | Cptr = GetSymbolValue (FV);\r | |
1181 | if ((Cptr != NULL) && !IS_NULL_SYMBOL_VALUE (Cptr)) {\r | |
1182 | IsForFv = TRUE;\r | |
1183 | } else {\r | |
1184 | IsForFv = FALSE;\r | |
1185 | }\r | |
1186 | //\r | |
1187 | // As an optimization, if they've defined SKIP_FV_NULL as non-zero, and\r | |
1188 | // the component is not destined for an FV, then skip it.\r | |
1189 | // Since libraries are never intended for firmware volumes, we have to\r | |
1190 | // build all of them.\r | |
1191 | //\r | |
1192 | if ((DscSectionType == DSC_SECTION_TYPE_COMPONENTS) && (IsForFv == FALSE)) {\r | |
1193 | if ((GetSymbolValue (SKIP_FV_NULL) != NULL) && (atoi (GetSymbolValue (SKIP_FV_NULL)) != 0)) {\r | |
1194 | Message (0, "%s not being built (FV=NULL)", FileName);\r | |
1195 | goto ComponentDone;\r | |
1196 | }\r | |
1197 | }\r | |
1198 | //\r | |
1199 | // Prepend EFI_SOURCE to the component description file to get the\r | |
1200 | // full path. Only do this if the path is not a full path already.\r | |
1201 | //\r | |
1202 | if (ComponentFilePathAbsolute == 0) {\r | |
1203 | name = GetSymbolValue (EFI_SOURCE);\r | |
1204 | sprintf (FileName, "%s\\%s", name, Line);\r | |
1205 | } else {\r | |
1206 | strcpy (FileName, Line);\r | |
1207 | }\r | |
1208 | //\r | |
1209 | // Print a message, depending on verbose level.\r | |
1210 | //\r | |
1211 | if (DscSectionType == DSC_SECTION_TYPE_COMPONENTS) {\r | |
1212 | Message (1, "Processing component %s", FileName);\r | |
1213 | } else {\r | |
1214 | Message (1, "Processing library %s", FileName);\r | |
1215 | }\r | |
1216 | //\r | |
1217 | // Open the component's description file and get the sections. If we fail\r | |
1218 | // to open it, see if they defined "OPTIONAL=1, in which case we'll just\r | |
1219 | // ignore the component.\r | |
1220 | //\r | |
1221 | TempFptr = fopen (FileName, "r");\r | |
1222 | if (TempFptr == NULL) {\r | |
1223 | //\r | |
1224 | // Better have defined OPTIONAL\r | |
1225 | //\r | |
1226 | if (GetSymbolValue (OPTIONAL_COMPONENT) != NULL) {\r | |
1227 | if (atoi (GetSymbolValue (OPTIONAL_COMPONENT)) != 0) {\r | |
1228 | Message (0, "Optional component '%s' not found", FileName);\r | |
1229 | goto ComponentDone;\r | |
1230 | }\r | |
1231 | }\r | |
1232 | \r | |
1233 | ParserError (0, FileName, "failed to open component file");\r | |
1234 | return STATUS_ERROR;\r | |
1235 | } else {\r | |
1236 | fclose (TempFptr);\r | |
1237 | }\r | |
1238 | \r | |
1239 | DSCFileInit (&ComponentFile);\r | |
1240 | ComponentCreated = 1;\r | |
1241 | if (DSCFileSetFile (&ComponentFile, FileName)) {\r | |
1242 | Error (NULL, 0, 0, NULL, "failed to preprocess component file '%s'", FileName);\r | |
1243 | return STATUS_ERROR;\r | |
1244 | }\r | |
1245 | //\r | |
1246 | // Add a symbol for the INF filename so users can create dependencies\r | |
1247 | // in makefiles.\r | |
1248 | //\r | |
1249 | AddSymbol (INF_FILENAME, FileName, SYM_OVERWRITE | SYM_LOCAL | SYM_FILENAME);\r | |
1250 | //\r | |
1251 | // Process the [defines], [defines.$(PROCESSOR)], and [defines.$(PROCESSOR).$(PLATFORM)]\r | |
1252 | // sections in the INF file\r | |
1253 | //\r | |
1254 | ProcessINFDefinesSection (&ComponentFile);\r | |
1255 | //\r | |
1256 | // Better have defined FILE_GUID if not a library\r | |
1257 | //\r | |
1258 | if ((GetSymbolValue (GUID) == NULL) &&\r | |
1259 | (GetSymbolValue (FILE_GUID) == NULL) &&\r | |
1260 | (DscSectionType == DSC_SECTION_TYPE_COMPONENTS)\r | |
1261 | ) {\r | |
1262 | Error (GetSymbolValue (INF_FILENAME), 1, 0, NULL, "missing FILE_GUID definition in component file");\r | |
1263 | DSCFileDestroy (&ComponentFile);\r | |
1264 | return STATUS_ERROR;\r | |
1265 | }\r | |
1266 | //\r | |
1267 | // Better have defined base name\r | |
1268 | //\r | |
1269 | if (GetSymbolValue (BASE_NAME) == NULL) {\r | |
1270 | Error (GetSymbolValue (INF_FILENAME), 1, 0, NULL, "missing BASE_NAME definition in INF file");\r | |
1271 | DSCFileDestroy (&ComponentFile);\r | |
1272 | return STATUS_ERROR;\r | |
1273 | }\r | |
1274 | //\r | |
1275 | // Better have defined COMPONENT_TYPE, since it's used to find named sections.\r | |
1276 | //\r | |
1277 | if (GetSymbolValue (COMPONENT_TYPE) == NULL) {\r | |
1278 | Error (GetSymbolValue (INF_FILENAME), 1, 0, NULL, "missing COMPONENT_TYPE definition in INF file");\r | |
1279 | DSCFileDestroy (&ComponentFile);\r | |
1280 | return STATUS_ERROR;\r | |
1281 | }\r | |
1282 | \r | |
1283 | //\r | |
1284 | // Create the source directory path from the component file's path. If the component\r | |
1285 | // file's path is absolute, we may have problems here. Try to account for it though.\r | |
1286 | //\r | |
1287 | if (ComponentFilePathAbsolute == 0) {\r | |
1288 | sprintf (\r | |
1289 | FileName,\r | |
1290 | "%s\\%s",\r | |
1291 | GetSymbolValue (EFI_SOURCE),\r | |
1292 | ComponentFilePath\r | |
1293 | );\r | |
1294 | } else {\r | |
1295 | strcpy (FileName, ComponentFilePath);\r | |
1296 | }\r | |
1297 | AddSymbol (SOURCE_DIR, FileName, SYM_OVERWRITE | SYM_LOCAL | SYM_FILEPATH);\r | |
1298 | \r | |
1299 | //\r | |
1300 | // Create the destination path. \r | |
1301 | // They may have defined DEST_DIR on the component INF line, so it's already\r | |
1302 | // been defined, If that's the case, then don't set it to the path of this file.\r | |
1303 | //\r | |
95d675b5 | 1304 | TempCptr = GetSymbolValue (DEST_DIR);\r |
1305 | if (TempCptr == NULL) {\r | |
3eb9473e | 1306 | if (ComponentFilePathAbsolute == 0) {\r |
1307 | //\r | |
1308 | // The destination path is $(BUILD_DIR)\$(PROCESSOR)\component_path\r | |
1309 | //\r | |
1310 | sprintf (\r | |
1311 | FileName,\r | |
1312 | "%s\\%s\\%s",\r | |
1313 | GetSymbolValue (BUILD_DIR),\r | |
1314 | Processor,\r | |
1315 | ComponentFilePath\r | |
1316 | );\r | |
1317 | } else {\r | |
1318 | //\r | |
1319 | // The destination path is $(BUILD_DIR)\$(PROCESSOR)\$(BASE_NAME)\r | |
1320 | //\r | |
1321 | sprintf (\r | |
1322 | FileName,\r | |
1323 | "%s\\%s\\%s",\r | |
1324 | GetSymbolValue (BUILD_DIR),\r | |
1325 | Processor,\r | |
1326 | GetSymbolValue (BASE_NAME)\r | |
1327 | );\r | |
1328 | }\r | |
1329 | AddSymbol (DEST_DIR, FileName, SYM_OVERWRITE | SYM_LOCAL | SYM_FILEPATH);\r | |
95d675b5 | 1330 | } else {\r |
1331 | ReplaceSlash (TempCptr);\r | |
3eb9473e | 1332 | }\r |
1333 | \r | |
1334 | //\r | |
1335 | // Create the output directory, then open the output component's makefile\r | |
1336 | // we're going to create. Allow them to override the makefile name.\r | |
1337 | //\r | |
1338 | TempCptr = GetSymbolValue (MAKEFILE_NAME);\r | |
1339 | if (TempCptr != NULL) {\r | |
1340 | ExpandSymbols (TempCptr, ComponentMakefileName, sizeof (ComponentMakefileName), EXPANDMODE_NO_UNDEFS);\r | |
1341 | TempCptr = ComponentMakefileName;\r | |
1342 | } else {\r | |
1343 | TempCptr = "makefile";\r | |
1344 | }\r | |
1345 | \r | |
1346 | sprintf (FileName, "%s\\%s", GetSymbolValue (DEST_DIR), TempCptr);\r | |
1347 | //\r | |
1348 | // Save it now with path info\r | |
1349 | //\r | |
1350 | AddSymbol (MAKEFILE_NAME, FileName, SYM_OVERWRITE | SYM_LOCAL | SYM_FILENAME);\r | |
1351 | \r | |
1352 | if (MakeFilePath (FileName)) {\r | |
1353 | return STATUS_ERROR;\r | |
1354 | }\r | |
1355 | \r | |
1356 | if ((MakeFptr = fopen (FileName, "w")) == NULL) {\r | |
1357 | Error (NULL, 0, 0, FileName, "could not create makefile");\r | |
1358 | return STATUS_ERROR;\r | |
1359 | }\r | |
1360 | //\r | |
1361 | // At this point we should have all the info we need to create a package\r | |
1362 | // file if setup to do so. Libraries don't use package files, so\r | |
1363 | // don't do this for libs.\r | |
1364 | //\r | |
1365 | if (DscSectionType == DSC_SECTION_TYPE_COMPONENTS) {\r | |
1366 | CreatePackageFile (DSCFile);\r | |
1367 | }\r | |
1368 | \r | |
3e99020d LG |
1369 | //\r |
1370 | // Add a new build item to mCurrentBuildList\r | |
1371 | //\r | |
1372 | mCurrentBuildItem = AddBuildItem (mCurrentBuildList, GetSymbolValue (BASE_NAME), Processor, FileName);\r | |
1373 | //\r | |
1374 | // ProcessDsc allows duplicate base name libraries. Make sure the duplicate \r | |
1375 | // base name libraries will be built in the same order as listed in DSC file.\r | |
1376 | //\r | |
1377 | AddDependency (*mCurrentBuildList, mCurrentBuildItem, mCurrentBuildItem->BaseName, 1);\r | |
1378 | \r | |
3eb9473e | 1379 | //\r |
1380 | // Add Module name to the global module list\r | |
1381 | //\r | |
1382 | AddModuleName (&gGlobals.ModuleList, GetSymbolValue (BASE_NAME), GetSymbolValue (INF_FILENAME));\r | |
1383 | //\r | |
1384 | // Write an nmake line to makefile.out\r | |
1385 | //\r | |
1386 | fprintf (gGlobals.MakefileFptr, " @cd %s\n", Processor);\r | |
1387 | fprintf (gGlobals.MakefileFptr, " $(MAKE) -f %s all\n", FileName);\r | |
1388 | fprintf (gGlobals.MakefileFptr, " @cd ..\n");\r | |
1389 | \r | |
1390 | //\r | |
1391 | // Copy the common makefile section from the description file to\r | |
1392 | // the component's makefile\r | |
1393 | //\r | |
1394 | WriteCommonMakefile (DSCFile, MakeFptr, Processor);\r | |
1395 | //\r | |
1396 | // Process the component's [nmake.common] and [nmake.$(PROCESSOR)] sections\r | |
1397 | //\r | |
1398 | ProcessINFNMakeSection (&ComponentFile, MakeFptr);\r | |
1399 | //\r | |
1400 | // Create the SOURCE_FILES macro that includes the names of all source\r | |
1401 | // files in this component. This macro can then be used elsewhere to\r | |
1402 | // process all the files making up the component. Required for scanning\r | |
1403 | // files for string localization.\r | |
3e99020d | 1404 | // Also add source files to mCurrentBuildItem.\r |
3eb9473e | 1405 | //\r |
1406 | ProcessSourceFiles (DSCFile, &ComponentFile, MakeFptr, SOURCE_MODE_SOURCE_FILES);\r | |
1407 | //\r | |
1408 | // Create the include paths. Process [includes.common] and\r | |
1409 | // [includes.$(PROCESSOR)] and [includes.$(PROCESSOR).$(PLATFORM)] sections.\r | |
1410 | //\r | |
1411 | ProcessIncludesSection (&ComponentFile, MakeFptr);\r | |
1412 | //\r | |
1413 | // Process all include source files to create a dependency list that can\r | |
1414 | // be used in the makefile.\r | |
1415 | //\r | |
1416 | ProcessIncludeFiles (&ComponentFile, MakeFptr);\r | |
1417 | //\r | |
1418 | // Process the [sources.common], [sources.$(PROCESSOR)], and\r | |
1419 | // [sources.$(PROCESSOR).$(PLATFORM)] files and emit their build commands\r | |
1420 | //\r | |
1421 | ProcessSourceFiles (DSCFile, &ComponentFile, MakeFptr, SOURCE_MODE_BUILD_COMMANDS);\r | |
1422 | //\r | |
1423 | // Process sources again to create an OBJECTS macro\r | |
1424 | //\r | |
1425 | ProcessObjects (&ComponentFile, MakeFptr);\r | |
1426 | \r | |
1427 | //\r | |
1428 | // Add Single Module target : build and clean in top level makefile\r | |
1429 | //\r | |
1430 | fprintf (gGlobals.ModuleMakefileFptr, "%sbuild ::", GetSymbolValue (BASE_NAME));\r | |
1431 | if (DscSectionType == DSC_SECTION_TYPE_COMPONENTS) {\r | |
1432 | fprintf (gGlobals.ModuleMakefileFptr, " %sbuild", GLOBAL_LINK_LIB_NAME);\r | |
1433 | }\r | |
1434 | \r | |
1435 | //\r | |
1436 | // Process all the libraries to define "LIBS = x.lib y.lib..."\r | |
1437 | // Be generous and append ".lib" if they forgot.\r | |
1438 | // Make a macro definition: LIBS = $(LIBS) xlib.lib ylib.lib...\r | |
3e99020d LG |
1439 | // Add libs dependency for single module build: basenamebuild :: xlibbuild ylibbuild ...\r |
1440 | // Also add libs dependency to mCurrentBuildItem.\r | |
3eb9473e | 1441 | //\r |
1442 | ProcessLibs (&ComponentFile, MakeFptr);\r | |
1443 | \r | |
1444 | fprintf (gGlobals.ModuleMakefileFptr, "\n");\r | |
1445 | \r | |
1446 | fprintf (gGlobals.ModuleMakefileFptr, " @cd %s\n", Processor);\r | |
1447 | fprintf (gGlobals.ModuleMakefileFptr, " $(MAKE) -f %s all\n", FileName);\r | |
1448 | fprintf (gGlobals.ModuleMakefileFptr, " @cd ..\n\n");\r | |
1449 | \r | |
1450 | fprintf (gGlobals.ModuleMakefileFptr, "%sclean ::\n", GetSymbolValue (BASE_NAME));\r | |
1451 | fprintf (gGlobals.ModuleMakefileFptr, " $(MAKE) -f %s clean\n\n", FileName);\r | |
1452 | \r | |
1453 | //\r | |
1454 | // Emit commands to create the component. These are simply copied from\r | |
1455 | // the description file to the component's makefile. First look for\r | |
1456 | // [build.$(PROCESSOR).$(BUILD_TYPE)]. If not found, then look for if\r | |
1457 | // find a [build.$(PROCESSOR).$(COMPONENT_TYPE)] line.\r | |
1458 | //\r | |
1459 | Cptr = GetSymbolValue (BUILD_TYPE);\r | |
1460 | if (Cptr != NULL) {\r | |
1461 | sprintf (InLine, "build.%s.%s", Processor, Cptr);\r | |
1462 | WriteComponentTypeBuildCommands (DSCFile, MakeFptr, InLine);\r | |
1463 | } else {\r | |
1464 | sprintf (InLine, "build.%s.%s", Processor, GetSymbolValue (COMPONENT_TYPE));\r | |
1465 | WriteComponentTypeBuildCommands (DSCFile, MakeFptr, InLine);\r | |
1466 | }\r | |
1467 | //\r | |
1468 | // Add it to the FV if not a library\r | |
1469 | //\r | |
1470 | if (DscSectionType == DSC_SECTION_TYPE_COMPONENTS) {\r | |
1471 | //\r | |
1472 | // Create the FV filename and add it to the FV.\r | |
1473 | // By this point we know it's in FV.\r | |
1474 | //\r | |
1475 | Cptr = GetSymbolValue (FILE_GUID);\r | |
1476 | if (Cptr == NULL) {\r | |
1477 | Cptr = GetSymbolValue (GUID);\r | |
1478 | }\r | |
1479 | \r | |
1480 | sprintf (InLine, "%s-%s", Cptr, GetSymbolValue (BASE_NAME));\r | |
1481 | //\r | |
1482 | // We've deprecated FV_EXT, which should be FFS_EXT, the extension\r | |
1483 | // of the FFS file generated by GenFFSFile.\r | |
1484 | //\r | |
1485 | TempCptr = GetSymbolValue (FFS_EXT);\r | |
1486 | if (TempCptr == NULL) {\r | |
1487 | TempCptr = GetSymbolValue ("FV_EXT");\r | |
1488 | }\r | |
1489 | \r | |
1490 | CFVAddFVFile (\r | |
1491 | InLine,\r | |
1492 | GetSymbolValue (COMPONENT_TYPE),\r | |
1493 | GetSymbolValue (FV),\r | |
1494 | Instance,\r | |
1495 | TempCptr,\r | |
1496 | Processor,\r | |
1497 | GetSymbolValue (APRIORI),\r | |
1498 | GetSymbolValue (BASE_NAME),\r | |
1499 | Cptr\r | |
1500 | );\r | |
1501 | }\r | |
1502 | //\r | |
1503 | // Catch any failures and print the name of the component file\r | |
1504 | // being processed to assist debugging.\r | |
1505 | //\r | |
1506 | ComponentDone:\r | |
1507 | \r | |
1508 | Cptr = CatchException ();\r | |
1509 | if (Cptr != NULL) {\r | |
1510 | fprintf (stderr, "%s\n", Cptr);\r | |
1511 | sprintf (InLine, "Processing of component %s failed", ArgLine);\r | |
1512 | ThrowException (InLine);\r | |
1513 | }\r | |
1514 | \r | |
1515 | if (MakeFptr != NULL) {\r | |
1516 | fclose (MakeFptr);\r | |
1517 | }\r | |
1518 | \r | |
1519 | if (ComponentCreated) {\r | |
1520 | DSCFileDestroy (&ComponentFile);\r | |
1521 | }\r | |
1522 | \r | |
1523 | return STATUS_SUCCESS;\r | |
1524 | }\r | |
1525 | \r | |
1526 | static\r | |
1527 | int\r | |
1528 | CreatePackageFile (\r | |
1529 | DSC_FILE *DSCFile\r | |
1530 | )\r | |
1531 | {\r | |
1532 | INT8 *Package;\r | |
1533 | SECTION *TempSect;\r | |
1534 | INT8 Str[MAX_LINE_LEN];\r | |
1535 | INT8 StrExpanded[MAX_LINE_LEN];\r | |
1536 | SMART_FILE *PkgFptr;\r | |
1537 | int Status;\r | |
1538 | \r | |
1539 | PkgFptr = NULL;\r | |
1540 | \r | |
1541 | //\r | |
1542 | // First find out if PACKAGE_FILENAME or PACKAGE is defined. PACKAGE_FILENAME\r | |
1543 | // is used to specify the exact package file to use. PACKAGE is used to\r | |
1544 | // specify the package section name.\r | |
1545 | //\r | |
1546 | Package = GetSymbolValue (PACKAGE_FILENAME);\r | |
1547 | if (Package != NULL) {\r | |
1548 | //\r | |
1549 | // Use existing file. We're done.\r | |
1550 | //\r | |
1551 | return STATUS_SUCCESS;\r | |
1552 | }\r | |
1553 | //\r | |
1554 | // See if PACKAGE or PACKAGE_TAG is defined\r | |
1555 | //\r | |
1556 | Package = GetSymbolValue (PACKAGE);\r | |
1557 | if (Package == NULL) {\r | |
1558 | Package = GetSymbolValue (PACKAGE_TAG);\r | |
1559 | }\r | |
1560 | \r | |
1561 | if (Package == NULL) {\r | |
1562 | //\r | |
1563 | // Not defined either. Assume they are not using the package functionality\r | |
1564 | // of this utility. However define the PACKAGE_FILENAME macro to the\r | |
1565 | // best-guess value.\r | |
1566 | //\r | |
1567 | sprintf (\r | |
1568 | Str,\r | |
1569 | "%s\\%s.pkg",\r | |
1570 | GetSymbolValue (SOURCE_DIR),\r | |
1571 | GetSymbolValue (BASE_NAME)\r | |
1572 | );\r | |
1573 | \r | |
1574 | //\r | |
1575 | // Expand symbols in the package filename\r | |
1576 | //\r | |
1577 | ExpandSymbols (Str, StrExpanded, sizeof (StrExpanded), EXPANDMODE_NO_UNDEFS); \r | |
1578 | \r | |
1579 | AddSymbol (PACKAGE_FILENAME, StrExpanded, SYM_LOCAL | SYM_FILENAME);\r | |
1580 | return STATUS_SUCCESS;\r | |
1581 | }\r | |
1582 | //\r | |
1583 | // Save the position in the DSC file.\r | |
1584 | // Find the [package.$(COMPONENT_TYPE).$(PACKAGE)] section in the DSC file\r | |
1585 | //\r | |
1586 | Status = STATUS_SUCCESS;\r | |
1587 | DSCFileSavePosition (DSCFile);\r | |
1588 | sprintf (Str, "%s.%s.%s", PACKAGE, GetSymbolValue (COMPONENT_TYPE), Package);\r | |
1589 | TempSect = DSCFileFindSection (DSCFile, Str);\r | |
1590 | if (TempSect != NULL) {\r | |
1591 | //\r | |
1592 | // So far so good. Create the name of the package file, then open it up\r | |
1593 | // for writing. File name is c:\...\oem\platform\nt32\ia32\...\BaseName.pkg.\r | |
1594 | //\r | |
1595 | sprintf (\r | |
1596 | Str,\r | |
1597 | "%s\\%s.pkg",\r | |
1598 | GetSymbolValue (DEST_DIR),\r | |
1599 | GetSymbolValue (BASE_NAME)\r | |
1600 | );\r | |
1601 | \r | |
1602 | //\r | |
1603 | // Expand symbols in the package filename\r | |
1604 | //\r | |
1605 | ExpandSymbols (Str, StrExpanded, sizeof (StrExpanded), EXPANDMODE_NO_UNDEFS); \r | |
1606 | \r | |
1607 | //\r | |
1608 | // Try to open the file, then save the file name as the PACKAGE_FILENAME\r | |
1609 | // symbol for use elsewhere.\r | |
1610 | //\r | |
1611 | if ((PkgFptr = SmartOpen (StrExpanded)) == NULL) {\r | |
1612 | Error (NULL, 0, 0, Str, "could not open package file for writing");\r | |
1613 | Status = STATUS_ERROR;\r | |
1614 | goto Finish;\r | |
1615 | }\r | |
1616 | \r | |
1617 | AddSymbol (PACKAGE_FILENAME, StrExpanded, SYM_LOCAL | SYM_FILENAME);\r | |
1618 | //\r | |
1619 | // Now read lines in from the DSC file and write them back out to the\r | |
1620 | // package file (with string substitution).\r | |
1621 | //\r | |
1622 | while (DSCFileGetLine (DSCFile, Str, sizeof (Str)) != NULL) {\r | |
1623 | //\r | |
1624 | // Expand symbols, then write the line out to the package file\r | |
1625 | //\r | |
1626 | ExpandSymbols (Str, StrExpanded, sizeof (StrExpanded), EXPANDMODE_RECURSIVE);\r | |
1627 | SmartWrite (PkgFptr, StrExpanded);\r | |
1628 | }\r | |
1629 | } else {\r | |
1630 | Warning (\r | |
1631 | NULL,\r | |
1632 | 0,\r | |
1633 | 0,\r | |
1634 | NULL,\r | |
1635 | "cannot locate package section [%s] in DSC file for %s",\r | |
1636 | Str,\r | |
1637 | GetSymbolValue (INF_FILENAME)\r | |
1638 | );\r | |
1639 | Status = STATUS_WARNING;\r | |
1640 | goto Finish;\r | |
1641 | }\r | |
1642 | \r | |
1643 | if (PkgFptr != NULL) {\r | |
1644 | SmartClose (PkgFptr);\r | |
1645 | }\r | |
1646 | \r | |
1647 | Finish:\r | |
1648 | //\r | |
1649 | // Restore the position in the DSC file\r | |
1650 | //\r | |
1651 | DSCFileRestorePosition (DSCFile);\r | |
1652 | \r | |
1653 | return STATUS_SUCCESS;\r | |
1654 | }\r | |
1655 | \r | |
1656 | static\r | |
1657 | int\r | |
1658 | ProcessINFDefinesSection (\r | |
1659 | DSC_FILE *ComponentFile\r | |
1660 | )\r | |
1661 | /*++\r | |
1662 | \r | |
1663 | Routine Description:\r | |
1664 | \r | |
1665 | Process the [defines.xxx] sections of the component description file. Process\r | |
1666 | platform first, then processor. In this way, if a platform wants and override,\r | |
1667 | that one gets parsed first, and later assignments do not overwrite the value.\r | |
1668 | \r | |
1669 | Arguments:\r | |
1670 | \r | |
1671 | ComponentFile - section info on the component file being processed\r | |
1672 | \r | |
1673 | Returns:\r | |
1674 | \r | |
1675 | \r | |
1676 | --*/\r | |
1677 | {\r | |
1678 | INT8 *Cptr;\r | |
1679 | INT8 Str[MAX_LINE_LEN];\r | |
1680 | \r | |
1681 | //\r | |
1682 | // Find a [defines.$(PROCESSOR).$(PLATFORM)] section and process it\r | |
1683 | //\r | |
1684 | Cptr = GetSymbolValue (PLATFORM);\r | |
1685 | if (Cptr != NULL) {\r | |
1686 | sprintf (\r | |
1687 | Str,\r | |
1688 | "%s.%s.%s",\r | |
1689 | DEFINES_SECTION_NAME,\r | |
1690 | GetSymbolValue (PROCESSOR),\r | |
1691 | Cptr\r | |
1692 | );\r | |
1693 | ProcessINFDefinesSectionSingle (ComponentFile, Str);\r | |
1694 | }\r | |
1695 | //\r | |
1696 | // Find a [defines.$(PROCESSOR)] section and process it\r | |
1697 | //\r | |
1698 | sprintf (Str, "%s.%s", DEFINES_SECTION_NAME, GetSymbolValue (PROCESSOR));\r | |
1699 | ProcessINFDefinesSectionSingle (ComponentFile, Str);\r | |
1700 | \r | |
1701 | //\r | |
1702 | // Find a [defines] section and process it\r | |
1703 | //\r | |
1704 | if (ProcessINFDefinesSectionSingle (ComponentFile, DEFINES_SECTION_NAME) != STATUS_SUCCESS) {\r | |
1705 | Error (NULL, 0, 0, NULL, "missing [defines] section in component file %s", GetSymbolValue (INF_FILENAME));\r | |
1706 | return STATUS_ERROR;\r | |
1707 | }\r | |
1708 | \r | |
1709 | return STATUS_SUCCESS;\r | |
1710 | }\r | |
1711 | \r | |
1712 | static\r | |
1713 | int\r | |
1714 | ProcessINFDefinesSectionSingle (\r | |
1715 | DSC_FILE *ComponentFile,\r | |
1716 | INT8 *SectionName\r | |
1717 | )\r | |
1718 | {\r | |
1719 | INT8 *Cptr;\r | |
1720 | INT8 Str[MAX_LINE_LEN];\r | |
1721 | INT8 ExpandedLine[MAX_LINE_LEN];\r | |
1722 | SECTION *TempSect;\r | |
1723 | \r | |
1724 | TempSect = DSCFileFindSection (ComponentFile, SectionName);\r | |
1725 | if (TempSect != NULL) {\r | |
1726 | while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r | |
1727 | ExpandSymbols (Str, ExpandedLine, sizeof (ExpandedLine), 0);\r | |
1728 | Cptr = StripLine (ExpandedLine);\r | |
1729 | //\r | |
1730 | // Don't process blank lines.\r | |
1731 | //\r | |
1732 | if (*Cptr) {\r | |
1733 | //\r | |
1734 | // Add without overwriting macros specified on the component line\r | |
1735 | // in the description file\r | |
1736 | //\r | |
1737 | AddSymbol (Cptr, NULL, SYM_LOCAL);\r | |
1738 | }\r | |
1739 | }\r | |
1740 | } else {\r | |
1741 | return STATUS_WARNING;\r | |
1742 | }\r | |
1743 | \r | |
1744 | return STATUS_SUCCESS;\r | |
1745 | }\r | |
1746 | \r | |
1747 | static\r | |
1748 | int\r | |
1749 | ProcessINFNMakeSection (\r | |
1750 | DSC_FILE *ComponentFile,\r | |
1751 | FILE *MakeFptr\r | |
1752 | )\r | |
1753 | /*++\r | |
1754 | \r | |
1755 | Routine Description:\r | |
1756 | \r | |
1757 | Process the [nmake.common] and [nmake.$(PROCESSOR)] sections of the component\r | |
1758 | description file and write and copy them to the component's makefile.\r | |
1759 | \r | |
1760 | Arguments:\r | |
1761 | \r | |
1762 | ComponentFile - section info on the component file being processed\r | |
1763 | MakeFptr - file pointer to the component' makefile we're creating\r | |
1764 | \r | |
1765 | Returns:\r | |
1766 | \r | |
1767 | Always STATUS_SUCCESS right now, since the sections are optional.\r | |
1768 | \r | |
1769 | --*/\r | |
1770 | {\r | |
1771 | INT8 *Cptr;\r | |
1772 | INT8 Str[MAX_LINE_LEN];\r | |
1773 | INT8 ExpandedLine[MAX_LINE_LEN];\r | |
1774 | SECTION *TempSect;\r | |
1775 | \r | |
1776 | //\r | |
1777 | // Copy the [nmake.common] and [nmake.$(PROCESSOR)] sections from the\r | |
1778 | // component file directly to the output file.\r | |
1779 | // The line will be stripped and don't print blank lines\r | |
1780 | //\r | |
1781 | sprintf (Str, "%s.%s", NMAKE_SECTION_NAME, COMMON_SECTION_NAME);\r | |
1782 | TempSect = DSCFileFindSection (ComponentFile, Str);\r | |
1783 | if (TempSect != NULL) {\r | |
1784 | while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r | |
1785 | ExpandSymbols (\r | |
1786 | Str,\r | |
1787 | ExpandedLine,\r | |
1788 | sizeof (ExpandedLine),\r | |
1789 | EXPANDMODE_NO_DESTDIR | EXPANDMODE_NO_SOURCEDIR\r | |
1790 | );\r | |
1791 | Cptr = StripLine (ExpandedLine);\r | |
1792 | if (*Cptr) {\r | |
1793 | fprintf (MakeFptr, "%s\n", Cptr);\r | |
1794 | }\r | |
1795 | }\r | |
1796 | \r | |
1797 | fprintf (MakeFptr, "\n");\r | |
1798 | } else {\r | |
1799 | Error (GetSymbolValue (INF_FILENAME), 1, 0, Str, "section not found in component INF file");\r | |
1800 | }\r | |
1801 | \r | |
1802 | sprintf (Str, "%s.%s", NMAKE_SECTION_NAME, GetSymbolValue (PROCESSOR));\r | |
1803 | TempSect = DSCFileFindSection (ComponentFile, Str);\r | |
1804 | if (TempSect != NULL) {\r | |
1805 | while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r | |
1806 | ExpandSymbols (\r | |
1807 | Str,\r | |
1808 | ExpandedLine,\r | |
1809 | sizeof (ExpandedLine),\r | |
1810 | EXPANDMODE_NO_DESTDIR | EXPANDMODE_NO_SOURCEDIR\r | |
1811 | );\r | |
1812 | Cptr = StripLine (ExpandedLine);\r | |
1813 | if (*Cptr) {\r | |
1814 | fprintf (MakeFptr, "%s\n", Cptr);\r | |
1815 | }\r | |
1816 | }\r | |
1817 | \r | |
1818 | fprintf (MakeFptr, "\n");\r | |
1819 | }\r | |
1820 | //\r | |
1821 | // Do the same for [nmake.$(PROCESSOR).$(PLATFORM)]\r | |
1822 | //\r | |
1823 | Cptr = GetSymbolValue (PLATFORM);\r | |
1824 | if (Cptr != NULL) {\r | |
1825 | sprintf (Str, "%s.%s.%s", NMAKE_SECTION_NAME, GetSymbolValue (PROCESSOR), Cptr);\r | |
1826 | TempSect = DSCFileFindSection (ComponentFile, Str);\r | |
1827 | if (TempSect != NULL) {\r | |
1828 | while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r | |
1829 | ExpandSymbols (\r | |
1830 | Str,\r | |
1831 | ExpandedLine,\r | |
1832 | sizeof (ExpandedLine),\r | |
1833 | EXPANDMODE_NO_DESTDIR | EXPANDMODE_NO_SOURCEDIR\r | |
1834 | );\r | |
1835 | Cptr = StripLine (ExpandedLine);\r | |
1836 | if (*Cptr) {\r | |
1837 | fprintf (MakeFptr, "%s\n", Cptr);\r | |
1838 | }\r | |
1839 | }\r | |
1840 | \r | |
1841 | fprintf (MakeFptr, "\n");\r | |
1842 | }\r | |
1843 | }\r | |
1844 | \r | |
1845 | return STATUS_SUCCESS;\r | |
1846 | }\r | |
1847 | \r | |
1848 | static\r | |
1849 | int\r | |
1850 | ProcessIncludesSection (\r | |
1851 | DSC_FILE *ComponentFile,\r | |
1852 | FILE *MakeFptr\r | |
1853 | )\r | |
1854 | /*++\r | |
1855 | \r | |
1856 | Routine Description:\r | |
1857 | \r | |
1858 | Process the [includes.common], [includes.processor], and \r | |
1859 | [includes.processor.platform] section of the component description file \r | |
1860 | and write the appropriate macros to the component's makefile.\r | |
1861 | \r | |
1862 | Process in reverse order to allow overrides on platform basis.\r | |
1863 | \r | |
1864 | Arguments:\r | |
1865 | \r | |
1866 | ComponentFile - section info on the component file being processed\r | |
1867 | MakeFptr - file pointer to the component' makefile we're creating\r | |
1868 | \r | |
1869 | Returns:\r | |
1870 | \r | |
1871 | Always STATUS_SUCCESS right now, since the sections are optional.\r | |
1872 | \r | |
1873 | --*/\r | |
1874 | {\r | |
1875 | INT8 *Cptr;\r | |
1876 | INT8 Str[MAX_LINE_LEN];\r | |
1877 | INT8 *Processor;\r | |
1878 | INT8 *OverridePath;\r | |
1879 | \r | |
1880 | //\r | |
1881 | // Write a useful comment to the output makefile so the user knows where\r | |
1882 | // the data came from.\r | |
1883 | //\r | |
1884 | fprintf (MakeFptr, "#\n# Tool-generated list of include paths that are created\n");\r | |
1885 | fprintf (MakeFptr, "# from the list of include paths in the [includes.*] sections\n");\r | |
1886 | fprintf (MakeFptr, "# of the component INF file.\n#\n");\r | |
1887 | \r | |
1888 | //\r | |
1889 | // We use this a lot here, so get the value only once.\r | |
1890 | //\r | |
1891 | Processor = GetSymbolValue (PROCESSOR);\r | |
1892 | //\r | |
1893 | // If they're using an override source path, then add OverridePath and\r | |
1894 | // OverridePath\$(PROCESSOR) to the list of include paths.\r | |
1895 | //\r | |
1896 | OverridePath = GetSymbolValue (SOURCE_OVERRIDE_PATH);\r | |
1897 | if (OverridePath != NULL) {\r | |
95d675b5 | 1898 | ReplaceSlash (OverridePath);\r |
3e99020d | 1899 | fprintf (MakeFptr, "!IF EXIST(%s)\n", OverridePath);\r |
3eb9473e | 1900 | fprintf (MakeFptr, "INC = $(INC) -I %s\n", OverridePath);\r |
3e99020d LG |
1901 | fprintf (MakeFptr, "!IF EXIST(%s\\%s)\n", OverridePath, Processor);\r |
1902 | fprintf (MakeFptr, "INC = $(INC) -I %s\\%s\n", OverridePath, Processor);\r | |
1903 | fprintf (MakeFptr, "!ENDIF\n");\r | |
1904 | fprintf (MakeFptr, "!ELSE\n");\r | |
1905 | fprintf (MakeFptr, "!MESSAGE Warning: include dir %s does not exist\n", OverridePath);\r | |
1906 | fprintf (MakeFptr, "!ENDIF\n");\r | |
3eb9473e | 1907 | }\r |
1908 | //\r | |
1909 | // Try for an [includes.$(PROCESSOR).$(PLATFORM)]\r | |
1910 | //\r | |
1911 | Cptr = GetSymbolValue (PLATFORM);\r | |
1912 | if (Cptr != NULL) {\r | |
1913 | sprintf (Str, "%s.%s.%s", INCLUDE_SECTION_NAME, Processor, Cptr);\r | |
1914 | ProcessIncludesSectionSingle (ComponentFile, MakeFptr, Str);\r | |
1915 | }\r | |
1916 | //\r | |
1917 | // Now the [includes.$(PROCESSOR)] section\r | |
1918 | //\r | |
1919 | sprintf (Str, "%s.%s", INCLUDE_SECTION_NAME, Processor);\r | |
1920 | ProcessIncludesSectionSingle (ComponentFile, MakeFptr, Str);\r | |
1921 | \r | |
1922 | //\r | |
1923 | // Now the [includes.common] section\r | |
1924 | //\r | |
1925 | sprintf (Str, "%s.%s", INCLUDE_SECTION_NAME, COMMON_SECTION_NAME);\r | |
1926 | ProcessIncludesSectionSingle (ComponentFile, MakeFptr, Str);\r | |
1927 | \r | |
1928 | //\r | |
1929 | // Done\r | |
1930 | //\r | |
1931 | fprintf (MakeFptr, "\n");\r | |
1932 | return STATUS_SUCCESS;\r | |
1933 | }\r | |
1934 | //\r | |
1935 | // Process one of the [includes.xxx] sections to create a list of all\r | |
1936 | // the include paths.\r | |
1937 | //\r | |
1938 | static\r | |
1939 | int\r | |
1940 | ProcessIncludesSectionSingle (\r | |
1941 | DSC_FILE *ComponentFile,\r | |
1942 | FILE *MakeFptr,\r | |
1943 | INT8 *SectionName\r | |
1944 | )\r | |
1945 | {\r | |
1946 | INT8 *Cptr;\r | |
1947 | SECTION *TempSect;\r | |
1948 | INT8 Str[MAX_LINE_LEN];\r | |
1949 | INT8 ExpandedLine[MAX_LINE_LEN];\r | |
1950 | INT8 *Processor;\r | |
1951 | \r | |
1952 | TempSect = DSCFileFindSection (ComponentFile, SectionName);\r | |
1953 | if (TempSect != NULL) {\r | |
1954 | //\r | |
1955 | // Add processor subdirectory on every include path\r | |
1956 | //\r | |
1957 | Processor = GetSymbolValue (PROCESSOR);\r | |
1958 | //\r | |
1959 | // Copy lines directly\r | |
1960 | //\r | |
1961 | while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r | |
1962 | ExpandSymbols (Str, ExpandedLine, sizeof (ExpandedLine), 0);\r | |
1963 | Cptr = StripLine (ExpandedLine);\r | |
1964 | //\r | |
1965 | // Don't process blank lines\r | |
1966 | //\r | |
1967 | if (*Cptr) {\r | |
95d675b5 | 1968 | ReplaceSlash (Cptr);\r |
3eb9473e | 1969 | //\r |
1970 | // Strip off trailing slash\r | |
1971 | //\r | |
1972 | if (Cptr[strlen (Cptr) - 1] == '\\') {\r | |
1973 | Cptr[strlen (Cptr) - 1] = 0;\r | |
1974 | }\r | |
1975 | //\r | |
1976 | // Special case of ".". Replace it with source path\r | |
1977 | // and the rest of the line (for .\$(PROCESSOR))\r | |
1978 | //\r | |
1979 | if (*Cptr == '.') {\r | |
1980 | //\r | |
1981 | // Handle case of just a "."\r | |
1982 | //\r | |
1983 | if (Cptr[1] == 0) {\r | |
1984 | fprintf (MakeFptr, "INC = $(INC) -I $(SOURCE_DIR)\n");\r | |
3e99020d LG |
1985 | fprintf (MakeFptr, "!IF EXIST($(SOURCE_DIR)\\%s)\n", Processor);\r |
1986 | fprintf (MakeFptr, "INC = $(INC) -I $(SOURCE_DIR)\\%s\n", Processor);\r | |
1987 | fprintf (MakeFptr, "!ENDIF\n");\r | |
3eb9473e | 1988 | } else {\r |
1989 | //\r | |
1990 | // Handle case of ".\path\path\path" or "..\path\path\path"\r | |
1991 | //\r | |
3e99020d LG |
1992 | fprintf (MakeFptr, "!IF EXIST($(SOURCE_DIR)\\%s)\n", Cptr);\r |
1993 | fprintf (MakeFptr, "INC = $(INC) -I $(SOURCE_DIR)\\%s\n", Cptr);\r | |
1994 | fprintf (MakeFptr, "!IF EXIST($(SOURCE_DIR)\\%s\\%s)\n", Cptr, Processor);\r | |
1995 | fprintf (MakeFptr, "INC = $(INC) -I $(SOURCE_DIR)\\%s\\%s\n", Cptr, Processor);\r | |
1996 | fprintf (MakeFptr, "!ENDIF\n");\r | |
1997 | fprintf (MakeFptr, "!ELSE\n");\r | |
1998 | fprintf (MakeFptr, "!MESSAGE Warning: include dir $(SOURCE_DIR)\\%s does not exist\n", Cptr);\r | |
1999 | fprintf (MakeFptr, "!ENDIF\n");\r | |
3eb9473e | 2000 | }\r |
2001 | } else if ((Cptr[1] != ':') && isalpha (*Cptr)) {\r | |
3e99020d LG |
2002 | fprintf (MakeFptr, "!IF EXIST($(EFI_SOURCE)\\%s)\n", Cptr);\r |
2003 | fprintf (MakeFptr, "INC = $(INC) -I $(EFI_SOURCE)\\%s\n", Cptr);\r | |
2004 | fprintf (MakeFptr, "!IF EXIST($(EFI_SOURCE)\\%s\\%s)\n", Cptr, Processor);\r | |
2005 | fprintf (MakeFptr, "INC = $(INC) -I $(EFI_SOURCE)\\%s\\%s\n", Cptr, Processor);\r | |
2006 | fprintf (MakeFptr, "!ENDIF\n");\r | |
2007 | fprintf (MakeFptr, "!ELSE\n");\r | |
2008 | fprintf (MakeFptr, "!MESSAGE Warning: include dir $(EFI_SOURCE)\\%s does not exist\n", Cptr);\r | |
2009 | fprintf (MakeFptr, "!ENDIF\n");\r | |
3eb9473e | 2010 | } else {\r |
2011 | //\r | |
2012 | // The line is something like: $(EFI_SOURCE)\dxe\include. Add it to\r | |
2013 | // the existing $(INC) definition. Add user includes before any\r | |
2014 | // other existing paths.\r | |
2015 | //\r | |
3e99020d LG |
2016 | fprintf (MakeFptr, "!IF EXIST(%s)\n", Cptr);\r |
2017 | fprintf (MakeFptr, "INC = $(INC) -I %s\n", Cptr);\r | |
2018 | fprintf (MakeFptr, "!IF EXIST(%s\\%s)\n", Cptr, Processor);\r | |
2019 | fprintf (MakeFptr, "INC = $(INC) -I %s\\%s\n", Cptr, Processor);\r | |
2020 | fprintf (MakeFptr, "!ENDIF\n");\r | |
2021 | fprintf (MakeFptr, "!ELSE\n");\r | |
2022 | fprintf (MakeFptr, "!MESSAGE Warning: include dir %s does not exist\n", Cptr);\r | |
2023 | fprintf (MakeFptr, "!ENDIF\n");\r | |
3eb9473e | 2024 | }\r |
2025 | }\r | |
2026 | }\r | |
2027 | }\r | |
2028 | \r | |
2029 | return STATUS_SUCCESS;\r | |
2030 | }\r | |
2031 | \r | |
2032 | static\r | |
2033 | int\r | |
2034 | ProcessSourceFiles (\r | |
2035 | DSC_FILE *DSCFile,\r | |
2036 | DSC_FILE *ComponentFile,\r | |
2037 | FILE *MakeFptr,\r | |
2038 | UINT32 Mode\r | |
2039 | )\r | |
2040 | /*++\r | |
2041 | \r | |
2042 | Routine Description:\r | |
2043 | \r | |
2044 | Process the [sources.common], [sources.$(PROCESSOR)], and \r | |
2045 | [sources.$(PROCESSOR).$(PLATFORM] sections of the component\r | |
2046 | description file and write the appropriate build commands out to the \r | |
2047 | component's makefile. If $(SOURCE_SELECT) is defined, then it overrides\r | |
2048 | the source selections. We use this functionality for SMM.\r | |
2049 | \r | |
2050 | Arguments:\r | |
2051 | \r | |
2052 | ComponentFile - section info on the component file being processed\r | |
2053 | MakeFptr - file pointer to the component' makefile we're creating\r | |
2054 | DSCFile - section info on the description file we're processing\r | |
2055 | Mode - to write build commands, or just create a list\r | |
2056 | of sources.\r | |
2057 | \r | |
2058 | Returns:\r | |
2059 | \r | |
2060 | Always STATUS_SUCCESS right now, since the sections are optional.\r | |
2061 | \r | |
2062 | --*/\r | |
2063 | {\r | |
2064 | INT8 Str[MAX_LINE_LEN];\r | |
2065 | INT8 *Processor;\r | |
2066 | INT8 *Platform;\r | |
2067 | INT8 *SourceSelect;\r | |
2068 | INT8 *CStart;\r | |
2069 | INT8 *CEnd;\r | |
2070 | INT8 CSave;\r | |
2071 | INT8 *CopySourceSelect;\r | |
2072 | \r | |
2073 | if (Mode & SOURCE_MODE_SOURCE_FILES) {\r | |
2074 | //\r | |
2075 | // Write a useful comment to the output makefile so the user knows where\r | |
2076 | // the data came from.\r | |
2077 | //\r | |
2078 | fprintf (MakeFptr, "#\n# Tool-generated list of source files that are created\n");\r | |
2079 | fprintf (MakeFptr, "# from the list of source files in the [sources.*] sections\n");\r | |
2080 | fprintf (MakeFptr, "# of the component INF file.\n#\n");\r | |
2081 | }\r | |
2082 | \r | |
2083 | //\r | |
2084 | // We use this a lot here, so get the value only once.\r | |
2085 | //\r | |
2086 | Processor = GetSymbolValue (PROCESSOR);\r | |
2087 | //\r | |
2088 | // See if they defined SOURCE_SELECT=xxx,yyy in which case we'll\r | |
2089 | // select each [sources.xxx] and [sources.yyy] files and process\r | |
2090 | // them.\r | |
2091 | //\r | |
2092 | SourceSelect = GetSymbolValue (SOURCE_SELECT);\r | |
2093 | \r | |
2094 | if (SourceSelect != NULL) {\r | |
2095 | //\r | |
2096 | // Make a copy of the string and break it up (comma-separated) and\r | |
2097 | // select each [sources.*] file from the INF.\r | |
2098 | //\r | |
2099 | CopySourceSelect = (INT8 *) malloc (strlen (SourceSelect) + 1);\r | |
2100 | if (CopySourceSelect == NULL) {\r | |
2101 | Error (NULL, 0, 0, NULL, "failed to allocate memory");\r | |
2102 | return STATUS_ERROR;\r | |
2103 | }\r | |
2104 | \r | |
2105 | strcpy (CopySourceSelect, SourceSelect);\r | |
2106 | CStart = CopySourceSelect;\r | |
2107 | CEnd = CStart;\r | |
2108 | while (*CStart) {\r | |
2109 | CEnd = CStart + 1;\r | |
2110 | while (*CEnd && *CEnd != ',') {\r | |
2111 | CEnd++;\r | |
2112 | }\r | |
2113 | \r | |
2114 | CSave = *CEnd;\r | |
2115 | *CEnd = 0;\r | |
2116 | sprintf (Str, "%s.%s", SOURCES_SECTION_NAME, CStart);\r | |
2117 | ProcessSourceFilesSection (DSCFile, ComponentFile, MakeFptr, Str, Mode);\r | |
2118 | //\r | |
2119 | // Restore the terminator and advance\r | |
2120 | //\r | |
2121 | *CEnd = CSave;\r | |
2122 | CStart = CEnd;\r | |
2123 | if (*CStart) {\r | |
2124 | CStart++;\r | |
2125 | }\r | |
2126 | }\r | |
2127 | \r | |
2128 | free (CopySourceSelect);\r | |
2129 | \r | |
2130 | } else {\r | |
2131 | //\r | |
2132 | // Process all the [sources.common] source files to make them build\r | |
2133 | //\r | |
2134 | sprintf (Str, "%s.%s", SOURCES_SECTION_NAME, COMMON_SECTION_NAME);\r | |
2135 | ProcessSourceFilesSection (DSCFile, ComponentFile, MakeFptr, Str, Mode);\r | |
2136 | //\r | |
2137 | // Now process the [sources.$(PROCESSOR)] files.\r | |
2138 | //\r | |
2139 | sprintf (Str, "sources.%s", Processor);\r | |
2140 | ProcessSourceFilesSection (DSCFile, ComponentFile, MakeFptr, Str, Mode);\r | |
2141 | //\r | |
2142 | // Now process the [sources.$(PROCESSOR).$(PLATFORM)] files.\r | |
2143 | //\r | |
2144 | Platform = GetSymbolValue (PLATFORM);\r | |
2145 | if (Platform != NULL) {\r | |
2146 | sprintf (Str, "sources.%s.%s", Processor, Platform);\r | |
2147 | ProcessSourceFilesSection (DSCFile, ComponentFile, MakeFptr, Str, Mode);\r | |
2148 | }\r | |
2149 | }\r | |
2150 | \r | |
2151 | fprintf (MakeFptr, "\n");\r | |
2152 | return STATUS_SUCCESS;\r | |
2153 | }\r | |
2154 | \r | |
2155 | /*++\r | |
2156 | \r | |
2157 | Routine Description:\r | |
2158 | Given a source file line from an INF file, parse it to see if there are\r | |
2159 | any defines on it. If so, then add them to the symbol table.\r | |
2160 | Also, terminate the line after the file name.\r | |
2161 | \r | |
2162 | Arguments:\r | |
2163 | SourceFileLine - a line from a [sources.?] section of the INF file. Likely\r | |
2164 | something like:\r | |
2165 | \r | |
2166 | MySourceFile.c BUILT_NAME=$(BUILD_DIR)\MySourceFile.obj\r | |
2167 | \r | |
2168 | Returns:\r | |
2169 | Nothing.\r | |
2170 | \r | |
2171 | --*/\r | |
2172 | static\r | |
2173 | void\r | |
2174 | AddFileSymbols (\r | |
2175 | INT8 *SourceFileLine\r | |
2176 | )\r | |
2177 | {\r | |
2178 | int Len;\r | |
2179 | //\r | |
2180 | // Skip spaces\r | |
2181 | //\r | |
2182 | for (; *SourceFileLine && isspace (*SourceFileLine); SourceFileLine++)\r | |
2183 | ;\r | |
2184 | for (; *SourceFileLine && !isspace (*SourceFileLine); SourceFileLine++)\r | |
2185 | ;\r | |
2186 | if (*SourceFileLine) {\r | |
2187 | *SourceFileLine = 0;\r | |
2188 | SourceFileLine++;\r | |
2189 | //\r | |
2190 | // AddSymbol() will parse it for us, and return the length. Keep calling\r | |
2191 | // it until it reports an error or is done.\r | |
2192 | //\r | |
2193 | do {\r | |
2194 | Len = AddSymbol (SourceFileLine, NULL, SYM_FILE);\r | |
2195 | SourceFileLine += Len;\r | |
2196 | } while (Len > 0);\r | |
2197 | }\r | |
2198 | }\r | |
2199 | //\r | |
2200 | // Process a single section of source files in the component INF file\r | |
2201 | //\r | |
2202 | static\r | |
2203 | int\r | |
2204 | ProcessSourceFilesSection (\r | |
2205 | DSC_FILE *DSCFile,\r | |
2206 | DSC_FILE *ComponentFile,\r | |
2207 | FILE *MakeFptr,\r | |
2208 | INT8 *SectionName,\r | |
2209 | UINT32 Mode\r | |
2210 | )\r | |
2211 | {\r | |
2212 | INT8 *Cptr;\r | |
2213 | INT8 FileName[MAX_EXP_LINE_LEN];\r | |
2214 | INT8 FilePath[MAX_PATH];\r | |
2215 | INT8 TempFileName[MAX_PATH];\r | |
2216 | SECTION *TempSect;\r | |
2217 | INT8 Str[MAX_LINE_LEN];\r | |
2218 | INT8 *Processor;\r | |
2219 | INT8 *OverridePath;\r | |
2220 | FILE *FPtr;\r | |
2221 | \r | |
2222 | TempSect = DSCFileFindSection (ComponentFile, SectionName);\r | |
2223 | if (TempSect != NULL) {\r | |
2224 | Processor = GetSymbolValue (PROCESSOR);\r | |
2225 | while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r | |
2226 | Cptr = StripLine (Str);\r | |
2227 | //\r | |
2228 | // Don't process blank lines\r | |
2229 | //\r | |
2230 | if (*Cptr) {\r | |
2231 | //\r | |
2232 | // Expand symbols in the filename, then parse the line for symbol\r | |
2233 | // definitions. AddFileSymbols() will null-terminate the line\r | |
2234 | // after the file name. Save a copy for override purposes, in which\r | |
2235 | // case we'll need to know the file name and path (in case it's in\r | |
2236 | // a subdirectory).\r | |
2237 | //\r | |
2238 | ExpandSymbols (Cptr, FileName, sizeof (FileName), 0);\r | |
2239 | AddFileSymbols (FileName);\r | |
95d675b5 | 2240 | ReplaceSlash (FileName);\r |
3eb9473e | 2241 | //\r |
2242 | // Set the SOURCE_FILE_NAME symbol. What we have now is the name of\r | |
2243 | // the file, relative to the location of the INF file. So prepend\r | |
2244 | // $(SOURCE_DIR) to it first.\r | |
2245 | //\r | |
2246 | if (IsAbsolutePath (FileName)) {\r | |
2247 | strcpy (TempFileName, FileName);\r | |
2248 | } else {\r | |
2249 | strcpy (TempFileName, "$(SOURCE_DIR)\\");\r | |
2250 | strcat (TempFileName, FileName);\r | |
2251 | }\r | |
2252 | AddSymbol (SOURCE_FILE_NAME, TempFileName, SYM_FILE | SYM_OVERWRITE);\r | |
2253 | //\r | |
2254 | // Extract path information from the source file and set internal\r | |
2255 | // variable SOURCE_RELATIVE_PATH. Only do this if the path\r | |
2256 | // contains a backslash.\r | |
2257 | //\r | |
2258 | strcpy (FilePath, FileName);\r | |
2259 | for (Cptr = FilePath + strlen (FilePath) - 1; (Cptr > FilePath) && (*Cptr != '\\'); Cptr--)\r | |
2260 | ;\r | |
2261 | if (*Cptr == '\\') {\r | |
2262 | *(Cptr + 1) = 0;\r | |
2263 | AddSymbol (SOURCE_RELATIVE_PATH, FilePath, SYM_FILE);\r | |
2264 | }\r | |
2265 | //\r | |
2266 | // Define another internal symbol for the name of the file without\r | |
2267 | // the path and extension.\r | |
2268 | //\r | |
2269 | for (Cptr = FileName + strlen (FileName) - 1; (Cptr > FileName) && (*Cptr != '\\'); Cptr--)\r | |
2270 | ;\r | |
2271 | if (*Cptr == '\\') {\r | |
2272 | Cptr++;\r | |
2273 | }\r | |
2274 | \r | |
2275 | strcpy (FilePath, Cptr);\r | |
2276 | //\r | |
2277 | // We now have a file name with no path information. Before we do anything else,\r | |
2278 | // see if OVERRIDE_PATH is set, and if so, see if file $(OVERRIDE_PATH)FileName\r | |
2279 | // exists. If it does, then recursive call this function to use the override file\r | |
2280 | // instead of the one from the INF file.\r | |
2281 | //\r | |
2282 | if (IsAbsolutePath (FileName)) {\r | |
2283 | OverridePath = NULL;\r | |
2284 | } else {\r | |
2285 | OverridePath = GetSymbolValue (SOURCE_OVERRIDE_PATH);\r | |
2286 | }\r | |
2287 | if (OverridePath != NULL) {\r | |
95d675b5 | 2288 | ReplaceSlash (OverridePath);\r |
3eb9473e | 2289 | //\r |
2290 | // See if the file exists. If it does, reset the SOURCE_FILE_NAME symbol.\r | |
2291 | //\r | |
2292 | strcpy (TempFileName, OverridePath);\r | |
2293 | strcat (TempFileName, "\\");\r | |
2294 | strcat (TempFileName, FileName);\r | |
2295 | if ((FPtr = fopen (TempFileName, "rb")) != NULL) {\r | |
2296 | fclose (FPtr);\r | |
2297 | AddSymbol (SOURCE_FILE_NAME, TempFileName, SYM_FILE | SYM_OVERWRITE);\r | |
2298 | //\r | |
2299 | // Print a message. This function is called to create build commands\r | |
2300 | // for source files, and to create a macro of all source files. Therefore\r | |
2301 | // do this check so we don't print the override message multiple times.\r | |
2302 | //\r | |
2303 | if (Mode & SOURCE_MODE_BUILD_COMMANDS) {\r | |
2304 | fprintf (stdout, "Override: %s\n", TempFileName);\r | |
2305 | }\r | |
2306 | } else {\r | |
2307 | //\r | |
2308 | // Set override path to null to use as a flag below\r | |
2309 | //\r | |
2310 | OverridePath = NULL;\r | |
2311 | }\r | |
2312 | }\r | |
2313 | \r | |
2314 | //\r | |
2315 | // Start at the end and work back\r | |
2316 | //\r | |
2317 | for (Cptr = FilePath + strlen (FilePath) - 1; (Cptr > FilePath) && (*Cptr != '\\') && (*Cptr != '.'); Cptr--)\r | |
2318 | ;\r | |
2319 | if (*Cptr == '.') {\r | |
2320 | *Cptr = 0;\r | |
2321 | AddSymbol (SOURCE_FILE_EXTENSION, Cptr + 1, SYM_FILE);\r | |
2322 | }\r | |
2323 | \r | |
2324 | AddSymbol (SOURCE_BASE_NAME, FilePath, SYM_FILE);\r | |
2325 | //\r | |
2326 | // If we're just creating the SOURCE_FILES macro, then write the\r | |
2327 | // file name out to the makefile.\r | |
2328 | //\r | |
2329 | if (Mode & SOURCE_MODE_SOURCE_FILES) {\r | |
2330 | //\r | |
2331 | // If we're processing an override file, then use the file name as-is\r | |
2332 | //\r | |
2333 | if (OverridePath != NULL) {\r | |
2334 | //\r | |
2335 | // SOURCE_FILES = $(SOURCE_FILES) c:\Path\ThisFile.c\r | |
2336 | //\r | |
2337 | fprintf (MakeFptr, "SOURCE_FILES = $(SOURCE_FILES) %s\n", TempFileName);\r | |
3e99020d LG |
2338 | //\r |
2339 | // Save the source absolute path\r | |
2340 | //\r | |
2341 | if (PathCanonicalize (FilePath, TempFileName)) {\r | |
2342 | AddSourceFile (mCurrentBuildItem, FilePath);\r | |
2343 | }\r | |
3eb9473e | 2344 | } else if (IsAbsolutePath (FileName)) {\r |
2345 | //\r | |
2346 | // For Absolute path, don't print $(SOURCE_FILE) directory.\r | |
2347 | //\r | |
2348 | fprintf (MakeFptr, "SOURCE_FILES = $(SOURCE_FILES) %s\n", FileName);\r | |
3e99020d LG |
2349 | //\r |
2350 | // Save the source absolute path\r | |
2351 | //\r | |
2352 | if (PathCanonicalize (FilePath, FileName)) {\r | |
2353 | AddSourceFile (mCurrentBuildItem, FilePath);\r | |
2354 | }\r | |
3eb9473e | 2355 | } else {\r |
2356 | //\r | |
2357 | // SOURCE_FILES = $(SOURCE_FILES) $(SOURCE_DIR)\ThisFile.c\r | |
2358 | //\r | |
2359 | fprintf (MakeFptr, "SOURCE_FILES = $(SOURCE_FILES) $(SOURCE_DIR)\\%s\n", FileName);\r | |
3e99020d LG |
2360 | //\r |
2361 | // Save the source absolute path\r | |
2362 | //\r | |
2363 | sprintf (Str, "%s\\%s", GetSymbolValue (SOURCE_DIR), FileName);\r | |
2364 | if (PathCanonicalize (FilePath, Str)) {\r | |
2365 | AddSourceFile (mCurrentBuildItem, FilePath);\r | |
2366 | }\r | |
3eb9473e | 2367 | }\r |
2368 | } else if (Mode & SOURCE_MODE_BUILD_COMMANDS) {\r | |
2369 | //\r | |
2370 | // Write the build commands for this file per the build commands\r | |
2371 | // for this file type as defined in the description file.\r | |
2372 | // Also create the directory for it in the build path.\r | |
2373 | //\r | |
2374 | WriteCompileCommands (DSCFile, MakeFptr, FileName, Processor);\r | |
2375 | if (!IsAbsolutePath (FileName)) {\r | |
2376 | sprintf (Str, "%s\\%s", GetSymbolValue (DEST_DIR), FileName);\r | |
2377 | MakeFilePath (Str);\r | |
2378 | //\r | |
2379 | // Get all output directory for build output files.\r | |
2380 | //\r | |
2381 | Cptr = FileName + strlen (FileName) - 1;\r | |
2382 | for (; (Cptr > FileName) && (*Cptr != '\\'); Cptr--);\r | |
2383 | if (*Cptr == '\\') {\r | |
2384 | *Cptr = '\0';\r | |
2385 | AddModuleName (&gGlobals.OutdirList, FileName, NULL);\r | |
2386 | }\r | |
2387 | }\r | |
2388 | }\r | |
2389 | //\r | |
2390 | // Remove file-level symbols\r | |
2391 | //\r | |
2392 | RemoveFileSymbols ();\r | |
2393 | }\r | |
2394 | }\r | |
2395 | }\r | |
2396 | \r | |
2397 | return STATUS_SUCCESS;\r | |
2398 | }\r | |
2399 | //\r | |
2400 | // Process the INF [sources.*] sections and emit the OBJECTS = .....\r | |
2401 | // lines to the component's makefile.\r | |
2402 | //\r | |
2403 | static\r | |
2404 | int\r | |
2405 | ProcessObjects (\r | |
2406 | DSC_FILE *ComponentFile,\r | |
2407 | FILE *MakeFptr\r | |
2408 | )\r | |
2409 | {\r | |
2410 | INT8 Str[MAX_LINE_LEN];\r | |
2411 | INT8 *Processor;\r | |
2412 | INT8 *Platform;\r | |
2413 | INT8 *SourceSelect;\r | |
2414 | INT8 *CStart;\r | |
2415 | INT8 *CEnd;\r | |
2416 | INT8 CSave;\r | |
2417 | INT8 *CopySourceSelect;\r | |
2418 | SYMBOL *TempSymbol;\r | |
2419 | \r | |
2420 | //\r | |
2421 | // Write a useful comment to the output makefile so the user knows where\r | |
2422 | // the data came from.\r | |
2423 | //\r | |
2424 | fprintf (MakeFptr, "#\n# Tool-generated list of object files that are created\n");\r | |
2425 | fprintf (MakeFptr, "# from the list of source files in the [sources.*] sections\n");\r | |
2426 | fprintf (MakeFptr, "# of the component INF file.\n#\n");\r | |
2427 | //\r | |
2428 | // We use this a lot here, so get the value only once.\r | |
2429 | //\r | |
2430 | Processor = GetSymbolValue (PROCESSOR);\r | |
2431 | //\r | |
2432 | // Now define the OBJECTS variable and assign it to be all the object files we're going\r | |
2433 | // to create. Afterwards create a pseudo-target objects to let the user quickly just compile\r | |
2434 | // the source files. This means we need to process all the common objects and\r | |
2435 | // processor-specific objects again.\r | |
2436 | //\r | |
2437 | fprintf (MakeFptr, "OBJECTS = $(OBJECTS) ");\r | |
2438 | //\r | |
2439 | // See if they defined SOURCE_SELECT=xxx,yyy in which case well\r | |
2440 | // select each [sources.xxx] and [sources.yyy] files and process\r | |
2441 | // them.\r | |
2442 | //\r | |
2443 | SourceSelect = GetSymbolValue (SOURCE_SELECT);\r | |
2444 | \r | |
2445 | if (SourceSelect != NULL) {\r | |
2446 | //\r | |
2447 | // Make a copy of the string and break it up (comma-separated) and\r | |
2448 | // select each [sources.*] file from the INF.\r | |
2449 | //\r | |
2450 | CopySourceSelect = (INT8 *) malloc (strlen (SourceSelect) + 1);\r | |
2451 | if (CopySourceSelect == NULL) {\r | |
2452 | Error (NULL, 0, 0, NULL, "failed to allocate memory");\r | |
2453 | return STATUS_ERROR;\r | |
2454 | }\r | |
2455 | \r | |
2456 | strcpy (CopySourceSelect, SourceSelect);\r | |
2457 | CStart = CopySourceSelect;\r | |
2458 | CEnd = CStart;\r | |
2459 | while (*CStart) {\r | |
2460 | CEnd = CStart + 1;\r | |
2461 | while (*CEnd && *CEnd != ',') {\r | |
2462 | CEnd++;\r | |
2463 | }\r | |
2464 | \r | |
2465 | CSave = *CEnd;\r | |
2466 | *CEnd = 0;\r | |
2467 | sprintf (Str, "%s.%s", SOURCES_SECTION_NAME, CStart);\r | |
2468 | ProcessObjectsSingle (ComponentFile, MakeFptr, Str);\r | |
2469 | //\r | |
2470 | // Restore the terminator and advance\r | |
2471 | //\r | |
2472 | *CEnd = CSave;\r | |
2473 | CStart = CEnd;\r | |
2474 | if (*CStart) {\r | |
2475 | CStart++;\r | |
2476 | }\r | |
2477 | }\r | |
2478 | \r | |
2479 | free (CopySourceSelect);\r | |
2480 | \r | |
2481 | } else {\r | |
2482 | //\r | |
2483 | // Now process all the [sources.common] files and emit build commands for them\r | |
2484 | //\r | |
2485 | sprintf (Str, "%s.%s", SOURCES_SECTION_NAME, COMMON_SECTION_NAME);\r | |
2486 | if (ProcessObjectsSingle (ComponentFile, MakeFptr, Str) != STATUS_SUCCESS) {\r | |
2487 | Warning (GetSymbolValue (INF_FILENAME), 1, 0, NULL, "no [%s] section found in component description", Str);\r | |
2488 | }\r | |
2489 | //\r | |
2490 | // Now process any processor-specific source files in [sources.$(PROCESSOR)]\r | |
2491 | //\r | |
2492 | sprintf (Str, "%s.%s", SOURCES_SECTION_NAME, Processor);\r | |
2493 | ProcessObjectsSingle (ComponentFile, MakeFptr, Str);\r | |
2494 | \r | |
2495 | //\r | |
2496 | // Now process any [sources.$(PROCESSOR).$(PLATFORM)] files\r | |
2497 | //\r | |
2498 | Platform = GetSymbolValue (PLATFORM);\r | |
2499 | if (Platform != NULL) {\r | |
2500 | sprintf (Str, "sources.%s.%s", Processor, Platform);\r | |
2501 | ProcessObjectsSingle (ComponentFile, MakeFptr, Str);\r | |
2502 | }\r | |
2503 | }\r | |
2504 | \r | |
2505 | fprintf (MakeFptr, "\n\n");\r | |
2506 | \r | |
2507 | //\r | |
2508 | // Write a useful comment to the output makefile so the user knows where\r | |
2509 | // the data came from.\r | |
2510 | //\r | |
2511 | fprintf (MakeFptr, "#\n# Tool-generated list of dest output dirs that are created\n");\r | |
2512 | fprintf (MakeFptr, "# from the list of source files in the [sources.*] sections\n");\r | |
2513 | fprintf (MakeFptr, "# of the component INF file.\n#\n");\r | |
2514 | //\r | |
2515 | // Create output directory list \r | |
2516 | // for clean target to delete all build output files.\r | |
2517 | //\r | |
2518 | fprintf (MakeFptr, "DEST_OUTPUT_DIRS = $(%s) ", DEST_DIR);\r | |
2519 | \r | |
2520 | TempSymbol = gGlobals.OutdirList;\r | |
2521 | while (TempSymbol != NULL) {\r | |
2522 | fprintf (MakeFptr, "\\\n $(%s)\\%s ", \r | |
2523 | DEST_DIR, TempSymbol->Name);\r | |
2524 | TempSymbol = TempSymbol->Next;\r | |
2525 | }\r | |
2526 | fprintf (MakeFptr, "\n\n");\r | |
2527 | \r | |
2528 | //\r | |
2529 | // clean up for the next module\r | |
2530 | //\r | |
2531 | FreeSymbols (gGlobals.OutdirList);\r | |
2532 | gGlobals.OutdirList = NULL;\r | |
2533 | \r | |
2534 | return STATUS_SUCCESS;\r | |
2535 | }\r | |
2536 | \r | |
2537 | static\r | |
2538 | INT8 *\r | |
2539 | BuiltFileExtension (\r | |
2540 | INT8 *SourceFileName\r | |
2541 | )\r | |
2542 | {\r | |
2543 | int i;\r | |
2544 | INT8 *Cptr;\r | |
2545 | //\r | |
2546 | // Find the dot in the filename extension\r | |
2547 | //\r | |
2548 | for (Cptr = SourceFileName + strlen (SourceFileName) - 1;\r | |
2549 | (Cptr > SourceFileName) && (*Cptr != '\\') && (*Cptr != '.');\r | |
2550 | Cptr--\r | |
2551 | ) {\r | |
2552 | //\r | |
2553 | // Do nothing\r | |
2554 | //\r | |
2555 | }\r | |
2556 | \r | |
2557 | if (*Cptr != '.') {\r | |
2558 | return NULL;\r | |
2559 | }\r | |
2560 | //\r | |
2561 | // Look through our list of known file types and return a pointer to\r | |
2562 | // its built file extension.\r | |
2563 | //\r | |
2564 | for (i = 0; mFileTypes[i].Extension != NULL; i++) {\r | |
2565 | if (_stricmp (Cptr, mFileTypes[i].Extension) == 0) {\r | |
2566 | return mFileTypes[i].BuiltExtension;\r | |
2567 | }\r | |
2568 | }\r | |
2569 | \r | |
2570 | return NULL;\r | |
2571 | }\r | |
2572 | \r | |
2573 | int\r | |
2574 | ProcessObjectsSingle (\r | |
2575 | DSC_FILE *ComponentFile,\r | |
2576 | FILE *MakeFptr,\r | |
2577 | INT8 *SectionName\r | |
2578 | )\r | |
2579 | {\r | |
2580 | INT8 *Cptr;\r | |
2581 | INT8 *Cptr2;\r | |
2582 | INT8 Str[MAX_LINE_LEN];\r | |
2583 | INT8 FileName[MAX_EXP_LINE_LEN];\r | |
2584 | SECTION *TempSect;\r | |
2585 | \r | |
2586 | TempSect = DSCFileFindSection (ComponentFile, SectionName);\r | |
2587 | if (TempSect != NULL) {\r | |
2588 | while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r | |
2589 | Cptr = StripLine (Str);\r | |
2590 | //\r | |
2591 | // Don't process blank lines\r | |
2592 | //\r | |
2593 | if (*Cptr) {\r | |
2594 | //\r | |
2595 | // Expand symbols then create the output filename. We'll do a lookup\r | |
2596 | // on the source file's extension to determine what the extension of\r | |
2597 | // the built version of the file is. For example, .c -> .obj.\r | |
2598 | //\r | |
2599 | if (!IsIncludeFile (Cptr)) {\r | |
2600 | ExpandSymbols (Cptr, FileName, sizeof (FileName), 0);\r | |
95d675b5 | 2601 | ReplaceSlash (FileName);\r |
3eb9473e | 2602 | Cptr2 = BuiltFileExtension (FileName);\r |
2603 | if (Cptr2 != NULL) {\r | |
2604 | SetFileExtension (FileName, Cptr2);\r | |
2605 | if (!IsAbsolutePath (FileName)) {\r | |
2606 | fprintf (MakeFptr, "\\\n $(%s)\\%s ", DEST_DIR, FileName);\r | |
2607 | } else {\r | |
2608 | fprintf (MakeFptr, "\\\n %s ", FileName);\r | |
2609 | }\r | |
2610 | }\r | |
2611 | }\r | |
2612 | }\r | |
2613 | }\r | |
2614 | } else {\r | |
2615 | return STATUS_WARNING;\r | |
2616 | }\r | |
2617 | \r | |
2618 | return STATUS_SUCCESS;\r | |
2619 | }\r | |
2620 | //\r | |
2621 | // Process all [libraries.*] sections in the component INF file to create a\r | |
2622 | // macro to the component's output makefile: LIBS = Lib1 Lib2, ...\r | |
2623 | //\r | |
2624 | static\r | |
2625 | int\r | |
2626 | ProcessLibs (\r | |
2627 | DSC_FILE *ComponentFile,\r | |
2628 | FILE *MakeFptr\r | |
2629 | )\r | |
2630 | {\r | |
2631 | INT8 Str[MAX_LINE_LEN];\r | |
2632 | INT8 *Processor;\r | |
2633 | INT8 *Platform;\r | |
2634 | \r | |
2635 | //\r | |
2636 | // Print a useful comment to the component's makefile so the user knows\r | |
2637 | // where the data came from.\r | |
2638 | //\r | |
2639 | fprintf (MakeFptr, "#\n# Tool-generated list of libraries that are generated\n");\r | |
2640 | fprintf (MakeFptr, "# from the list of libraries listed in the [libraries.*] sections\n");\r | |
2641 | fprintf (MakeFptr, "# of the component INF file.\n#\n");\r | |
2642 | \r | |
2643 | fprintf (MakeFptr, "LIBS = $(LIBS) ");\r | |
2644 | \r | |
2645 | Processor = GetSymbolValue (PROCESSOR);\r | |
2646 | //\r | |
2647 | // Process [libraries.common] files\r | |
2648 | //\r | |
2649 | sprintf (Str, "%s.%s", LIBRARIES_SECTION_NAME, COMMON_SECTION_NAME);\r | |
2650 | ProcessLibsSingle (ComponentFile, MakeFptr, Str);\r | |
2651 | //\r | |
2652 | // Process the [libraries.$(PROCESSOR)] libraries to define "LIBS = x.lib y.lib..."\r | |
2653 | //\r | |
2654 | sprintf (Str, "%s.%s", LIBRARIES_SECTION_NAME, Processor);\r | |
2655 | ProcessLibsSingle (ComponentFile, MakeFptr, Str);\r | |
2656 | //\r | |
2657 | // Now process any [libraries.$(PROCESSOR).$(PLATFORM)] files\r | |
2658 | //\r | |
2659 | Platform = GetSymbolValue (PLATFORM);\r | |
2660 | if (Platform != NULL) {\r | |
2661 | sprintf (Str, "%s.%s.%s", LIBRARIES_SECTION_NAME, Processor, Platform);\r | |
2662 | ProcessLibsSingle (ComponentFile, MakeFptr, Str);\r | |
2663 | }\r | |
2664 | //\r | |
2665 | // Process any [libraries.platform] files\r | |
2666 | //\r | |
2667 | ProcessLibsSingle (ComponentFile, MakeFptr, LIBRARIES_PLATFORM_SECTION_NAME);\r | |
2668 | \r | |
2669 | fprintf (MakeFptr, "\n\n");\r | |
2670 | return STATUS_SUCCESS;\r | |
2671 | }\r | |
2672 | \r | |
2673 | static\r | |
2674 | int\r | |
2675 | ProcessLibsSingle (\r | |
2676 | DSC_FILE *ComponentFile,\r | |
2677 | FILE *MakeFptr,\r | |
2678 | INT8 *SectionName\r | |
2679 | )\r | |
2680 | {\r | |
2681 | INT8 *Cptr;\r | |
2682 | INT8 Str[MAX_LINE_LEN];\r | |
2683 | INT8 ExpandedLine[MAX_LINE_LEN];\r | |
2684 | SECTION *TempSect;\r | |
2685 | \r | |
2686 | TempSect = DSCFileFindSection (ComponentFile, SectionName);\r | |
2687 | if (TempSect != NULL) {\r | |
2688 | while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r | |
2689 | ExpandSymbols (Str, ExpandedLine, sizeof (ExpandedLine), 0);\r | |
2690 | Cptr = StripLine (ExpandedLine);\r | |
2691 | //\r | |
2692 | // Don't process blank lines\r | |
2693 | //\r | |
2694 | if (*Cptr) {\r | |
2695 | if (Cptr[strlen (Cptr) - 4] != '.') {\r | |
2696 | fprintf (MakeFptr, " \\\n $(LIB_DIR)\\%s.lib", Cptr);\r | |
2697 | //\r | |
2698 | // Add lib dependency for single module build\r | |
2699 | //\r | |
2700 | fprintf (gGlobals.ModuleMakefileFptr, " %sbuild", Cptr);\r | |
2701 | } else {\r | |
2702 | fprintf (MakeFptr, " \\\n $(LIB_DIR)\\%s", Cptr);\r | |
2703 | //\r | |
2704 | // Add lib dependency for single module build\r | |
2705 | //\r | |
2706 | Cptr[strlen (Cptr) - 4] = 0;\r | |
2707 | fprintf (gGlobals.ModuleMakefileFptr, " %sbuild", Cptr);\r | |
2708 | }\r | |
3e99020d LG |
2709 | //\r |
2710 | // Add libs dependency for mCurrentBuildItem \r | |
2711 | //\r | |
2712 | AddDependency (*mCurrentBuildList, mCurrentBuildItem, Cptr, 0);\r | |
3eb9473e | 2713 | }\r |
2714 | }\r | |
2715 | }\r | |
2716 | \r | |
2717 | return STATUS_SUCCESS;\r | |
2718 | }\r | |
2719 | \r | |
2720 | static\r | |
2721 | int\r | |
2722 | ProcessIncludeFiles (\r | |
2723 | DSC_FILE *ComponentFile,\r | |
2724 | FILE *MakeFptr\r | |
2725 | )\r | |
2726 | {\r | |
2727 | INT8 Str[MAX_LINE_LEN];\r | |
2728 | INT8 *Processor;\r | |
2729 | INT8 *Platform;\r | |
2730 | INT8 *SourceSelect;\r | |
2731 | INT8 *CStart;\r | |
2732 | INT8 *CEnd;\r | |
2733 | INT8 CSave;\r | |
2734 | INT8 *CopySourceSelect;\r | |
2735 | \r | |
2736 | //\r | |
2737 | // Print a useful comment to the output makefile so the user knows where\r | |
2738 | // the info came from\r | |
2739 | //\r | |
2740 | //fprintf (MakeFptr, "#\n# Tool-generated include dependencies from any include files in the\n");\r | |
2741 | //fprintf (MakeFptr, "# [sources.*] sections of the component INF file\n#\n");\r | |
2742 | \r | |
2743 | Processor = GetSymbolValue (PROCESSOR);\r | |
2744 | \r | |
2745 | //\r | |
2746 | // See if they defined SOURCE_SELECT=xxx,yyy in which case we'll\r | |
2747 | // select each [sources.xxx] and [sources.yyy] files and process\r | |
2748 | // them.\r | |
2749 | //\r | |
2750 | SourceSelect = GetSymbolValue (SOURCE_SELECT);\r | |
2751 | \r | |
2752 | if (SourceSelect != NULL) {\r | |
2753 | //\r | |
2754 | // Make a copy of the string and break it up (comma-separated) and\r | |
2755 | // select each [sources.*] file from the INF.\r | |
2756 | //\r | |
2757 | CopySourceSelect = (INT8 *) malloc (strlen (SourceSelect) + 1);\r | |
2758 | if (CopySourceSelect == NULL) {\r | |
2759 | Error (NULL, 0, 0, NULL, "failed to allocate memory");\r | |
2760 | return STATUS_ERROR;\r | |
2761 | }\r | |
2762 | \r | |
2763 | strcpy (CopySourceSelect, SourceSelect);\r | |
2764 | CStart = CopySourceSelect;\r | |
2765 | CEnd = CStart;\r | |
2766 | while (*CStart) {\r | |
2767 | CEnd = CStart + 1;\r | |
2768 | while (*CEnd && *CEnd != ',') {\r | |
2769 | CEnd++;\r | |
2770 | }\r | |
2771 | \r | |
2772 | CSave = *CEnd;\r | |
2773 | *CEnd = 0;\r | |
2774 | sprintf (Str, "%s.%s", SOURCES_SECTION_NAME, CStart);\r | |
2775 | ProcessIncludeFilesSingle (ComponentFile, MakeFptr, Str);\r | |
2776 | //\r | |
2777 | // Restore the terminator and advance\r | |
2778 | //\r | |
2779 | *CEnd = CSave;\r | |
2780 | CStart = CEnd;\r | |
2781 | if (*CStart) {\r | |
2782 | CStart++;\r | |
2783 | }\r | |
2784 | }\r | |
2785 | \r | |
2786 | free (CopySourceSelect);\r | |
2787 | \r | |
2788 | } else {\r | |
2789 | //\r | |
2790 | // Find all the include files in the [sources.common] sections.\r | |
2791 | //\r | |
2792 | sprintf (Str, "%s.%s", SOURCES_SECTION_NAME, COMMON_SECTION_NAME);\r | |
2793 | ProcessIncludeFilesSingle (ComponentFile, MakeFptr, Str);\r | |
2794 | //\r | |
2795 | // Now process the [sources.$(PROCESSOR)] files.\r | |
2796 | //\r | |
2797 | sprintf (Str, "%s.%s", SOURCES_SECTION_NAME, Processor);\r | |
2798 | ProcessIncludeFilesSingle (ComponentFile, MakeFptr, Str);\r | |
2799 | //\r | |
2800 | // Now process the [sources.$(PROCESSOR).$(PLATFORM)] files.\r | |
2801 | //\r | |
2802 | Platform = GetSymbolValue (PLATFORM);\r | |
2803 | if (Platform != NULL) {\r | |
2804 | sprintf (Str, "sources.%s.%s", Processor, Platform);\r | |
2805 | ProcessIncludeFilesSingle (ComponentFile, MakeFptr, Str);\r | |
2806 | }\r | |
2807 | }\r | |
2808 | \r | |
2809 | fprintf (MakeFptr, "\n");\r | |
2810 | return STATUS_SUCCESS;\r | |
2811 | }\r | |
2812 | \r | |
2813 | int\r | |
2814 | ProcessIncludeFilesSingle (\r | |
2815 | DSC_FILE *ComponentFile,\r | |
2816 | FILE *MakeFptr,\r | |
2817 | INT8 *SectionName\r | |
2818 | )\r | |
2819 | {\r | |
2820 | INT8 *Cptr;\r | |
2821 | INT8 FileName[MAX_EXP_LINE_LEN];\r | |
2822 | INT8 TempFileName[MAX_PATH];\r | |
2823 | SECTION *TempSect;\r | |
2824 | INT8 Str[MAX_LINE_LEN];\r | |
2825 | INT8 *OverridePath;\r | |
2826 | FILE *FPtr;\r | |
2827 | \r | |
2828 | TempSect = DSCFileFindSection (ComponentFile, SectionName);\r | |
2829 | if (TempSect != NULL) {\r | |
2830 | //\r | |
2831 | // See if the SOURCE_OVERRIDE_PATH has been set. If it has, and\r | |
2832 | // they have an include file that is overridden, then add the path\r | |
2833 | // to it to the list of include paths (prepend).\r | |
2834 | //\r | |
2835 | OverridePath = GetSymbolValue (SOURCE_OVERRIDE_PATH);\r | |
2836 | while (DSCFileGetLine (ComponentFile, Str, sizeof (Str)) != NULL) {\r | |
2837 | Cptr = StripLine (Str);\r | |
2838 | //\r | |
2839 | // Don't process blank lines\r | |
2840 | //\r | |
2841 | if (*Cptr) {\r | |
2842 | //\r | |
2843 | // Expand symbols in the filename, then get its parts\r | |
2844 | //\r | |
2845 | ExpandSymbols (Cptr, FileName, sizeof (FileName), 0);\r | |
2846 | AddFileSymbols (FileName);\r | |
95d675b5 | 2847 | ReplaceSlash (FileName);\r |
3eb9473e | 2848 | if (IsIncludeFile (FileName)) {\r |
2849 | if ((OverridePath != NULL) && (!IsAbsolutePath (FileName))) {\r | |
95d675b5 | 2850 | ReplaceSlash (OverridePath);\r |
3eb9473e | 2851 | strcpy (TempFileName, OverridePath);\r |
2852 | strcat (TempFileName, "\\");\r | |
2853 | strcat (TempFileName, FileName);\r | |
2854 | if ((FPtr = fopen (TempFileName, "rb")) != NULL) {\r | |
2855 | fclose (FPtr);\r | |
2856 | //\r | |
2857 | // Null-terminate the file name at the last backslash and add that\r | |
2858 | // to the beginning of the list of include paths.\r | |
2859 | //\r | |
2860 | for (Cptr = TempFileName + strlen (TempFileName) - 1;\r | |
95d675b5 | 2861 | (Cptr >= TempFileName) && (*Cptr != '\\');\r |
3eb9473e | 2862 | Cptr--\r |
2863 | )\r | |
2864 | ;\r | |
2865 | if (Cptr >= TempFileName) {\r | |
2866 | *Cptr = 0;\r | |
2867 | }\r | |
3e99020d | 2868 | fprintf (MakeFptr, "!IF EXIST(%s)\n", TempFileName);\r |
3eb9473e | 2869 | fprintf (MakeFptr, "INC = -I %s $(INC)\n", TempFileName);\r |
3e99020d | 2870 | fprintf (MakeFptr, "!ENDIF\n");\r |
3eb9473e | 2871 | }\r |
2872 | }\r | |
2873 | //\r | |
2874 | // If absolute path already, don't prepend source directory\r | |
2875 | //\r | |
2876 | // if (IsAbsolutePath (FileName)) {\r | |
2877 | // fprintf (MakeFptr, "INC_DEPS = $(INC_DEPS) %s\n", FileName);\r | |
2878 | // } else {\r | |
2879 | // fprintf (MakeFptr, "INC_DEPS = $(INC_DEPS) $(SOURCE_DIR)\\%s\n", FileName);\r | |
2880 | // }\r | |
2881 | }\r | |
2882 | \r | |
2883 | RemoveFileSymbols ();\r | |
2884 | }\r | |
2885 | }\r | |
2886 | }\r | |
2887 | \r | |
2888 | return STATUS_SUCCESS;\r | |
2889 | }\r | |
2890 | \r | |
2891 | static\r | |
2892 | void\r | |
2893 | FreeFileParts (\r | |
2894 | FILE_NAME_PARTS *FP\r | |
2895 | )\r | |
2896 | {\r | |
2897 | if (FP != NULL) {\r | |
2898 | if (FP->Path != NULL) {\r | |
2899 | free (FP->Path);\r | |
2900 | }\r | |
2901 | \r | |
2902 | if (FP->BaseName != NULL) {\r | |
2903 | free (FP->BaseName);\r | |
2904 | }\r | |
2905 | \r | |
2906 | if (FP->Extension != NULL) {\r | |
2907 | free (FP->Extension);\r | |
2908 | }\r | |
2909 | }\r | |
2910 | }\r | |
2911 | \r | |
2912 | static\r | |
2913 | FILE_NAME_PARTS *\r | |
2914 | GetFileParts (\r | |
2915 | INT8 *FileName\r | |
2916 | )\r | |
2917 | {\r | |
2918 | FILE_NAME_PARTS *FP;\r | |
2919 | INT8 *Cptr;\r | |
2920 | INT8 CopyFileName[MAX_PATH];\r | |
2921 | INT8 *FileNamePtr;\r | |
2922 | \r | |
2923 | strcpy (CopyFileName, FileName);\r | |
2924 | FP = (FILE_NAME_PARTS *) malloc (sizeof (FILE_NAME_PARTS));\r | |
2925 | if (FP == NULL) {\r | |
2926 | Error (NULL, 0, 0, NULL, "failed to allocate memory");\r | |
2927 | return NULL;\r | |
2928 | }\r | |
2929 | \r | |
2930 | memset ((INT8 *) FP, 0, sizeof (FILE_NAME_PARTS));\r | |
2931 | //\r | |
2932 | // Get extension code\r | |
2933 | //\r | |
2934 | FP->ExtensionCode = GetSourceFileType (CopyFileName);\r | |
2935 | //\r | |
2936 | // Get drive if there\r | |
2937 | //\r | |
2938 | FileNamePtr = CopyFileName;\r | |
2939 | if (FileNamePtr[1] == ':') {\r | |
2940 | FP->Drive[0] = FileNamePtr[0];\r | |
2941 | FP->Drive[1] = ':';\r | |
2942 | FileNamePtr += 2;\r | |
2943 | }\r | |
2944 | //\r | |
2945 | // Start at the end and work back\r | |
2946 | //\r | |
2947 | for (Cptr = FileNamePtr + strlen (FileNamePtr) - 1; (Cptr > FileNamePtr) && (*Cptr != '.'); Cptr--)\r | |
2948 | ;\r | |
2949 | \r | |
2950 | if (*Cptr == '.') {\r | |
2951 | //\r | |
2952 | // Don't copy the dot\r | |
2953 | //\r | |
2954 | FP->Extension = (char *) malloc (strlen (Cptr));\r | |
2955 | strcpy (FP->Extension, Cptr + 1);\r | |
2956 | *Cptr = 0;\r | |
2957 | Cptr--;\r | |
2958 | StripTrailingSpaces (FP->Extension);\r | |
2959 | } else {\r | |
2960 | //\r | |
2961 | // Create empty string for extension\r | |
2962 | //\r | |
2963 | FP->Extension = (char *) malloc (1);\r | |
2964 | FP->Extension[0] = 0;\r | |
2965 | }\r | |
2966 | //\r | |
95d675b5 | 2967 | // Now back up and get the base name (include the preceding '\')\r |
3eb9473e | 2968 | //\r |
95d675b5 | 2969 | for (; (Cptr > FileNamePtr) && (*Cptr != '\\'); Cptr--)\r |
3eb9473e | 2970 | ;\r |
2971 | FP->BaseName = (char *) malloc (strlen (Cptr) + 1);\r | |
2972 | strcpy (FP->BaseName, Cptr);\r | |
2973 | *Cptr = 0;\r | |
2974 | Cptr--;\r | |
2975 | //\r | |
2976 | // Rest is path\r | |
2977 | //\r | |
2978 | if (Cptr >= FileNamePtr) {\r | |
2979 | Cptr = FileNamePtr;\r | |
2980 | FP->Path = (char *) malloc (strlen (Cptr) + 1);\r | |
2981 | strcpy (FP->Path, Cptr);\r | |
2982 | } else {\r | |
2983 | FP->Path = (char *) malloc (1);\r | |
2984 | FP->Path[0] = 0;\r | |
2985 | }\r | |
2986 | \r | |
2987 | return FP;\r | |
2988 | }\r | |
2989 | \r | |
2990 | /*****************************************************************************\r | |
2991 | ******************************************************************************/\r | |
2992 | static\r | |
2993 | int\r | |
2994 | WriteCommonMakefile (\r | |
2995 | DSC_FILE *DSCFile,\r | |
2996 | FILE *MakeFptr,\r | |
2997 | INT8 *Processor\r | |
2998 | )\r | |
2999 | {\r | |
3000 | INT8 InLine[MAX_LINE_LEN];\r | |
3001 | INT8 OutLine[MAX_EXP_LINE_LEN];\r | |
3002 | SECTION *Sect;\r | |
3003 | INT8 *Sym;\r | |
3004 | int i;\r | |
3005 | //\r | |
3006 | // Don't mess up the original file pointer, since we're processing it at a higher\r | |
3007 | // level.\r | |
3008 | //\r | |
3009 | DSCFileSavePosition (DSCFile);\r | |
3010 | //\r | |
3011 | // Write the header to the file\r | |
3012 | //\r | |
3013 | for (i = 0; MakefileHeader[i] != NULL; i++) {\r | |
3014 | fprintf (MakeFptr, "%s\n", MakefileHeader[i]);\r | |
3015 | }\r | |
3016 | \r | |
3017 | fprintf (MakeFptr, "#\n# Hard-coded defines output by the tool\n#\n");\r | |
3018 | //\r | |
3019 | // First write the basics to the component's makefile. These includes\r | |
3020 | // EFI_SOURCE, BIN_DIR, OUT_DIR, LIB_DIR, SOURCE_DIR, DEST_DIR.\r | |
3021 | //\r | |
3022 | Sym = GetSymbolValue (EFI_SOURCE);\r | |
3023 | fprintf (MakeFptr, "%s = %s\n", EFI_SOURCE, Sym);\r | |
3024 | Sym = GetSymbolValue (BUILD_DIR);\r | |
3025 | fprintf (MakeFptr, "%s = %s\n", BUILD_DIR, Sym);\r | |
3026 | Sym = GetSymbolValue (BIN_DIR);\r | |
3027 | fprintf (MakeFptr, "%s = %s\n", BIN_DIR, Sym);\r | |
3028 | Sym = GetSymbolValue (OUT_DIR);\r | |
3029 | fprintf (MakeFptr, "%s = %s\n", OUT_DIR, Sym);\r | |
3030 | Sym = GetSymbolValue (LIB_DIR);\r | |
3031 | fprintf (MakeFptr, "%s = %s\n", LIB_DIR, Sym);\r | |
3032 | Sym = GetSymbolValue (SOURCE_DIR);\r | |
3033 | fprintf (MakeFptr, "%s = %s\n", SOURCE_DIR, Sym);\r | |
3034 | Sym = GetSymbolValue (DEST_DIR);\r | |
3035 | fprintf (MakeFptr, "%s = %s\n", DEST_DIR, Sym);\r | |
3036 | fprintf (MakeFptr, "\n");\r | |
3037 | //\r | |
3038 | // If there was a [makefile.common] section in the description file,\r | |
3039 | // copy it (after symbol expansion) to the output file.\r | |
3040 | //\r | |
3041 | sprintf (InLine, "%s.%s", MAKEFILE_SECTION_NAME, COMMON_SECTION_NAME);\r | |
3042 | Sect = DSCFileFindSection (DSCFile, InLine);\r | |
3043 | if (Sect != NULL) {\r | |
3044 | //\r | |
3045 | // fprintf (MakeFptr, "# From the [makefile.common] section of the DSC file\n");\r | |
3046 | // Read lines, expand, then dump out\r | |
3047 | //\r | |
3048 | while (DSCFileGetLine (DSCFile, InLine, sizeof (InLine)) != NULL) {\r | |
3049 | //\r | |
3050 | // Replace symbols\r | |
3051 | //\r | |
3052 | ExpandSymbols (InLine, OutLine, sizeof (OutLine), EXPANDMODE_RECURSIVE);\r | |
3053 | fprintf (MakeFptr, OutLine);\r | |
3054 | }\r | |
3055 | }\r | |
3056 | //\r | |
3057 | // If there was a [makefile.platform] section in the description file,\r | |
3058 | // copy it (after symbol expansion) to the output file.\r | |
3059 | //\r | |
3060 | sprintf (InLine, "%s.%s", MAKEFILE_SECTION_NAME, "Platform");\r | |
3061 | Sect = DSCFileFindSection (DSCFile, InLine);\r | |
3062 | if (Sect != NULL) {\r | |
3063 | //\r | |
3064 | // Read lines, expand, then dump out\r | |
3065 | //\r | |
3066 | while (DSCFileGetLine (DSCFile, InLine, sizeof (InLine)) != NULL) {\r | |
3067 | //\r | |
3068 | // Replace symbols\r | |
3069 | //\r | |
3070 | ExpandSymbols (InLine, OutLine, sizeof (OutLine), EXPANDMODE_RECURSIVE);\r | |
3071 | fprintf (MakeFptr, OutLine);\r | |
3072 | }\r | |
3073 | }\r | |
3074 | //\r | |
3075 | // Do the same for any [makefile.$(PROCESSOR)]\r | |
3076 | //\r | |
3077 | sprintf (InLine, "%s.%s", MAKEFILE_SECTION_NAME, Processor);\r | |
3078 | Sect = DSCFileFindSection (DSCFile, InLine);\r | |
3079 | if (Sect != NULL) {\r | |
3080 | //\r | |
3081 | // Read lines, expand, then dump out\r | |
3082 | //\r | |
3083 | while (DSCFileGetLine (DSCFile, InLine, sizeof (InLine)) != NULL) {\r | |
3084 | ExpandSymbols (InLine, OutLine, sizeof (OutLine), EXPANDMODE_RECURSIVE);\r | |
3085 | fprintf (MakeFptr, OutLine);\r | |
3086 | }\r | |
3087 | }\r | |
3088 | //\r | |
3089 | // Same thing for [makefile.$(PROCESSOR).$(PLATFORM)]\r | |
3090 | //\r | |
3091 | Sym = GetSymbolValue (PLATFORM);\r | |
3092 | if (Sym != NULL) {\r | |
3093 | sprintf (InLine, "%s.%s.%s", MAKEFILE_SECTION_NAME, Processor, Sym);\r | |
3094 | Sect = DSCFileFindSection (DSCFile, InLine);\r | |
3095 | if (Sect != NULL) {\r | |
3096 | //\r | |
3097 | // Read lines, expand, then dump out\r | |
3098 | //\r | |
3099 | while (DSCFileGetLine (DSCFile, InLine, sizeof (InLine)) != NULL) {\r | |
3100 | ExpandSymbols (InLine, OutLine, sizeof (OutLine), EXPANDMODE_RECURSIVE);\r | |
3101 | fprintf (MakeFptr, OutLine);\r | |
3102 | }\r | |
3103 | }\r | |
3104 | }\r | |
3105 | \r | |
3106 | fprintf (MakeFptr, "\n");\r | |
3107 | DSCFileRestorePosition (DSCFile);\r | |
3108 | return 0;\r | |
3109 | }\r | |
3110 | \r | |
3111 | static\r | |
3112 | int\r | |
3113 | WriteComponentTypeBuildCommands (\r | |
3114 | DSC_FILE *DSCFile,\r | |
3115 | FILE *MakeFptr,\r | |
3116 | INT8 *SectionName\r | |
3117 | )\r | |
3118 | /*++\r | |
3119 | \r | |
3120 | Routine Description:\r | |
3121 | \r | |
3122 | Given a section name such as [build.ia32.library], find the section in\r | |
3123 | the description file and copy the build commands.\r | |
3124 | \r | |
3125 | Arguments:\r | |
3126 | \r | |
3127 | DSCFile - section information on the main description file\r | |
3128 | MakeFptr - file pointer to the makefile we're writing to\r | |
3129 | SectionName - name of the section we're to copy out to the makefile.\r | |
3130 | \r | |
3131 | Returns:\r | |
3132 | \r | |
3133 | Always successful, since the section may be optional.\r | |
3134 | \r | |
3135 | --*/\r | |
3136 | {\r | |
3137 | SECTION *Sect;\r | |
3138 | INT8 InLine[MAX_LINE_LEN];\r | |
3139 | INT8 OutLine[MAX_EXP_LINE_LEN];\r | |
3140 | \r | |
3141 | //\r | |
3142 | // Don't mess up the original file pointer, since we're processing it at a higher\r | |
3143 | // level.\r | |
3144 | //\r | |
3145 | DSCFileSavePosition (DSCFile);\r | |
3146 | Sect = DSCFileFindSection (DSCFile, SectionName);\r | |
3147 | if (Sect != NULL) {\r | |
3148 | //\r | |
3149 | // Read lines, expand, then dump out\r | |
3150 | //\r | |
3151 | while (DSCFileGetLine (DSCFile, InLine, sizeof (InLine)) != NULL) {\r | |
3152 | ExpandSymbols (\r | |
3153 | InLine, \r | |
3154 | OutLine, \r | |
3155 | sizeof(OutLine), \r | |
3156 | EXPANDMODE_NO_DESTDIR | EXPANDMODE_NO_SOURCEDIR\r | |
3157 | );\r | |
3158 | fprintf (MakeFptr, OutLine);\r | |
3159 | }\r | |
3160 | } else {\r | |
3161 | Warning (\r | |
3162 | NULL,\r | |
3163 | 0,\r | |
3164 | 0,\r | |
3165 | GetSymbolValue (INF_FILENAME),\r | |
3166 | "no [%s] build commands found in DSC file for component",\r | |
3167 | SectionName\r | |
3168 | );\r | |
3169 | }\r | |
3170 | \r | |
3171 | DSCFileRestorePosition (DSCFile);\r | |
3172 | return STATUS_SUCCESS;\r | |
3173 | }\r | |
3174 | \r | |
3175 | /*****************************************************************************\r | |
3176 | \r | |
3177 | ******************************************************************************/\r | |
3178 | static\r | |
3179 | int\r | |
3180 | WriteCompileCommands (\r | |
3181 | DSC_FILE *DscFile,\r | |
3182 | FILE *MakeFptr,\r | |
3183 | INT8 *FileName,\r | |
3184 | INT8 *Processor\r | |
3185 | )\r | |
3186 | {\r | |
3187 | FILE_NAME_PARTS *File;\r | |
3188 | SECTION *Sect;\r | |
3189 | INT8 BuildSectionName[40];\r | |
3190 | INT8 InLine[MAX_LINE_LEN];\r | |
3191 | INT8 OutLine[MAX_EXP_LINE_LEN];\r | |
3192 | INT8 *SourceCompileType;\r | |
3193 | char *CPtr;\r | |
3194 | char *CPtr2;\r | |
3195 | //\r | |
3196 | // Determine the filename, then chop it up into its parts\r | |
3197 | //\r | |
3198 | File = GetFileParts (FileName);\r | |
3199 | if (File != NULL) {\r | |
3200 | //\r | |
3201 | // Don't mess up the original file pointer, since we're processing it at a higher\r | |
3202 | // level.\r | |
3203 | //\r | |
3204 | DSCFileSavePosition (DscFile);\r | |
3205 | //\r | |
3206 | // Option 1: SOURCE_COMPILE_TYPE=MyCompileSection\r | |
3207 | // Find a section of that name from which to get the compile\r | |
3208 | // commands for this source file. \r | |
3209 | // Look for [compile.$(PROCESSOR).$(SOURCE_COMPILE_TYPE]\r | |
3210 | // Option 2: COMPILE_SELECT=.c=MyCCompile,.asm=MyAsm\r | |
3211 | // Find a [compile.$(PROCESSOR).MyCompile] section from which to\r | |
3212 | // get the compile commands for this source file. \r | |
3213 | // Look for [compile.$(PROCESSOR).MyCompile]\r | |
3214 | // Option 3: Look for standard section types to compile the file by extension.\r | |
3215 | // Look for [compile.$(PROCESSOR).<extension>]\r | |
3216 | //\r | |
3217 | Sect = NULL;\r | |
3218 | //\r | |
3219 | // Option 1 - use SOURCE_COMPILE_TYPE variable\r | |
3220 | //\r | |
3221 | SourceCompileType = GetSymbolValue (SOURCE_COMPILE_TYPE);\r | |
3222 | if (SourceCompileType != NULL) {\r | |
3223 | sprintf (BuildSectionName, "compile.%s.%s", Processor, SourceCompileType);\r | |
3224 | Sect = DSCFileFindSection (DscFile, BuildSectionName);\r | |
3225 | }\r | |
3226 | //\r | |
3227 | // Option 2 - use COMPILE_SELECT variable\r | |
3228 | //\r | |
3229 | if (Sect == NULL) {\r | |
3230 | SourceCompileType = GetSymbolValue (COMPILE_SELECT);\r | |
3231 | if (SourceCompileType != NULL) {\r | |
3232 | //\r | |
3233 | // Parse the variable, which looks like COMPILE_SELECT=.c=MyCCompiler;.asm=MyAsm;\r | |
3234 | // to find an entry with a matching file name extension. If you find one,\r | |
3235 | // then use that name to find the section name.\r | |
3236 | //\r | |
3237 | CPtr = SourceCompileType;\r | |
3238 | while (*CPtr && (Sect == NULL)) {\r | |
3239 | //\r | |
3240 | // See if we found a match with this source file name extension. File->Extension\r | |
3241 | // does not include the dot, so skip the dot in the COMPILE_SELECT variable if there\r | |
3242 | // is one.\r | |
3243 | //\r | |
3244 | if (*CPtr == '.') {\r | |
3245 | CPtr++;\r | |
3246 | }\r | |
3247 | \r | |
3248 | if (_strnicmp (CPtr, File->Extension, strlen (File->Extension)) == 0) {\r | |
3249 | //\r | |
3250 | // Found a file name extension match -- extract the name from the variable, for\r | |
3251 | // example "MyCCompiler"\r | |
3252 | //\r | |
3253 | while (*CPtr && (*CPtr != '=')) {\r | |
3254 | CPtr++;\r | |
3255 | }\r | |
3256 | \r | |
3257 | if ((*CPtr != '=') || (CPtr[1] == 0)) {\r | |
3258 | Error (NULL, 0, 0, SourceCompileType, "malformed COMPILE_SELECT variable");\r | |
3259 | break;\r | |
3260 | }\r | |
3261 | \r | |
3262 | CPtr++;\r | |
3263 | sprintf (BuildSectionName, "compile.%s.", Processor);\r | |
3264 | for (CPtr2 = BuildSectionName + strlen (BuildSectionName);\r | |
3265 | *CPtr && (*CPtr != ',') && (*CPtr != ';');\r | |
3266 | CPtr++\r | |
3267 | ) {\r | |
3268 | *CPtr2 = *CPtr;\r | |
3269 | CPtr2++;\r | |
3270 | }\r | |
3271 | \r | |
3272 | *CPtr2 = 0;\r | |
3273 | Sect = DSCFileFindSection (DscFile, BuildSectionName);\r | |
3274 | if (Sect == NULL) {\r | |
3275 | ParserError (\r | |
3276 | 0,\r | |
3277 | BuildSectionName,\r | |
3278 | "could not find section in DSC file - selected by COMPILE_SELECT variable"\r | |
3279 | );\r | |
3280 | }\r | |
3281 | }\r | |
3282 | \r | |
3283 | //\r | |
3284 | // Skip to next file name extension in the COMPILE_SELECT variable\r | |
3285 | //\r | |
3286 | while (*CPtr && (*CPtr != ';') && (*CPtr != ',')) {\r | |
3287 | CPtr++;\r | |
3288 | }\r | |
3289 | \r | |
3290 | if (*CPtr) {\r | |
3291 | CPtr++;\r | |
3292 | }\r | |
3293 | }\r | |
3294 | }\r | |
3295 | }\r | |
3296 | //\r | |
3297 | // Option 3 - use "Compile.$(PROCESSOR).<Extension>" section\r | |
3298 | //\r | |
3299 | if (Sect == NULL) {\r | |
3300 | sprintf (BuildSectionName, "compile.%s.%s", Processor, File->Extension);\r | |
3301 | Sect = DSCFileFindSection (DscFile, BuildSectionName);\r | |
3302 | }\r | |
3303 | //\r | |
3304 | // Should have found something by now unless it's an include (.h) file\r | |
3305 | //\r | |
3306 | if (Sect != NULL) {\r | |
3307 | //\r | |
3308 | // Temporarily add a FILE variable to the global symbol table. Omit the\r | |
3309 | // extension.\r | |
3310 | //\r | |
3311 | sprintf (InLine, "%s%s%s", File->Drive, File->Path, File->BaseName);\r | |
3312 | AddSymbol ("FILE", InLine, SYM_OVERWRITE | SYM_LOCAL | SYM_FILENAME);\r | |
3313 | //\r | |
3314 | // Read lines, expand (except SOURCE_DIR and DEST_DIR), then dump out\r | |
3315 | //\r | |
3316 | while (DSCFileGetLine (DscFile, InLine, sizeof (InLine)) != NULL) {\r | |
3317 | ExpandSymbols (\r | |
3318 | InLine,\r | |
3319 | OutLine,\r | |
3320 | sizeof (OutLine),\r | |
3321 | EXPANDMODE_NO_DESTDIR | EXPANDMODE_NO_SOURCEDIR\r | |
3322 | );\r | |
3323 | fprintf (MakeFptr, OutLine);\r | |
3324 | }\r | |
3325 | fprintf (MakeFptr, "\n");\r | |
3326 | } else {\r | |
3327 | //\r | |
3328 | // Be nice and ignore include files\r | |
3329 | //\r | |
3330 | if (!IsIncludeFile (FileName)) {\r | |
3331 | Error (\r | |
3332 | NULL,\r | |
3333 | 0,\r | |
3334 | 0,\r | |
3335 | NULL,\r | |
3336 | "no compile commands section [%s] found in DSC file for %s",\r | |
3337 | BuildSectionName,\r | |
3338 | FileName\r | |
3339 | );\r | |
3340 | }\r | |
3341 | }\r | |
3342 | \r | |
3343 | DSCFileRestorePosition (DscFile);\r | |
3344 | FreeFileParts (File);\r | |
3345 | }\r | |
3346 | \r | |
3347 | return STATUS_SUCCESS;\r | |
3348 | }\r | |
3349 | \r | |
3350 | /*****************************************************************************\r | |
3351 | ******************************************************************************/\r | |
3352 | static\r | |
3353 | int\r | |
3354 | SetFileExtension (\r | |
3355 | INT8 *FileName,\r | |
3356 | INT8 *Extension\r | |
3357 | )\r | |
3358 | {\r | |
3359 | INT8 *Cptr;\r | |
3360 | \r | |
3361 | Cptr = FileName + strlen (FileName) - 1;\r | |
3362 | while ((Cptr > FileName) && (*Cptr != '.')) {\r | |
3363 | Cptr--;\r | |
3364 | \r | |
3365 | }\r | |
3366 | //\r | |
3367 | // Better be a dot\r | |
3368 | //\r | |
3369 | if (*Cptr != '.') {\r | |
3370 | Message (2, "Missing filename extension: %s", FileName);\r | |
3371 | return STATUS_WARNING;\r | |
3372 | }\r | |
3373 | \r | |
3374 | Cptr++;\r | |
3375 | if (*Extension == '.') {\r | |
3376 | Extension++;\r | |
3377 | }\r | |
3378 | \r | |
3379 | strcpy (Cptr, Extension);\r | |
3380 | return STATUS_SUCCESS;\r | |
3381 | }\r | |
3382 | \r | |
3383 | /*****************************************************************************\r | |
3384 | ******************************************************************************/\r | |
3385 | int\r | |
3386 | MakeFilePath (\r | |
3387 | INT8 *FileName\r | |
3388 | )\r | |
3389 | {\r | |
3390 | INT8 *Cptr;\r | |
3391 | INT8 SavedChar;\r | |
3392 | INT8 BuildDir[MAX_PATH];\r | |
3393 | INT8 CopyFileName[MAX_PATH];\r | |
3394 | \r | |
3395 | //\r | |
3396 | // Expand symbols in the filename\r | |
3397 | //\r | |
3398 | if (ExpandSymbols (FileName, CopyFileName, sizeof (CopyFileName), EXPANDMODE_NO_UNDEFS)) {\r | |
3399 | Error (NULL, 0, 0, NULL, "undefined symbols in file path: %s", FileName);\r | |
3400 | return STATUS_ERROR;\r | |
3401 | }\r | |
3402 | //\r | |
3403 | // Copy it back\r | |
3404 | //\r | |
3405 | strcpy (FileName, CopyFileName);\r | |
3406 | //\r | |
3407 | // To avoid creating $(BUILD_DIR) path, see if this path is the same as\r | |
3408 | // $(BUILD_DIR), and if it is, see if build dir exists and skip over that\r | |
3409 | // portion if it does\r | |
3410 | //\r | |
3411 | Cptr = GetSymbolValue (BUILD_DIR);\r | |
3412 | if (Cptr != NULL) {\r | |
3413 | if (_strnicmp (Cptr, FileName, strlen (Cptr)) == 0) {\r | |
3414 | //\r | |
3415 | // BUILD_DIR path. See if it exists\r | |
3416 | //\r | |
3417 | strcpy (BuildDir, FileName);\r | |
3418 | BuildDir[strlen (Cptr)] = 0;\r | |
3419 | if ((_mkdir (BuildDir) != 0) && (errno != EEXIST)) {\r | |
3420 | Cptr = FileName;\r | |
3421 | } else {\r | |
3422 | //\r | |
3423 | // Already done. Shortcut. Skip to next path so that we don't create\r | |
3424 | // the BUILD_DIR as well.\r | |
3425 | //\r | |
3426 | Cptr = FileName + strlen (Cptr);\r | |
3427 | if (*Cptr == '\\') {\r | |
3428 | Cptr++;\r | |
3429 | }\r | |
3430 | }\r | |
3431 | } else {\r | |
3432 | //\r | |
3433 | // Not build dir\r | |
3434 | //\r | |
3435 | Cptr = FileName;\r | |
3436 | }\r | |
3437 | } else {\r | |
3438 | Cptr = FileName;\r | |
3439 | }\r | |
3440 | //\r | |
3441 | // Create directories until done. Skip over "c:\" in the path if it exists\r | |
3442 | //\r | |
3443 | if (*Cptr && (*(Cptr + 1) == ':') && (*(Cptr + 2) == '\\')) {\r | |
3444 | Cptr += 3;\r | |
3445 | }\r | |
3446 | \r | |
3447 | for (;;) {\r | |
95d675b5 | 3448 | for (; *Cptr && (*Cptr != '\\'); Cptr++)\r |
3eb9473e | 3449 | ;\r |
3450 | if (*Cptr) {\r | |
3451 | SavedChar = *Cptr;\r | |
3452 | *Cptr = 0;\r | |
3453 | if ((_mkdir (FileName) != 0)) {\r | |
3454 | //\r | |
3455 | // Error (NULL, 0, 0, FileName, "failed to create directory");\r | |
3456 | // return 1;\r | |
3457 | //\r | |
3458 | }\r | |
3459 | \r | |
3460 | *Cptr = SavedChar;\r | |
3461 | Cptr++;\r | |
3462 | } else {\r | |
3463 | break;\r | |
3464 | }\r | |
3465 | }\r | |
3466 | \r | |
3467 | return STATUS_SUCCESS;\r | |
3468 | }\r | |
3469 | \r | |
3470 | /*****************************************************************************\r | |
3471 | ******************************************************************************/\r | |
3472 | int\r | |
3473 | ExpandSymbols (\r | |
3474 | INT8 *SourceLine,\r | |
3475 | INT8 *DestLine,\r | |
3476 | int LineLen,\r | |
3477 | int ExpandMode\r | |
3478 | )\r | |
3479 | {\r | |
3480 | static int NestDepth = 0;\r | |
3481 | INT8 *FromPtr;\r | |
3482 | INT8 *ToPtr;\r | |
3483 | INT8 *SaveStart;\r | |
3484 | INT8 *Cptr;\r | |
3485 | INT8 *value;\r | |
3486 | int Expanded;\r | |
3487 | int ExpandedCount;\r | |
3488 | INT8 *LocalDestLine;\r | |
3489 | STATUS Status;\r | |
3490 | int LocalLineLen;\r | |
3491 | \r | |
3492 | NestDepth++;\r | |
3493 | Status = STATUS_SUCCESS;\r | |
3494 | LocalDestLine = (INT8 *) malloc (LineLen);\r | |
3495 | if (LocalDestLine == NULL) {\r | |
3496 | Error (__FILE__, __LINE__, 0, "application error", "memory allocation failed");\r | |
3497 | NestDepth = 0;\r | |
3498 | return STATUS_ERROR;\r | |
3499 | }\r | |
3500 | \r | |
3501 | FromPtr = SourceLine;\r | |
3502 | ToPtr = LocalDestLine;\r | |
3503 | //\r | |
3504 | // Walk the entire line, replacing $(SYMBOL_NAME).\r | |
3505 | //\r | |
3506 | LocalLineLen = LineLen;\r | |
3507 | ExpandedCount = 0;\r | |
3508 | while (*FromPtr && (LocalLineLen > 0)) {\r | |
3509 | if ((*FromPtr == '$') && (*(FromPtr + 1) == '(')) {\r | |
3510 | //\r | |
3511 | // Save the start in case it's undefined, in which case we copy it as-is.\r | |
3512 | //\r | |
3513 | SaveStart = FromPtr;\r | |
3514 | Expanded = 0;\r | |
3515 | //\r | |
3516 | // Symbol expansion time. Find the end (no spaces allowed)\r | |
3517 | //\r | |
3518 | FromPtr += 2;\r | |
3519 | for (Cptr = FromPtr; *Cptr && (*Cptr != ')'); Cptr++)\r | |
3520 | ;\r | |
3521 | if (*Cptr) {\r | |
3522 | //\r | |
3523 | // Truncate the string at the closing parenthesis for ease-of-use.\r | |
3524 | // Then copy the string directly to the destination line in case we don't find\r | |
3525 | // a definition for it.\r | |
3526 | //\r | |
3527 | *Cptr = 0;\r | |
3528 | strcpy (ToPtr, SaveStart);\r | |
3529 | if ((_stricmp (SOURCE_DIR, FromPtr) == 0) && (ExpandMode & EXPANDMODE_NO_SOURCEDIR)) {\r | |
3530 | //\r | |
3531 | // excluded this expansion\r | |
3532 | //\r | |
3533 | } else if ((_stricmp (DEST_DIR, FromPtr) == 0) && (ExpandMode & EXPANDMODE_NO_DESTDIR)) {\r | |
3534 | //\r | |
3535 | // excluded this expansion\r | |
3536 | //\r | |
3537 | } else if ((value = GetSymbolValue (FromPtr)) != NULL) {\r | |
3538 | strcpy (ToPtr, value);\r | |
3539 | LocalLineLen -= strlen (value);\r | |
3540 | ToPtr += strlen (value);\r | |
3541 | Expanded = 1;\r | |
3542 | ExpandedCount++;\r | |
3543 | } else if (ExpandMode & EXPANDMODE_NO_UNDEFS) {\r | |
3544 | Error (NULL, 0, 0, "undefined symbol", "$(%s)", FromPtr);\r | |
3545 | Status = STATUS_ERROR;\r | |
3546 | goto Done;\r | |
3547 | }\r | |
3548 | \r | |
3549 | //\r | |
3550 | // Restore closing parenthesis, and advance to next character\r | |
3551 | //\r | |
3552 | *Cptr = ')';\r | |
3553 | if (!Expanded) {\r | |
3554 | FromPtr = SaveStart + 1;\r | |
3555 | ToPtr++;\r | |
3556 | } else {\r | |
3557 | FromPtr = Cptr + 1;\r | |
3558 | }\r | |
3559 | } else {\r | |
3560 | Error (NULL, 0, 0, SourceLine, "missing closing parenthesis on symbol");\r | |
3561 | strcpy (ToPtr, FromPtr);\r | |
3562 | Status = STATUS_WARNING;\r | |
3563 | goto Done;\r | |
3564 | }\r | |
3565 | } else {\r | |
3566 | *ToPtr = *FromPtr;\r | |
3567 | FromPtr++;\r | |
3568 | ToPtr++;\r | |
3569 | LocalLineLen--;\r | |
3570 | }\r | |
3571 | }\r | |
3572 | \r | |
3573 | if (*FromPtr == 0) {\r | |
3574 | *ToPtr = 0;\r | |
3575 | }\r | |
3576 | \r | |
3577 | //\r | |
3578 | // If we're in recursive mode, and we expanded at least one string successfully,\r | |
3579 | // then make a recursive call to try again.\r | |
3580 | //\r | |
3581 | if ((ExpandedCount != 0) && (Status == STATUS_SUCCESS) && (ExpandMode & EXPANDMODE_RECURSIVE) && (NestDepth < 2)) {\r | |
3582 | Status = ExpandSymbols (LocalDestLine, DestLine, LineLen, ExpandMode);\r | |
3583 | free (LocalDestLine);\r | |
3584 | NestDepth = 0;\r | |
3585 | return Status;\r | |
3586 | }\r | |
3587 | \r | |
3588 | Done:\r | |
3589 | if (Status != STATUS_ERROR) {\r | |
3590 | strcpy (DestLine, LocalDestLine);\r | |
3591 | }\r | |
3592 | \r | |
3593 | NestDepth = 0;\r | |
3594 | free (LocalDestLine);\r | |
3595 | return Status;\r | |
3596 | }\r | |
3597 | \r | |
3598 | INT8 *\r | |
3599 | GetSymbolValue (\r | |
3600 | INT8 *SymbolName\r | |
3601 | )\r | |
3602 | /*++\r | |
3603 | \r | |
3604 | Routine Description:\r | |
3605 | \r | |
3606 | Look up a symbol in our symbol table.\r | |
3607 | \r | |
3608 | Arguments:\r | |
3609 | \r | |
3610 | SymbolName - The name of symbol.\r | |
3611 | \r | |
3612 | Returns:\r | |
3613 | \r | |
3614 | Pointer to the value of the symbol if found\r | |
3615 | NULL if the symbol is not found\r | |
3616 | \r | |
3617 | --*/\r | |
3618 | {\r | |
3619 | SYMBOL *Symbol;\r | |
3620 | \r | |
3621 | //\r | |
3622 | // Scan once for file-level symbols\r | |
3623 | //\r | |
3624 | Symbol = gGlobals.Symbol;\r | |
3625 | while (Symbol) {\r | |
3626 | if ((_stricmp (SymbolName, Symbol->Name) == 0) && (Symbol->Type & SYM_FILE)) {\r | |
3627 | return Symbol->Value;\r | |
3628 | }\r | |
3629 | \r | |
3630 | Symbol = Symbol->Next;\r | |
3631 | }\r | |
3632 | //\r | |
3633 | // Scan once for local symbols\r | |
3634 | //\r | |
3635 | Symbol = gGlobals.Symbol;\r | |
3636 | while (Symbol) {\r | |
3637 | if ((_stricmp (SymbolName, Symbol->Name) == 0) && (Symbol->Type & SYM_LOCAL)) {\r | |
3638 | return Symbol->Value;\r | |
3639 | }\r | |
3640 | \r | |
3641 | Symbol = Symbol->Next;\r | |
3642 | }\r | |
3643 | //\r | |
3644 | // No local value found. Scan for globals.\r | |
3645 | //\r | |
3646 | Symbol = gGlobals.Symbol;\r | |
3647 | while (Symbol) {\r | |
3648 | if ((_stricmp (SymbolName, Symbol->Name) == 0) && (Symbol->Type & SYM_GLOBAL)) {\r | |
3649 | return Symbol->Value;\r | |
3650 | }\r | |
3651 | \r | |
3652 | Symbol = Symbol->Next;\r | |
3653 | }\r | |
3654 | //\r | |
3655 | // For backwards-compatibility, if it's "GUID", return FILE_GUID value\r | |
3656 | //\r | |
3657 | if (_stricmp (SymbolName, GUID) == 0) {\r | |
3658 | return GetSymbolValue (FILE_GUID);\r | |
3659 | }\r | |
3660 | \r | |
3661 | return NULL;\r | |
3662 | }\r | |
3663 | \r | |
3664 | static\r | |
3665 | int\r | |
3666 | RemoveLocalSymbols (\r | |
3667 | VOID\r | |
3668 | )\r | |
3669 | /*++\r | |
3670 | \r | |
3671 | Routine Description:\r | |
3672 | \r | |
3673 | Remove all local symbols from the symbol table. Local symbols are those\r | |
3674 | that are defined typically by the component's INF file.\r | |
3675 | \r | |
3676 | Arguments:\r | |
3677 | \r | |
3678 | None.\r | |
3679 | \r | |
3680 | Returns:\r | |
3681 | \r | |
3682 | Right now, never fails.\r | |
3683 | \r | |
3684 | --*/\r | |
3685 | {\r | |
3686 | SYMBOL *Sym;\r | |
3687 | int FoundOne;\r | |
3688 | \r | |
3689 | do {\r | |
3690 | FoundOne = 0;\r | |
3691 | Sym = gGlobals.Symbol;\r | |
3692 | while (Sym) {\r | |
3693 | if (Sym->Type & SYM_LOCAL) {\r | |
3694 | //\r | |
3695 | // Going to delete it out from under ourselves, so break and restart\r | |
3696 | //\r | |
3697 | FoundOne = 1;\r | |
3698 | RemoveSymbol (Sym->Name, SYM_LOCAL);\r | |
3699 | break;\r | |
3700 | }\r | |
3701 | \r | |
3702 | Sym = Sym->Next;\r | |
3703 | }\r | |
3704 | } while (FoundOne);\r | |
3705 | return STATUS_SUCCESS;\r | |
3706 | }\r | |
3707 | \r | |
3708 | static\r | |
3709 | int\r | |
3710 | RemoveFileSymbols (\r | |
3711 | VOID\r | |
3712 | )\r | |
3713 | /*++\r | |
3714 | \r | |
3715 | Routine Description:\r | |
3716 | \r | |
3717 | Remove all file-level symbols from the symbol table. File-level symbols are \r | |
3718 | those that are defined on a source file line in an INF file.\r | |
3719 | \r | |
3720 | Arguments:\r | |
3721 | \r | |
3722 | None.\r | |
3723 | \r | |
3724 | Returns:\r | |
3725 | \r | |
3726 | Right now, never fails.\r | |
3727 | \r | |
3728 | --*/\r | |
3729 | {\r | |
3730 | SYMBOL *Sym;\r | |
3731 | int FoundOne;\r | |
3732 | \r | |
3733 | do {\r | |
3734 | FoundOne = 0;\r | |
3735 | Sym = gGlobals.Symbol;\r | |
3736 | while (Sym) {\r | |
3737 | if (Sym->Type & SYM_FILE) {\r | |
3738 | //\r | |
3739 | // Going to delete it out from under ourselves, so break and restart\r | |
3740 | //\r | |
3741 | FoundOne = 1;\r | |
3742 | RemoveSymbol (Sym->Name, SYM_FILE);\r | |
3743 | break;\r | |
3744 | }\r | |
3745 | \r | |
3746 | Sym = Sym->Next;\r | |
3747 | }\r | |
3748 | } while (FoundOne);\r | |
3749 | return STATUS_SUCCESS;\r | |
3750 | }\r | |
3751 | \r | |
3752 | static\r | |
3753 | STATUS\r | |
3754 | ParseGuidDatabaseFile (\r | |
3755 | INT8 *FileName\r | |
3756 | )\r | |
3757 | /*++\r | |
3758 | \r | |
3759 | Routine Description:\r | |
3760 | This function parses a GUID-to-basename text file (perhaps output by\r | |
3761 | the GuidChk utility) to define additional symbols. The format of the \r | |
3762 | file should be:\r | |
3763 | \r | |
3764 | 7BB28B99-61BB-11D5-9A5D-0090273FC14D EFI_DEFAULT_BMP_LOGO_GUID gEfiDefaultBmpLogoGuid\r | |
3765 | \r | |
3766 | This function parses the line and defines global symbol:\r | |
3767 | \r | |
3768 | EFI_DEFAULT_BMP_LOGO_GUID=7BB28B99-61BB-11D5-9A5D-0090273FC14D \r | |
3769 | \r | |
3770 | This symbol (rather than the actual GUID) can then be used in INF files to \r | |
3771 | fix duplicate GUIDs\r | |
3772 | \r | |
3773 | Arguments:\r | |
3774 | FileName - the name of the file to parse.\r | |
3775 | \r | |
3776 | Returns:\r | |
3777 | STATUS_ERROR - could not open FileName\r | |
3778 | STATUS_SUCCESS - we opened the file\r | |
3779 | \r | |
3780 | --*/\r | |
3781 | {\r | |
3782 | FILE *Fptr;\r | |
3783 | INT8 Line[100];\r | |
3784 | INT8 Guid[100];\r | |
3785 | INT8 DefineName[80];\r | |
3786 | \r | |
3787 | Fptr = fopen (FileName, "r");\r | |
3788 | if (Fptr == NULL) {\r | |
3789 | Error (NULL, 0, 0, FileName, "failed to open input GUID database input file");\r | |
3790 | return STATUS_ERROR;\r | |
3791 | }\r | |
3792 | \r | |
3793 | while (fgets (Line, sizeof (Line), Fptr) != NULL) {\r | |
3794 | //\r | |
3795 | // Get the GUID string, skip the defined name (EFI_XXX_GUID), and get the\r | |
3796 | // variable name (gWhateverProtocolGuid)\r | |
3797 | //\r | |
3798 | if (sscanf (Line, "%s %s %*s", Guid, DefineName) == 2) {\r | |
3799 | AddSymbol (DefineName, Guid, SYM_GLOBAL);\r | |
3800 | }\r | |
3801 | }\r | |
3802 | \r | |
3803 | fclose (Fptr);\r | |
3804 | return STATUS_SUCCESS;\r | |
3805 | }\r | |
3806 | \r | |
3807 | /*****************************************************************************\r | |
3808 | \r | |
3809 | Returns:\r | |
3810 | 0 if successful standard add\r | |
3811 | length of the parsed string if passed in " name = value "\r | |
3812 | < 0 on error\r | |
3813 | \r | |
3814 | ******************************************************************************/\r | |
3815 | int\r | |
3816 | AddSymbol (\r | |
3817 | INT8 *Name,\r | |
3818 | INT8 *Value,\r | |
3819 | int Mode\r | |
3820 | )\r | |
3821 | {\r | |
3822 | SYMBOL *Symbol;\r | |
3823 | SYMBOL *NewSymbol;\r | |
3824 | int Len;\r | |
3825 | INT8 *Start;\r | |
3826 | INT8 *Cptr;\r | |
3827 | INT8 CSave1;\r | |
3828 | INT8 *SaveCptr1;\r | |
3829 | INT8 CSave2;\r | |
3830 | INT8 *SaveCptr2;\r | |
3831 | INT8 ShortName[MAX_PATH];\r | |
3832 | \r | |
3833 | Len = 0;\r | |
3834 | SaveCptr1 = NULL;\r | |
3835 | CSave1 = 0;\r | |
3836 | SaveCptr2 = NULL;\r | |
3837 | CSave2 = 0;\r | |
3838 | \r | |
3839 | ShortName[0] = 0;\r | |
3840 | //\r | |
3841 | // Mode better be local or global symbol\r | |
3842 | //\r | |
3843 | if ((Mode & (SYM_LOCAL | SYM_GLOBAL | SYM_FILE)) == 0) {\r | |
3844 | Error (NULL, 0, 0, "APP ERROR", "adding symbol '%s' that is not local, global, nor file level", Name);\r | |
3845 | return -1;\r | |
3846 | }\r | |
3847 | //\r | |
3848 | // If value pointer is null, then they passed us a line something like:\r | |
3849 | // varname = value, or simply var =\r | |
3850 | //\r | |
3851 | if (Value == NULL) {\r | |
3852 | Start = Name;\r | |
3853 | while (*Name && isspace (*Name)) {\r | |
3854 | Name++;\r | |
3855 | \r | |
3856 | }\r | |
3857 | \r | |
3858 | if (!*Name) {\r | |
3859 | return -1;\r | |
3860 | }\r | |
3861 | //\r | |
3862 | // Find the end of the name. Either space or a '='.\r | |
3863 | //\r | |
3864 | for (Value = Name; *Value && !isspace (*Value) && (*Value != '='); Value++)\r | |
3865 | ;\r | |
3866 | if (!*Value) {\r | |
3867 | return -1;\r | |
3868 | }\r | |
3869 | //\r | |
3870 | // Look for the '='\r | |
3871 | //\r | |
3872 | Cptr = Value;\r | |
3873 | while (*Value && (*Value != '=')) {\r | |
3874 | Value++;\r | |
3875 | }\r | |
3876 | \r | |
3877 | if (!*Value) {\r | |
3878 | return -1;\r | |
3879 | }\r | |
3880 | \r | |
3881 | //\r | |
3882 | // Now truncate the name\r | |
3883 | //\r | |
3884 | CSave1 = *Cptr;\r | |
3885 | SaveCptr1 = Cptr;\r | |
3886 | *Cptr = 0; \r | |
3887 | \r | |
3888 | //\r | |
3889 | // Skip over the = and then any spaces\r | |
3890 | //\r | |
3891 | Value++;\r | |
3892 | while (*Value && isspace (*Value)) {\r | |
3893 | Value++;\r | |
3894 | \r | |
3895 | }\r | |
3896 | //\r | |
3897 | // Find end of string, checking for quoted string\r | |
3898 | //\r | |
3899 | if (*Value == '\"') {\r | |
3900 | Value++;\r | |
3901 | for (Cptr = Value; *Cptr && *Cptr != '\"'; Cptr++)\r | |
3902 | ;\r | |
3903 | } else {\r | |
3904 | for (Cptr = Value; *Cptr && !isspace (*Cptr); Cptr++)\r | |
3905 | ;\r | |
3906 | }\r | |
3907 | //\r | |
3908 | // Null terminate the value string\r | |
3909 | //\r | |
3910 | if (*Cptr) {\r | |
3911 | Len = (int) (Cptr - Start) + 1;\r | |
3912 | CSave2 = *Cptr;\r | |
3913 | SaveCptr2 = Cptr;\r | |
3914 | *Cptr = 0;\r | |
3915 | } else {\r | |
3916 | Len = (int) (Cptr - Start);\r | |
3917 | }\r | |
3918 | }\r | |
3919 | \r | |
3920 | //\r | |
3921 | // If file name or file path, and we're shortening, then print it\r | |
3922 | //\r | |
3923 | if ((Mode & (SYM_FILEPATH | SYM_FILENAME)) && (GetSymbolValue (SHORT_NAMES) != NULL)) {\r | |
3924 | if (GetShortPathName (Value, ShortName, sizeof (ShortName)) > 0) {\r | |
3925 | //\r | |
3926 | // fprintf (stdout, "String value '%s' shortened to '%s'\n",\r | |
3927 | // Value, ShortName);\r | |
3928 | //\r | |
3929 | Value = ShortName;\r | |
3930 | } else {\r | |
3931 | //\r | |
3932 | // fprintf (stdout, "WARNING: Failed to get short name for %s\n", Value);\r | |
3933 | //\r | |
3934 | }\r | |
3935 | }\r | |
3936 | //\r | |
3937 | // We now have a symbol name and a value. Look for an existing variable of\r | |
3938 | // the same type (global or local) and overwrite it.\r | |
3939 | //\r | |
3940 | Symbol = gGlobals.Symbol;\r | |
3941 | while (Symbol) {\r | |
3942 | //\r | |
3943 | // Check for symbol name match\r | |
3944 | //\r | |
3945 | if (_stricmp (Name, Symbol->Name) == 0) {\r | |
3946 | //\r | |
3947 | // See if this symbol is of the same type (global or local) as what\r | |
3948 | // they're requesting\r | |
3949 | //\r | |
3950 | if ((Symbol->Type & (SYM_LOCAL | SYM_GLOBAL)) == (Mode & (SYM_LOCAL | SYM_GLOBAL))) {\r | |
3951 | //\r | |
3952 | // Did they say we could overwrite it?\r | |
3953 | //\r | |
3954 | if (Mode & SYM_OVERWRITE) {\r | |
3955 | free (Symbol->Value);\r | |
3956 | Symbol->Value = (INT8 *) malloc (strlen (Value) + 1);\r | |
3957 | if (Symbol->Value == NULL) {\r | |
3958 | Error (NULL, 0, 0, NULL, "failed to allocate memory");\r | |
3959 | return -1;\r | |
3960 | }\r | |
3961 | \r | |
3962 | strcpy (Symbol->Value, Value);\r | |
3963 | //\r | |
3964 | // If value == "NULL", then make it a 0-length string\r | |
3965 | //\r | |
3966 | if (_stricmp (Symbol->Value, "NULL") == 0) {\r | |
3967 | Symbol->Value[0] = 0;\r | |
3968 | }\r | |
3969 | \r | |
3970 | return Len;\r | |
3971 | } else {\r | |
3972 | return STATUS_ERROR;\r | |
3973 | }\r | |
3974 | }\r | |
3975 | }\r | |
3976 | \r | |
3977 | Symbol = Symbol->Next;\r | |
3978 | }\r | |
3979 | //\r | |
3980 | // Does not exist, create a new one\r | |
3981 | //\r | |
3982 | NewSymbol = (SYMBOL *) malloc (sizeof (SYMBOL));\r | |
3983 | if (NewSymbol == NULL) {\r | |
3984 | Error (NULL, 0, 0, NULL, "failed to allocate memory");\r | |
3985 | return -1;\r | |
3986 | }\r | |
3987 | \r | |
3988 | memset ((INT8 *) NewSymbol, 0, sizeof (SYMBOL));\r | |
3989 | NewSymbol->Name = (INT8 *) malloc (strlen (Name) + 1);\r | |
3990 | NewSymbol->Value = (INT8 *) malloc (strlen (Value) + 1);\r | |
3991 | //\r | |
3992 | // Simply use the mode bits as the type.\r | |
3993 | //\r | |
3994 | NewSymbol->Type = Mode;\r | |
3995 | if ((NewSymbol->Name == NULL) || (NewSymbol->Value == NULL)) {\r | |
3996 | Error (NULL, 0, 0, NULL, "failed to allocate memory");\r | |
3997 | return -1;\r | |
3998 | }\r | |
3999 | \r | |
4000 | strcpy (NewSymbol->Name, Name);\r | |
4001 | strcpy (NewSymbol->Value, Value);\r | |
4002 | //\r | |
4003 | // Remove trailing spaces\r | |
4004 | //\r | |
4005 | Cptr = NewSymbol->Value + strlen (NewSymbol->Value) - 1;\r | |
4006 | while (Cptr > NewSymbol->Value) {\r | |
4007 | if (isspace (*Cptr)) {\r | |
4008 | *Cptr = 0;\r | |
4009 | Cptr--;\r | |
4010 | } else {\r | |
4011 | break;\r | |
4012 | }\r | |
4013 | }\r | |
4014 | //\r | |
4015 | // Add it to the head of the list.\r | |
4016 | //\r | |
4017 | NewSymbol->Next = gGlobals.Symbol;\r | |
4018 | gGlobals.Symbol = NewSymbol;\r | |
4019 | //\r | |
4020 | // If value == "NULL", then make it a 0-length string\r | |
4021 | //\r | |
4022 | if (_stricmp (NewSymbol->Value, "NULL") == 0) {\r | |
4023 | NewSymbol->Value[0] = 0;\r | |
4024 | }\r | |
4025 | //\r | |
4026 | // Restore the terminator we inserted if they passed in var=value\r | |
4027 | //\r | |
4028 | if (SaveCptr1 != NULL) {\r | |
4029 | *SaveCptr1 = CSave1;\r | |
4030 | }\r | |
4031 | if (SaveCptr2 != NULL) {\r | |
4032 | *SaveCptr2 = CSave2;\r | |
4033 | }\r | |
4034 | \r | |
4035 | return Len;\r | |
4036 | }\r | |
4037 | \r | |
4038 | /*****************************************************************************\r | |
4039 | ******************************************************************************/\r | |
4040 | static\r | |
4041 | int\r | |
4042 | RemoveSymbol (\r | |
4043 | INT8 *Name,\r | |
4044 | INT8 SymbolType\r | |
4045 | )\r | |
4046 | {\r | |
4047 | SYMBOL *Symbol;\r | |
4048 | SYMBOL *PrevSymbol;\r | |
4049 | \r | |
4050 | PrevSymbol = NULL;\r | |
4051 | Symbol = gGlobals.Symbol;\r | |
4052 | while (Symbol) {\r | |
4053 | if ((_stricmp (Name, Symbol->Name) == 0) && (Symbol->Type & SymbolType)) {\r | |
4054 | if (Symbol->Value) {\r | |
4055 | free (Symbol->Value);\r | |
4056 | }\r | |
4057 | \r | |
4058 | free (Symbol->Name);\r | |
4059 | if (PrevSymbol) {\r | |
4060 | PrevSymbol->Next = Symbol->Next;\r | |
4061 | } else {\r | |
4062 | gGlobals.Symbol = Symbol->Next;\r | |
4063 | }\r | |
4064 | \r | |
4065 | free (Symbol);\r | |
4066 | return STATUS_SUCCESS;\r | |
4067 | }\r | |
4068 | \r | |
4069 | PrevSymbol = Symbol;\r | |
4070 | Symbol = Symbol->Next;\r | |
4071 | }\r | |
4072 | \r | |
4073 | return STATUS_WARNING;\r | |
4074 | }\r | |
4075 | \r | |
4076 | #if 0\r | |
4077 | \r | |
4078 | /*****************************************************************************\r | |
4079 | ******************************************************************************/\r | |
4080 | static\r | |
4081 | void\r | |
4082 | FreeSections (\r | |
4083 | SECTION *Sect\r | |
4084 | )\r | |
4085 | {\r | |
4086 | SECTION *Next;\r | |
4087 | \r | |
4088 | while (Sect != NULL) {\r | |
4089 | Next = Sect->Next;\r | |
4090 | if (Sect->Name != NULL) {\r | |
4091 | delete[] Sect->Name;\r | |
4092 | }\r | |
4093 | \r | |
4094 | delete Sect;\r | |
4095 | Sect = Next;\r | |
4096 | }\r | |
4097 | }\r | |
4098 | #endif\r | |
4099 | \r | |
4100 | /*****************************************************************************\r | |
4101 | ******************************************************************************/\r | |
4102 | static\r | |
4103 | INT8 *\r | |
4104 | StripLine (\r | |
4105 | INT8 *Line\r | |
4106 | )\r | |
4107 | {\r | |
4108 | INT8 *Cptr;\r | |
4109 | int Len;\r | |
4110 | \r | |
4111 | Cptr = Line;\r | |
4112 | //\r | |
4113 | // Look for '#' comments in first character of line\r | |
4114 | //\r | |
4115 | if (*Cptr == '#') {\r | |
4116 | *Cptr = 0;\r | |
4117 | return Cptr;\r | |
4118 | }\r | |
4119 | \r | |
4120 | while (isspace (*Cptr)) {\r | |
4121 | Cptr++;\r | |
4122 | }\r | |
4123 | //\r | |
4124 | // Hack off newlines\r | |
4125 | //\r | |
4126 | Len = strlen (Cptr);\r | |
4127 | if ((Len > 0) && (Cptr[Len - 1] == '\n')) {\r | |
4128 | Cptr[Len - 1] = 0;\r | |
4129 | }\r | |
4130 | //\r | |
4131 | // Hack off trailing spaces\r | |
4132 | //\r | |
4133 | StripTrailingSpaces (Cptr);\r | |
4134 | return Cptr;\r | |
4135 | }\r | |
4136 | \r | |
4137 | /*****************************************************************************\r | |
4138 | FUNCTION: ProcessOptions()\r | |
4139 | \r | |
4140 | DESCRIPTION: Process the command-line options. \r | |
4141 | ******************************************************************************/\r | |
4142 | static\r | |
4143 | int\r | |
4144 | ProcessOptions (\r | |
4145 | int Argc,\r | |
4146 | INT8 *Argv[]\r | |
4147 | )\r | |
4148 | /*++\r | |
4149 | \r | |
4150 | Routine Description:\r | |
4151 | \r | |
4152 | Process the command line options to this utility.\r | |
4153 | \r | |
4154 | Arguments:\r | |
4155 | \r | |
4156 | Argc - Standard Argc.\r | |
4157 | Argv[] - Standard Argv.\r | |
4158 | \r | |
4159 | Returns:\r | |
4160 | \r | |
4161 | --*/\r | |
4162 | {\r | |
4163 | INT8 *Cptr;\r | |
4164 | int FreeCwd;\r | |
4165 | \r | |
4166 | //\r | |
4167 | // Clear out the options\r | |
4168 | //\r | |
4169 | memset ((INT8 *) &gGlobals, 0, sizeof (gGlobals));\r | |
4170 | \r | |
4171 | Argc--;\r | |
4172 | Argv++;\r | |
4173 | \r | |
4174 | if (Argc == 0) {\r | |
4175 | Usage ();\r | |
4176 | return STATUS_ERROR;\r | |
4177 | }\r | |
4178 | //\r | |
4179 | // Now process the arguments\r | |
4180 | //\r | |
4181 | while (Argc > 0) {\r | |
4182 | \r | |
4183 | if ((Argv[0][0] == '-') || (Argv[0][0] == '/')) {\r | |
4184 | switch (Argv[0][1]) {\r | |
4185 | //\r | |
4186 | // -? or -h help option\r | |
4187 | //\r | |
4188 | case '?':\r | |
4189 | case 'h':\r | |
4190 | case 'H':\r | |
4191 | Usage ();\r | |
4192 | return STATUS_ERROR;\r | |
4193 | \r | |
4194 | //\r | |
4195 | // /d symbol=name\r | |
4196 | //\r | |
4197 | case 'd':\r | |
4198 | case 'D':\r | |
4199 | //\r | |
4200 | // Skip to next arg\r | |
4201 | //\r | |
4202 | Argc--;\r | |
4203 | Argv++;\r | |
4204 | if (Argc == 0) {\r | |
4205 | Argv--;\r | |
4206 | Error (NULL, 0, 0, NULL, "missing symbol definition with %c%c", Argv[0][0], Argv[0][1]);\r | |
4207 | return STATUS_ERROR;\r | |
4208 | } else {\r | |
4209 | if (AddSymbol (Argv[0], NULL, SYM_OVERWRITE | SYM_GLOBAL) <= 0) {\r | |
4210 | Warning (NULL, 0, 0, Argv[0], "failed to add symbol: %s");\r | |
4211 | }\r | |
4212 | }\r | |
4213 | break;\r | |
4214 | \r | |
4215 | //\r | |
4216 | // output makefile name\r | |
4217 | //\r | |
4218 | case 'm':\r | |
4219 | case 'M':\r | |
4220 | //\r | |
4221 | // Skip to next arg\r | |
4222 | //\r | |
4223 | Argc--;\r | |
4224 | Argv++;\r | |
4225 | if (Argc == 0) {\r | |
4226 | Argv--;\r | |
4227 | Error (NULL, 0, 0, Argv[0], "missing output makefile name with option");\r | |
4228 | Usage ();\r | |
4229 | return STATUS_ERROR;\r | |
4230 | } else {\r | |
4231 | strcpy (gGlobals.MakefileName, Argv[0]);\r | |
4232 | }\r | |
4233 | break;\r | |
4234 | \r | |
4235 | //\r | |
4236 | // Print a cross-reference file containing guid/basename/processor\r | |
4237 | //\r | |
4238 | case 'x':\r | |
4239 | case 'X':\r | |
4240 | //\r | |
4241 | // Skip to next arg\r | |
4242 | //\r | |
4243 | Argc--;\r | |
4244 | Argv++;\r | |
4245 | if (Argc == 0) {\r | |
4246 | Argv--;\r | |
4247 | Error (NULL, 0, 0, Argv[0], "missing cross-reference output filename with option");\r | |
4248 | Usage ();\r | |
4249 | return STATUS_ERROR;\r | |
4250 | } else {\r | |
4251 | strcpy (gGlobals.XRefFileName, Argv[0]);\r | |
4252 | }\r | |
4253 | break;\r | |
4254 | \r | |
4255 | //\r | |
4256 | // GUID database file to preparse\r | |
4257 | //\r | |
4258 | case 'g':\r | |
4259 | case 'G':\r | |
4260 | //\r | |
4261 | // Skip to next arg\r | |
4262 | //\r | |
4263 | Argc--;\r | |
4264 | Argv++;\r | |
4265 | if (Argc == 0) {\r | |
4266 | Argv--;\r | |
4267 | Error (NULL, 0, 0, Argv[0], "missing input GUID database filename with option");\r | |
4268 | Usage ();\r | |
4269 | return STATUS_ERROR;\r | |
4270 | } else {\r | |
4271 | strcpy (gGlobals.GuidDatabaseFileName, Argv[0]);\r | |
4272 | }\r | |
4273 | break;\r | |
4274 | \r | |
3e99020d LG |
4275 | //\r |
4276 | // Enable multi-thread build and specify the thread number\r | |
4277 | //\r | |
4278 | case 'n':\r | |
4279 | case 'N':\r | |
4280 | //\r | |
4281 | // Skip to next arg\r | |
4282 | //\r | |
4283 | Argc--;\r | |
4284 | Argv++;\r | |
4285 | if (Argc == 0) {\r | |
4286 | Argv--;\r | |
4287 | Error (NULL, 0, 0, Argv[0], "missing input thread number with option");\r | |
4288 | Usage ();\r | |
4289 | return STATUS_ERROR;\r | |
4290 | } else {\r | |
4291 | gGlobals.ThreadNumber = atoi (Argv[0]);\r | |
4292 | if (gGlobals.ThreadNumber == 0) {\r | |
4293 | Argv--;\r | |
4294 | Error (NULL, 0, 0, Argv[0], "input thread number should not be %s", Argv[1]);\r | |
4295 | return STATUS_ERROR;\r | |
4296 | } else if (gGlobals.ThreadNumber > MAXIMUM_WAIT_OBJECTS) {\r | |
4297 | Argv--;\r | |
4298 | Error (NULL, 0, 0, Argv[0], "input thread number should not greater than %d", MAXIMUM_WAIT_OBJECTS);\r | |
4299 | return STATUS_ERROR;\r | |
4300 | }\r | |
4301 | }\r | |
4302 | break;\r | |
4303 | \r | |
4304 | //\r | |
4305 | // Specify the multi-thread build target\r | |
4306 | //\r | |
4307 | case 't':\r | |
4308 | case 'T':\r | |
4309 | //\r | |
4310 | // Skip to next arg\r | |
4311 | //\r | |
4312 | Argc--;\r | |
4313 | Argv++;\r | |
4314 | if (Argc == 0) {\r | |
4315 | Argv--;\r | |
4316 | Error (NULL, 0, 0, Argv[0], "missing input build target with option");\r | |
4317 | Usage ();\r | |
4318 | return STATUS_ERROR;\r | |
4319 | } else if (_stricmp (Argv[0], "all") == 0) {\r | |
4320 | gGlobals.BuildTarget |= BUILD_TARGET_ALL;\r | |
4321 | } else if (_stricmp (Argv[0], "libraries") == 0) {\r | |
4322 | gGlobals.BuildTarget |= BUILD_TARGET_LIBRARIES;\r | |
4323 | } else if (_stricmp (Argv[0], "components") == 0) {\r | |
4324 | gGlobals.BuildTarget |= BUILD_TARGET_COMPONENTS;\r | |
4325 | } else {\r | |
4326 | Argv--;\r | |
4327 | Error (NULL, 0, 0, Argv[0], "input build target not supported");\r | |
4328 | Usage ();\r | |
4329 | }\r | |
4330 | break;\r | |
4331 | \r | |
3eb9473e | 4332 | case 'v':\r |
4333 | case 'V':\r | |
4334 | gGlobals.Verbose = 1;\r | |
4335 | break;\r | |
4336 | \r | |
4337 | default:\r | |
4338 | Error (NULL, 0, 0, Argv[0], "unrecognized option");\r | |
4339 | return STATUS_ERROR;\r | |
4340 | }\r | |
4341 | } else {\r | |
4342 | break;\r | |
4343 | }\r | |
4344 | \r | |
4345 | Argc--;\r | |
4346 | Argv++;\r | |
4347 | }\r | |
4348 | //\r | |
4349 | // Must be at least one arg left\r | |
4350 | //\r | |
4351 | if (Argc > 0) {\r | |
4352 | gGlobals.DscFilename = Argv[0];\r | |
4353 | }\r | |
4354 | \r | |
4355 | if (gGlobals.DscFilename == NULL) {\r | |
4356 | Error (NULL, 0, 0, NULL, "must specify DSC filename on command line");\r | |
4357 | return STATUS_ERROR;\r | |
4358 | }\r | |
4359 | //\r | |
4360 | // Make a global symbol for the DSC filename\r | |
4361 | //\r | |
4362 | AddSymbol (DSC_FILENAME, gGlobals.DscFilename, SYM_GLOBAL | SYM_FILENAME);\r | |
4363 | //\r | |
4364 | // If no output makefile specified, take the default\r | |
4365 | //\r | |
4366 | if (gGlobals.MakefileName[0] == 0) {\r | |
4367 | strcpy (gGlobals.MakefileName, MAKEFILE_OUT_NAME);\r | |
4368 | }\r | |
4369 | //\r | |
4370 | // Get the current working directory and use it for the build directory.\r | |
4371 | // Only do this if they have not defined it on the command line. Do the\r | |
4372 | // same for the bin dir, output dir, and library directory.\r | |
4373 | //\r | |
4374 | Cptr = GetSymbolValue (BUILD_DIR);\r | |
4375 | if (Cptr == NULL) {\r | |
4376 | Cptr = _getcwd (NULL, 0);\r | |
4377 | FreeCwd = 1;\r | |
4378 | AddSymbol (BUILD_DIR, Cptr, SYM_OVERWRITE | SYM_GLOBAL | SYM_FILEPATH);\r | |
4379 | } else {\r | |
95d675b5 | 4380 | ReplaceSlash (Cptr);\r |
3eb9473e | 4381 | FreeCwd = 0;\r |
4382 | }\r | |
4383 | \r | |
4384 | if (FreeCwd) {\r | |
4385 | free (Cptr);\r | |
4386 | }\r | |
3e99020d LG |
4387 | \r |
4388 | //\r | |
4389 | // Default build target is all\r | |
4390 | //\r | |
4391 | if (gGlobals.BuildTarget == 0) {\r | |
4392 | gGlobals.BuildTarget = BUILD_TARGET_ALL;\r | |
4393 | }\r | |
4394 | \r | |
3eb9473e | 4395 | return 0;\r |
4396 | }\r | |
4397 | \r | |
4398 | /*****************************************************************************\r | |
4399 | ******************************************************************************/\r | |
4400 | static\r | |
4401 | SYMBOL *\r | |
4402 | FreeSymbols (\r | |
4403 | SYMBOL *Syms\r | |
4404 | )\r | |
4405 | {\r | |
4406 | SYMBOL *Next;\r | |
4407 | while (Syms) {\r | |
4408 | \r | |
4409 | if (Syms->Name != NULL) {\r | |
4410 | free (Syms->Name);\r | |
4411 | }\r | |
4412 | \r | |
4413 | if (Syms->Value != NULL) {\r | |
4414 | free (Syms->Value);\r | |
4415 | }\r | |
4416 | \r | |
4417 | Next = Syms->Next;\r | |
4418 | free (Syms);\r | |
4419 | Syms = Next;\r | |
4420 | }\r | |
4421 | \r | |
4422 | return Syms;\r | |
4423 | }\r | |
4424 | \r | |
4425 | /*****************************************************************************\r | |
4426 | ******************************************************************************/\r | |
4427 | static\r | |
4428 | int\r | |
4429 | GetSourceFileType (\r | |
4430 | INT8 *FileName\r | |
4431 | )\r | |
4432 | {\r | |
4433 | INT8 *Cptr;\r | |
4434 | int len;\r | |
4435 | int i;\r | |
4436 | \r | |
4437 | len = strlen (FileName);\r | |
4438 | if (len == 0) {\r | |
4439 | return FILETYPE_UNKNOWN;\r | |
4440 | \r | |
4441 | }\r | |
4442 | \r | |
4443 | Cptr = FileName + len - 1;\r | |
4444 | while ((*Cptr != '.') && (Cptr >= FileName)) {\r | |
4445 | Cptr--;\r | |
4446 | \r | |
4447 | }\r | |
4448 | \r | |
4449 | if (*Cptr == '.') {\r | |
4450 | \r | |
4451 | for (i = 0; mFileTypes[i].Extension != NULL; i++) {\r | |
4452 | len = strlen (mFileTypes[i].Extension);\r | |
4453 | if (_strnicmp (mFileTypes[i].Extension, Cptr, len) == 0) {\r | |
4454 | if ((*(Cptr + len) == 0) || isspace (*(Cptr + len))) {\r | |
4455 | return mFileTypes[i].FileType;\r | |
4456 | }\r | |
4457 | }\r | |
4458 | }\r | |
4459 | }\r | |
4460 | \r | |
4461 | return FILETYPE_UNKNOWN;\r | |
4462 | }\r | |
4463 | //\r | |
4464 | // Determine if a given file is a standard include file. If we don't know,\r | |
4465 | // then assume it's not.\r | |
4466 | //\r | |
4467 | static\r | |
4468 | int\r | |
4469 | IsIncludeFile (\r | |
4470 | INT8 *FileName\r | |
4471 | )\r | |
4472 | {\r | |
4473 | INT8 *Cptr;\r | |
4474 | int len;\r | |
4475 | int i;\r | |
4476 | \r | |
4477 | len = strlen (FileName);\r | |
4478 | if (len == 0) {\r | |
4479 | return 0;\r | |
4480 | }\r | |
4481 | \r | |
4482 | Cptr = FileName + len - 1;\r | |
4483 | while ((*Cptr != '.') && (Cptr >= FileName)) {\r | |
4484 | Cptr--;\r | |
4485 | }\r | |
4486 | \r | |
4487 | if (*Cptr == '.') {\r | |
4488 | //\r | |
4489 | // Now go through the list of filename extensions and try to find\r | |
4490 | // a match for this file extension.\r | |
4491 | //\r | |
4492 | for (i = 0; mFileTypes[i].Extension != NULL; i++) {\r | |
4493 | len = strlen (mFileTypes[i].Extension);\r | |
4494 | if (_strnicmp (mFileTypes[i].Extension, Cptr, len) == 0) {\r | |
4495 | //\r | |
4496 | // Make sure that's all there is to the filename extension.\r | |
4497 | //\r | |
4498 | if ((*(Cptr + len) == 0) || isspace (*(Cptr + len))) {\r | |
4499 | return mFileTypes[i].FileFlags & FILE_FLAG_INCLUDE;\r | |
4500 | }\r | |
4501 | }\r | |
4502 | }\r | |
4503 | }\r | |
4504 | \r | |
4505 | return 0;\r | |
4506 | }\r | |
4507 | \r | |
4508 | /*****************************************************************************\r | |
4509 | ******************************************************************************/\r | |
4510 | static\r | |
4511 | void\r | |
4512 | StripTrailingSpaces (\r | |
4513 | INT8 *Str\r | |
4514 | )\r | |
4515 | {\r | |
4516 | INT8 *Cptr;\r | |
4517 | Cptr = Str + strlen (Str) - 1;\r | |
4518 | while (Cptr > Str) {\r | |
4519 | if (isspace (*Cptr)) {\r | |
4520 | *Cptr = 0;\r | |
4521 | Cptr--;\r | |
4522 | } else {\r | |
4523 | break;\r | |
4524 | }\r | |
4525 | }\r | |
4526 | }\r | |
4527 | \r | |
4528 | /*****************************************************************************\r | |
4529 | ******************************************************************************/\r | |
4530 | static\r | |
4531 | int\r | |
4532 | GetEfiSource (\r | |
4533 | VOID\r | |
4534 | )\r | |
4535 | {\r | |
4536 | INT8 *EfiSource;\r | |
4537 | \r | |
4538 | //\r | |
4539 | // Don't set it if the user specified it on the command line.\r | |
4540 | //\r | |
4541 | EfiSource = GetSymbolValue (EFI_SOURCE);\r | |
4542 | if ( EfiSource != NULL) {\r | |
95d675b5 | 4543 | ReplaceSlash (EfiSource);\r |
3eb9473e | 4544 | if (EfiSource[strlen (EfiSource) - 1] == '\\') {\r |
4545 | EfiSource[strlen (EfiSource) - 1] = 0;\r | |
4546 | } \r | |
4547 | return STATUS_SUCCESS;\r | |
4548 | }\r | |
4549 | \r | |
4550 | //\r | |
4551 | // Get the environmental variable setting of EFI_SOURCE. \r | |
4552 | //\r | |
4553 | EfiSource = getenv (EFI_SOURCE);\r | |
4554 | if (EfiSource != NULL) {\r | |
95d675b5 | 4555 | ReplaceSlash (EfiSource);\r |
3eb9473e | 4556 | if (EfiSource[strlen (EfiSource) - 1] == '\\') {\r |
4557 | EfiSource[strlen (EfiSource) - 1] = 0;\r | |
4558 | }\r | |
4559 | AddSymbol (EFI_SOURCE, EfiSource, SYM_GLOBAL | SYM_FILEPATH); \r | |
4560 | return STATUS_SUCCESS;\r | |
4561 | }\r | |
4562 | \r | |
4563 | Error (NULL, 0, 0, NULL, "could not determine EFI_SOURCE");\r | |
4564 | return STATUS_ERROR;\r | |
4565 | }\r | |
4566 | \r | |
4567 | void\r | |
4568 | Message (\r | |
4569 | UINT32 PrintMask,\r | |
4570 | INT8 *Fmt,\r | |
4571 | ...\r | |
4572 | )\r | |
4573 | {\r | |
4574 | INT8 Line[MAX_LINE_LEN];\r | |
4575 | va_list List;\r | |
4576 | \r | |
4577 | va_start (List, Fmt);\r | |
4578 | vsprintf (Line, Fmt, List);\r | |
4579 | if (PrintMask & gGlobals.Verbose) {\r | |
4580 | fprintf (stdout, "%s\n", Line);\r | |
4581 | }\r | |
4582 | \r | |
4583 | va_end (List);\r | |
4584 | }\r | |
4585 | \r | |
4586 | static\r | |
4587 | void\r | |
4588 | Usage (\r | |
4589 | VOID\r | |
4590 | )\r | |
4591 | {\r | |
3e99020d LG |
4592 | int Index;\r |
4593 | const char *Str[] = {\r | |
4594 | UTILITY_NAME" "UTILITY_VERSION" - Intel Process DSC File Utility",\r | |
4595 | " Copyright (C), 2004 - 2008 Intel Corporation",\r | |
4596 | \r | |
4597 | #if ( defined(UTILITY_BUILD) && defined(UTILITY_VENDOR) )\r | |
4598 | " Built from "UTILITY_BUILD", project of "UTILITY_VENDOR,\r | |
4599 | #endif\r | |
4600 | "",\r | |
4601 | "Usage:",\r | |
4602 | " "UTILITY_NAME" [OPTION]... DSCFILE",\r | |
4603 | "Options:",\r | |
4604 | " -d var=value to define symbol 'var' to 'value'",\r | |
4605 | " -v for verbose mode",\r | |
4606 | " -g filename to preparse GUID listing file",\r | |
4607 | " -x filename to create a cross-reference file",\r | |
4608 | " -n threadnumber to build with multi-thread",\r | |
4609 | " -t target to build the specified target:",\r | |
4610 | " all, libraries or components",\r | |
3eb9473e | 4611 | NULL\r |
4612 | };\r | |
3e99020d LG |
4613 | for (Index = 0; Str[Index] != NULL; Index++) {\r |
4614 | fprintf (stdout, "%s\n", Str[Index]);\r | |
3eb9473e | 4615 | }\r |
4616 | }\r | |
4617 | \r | |
4618 | /*++\r | |
4619 | \r | |
4620 | Routine Description:\r | |
4621 | \r | |
4622 | Process the [defines] section in the DSC file.\r | |
4623 | \r | |
4624 | Arguments:\r | |
4625 | \r | |
4626 | DscFile - pointer to the DSCFile class that contains the relevant info.\r | |
4627 | \r | |
4628 | Returns:\r | |
4629 | \r | |
4630 | 0 if not necessarily an absolute path\r | |
4631 | 1 otherwise\r | |
4632 | \r | |
4633 | --*/\r | |
4634 | static\r | |
4635 | int\r | |
4636 | ProcessDSCDefinesSection (\r | |
4637 | DSC_FILE *DscFile\r | |
4638 | )\r | |
4639 | {\r | |
4640 | INT8 Line[MAX_LINE_LEN];\r | |
4641 | INT8 Line2[MAX_EXP_LINE_LEN];\r | |
4642 | INT8 *Cptr;\r | |
4643 | SECTION *Sect;\r | |
4644 | \r | |
4645 | //\r | |
4646 | // Look for a [defines] section and process it\r | |
4647 | //\r | |
4648 | Sect = DSCFileFindSection (DscFile, DEFINES_SECTION_NAME);\r | |
4649 | if (Sect == NULL) {\r | |
4650 | return STATUS_ERROR;\r | |
4651 | }\r | |
4652 | //\r | |
4653 | // Read lines while they're valid\r | |
4654 | //\r | |
4655 | while (DSCFileGetLine (DscFile, Line, sizeof (Line)) != NULL) {\r | |
4656 | //\r | |
4657 | // Expand symbols on the line\r | |
4658 | //\r | |
4659 | if (ExpandSymbols (Line, Line2, sizeof (Line2), 0)) {\r | |
4660 | return STATUS_ERROR;\r | |
4661 | }\r | |
4662 | //\r | |
4663 | // Strip the line\r | |
4664 | //\r | |
4665 | Cptr = StripLine (Line2);\r | |
4666 | if (*Cptr) {\r | |
4667 | //\r | |
4668 | // Make the assignment\r | |
4669 | //\r | |
4670 | AddSymbol (Line2, NULL, SYM_OVERWRITE | SYM_GLOBAL);\r | |
4671 | }\r | |
4672 | }\r | |
4673 | \r | |
4674 | return STATUS_SUCCESS;\r | |
4675 | }\r | |
4676 | \r | |
4677 | int\r | |
4678 | IsAbsolutePath (\r | |
4679 | char *FileName\r | |
4680 | )\r | |
4681 | /*++\r | |
4682 | \r | |
4683 | Routine Description:\r | |
4684 | \r | |
4685 | Determine if a given filename contains the full path information.\r | |
4686 | \r | |
4687 | Arguments:\r | |
4688 | \r | |
4689 | FileName - the name of the file, with symbol expanded.\r | |
4690 | \r | |
4691 | Returns:\r | |
4692 | \r | |
4693 | 0 if not necessarily an absolute path\r | |
4694 | 1 otherwise\r | |
4695 | \r | |
4696 | --*/\r | |
4697 | {\r | |
4698 | //\r | |
4699 | // If the first character is a-z, and the second character is a colon, then\r | |
4700 | // it is an absolute path.\r | |
4701 | //\r | |
4702 | if (isalpha (FileName[0]) && (FileName[1] == ':')) {\r | |
4703 | return 1;\r | |
4704 | }\r | |
4705 | \r | |
4706 | return 0;\r | |
4707 | }\r | |
4708 | \r | |
4709 | SMART_FILE *\r | |
4710 | SmartOpen (\r | |
4711 | char *FileName\r | |
4712 | )\r | |
4713 | {\r | |
4714 | SMART_FILE *SmartFile;\r | |
4715 | FILE *Fptr;\r | |
4716 | int FileSize;\r | |
4717 | \r | |
4718 | SmartFile = malloc (sizeof (SMART_FILE));\r | |
4719 | if (SmartFile == NULL) { \r | |
4720 | return NULL;\r | |
4721 | }\r | |
4722 | memset (SmartFile, 0, sizeof (SMART_FILE));\r | |
4723 | \r | |
4724 | SmartFile->FileName = malloc (strlen (FileName) + 1);\r | |
4725 | if (SmartFile->FileName == NULL){\r | |
4726 | SmartFree (SmartFile); \r | |
4727 | return NULL;\r | |
4728 | }\r | |
4729 | strcpy (SmartFile->FileName, FileName);\r | |
4730 | \r | |
4731 | if ((Fptr = fopen (FileName, "r")) != NULL) {\r | |
4732 | fseek (Fptr, 0, SEEK_END);\r | |
4733 | FileSize = ftell (Fptr);\r | |
4734 | fseek (Fptr, 0, SEEK_SET);\r | |
4735 | SmartFile->FileContent = malloc (FileSize + 1);\r | |
4736 | if (SmartFile->FileContent != NULL) {\r | |
4737 | memset (SmartFile->FileContent, 0, FileSize + 1);\r | |
4738 | //\r | |
60d8f1f8 | 4739 | // Usually FileLength < FileSize, because in text mode, carriage return-linefeed\r |
3eb9473e | 4740 | // combinations are translated into single linefeeds on input\r |
4741 | // \r | |
4742 | SmartFile->FileLength = fread (SmartFile->FileContent, sizeof(char), FileSize, Fptr);\r | |
4743 | }\r | |
4744 | fclose (Fptr);\r | |
4745 | }\r | |
4746 | \r | |
4747 | //\r | |
4748 | // No previous output file content, re-create the file\r | |
4749 | //\r | |
4750 | if (SmartFile->FileContent == NULL) {\r | |
4751 | if ((SmartFile->FilePtr = fopen (FileName, "w")) == NULL) {\r | |
4752 | SmartFree (SmartFile);\r | |
4753 | return NULL;\r | |
4754 | } \r | |
4755 | }\r | |
4756 | \r | |
4757 | return SmartFile;\r | |
4758 | }\r | |
4759 | \r | |
4760 | int\r | |
4761 | SmartWrite (\r | |
4762 | SMART_FILE *SmartFile,\r | |
4763 | char *String\r | |
4764 | )\r | |
4765 | {\r | |
4766 | int StrLen;\r | |
4767 | \r | |
4768 | if (SmartFile->FilePtr != NULL) {\r | |
4769 | return fprintf (SmartFile->FilePtr, "%s", String);\r | |
4770 | } else {\r | |
4771 | StrLen = strlen (String);\r | |
4772 | if ((StrLen > SmartFile->FileLength - SmartFile->FilePosition) || \r | |
4773 | (_strnicmp (&SmartFile->FileContent[SmartFile->FilePosition], String, StrLen) != 0)) {\r | |
4774 | //\r | |
4775 | // file changed, need to re-create.\r | |
4776 | //\r | |
4777 | if ((SmartFile->FilePtr = fopen (SmartFile->FileName, "w")) == NULL) {\r | |
4778 | Error (NULL, 0, 0, SmartFile->FileName, "could not open file for writing when SmartWrite");\r | |
4779 | return -1;\r | |
4780 | } else {\r | |
4781 | SmartFile->FileContent[SmartFile->FilePosition] = 0;\r | |
4782 | fprintf (SmartFile->FilePtr, "%s%s", SmartFile->FileContent, String);\r | |
4783 | return StrLen;\r | |
4784 | } \r | |
4785 | } else {\r | |
4786 | SmartFile->FilePosition += StrLen;\r | |
4787 | return StrLen;\r | |
4788 | }\r | |
4789 | }\r | |
4790 | }\r | |
4791 | \r | |
4792 | void\r | |
4793 | SmartClose (\r | |
4794 | SMART_FILE *SmartFile\r | |
4795 | )\r | |
4796 | {\r | |
4797 | if ((SmartFile->FilePtr == NULL) && (SmartFile->FilePosition < SmartFile->FileLength)) {\r | |
4798 | //\r | |
4799 | // The new file is smaller than before, re-create it.\r | |
4800 | //\r | |
4801 | if ((SmartFile->FilePtr = fopen (SmartFile->FileName, "w")) == NULL) {\r | |
4802 | Error (NULL, 0, 0, SmartFile->FileName, "could not open file for writing when SmartClose");\r | |
4803 | } else {\r | |
4804 | SmartFile->FileContent[SmartFile->FilePosition] = 0;\r | |
4805 | fprintf (SmartFile->FilePtr, "%s", SmartFile->FileContent);\r | |
4806 | }\r | |
4807 | }\r | |
4808 | \r | |
4809 | SmartFree(SmartFile);\r | |
4810 | }\r | |
4811 | \r | |
4812 | static\r | |
4813 | void\r | |
4814 | SmartFree (\r | |
4815 | SMART_FILE *SmartFile\r | |
4816 | )\r | |
4817 | {\r | |
4818 | if (SmartFile == NULL) {\r | |
4819 | return;\r | |
4820 | }\r | |
4821 | \r | |
4822 | if (SmartFile->FileName != NULL ) {\r | |
4823 | free (SmartFile->FileName);\r | |
4824 | }\r | |
4825 | \r | |
4826 | if (SmartFile->FileContent != NULL ) {\r | |
4827 | free (SmartFile->FileContent);\r | |
4828 | }\r | |
4829 | \r | |
4830 | if (SmartFile->FilePtr != NULL ) {\r | |
4831 | fclose (SmartFile->FilePtr);\r | |
4832 | } \r | |
4833 | \r | |
4834 | free (SmartFile);\r | |
4835 | \r | |
4836 | return;\r | |
4837 | }\r | |
4838 | \r | |
4839 | static \r | |
4840 | int\r | |
4841 | AddModuleName (\r | |
4842 | SYMBOL **SymbolList,\r | |
4843 | INT8 *ModuleName,\r | |
4844 | INT8 *InfName\r | |
4845 | )\r | |
4846 | /*++\r | |
4847 | \r | |
4848 | Routine Description:\r | |
4849 | \r | |
4850 | Add module name in the global module list. \r | |
4851 | For the same module names, it is only added once.\r | |
4852 | \r | |
4853 | Arguments:\r | |
4854 | SymbolList : add name into this list\r | |
4855 | ModuleName : point to one module name char string.\r | |
4856 | InfName : point to this module inf file name with path.\r | |
4857 | \r | |
4858 | Returns:\r | |
4859 | \r | |
4860 | 0 : Successfully add input name into the global list.\r | |
4861 | other value : allocate memory failed.\r | |
4862 | \r | |
4863 | --*/\r | |
4864 | {\r | |
4865 | SYMBOL *CurrentSymbol;\r | |
4866 | SYMBOL *LastSymbol;\r | |
4867 | \r | |
4868 | //\r | |
4869 | // Get the global module list.\r | |
4870 | //\r | |
4871 | CurrentSymbol = *SymbolList;\r | |
4872 | LastSymbol = *SymbolList;\r | |
4873 | \r | |
4874 | //\r | |
4875 | // Search whether this module name has been added into the global list.\r | |
4876 | //\r | |
4877 | while (CurrentSymbol != NULL) {\r | |
4878 | if (_stricmp (CurrentSymbol->Name, ModuleName) == 0) {\r | |
4879 | if ((CurrentSymbol->Value == NULL) && (InfName == NULL)) {\r | |
4880 | break;\r | |
4881 | } else if ((CurrentSymbol->Value != NULL) && (InfName != NULL) && \\r | |
4882 | (_stricmp (CurrentSymbol->Value, InfName) == 0)) {\r | |
4883 | break;\r | |
4884 | }\r | |
4885 | }\r | |
4886 | LastSymbol = CurrentSymbol;\r | |
4887 | CurrentSymbol = CurrentSymbol->Next;\r | |
4888 | }\r | |
4889 | \r | |
4890 | //\r | |
4891 | // Add new module name in list.\r | |
4892 | //\r | |
4893 | if (CurrentSymbol == NULL) {\r | |
4894 | CurrentSymbol = (SYMBOL *) malloc (sizeof (SYMBOL));\r | |
4895 | if (CurrentSymbol == NULL) {\r | |
4896 | Error (NULL, 0, 0, NULL, "failed to allocate memory");\r | |
4897 | return -1;\r | |
4898 | }\r | |
4899 | memset ((INT8 *) CurrentSymbol, 0, sizeof (SYMBOL));\r | |
4900 | \r | |
4901 | if (ModuleName != NULL) {\r | |
4902 | CurrentSymbol->Name = (INT8 *) malloc (strlen (ModuleName) + 1);\r | |
4903 | strcpy (CurrentSymbol->Name, ModuleName);\r | |
4904 | }\r | |
4905 | \r | |
4906 | if (InfName != NULL) {\r | |
4907 | CurrentSymbol->Value = (INT8 *) malloc (strlen (InfName) + 1);\r | |
4908 | strcpy (CurrentSymbol->Value, InfName);\r | |
4909 | }\r | |
4910 | \r | |
4911 | if (LastSymbol == NULL) { \r | |
4912 | *SymbolList = CurrentSymbol;\r | |
4913 | } else {\r | |
4914 | LastSymbol->Next = CurrentSymbol;\r | |
4915 | }\r | |
4916 | }\r | |
4917 | \r | |
4918 | return 0;\r | |
4919 | }\r | |
4920 | \r | |
95d675b5 | 4921 | \r |
4922 | static \r | |
4923 | void\r | |
4924 | ReplaceSlash (\r | |
4925 | INT8 *Path\r | |
4926 | )\r | |
4927 | /*++\r | |
4928 | \r | |
4929 | Routine Description:\r | |
4930 | \r | |
4931 | Replace '/' with '\\'\r | |
4932 | \r | |
4933 | Returns:\r | |
4934 | \r | |
4935 | --*/\r | |
4936 | {\r | |
4937 | while (*Path) {\r | |
4938 | if (*Path == '/') {\r | |
4939 | *Path = '\\';\r | |
4940 | }\r | |
4941 | Path++;\r | |
4942 | }\r | |
b4e547b6 | 4943 | }\r |