echo [WMC] commands
[reactos.git] / reactos / tools / rbuild / backend / mingw / modulehandler.cpp
1 #include "../../pch.h"
2 #include <assert.h>
3
4 #include "../../rbuild.h"
5 #include "mingw.h"
6 #include "modulehandler.h"
7
8 using std::string;
9 using std::vector;
10
11 #define CLEAN_FILE(f) clean_files.push_back ( f ); /*if ( module.name == "crt" ) printf ( "%s(%i): clean: %s\n", __FILE__, __LINE__, f.c_str() )*/
12
13 FILE*
14 MingwModuleHandler::fMakefile = NULL;
15 bool
16 MingwModuleHandler::use_pch = false;
17
18 string
19 ReplaceExtension ( const string& filename,
20 const string& newExtension )
21 {
22 size_t index = filename.find_last_of ( '/' );
23 if ( index == string::npos )
24 index = 0;
25 size_t index2 = filename.find_last_of ( '\\' );
26 if ( index2 != string::npos && index2 > index )
27 index = index2;
28 string tmp = filename.substr( index /*, filename.size() - index*/ );
29 size_t ext_index = tmp.find_last_of( '.' );
30 if ( ext_index != string::npos )
31 return filename.substr ( 0, index + ext_index ) + newExtension;
32 return filename + newExtension;
33 }
34
35 string
36 PrefixFilename (
37 const string& filename,
38 const string& prefix )
39 {
40 if ( !prefix.length() )
41 return filename;
42 string out;
43 const char* pfilename = filename.c_str();
44 const char* p1 = strrchr ( pfilename, '/' );
45 const char* p2 = strrchr ( pfilename, '\\' );
46 if ( p1 || p2 )
47 {
48 if ( p2 > p1 )
49 p1 = p2;
50 out += string(pfilename,p1-pfilename) + CSEP;
51 pfilename = p1 + 1;
52 }
53 out += prefix + pfilename;
54 return out;
55 }
56
57 string v2s ( const vector<string>& v, int wrap_at )
58 {
59 if ( !v.size() )
60 return "";
61 string s;
62 int wrap_count = 0;
63 for ( size_t i = 0; i < v.size(); i++ )
64 {
65 if ( !v[i].size() )
66 continue;
67 if ( wrap_at > 0 && wrap_count++ == wrap_at )
68 s += " \\\n\t\t";
69 else if ( s.size() )
70 s += " ";
71 s += v[i];
72 }
73 return s;
74 }
75
76 MingwModuleHandler::MingwModuleHandler ( ModuleType moduletype,
77 MingwBackend* backend_ )
78 : backend ( backend_ )
79 {
80 }
81
82 MingwModuleHandler::~MingwModuleHandler()
83 {
84 }
85
86 const string &
87 MingwModuleHandler::PassThruCacheDirectory ( const string &file )
88 {
89 backend->CreateDirectoryTargetIfNotYetCreated ( GetDirectory ( file ) );
90 return file;
91 }
92
93 void
94 MingwModuleHandler::SetMakefile ( FILE* f )
95 {
96 fMakefile = f;
97 }
98
99 void
100 MingwModuleHandler::SetUsePch ( bool b )
101 {
102 use_pch = b;
103 }
104
105 MingwModuleHandler*
106 MingwModuleHandler::InstanciateHandler ( const string& location,
107 ModuleType moduletype,
108 MingwBackend* backend )
109 {
110 MingwModuleHandler* handler;
111 switch ( moduletype )
112 {
113 case BuildTool:
114 handler = new MingwBuildToolModuleHandler ( backend );
115 break;
116 case StaticLibrary:
117 handler = new MingwStaticLibraryModuleHandler ( backend );
118 break;
119 case ObjectLibrary:
120 handler = new MingwObjectLibraryModuleHandler ( backend );
121 break;
122 case Kernel:
123 handler = new MingwKernelModuleHandler ( backend );
124 break;
125 case NativeCUI:
126 handler = new MingwNativeCUIModuleHandler ( backend );
127 break;
128 case Win32CUI:
129 handler = new MingwWin32CUIModuleHandler ( backend );
130 break;
131 case Win32GUI:
132 handler = new MingwWin32GUIModuleHandler ( backend );
133 break;
134 case KernelModeDLL:
135 handler = new MingwKernelModeDLLModuleHandler ( backend );
136 break;
137 case NativeDLL:
138 handler = new MingwNativeDLLModuleHandler ( backend );
139 break;
140 case Win32DLL:
141 handler = new MingwWin32DLLModuleHandler ( backend );
142 break;
143 case KernelModeDriver:
144 handler = new MingwKernelModeDriverModuleHandler ( backend );
145 break;
146 case BootLoader:
147 handler = new MingwBootLoaderModuleHandler ( backend );
148 break;
149 case BootSector:
150 handler = new MingwBootSectorModuleHandler ( backend );
151 break;
152 case Iso:
153 handler = new MingwIsoModuleHandler ( backend );
154 break;
155 }
156 return handler;
157 }
158
159 string
160 MingwModuleHandler::GetWorkingDirectory () const
161 {
162 return ".";
163 }
164
165 string
166 MingwModuleHandler::GetBasename ( const string& filename ) const
167 {
168 size_t index = filename.find_last_of ( '.' );
169 if ( index != string::npos )
170 return filename.substr ( 0, index );
171 return "";
172 }
173
174 string
175 MingwModuleHandler::GetActualSourceFilename ( const string& filename ) const
176 {
177 string extension = GetExtension ( filename );
178 if ( extension == ".spec" || extension == "SPEC" )
179 {
180 string basename = GetBasename ( filename );
181 return basename + ".stubs.c";
182 }
183 else
184 return filename;
185 }
186
187 string
188 MingwModuleHandler::GetModuleArchiveFilename ( const Module& module ) const
189 {
190 return ReplaceExtension ( FixupTargetFilename ( module.GetPath () ),
191 ".a" );
192 }
193
194 bool
195 MingwModuleHandler::IsGeneratedFile ( const File& file ) const
196 {
197 string extension = GetExtension ( file.name );
198 if ( extension == ".spec" || extension == "SPEC" )
199 return true;
200 else
201 return false;
202 }
203
204 string
205 MingwModuleHandler::GetImportLibraryDependency ( const Module& importedModule )
206 {
207 if ( importedModule.type == ObjectLibrary )
208 return GetObjectsMacro ( importedModule );
209 else
210 return PassThruCacheDirectory ( FixupTargetFilename ( importedModule.GetDependencyPath () ) );
211 }
212
213 string
214 MingwModuleHandler::GetModuleDependencies ( const Module& module )
215 {
216 if ( module.dependencies.size () == 0 )
217 return "";
218
219 string dependencies ( "" );
220 for ( size_t i = 0; i < module.dependencies.size (); i++ )
221 {
222 if ( dependencies.size () > 0 )
223 dependencies += " ";
224 const Dependency* dependency = module.dependencies[i];
225 const Module* dependencyModule = dependency->dependencyModule;
226 dependencies += dependencyModule->GetTargets ();
227 }
228 string definitionDependencies = GetDefinitionDependencies ( module );
229 if ( dependencies.length () > 0 && definitionDependencies.length () > 0 )
230 dependencies += " " + definitionDependencies;
231 else if ( definitionDependencies.length () > 0 )
232 dependencies = definitionDependencies;
233 return dependencies;
234 }
235
236 string
237 MingwModuleHandler::GetSourceFilenames ( const Module& module,
238 bool includeGeneratedFiles ) const
239 {
240 size_t i;
241
242 string sourceFilenames ( "" );
243 const vector<File*>& files = module.non_if_data.files;
244 for ( i = 0; i < files.size (); i++ )
245 {
246 if ( includeGeneratedFiles || !IsGeneratedFile ( *files[i] ) )
247 sourceFilenames += " " + GetActualSourceFilename ( files[i]->name );
248 }
249 // intentionally make a copy so that we can append more work in
250 // the middle of processing without having to go recursive
251 vector<If*> v = module.non_if_data.ifs;
252 for ( i = 0; i < v.size (); i++ )
253 {
254 size_t j;
255 If& rIf = *v[i];
256 // check for sub-ifs to add to list
257 const vector<If*>& ifs = rIf.data.ifs;
258 for ( j = 0; j < ifs.size (); j++ )
259 v.push_back ( ifs[j] );
260 const vector<File*>& files = rIf.data.files;
261 for ( j = 0; j < files.size (); j++ )
262 {
263 File& file = *files[j];
264 if ( includeGeneratedFiles || !IsGeneratedFile ( file ) )
265 sourceFilenames += " " + GetActualSourceFilename ( file.name );
266 }
267 }
268 return sourceFilenames;
269 }
270
271 string
272 MingwModuleHandler::GetSourceFilenames ( const Module& module ) const
273 {
274 return GetSourceFilenames ( module,
275 true );
276 }
277
278 string
279 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles ( const Module& module ) const
280 {
281 return GetSourceFilenames ( module,
282 false );
283 }
284
285 static string
286 GetObjectFilename ( const Module& module, const string& sourceFilename )
287 {
288 string newExtension;
289 string extension = GetExtension ( sourceFilename );
290 if ( extension == ".rc" || extension == ".RC" )
291 newExtension = ".coff";
292 else if ( extension == ".spec" || extension == ".SPEC" )
293 newExtension = ".stubs.o";
294 else
295 newExtension = ".o";
296 return FixupTargetFilename (
297 ReplaceExtension (
298 PrefixFilename(sourceFilename,module.prefix),
299 newExtension ) );
300 }
301
302 void
303 MingwModuleHandler::GenerateCleanTarget (
304 const Module& module,
305 const string_list& clean_files ) const
306 {
307 if ( 0 == clean_files.size() )
308 return;
309 fprintf ( fMakefile, ".PHONY: %s_clean\n", module.name.c_str() );
310 fprintf ( fMakefile, "%s_clean:\n\t-@$(rm)", module.name.c_str() );
311 for ( size_t i = 0; i < clean_files.size(); i++ )
312 {
313 if ( 9==((i+1)%10) )
314 fprintf ( fMakefile, " 2>$(NUL)\n\t-@$(rm)" );
315 fprintf ( fMakefile, " %s", clean_files[i].c_str() );
316 }
317 fprintf ( fMakefile, " 2>$(NUL)\n" );
318 fprintf ( fMakefile, "clean: %s_clean\n\n", module.name.c_str() );
319 }
320
321 string
322 MingwModuleHandler::GetObjectFilenames ( const Module& module )
323 {
324 const vector<File*>& files = module.non_if_data.files;
325 if ( files.size () == 0 )
326 return "";
327
328 string objectFilenames ( "" );
329 for ( size_t i = 0; i < files.size (); i++ )
330 {
331 if ( objectFilenames.size () > 0 )
332 objectFilenames += " ";
333 objectFilenames += PassThruCacheDirectory (
334 GetObjectFilename ( module, files[i]->name ) );
335 }
336 return objectFilenames;
337 }
338
339 string
340 MingwModuleHandler::GenerateGccDefineParametersFromVector ( const vector<Define*>& defines ) const
341 {
342 string parameters;
343 for ( size_t i = 0; i < defines.size (); i++ )
344 {
345 Define& define = *defines[i];
346 if (parameters.length () > 0)
347 parameters += " ";
348 parameters += "-D";
349 parameters += define.name;
350 if (define.value.length () > 0)
351 {
352 parameters += "=";
353 parameters += define.value;
354 }
355 }
356 return parameters;
357 }
358
359 string
360 MingwModuleHandler::GenerateGccDefineParameters ( const Module& module ) const
361 {
362 string parameters = GenerateGccDefineParametersFromVector ( module.project.non_if_data.defines );
363 string s = GenerateGccDefineParametersFromVector ( module.non_if_data.defines );
364 if ( s.length () > 0 )
365 {
366 parameters += " ";
367 parameters += s;
368 }
369 return parameters;
370 }
371
372 string
373 MingwModuleHandler::ConcatenatePaths ( const string& path1,
374 const string& path2 ) const
375 {
376 if ( ( path1.length () == 0 ) || ( path1 == "." ) || ( path1 == "./" ) )
377 return path2;
378 if ( path1[path1.length ()] == CSEP )
379 return path1 + path2;
380 else
381 return path1 + CSEP + path2;
382 }
383
384 string
385 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector<Include*>& includes ) const
386 {
387 string parameters;
388 for ( size_t i = 0; i < includes.size (); i++ )
389 {
390 Include& include = *includes[i];
391 if ( parameters.length () > 0 )
392 parameters += " ";
393 parameters += "-I" + include.directory;
394 }
395 return parameters;
396 }
397
398 string
399 MingwModuleHandler::GenerateGccIncludeParameters ( const Module& module ) const
400 {
401 string parameters = GenerateGccIncludeParametersFromVector ( module.non_if_data.includes );
402 string s = GenerateGccIncludeParametersFromVector ( module.project.non_if_data.includes );
403 if ( s.length () > 0 )
404 {
405 parameters += " ";
406 parameters += s;
407 }
408 return parameters;
409 }
410
411
412 string
413 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector<CompilerFlag*>& compilerFlags ) const
414 {
415 string parameters;
416 for ( size_t i = 0; i < compilerFlags.size (); i++ )
417 {
418 CompilerFlag& compilerFlag = *compilerFlags[i];
419 if ( parameters.length () > 0 )
420 parameters += " ";
421 parameters += compilerFlag.flag;
422 }
423 return parameters;
424 }
425
426 string
427 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector<LinkerFlag*>& linkerFlags ) const
428 {
429 string parameters;
430 for ( size_t i = 0; i < linkerFlags.size (); i++ )
431 {
432 LinkerFlag& linkerFlag = *linkerFlags[i];
433 if ( parameters.length () > 0 )
434 parameters += " ";
435 parameters += linkerFlag.flag;
436 }
437 return parameters;
438 }
439
440 string
441 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
442 const vector<Library*>& libraries )
443 {
444 string dependencies ( "" );
445 int wrap_count = 0;
446 for ( size_t i = 0; i < libraries.size (); i++ )
447 {
448 if ( wrap_count++ == 5 )
449 dependencies += " \\\n\t\t", wrap_count = 0;
450 else if ( dependencies.size () > 0 )
451 dependencies += " ";
452 dependencies += GetImportLibraryDependency ( *libraries[i]->imported_module );
453 }
454 return dependencies;
455 }
456
457 string
458 MingwModuleHandler::GenerateLinkerParameters ( const Module& module ) const
459 {
460 return GenerateLinkerParametersFromVector ( module.linkerFlags );
461 }
462
463 void
464 MingwModuleHandler::GenerateMacro (
465 const char* assignmentOperation,
466 const string& macro,
467 const IfableData& data,
468 const vector<CompilerFlag*>* compilerFlags )
469 {
470 size_t i;
471
472 fprintf (
473 fMakefile,
474 "%s %s",
475 macro.c_str(),
476 assignmentOperation );
477
478 if ( compilerFlags != NULL )
479 {
480 string compilerParameters = GenerateCompilerParametersFromVector ( *compilerFlags );
481 if ( compilerParameters.size () > 0 )
482 {
483 fprintf (
484 fMakefile,
485 " %s",
486 compilerParameters.c_str () );
487 }
488 }
489
490 for ( i = 0; i < data.includes.size(); i++ )
491 {
492 fprintf (
493 fMakefile,
494 " -I%s",
495 data.includes[i]->directory.c_str() );
496 }
497 for ( i = 0; i < data.defines.size(); i++ )
498 {
499 Define& d = *data.defines[i];
500 fprintf (
501 fMakefile,
502 " -D%s",
503 d.name.c_str() );
504 if ( d.value.size() )
505 fprintf (
506 fMakefile,
507 "=%s",
508 d.value.c_str() );
509 }
510 fprintf ( fMakefile, "\n" );
511 }
512
513 void
514 MingwModuleHandler::GenerateMacros (
515 const Module& module,
516 const char* assignmentOperation,
517 const IfableData& data,
518 const vector<CompilerFlag*>* compilerFlags,
519 const vector<LinkerFlag*>* linkerFlags,
520 const string& cflags_macro,
521 const string& nasmflags_macro,
522 const string& windresflags_macro,
523 const string& linkerflags_macro,
524 const string& objs_macro,
525 const string& libs_macro,
526 const string& linkdeps_macro )
527 {
528 size_t i;
529
530 if ( data.includes.size () > 0 || data.defines.size () > 0 )
531 {
532 GenerateMacro ( assignmentOperation,
533 cflags_macro,
534 data,
535 compilerFlags );
536 GenerateMacro ( assignmentOperation,
537 windresflags_macro,
538 data,
539 compilerFlags );
540 }
541
542 if ( linkerFlags != NULL )
543 {
544 string linkerParameters = GenerateLinkerParametersFromVector ( *linkerFlags );
545 if ( linkerParameters.size () > 0 )
546 {
547 fprintf (
548 fMakefile,
549 "%s %s %s\n",
550 linkerflags_macro.c_str (),
551 assignmentOperation,
552 linkerParameters.c_str() );
553 }
554 }
555
556 if ( data.libraries.size () > 0 )
557 {
558 string deps = GenerateImportLibraryDependenciesFromVector ( data.libraries );
559 if ( deps.size () > 0 )
560 {
561 fprintf (
562 fMakefile,
563 "%s %s %s\n",
564 libs_macro.c_str(),
565 assignmentOperation,
566 deps.c_str() );
567 }
568 }
569
570 const vector<File*>& files = data.files;
571 if ( files.size () > 0 )
572 {
573 for ( i = 0; i < files.size (); i++ )
574 {
575 File& file = *files[i];
576 if ( file.first )
577 {
578 fprintf ( fMakefile,
579 "%s := %s $(%s)\n",
580 objs_macro.c_str(),
581 PassThruCacheDirectory (
582 GetObjectFilename ( module, file.name ) ).c_str (),
583 objs_macro.c_str() );
584 }
585 }
586 fprintf (
587 fMakefile,
588 "%s %s",
589 objs_macro.c_str (),
590 assignmentOperation );
591 for ( i = 0; i < files.size(); i++ )
592 {
593 File& file = *files[i];
594 if ( !file.first )
595 {
596 fprintf (
597 fMakefile,
598 "%s%s",
599 ( i%10 == 9 ? "\\\n\t" : " " ),
600 PassThruCacheDirectory (
601 GetObjectFilename ( module, file.name ) ).c_str () );
602 }
603 }
604 fprintf ( fMakefile, "\n" );
605 }
606
607 const vector<If*>& ifs = data.ifs;
608 for ( i = 0; i < ifs.size(); i++ )
609 {
610 If& rIf = *ifs[i];
611 if ( rIf.data.defines.size()
612 || rIf.data.includes.size()
613 || rIf.data.libraries.size()
614 || rIf.data.files.size()
615 || rIf.data.ifs.size() )
616 {
617 fprintf (
618 fMakefile,
619 "ifeq (\"$(%s)\",\"%s\")\n",
620 rIf.property.c_str(),
621 rIf.value.c_str() );
622 GenerateMacros (
623 module,
624 "+=",
625 rIf.data,
626 NULL,
627 NULL,
628 cflags_macro,
629 nasmflags_macro,
630 windresflags_macro,
631 linkerflags_macro,
632 objs_macro,
633 libs_macro,
634 linkdeps_macro );
635 fprintf (
636 fMakefile,
637 "endif\n\n" );
638 }
639 }
640 }
641
642 void
643 MingwModuleHandler::GenerateMacros (
644 const Module& module,
645 const string& cflags_macro,
646 const string& nasmflags_macro,
647 const string& windresflags_macro,
648 const string& linkerflags_macro,
649 const string& objs_macro,
650 const string& libs_macro,
651 const string& linkdeps_macro )
652 {
653 GenerateMacros (
654 module,
655 "=",
656 module.non_if_data,
657 &module.compilerFlags,
658 &module.linkerFlags,
659 cflags_macro,
660 nasmflags_macro,
661 windresflags_macro,
662 linkerflags_macro,
663 objs_macro,
664 libs_macro,
665 linkdeps_macro );
666
667 if ( module.importLibrary )
668 {
669 string s;
670 const vector<File*>& files = module.non_if_data.files;
671 for ( size_t i = 0; i < files.size (); i++ )
672 {
673 File& file = *files[i];
674 string extension = GetExtension ( file.name );
675 if ( extension == ".spec" || extension == ".SPEC" )
676 {
677 if ( s.length () > 0 )
678 s += " ";
679 s += GetSpecObjectDependencies ( file.name );
680 }
681 }
682 if ( s.length () > 0 )
683 {
684 fprintf (
685 fMakefile,
686 "%s += %s\n",
687 linkdeps_macro.c_str(),
688 s.c_str() );
689 }
690 }
691
692 fprintf (
693 fMakefile,
694 "%s += $(PROJECT_CFLAGS)\n",
695 cflags_macro.c_str () );
696
697 fprintf (
698 fMakefile,
699 "%s += $(PROJECT_RCFLAGS)\n",
700 windresflags_macro.c_str () );
701
702 fprintf (
703 fMakefile,
704 "%s_LFLAGS += $(PROJECT_LFLAGS)\n",
705 module.name.c_str () );
706
707 fprintf (
708 fMakefile,
709 "%s += $(%s)",
710 linkdeps_macro.c_str (),
711 libs_macro.c_str () );
712
713 fprintf ( fMakefile, "\n" );
714 }
715
716 void
717 MingwModuleHandler::GenerateGccCommand ( const Module& module,
718 const string& sourceFilename,
719 const string& cc,
720 const string& cflagsMacro )
721 {
722 string deps = sourceFilename;
723 if ( module.pch && use_pch )
724 deps += " " + module.pch->header + ".gch";
725 string objectFilename = PassThruCacheDirectory (
726 GetObjectFilename ( module, sourceFilename ) );
727 fprintf ( fMakefile,
728 "%s: %s\n",
729 objectFilename.c_str (),
730 deps.c_str () );
731 fprintf ( fMakefile, "\t$(ECHO_CC)\n" );
732 fprintf ( fMakefile,
733 "\t%s -c %s -o %s %s\n",
734 cc.c_str (),
735 sourceFilename.c_str (),
736 objectFilename.c_str (),
737 cflagsMacro.c_str () );
738 }
739
740 void
741 MingwModuleHandler::GenerateGccAssemblerCommand ( const Module& module,
742 const string& sourceFilename,
743 const string& cc,
744 const string& cflagsMacro )
745 {
746 string objectFilename = PassThruCacheDirectory (
747 GetObjectFilename ( module, sourceFilename ) );
748 fprintf ( fMakefile,
749 "%s: %s %s\n",
750 objectFilename.c_str (),
751 objectFilename.c_str (),
752 sourceFilename.c_str () );
753 fprintf ( fMakefile, "\t$(ECHO_GAS)\n" );
754 fprintf ( fMakefile,
755 "\t%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",
756 cc.c_str (),
757 sourceFilename.c_str (),
758 objectFilename.c_str (),
759 cflagsMacro.c_str () );
760 }
761
762 void
763 MingwModuleHandler::GenerateNasmCommand ( const Module& module,
764 const string& sourceFilename,
765 const string& nasmflagsMacro )
766 {
767 string objectFilename = PassThruCacheDirectory (
768 GetObjectFilename ( module, sourceFilename ) );
769 fprintf ( fMakefile,
770 "%s: %s %s\n",
771 objectFilename.c_str (),
772 objectFilename.c_str (),
773 sourceFilename.c_str () );
774 fprintf ( fMakefile, "\t$(ECHO_NASM)\n" );
775 fprintf ( fMakefile,
776 "\t%s -f win32 %s -o %s %s\n",
777 "$(Q)nasm",
778 sourceFilename.c_str (),
779 objectFilename.c_str (),
780 nasmflagsMacro.c_str () );
781 }
782
783 void
784 MingwModuleHandler::GenerateWindresCommand ( const Module& module,
785 const string& sourceFilename,
786 const string& windresflagsMacro )
787 {
788 string objectFilename = PassThruCacheDirectory (
789 GetObjectFilename ( module, sourceFilename ) );
790 string rciFilename = ReplaceExtension ( sourceFilename,
791 ".rci" );
792 string resFilename = ReplaceExtension ( sourceFilename,
793 ".res" );
794 fprintf ( fMakefile,
795 "%s: %s %s $(WRC_TARGET)\n",
796 objectFilename.c_str (),
797 objectFilename.c_str (),
798 sourceFilename.c_str () );
799 fprintf ( fMakefile, "\t$(ECHO_WRC)\n" );
800 fprintf ( fMakefile,
801 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
802 windresflagsMacro.c_str (),
803 sourceFilename.c_str (),
804 rciFilename.c_str () );
805 fprintf ( fMakefile,
806 "\t${wrc} ${%s} %s %s\n",
807 windresflagsMacro.c_str (),
808 rciFilename.c_str (),
809 resFilename.c_str () );
810 fprintf ( fMakefile,
811 "\t-@${rm} %s\n",
812 rciFilename.c_str () );
813 fprintf ( fMakefile,
814 "\t${windres} %s -o %s\n",
815 resFilename.c_str (),
816 objectFilename.c_str () );
817 fprintf ( fMakefile,
818 "\t-@${rm} %s\n",
819 resFilename.c_str () );
820 }
821
822 void
823 MingwModuleHandler::GenerateWinebuildCommands (
824 const Module& module,
825 const string& sourceFilename,
826 string_list& clean_files ) const
827 {
828 string basename = GetBasename ( sourceFilename );
829
830 string def_file = basename + ".spec.def";
831 CLEAN_FILE ( def_file );
832
833 string stub_file = basename + ".stubs.c";
834 CLEAN_FILE ( stub_file );
835
836 fprintf ( fMakefile,
837 "%s: %s $(WINEBUILD_TARGET)\n",
838 def_file.c_str (),
839 sourceFilename.c_str () );
840 fprintf ( fMakefile, "\t$(ECHO_WINEBLD)\n" );
841 fprintf ( fMakefile,
842 "\t%s --def=%s -o %s\n",
843 "${winebuild}",
844 sourceFilename.c_str (),
845 def_file.c_str () );
846
847 fprintf ( fMakefile,
848 "%s: %s\n",
849 stub_file.c_str (),
850 sourceFilename.c_str () );
851 fprintf ( fMakefile, "\t$(ECHO_WINEBLD)\n" );
852 fprintf ( fMakefile,
853 "\t%s --pedll=%s -o %s\n",
854 "${winebuild}",
855 sourceFilename.c_str (),
856 stub_file.c_str () );
857 }
858
859 void
860 MingwModuleHandler::GenerateCommands (
861 const Module& module,
862 const string& sourceFilename,
863 const string& cc,
864 const string& cppc,
865 const string& cflagsMacro,
866 const string& nasmflagsMacro,
867 const string& windresflagsMacro,
868 string_list& clean_files )
869 {
870 CLEAN_FILE ( GetObjectFilename(module,sourceFilename) );
871 string extension = GetExtension ( sourceFilename );
872 if ( extension == ".c" || extension == ".C" )
873 {
874 GenerateGccCommand ( module,
875 sourceFilename,
876 cc,
877 cflagsMacro );
878 return;
879 }
880 else if ( extension == ".cc" || extension == ".CC" ||
881 extension == ".cpp" || extension == ".CPP" ||
882 extension == ".cxx" || extension == ".CXX" )
883 {
884 GenerateGccCommand ( module,
885 sourceFilename,
886 cppc,
887 cflagsMacro );
888 return;
889 }
890 else if ( extension == ".s" || extension == ".S" )
891 {
892 GenerateGccAssemblerCommand ( module,
893 sourceFilename,
894 cc,
895 cflagsMacro );
896 return;
897 }
898 else if ( extension == ".asm" || extension == ".ASM" )
899 {
900 GenerateNasmCommand ( module,
901 sourceFilename,
902 nasmflagsMacro );
903 return;
904 }
905 else if ( extension == ".rc" || extension == ".RC" )
906 {
907 GenerateWindresCommand ( module,
908 sourceFilename,
909 windresflagsMacro );
910 return;
911 }
912 else if ( extension == ".spec" || extension == ".SPEC" )
913 {
914 GenerateWinebuildCommands ( module,
915 sourceFilename,
916 clean_files );
917 GenerateGccCommand ( module,
918 GetActualSourceFilename ( sourceFilename ),
919 cc,
920 cflagsMacro );
921 return;
922 }
923
924 throw InvalidOperationException ( __FILE__,
925 __LINE__,
926 "Unsupported filename extension '%s' in file '%s'",
927 extension.c_str (),
928 sourceFilename.c_str () );
929 }
930
931 void
932 MingwModuleHandler::GenerateLinkerCommand (
933 const Module& module,
934 const string& target,
935 const string& dependencies,
936 const string& linker,
937 const string& linkerParameters,
938 const string& objectsMacro,
939 const string& libsMacro,
940 string_list& clean_files ) const
941 {
942 fprintf ( fMakefile,
943 "%s: %s ${RSYM_TARGET}\n",
944 target.c_str (),
945 dependencies.c_str () );
946 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
947 string targetName ( module.GetTargetName () );
948 if ( module.importLibrary != NULL )
949 {
950 static string ros_junk ( "$(ROS_TEMPORARY)" );
951 string base_tmp = ros_junk + module.name + ".base.tmp";
952 CLEAN_FILE ( base_tmp );
953 string junk_tmp = ros_junk + module.name + ".junk.tmp";
954 CLEAN_FILE ( junk_tmp );
955 string temp_exp = ros_junk + module.name + ".temp.exp";
956 CLEAN_FILE ( temp_exp );
957 string def_file = module.GetBasePath () + SSEP + module.importLibrary->definition;
958
959 fprintf ( fMakefile,
960 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
961 linker.c_str (),
962 linkerParameters.c_str (),
963 base_tmp.c_str (),
964 junk_tmp.c_str (),
965 objectsMacro.c_str (),
966 libsMacro.c_str (),
967 GetLinkerMacro ( module ).c_str () );
968
969 fprintf ( fMakefile,
970 "\t-@${rm} %s\n",
971 junk_tmp.c_str () );
972
973 string killAt = module.mangledSymbols ? "" : "--kill-at";
974 fprintf ( fMakefile,
975 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
976 targetName.c_str (),
977 base_tmp.c_str (),
978 def_file.c_str (),
979 temp_exp.c_str (),
980 killAt.c_str () );
981
982 fprintf ( fMakefile,
983 "\t-@${rm} %s\n",
984 base_tmp.c_str () );
985
986 fprintf ( fMakefile,
987 "\t%s %s %s -o %s %s %s %s\n",
988 linker.c_str (),
989 linkerParameters.c_str (),
990 temp_exp.c_str (),
991 target.c_str (),
992 objectsMacro.c_str (),
993 libsMacro.c_str (),
994 GetLinkerMacro ( module ).c_str () );
995
996 fprintf ( fMakefile,
997 "\t-@${rm} %s\n",
998 temp_exp.c_str () );
999 }
1000 else
1001 {
1002 fprintf ( fMakefile,
1003 "\t%s %s -o %s %s %s %s\n",
1004 linker.c_str (),
1005 linkerParameters.c_str (),
1006 target.c_str (),
1007 objectsMacro.c_str (),
1008 libsMacro.c_str (),
1009 GetLinkerMacro ( module ).c_str () );
1010 }
1011
1012 fprintf ( fMakefile, "\t$(ECHO_RSYM)\n" );
1013 fprintf ( fMakefile,
1014 "\t${rsym} %s %s\n\n",
1015 target.c_str (),
1016 target.c_str () );
1017 }
1018
1019 void
1020 MingwModuleHandler::GenerateObjectFileTargets (
1021 const Module& module,
1022 const IfableData& data,
1023 const string& cc,
1024 const string& cppc,
1025 const string& cflagsMacro,
1026 const string& nasmflagsMacro,
1027 const string& windresflagsMacro,
1028 string_list& clean_files )
1029 {
1030 size_t i;
1031
1032 const vector<File*>& files = data.files;
1033 for ( i = 0; i < files.size (); i++ )
1034 {
1035 string sourceFilename = files[i]->name;
1036 GenerateCommands ( module,
1037 sourceFilename,
1038 cc,
1039 cppc,
1040 cflagsMacro,
1041 nasmflagsMacro,
1042 windresflagsMacro,
1043 clean_files );
1044 fprintf ( fMakefile,
1045 "\n" );
1046 }
1047
1048 const vector<If*>& ifs = data.ifs;
1049 for ( i = 0; i < ifs.size(); i++ )
1050 {
1051 GenerateObjectFileTargets ( module,
1052 ifs[i]->data,
1053 cc,
1054 cppc,
1055 cflagsMacro,
1056 nasmflagsMacro,
1057 windresflagsMacro,
1058 clean_files );
1059 }
1060 }
1061
1062 void
1063 MingwModuleHandler::GenerateObjectFileTargets (
1064 const Module& module,
1065 const string& cc,
1066 const string& cppc,
1067 const string& cflagsMacro,
1068 const string& nasmflagsMacro,
1069 const string& windresflagsMacro,
1070 string_list& clean_files )
1071 {
1072 if ( module.pch )
1073 {
1074 const string& pch_file = module.pch->header;
1075 string gch_file = pch_file + ".gch";
1076 CLEAN_FILE(gch_file);
1077 if ( use_pch )
1078 {
1079 fprintf (
1080 fMakefile,
1081 "%s: %s\n",
1082 gch_file.c_str(),
1083 pch_file.c_str() );
1084 fprintf ( fMakefile, "\t$(ECHO_PCH)\n" );
1085 fprintf (
1086 fMakefile,
1087 "\t%s -o %s %s -g %s\n\n",
1088 ( module.cplusplus ? cppc.c_str() : cc.c_str() ),
1089 gch_file.c_str(),
1090 cflagsMacro.c_str(),
1091 pch_file.c_str() );
1092 }
1093 }
1094
1095 GenerateObjectFileTargets ( module,
1096 module.non_if_data,
1097 cc,
1098 cppc,
1099 cflagsMacro,
1100 nasmflagsMacro,
1101 windresflagsMacro,
1102 clean_files );
1103 fprintf ( fMakefile, "\n" );
1104 }
1105
1106 string
1107 MingwModuleHandler::GenerateArchiveTarget ( const Module& module,
1108 const string& ar,
1109 const string& objs_macro ) const
1110 {
1111 string archiveFilename = GetModuleArchiveFilename ( module );
1112
1113 fprintf ( fMakefile,
1114 "%s: %s\n",
1115 archiveFilename.c_str (),
1116 objs_macro.c_str ());
1117
1118 fprintf ( fMakefile, "\t$(ECHO_AR)\n" );
1119
1120 fprintf ( fMakefile,
1121 "\t%s -rc %s %s\n\n",
1122 ar.c_str (),
1123 archiveFilename.c_str (),
1124 objs_macro.c_str ());
1125
1126 return archiveFilename;
1127 }
1128
1129 string
1130 MingwModuleHandler::GetCFlagsMacro ( const Module& module ) const
1131 {
1132 return ssprintf ( "$(%s_CFLAGS)",
1133 module.name.c_str () );
1134 }
1135
1136 string
1137 MingwModuleHandler::GetObjectsMacro ( const Module& module ) const
1138 {
1139 return ssprintf ( "$(%s_OBJS)",
1140 module.name.c_str () );
1141 }
1142
1143 string
1144 MingwModuleHandler::GetLinkingDependenciesMacro ( const Module& module ) const
1145 {
1146 return ssprintf ( "$(%s_LINKDEPS)", module.name.c_str () );
1147 }
1148
1149 string
1150 MingwModuleHandler::GetLibsMacro ( const Module& module ) const
1151 {
1152 return ssprintf ( "$(%s_LIBS)", module.name.c_str () );
1153 }
1154
1155 string
1156 MingwModuleHandler::GetLinkerMacro ( const Module& module ) const
1157 {
1158 return ssprintf ( "$(%s_LFLAGS)",
1159 module.name.c_str () );
1160 }
1161
1162 void
1163 MingwModuleHandler::GenerateMacrosAndTargets (
1164 const Module& module,
1165 const string* cflags,
1166 const string* nasmflags,
1167 string_list& clean_files )
1168 {
1169 string cc = ( module.host == HostTrue ? "${host_gcc}" : "${gcc}" );
1170 string cppc = ( module.host == HostTrue ? "${host_gpp}" : "${gpp}" );
1171 string ar = ( module.host == HostTrue ? "${host_ar}" : "${ar}" );
1172
1173 string cflagsMacro = ssprintf ("%s_CFLAGS", module.name.c_str ());
1174 string nasmflagsMacro = ssprintf ("%s_NASMFLAGS", module.name.c_str ());
1175 string windresflagsMacro = ssprintf ("%s_RCFLAGS", module.name.c_str ());
1176 string linkerFlagsMacro = ssprintf ("%s_LFLAGS", module.name.c_str ());
1177 string objectsMacro = ssprintf ("%s_OBJS", module.name.c_str ());
1178 string libsMacro = ssprintf("%s_LIBS", module.name.c_str ());
1179 string linkDepsMacro = ssprintf ("%s_LINKDEPS", module.name.c_str ());
1180
1181 GenerateMacros ( module,
1182 cflagsMacro,
1183 nasmflagsMacro,
1184 windresflagsMacro,
1185 linkerFlagsMacro,
1186 objectsMacro,
1187 libsMacro,
1188 linkDepsMacro );
1189
1190 if ( cflags != NULL )
1191 {
1192 fprintf ( fMakefile,
1193 "%s += %s\n\n",
1194 cflagsMacro.c_str (),
1195 cflags->c_str () );
1196 }
1197
1198 if ( nasmflags != NULL )
1199 {
1200 fprintf ( fMakefile,
1201 "%s += %s\n\n",
1202 nasmflagsMacro.c_str (),
1203 nasmflags->c_str () );
1204 }
1205
1206 // generate phony target for module name
1207 fprintf ( fMakefile, ".PHONY: %s\n",
1208 module.name.c_str () );
1209 fprintf ( fMakefile, "%s: %s\n\n",
1210 module.name.c_str (),
1211 FixupTargetFilename ( module.GetPath () ).c_str () );
1212
1213 // future references to the macros will be to get their values
1214 cflagsMacro = ssprintf ("$(%s)", cflagsMacro.c_str ());
1215 nasmflagsMacro = ssprintf ("$(%s)", nasmflagsMacro.c_str ());
1216 objectsMacro = ssprintf ("$(%s)", objectsMacro.c_str ());
1217
1218 string ar_target = GenerateArchiveTarget ( module, ar, objectsMacro );
1219 GenerateObjectFileTargets ( module,
1220 cc,
1221 cppc,
1222 cflagsMacro,
1223 nasmflagsMacro,
1224 windresflagsMacro,
1225 clean_files );
1226
1227 CLEAN_FILE ( ar_target );
1228 string tgt = FixupTargetFilename(module.GetPath());
1229 if ( tgt != ar_target )
1230 {
1231 CLEAN_FILE ( tgt );
1232 }
1233 }
1234
1235 string
1236 MingwModuleHandler::GetInvocationDependencies ( const Module& module )
1237 {
1238 string dependencies;
1239 for ( size_t i = 0; i < module.invocations.size (); i++ )
1240 {
1241 Invoke& invoke = *module.invocations[i];
1242 if (invoke.invokeModule == &module)
1243 /* Protect against circular dependencies */
1244 continue;
1245 if ( dependencies.length () > 0 )
1246 dependencies += " ";
1247 dependencies += invoke.GetTargets ();
1248 }
1249 return dependencies;
1250 }
1251
1252 void
1253 MingwModuleHandler::GenerateInvocations ( const Module& module ) const
1254 {
1255 if ( module.invocations.size () == 0 )
1256 return;
1257
1258 for ( size_t i = 0; i < module.invocations.size (); i++ )
1259 {
1260 const Invoke& invoke = *module.invocations[i];
1261
1262 if ( invoke.invokeModule->type != BuildTool )
1263 {
1264 throw InvalidBuildFileException ( module.node.location,
1265 "Only modules of type buildtool can be invoked." );
1266 }
1267
1268 string invokeTarget = module.GetInvocationTarget ( i );
1269 fprintf ( fMakefile,
1270 ".PHONY: %s\n\n",
1271 invokeTarget.c_str () );
1272 fprintf ( fMakefile,
1273 "%s: %s\n\n",
1274 invokeTarget.c_str (),
1275 invoke.GetTargets ().c_str () );
1276 fprintf ( fMakefile,
1277 "%s: %s\n",
1278 invoke.GetTargets ().c_str (),
1279 FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str () );
1280 fprintf ( fMakefile, "\t$(ECHO_INVOKE)\n" );
1281 fprintf ( fMakefile,
1282 "\t%s %s\n\n",
1283 FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str (),
1284 invoke.GetParameters ().c_str () );
1285 }
1286 }
1287
1288 string
1289 MingwModuleHandler::GetPreconditionDependenciesName ( const Module& module ) const
1290 {
1291 return module.name + "_precondition";
1292 }
1293
1294 string
1295 MingwModuleHandler::GetDefaultDependencies ( const Module& module ) const
1296 {
1297 /* Avoid circular dependency */
1298 if ( module.type == BuildTool
1299 || module.name == "zlib"
1300 || module.name == "hostzlib" )
1301 return "";
1302 else
1303 return "$(INIT)";
1304 }
1305
1306 void
1307 MingwModuleHandler::GeneratePreconditionDependencies ( const Module& module )
1308 {
1309 string preconditionDependenciesName = GetPreconditionDependenciesName ( module );
1310 string sourceFilenames = GetSourceFilenamesWithoutGeneratedFiles ( module );
1311 string dependencies = GetDefaultDependencies ( module );
1312 string s = GetModuleDependencies ( module );
1313 if ( s.length () > 0 )
1314 {
1315 if ( dependencies.length () > 0 )
1316 dependencies += " ";
1317 dependencies += s;
1318 }
1319
1320 s = GetInvocationDependencies ( module );
1321 if ( s.length () > 0 )
1322 {
1323 if ( dependencies.length () > 0 )
1324 dependencies += " ";
1325 dependencies += s;
1326 }
1327
1328 fprintf ( fMakefile,
1329 "%s = %s\n\n",
1330 preconditionDependenciesName.c_str (),
1331 dependencies.c_str () );
1332 const char* p = sourceFilenames.c_str();
1333 const char* end = p + strlen(p);
1334 while ( p < end )
1335 {
1336 const char* p2 = &p[512];
1337 if ( p2 > end )
1338 p2 = end;
1339 while ( p2 > p && !isspace(*p2) )
1340 --p2;
1341 if ( p == p2 )
1342 {
1343 p2 = strpbrk ( p, " \t" );
1344 if ( !p2 )
1345 p2 = end;
1346 }
1347 fprintf ( fMakefile,
1348 "%.*s: ${%s}\n",
1349 p2-p,
1350 p,
1351 preconditionDependenciesName.c_str ());
1352 p = p2;
1353 p += strspn ( p, " \t" );
1354 }
1355 fprintf ( fMakefile, "\n" );
1356 }
1357
1358 void
1359 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded (
1360 const Module& module,
1361 string_list& clean_files )
1362 {
1363 if ( module.importLibrary != NULL )
1364 {
1365 string library_target = PassThruCacheDirectory ( FixupTargetFilename ( module.GetDependencyPath () ) ).c_str ();
1366 CLEAN_FILE ( library_target );
1367
1368 string definitionDependencies = GetDefinitionDependencies ( module );
1369 fprintf ( fMakefile, "%s: %s %s\n",
1370 library_target.c_str (),
1371 library_target.c_str (),
1372 definitionDependencies.c_str () );
1373
1374 fprintf ( fMakefile, "\t$(ECHO_DLLTOOL)\n" );
1375
1376 string killAt = module.mangledSymbols ? "" : "--kill-at";
1377 fprintf ( fMakefile,
1378 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1379 module.GetTargetName ().c_str (),
1380 ( module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),
1381 library_target.c_str (),
1382 killAt.c_str () );
1383 }
1384 }
1385
1386 string
1387 MingwModuleHandler::GetSpecObjectDependencies ( const string& filename ) const
1388 {
1389 string basename = GetBasename ( filename );
1390 return basename + ".spec.def" + " " + basename + ".stubs.c";
1391 }
1392
1393 string
1394 MingwModuleHandler::GetDefinitionDependencies ( const Module& module )
1395 {
1396 string dependencies;
1397 string dkNkmLibNoFixup = "dk/nkm/lib";
1398 dependencies += FixupTargetFilename ( dkNkmLibNoFixup );
1399 PassThruCacheDirectory ( dkNkmLibNoFixup + SSEP );
1400 const vector<File*>& files = module.non_if_data.files;
1401 for ( size_t i = 0; i < files.size (); i++ )
1402 {
1403 File& file = *files[i];
1404 string extension = GetExtension ( file.name );
1405 if ( extension == ".spec" || extension == ".SPEC" )
1406 {
1407 if ( dependencies.length () > 0 )
1408 dependencies += " ";
1409 dependencies += GetSpecObjectDependencies ( file.name );
1410 }
1411 }
1412 return dependencies;
1413 }
1414
1415 bool
1416 MingwModuleHandler::IsCPlusPlusModule ( const Module& module )
1417 {
1418 return module.cplusplus;
1419 }
1420
1421
1422 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( MingwBackend* backend )
1423 : MingwModuleHandler ( BuildTool,
1424 backend )
1425 {
1426 }
1427
1428 void
1429 MingwBuildToolModuleHandler::Process ( const Module& module, string_list& clean_files )
1430 {
1431 GeneratePreconditionDependencies ( module );
1432 GenerateBuildToolModuleTarget ( module, clean_files );
1433 GenerateInvocations ( module );
1434 }
1435
1436 void
1437 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module& module, string_list& clean_files )
1438 {
1439 string target ( FixupTargetFilename ( module.GetPath () ) );
1440 string objectsMacro = GetObjectsMacro ( module );
1441 string linkDepsMacro = GetLinkingDependenciesMacro ( module );
1442 string libsMacro = GetLibsMacro ( module );
1443
1444 GenerateMacrosAndTargets (
1445 module,
1446 NULL,
1447 NULL,
1448 clean_files );
1449
1450 string linker;
1451 if ( IsCPlusPlusModule ( module ) )
1452 linker = "${host_gpp}";
1453 else
1454 linker = "${host_gcc}";
1455
1456 fprintf ( fMakefile, "%s: %s %s\n",
1457 target.c_str (),
1458 objectsMacro.c_str (),
1459 linkDepsMacro.c_str () );
1460 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
1461 fprintf ( fMakefile,
1462 "\t%s %s -o %s %s %s\n\n",
1463 linker.c_str (),
1464 GetLinkerMacro ( module ).c_str (),
1465 target.c_str (),
1466 objectsMacro.c_str (),
1467 libsMacro.c_str () );
1468 }
1469
1470
1471 MingwKernelModuleHandler::MingwKernelModuleHandler ( MingwBackend* backend )
1472 : MingwModuleHandler ( Kernel,
1473 backend )
1474 {
1475 }
1476
1477 void
1478 MingwKernelModuleHandler::Process ( const Module& module, string_list& clean_files )
1479 {
1480 GeneratePreconditionDependencies ( module );
1481 GenerateKernelModuleTarget ( module, clean_files );
1482 GenerateInvocations ( module );
1483 }
1484
1485 void
1486 MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module& module, string_list& clean_files )
1487 {
1488 static string ros_junk ( "$(ROS_TEMPORARY)" );
1489 string targetName ( module.GetTargetName () ); // i.e. "ntoskrnl.exe"
1490 string target ( FixupTargetFilename (module.GetPath ()) ); // i.e. "$(ROS_INT).\ntoskrnl\ntoskrnl.exe"
1491 string workingDirectory = GetWorkingDirectory ();
1492 string objectsMacro = GetObjectsMacro ( module );
1493 string linkDepsMacro = GetLinkingDependenciesMacro ( module );
1494 string libsMacro = GetLibsMacro ( module );
1495 string base_tmp = ros_junk + module.name + ".base.tmp";
1496 CLEAN_FILE ( base_tmp );
1497 string junk_tmp = ros_junk + module.name + ".junk.tmp";
1498 CLEAN_FILE ( junk_tmp );
1499 string temp_exp = ros_junk + module.name + ".temp.exp";
1500 CLEAN_FILE ( temp_exp );
1501 string gccOptions = ssprintf ("-Wl,-T,%s" SSEP "ntoskrnl.lnk -Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1502 module.GetBasePath ().c_str (),
1503 module.entrypoint.c_str (),
1504 module.baseaddress.c_str () );
1505
1506 GenerateMacrosAndTargets ( module, NULL, NULL, clean_files );
1507
1508 GenerateImportLibraryTargetIfNeeded ( module, clean_files );
1509
1510 fprintf ( fMakefile, "%s: %s %s ${RSYM_TARGET}\n",
1511 target.c_str (),
1512 objectsMacro.c_str (),
1513 linkDepsMacro.c_str () );
1514 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
1515 fprintf ( fMakefile,
1516 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1517 GetLinkerMacro ( module ).c_str (),
1518 gccOptions.c_str (),
1519 base_tmp.c_str (),
1520 junk_tmp.c_str (),
1521 objectsMacro.c_str (),
1522 linkDepsMacro.c_str () );
1523 fprintf ( fMakefile,
1524 "\t-@${rm} %s\n",
1525 junk_tmp.c_str () );
1526 string killAt = module.mangledSymbols ? "" : "--kill-at";
1527 fprintf ( fMakefile,
1528 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1529 targetName.c_str (),
1530 base_tmp.c_str (),
1531 temp_exp.c_str (),
1532 killAt.c_str () );
1533 fprintf ( fMakefile,
1534 "\t-@${rm} %s\n",
1535 base_tmp.c_str () );
1536 fprintf ( fMakefile,
1537 "\t${gcc} %s %s -Wl,%s -o %s %s %s\n",
1538 GetLinkerMacro ( module ).c_str (),
1539 gccOptions.c_str (),
1540 temp_exp.c_str (),
1541 target.c_str (),
1542 objectsMacro.c_str (),
1543 linkDepsMacro.c_str () );
1544 fprintf ( fMakefile,
1545 "\t-@${rm} %s\n",
1546 temp_exp.c_str () );
1547 fprintf ( fMakefile, "\t$(ECHO_RSYM)\n" );
1548 fprintf ( fMakefile,
1549 "\t${rsym} %s %s\n\n",
1550 target.c_str (),
1551 target.c_str () );
1552 }
1553
1554
1555 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ( MingwBackend* backend )
1556 : MingwModuleHandler ( StaticLibrary,
1557 backend )
1558 {
1559 }
1560
1561 void
1562 MingwStaticLibraryModuleHandler::Process ( const Module& module, string_list& clean_files )
1563 {
1564 GeneratePreconditionDependencies ( module );
1565 GenerateStaticLibraryModuleTarget ( module, clean_files );
1566 GenerateInvocations ( module );
1567 }
1568
1569 void
1570 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module& module, string_list& clean_files )
1571 {
1572 GenerateMacrosAndTargets ( module, NULL, NULL, clean_files );
1573 }
1574
1575
1576 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler ( MingwBackend* backend )
1577 : MingwModuleHandler ( ObjectLibrary,
1578 backend )
1579 {
1580 }
1581
1582 void
1583 MingwObjectLibraryModuleHandler::Process ( const Module& module, string_list& clean_files )
1584 {
1585 GeneratePreconditionDependencies ( module );
1586 GenerateObjectLibraryModuleTarget ( module, clean_files );
1587 GenerateInvocations ( module );
1588 }
1589
1590 void
1591 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ( const Module& module, string_list& clean_files )
1592 {
1593 GenerateMacrosAndTargets ( module, NULL, NULL, clean_files );
1594 }
1595
1596
1597 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ( MingwBackend* backend )
1598 : MingwModuleHandler ( KernelModeDLL,
1599 backend )
1600 {
1601 }
1602
1603 void
1604 MingwKernelModeDLLModuleHandler::Process ( const Module& module, string_list& clean_files )
1605 {
1606 GeneratePreconditionDependencies ( module );
1607 GenerateKernelModeDLLModuleTarget ( module, clean_files );
1608 GenerateInvocations ( module );
1609 }
1610
1611 void
1612 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget (
1613 const Module& module,
1614 string_list& clean_files )
1615 {
1616 static string ros_junk ( "$(ROS_TEMPORARY)" );
1617 string target ( FixupTargetFilename ( module.GetPath () ) );
1618 string workingDirectory = GetWorkingDirectory ( );
1619 string objectsMacro = GetObjectsMacro ( module );
1620 string linkDepsMacro = GetLinkingDependenciesMacro ( module );
1621 string libsMacro = GetLibsMacro ( module );
1622
1623 GenerateImportLibraryTargetIfNeeded ( module, clean_files );
1624
1625 if ( module.non_if_data.files.size () > 0 )
1626 {
1627 GenerateMacrosAndTargets ( module, NULL, NULL, clean_files );
1628
1629 string dependencies =
1630 objectsMacro + " " + linkDepsMacro;
1631
1632 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1633 module.entrypoint.c_str (),
1634 module.baseaddress.c_str () );
1635 GenerateLinkerCommand ( module,
1636 target,
1637 dependencies,
1638 "${gcc}",
1639 linkerParameters,
1640 objectsMacro,
1641 libsMacro,
1642 clean_files );
1643 }
1644 else
1645 {
1646 fprintf ( fMakefile, ".PHONY: %s\n\n",
1647 target.c_str ());
1648 fprintf ( fMakefile, "%s:\n",
1649 target.c_str ());
1650 }
1651 }
1652
1653
1654 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ( MingwBackend* backend )
1655 : MingwModuleHandler ( KernelModeDriver,
1656 backend )
1657 {
1658 }
1659
1660 void
1661 MingwKernelModeDriverModuleHandler::Process ( const Module& module, string_list& clean_files )
1662 {
1663 GeneratePreconditionDependencies ( module );
1664 GenerateKernelModeDriverModuleTarget ( module, clean_files );
1665 GenerateInvocations ( module );
1666 }
1667
1668
1669 void
1670 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget (
1671 const Module& module,
1672 string_list& clean_files )
1673 {
1674 static string ros_junk ( "$(ROS_TEMPORARY)" );
1675 string target ( PassThruCacheDirectory( FixupTargetFilename ( module.GetPath () ) ) );
1676 string workingDirectory = GetWorkingDirectory ();
1677 string objectsMacro = GetObjectsMacro ( module );
1678 string linkDepsMacro = GetLinkingDependenciesMacro ( module );
1679 string libsMacro = GetLibsMacro ( module );
1680
1681 GenerateImportLibraryTargetIfNeeded ( module, clean_files );
1682
1683 if ( module.non_if_data.files.size () > 0 )
1684 {
1685 string cflags ( "-D__NTDRIVER__" );
1686 GenerateMacrosAndTargets ( module,
1687 &cflags,
1688 NULL,
1689 clean_files );
1690
1691 string dependencies =
1692 objectsMacro + " " + linkDepsMacro;
1693
1694 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1695 module.entrypoint.c_str (),
1696 module.baseaddress.c_str () );
1697 GenerateLinkerCommand ( module,
1698 target,
1699 dependencies,
1700 "${gcc}",
1701 linkerParameters,
1702 objectsMacro,
1703 libsMacro,
1704 clean_files );
1705 }
1706 else
1707 {
1708 fprintf ( fMakefile, ".PHONY: %s\n\n",
1709 target.c_str ());
1710 fprintf ( fMakefile, "%s:\n",
1711 target.c_str () );
1712 }
1713 }
1714
1715
1716 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ( MingwBackend* backend )
1717 : MingwModuleHandler ( NativeDLL,
1718 backend )
1719 {
1720 }
1721
1722 void
1723 MingwNativeDLLModuleHandler::Process ( const Module& module, string_list& clean_files )
1724 {
1725 GeneratePreconditionDependencies ( module );
1726 GenerateNativeDLLModuleTarget ( module, clean_files );
1727 GenerateInvocations ( module );
1728 }
1729
1730 void
1731 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module& module, string_list& clean_files )
1732 {
1733 static string ros_junk ( "$(ROS_TEMPORARY)" );
1734 string target ( FixupTargetFilename ( module.GetPath () ) );
1735 string workingDirectory = GetWorkingDirectory ( );
1736 string objectsMacro = GetObjectsMacro ( module );
1737 string linkDepsMacro = GetLinkingDependenciesMacro ( module );
1738 string libsMacro = GetLibsMacro ( module );
1739
1740 GenerateImportLibraryTargetIfNeeded ( module, clean_files );
1741
1742 if ( module.non_if_data.files.size () > 0 )
1743 {
1744 GenerateMacrosAndTargets ( module, NULL, NULL, clean_files );
1745
1746 string dependencies =
1747 objectsMacro + " " + linkDepsMacro;
1748
1749 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1750 module.entrypoint.c_str (),
1751 module.baseaddress.c_str () );
1752 GenerateLinkerCommand ( module,
1753 target,
1754 dependencies,
1755 "${gcc}",
1756 linkerParameters,
1757 objectsMacro,
1758 libsMacro,
1759 clean_files );
1760 }
1761 else
1762 {
1763 fprintf ( fMakefile, ".PHONY: %s\n\n",
1764 target.c_str ());
1765 fprintf ( fMakefile, "%s:\n\n",
1766 target.c_str ());
1767 }
1768 }
1769
1770
1771 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler ( MingwBackend* backend )
1772 : MingwModuleHandler ( NativeCUI,
1773 backend )
1774 {
1775 }
1776
1777 void
1778 MingwNativeCUIModuleHandler::Process ( const Module& module, string_list& clean_files )
1779 {
1780 GeneratePreconditionDependencies ( module );
1781 GenerateNativeCUIModuleTarget ( module, clean_files );
1782 GenerateInvocations ( module );
1783 }
1784
1785 void
1786 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ( const Module& module, string_list& clean_files )
1787 {
1788 static string ros_junk ( "$(ROS_TEMPORARY)" );
1789 string target ( FixupTargetFilename ( module.GetPath () ) );
1790 string workingDirectory = GetWorkingDirectory ( );
1791 string objectsMacro = GetObjectsMacro ( module );
1792 string linkDepsMacro = GetLinkingDependenciesMacro ( module );
1793 string libsMacro = GetLibsMacro ( module );
1794
1795 GenerateImportLibraryTargetIfNeeded ( module, clean_files );
1796
1797 if ( module.non_if_data.files.size () > 0 )
1798 {
1799 string cflags ( "-D__NTAPP__" );
1800 GenerateMacrosAndTargets ( module,
1801 &cflags,
1802 NULL,
1803 clean_files );
1804
1805 string dependencies =
1806 objectsMacro + " " + linkDepsMacro;
1807
1808 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1809 module.entrypoint.c_str (),
1810 module.baseaddress.c_str () );
1811 GenerateLinkerCommand ( module,
1812 target,
1813 dependencies,
1814 "${gcc}",
1815 linkerParameters,
1816 objectsMacro,
1817 libsMacro,
1818 clean_files );
1819 }
1820 else
1821 {
1822 fprintf ( fMakefile, ".PHONY: %s\n\n",
1823 target.c_str ());
1824 fprintf ( fMakefile, "%s:\n\n",
1825 target.c_str ());
1826 }
1827 }
1828
1829
1830 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ( MingwBackend* backend )
1831 : MingwModuleHandler ( Win32DLL,
1832 backend )
1833 {
1834 }
1835
1836 void
1837 MingwWin32DLLModuleHandler::Process ( const Module& module, string_list& clean_files )
1838 {
1839 GenerateExtractWineDLLResourcesTarget ( module, clean_files );
1840 GeneratePreconditionDependencies ( module );
1841 GenerateWin32DLLModuleTarget ( module, clean_files );
1842 GenerateInvocations ( module );
1843 }
1844
1845 void
1846 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ( const Module& module, string_list& clean_files )
1847 {
1848 fprintf ( fMakefile, ".PHONY: %s_extractresources\n\n",
1849 module.name.c_str () );
1850 fprintf ( fMakefile, "%s_extractresources: $(BIN2RES_TARGET)\n",
1851 module.name.c_str () );
1852 const vector<File*>& files = module.non_if_data.files;
1853 for ( size_t i = 0; i < files.size (); i++ )
1854 {
1855 File& file = *files[i];
1856 string extension = GetExtension ( file.name );
1857 if ( extension == ".rc" || extension == ".RC" )
1858 {
1859 string resource = FixupTargetFilename ( file.name );
1860 fprintf ( fMakefile, "\t$(ECHO_BIN2RES)\n" );
1861 fprintf ( fMakefile, "\t@:echo ${bin2res} -f -x %s\n",
1862 resource.c_str () );
1863 }
1864 }
1865 fprintf ( fMakefile, "\n");
1866 }
1867
1868 void
1869 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module& module, string_list& clean_files )
1870 {
1871 static string ros_junk ( "$(ROS_TEMPORARY)" );
1872 string target ( FixupTargetFilename ( module.GetPath () ) );
1873 string workingDirectory = GetWorkingDirectory ( );
1874 string objectsMacro = GetObjectsMacro ( module );
1875 string linkDepsMacro = GetLinkingDependenciesMacro ( module );
1876 string libsMacro = GetLibsMacro ( module );
1877
1878 GenerateImportLibraryTargetIfNeeded ( module, clean_files );
1879
1880 if ( module.non_if_data.files.size () > 0 )
1881 {
1882 GenerateMacrosAndTargets ( module, NULL, NULL, clean_files );
1883
1884 string dependencies =
1885 objectsMacro + " " + linkDepsMacro;
1886
1887 string linker;
1888 if ( module.cplusplus )
1889 linker = "${gpp}";
1890 else
1891 linker = "${gcc}";
1892
1893 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1894 module.entrypoint.c_str (),
1895 module.baseaddress.c_str () );
1896 GenerateLinkerCommand ( module,
1897 target,
1898 dependencies,
1899 linker,
1900 linkerParameters,
1901 objectsMacro,
1902 libsMacro,
1903 clean_files );
1904 }
1905 else
1906 {
1907 fprintf ( fMakefile, ".PHONY: %s\n\n",
1908 target.c_str () );
1909 fprintf ( fMakefile, "%s:\n\n",
1910 target.c_str () );
1911 }
1912 }
1913
1914
1915 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler ( MingwBackend* backend )
1916 : MingwModuleHandler ( Win32CUI,
1917 backend )
1918 {
1919 }
1920
1921 void
1922 MingwWin32CUIModuleHandler::Process ( const Module& module, string_list& clean_files )
1923 {
1924 GeneratePreconditionDependencies ( module );
1925 GenerateWin32CUIModuleTarget ( module, clean_files );
1926 GenerateInvocations ( module );
1927 }
1928
1929 void
1930 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ( const Module& module, string_list& clean_files )
1931 {
1932 static string ros_junk ( "$(ROS_TEMPORARY)" );
1933 string target ( FixupTargetFilename ( module.GetPath () ) );
1934 string workingDirectory = GetWorkingDirectory ( );
1935 string objectsMacro = GetObjectsMacro ( module );
1936 string linkDepsMacro = GetLinkingDependenciesMacro ( module );
1937 string libsMacro = GetLibsMacro ( module );
1938
1939 GenerateImportLibraryTargetIfNeeded ( module, clean_files );
1940
1941 if ( module.non_if_data.files.size () > 0 )
1942 {
1943 GenerateMacrosAndTargets ( module, NULL, NULL, clean_files );
1944
1945 string dependencies =
1946 objectsMacro + " " + linkDepsMacro;
1947
1948 string linker;
1949 if ( module.cplusplus )
1950 linker = "${gpp}";
1951 else
1952 linker = "${gcc}";
1953
1954 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1955 module.entrypoint.c_str (),
1956 module.baseaddress.c_str () );
1957 GenerateLinkerCommand ( module,
1958 target,
1959 dependencies,
1960 linker,
1961 linkerParameters,
1962 objectsMacro,
1963 libsMacro,
1964 clean_files );
1965 }
1966 else
1967 {
1968 fprintf ( fMakefile, ".PHONY: %s\n\n",
1969 target.c_str ());
1970 fprintf ( fMakefile, "%s:\n\n",
1971 target.c_str ());
1972 }
1973 }
1974
1975
1976 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler ( MingwBackend* backend )
1977 : MingwModuleHandler ( Win32GUI,
1978 backend )
1979 {
1980 }
1981
1982 void
1983 MingwWin32GUIModuleHandler::Process ( const Module& module, string_list& clean_files )
1984 {
1985 GeneratePreconditionDependencies ( module );
1986 GenerateWin32GUIModuleTarget ( module, clean_files );
1987 GenerateInvocations ( module );
1988 }
1989
1990 void
1991 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module& module, string_list& clean_files )
1992 {
1993 static string ros_junk ( "$(ROS_TEMPORARY)" );
1994 string target ( FixupTargetFilename ( module.GetPath () ) );
1995 string workingDirectory = GetWorkingDirectory ( );
1996 string objectsMacro = GetObjectsMacro ( module );
1997 string linkDepsMacro = GetLinkingDependenciesMacro ( module );
1998 string libsMacro = GetLibsMacro ( module );
1999
2000 GenerateImportLibraryTargetIfNeeded ( module, clean_files );
2001
2002 if ( module.non_if_data.files.size () > 0 )
2003 {
2004 GenerateMacrosAndTargets ( module, NULL, NULL, clean_files );
2005
2006 string dependencies =
2007 objectsMacro + " " + linkDepsMacro;
2008
2009 string linker;
2010 if ( module.cplusplus )
2011 linker = "${gpp}";
2012 else
2013 linker = "${gcc}";
2014
2015 string linkerParameters = ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2016 module.entrypoint.c_str (),
2017 module.baseaddress.c_str () );
2018 GenerateLinkerCommand ( module,
2019 target,
2020 dependencies,
2021 linker,
2022 linkerParameters,
2023 objectsMacro,
2024 libsMacro,
2025 clean_files );
2026 }
2027 else
2028 {
2029 fprintf ( fMakefile, ".PHONY: %s\n\n",
2030 target.c_str ());
2031 fprintf ( fMakefile, "%s:\n\n",
2032 target.c_str ());
2033 }
2034 }
2035
2036
2037 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler ( MingwBackend* backend )
2038 : MingwModuleHandler ( BootLoader,
2039 backend )
2040 {
2041 }
2042
2043 void
2044 MingwBootLoaderModuleHandler::Process ( const Module& module, string_list& clean_files )
2045 {
2046 GeneratePreconditionDependencies ( module );
2047 GenerateBootLoaderModuleTarget ( module, clean_files );
2048 GenerateInvocations ( module );
2049 }
2050
2051 void
2052 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget (
2053 const Module& module,
2054 string_list& clean_files )
2055 {
2056 static string ros_junk ( "$(ROS_TEMPORARY)" );
2057 string targetName ( module.GetTargetName () );
2058 string target ( FixupTargetFilename ( module.GetPath () ) );
2059 string workingDirectory = GetWorkingDirectory ();
2060 string junk_tmp = ros_junk + module.name + ".junk.tmp";
2061 CLEAN_FILE ( junk_tmp );
2062 string objectsMacro = GetObjectsMacro ( module );
2063 string linkDepsMacro = GetLinkingDependenciesMacro ( module );
2064 string libsMacro = GetLibsMacro ( module );
2065
2066 GenerateMacrosAndTargets ( module, NULL, NULL, clean_files );
2067
2068 fprintf ( fMakefile, "%s: %s %s\n",
2069 target.c_str (),
2070 objectsMacro.c_str (),
2071 linkDepsMacro.c_str () );
2072
2073 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
2074
2075 fprintf ( fMakefile,
2076 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2077 GetLinkerMacro ( module ).c_str (),
2078 junk_tmp.c_str (),
2079 objectsMacro.c_str (),
2080 linkDepsMacro.c_str () );
2081 fprintf ( fMakefile,
2082 "\t${objcopy} -O binary %s %s\n",
2083 junk_tmp.c_str (),
2084 target.c_str () );
2085 fprintf ( fMakefile,
2086 "\t-@${rm} %s\n",
2087 junk_tmp.c_str () );
2088 }
2089
2090
2091 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler ( MingwBackend* backend )
2092 : MingwModuleHandler ( BootSector,
2093 backend )
2094 {
2095 }
2096
2097 void
2098 MingwBootSectorModuleHandler::Process ( const Module& module, string_list& clean_files )
2099 {
2100 GeneratePreconditionDependencies ( module );
2101 GenerateBootSectorModuleTarget ( module, clean_files );
2102 GenerateInvocations ( module );
2103 }
2104
2105 void
2106 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ( const Module& module, string_list& clean_files )
2107 {
2108 string objectsMacro = GetObjectsMacro ( module );
2109
2110 string* nasmflags = new string ( "-f bin" );
2111 GenerateMacrosAndTargets ( module,
2112 NULL,
2113 nasmflags,
2114 clean_files );
2115
2116 fprintf ( fMakefile, ".PHONY: %s\n\n",
2117 module.name.c_str ());
2118 fprintf ( fMakefile,
2119 "%s: %s\n",
2120 module.name.c_str (),
2121 objectsMacro.c_str () );
2122 }
2123
2124
2125 MingwIsoModuleHandler::MingwIsoModuleHandler ( MingwBackend* backend )
2126 : MingwModuleHandler ( Iso,
2127 backend )
2128 {
2129 }
2130
2131 void
2132 MingwIsoModuleHandler::Process ( const Module& module, string_list& clean_files )
2133 {
2134 GeneratePreconditionDependencies ( module );
2135 GenerateIsoModuleTarget ( module, clean_files );
2136 GenerateInvocations ( module );
2137 }
2138
2139 void
2140 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands ( const string& bootcdDirectory,
2141 const Module& module )
2142 {
2143 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2144 {
2145 const Module& m = *module.project.modules[i];
2146 if ( m.bootstrap != NULL )
2147 {
2148 string targetFilenameNoFixup = bootcdDirectory + SSEP + m.bootstrap->base + SSEP + m.bootstrap->nameoncd;
2149 string targetFilename = PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup ) );
2150 fprintf ( fMakefile,
2151 "\t${cp} %s %s\n",
2152 m.GetPath ().c_str (),
2153 targetFilename.c_str () );
2154 }
2155 }
2156 }
2157
2158 void
2159 MingwIsoModuleHandler::OutputCdfileCopyCommands ( const string& bootcdDirectory,
2160 const Module& module )
2161 {
2162 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2163 {
2164 const CDFile& cdfile = *module.project.cdfiles[i];
2165 string targetFilenameNoFixup = bootcdDirectory + SSEP + cdfile.base + SSEP + cdfile.nameoncd;
2166 string targetFilename = PassThruCacheDirectory ( FixupTargetFilename ( targetFilenameNoFixup ) );
2167 fprintf ( fMakefile,
2168 "\t${cp} %s %s\n",
2169 cdfile.GetPath ().c_str (),
2170 targetFilename.c_str () );
2171 }
2172 }
2173
2174 string
2175 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string& bootcdDirectory,
2176 const Module& module )
2177 {
2178 string directories;
2179 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2180 {
2181 const Module& m = *module.project.modules[i];
2182 if ( m.bootstrap != NULL )
2183 {
2184 string targetDirecctory = bootcdDirectory + SSEP + m.bootstrap->base;
2185 if ( directories.size () > 0 )
2186 directories += " ";
2187 directories += PassThruCacheDirectory ( FixupTargetFilename ( targetDirecctory ) );
2188 }
2189 }
2190 return directories;
2191 }
2192
2193 string
2194 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string& bootcdDirectory,
2195 const Module& module )
2196 {
2197 string directories;
2198 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2199 {
2200 const CDFile& cdfile = *module.project.cdfiles[i];
2201 string targetDirecctory = bootcdDirectory + SSEP + cdfile.base;
2202 if ( directories.size () > 0 )
2203 directories += " ";
2204 directories += PassThruCacheDirectory ( FixupTargetFilename ( targetDirecctory ) );
2205 }
2206 return directories;
2207 }
2208
2209 string
2210 MingwIsoModuleHandler::GetCdDirectories ( const string& bootcdDirectory,
2211 const Module& module )
2212 {
2213 string directories = GetBootstrapCdDirectories ( bootcdDirectory,
2214 module );
2215 directories += " " + GetNonModuleCdDirectories ( bootcdDirectory,
2216 module );
2217 return directories;
2218 }
2219
2220 void
2221 MingwIsoModuleHandler::GetBootstrapCdFiles (
2222 vector<string>& out,
2223 const Module& module ) const
2224 {
2225 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2226 {
2227 const Module& m = *module.project.modules[i];
2228 if ( m.bootstrap != NULL )
2229 out.push_back ( FixupTargetFilename ( m.GetPath () ) );
2230 }
2231 }
2232
2233 void
2234 MingwIsoModuleHandler::GetNonModuleCdFiles (
2235 vector<string>& out,
2236 const Module& module ) const
2237 {
2238 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2239 {
2240 const CDFile& cdfile = *module.project.cdfiles[i];
2241 out.push_back ( NormalizeFilename ( cdfile.GetPath () ) );
2242 }
2243 }
2244
2245 void
2246 MingwIsoModuleHandler::GetCdFiles (
2247 vector<string>& out,
2248 const Module& module ) const
2249 {
2250 GetBootstrapCdFiles ( out, module );
2251 GetNonModuleCdFiles ( out, module );
2252 }
2253
2254 void
2255 MingwIsoModuleHandler::GenerateIsoModuleTarget ( const Module& module, string_list& clean_files )
2256 {
2257 string bootcdDirectory = "cd";
2258 string isoboot = FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );
2259 string bootcdReactosNoFixup = bootcdDirectory + "/reactos";
2260 string bootcdReactos = FixupTargetFilename ( bootcdReactosNoFixup );
2261 PassThruCacheDirectory ( bootcdReactos + SSEP );
2262 string reactosInf = FixupTargetFilename ( bootcdReactosNoFixup + "/reactos.inf" );
2263 string reactosDff = NormalizeFilename ( "bootdata/packages/reactos.dff" );
2264 string cdDirectories = GetCdDirectories ( bootcdDirectory,
2265 module );
2266 vector<string> vCdFiles;
2267 GetCdFiles ( vCdFiles, module );
2268 string cdFiles = v2s ( vCdFiles, 5 );
2269
2270 fprintf ( fMakefile, ".PHONY: %s\n\n",
2271 module.name.c_str ());
2272 fprintf ( fMakefile,
2273 "%s: all %s %s %s %s ${CABMAN_TARGET} ${CDMAKE_TARGET}\n",
2274 module.name.c_str (),
2275 isoboot.c_str (),
2276 PassThruCacheDirectory ( bootcdReactos ).c_str (),
2277 cdDirectories.c_str (),
2278 cdFiles.c_str () );
2279 fprintf ( fMakefile, "\t$(ECHO_CABMAN)\n" );
2280 fprintf ( fMakefile,
2281 "\t${cabman} -C %s -L %s -I\n",
2282 reactosDff.c_str (),
2283 bootcdReactos.c_str () );
2284 fprintf ( fMakefile,
2285 "\t${cabman} -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2286 reactosDff.c_str (),
2287 reactosInf.c_str (),
2288 bootcdReactos.c_str ());
2289 fprintf ( fMakefile,
2290 "\t-@${rm} %s\n",
2291 reactosInf.c_str () );
2292 OutputBootstrapfileCopyCommands ( bootcdDirectory,
2293 module );
2294 OutputCdfileCopyCommands ( bootcdDirectory,
2295 module );
2296 fprintf ( fMakefile, "\t$(ECHO_CDMAKE)\n" );
2297 fprintf ( fMakefile,
2298 "\t${cdmake} -v -m -b %s %s REACTOS ReactOS.iso\n",
2299 isoboot.c_str (),
2300 bootcdDirectory.c_str () );
2301 fprintf ( fMakefile,
2302 "\n" );
2303 }