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