Output rules for objectlibrary files
[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 string ar_target;
1285 if ( module.type != ObjectLibrary )
1286 ar_target = GenerateArchiveTarget ( ar, objectsMacro );
1287
1288 GenerateObjectFileTargets ( cc,
1289 cppc,
1290 cflagsMacro,
1291 nasmflagsMacro,
1292 windresflagsMacro );
1293
1294 if ( module.type != ObjectLibrary )
1295 {
1296 if ( targetMacro != ar_target )
1297 {
1298 CLEAN_FILE ( ar_target );
1299 }
1300 }
1301 }
1302
1303 void
1304 MingwModuleHandler::GetInvocationDependencies (
1305 const Module& module,
1306 string_list& dependencies )
1307 {
1308 for ( size_t i = 0; i < module.invocations.size (); i++ )
1309 {
1310 Invoke& invoke = *module.invocations[i];
1311 if ( invoke.invokeModule == &module )
1312 /* Protect against circular dependencies */
1313 continue;
1314 invoke.GetTargets ( dependencies );
1315 }
1316 }
1317
1318 void
1319 MingwModuleHandler::GenerateInvocations () const
1320 {
1321 if ( module.invocations.size () == 0 )
1322 return;
1323
1324 size_t iend = module.invocations.size ();
1325 for ( size_t i = 0; i < iend; i++ )
1326 {
1327 const Invoke& invoke = *module.invocations[i];
1328
1329 if ( invoke.invokeModule->type != BuildTool )
1330 {
1331 throw InvalidBuildFileException ( module.node.location,
1332 "Only modules of type buildtool can be invoked." );
1333 }
1334
1335 string invokeTarget = module.GetInvocationTarget ( i );
1336 string_list invoke_targets;
1337 assert ( invoke_targets.size() );
1338 invoke.GetTargets ( invoke_targets );
1339 fprintf ( fMakefile,
1340 ".PHONY: %s\n\n",
1341 invokeTarget.c_str () );
1342 fprintf ( fMakefile,
1343 "%s:",
1344 invokeTarget.c_str () );
1345 size_t j, jend = invoke_targets.size();
1346 for ( j = 0; j < jend; j++ )
1347 {
1348 fprintf ( fMakefile,
1349 " %s",
1350 invoke_targets[i].c_str () );
1351 }
1352 fprintf ( fMakefile, "\n\n%s", invoke_targets[0].c_str () );
1353 for ( j = 1; j < jend; j++ )
1354 fprintf ( fMakefile,
1355 " %s",
1356 invoke_targets[i].c_str () );
1357 fprintf ( fMakefile,
1358 ": %s\n",
1359 FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str () );
1360 fprintf ( fMakefile, "\t$(ECHO_INVOKE)\n" );
1361 fprintf ( fMakefile,
1362 "\t%s %s\n\n",
1363 FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str (),
1364 invoke.GetParameters ().c_str () );
1365 }
1366 }
1367
1368 string
1369 MingwModuleHandler::GetPreconditionDependenciesName () const
1370 {
1371 return module.name + "_precondition";
1372 }
1373
1374 void
1375 MingwModuleHandler::GetDefaultDependencies (
1376 string_list& dependencies ) const
1377 {
1378 /* Avoid circular dependency */
1379 if ( module.type != BuildTool
1380 && module.name != "zlib"
1381 && module.name != "hostzlib" )
1382
1383 dependencies.push_back ( "$(INIT)" );
1384 }
1385
1386 void
1387 MingwModuleHandler::GeneratePreconditionDependencies ()
1388 {
1389 string preconditionDependenciesName = GetPreconditionDependenciesName ();
1390 string_list sourceFilenames;
1391 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames );
1392 string_list dependencies;
1393 GetDefaultDependencies ( dependencies );
1394 GetModuleDependencies ( dependencies );
1395
1396 GetInvocationDependencies ( module, dependencies );
1397
1398 if ( dependencies.size() )
1399 {
1400 fprintf ( fMakefile,
1401 "%s =",
1402 preconditionDependenciesName.c_str () );
1403 for ( size_t i = 0; i < dependencies.size(); i++ )
1404 fprintf ( fMakefile,
1405 " %s",
1406 dependencies[i].c_str () );
1407 fprintf ( fMakefile, "\n\n" );
1408 }
1409
1410 for ( size_t i = 0; i < sourceFilenames.size(); i++ )
1411 {
1412 fprintf ( fMakefile,
1413 "%s: ${%s}\n",
1414 sourceFilenames[i].c_str(),
1415 preconditionDependenciesName.c_str ());
1416 }
1417 fprintf ( fMakefile, "\n" );
1418 }
1419
1420 void
1421 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
1422 {
1423 if ( module.importLibrary != NULL )
1424 {
1425 string library_target (
1426 GetImportLibraryFilename ( module, &clean_files ) );
1427
1428 string_list deps;
1429 GetDefinitionDependencies ( deps );
1430
1431 fprintf ( fMakefile, "# IMPORT LIBRARY RULE:\n" );
1432
1433 fprintf ( fMakefile, "%s:",
1434 library_target.c_str () );
1435
1436 size_t i, iend = deps.size();
1437 for ( i = 0; i < iend; i++ )
1438 fprintf ( fMakefile, " %s",
1439 deps[i].c_str () );
1440
1441 fprintf ( fMakefile, " %s\n",
1442 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
1443
1444 fprintf ( fMakefile, "\t$(ECHO_DLLTOOL)\n" );
1445
1446 string killAt = module.mangledSymbols ? "" : "--kill-at";
1447 fprintf ( fMakefile,
1448 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1449 module.GetTargetName ().c_str (),
1450 ( module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),
1451 library_target.c_str (),
1452 killAt.c_str () );
1453 }
1454 }
1455
1456 void
1457 MingwModuleHandler::GetSpecObjectDependencies (
1458 string_list& dependencies,
1459 const string& filename ) const
1460 {
1461 string basename = GetBasename ( filename );
1462 dependencies.push_back ( basename + ".spec.def" );
1463 dependencies.push_back ( basename + ".stubs.c" );
1464 }
1465
1466 void
1467 MingwModuleHandler::GetDefinitionDependencies (
1468 string_list& dependencies ) const
1469 {
1470 string dkNkmLibNoFixup = "dk/nkm/lib";
1471 // TODO FIXME - verify this is the correct dependency...
1472 // easiest way to tell is to remove it and see what breaks
1473 /*dependencies += PassThruCacheDirectory (
1474 FixupTargetFilename ( dkNkmLibNoFixup ),
1475 false, NULL );*/
1476 const vector<File*>& files = module.non_if_data.files;
1477 for ( size_t i = 0; i < files.size (); i++ )
1478 {
1479 File& file = *files[i];
1480 string extension = GetExtension ( file.name );
1481 if ( extension == ".spec" || extension == ".SPEC" )
1482 {
1483 GetSpecObjectDependencies ( dependencies, file.name );
1484 }
1485 }
1486 }
1487
1488 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module& module_ )
1489 : MingwModuleHandler ( module_ )
1490 {
1491 }
1492
1493 void
1494 MingwBuildToolModuleHandler::Process ()
1495 {
1496 GenerateBuildToolModuleTarget ();
1497 }
1498
1499 void
1500 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
1501 {
1502 string targetMacro ( GetTargetMacro (module) );
1503 string objectsMacro = GetObjectsMacro ( module );
1504 string linkDepsMacro = GetLinkingDependenciesMacro ();
1505 string libsMacro = GetLibsMacro ();
1506
1507 GenerateRules ();
1508
1509 string linker;
1510 if ( module.cplusplus )
1511 linker = "${host_gpp}";
1512 else
1513 linker = "${host_gcc}";
1514
1515 fprintf ( fMakefile, "%s: %s %s %s\n",
1516 targetMacro.c_str (),
1517 objectsMacro.c_str (),
1518 linkDepsMacro.c_str (),
1519 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
1520 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
1521 fprintf ( fMakefile,
1522 "\t%s %s -o $@ %s %s\n\n",
1523 linker.c_str (),
1524 GetLinkerMacro ().c_str (),
1525 objectsMacro.c_str (),
1526 libsMacro.c_str () );
1527 }
1528
1529
1530 MingwKernelModuleHandler::MingwKernelModuleHandler (
1531 const Module& module_ )
1532
1533 : MingwModuleHandler ( module_ )
1534 {
1535 }
1536
1537 void
1538 MingwKernelModuleHandler::Process ()
1539 {
1540 GenerateKernelModuleTarget ();
1541 }
1542
1543 void
1544 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
1545 {
1546 string targetName ( module.GetTargetName () ); // i.e. "ntoskrnl.exe"
1547 string targetMacro ( GetTargetMacro (module) ); // i.e. "$(NTOSKRNL_TARGET)"
1548 string workingDirectory = GetWorkingDirectory ();
1549 string objectsMacro = GetObjectsMacro ( module );
1550 string linkDepsMacro = GetLinkingDependenciesMacro ();
1551 string libsMacro = GetLibsMacro ();
1552 string base_tmp = ros_temp + module.name + ".base.tmp";
1553 CLEAN_FILE ( base_tmp );
1554 string junk_tmp = ros_temp + module.name + ".junk.tmp";
1555 CLEAN_FILE ( junk_tmp );
1556 string temp_exp = ros_temp + module.name + ".temp.exp";
1557 CLEAN_FILE ( temp_exp );
1558 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",
1559 module.GetBasePath ().c_str (),
1560 module.entrypoint.c_str (),
1561 module.baseaddress.c_str () );
1562
1563 GenerateRules ();
1564
1565 GenerateImportLibraryTargetIfNeeded ();
1566
1567 fprintf ( fMakefile, "%s: %s %s %s $(RSYM_TARGET)\n",
1568 targetMacro.c_str (),
1569 objectsMacro.c_str (),
1570 linkDepsMacro.c_str (),
1571 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
1572 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
1573 fprintf ( fMakefile,
1574 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1575 GetLinkerMacro ().c_str (),
1576 gccOptions.c_str (),
1577 base_tmp.c_str (),
1578 junk_tmp.c_str (),
1579 objectsMacro.c_str (),
1580 linkDepsMacro.c_str () );
1581 fprintf ( fMakefile,
1582 "\t-@${rm} %s 2>$(NUL)\n",
1583 junk_tmp.c_str () );
1584 string killAt = module.mangledSymbols ? "" : "--kill-at";
1585 fprintf ( fMakefile,
1586 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1587 targetName.c_str (),
1588 base_tmp.c_str (),
1589 temp_exp.c_str (),
1590 killAt.c_str () );
1591 fprintf ( fMakefile,
1592 "\t-@${rm} %s 2>$(NUL)\n",
1593 base_tmp.c_str () );
1594 fprintf ( fMakefile,
1595 "\t${gcc} %s %s -Wl,%s -o $@ %s %s\n",
1596 GetLinkerMacro ().c_str (),
1597 gccOptions.c_str (),
1598 temp_exp.c_str (),
1599 objectsMacro.c_str (),
1600 linkDepsMacro.c_str () );
1601 fprintf ( fMakefile,
1602 "\t-@${rm} %s 2>$(NUL)\n",
1603 temp_exp.c_str () );
1604 fprintf ( fMakefile, "\t$(ECHO_RSYM)\n" );
1605 fprintf ( fMakefile,
1606 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1607 }
1608
1609
1610 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
1611 const Module& module_ )
1612
1613 : MingwModuleHandler ( module_ )
1614 {
1615 }
1616
1617 void
1618 MingwStaticLibraryModuleHandler::Process ()
1619 {
1620 GenerateStaticLibraryModuleTarget ();
1621 }
1622
1623 void
1624 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
1625 {
1626 GenerateRules ();
1627 }
1628
1629
1630 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
1631 const Module& module_ )
1632
1633 : MingwModuleHandler ( module_ )
1634 {
1635 }
1636
1637 void
1638 MingwObjectLibraryModuleHandler::Process ()
1639 {
1640 GenerateObjectLibraryModuleTarget ();
1641 }
1642
1643 void
1644 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
1645 {
1646 GenerateRules ();
1647 }
1648
1649
1650 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
1651 const Module& module_ )
1652
1653 : MingwModuleHandler ( module_ )
1654 {
1655 }
1656
1657 void
1658 MingwKernelModeDLLModuleHandler::Process ()
1659 {
1660 GenerateKernelModeDLLModuleTarget ();
1661 }
1662
1663 void
1664 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
1665 {
1666 string targetMacro ( GetTargetMacro (module) );
1667 string workingDirectory = GetWorkingDirectory ( );
1668 string objectsMacro = GetObjectsMacro ( module );
1669 string linkDepsMacro = GetLinkingDependenciesMacro ();
1670 string libsMacro = GetLibsMacro ();
1671
1672 GenerateImportLibraryTargetIfNeeded ();
1673
1674 if ( module.non_if_data.files.size () > 0 )
1675 {
1676 GenerateRules ();
1677
1678 string dependencies =
1679 objectsMacro + " " + linkDepsMacro;
1680
1681 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1682 module.entrypoint.c_str (),
1683 module.baseaddress.c_str () );
1684 GenerateLinkerCommand ( dependencies,
1685 "${gcc}",
1686 linkerParameters,
1687 objectsMacro,
1688 libsMacro );
1689 }
1690 else
1691 {
1692 GeneratePhonyTarget();
1693 }
1694 }
1695
1696
1697 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
1698 const Module& module_ )
1699
1700 : MingwModuleHandler ( module_ )
1701 {
1702 }
1703
1704 void
1705 MingwKernelModeDriverModuleHandler::Process ()
1706 {
1707 GenerateKernelModeDriverModuleTarget ();
1708 }
1709
1710
1711 void
1712 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
1713 {
1714 string targetMacro ( GetTargetMacro (module) );
1715 string workingDirectory = GetWorkingDirectory ();
1716 string objectsMacro = GetObjectsMacro ( module );
1717 string linkDepsMacro = GetLinkingDependenciesMacro ();
1718 string libsMacro = GetLibsMacro ();
1719
1720 GenerateImportLibraryTargetIfNeeded ();
1721
1722 if ( module.non_if_data.files.size () > 0 )
1723 {
1724 GenerateRules ();
1725
1726 string dependencies = objectsMacro + " " + linkDepsMacro;
1727
1728 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1729 module.entrypoint.c_str (),
1730 module.baseaddress.c_str () );
1731 GenerateLinkerCommand ( dependencies,
1732 "${gcc}",
1733 linkerParameters,
1734 objectsMacro,
1735 libsMacro );
1736 }
1737 else
1738 {
1739 GeneratePhonyTarget();
1740 }
1741 }
1742
1743
1744 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
1745 const Module& module_ )
1746
1747 : MingwModuleHandler ( module_ )
1748 {
1749 }
1750
1751 void
1752 MingwNativeDLLModuleHandler::Process ()
1753 {
1754 GenerateNativeDLLModuleTarget ();
1755 }
1756
1757 void
1758 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
1759 {
1760 string targetMacro ( GetTargetMacro (module) );
1761 string workingDirectory = GetWorkingDirectory ( );
1762 string objectsMacro = GetObjectsMacro ( module );
1763 string linkDepsMacro = GetLinkingDependenciesMacro ();
1764 string libsMacro = GetLibsMacro ();
1765
1766 GenerateImportLibraryTargetIfNeeded ();
1767
1768 if ( module.non_if_data.files.size () > 0 )
1769 {
1770 GenerateRules ();
1771
1772 string dependencies =
1773 objectsMacro + " " + linkDepsMacro;
1774
1775 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1776 module.entrypoint.c_str (),
1777 module.baseaddress.c_str () );
1778 GenerateLinkerCommand ( dependencies,
1779 "${gcc}",
1780 linkerParameters,
1781 objectsMacro,
1782 libsMacro );
1783 }
1784 else
1785 {
1786 GeneratePhonyTarget();
1787 }
1788 }
1789
1790
1791 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
1792 const Module& module_ )
1793
1794 : MingwModuleHandler ( module_ )
1795 {
1796 }
1797
1798 void
1799 MingwNativeCUIModuleHandler::Process ()
1800 {
1801 GenerateNativeCUIModuleTarget ();
1802 }
1803
1804 void
1805 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
1806 {
1807 string targetMacro ( GetTargetMacro (module) );
1808 string workingDirectory = GetWorkingDirectory ( );
1809 string objectsMacro = GetObjectsMacro ( module );
1810 string linkDepsMacro = GetLinkingDependenciesMacro ();
1811 string libsMacro = GetLibsMacro ();
1812
1813 GenerateImportLibraryTargetIfNeeded ();
1814
1815 if ( module.non_if_data.files.size () > 0 )
1816 {
1817 GenerateRules ();
1818
1819 string dependencies =
1820 objectsMacro + " " + linkDepsMacro;
1821
1822 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1823 module.entrypoint.c_str (),
1824 module.baseaddress.c_str () );
1825 GenerateLinkerCommand ( dependencies,
1826 "${gcc}",
1827 linkerParameters,
1828 objectsMacro,
1829 libsMacro );
1830 }
1831 else
1832 {
1833 GeneratePhonyTarget();
1834 }
1835 }
1836
1837
1838 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
1839 const Module& module_ )
1840
1841 : MingwModuleHandler ( module_ )
1842 {
1843 }
1844
1845 void
1846 MingwWin32DLLModuleHandler::Process ()
1847 {
1848 GenerateExtractWineDLLResourcesTarget ();
1849 GenerateWin32DLLModuleTarget ();
1850 }
1851
1852 void
1853 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ()
1854 {
1855 fprintf ( fMakefile, ".PHONY: %s_extractresources\n\n",
1856 module.name.c_str () );
1857 fprintf ( fMakefile, "%s_extractresources: $(BIN2RES_TARGET)\n",
1858 module.name.c_str () );
1859 const vector<File*>& files = module.non_if_data.files;
1860 for ( size_t i = 0; i < files.size (); i++ )
1861 {
1862 File& file = *files[i];
1863 string extension = GetExtension ( file.name );
1864 if ( extension == ".rc" || extension == ".RC" )
1865 {
1866 string resource = FixupTargetFilename ( file.name );
1867 fprintf ( fMakefile, "\t$(ECHO_BIN2RES)\n" );
1868 fprintf ( fMakefile, "\t@:echo ${bin2res} -f -x %s\n",
1869 resource.c_str () );
1870 }
1871 }
1872 fprintf ( fMakefile, "\n");
1873 }
1874
1875 void
1876 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
1877 {
1878 string targetMacro ( GetTargetMacro (module) );
1879 string workingDirectory = GetWorkingDirectory ( );
1880 string objectsMacro = GetObjectsMacro ( module );
1881 string linkDepsMacro = GetLinkingDependenciesMacro ();
1882 string libsMacro = GetLibsMacro ();
1883
1884 GenerateImportLibraryTargetIfNeeded ();
1885
1886 if ( module.non_if_data.files.size () > 0 )
1887 {
1888 GenerateRules ();
1889
1890 string dependencies = objectsMacro + " " + linkDepsMacro;
1891
1892 string linker;
1893 if ( module.cplusplus )
1894 linker = "${gpp}";
1895 else
1896 linker = "${gcc}";
1897
1898 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1899 module.entrypoint.c_str (),
1900 module.baseaddress.c_str () );
1901 GenerateLinkerCommand ( dependencies,
1902 linker,
1903 linkerParameters,
1904 objectsMacro,
1905 libsMacro );
1906 }
1907 else
1908 {
1909 GeneratePhonyTarget();
1910 }
1911 }
1912
1913
1914 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
1915 const Module& module_ )
1916
1917 : MingwModuleHandler ( module_ )
1918 {
1919 }
1920
1921 void
1922 MingwWin32CUIModuleHandler::Process ()
1923 {
1924 GenerateWin32CUIModuleTarget ();
1925 }
1926
1927 void
1928 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
1929 {
1930 string targetMacro ( GetTargetMacro (module) );
1931 string workingDirectory = GetWorkingDirectory ( );
1932 string objectsMacro = GetObjectsMacro ( module );
1933 string linkDepsMacro = GetLinkingDependenciesMacro ();
1934 string libsMacro = GetLibsMacro ();
1935
1936 GenerateImportLibraryTargetIfNeeded ();
1937
1938 if ( module.non_if_data.files.size () > 0 )
1939 {
1940 GenerateRules ();
1941
1942 string dependencies =
1943 objectsMacro + " " + linkDepsMacro;
1944
1945 string linker;
1946 if ( module.cplusplus )
1947 linker = "${gpp}";
1948 else
1949 linker = "${gcc}";
1950
1951 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1952 module.entrypoint.c_str (),
1953 module.baseaddress.c_str () );
1954 GenerateLinkerCommand ( dependencies,
1955 linker,
1956 linkerParameters,
1957 objectsMacro,
1958 libsMacro );
1959 }
1960 else
1961 {
1962 GeneratePhonyTarget();
1963 }
1964 }
1965
1966
1967 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
1968 const Module& module_ )
1969
1970 : MingwModuleHandler ( module_ )
1971 {
1972 }
1973
1974 void
1975 MingwWin32GUIModuleHandler::Process ()
1976 {
1977 GenerateWin32GUIModuleTarget ();
1978 }
1979
1980 void
1981 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
1982 {
1983 string targetMacro ( GetTargetMacro (module) );
1984 string workingDirectory = GetWorkingDirectory ( );
1985 string objectsMacro = GetObjectsMacro ( module );
1986 string linkDepsMacro = GetLinkingDependenciesMacro ();
1987 string libsMacro = GetLibsMacro ();
1988
1989 GenerateImportLibraryTargetIfNeeded ();
1990
1991 if ( module.non_if_data.files.size () > 0 )
1992 {
1993 GenerateRules ();
1994
1995 string dependencies =
1996 objectsMacro + " " + linkDepsMacro;
1997
1998 string linker;
1999 if ( module.cplusplus )
2000 linker = "${gpp}";
2001 else
2002 linker = "${gcc}";
2003
2004 string linkerParameters = ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2005 module.entrypoint.c_str (),
2006 module.baseaddress.c_str () );
2007 GenerateLinkerCommand ( dependencies,
2008 linker,
2009 linkerParameters,
2010 objectsMacro,
2011 libsMacro );
2012 }
2013 else
2014 {
2015 GeneratePhonyTarget();
2016 }
2017 }
2018
2019
2020 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
2021 const Module& module_ )
2022
2023 : MingwModuleHandler ( module_ )
2024 {
2025 }
2026
2027 void
2028 MingwBootLoaderModuleHandler::Process ()
2029 {
2030 GenerateBootLoaderModuleTarget ();
2031 }
2032
2033 void
2034 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
2035 {
2036 string targetName ( module.GetTargetName () );
2037 string targetMacro ( GetTargetMacro (module) );
2038 string workingDirectory = GetWorkingDirectory ();
2039 string junk_tmp = ros_temp + module.name + ".junk.tmp";
2040 CLEAN_FILE ( junk_tmp );
2041 string objectsMacro = GetObjectsMacro ( module );
2042 string linkDepsMacro = GetLinkingDependenciesMacro ();
2043 string libsMacro = GetLibsMacro ();
2044
2045 GenerateRules ();
2046
2047 fprintf ( fMakefile, "%s: %s %s %s\n",
2048 targetMacro.c_str (),
2049 objectsMacro.c_str (),
2050 linkDepsMacro.c_str (),
2051 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
2052
2053 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
2054
2055 fprintf ( fMakefile,
2056 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2057 GetLinkerMacro ().c_str (),
2058 junk_tmp.c_str (),
2059 objectsMacro.c_str (),
2060 linkDepsMacro.c_str () );
2061 fprintf ( fMakefile,
2062 "\t${objcopy} -O binary %s $@\n",
2063 junk_tmp.c_str () );
2064 fprintf ( fMakefile,
2065 "\t-@${rm} %s 2>$(NUL)\n",
2066 junk_tmp.c_str () );
2067 }
2068
2069
2070 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
2071 const Module& module_ )
2072
2073 : MingwModuleHandler ( module_ )
2074 {
2075 }
2076
2077 void
2078 MingwBootSectorModuleHandler::Process ()
2079 {
2080 GenerateBootSectorModuleTarget ();
2081 }
2082
2083 void
2084 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
2085 {
2086 string objectsMacro = GetObjectsMacro ( module );
2087
2088 GenerateRules ();
2089
2090 fprintf ( fMakefile, ".PHONY: %s\n\n",
2091 module.name.c_str ());
2092 fprintf ( fMakefile,
2093 "%s: %s\n",
2094 module.name.c_str (),
2095 objectsMacro.c_str () );
2096 }
2097
2098
2099 MingwIsoModuleHandler::MingwIsoModuleHandler (
2100 const Module& module_ )
2101
2102 : MingwModuleHandler ( module_ )
2103 {
2104 }
2105
2106 void
2107 MingwIsoModuleHandler::Process ()
2108 {
2109 GenerateIsoModuleTarget ();
2110 }
2111
2112 void
2113 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
2114 const string& bootcdDirectory )
2115 {
2116 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2117 {
2118 const Module& m = *module.project.modules[i];
2119 if ( m.bootstrap != NULL )
2120 {
2121 string targetFilenameNoFixup ( bootcdDirectory + SSEP + m.bootstrap->base + SSEP + m.bootstrap->nameoncd );
2122 string targetFilename ( GetTargetMacro ( module ) );
2123 fprintf ( fMakefile,
2124 "\t${cp} %s %s\n",
2125 m.GetPath ().c_str (),
2126 targetFilename.c_str () );
2127 }
2128 }
2129 }
2130
2131 void
2132 MingwIsoModuleHandler::OutputCdfileCopyCommands (
2133 const string& bootcdDirectory )
2134 {
2135 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2136 {
2137 const CDFile& cdfile = *module.project.cdfiles[i];
2138 string targetFilenameNoFixup = bootcdDirectory + SSEP + cdfile.base + SSEP + cdfile.nameoncd;
2139 string targetFilename = GetTargetMacro(module);
2140 fprintf ( fMakefile,
2141 "\t${cp} %s %s\n",
2142 cdfile.GetPath ().c_str (),
2143 targetFilename.c_str () );
2144 }
2145 }
2146
2147 string
2148 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string& bootcdDirectory )
2149 {
2150 string directories;
2151 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2152 {
2153 const Module& m = *module.project.modules[i];
2154 if ( m.bootstrap != NULL )
2155 {
2156 string targetDirectory ( bootcdDirectory + SSEP + m.bootstrap->base );
2157 if ( directories.size () > 0 )
2158 directories += " ";
2159 directories += PassThruCacheDirectory (
2160 FixupTargetFilename ( targetDirectory ),
2161 true );
2162 }
2163 }
2164 return directories;
2165 }
2166
2167 string
2168 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string& bootcdDirectory )
2169 {
2170 string directories;
2171 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2172 {
2173 const CDFile& cdfile = *module.project.cdfiles[i];
2174 string targetDirectory ( bootcdDirectory + SSEP + cdfile.base );
2175 if ( directories.size () > 0 )
2176 directories += " ";
2177 directories += PassThruCacheDirectory (
2178 FixupTargetFilename ( targetDirectory ),
2179 true );
2180 }
2181 return directories;
2182 }
2183
2184 string
2185 MingwIsoModuleHandler::GetCdDirectories ( const string& bootcdDirectory )
2186 {
2187 string directories = GetBootstrapCdDirectories ( bootcdDirectory );
2188 directories += " " + GetNonModuleCdDirectories ( bootcdDirectory );
2189 return directories;
2190 }
2191
2192 void
2193 MingwIsoModuleHandler::GetBootstrapCdFiles (
2194 vector<string>& out ) const
2195 {
2196 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2197 {
2198 const Module& m = *module.project.modules[i];
2199 if ( m.bootstrap != NULL )
2200 out.push_back ( FixupTargetFilename ( m.GetPath () ) );
2201 }
2202 }
2203
2204 void
2205 MingwIsoModuleHandler::GetNonModuleCdFiles (
2206 vector<string>& out ) const
2207 {
2208 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2209 {
2210 const CDFile& cdfile = *module.project.cdfiles[i];
2211 out.push_back ( NormalizeFilename ( cdfile.GetPath () ) );
2212 }
2213 }
2214
2215 void
2216 MingwIsoModuleHandler::GetCdFiles (
2217 vector<string>& out ) const
2218 {
2219 GetBootstrapCdFiles ( out );
2220 GetNonModuleCdFiles ( out );
2221 }
2222
2223 void
2224 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
2225 {
2226 string bootcdDirectory = "cd";
2227 string isoboot = FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );
2228 string bootcdReactosNoFixup = bootcdDirectory + "/reactos";
2229 string bootcdReactos = PassThruCacheDirectory (
2230 FixupTargetFilename ( bootcdReactosNoFixup ),
2231 true );
2232 CLEAN_FILE ( bootcdReactos );
2233 string reactosInf = ros_temp + FixupTargetFilename ( bootcdReactosNoFixup + "/reactos.inf" );
2234 string reactosDff = NormalizeFilename ( "bootdata/packages/reactos.dff" );
2235 string cdDirectories = GetCdDirectories ( bootcdDirectory );
2236 vector<string> vCdFiles;
2237 GetCdFiles ( vCdFiles );
2238 string cdFiles = v2s ( vCdFiles, 5 );
2239
2240 fprintf ( fMakefile, ".PHONY: %s\n\n",
2241 module.name.c_str ());
2242 fprintf ( fMakefile,
2243 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
2244 module.name.c_str (),
2245 isoboot.c_str (),
2246 bootcdReactos.c_str (),
2247 cdDirectories.c_str (),
2248 cdFiles.c_str () );
2249 fprintf ( fMakefile, "\t$(ECHO_CABMAN)\n" );
2250 fprintf ( fMakefile,
2251 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I\n",
2252 reactosDff.c_str (),
2253 bootcdReactos.c_str () );
2254 fprintf ( fMakefile,
2255 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2256 reactosDff.c_str (),
2257 reactosInf.c_str (),
2258 bootcdReactos.c_str ());
2259 fprintf ( fMakefile,
2260 "\t-@${rm} %s 2>$(NUL)\n",
2261 reactosInf.c_str () );
2262 OutputBootstrapfileCopyCommands ( bootcdDirectory );
2263 OutputCdfileCopyCommands ( bootcdDirectory );
2264 fprintf ( fMakefile, "\t$(ECHO_CDMAKE)\n" );
2265 fprintf ( fMakefile,
2266 "\t$(Q)$(CDMAKE_TARGET) -v -m -b %s %s REACTOS ReactOS.iso\n",
2267 isoboot.c_str (),
2268 bootcdDirectory.c_str () );
2269 fprintf ( fMakefile,
2270 "\n" );
2271 }
2272
2273
2274 MingwTestModuleHandler::MingwTestModuleHandler (
2275 const Module& module_ )
2276
2277 : MingwModuleHandler ( module_ )
2278 {
2279 }
2280
2281 void
2282 MingwTestModuleHandler::Process ()
2283 {
2284 GenerateTestModuleTarget ();
2285 }
2286
2287 void
2288 MingwTestModuleHandler::GenerateTestModuleTarget ()
2289 {
2290 string targetMacro ( GetTargetMacro (module) );
2291 string workingDirectory = GetWorkingDirectory ( );
2292 string objectsMacro = GetObjectsMacro ( module );
2293 string linkDepsMacro = GetLinkingDependenciesMacro ();
2294 string libsMacro = GetLibsMacro ();
2295
2296 GenerateImportLibraryTargetIfNeeded ();
2297
2298 if ( module.non_if_data.files.size () > 0 )
2299 {
2300 GenerateRules ();
2301
2302 string dependencies = objectsMacro + " " + linkDepsMacro;
2303
2304 string linker;
2305 if ( module.cplusplus )
2306 linker = "${gpp}";
2307 else
2308 linker = "${gcc}";
2309
2310 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2311 module.entrypoint.c_str (),
2312 module.baseaddress.c_str () );
2313 GenerateLinkerCommand ( dependencies,
2314 linker,
2315 linkerParameters,
2316 objectsMacro,
2317 libsMacro );
2318 }
2319 else
2320 {
2321 GeneratePhonyTarget();
2322 }
2323 }