Merge 12736:14980 from trunk
[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 );
12
13 static string ros_temp = "$(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 GetTargetMacro ( const Module& module, bool with_dollar )
45 {
46 string s ( module.name );
47 strupr ( &s[0] );
48 s += "_TARGET";
49 if ( with_dollar )
50 return ssprintf ( "$(%s)", s.c_str() );
51 return s;
52 }
53
54 MingwModuleHandler::MingwModuleHandler (
55 const Module& module_ )
56
57 : module(module_)
58 {
59 }
60
61 MingwModuleHandler::~MingwModuleHandler()
62 {
63 }
64
65 /*static*/ void
66 MingwModuleHandler::SetBackend ( MingwBackend* backend_ )
67 {
68 backend = backend_;
69 }
70
71 /*static*/ void
72 MingwModuleHandler::SetMakefile ( FILE* f )
73 {
74 fMakefile = f;
75 }
76
77 /*static*/ void
78 MingwModuleHandler::SetUsePch ( bool b )
79 {
80 use_pch = b;
81 }
82
83 /* static*/ string
84 MingwModuleHandler::RemoveVariables ( string path)
85 {
86 size_t i = path.find ( '$' );
87 if ( i != string::npos )
88 {
89 size_t j = path.find ( ')', i );
90 if ( j != string::npos )
91 {
92 if ( j + 2 < path.length () && path[j + 1] == CSEP )
93 return path.substr ( j + 2);
94 else
95 return path.substr ( j + 1);
96 }
97 }
98 return path;
99 }
100
101 /*static*/ string
102 MingwModuleHandler::PassThruCacheDirectory (
103 const string &file,
104 Directory* directoryTree )
105 {
106 string directory ( GetDirectory ( RemoveVariables ( file ) ) );
107 string generatedFilesDirectory = backend->AddDirectoryTarget ( directory,
108 directoryTree );
109 if ( directory.find ( generatedFilesDirectory ) != string::npos )
110 /* This path already includes the generated files directory variable */
111 return file;
112 else
113 return generatedFilesDirectory + SSEP + file;
114 }
115
116 /*static*/ Directory*
117 MingwModuleHandler::GetTargetDirectoryTree (
118 const Module& module )
119 {
120 if ( module.type == StaticLibrary )
121 return backend->intermediateDirectory;
122 return backend->outputDirectory;
123 }
124
125 /*static*/ string
126 MingwModuleHandler::GetTargetFilename (
127 const Module& module,
128 string_list* pclean_files )
129 {
130 string target = PassThruCacheDirectory (
131 NormalizeFilename ( module.GetPath () ),
132 GetTargetDirectoryTree ( module ) );
133 if ( pclean_files )
134 {
135 string_list& clean_files = *pclean_files;
136 CLEAN_FILE ( target );
137 }
138 return target;
139 }
140
141 /*static*/ string
142 MingwModuleHandler::GetImportLibraryFilename (
143 const Module& module,
144 string_list* pclean_files )
145 {
146 string target = PassThruCacheDirectory (
147 NormalizeFilename ( module.GetDependencyPath () ),
148 backend->intermediateDirectory );
149 if ( pclean_files )
150 {
151 string_list& clean_files = *pclean_files;
152 CLEAN_FILE ( target );
153 }
154 return target;
155 }
156
157 /*static*/ MingwModuleHandler*
158 MingwModuleHandler::InstanciateHandler (
159 const Module& module,
160 MingwBackend* backend )
161 {
162 MingwModuleHandler* handler;
163 switch ( module.type )
164 {
165 case BuildTool:
166 handler = new MingwBuildToolModuleHandler ( module );
167 break;
168 case StaticLibrary:
169 handler = new MingwStaticLibraryModuleHandler ( module );
170 break;
171 case ObjectLibrary:
172 handler = new MingwObjectLibraryModuleHandler ( module );
173 break;
174 case Kernel:
175 handler = new MingwKernelModuleHandler ( module );
176 break;
177 case NativeCUI:
178 handler = new MingwNativeCUIModuleHandler ( module );
179 break;
180 case Win32CUI:
181 handler = new MingwWin32CUIModuleHandler ( module );
182 break;
183 case Win32GUI:
184 handler = new MingwWin32GUIModuleHandler ( module );
185 break;
186 case KernelModeDLL:
187 handler = new MingwKernelModeDLLModuleHandler ( module );
188 break;
189 case NativeDLL:
190 handler = new MingwNativeDLLModuleHandler ( module );
191 break;
192 case Win32DLL:
193 handler = new MingwWin32DLLModuleHandler ( module );
194 break;
195 case KernelModeDriver:
196 handler = new MingwKernelModeDriverModuleHandler ( module );
197 break;
198 case BootLoader:
199 handler = new MingwBootLoaderModuleHandler ( module );
200 break;
201 case BootSector:
202 handler = new MingwBootSectorModuleHandler ( module );
203 break;
204 case Iso:
205 handler = new MingwIsoModuleHandler ( module );
206 break;
207 case LiveIso:
208 handler = new MingwLiveIsoModuleHandler ( module );
209 break;
210 case Test:
211 handler = new MingwTestModuleHandler ( module );
212 break;
213 case RpcServer:
214 handler = new MingwRpcServerModuleHandler ( module );
215 break;
216 case RpcClient:
217 handler = new MingwRpcClientModuleHandler ( module );
218 break;
219 default:
220 throw UnknownModuleTypeException (
221 module.node.location,
222 module.type );
223 break;
224 }
225 return handler;
226 }
227
228 string
229 MingwModuleHandler::GetWorkingDirectory () const
230 {
231 return ".";
232 }
233
234 string
235 MingwModuleHandler::GetBasename ( const string& filename ) const
236 {
237 size_t index = filename.find_last_of ( '.' );
238 if ( index != string::npos )
239 return filename.substr ( 0, index );
240 return "";
241 }
242
243 string
244 MingwModuleHandler::GetActualSourceFilename (
245 const string& filename ) const
246 {
247 string extension = GetExtension ( filename );
248 if ( extension == ".spec" || extension == ".SPEC" )
249 {
250 string basename = GetBasename ( filename );
251 return PassThruCacheDirectory ( NormalizeFilename ( basename + ".stubs.c" ),
252 backend->intermediateDirectory );
253 }
254 else if ( extension == ".idl" || extension == ".IDL" )
255 {
256 string basename = GetBasename ( filename );
257 string newname;
258 if ( module.type == RpcServer )
259 newname = basename + "_s.c";
260 else
261 newname = basename + "_c.c";
262 return PassThruCacheDirectory ( NormalizeFilename ( newname ),
263 backend->intermediateDirectory );
264 }
265 else
266 return filename;
267 }
268
269 string
270 MingwModuleHandler::GetModuleArchiveFilename () const
271 {
272 if ( module.type == StaticLibrary )
273 return GetTargetFilename ( module, NULL );
274 return PassThruCacheDirectory ( ReplaceExtension (
275 NormalizeFilename ( module.GetPath () ),
276 ".temp.a" ),
277 backend->intermediateDirectory );
278 }
279
280 bool
281 MingwModuleHandler::IsGeneratedFile ( const File& file ) const
282 {
283 string extension = GetExtension ( file.name );
284 return ( extension == ".spec" || extension == ".SPEC" );
285 }
286
287 /*static*/ bool
288 MingwModuleHandler::ReferenceObjects (
289 const Module& module )
290 {
291 if ( module.type == ObjectLibrary )
292 return true;
293 if ( module.type == RpcServer )
294 return true;
295 if ( module.type == RpcClient )
296 return true;
297 return false;
298 }
299
300 string
301 MingwModuleHandler::GetImportLibraryDependency (
302 const Module& importedModule )
303 {
304 string dep;
305 if ( ReferenceObjects ( importedModule ) )
306 dep = GetTargetMacro ( importedModule );
307 else
308 dep = GetImportLibraryFilename ( importedModule, NULL );
309 return dep;
310 }
311
312 void
313 MingwModuleHandler::GetTargets ( const Module& dependencyModule,
314 string_list& targets )
315 {
316 if ( dependencyModule.invocations.size () > 0 )
317 {
318 for ( size_t i = 0; i < dependencyModule.invocations.size (); i++ )
319 {
320 Invoke& invoke = *dependencyModule.invocations[i];
321 invoke.GetTargets ( targets );
322 }
323 }
324 else
325 targets.push_back ( GetImportLibraryDependency ( dependencyModule ) );
326 }
327
328 void
329 MingwModuleHandler::GetModuleDependencies (
330 string_list& dependencies )
331 {
332 size_t iend = module.dependencies.size ();
333
334 if ( iend == 0 )
335 return;
336
337 for ( size_t i = 0; i < iend; i++ )
338 {
339 const Dependency& dependency = *module.dependencies[i];
340 const Module& dependencyModule = *dependency.dependencyModule;
341 GetTargets ( dependencyModule,
342 dependencies );
343 }
344 GetDefinitionDependencies ( dependencies );
345 }
346
347 void
348 MingwModuleHandler::GetSourceFilenames (
349 string_list& list,
350 bool includeGeneratedFiles ) const
351 {
352 size_t i;
353
354 const vector<File*>& files = module.non_if_data.files;
355 for ( i = 0; i < files.size (); i++ )
356 {
357 if ( includeGeneratedFiles || !IsGeneratedFile ( *files[i] ) )
358 {
359 list.push_back (
360 GetActualSourceFilename ( files[i]->name ) );
361 }
362 }
363 // intentionally make a copy so that we can append more work in
364 // the middle of processing without having to go recursive
365 vector<If*> v = module.non_if_data.ifs;
366 for ( i = 0; i < v.size (); i++ )
367 {
368 size_t j;
369 If& rIf = *v[i];
370 // check for sub-ifs to add to list
371 const vector<If*>& ifs = rIf.data.ifs;
372 for ( j = 0; j < ifs.size (); j++ )
373 v.push_back ( ifs[j] );
374 const vector<File*>& files = rIf.data.files;
375 for ( j = 0; j < files.size (); j++ )
376 {
377 File& file = *files[j];
378 if ( includeGeneratedFiles || !IsGeneratedFile ( file ) )
379 {
380 list.push_back (
381 GetActualSourceFilename ( file.name ) );
382 }
383 }
384 }
385 }
386
387 void
388 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
389 string_list& list ) const
390 {
391 GetSourceFilenames ( list, false );
392 }
393
394 string
395 MingwModuleHandler::GetObjectFilename (
396 const string& sourceFilename,
397 string_list* pclean_files ) const
398 {
399 Directory* directoryTree;
400
401 string newExtension;
402 string extension = GetExtension ( sourceFilename );
403 if ( extension == ".rc" || extension == ".RC" )
404 newExtension = ".coff";
405 else if ( extension == ".spec" || extension == ".SPEC" )
406 newExtension = ".stubs.o";
407 else if ( extension == ".idl" || extension == ".IDL" )
408 {
409 if ( module.type == RpcServer )
410 newExtension = "_s.o";
411 else
412 newExtension = "_c.o";
413 }
414 else
415 newExtension = ".o";
416
417 if ( module.type == BootSector )
418 directoryTree = backend->outputDirectory;
419 else
420 directoryTree = backend->intermediateDirectory;
421
422 string obj_file = PassThruCacheDirectory (
423 NormalizeFilename ( ReplaceExtension (
424 RemoveVariables ( sourceFilename ),
425 newExtension ) ),
426 directoryTree );
427 if ( pclean_files )
428 {
429 string_list& clean_files = *pclean_files;
430 CLEAN_FILE ( obj_file );
431 }
432 return obj_file;
433 }
434
435 void
436 MingwModuleHandler::GenerateCleanTarget () const
437 {
438 if ( 0 == clean_files.size() )
439 return;
440 fprintf ( fMakefile, ".PHONY: %s_clean\n", module.name.c_str() );
441 fprintf ( fMakefile, "%s_clean:\n\t-@${rm}", module.name.c_str() );
442 for ( size_t i = 0; i < clean_files.size(); i++ )
443 {
444 if ( 9==((i+1)%10) )
445 fprintf ( fMakefile, " 2>$(NUL)\n\t-@${rm}" );
446 fprintf ( fMakefile, " %s", clean_files[i].c_str() );
447 }
448 fprintf ( fMakefile, " 2>$(NUL)\n" );
449 fprintf ( fMakefile, "clean: %s_clean\n\n", module.name.c_str() );
450 }
451
452 void
453 MingwModuleHandler::GenerateInstallTarget () const
454 {
455 if ( module.installName.length () == 0 )
456 return;
457 fprintf ( fMakefile, ".PHONY: %s_install\n", module.name.c_str() );
458 fprintf ( fMakefile, "%s_install:\n", module.name.c_str() );
459 string sourceFilename = MingwModuleHandler::PassThruCacheDirectory (
460 NormalizeFilename ( module.GetPath () ),
461 backend->outputDirectory );
462 string normalizedTargetFilename = MingwModuleHandler::PassThruCacheDirectory (
463 NormalizeFilename ( module.installBase + SSEP + module.installName ),
464 backend->installDirectory );
465 fprintf ( fMakefile,
466 "\t$(ECHO_CP)\n" );
467 fprintf ( fMakefile,
468 "\t${cp} %s %s 1>$(NUL)\n",
469 sourceFilename.c_str (),
470 normalizedTargetFilename.c_str () );
471 }
472
473 string
474 MingwModuleHandler::GetObjectFilenames ()
475 {
476 const vector<File*>& files = module.non_if_data.files;
477 if ( files.size () == 0 )
478 return "";
479
480 string objectFilenames ( "" );
481 for ( size_t i = 0; i < files.size (); i++ )
482 {
483 if ( objectFilenames.size () > 0 )
484 objectFilenames += " ";
485 objectFilenames +=
486 GetObjectFilename ( files[i]->name, NULL );
487 }
488 return objectFilenames;
489 }
490
491 string
492 MingwModuleHandler::GenerateGccDefineParametersFromVector (
493 const vector<Define*>& defines ) const
494 {
495 string parameters;
496 for ( size_t i = 0; i < defines.size (); i++ )
497 {
498 Define& define = *defines[i];
499 if (parameters.length () > 0)
500 parameters += " ";
501 parameters += "-D";
502 parameters += define.name;
503 if (define.value.length () > 0)
504 {
505 parameters += "=";
506 parameters += define.value;
507 }
508 }
509 return parameters;
510 }
511
512 string
513 MingwModuleHandler::GenerateGccDefineParameters () const
514 {
515 string parameters = GenerateGccDefineParametersFromVector ( module.project.non_if_data.defines );
516 string s = GenerateGccDefineParametersFromVector ( module.non_if_data.defines );
517 if ( s.length () > 0 )
518 {
519 parameters += " ";
520 parameters += s;
521 }
522 return parameters;
523 }
524
525 string
526 MingwModuleHandler::ConcatenatePaths (
527 const string& path1,
528 const string& path2 ) const
529 {
530 if ( ( path1.length () == 0 ) || ( path1 == "." ) || ( path1 == "./" ) )
531 return path2;
532 if ( path1[path1.length ()] == CSEP )
533 return path1 + path2;
534 else
535 return path1 + CSEP + path2;
536 }
537
538 string
539 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector<Include*>& includes ) const
540 {
541 string parameters;
542 for ( size_t i = 0; i < includes.size (); i++ )
543 {
544 Include& include = *includes[i];
545 if ( parameters.length () > 0 )
546 parameters += " ";
547 parameters += "-I" + include.directory;
548 }
549 return parameters;
550 }
551
552 string
553 MingwModuleHandler::GenerateGccIncludeParameters () const
554 {
555 string parameters = GenerateGccIncludeParametersFromVector ( module.non_if_data.includes );
556 string s = GenerateGccIncludeParametersFromVector ( module.project.non_if_data.includes );
557 if ( s.length () > 0 )
558 {
559 parameters += " ";
560 parameters += s;
561 }
562 return parameters;
563 }
564
565
566 string
567 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector<CompilerFlag*>& compilerFlags ) const
568 {
569 string parameters;
570 for ( size_t i = 0; i < compilerFlags.size (); i++ )
571 {
572 CompilerFlag& compilerFlag = *compilerFlags[i];
573 if ( parameters.length () > 0 )
574 parameters += " ";
575 parameters += compilerFlag.flag;
576 }
577 return parameters;
578 }
579
580 string
581 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector<LinkerFlag*>& linkerFlags ) const
582 {
583 string parameters;
584 for ( size_t i = 0; i < linkerFlags.size (); i++ )
585 {
586 LinkerFlag& linkerFlag = *linkerFlags[i];
587 if ( parameters.length () > 0 )
588 parameters += " ";
589 parameters += linkerFlag.flag;
590 }
591 return parameters;
592 }
593
594 string
595 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
596 const vector<Library*>& libraries )
597 {
598 string dependencies ( "" );
599 int wrap_count = 0;
600 for ( size_t i = 0; i < libraries.size (); i++ )
601 {
602 if ( wrap_count++ == 5 )
603 dependencies += " \\\n\t\t", wrap_count = 0;
604 else if ( dependencies.size () > 0 )
605 dependencies += " ";
606 dependencies += GetImportLibraryDependency ( *libraries[i]->imported_module );
607 }
608 return dependencies;
609 }
610
611 string
612 MingwModuleHandler::GenerateLinkerParameters () const
613 {
614 return GenerateLinkerParametersFromVector ( module.linkerFlags );
615 }
616
617 void
618 MingwModuleHandler::GenerateMacro (
619 const char* assignmentOperation,
620 const string& macro,
621 const IfableData& data,
622 const vector<CompilerFlag*>* compilerFlags )
623 {
624 size_t i;
625
626 fprintf (
627 fMakefile,
628 "%s %s",
629 macro.c_str(),
630 assignmentOperation );
631
632 if ( compilerFlags != NULL )
633 {
634 string compilerParameters = GenerateCompilerParametersFromVector ( *compilerFlags );
635 if ( compilerParameters.size () > 0 )
636 {
637 fprintf (
638 fMakefile,
639 " %s",
640 compilerParameters.c_str () );
641 }
642 }
643
644 for ( i = 0; i < data.includes.size(); i++ )
645 {
646 fprintf (
647 fMakefile,
648 " -I%s",
649 data.includes[i]->directory.c_str() );
650 }
651 for ( i = 0; i < data.defines.size(); i++ )
652 {
653 Define& d = *data.defines[i];
654 fprintf (
655 fMakefile,
656 " -D%s",
657 d.name.c_str() );
658 if ( d.value.size() )
659 fprintf (
660 fMakefile,
661 "=%s",
662 d.value.c_str() );
663 }
664 fprintf ( fMakefile, "\n" );
665 }
666
667 void
668 MingwModuleHandler::GenerateMacros (
669 const char* assignmentOperation,
670 const IfableData& data,
671 const vector<CompilerFlag*>* compilerFlags,
672 const vector<LinkerFlag*>* linkerFlags )
673 {
674 size_t i;
675
676 if ( data.includes.size () > 0 || data.defines.size () > 0 )
677 {
678 GenerateMacro ( assignmentOperation,
679 cflagsMacro,
680 data,
681 compilerFlags );
682 GenerateMacro ( assignmentOperation,
683 windresflagsMacro,
684 data,
685 compilerFlags );
686 }
687
688 if ( linkerFlags != NULL )
689 {
690 string linkerParameters = GenerateLinkerParametersFromVector ( *linkerFlags );
691 if ( linkerParameters.size () > 0 )
692 {
693 fprintf (
694 fMakefile,
695 "%s %s %s\n",
696 linkerflagsMacro.c_str (),
697 assignmentOperation,
698 linkerParameters.c_str() );
699 }
700 }
701
702 if ( data.libraries.size () > 0 )
703 {
704 string deps = GenerateImportLibraryDependenciesFromVector ( data.libraries );
705 if ( deps.size () > 0 )
706 {
707 fprintf (
708 fMakefile,
709 "%s %s %s\n",
710 libsMacro.c_str(),
711 assignmentOperation,
712 deps.c_str() );
713 }
714 }
715
716 const vector<If*>& ifs = data.ifs;
717 for ( i = 0; i < ifs.size(); i++ )
718 {
719 If& rIf = *ifs[i];
720 if ( rIf.data.defines.size()
721 || rIf.data.includes.size()
722 || rIf.data.libraries.size()
723 || rIf.data.files.size()
724 || rIf.data.ifs.size() )
725 {
726 fprintf (
727 fMakefile,
728 "ifeq (\"$(%s)\",\"%s\")\n",
729 rIf.property.c_str(),
730 rIf.value.c_str() );
731 GenerateMacros (
732 "+=",
733 rIf.data,
734 NULL,
735 NULL );
736 fprintf (
737 fMakefile,
738 "endif\n\n" );
739 }
740 }
741 }
742
743 void
744 MingwModuleHandler::GenerateObjectMacros (
745 const char* assignmentOperation,
746 const IfableData& data,
747 const vector<CompilerFlag*>* compilerFlags,
748 const vector<LinkerFlag*>* linkerFlags )
749 {
750 size_t i;
751
752 const vector<File*>& files = data.files;
753 if ( files.size () > 0 )
754 {
755 for ( i = 0; i < files.size (); i++ )
756 {
757 File& file = *files[i];
758 if ( file.first )
759 {
760 fprintf ( fMakefile,
761 "%s := %s $(%s)\n",
762 objectsMacro.c_str(),
763 GetObjectFilename (
764 file.name, NULL ).c_str (),
765 objectsMacro.c_str() );
766 }
767 }
768 fprintf (
769 fMakefile,
770 "%s %s",
771 objectsMacro.c_str (),
772 assignmentOperation );
773 for ( i = 0; i < files.size(); i++ )
774 {
775 File& file = *files[i];
776 if ( !file.first )
777 {
778 fprintf (
779 fMakefile,
780 "%s%s",
781 ( i%10 == 9 ? " \\\n\t" : " " ),
782 GetObjectFilename (
783 file.name, NULL ).c_str () );
784 }
785 }
786 fprintf ( fMakefile, "\n" );
787 }
788
789 const vector<If*>& ifs = data.ifs;
790 for ( i = 0; i < ifs.size(); i++ )
791 {
792 If& rIf = *ifs[i];
793 if ( rIf.data.defines.size()
794 || rIf.data.includes.size()
795 || rIf.data.libraries.size()
796 || rIf.data.files.size()
797 || rIf.data.ifs.size() )
798 {
799 fprintf (
800 fMakefile,
801 "ifeq (\"$(%s)\",\"%s\")\n",
802 rIf.property.c_str(),
803 rIf.value.c_str() );
804 GenerateObjectMacros (
805 "+=",
806 rIf.data,
807 NULL,
808 NULL );
809 fprintf (
810 fMakefile,
811 "endif\n\n" );
812 }
813 }
814 }
815
816 void
817 MingwModuleHandler::GenerateGccCommand (
818 const string& sourceFilename,
819 const string& cc,
820 const string& cflagsMacro )
821 {
822 string dependencies = sourceFilename;
823 if ( module.pch && use_pch )
824 dependencies += " " + module.pch->header + ".gch";
825
826 /* WIDL generated headers may be used */
827 dependencies += " " + GetLinkingDependenciesMacro ();
828 dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
829
830 string objectFilename = GetObjectFilename (
831 sourceFilename, &clean_files );
832 fprintf ( fMakefile,
833 "%s: %s | %s\n",
834 objectFilename.c_str (),
835 dependencies.c_str (),
836 GetDirectory ( objectFilename ).c_str () );
837 fprintf ( fMakefile, "\t$(ECHO_CC)\n" );
838 fprintf ( fMakefile,
839 "\t%s -c $< -o $@ %s\n",
840 cc.c_str (),
841 cflagsMacro.c_str () );
842 }
843
844 void
845 MingwModuleHandler::GenerateGccAssemblerCommand (
846 const string& sourceFilename,
847 const string& cc,
848 const string& cflagsMacro )
849 {
850 string dependencies = sourceFilename;
851 dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
852 string objectFilename = GetObjectFilename (
853 sourceFilename, &clean_files );
854 fprintf ( fMakefile,
855 "%s: %s | %s\n",
856 objectFilename.c_str (),
857 dependencies.c_str (),
858 GetDirectory ( objectFilename ).c_str () );
859 fprintf ( fMakefile, "\t$(ECHO_GAS)\n" );
860 fprintf ( fMakefile,
861 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
862 cc.c_str (),
863 cflagsMacro.c_str () );
864 }
865
866 void
867 MingwModuleHandler::GenerateNasmCommand (
868 const string& sourceFilename,
869 const string& nasmflagsMacro )
870 {
871 string dependencies = sourceFilename;
872 dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
873 string objectFilename = GetObjectFilename (
874 sourceFilename, &clean_files );
875 fprintf ( fMakefile,
876 "%s: %s | %s\n",
877 objectFilename.c_str (),
878 dependencies.c_str (),
879 GetDirectory ( objectFilename ).c_str () );
880 fprintf ( fMakefile, "\t$(ECHO_NASM)\n" );
881 fprintf ( fMakefile,
882 "\t%s -f win32 $< -o $@ %s\n",
883 "$(Q)nasm",
884 nasmflagsMacro.c_str () );
885 }
886
887 void
888 MingwModuleHandler::GenerateWindresCommand (
889 const string& sourceFilename,
890 const string& windresflagsMacro )
891 {
892 string dependencies = sourceFilename;
893 dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
894 string objectFilename =
895 GetObjectFilename ( sourceFilename, &clean_files );
896 string rciFilename = ros_temp + module.name + ".rci.tmp";
897 string resFilename = ros_temp + module.name + ".res.tmp";
898 if ( module.useWRC )
899 {
900 fprintf ( fMakefile,
901 "%s: %s $(WRC_TARGET) | %s\n",
902 objectFilename.c_str (),
903 dependencies.c_str (),
904 GetDirectory ( objectFilename ).c_str () );
905 fprintf ( fMakefile, "\t$(ECHO_WRC)\n" );
906 fprintf ( fMakefile,
907 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
908 windresflagsMacro.c_str (),
909 sourceFilename.c_str (),
910 rciFilename.c_str () );
911 fprintf ( fMakefile,
912 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
913 windresflagsMacro.c_str (),
914 rciFilename.c_str (),
915 resFilename.c_str () );
916 fprintf ( fMakefile,
917 "\t-@${rm} %s 2>$(NUL)\n",
918 rciFilename.c_str () );
919 fprintf ( fMakefile,
920 "\t${windres} %s -o $@\n",
921 resFilename.c_str () );
922 fprintf ( fMakefile,
923 "\t-@${rm} %s 2>$(NUL)\n",
924 resFilename.c_str () );
925 }
926 else
927 {
928 fprintf ( fMakefile,
929 "%s: %s $(WRC_TARGET) | %s\n",
930 objectFilename.c_str (),
931 dependencies.c_str (),
932 GetDirectory ( objectFilename ).c_str () );
933 fprintf ( fMakefile, "\t$(ECHO_WRC)\n" );
934 fprintf ( fMakefile,
935 "\t${windres} $(%s) %s -o $@\n",
936 windresflagsMacro.c_str (),
937 sourceFilename.c_str () );
938 }
939 }
940
941 void
942 MingwModuleHandler::GenerateWinebuildCommands (
943 const string& sourceFilename )
944 {
945 string dependencies = sourceFilename;
946 dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
947
948 string basename = GetBasename ( sourceFilename );
949 string def_file = PassThruCacheDirectory (
950 basename + ".spec.def",
951 backend->intermediateDirectory );
952 CLEAN_FILE(def_file);
953
954 string stub_file = PassThruCacheDirectory (
955 basename + ".stubs.c",
956 backend->intermediateDirectory );
957 CLEAN_FILE(stub_file)
958
959 fprintf ( fMakefile,
960 "%s: %s $(WINEBUILD_TARGET)\n",
961 def_file.c_str (),
962 dependencies.c_str () );
963 fprintf ( fMakefile, "\t$(ECHO_WINEBLD)\n" );
964 fprintf ( fMakefile,
965 "\t%s --def=%s -o %s\n",
966 "$(Q)$(WINEBUILD_TARGET)",
967 sourceFilename.c_str (),
968 def_file.c_str () );
969
970 fprintf ( fMakefile,
971 "%s: %s $(WINEBUILD_TARGET)\n",
972 stub_file.c_str (),
973 sourceFilename.c_str () );
974 fprintf ( fMakefile, "\t$(ECHO_WINEBLD)\n" );
975 fprintf ( fMakefile,
976 "\t%s --pedll=%s -o %s\n",
977 "$(Q)$(WINEBUILD_TARGET)",
978 sourceFilename.c_str (),
979 stub_file.c_str () );
980 }
981
982 string
983 MingwModuleHandler::GetWidlFlags ( const File& file )
984 {
985 return file.switches;
986 }
987
988 void
989 MingwModuleHandler::GenerateWidlCommandsServer (
990 const File& file,
991 const string& widlflagsMacro )
992 {
993 string dependencies = file.name;
994 dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
995
996 string basename = GetBasename ( file.name );
997
998 /*string generatedHeaderFilename = PassThruCacheDirectory (
999 basename + ".h",
1000 backend->intermediateDirectory );
1001 CLEAN_FILE(generatedHeaderFilename);
1002 */
1003 string generatedHeaderFilename = basename + "_s.h";
1004 CLEAN_FILE(generatedHeaderFilename);
1005
1006 string generatedServerFilename = PassThruCacheDirectory (
1007 basename + "_s.c",
1008 backend->intermediateDirectory );
1009 CLEAN_FILE(generatedServerFilename);
1010
1011 fprintf ( fMakefile,
1012 "%s %s: %s $(WIDL_TARGET) | %s\n",
1013 generatedServerFilename.c_str (),
1014 generatedHeaderFilename.c_str (),
1015 dependencies.c_str (),
1016 GetDirectory ( generatedServerFilename ).c_str () );
1017 fprintf ( fMakefile, "\t$(ECHO_WIDL)\n" );
1018 fprintf ( fMakefile,
1019 "\t%s %s %s -h -H %s -s -S %s %s\n",
1020 "$(Q)$(WIDL_TARGET)",
1021 GetWidlFlags ( file ).c_str (),
1022 widlflagsMacro.c_str (),
1023 generatedHeaderFilename.c_str (),
1024 generatedServerFilename.c_str (),
1025 file.name.c_str () );
1026 }
1027
1028 void
1029 MingwModuleHandler::GenerateWidlCommandsClient (
1030 const File& file,
1031 const string& widlflagsMacro )
1032 {
1033 string dependencies = file.name;
1034 dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
1035
1036 string basename = GetBasename ( file.name );
1037
1038 /*string generatedHeaderFilename = PassThruCacheDirectory (
1039 basename + ".h",
1040 backend->intermediateDirectory );
1041 CLEAN_FILE(generatedHeaderFilename);
1042 */
1043 string generatedHeaderFilename = basename + "_c.h";
1044 CLEAN_FILE(generatedHeaderFilename);
1045
1046 string generatedClientFilename = PassThruCacheDirectory (
1047 basename + "_c.c",
1048 backend->intermediateDirectory );
1049 CLEAN_FILE(generatedClientFilename);
1050
1051 fprintf ( fMakefile,
1052 "%s %s: %s $(WIDL_TARGET) | %s\n",
1053 generatedClientFilename.c_str (),
1054 generatedHeaderFilename.c_str (),
1055 dependencies.c_str (),
1056 GetDirectory ( generatedClientFilename ).c_str () );
1057 fprintf ( fMakefile, "\t$(ECHO_WIDL)\n" );
1058 fprintf ( fMakefile,
1059 "\t%s %s %s -h -H %s -c -C %s %s\n",
1060 "$(Q)$(WIDL_TARGET)",
1061 GetWidlFlags ( file ).c_str (),
1062 widlflagsMacro.c_str (),
1063 generatedHeaderFilename.c_str (),
1064 generatedClientFilename.c_str (),
1065 file.name.c_str () );
1066 }
1067
1068 void
1069 MingwModuleHandler::GenerateWidlCommands (
1070 const File& file,
1071 const string& widlflagsMacro )
1072 {
1073 if ( module.type == RpcServer )
1074 GenerateWidlCommandsServer ( file,
1075 widlflagsMacro );
1076 else
1077 GenerateWidlCommandsClient ( file,
1078 widlflagsMacro );
1079 }
1080
1081 void
1082 MingwModuleHandler::GenerateCommands (
1083 const File& file,
1084 const string& cc,
1085 const string& cppc,
1086 const string& cflagsMacro,
1087 const string& nasmflagsMacro,
1088 const string& windresflagsMacro,
1089 const string& widlflagsMacro )
1090 {
1091 string extension = GetExtension ( file.name );
1092 if ( extension == ".c" || extension == ".C" )
1093 {
1094 GenerateGccCommand ( file.name,
1095 cc,
1096 cflagsMacro );
1097 return;
1098 }
1099 else if ( extension == ".cc" || extension == ".CC" ||
1100 extension == ".cpp" || extension == ".CPP" ||
1101 extension == ".cxx" || extension == ".CXX" )
1102 {
1103 GenerateGccCommand ( file.name,
1104 cppc,
1105 cflagsMacro );
1106 return;
1107 }
1108 else if ( extension == ".s" || extension == ".S" )
1109 {
1110 GenerateGccAssemblerCommand ( file.name,
1111 cc,
1112 cflagsMacro );
1113 return;
1114 }
1115 else if ( extension == ".asm" || extension == ".ASM" )
1116 {
1117 GenerateNasmCommand ( file.name,
1118 nasmflagsMacro );
1119 return;
1120 }
1121 else if ( extension == ".rc" || extension == ".RC" )
1122 {
1123 GenerateWindresCommand ( file.name,
1124 windresflagsMacro );
1125 return;
1126 }
1127 else if ( extension == ".spec" || extension == ".SPEC" )
1128 {
1129 GenerateWinebuildCommands ( file.name );
1130 GenerateGccCommand ( GetActualSourceFilename ( file.name ),
1131 cc,
1132 cflagsMacro );
1133 return;
1134 }
1135 else if ( extension == ".idl" || extension == ".IDL" )
1136 {
1137 GenerateWidlCommands ( file,
1138 widlflagsMacro );
1139 GenerateGccCommand ( GetActualSourceFilename ( file.name ),
1140 cc,
1141 cflagsMacro );
1142 return;
1143 }
1144
1145 throw InvalidOperationException ( __FILE__,
1146 __LINE__,
1147 "Unsupported filename extension '%s' in file '%s'",
1148 extension.c_str (),
1149 file.name.c_str () );
1150 }
1151
1152 void
1153 MingwModuleHandler::GenerateBuildMapCode ()
1154 {
1155 fprintf ( fMakefile,
1156 "ifeq ($(ROS_BUILDMAP),full)\n" );
1157
1158 string mapFilename = PassThruCacheDirectory (
1159 GetBasename ( module.GetPath () ) + ".map",
1160 backend->outputDirectory );
1161 CLEAN_FILE ( mapFilename );
1162
1163 fprintf ( fMakefile,
1164 "\t$(ECHO_OBJDUMP)\n" );
1165 fprintf ( fMakefile,
1166 "\t$(Q)${objdump} -d -S $@ > %s\n",
1167 mapFilename.c_str () );
1168
1169 fprintf ( fMakefile,
1170 "else\n" );
1171 fprintf ( fMakefile,
1172 "ifeq ($(ROS_BUILDMAP),yes)\n" );
1173
1174 fprintf ( fMakefile,
1175 "\t$(ECHO_NM)\n" );
1176 fprintf ( fMakefile,
1177 "\t$(Q)${nm} --numeric-sort $@ > %s\n",
1178 mapFilename.c_str () );
1179
1180 fprintf ( fMakefile,
1181 "endif\n" );
1182
1183 fprintf ( fMakefile,
1184 "endif\n" );
1185 }
1186
1187 void
1188 MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
1189 {
1190 fprintf ( fMakefile,
1191 "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
1192
1193 string filename = module.GetPath ();
1194 string outputFilename = PassThruCacheDirectory (
1195 filename,
1196 backend->outputDirectory );
1197 string nostripFilename = PassThruCacheDirectory (
1198 GetBasename ( filename ) + ".nostrip" + GetExtension ( filename ),
1199 backend->outputDirectory );
1200 CLEAN_FILE ( nostripFilename );
1201
1202 fprintf ( fMakefile,
1203 "\t$(ECHO_CP)\n" );
1204 fprintf ( fMakefile,
1205 "\t${cp} %s %s 1>$(NUL)\n",
1206 outputFilename.c_str (),
1207 nostripFilename.c_str () );
1208
1209 fprintf ( fMakefile,
1210 "endif\n" );
1211 }
1212
1213 void
1214 MergeStringVector ( const vector<string>& input,
1215 vector<string>& output )
1216 {
1217 int wrap_at = 25;
1218 string s;
1219 int wrap_count = -1;
1220 for ( size_t i = 0; i < input.size (); i++ )
1221 {
1222 if ( input[i].size () == 0 )
1223 continue;
1224 if ( wrap_count++ == wrap_at )
1225 {
1226 output.push_back ( s );
1227 s = "";
1228 wrap_count = 0;
1229 }
1230 else if ( s.size () > 0)
1231 s += " ";
1232 s += input[i];
1233 }
1234 if ( s.length () > 0 )
1235 output.push_back ( s );
1236 }
1237
1238 void
1239 MingwModuleHandler::GetObjectsVector ( const IfableData& data,
1240 vector<string>& objectFiles ) const
1241 {
1242 for ( size_t i = 0; i < data.files.size (); i++ )
1243 {
1244 File& file = *data.files[i];
1245 objectFiles.push_back ( GetObjectFilename ( file.name, NULL ) );
1246 }
1247 }
1248
1249 void
1250 MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
1251 {
1252 if ( backend->cleanAsYouGo )
1253 {
1254 vector<string> objectFiles;
1255 GetObjectsVector ( module.non_if_data,
1256 objectFiles );
1257 vector<string> lines;
1258 MergeStringVector ( objectFiles,
1259 lines );
1260 for ( size_t i = 0; i < lines.size (); i++ )
1261 {
1262 fprintf ( fMakefile,
1263 "\t-@${rm} %s 2>$(NUL)\n",
1264 lines[i].c_str () );
1265 }
1266 }
1267 }
1268
1269 void
1270 MingwModuleHandler::GenerateLinkerCommand (
1271 const string& dependencies,
1272 const string& linker,
1273 const string& linkerParameters,
1274 const string& objectsMacro,
1275 const string& libsMacro )
1276 {
1277 string target ( GetTargetMacro ( module ) );
1278 string target_folder ( GetDirectory ( GetTargetFilename ( module, NULL ) ) );
1279 string def_file = GetDefinitionFilename ();
1280
1281 fprintf ( fMakefile,
1282 "%s: %s %s $(RSYM_TARGET) | %s\n",
1283 target.c_str (),
1284 def_file.c_str (),
1285 dependencies.c_str (),
1286 target_folder.c_str () );
1287 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
1288 string targetName ( module.GetTargetName () );
1289
1290 if ( module.IsDLL () )
1291 {
1292 string base_tmp = ros_temp + module.name + ".base.tmp";
1293 CLEAN_FILE ( base_tmp );
1294 string junk_tmp = ros_temp + module.name + ".junk.tmp";
1295 CLEAN_FILE ( junk_tmp );
1296 string temp_exp = ros_temp + module.name + ".temp.exp";
1297 CLEAN_FILE ( temp_exp );
1298
1299 fprintf ( fMakefile,
1300 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
1301 linker.c_str (),
1302 linkerParameters.c_str (),
1303 base_tmp.c_str (),
1304 junk_tmp.c_str (),
1305 objectsMacro.c_str (),
1306 libsMacro.c_str (),
1307 GetLinkerMacro ().c_str () );
1308
1309 fprintf ( fMakefile,
1310 "\t-@${rm} %s 2>$(NUL)\n",
1311 junk_tmp.c_str () );
1312
1313 string killAt = module.mangledSymbols ? "" : "--kill-at";
1314 fprintf ( fMakefile,
1315 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
1316 targetName.c_str (),
1317 base_tmp.c_str (),
1318 def_file.c_str (),
1319 temp_exp.c_str (),
1320 killAt.c_str () );
1321
1322 fprintf ( fMakefile,
1323 "\t-@${rm} %s 2>$(NUL)\n",
1324 base_tmp.c_str () );
1325
1326 fprintf ( fMakefile,
1327 "\t%s %s %s -o %s %s %s %s\n",
1328 linker.c_str (),
1329 linkerParameters.c_str (),
1330 temp_exp.c_str (),
1331 target.c_str (),
1332 objectsMacro.c_str (),
1333 libsMacro.c_str (),
1334 GetLinkerMacro ().c_str () );
1335
1336 fprintf ( fMakefile,
1337 "\t-@${rm} %s 2>$(NUL)\n",
1338 temp_exp.c_str () );
1339
1340 GenerateCleanObjectsAsYouGoCode ();
1341
1342 GenerateBuildMapCode ();
1343
1344 GenerateBuildNonSymbolStrippedCode ();
1345
1346 fprintf ( fMakefile,
1347 "\t$(ECHO_RSYM)\n" );
1348 fprintf ( fMakefile,
1349 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1350 }
1351 else
1352 {
1353 fprintf ( fMakefile,
1354 "\t%s %s -o %s %s %s %s\n",
1355 linker.c_str (),
1356 linkerParameters.c_str (),
1357 target.c_str (),
1358 objectsMacro.c_str (),
1359 libsMacro.c_str (),
1360 GetLinkerMacro ().c_str () );
1361
1362 GenerateCleanObjectsAsYouGoCode ();
1363 }
1364 }
1365
1366 void
1367 MingwModuleHandler::GeneratePhonyTarget() const
1368 {
1369 string targetMacro ( GetTargetMacro(module) );
1370 fprintf ( fMakefile, ".PHONY: %s\n\n",
1371 targetMacro.c_str ());
1372 fprintf ( fMakefile, "%s: | %s\n",
1373 targetMacro.c_str (),
1374 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
1375 }
1376
1377 void
1378 MingwModuleHandler::GenerateObjectFileTargets (
1379 const IfableData& data,
1380 const string& cc,
1381 const string& cppc,
1382 const string& cflagsMacro,
1383 const string& nasmflagsMacro,
1384 const string& windresflagsMacro,
1385 const string& widlflagsMacro )
1386 {
1387 size_t i;
1388
1389 const vector<File*>& files = data.files;
1390 for ( i = 0; i < files.size (); i++ )
1391 {
1392 GenerateCommands ( *files[i],
1393 cc,
1394 cppc,
1395 cflagsMacro,
1396 nasmflagsMacro,
1397 windresflagsMacro,
1398 widlflagsMacro );
1399 fprintf ( fMakefile,
1400 "\n" );
1401 }
1402
1403 const vector<If*>& ifs = data.ifs;
1404 for ( i = 0; i < ifs.size(); i++ )
1405 {
1406 GenerateObjectFileTargets ( ifs[i]->data,
1407 cc,
1408 cppc,
1409 cflagsMacro,
1410 nasmflagsMacro,
1411 windresflagsMacro,
1412 widlflagsMacro );
1413 }
1414 }
1415
1416 void
1417 MingwModuleHandler::GenerateObjectFileTargets (
1418 const string& cc,
1419 const string& cppc,
1420 const string& cflagsMacro,
1421 const string& nasmflagsMacro,
1422 const string& windresflagsMacro,
1423 const string& widlflagsMacro )
1424 {
1425 if ( module.pch )
1426 {
1427 const string& pch_file = module.pch->header;
1428 string gch_file = pch_file + ".gch";
1429 CLEAN_FILE(gch_file);
1430 if ( use_pch )
1431 {
1432 fprintf (
1433 fMakefile,
1434 "%s: %s\n",
1435 gch_file.c_str(),
1436 pch_file.c_str() );
1437 fprintf ( fMakefile, "\t$(ECHO_PCH)\n" );
1438 fprintf (
1439 fMakefile,
1440 "\t%s -o %s %s -g %s\n\n",
1441 ( module.cplusplus ? cppc.c_str() : cc.c_str() ),
1442 gch_file.c_str(),
1443 cflagsMacro.c_str(),
1444 pch_file.c_str() );
1445 }
1446 }
1447
1448 GenerateObjectFileTargets ( module.non_if_data,
1449 cc,
1450 cppc,
1451 cflagsMacro,
1452 nasmflagsMacro,
1453 windresflagsMacro,
1454 widlflagsMacro );
1455 fprintf ( fMakefile, "\n" );
1456 }
1457
1458 string
1459 MingwModuleHandler::GenerateArchiveTarget ( const string& ar,
1460 const string& objs_macro ) const
1461 {
1462 string archiveFilename ( GetModuleArchiveFilename () );
1463
1464 fprintf ( fMakefile,
1465 "%s: %s | %s\n",
1466 archiveFilename.c_str (),
1467 objs_macro.c_str (),
1468 GetDirectory(archiveFilename).c_str() );
1469
1470 fprintf ( fMakefile, "\t$(ECHO_AR)\n" );
1471
1472 fprintf ( fMakefile,
1473 "\t%s -rc $@ %s\n",
1474 ar.c_str (),
1475 objs_macro.c_str ());
1476
1477 GenerateCleanObjectsAsYouGoCode ();
1478
1479 fprintf ( fMakefile, "\n" );
1480
1481 return archiveFilename;
1482 }
1483
1484 string
1485 MingwModuleHandler::GetCFlagsMacro () const
1486 {
1487 return ssprintf ( "$(%s_CFLAGS)",
1488 module.name.c_str () );
1489 }
1490
1491 /*static*/ string
1492 MingwModuleHandler::GetObjectsMacro ( const Module& module )
1493 {
1494 return ssprintf ( "$(%s_OBJS)",
1495 module.name.c_str () );
1496 }
1497
1498 string
1499 MingwModuleHandler::GetLinkingDependenciesMacro () const
1500 {
1501 return ssprintf ( "$(%s_LINKDEPS)", module.name.c_str () );
1502 }
1503
1504 string
1505 MingwModuleHandler::GetLibsMacro () const
1506 {
1507 return ssprintf ( "$(%s_LIBS)", module.name.c_str () );
1508 }
1509
1510 string
1511 MingwModuleHandler::GetLinkerMacro () const
1512 {
1513 return ssprintf ( "$(%s_LFLAGS)",
1514 module.name.c_str () );
1515 }
1516
1517 string
1518 MingwModuleHandler::GetModuleTargets ( const Module& module )
1519 {
1520 if ( ReferenceObjects ( module ) )
1521 return GetObjectsMacro ( module );
1522 else
1523 return GetTargetFilename ( module, NULL );
1524 }
1525
1526 void
1527 MingwModuleHandler::GenerateObjectMacro ()
1528 {
1529 objectsMacro = ssprintf ("%s_OBJS", module.name.c_str ());
1530
1531 GenerateObjectMacros (
1532 "=",
1533 module.non_if_data,
1534 &module.compilerFlags,
1535 &module.linkerFlags );
1536
1537 // future references to the macro will be to get its values
1538 objectsMacro = ssprintf ("$(%s)", objectsMacro.c_str ());
1539 }
1540
1541 void
1542 MingwModuleHandler::GenerateTargetMacro ()
1543 {
1544 fprintf ( fMakefile,
1545 "%s := %s\n",
1546 GetTargetMacro ( module, false ).c_str (),
1547 GetModuleTargets ( module ).c_str () );
1548 }
1549
1550 void
1551 MingwModuleHandler::GenerateOtherMacros ()
1552 {
1553 cflagsMacro = ssprintf ("%s_CFLAGS", module.name.c_str ());
1554 nasmflagsMacro = ssprintf ("%s_NASMFLAGS", module.name.c_str ());
1555 windresflagsMacro = ssprintf ("%s_RCFLAGS", module.name.c_str ());
1556 widlflagsMacro = ssprintf ("%s_WIDLFLAGS", module.name.c_str ());
1557 linkerflagsMacro = ssprintf ("%s_LFLAGS", module.name.c_str ());
1558 libsMacro = ssprintf("%s_LIBS", module.name.c_str ());
1559 linkDepsMacro = ssprintf ("%s_LINKDEPS", module.name.c_str ());
1560
1561 GenerateMacros (
1562 "=",
1563 module.non_if_data,
1564 &module.compilerFlags,
1565 &module.linkerFlags );
1566
1567 if ( module.importLibrary )
1568 {
1569 string_list s;
1570 const vector<File*>& files = module.non_if_data.files;
1571 for ( size_t i = 0; i < files.size (); i++ )
1572 {
1573 File& file = *files[i];
1574 string extension = GetExtension ( file.name );
1575 if ( extension == ".spec" || extension == ".SPEC" )
1576 GetSpecObjectDependencies ( s, file.name );
1577 }
1578 if ( s.size () > 0 )
1579 {
1580 fprintf (
1581 fMakefile,
1582 "%s +=",
1583 linkDepsMacro.c_str() );
1584 for ( size_t i = 0; i < s.size(); i++ )
1585 fprintf ( fMakefile,
1586 " %s",
1587 s[i].c_str () );
1588 fprintf ( fMakefile, "\n" );
1589 }
1590 }
1591
1592 string globalCflags = "-g";
1593 if ( backend->usePipe )
1594 globalCflags += " -pipe";
1595 if ( !module.enableWarnings )
1596 globalCflags += " -Werror";
1597
1598 fprintf (
1599 fMakefile,
1600 "%s += $(PROJECT_CFLAGS) %s\n",
1601 cflagsMacro.c_str (),
1602 globalCflags.c_str () );
1603
1604 fprintf (
1605 fMakefile,
1606 "%s += $(PROJECT_RCFLAGS)\n",
1607 windresflagsMacro.c_str () );
1608
1609 fprintf (
1610 fMakefile,
1611 "%s += $(PROJECT_WIDLFLAGS)\n",
1612 widlflagsMacro.c_str () );
1613
1614 fprintf (
1615 fMakefile,
1616 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
1617 module.name.c_str () );
1618
1619 fprintf (
1620 fMakefile,
1621 "%s += $(%s)\n",
1622 linkDepsMacro.c_str (),
1623 libsMacro.c_str () );
1624
1625 string cflags = TypeSpecificCFlags();
1626 if ( cflags.size() > 0 )
1627 {
1628 fprintf ( fMakefile,
1629 "%s += %s\n\n",
1630 cflagsMacro.c_str (),
1631 cflags.c_str () );
1632 }
1633
1634 string nasmflags = TypeSpecificNasmFlags();
1635 if ( nasmflags.size () > 0 )
1636 {
1637 fprintf ( fMakefile,
1638 "%s += %s\n\n",
1639 nasmflagsMacro.c_str (),
1640 nasmflags.c_str () );
1641 }
1642
1643 string linkerflags = TypeSpecificLinkerFlags();
1644 if ( linkerflags.size() > 0 )
1645 {
1646 fprintf ( fMakefile,
1647 "%s += %s\n\n",
1648 linkerflagsMacro.c_str (),
1649 linkerflags.c_str () );
1650 }
1651
1652 fprintf ( fMakefile, "\n\n" );
1653
1654 // future references to the macros will be to get their values
1655 cflagsMacro = ssprintf ("$(%s)", cflagsMacro.c_str ());
1656 nasmflagsMacro = ssprintf ("$(%s)", nasmflagsMacro.c_str ());
1657 widlflagsMacro = ssprintf ("$(%s)", widlflagsMacro.c_str ());
1658 }
1659
1660 void
1661 MingwModuleHandler::GenerateRules ()
1662 {
1663 string cc = ( module.host == HostTrue ? "${host_gcc}" : "${gcc}" );
1664 string cppc = ( module.host == HostTrue ? "${host_gpp}" : "${gpp}" );
1665 string ar = ( module.host == HostTrue ? "${host_ar}" : "${ar}" );
1666
1667 string targetMacro = GetTargetMacro ( module );
1668
1669 CLEAN_FILE ( targetMacro );
1670
1671 // generate phony target for module name
1672 fprintf ( fMakefile, ".PHONY: %s\n",
1673 module.name.c_str () );
1674 fprintf ( fMakefile, "%s: %s\n\n",
1675 module.name.c_str (),
1676 GetTargetMacro ( module ).c_str () );
1677
1678 if ( !ReferenceObjects ( module ) )
1679 {
1680 string ar_target ( GenerateArchiveTarget ( ar, objectsMacro ) );
1681 if ( targetMacro != ar_target )
1682 {
1683 CLEAN_FILE ( ar_target );
1684 }
1685 }
1686
1687 GenerateObjectFileTargets ( cc,
1688 cppc,
1689 cflagsMacro,
1690 nasmflagsMacro,
1691 windresflagsMacro,
1692 widlflagsMacro );
1693 }
1694
1695 void
1696 MingwModuleHandler::GetInvocationDependencies (
1697 const Module& module,
1698 string_list& dependencies )
1699 {
1700 for ( size_t i = 0; i < module.invocations.size (); i++ )
1701 {
1702 Invoke& invoke = *module.invocations[i];
1703 if ( invoke.invokeModule == &module )
1704 /* Protect against circular dependencies */
1705 continue;
1706 invoke.GetTargets ( dependencies );
1707 }
1708 }
1709
1710 void
1711 MingwModuleHandler::GenerateInvocations () const
1712 {
1713 if ( module.invocations.size () == 0 )
1714 return;
1715
1716 size_t iend = module.invocations.size ();
1717 for ( size_t i = 0; i < iend; i++ )
1718 {
1719 const Invoke& invoke = *module.invocations[i];
1720
1721 if ( invoke.invokeModule->type != BuildTool )
1722 {
1723 throw InvalidBuildFileException ( module.node.location,
1724 "Only modules of type buildtool can be invoked." );
1725 }
1726
1727 string invokeTarget = module.GetInvocationTarget ( i );
1728 string_list invoke_targets;
1729 assert ( invoke_targets.size() );
1730 invoke.GetTargets ( invoke_targets );
1731 fprintf ( fMakefile,
1732 ".PHONY: %s\n\n",
1733 invokeTarget.c_str () );
1734 fprintf ( fMakefile,
1735 "%s:",
1736 invokeTarget.c_str () );
1737 size_t j, jend = invoke_targets.size();
1738 for ( j = 0; j < jend; j++ )
1739 {
1740 fprintf ( fMakefile,
1741 " %s",
1742 invoke_targets[i].c_str () );
1743 }
1744 fprintf ( fMakefile, "\n\n%s", invoke_targets[0].c_str () );
1745 for ( j = 1; j < jend; j++ )
1746 fprintf ( fMakefile,
1747 " %s",
1748 invoke_targets[i].c_str () );
1749 fprintf ( fMakefile,
1750 ": %s\n",
1751 NormalizeFilename ( invoke.invokeModule->GetPath () ).c_str () );
1752 fprintf ( fMakefile, "\t$(ECHO_INVOKE)\n" );
1753 fprintf ( fMakefile,
1754 "\t%s %s\n\n",
1755 NormalizeFilename ( invoke.invokeModule->GetPath () ).c_str (),
1756 invoke.GetParameters ().c_str () );
1757 }
1758 }
1759
1760 string
1761 MingwModuleHandler::GetPreconditionDependenciesName () const
1762 {
1763 return module.name + "_precondition";
1764 }
1765
1766 void
1767 MingwModuleHandler::GetDefaultDependencies (
1768 string_list& dependencies ) const
1769 {
1770 /* Avoid circular dependency */
1771 if ( module.type != BuildTool
1772 && module.name != "zlib"
1773 && module.name != "hostzlib" )
1774
1775 dependencies.push_back ( "$(INIT)" );
1776 }
1777
1778 void
1779 MingwModuleHandler::GeneratePreconditionDependencies ()
1780 {
1781 string preconditionDependenciesName = GetPreconditionDependenciesName ();
1782 string_list sourceFilenames;
1783 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames );
1784 string_list dependencies;
1785 GetDefaultDependencies ( dependencies );
1786 GetModuleDependencies ( dependencies );
1787
1788 GetInvocationDependencies ( module, dependencies );
1789
1790 if ( dependencies.size() )
1791 {
1792 fprintf ( fMakefile,
1793 "%s =",
1794 preconditionDependenciesName.c_str () );
1795 for ( size_t i = 0; i < dependencies.size(); i++ )
1796 fprintf ( fMakefile,
1797 " %s",
1798 dependencies[i].c_str () );
1799 fprintf ( fMakefile, "\n\n" );
1800 }
1801
1802 for ( size_t i = 0; i < sourceFilenames.size(); i++ )
1803 {
1804 fprintf ( fMakefile,
1805 "%s: ${%s}\n",
1806 sourceFilenames[i].c_str(),
1807 preconditionDependenciesName.c_str ());
1808 }
1809 fprintf ( fMakefile, "\n" );
1810 }
1811
1812 bool
1813 MingwModuleHandler::IsWineModule () const
1814 {
1815 if ( module.importLibrary == NULL)
1816 return false;
1817
1818 size_t index = module.importLibrary->definition.rfind ( ".spec.def" );
1819 return ( index != string::npos );
1820 }
1821
1822 string
1823 MingwModuleHandler::GetDefinitionFilename () const
1824 {
1825 if ( module.importLibrary != NULL )
1826 {
1827 string defFilename = module.GetBasePath () + SSEP + module.importLibrary->definition;
1828 if ( IsWineModule () )
1829 return PassThruCacheDirectory ( NormalizeFilename ( defFilename ),
1830 backend->intermediateDirectory );
1831 else
1832 return defFilename;
1833 }
1834 else
1835 return "tools" SSEP "rbuild" SSEP "empty.def";
1836 }
1837
1838 void
1839 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
1840 {
1841 if ( module.importLibrary != NULL )
1842 {
1843 string library_target (
1844 GetImportLibraryFilename ( module, &clean_files ) );
1845 string defFilename = GetDefinitionFilename ();
1846
1847 string_list deps;
1848 GetDefinitionDependencies ( deps );
1849
1850 fprintf ( fMakefile, "# IMPORT LIBRARY RULE:\n" );
1851
1852 fprintf ( fMakefile, "%s: %s",
1853 library_target.c_str (),
1854 defFilename.c_str () );
1855
1856 size_t i, iend = deps.size();
1857 for ( i = 0; i < iend; i++ )
1858 fprintf ( fMakefile, " %s",
1859 deps[i].c_str () );
1860
1861 fprintf ( fMakefile, " | %s\n",
1862 GetDirectory ( GetTargetFilename ( module, NULL ) ).c_str () );
1863
1864 fprintf ( fMakefile, "\t$(ECHO_DLLTOOL)\n" );
1865
1866 string killAt = module.mangledSymbols ? "" : "--kill-at";
1867 fprintf ( fMakefile,
1868 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1869 module.GetTargetName ().c_str (),
1870 defFilename.c_str (),
1871 library_target.c_str (),
1872 killAt.c_str () );
1873 }
1874 }
1875
1876 void
1877 MingwModuleHandler::GetSpecObjectDependencies (
1878 string_list& dependencies,
1879 const string& filename ) const
1880 {
1881 string basename = GetBasename ( filename );
1882 string defDependency = PassThruCacheDirectory (
1883 NormalizeFilename ( basename + ".spec.def" ),
1884 backend->intermediateDirectory );
1885 dependencies.push_back ( defDependency );
1886 string stubsDependency = PassThruCacheDirectory (
1887 NormalizeFilename ( basename + ".stubs.c" ),
1888 backend->intermediateDirectory );
1889 dependencies.push_back ( stubsDependency );
1890 }
1891
1892 void
1893 MingwModuleHandler::GetWidlObjectDependencies (
1894 string_list& dependencies,
1895 const string& filename ) const
1896 {
1897 string basename = GetBasename ( filename );
1898 string serverDependency = PassThruCacheDirectory (
1899 NormalizeFilename ( basename + "_s.c" ),
1900 backend->intermediateDirectory );
1901 dependencies.push_back ( serverDependency );
1902 }
1903
1904 void
1905 MingwModuleHandler::GetDefinitionDependencies (
1906 string_list& dependencies ) const
1907 {
1908 string dkNkmLibNoFixup = "dk/nkm/lib";
1909 const vector<File*>& files = module.non_if_data.files;
1910 for ( size_t i = 0; i < files.size (); i++ )
1911 {
1912 File& file = *files[i];
1913 string extension = GetExtension ( file.name );
1914 if ( extension == ".spec" || extension == ".SPEC" )
1915 {
1916 GetSpecObjectDependencies ( dependencies, file.name );
1917 }
1918 if ( extension == ".idl" || extension == ".IDL" )
1919 {
1920 GetWidlObjectDependencies ( dependencies, file.name );
1921 }
1922 }
1923 }
1924
1925
1926 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module& module_ )
1927 : MingwModuleHandler ( module_ )
1928 {
1929 }
1930
1931 void
1932 MingwBuildToolModuleHandler::Process ()
1933 {
1934 GenerateBuildToolModuleTarget ();
1935 }
1936
1937 void
1938 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
1939 {
1940 string targetMacro ( GetTargetMacro (module) );
1941 string objectsMacro = GetObjectsMacro ( module );
1942 string linkDepsMacro = GetLinkingDependenciesMacro ();
1943 string libsMacro = GetLibsMacro ();
1944
1945 GenerateRules ();
1946
1947 string linker;
1948 if ( module.cplusplus )
1949 linker = "${host_gpp}";
1950 else
1951 linker = "${host_gcc}";
1952
1953 fprintf ( fMakefile, "%s: %s %s | %s\n",
1954 targetMacro.c_str (),
1955 objectsMacro.c_str (),
1956 linkDepsMacro.c_str (),
1957 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
1958 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
1959 fprintf ( fMakefile,
1960 "\t%s %s -o $@ %s %s\n\n",
1961 linker.c_str (),
1962 GetLinkerMacro ().c_str (),
1963 objectsMacro.c_str (),
1964 libsMacro.c_str () );
1965 }
1966
1967
1968 MingwKernelModuleHandler::MingwKernelModuleHandler (
1969 const Module& module_ )
1970
1971 : MingwModuleHandler ( module_ )
1972 {
1973 }
1974
1975 void
1976 MingwKernelModuleHandler::Process ()
1977 {
1978 GenerateKernelModuleTarget ();
1979 }
1980
1981 void
1982 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
1983 {
1984 string targetMacro ( GetTargetMacro ( module ) );
1985 string workingDirectory = GetWorkingDirectory ( );
1986 string objectsMacro = GetObjectsMacro ( module );
1987 string linkDepsMacro = GetLinkingDependenciesMacro ();
1988 string libsMacro = GetLibsMacro ();
1989
1990 GenerateImportLibraryTargetIfNeeded ();
1991
1992 if ( module.non_if_data.files.size () > 0 )
1993 {
1994 GenerateRules ();
1995
1996 string dependencies = linkDepsMacro + " " + objectsMacro;
1997
1998 string linkerParameters = 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 --dll",
1999 module.GetBasePath ().c_str (),
2000 module.entrypoint.c_str (),
2001 module.baseaddress.c_str () );
2002 GenerateLinkerCommand ( dependencies,
2003 "${gcc}",
2004 linkerParameters,
2005 objectsMacro,
2006 libsMacro );
2007 }
2008 else
2009 {
2010 GeneratePhonyTarget();
2011 }
2012 }
2013
2014
2015 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
2016 const Module& module_ )
2017
2018 : MingwModuleHandler ( module_ )
2019 {
2020 }
2021
2022 void
2023 MingwStaticLibraryModuleHandler::Process ()
2024 {
2025 GenerateStaticLibraryModuleTarget ();
2026 }
2027
2028 void
2029 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
2030 {
2031 GenerateRules ();
2032 }
2033
2034
2035 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
2036 const Module& module_ )
2037
2038 : MingwModuleHandler ( module_ )
2039 {
2040 }
2041
2042 void
2043 MingwObjectLibraryModuleHandler::Process ()
2044 {
2045 GenerateObjectLibraryModuleTarget ();
2046 }
2047
2048 void
2049 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
2050 {
2051 GenerateRules ();
2052 }
2053
2054
2055 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2056 const Module& module_ )
2057
2058 : MingwModuleHandler ( module_ )
2059 {
2060 }
2061
2062 void
2063 MingwKernelModeDLLModuleHandler::Process ()
2064 {
2065 GenerateKernelModeDLLModuleTarget ();
2066 }
2067
2068 void
2069 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
2070 {
2071 string targetMacro ( GetTargetMacro ( module ) );
2072 string workingDirectory = GetWorkingDirectory ( );
2073 string objectsMacro = GetObjectsMacro ( module );
2074 string linkDepsMacro = GetLinkingDependenciesMacro ();
2075 string libsMacro = GetLibsMacro ();
2076
2077 GenerateImportLibraryTargetIfNeeded ();
2078
2079 if ( module.non_if_data.files.size () > 0 )
2080 {
2081 GenerateRules ();
2082
2083 string dependencies = linkDepsMacro + " " + objectsMacro;
2084
2085 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll --dll",
2086 module.entrypoint.c_str (),
2087 module.baseaddress.c_str () );
2088 GenerateLinkerCommand ( dependencies,
2089 "${gcc}",
2090 linkerParameters,
2091 objectsMacro,
2092 libsMacro );
2093 }
2094 else
2095 {
2096 GeneratePhonyTarget();
2097 }
2098 }
2099
2100
2101 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
2102 const Module& module_ )
2103
2104 : MingwModuleHandler ( module_ )
2105 {
2106 }
2107
2108 void
2109 MingwKernelModeDriverModuleHandler::Process ()
2110 {
2111 GenerateKernelModeDriverModuleTarget ();
2112 }
2113
2114
2115 void
2116 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
2117 {
2118 string targetMacro ( GetTargetMacro (module) );
2119 string workingDirectory = GetWorkingDirectory ();
2120 string objectsMacro = GetObjectsMacro ( module );
2121 string linkDepsMacro = GetLinkingDependenciesMacro ();
2122 string libsMacro = GetLibsMacro ();
2123
2124 GenerateImportLibraryTargetIfNeeded ();
2125
2126 if ( module.non_if_data.files.size () > 0 )
2127 {
2128 GenerateRules ();
2129
2130 string dependencies = linkDepsMacro + " " + objectsMacro;
2131
2132 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll --dll",
2133 module.entrypoint.c_str (),
2134 module.baseaddress.c_str () );
2135 GenerateLinkerCommand ( dependencies,
2136 "${gcc}",
2137 linkerParameters,
2138 objectsMacro,
2139 libsMacro );
2140 }
2141 else
2142 {
2143 GeneratePhonyTarget();
2144 }
2145 }
2146
2147
2148 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
2149 const Module& module_ )
2150
2151 : MingwModuleHandler ( module_ )
2152 {
2153 }
2154
2155 void
2156 MingwNativeDLLModuleHandler::Process ()
2157 {
2158 GenerateNativeDLLModuleTarget ();
2159 }
2160
2161 void
2162 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
2163 {
2164 string targetMacro ( GetTargetMacro (module) );
2165 string workingDirectory = GetWorkingDirectory ( );
2166 string objectsMacro = GetObjectsMacro ( module );
2167 string linkDepsMacro = GetLinkingDependenciesMacro ();
2168 string libsMacro = GetLibsMacro ();
2169
2170 GenerateImportLibraryTargetIfNeeded ();
2171
2172 if ( module.non_if_data.files.size () > 0 )
2173 {
2174 GenerateRules ();
2175
2176 string dependencies = linkDepsMacro + " " + objectsMacro;
2177
2178 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll --dll",
2179 module.entrypoint.c_str (),
2180 module.baseaddress.c_str () );
2181 GenerateLinkerCommand ( dependencies,
2182 "${gcc}",
2183 linkerParameters,
2184 objectsMacro,
2185 libsMacro );
2186 }
2187 else
2188 {
2189 GeneratePhonyTarget();
2190 }
2191 }
2192
2193
2194 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
2195 const Module& module_ )
2196
2197 : MingwModuleHandler ( module_ )
2198 {
2199 }
2200
2201 void
2202 MingwNativeCUIModuleHandler::Process ()
2203 {
2204 GenerateNativeCUIModuleTarget ();
2205 }
2206
2207 void
2208 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
2209 {
2210 string targetMacro ( GetTargetMacro (module) );
2211 string workingDirectory = GetWorkingDirectory ( );
2212 string objectsMacro = GetObjectsMacro ( module );
2213 string linkDepsMacro = GetLinkingDependenciesMacro ();
2214 string libsMacro = GetLibsMacro ();
2215
2216 GenerateImportLibraryTargetIfNeeded ();
2217
2218 if ( module.non_if_data.files.size () > 0 )
2219 {
2220 GenerateRules ();
2221
2222 string dependencies = linkDepsMacro + " " + objectsMacro;
2223
2224 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
2225 module.entrypoint.c_str (),
2226 module.baseaddress.c_str () );
2227 GenerateLinkerCommand ( dependencies,
2228 "${gcc}",
2229 linkerParameters,
2230 objectsMacro,
2231 libsMacro );
2232 }
2233 else
2234 {
2235 GeneratePhonyTarget();
2236 }
2237 }
2238
2239
2240 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
2241 const Module& module_ )
2242
2243 : MingwModuleHandler ( module_ )
2244 {
2245 }
2246
2247 void
2248 MingwWin32DLLModuleHandler::Process ()
2249 {
2250 GenerateExtractWineDLLResourcesTarget ();
2251 GenerateWin32DLLModuleTarget ();
2252 }
2253
2254 void
2255 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ()
2256 {
2257 fprintf ( fMakefile, ".PHONY: %s_extractresources\n\n",
2258 module.name.c_str () );
2259 fprintf ( fMakefile, "%s_extractresources: $(BIN2RES_TARGET)\n",
2260 module.name.c_str () );
2261 const vector<File*>& files = module.non_if_data.files;
2262 for ( size_t i = 0; i < files.size (); i++ )
2263 {
2264 File& file = *files[i];
2265 string extension = GetExtension ( file.name );
2266 if ( extension == ".rc" || extension == ".RC" )
2267 {
2268 string resource = NormalizeFilename ( file.name );
2269 fprintf ( fMakefile, "\t$(ECHO_BIN2RES)\n" );
2270 fprintf ( fMakefile, "\t@:echo ${bin2res} -f -x %s\n",
2271 resource.c_str () );
2272 }
2273 }
2274 fprintf ( fMakefile, "\n");
2275 }
2276
2277 void
2278 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
2279 {
2280 string targetMacro ( GetTargetMacro (module) );
2281 string workingDirectory = GetWorkingDirectory ( );
2282 string objectsMacro = GetObjectsMacro ( module );
2283 string linkDepsMacro = GetLinkingDependenciesMacro ();
2284 string libsMacro = GetLibsMacro ();
2285
2286 GenerateImportLibraryTargetIfNeeded ();
2287
2288 if ( module.non_if_data.files.size () > 0 )
2289 {
2290 GenerateRules ();
2291
2292 string dependencies = linkDepsMacro + " " + objectsMacro;
2293
2294 string linker;
2295 if ( module.cplusplus )
2296 linker = "${gpp}";
2297 else
2298 linker = "${gcc}";
2299
2300 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll --dll",
2301 module.entrypoint.c_str (),
2302 module.baseaddress.c_str () );
2303 GenerateLinkerCommand ( dependencies,
2304 linker,
2305 linkerParameters,
2306 objectsMacro,
2307 libsMacro );
2308 }
2309 else
2310 {
2311 GeneratePhonyTarget();
2312 }
2313 }
2314
2315
2316 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
2317 const Module& module_ )
2318
2319 : MingwModuleHandler ( module_ )
2320 {
2321 }
2322
2323 void
2324 MingwWin32CUIModuleHandler::Process ()
2325 {
2326 GenerateWin32CUIModuleTarget ();
2327 }
2328
2329 void
2330 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
2331 {
2332 string targetMacro ( GetTargetMacro (module) );
2333 string workingDirectory = GetWorkingDirectory ( );
2334 string objectsMacro = GetObjectsMacro ( module );
2335 string linkDepsMacro = GetLinkingDependenciesMacro ();
2336 string libsMacro = GetLibsMacro ();
2337
2338 GenerateImportLibraryTargetIfNeeded ();
2339
2340 if ( module.non_if_data.files.size () > 0 )
2341 {
2342 GenerateRules ();
2343
2344 string dependencies = linkDepsMacro + " " + objectsMacro;
2345
2346 string linker;
2347 if ( module.cplusplus )
2348 linker = "${gpp}";
2349 else
2350 linker = "${gcc}";
2351
2352 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2353 module.entrypoint.c_str (),
2354 module.baseaddress.c_str () );
2355 GenerateLinkerCommand ( dependencies,
2356 linker,
2357 linkerParameters,
2358 objectsMacro,
2359 libsMacro );
2360 }
2361 else
2362 {
2363 GeneratePhonyTarget();
2364 }
2365 }
2366
2367
2368 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
2369 const Module& module_ )
2370
2371 : MingwModuleHandler ( module_ )
2372 {
2373 }
2374
2375 void
2376 MingwWin32GUIModuleHandler::Process ()
2377 {
2378 GenerateWin32GUIModuleTarget ();
2379 }
2380
2381 void
2382 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
2383 {
2384 string targetMacro ( GetTargetMacro (module) );
2385 string workingDirectory = GetWorkingDirectory ( );
2386 string objectsMacro = GetObjectsMacro ( module );
2387 string linkDepsMacro = GetLinkingDependenciesMacro ();
2388 string libsMacro = GetLibsMacro ();
2389
2390 GenerateImportLibraryTargetIfNeeded ();
2391
2392 if ( module.non_if_data.files.size () > 0 )
2393 {
2394 GenerateRules ();
2395
2396 string dependencies = linkDepsMacro + " " + objectsMacro;
2397
2398 string linker;
2399 if ( module.cplusplus )
2400 linker = "${gpp}";
2401 else
2402 linker = "${gcc}";
2403
2404 string linkerParameters = ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2405 module.entrypoint.c_str (),
2406 module.baseaddress.c_str () );
2407 GenerateLinkerCommand ( dependencies,
2408 linker,
2409 linkerParameters,
2410 objectsMacro,
2411 libsMacro );
2412 }
2413 else
2414 {
2415 GeneratePhonyTarget();
2416 }
2417 }
2418
2419
2420 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
2421 const Module& module_ )
2422
2423 : MingwModuleHandler ( module_ )
2424 {
2425 }
2426
2427 void
2428 MingwBootLoaderModuleHandler::Process ()
2429 {
2430 GenerateBootLoaderModuleTarget ();
2431 }
2432
2433 void
2434 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
2435 {
2436 string targetName ( module.GetTargetName () );
2437 string targetMacro ( GetTargetMacro (module) );
2438 string workingDirectory = GetWorkingDirectory ();
2439 string junk_tmp = ros_temp + module.name + ".junk.tmp";
2440 CLEAN_FILE ( junk_tmp );
2441 string objectsMacro = GetObjectsMacro ( module );
2442 string linkDepsMacro = GetLinkingDependenciesMacro ();
2443 string libsMacro = GetLibsMacro ();
2444
2445 GenerateRules ();
2446
2447 fprintf ( fMakefile, "%s: %s %s | %s\n",
2448 targetMacro.c_str (),
2449 objectsMacro.c_str (),
2450 linkDepsMacro.c_str (),
2451 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
2452
2453 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
2454
2455 fprintf ( fMakefile,
2456 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2457 GetLinkerMacro ().c_str (),
2458 junk_tmp.c_str (),
2459 objectsMacro.c_str (),
2460 linkDepsMacro.c_str () );
2461 fprintf ( fMakefile,
2462 "\t${objcopy} -O binary %s $@\n",
2463 junk_tmp.c_str () );
2464 fprintf ( fMakefile,
2465 "\t-@${rm} %s 2>$(NUL)\n",
2466 junk_tmp.c_str () );
2467 }
2468
2469
2470 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
2471 const Module& module_ )
2472
2473 : MingwModuleHandler ( module_ )
2474 {
2475 }
2476
2477 void
2478 MingwBootSectorModuleHandler::Process ()
2479 {
2480 GenerateBootSectorModuleTarget ();
2481 }
2482
2483 void
2484 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
2485 {
2486 string objectsMacro = GetObjectsMacro ( module );
2487
2488 GenerateRules ();
2489
2490 fprintf ( fMakefile, ".PHONY: %s\n\n",
2491 module.name.c_str ());
2492 fprintf ( fMakefile,
2493 "%s: %s\n",
2494 module.name.c_str (),
2495 objectsMacro.c_str () );
2496 }
2497
2498
2499 MingwIsoModuleHandler::MingwIsoModuleHandler (
2500 const Module& module_ )
2501
2502 : MingwModuleHandler ( module_ )
2503 {
2504 }
2505
2506 void
2507 MingwIsoModuleHandler::Process ()
2508 {
2509 GenerateIsoModuleTarget ();
2510 }
2511
2512 void
2513 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
2514 const string& bootcdDirectory )
2515 {
2516 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2517 {
2518 const Module& m = *module.project.modules[i];
2519 if ( m.bootstrap != NULL )
2520 {
2521 string sourceFilename = PassThruCacheDirectory (
2522 NormalizeFilename ( m.GetPath () ),
2523 backend->outputDirectory );
2524 string targetFilenameNoFixup ( bootcdDirectory + SSEP + m.bootstrap->base + SSEP + m.bootstrap->nameoncd );
2525 string targetFilename = MingwModuleHandler::PassThruCacheDirectory (
2526 NormalizeFilename ( targetFilenameNoFixup ),
2527 backend->outputDirectory );
2528 fprintf ( fMakefile,
2529 "\t$(ECHO_CP)\n" );
2530 fprintf ( fMakefile,
2531 "\t${cp} %s %s 1>$(NUL)\n",
2532 sourceFilename.c_str (),
2533 targetFilename.c_str () );
2534 }
2535 }
2536 }
2537
2538 void
2539 MingwIsoModuleHandler::OutputCdfileCopyCommands (
2540 const string& bootcdDirectory )
2541 {
2542 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2543 {
2544 const CDFile& cdfile = *module.project.cdfiles[i];
2545 string targetFilenameNoFixup = bootcdDirectory + SSEP + cdfile.base + SSEP + cdfile.nameoncd;
2546 string targetFilename = MingwModuleHandler::PassThruCacheDirectory (
2547 NormalizeFilename ( targetFilenameNoFixup ),
2548 backend->outputDirectory );
2549 fprintf ( fMakefile,
2550 "\t$(ECHO_CP)\n" );
2551 fprintf ( fMakefile,
2552 "\t${cp} %s %s 1>$(NUL)\n",
2553 cdfile.GetPath ().c_str (),
2554 targetFilename.c_str () );
2555 }
2556 }
2557
2558 string
2559 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string& bootcdDirectory )
2560 {
2561 string directories;
2562 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2563 {
2564 const Module& m = *module.project.modules[i];
2565 if ( m.bootstrap != NULL )
2566 {
2567 string targetDirectory ( bootcdDirectory + SSEP + m.bootstrap->base );
2568 if ( directories.size () > 0 )
2569 directories += " ";
2570 directories += PassThruCacheDirectory (
2571 NormalizeFilename ( targetDirectory ),
2572 backend->outputDirectory );
2573 }
2574 }
2575 return directories;
2576 }
2577
2578 string
2579 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string& bootcdDirectory )
2580 {
2581 string directories;
2582 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2583 {
2584 const CDFile& cdfile = *module.project.cdfiles[i];
2585 string targetDirectory ( bootcdDirectory + SSEP + cdfile.base );
2586 if ( directories.size () > 0 )
2587 directories += " ";
2588 directories += PassThruCacheDirectory (
2589 NormalizeFilename ( targetDirectory ),
2590 backend->outputDirectory );
2591 }
2592 return directories;
2593 }
2594
2595 string
2596 MingwIsoModuleHandler::GetCdDirectories ( const string& bootcdDirectory )
2597 {
2598 string directories = GetBootstrapCdDirectories ( bootcdDirectory );
2599 directories += " " + GetNonModuleCdDirectories ( bootcdDirectory );
2600 return directories;
2601 }
2602
2603 void
2604 MingwIsoModuleHandler::GetBootstrapCdFiles (
2605 vector<string>& out ) const
2606 {
2607 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2608 {
2609 const Module& m = *module.project.modules[i];
2610 if ( m.bootstrap != NULL )
2611 {
2612 string filename = PassThruCacheDirectory (
2613 NormalizeFilename ( m.GetPath () ),
2614 backend->outputDirectory );
2615 out.push_back ( filename );
2616 }
2617 }
2618 }
2619
2620 void
2621 MingwIsoModuleHandler::GetNonModuleCdFiles (
2622 vector<string>& out ) const
2623 {
2624 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2625 {
2626 const CDFile& cdfile = *module.project.cdfiles[i];
2627 out.push_back ( cdfile.GetPath () );
2628 }
2629 }
2630
2631 void
2632 MingwIsoModuleHandler::GetCdFiles (
2633 vector<string>& out ) const
2634 {
2635 GetBootstrapCdFiles ( out );
2636 GetNonModuleCdFiles ( out );
2637 }
2638
2639 void
2640 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
2641 {
2642 string bootcdDirectory = "cd";
2643 string bootcd = PassThruCacheDirectory (
2644 NormalizeFilename ( bootcdDirectory + SSEP ),
2645 backend->outputDirectory );
2646 string isoboot = PassThruCacheDirectory (
2647 NormalizeFilename ( "boot" SSEP "freeldr" SSEP "bootsect" SSEP "isoboot.o" ),
2648 backend->outputDirectory );
2649 string bootcdReactosNoFixup = bootcdDirectory + SSEP "reactos";
2650 string bootcdReactos = PassThruCacheDirectory (
2651 NormalizeFilename ( bootcdReactosNoFixup + SSEP ),
2652 backend->outputDirectory );
2653 CLEAN_FILE ( bootcdReactos );
2654 string reactosInf = PassThruCacheDirectory (
2655 NormalizeFilename ( bootcdReactosNoFixup + SSEP "reactos.inf" ),
2656 backend->outputDirectory );
2657 string reactosDff = NormalizeFilename ( "bootdata" SSEP "packages" SSEP "reactos.dff" );
2658 string cdDirectories = GetCdDirectories ( bootcdDirectory );
2659 vector<string> vCdFiles;
2660 GetCdFiles ( vCdFiles );
2661 string cdFiles = v2s ( vCdFiles, 5 );
2662
2663 fprintf ( fMakefile, ".PHONY: %s\n\n",
2664 module.name.c_str ());
2665 fprintf ( fMakefile,
2666 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
2667 module.name.c_str (),
2668 isoboot.c_str (),
2669 bootcdReactos.c_str (),
2670 cdDirectories.c_str (),
2671 cdFiles.c_str () );
2672 fprintf ( fMakefile, "\t$(ECHO_CABMAN)\n" );
2673 fprintf ( fMakefile,
2674 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
2675 reactosDff.c_str (),
2676 bootcdReactos.c_str () );
2677 fprintf ( fMakefile,
2678 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2679 reactosDff.c_str (),
2680 reactosInf.c_str (),
2681 bootcdReactos.c_str ());
2682 fprintf ( fMakefile,
2683 "\t-@${rm} %s 2>$(NUL)\n",
2684 reactosInf.c_str () );
2685 OutputBootstrapfileCopyCommands ( bootcdDirectory );
2686 OutputCdfileCopyCommands ( bootcdDirectory );
2687 fprintf ( fMakefile, "\t$(ECHO_CDMAKE)\n" );
2688 fprintf ( fMakefile,
2689 "\t$(Q)$(CDMAKE_TARGET) -v -m -b %s %s REACTOS ReactOS.iso\n",
2690 isoboot.c_str (),
2691 bootcd.c_str () );
2692 fprintf ( fMakefile,
2693 "\n" );
2694 }
2695
2696
2697 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
2698 const Module& module_ )
2699
2700 : MingwModuleHandler ( module_ )
2701 {
2702 }
2703
2704 void
2705 MingwLiveIsoModuleHandler::Process ()
2706 {
2707 GenerateLiveIsoModuleTarget ();
2708 }
2709
2710 void
2711 MingwLiveIsoModuleHandler::CreateDirectory ( const string& directory )
2712 {
2713 string normalizedDirectory = MingwModuleHandler::PassThruCacheDirectory (
2714 NormalizeFilename ( directory ) + SSEP,
2715 backend->outputDirectory );
2716 }
2717
2718 void
2719 MingwLiveIsoModuleHandler::OutputCopyCommand ( const string& sourceFilename,
2720 const string& targetFilename,
2721 const string& targetDirectory )
2722 {
2723 string normalizedTargetFilename = MingwModuleHandler::PassThruCacheDirectory (
2724 NormalizeFilename ( targetDirectory + SSEP + targetFilename ),
2725 backend->outputDirectory );
2726 fprintf ( fMakefile,
2727 "\t$(ECHO_CP)\n" );
2728 fprintf ( fMakefile,
2729 "\t${cp} %s %s 1>$(NUL)\n",
2730 sourceFilename.c_str (),
2731 normalizedTargetFilename.c_str () );
2732 }
2733
2734 void
2735 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string& livecdDirectory,
2736 string& reactosDirectory )
2737 {
2738 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2739 {
2740 const Module& m = *module.project.modules[i];
2741 if ( m.installName.length () > 0 )
2742 {
2743 string sourceFilename = MingwModuleHandler::PassThruCacheDirectory (
2744 NormalizeFilename ( m.GetPath () ),
2745 backend->outputDirectory );
2746 OutputCopyCommand ( sourceFilename,
2747 m.installName,
2748 livecdDirectory + SSEP + reactosDirectory + SSEP + m.installBase );
2749 }
2750 }
2751 }
2752
2753 void
2754 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string& livecdDirectory,
2755 string& reactosDirectory )
2756 {
2757 for ( size_t i = 0; i < module.project.installfiles.size (); i++ )
2758 {
2759 const InstallFile& installfile = *module.project.installfiles[i];
2760 OutputCopyCommand ( installfile.GetPath (),
2761 installfile.newname,
2762 livecdDirectory + SSEP + reactosDirectory + SSEP + installfile.base );
2763 }
2764 }
2765
2766 void
2767 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string& livecdDirectory )
2768 {
2769 CreateDirectory ( livecdDirectory + SSEP "Profiles" );
2770 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "All Users") ;
2771 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "All Users" SSEP "Desktop" );
2772 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "Default User" );
2773 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "Default User" SSEP "Desktop" );
2774 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "Default User" SSEP "My Documents" );
2775
2776 string livecdIni = "bootdata" SSEP "livecd.ini";
2777 OutputCopyCommand ( livecdIni,
2778 "freeldr.ini",
2779 livecdDirectory );
2780 }
2781
2782 void
2783 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string& livecdDirectory )
2784 {
2785 string freeldr = PassThruCacheDirectory (
2786 NormalizeFilename ( "boot" SSEP "freeldr" SSEP "freeldr" SSEP "freeldr.sys" ),
2787 backend->outputDirectory );
2788 CreateDirectory ( livecdDirectory + SSEP "loader" );
2789 OutputCopyCommand ( freeldr,
2790 "setupldr.sys",
2791 livecdDirectory + SSEP + "loader" );
2792 }
2793
2794 void
2795 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string& livecdDirectory )
2796 {
2797 string reactosSystem32ConfigDirectory = NormalizeFilename (
2798 MingwModuleHandler::PassThruCacheDirectory (
2799 livecdDirectory + SSEP "reactos" SSEP "system32" SSEP "config" SSEP,
2800 backend->outputDirectory ) );
2801 fprintf ( fMakefile,
2802 "\t$(ECHO_MKHIVE)\n" );
2803 fprintf ( fMakefile,
2804 "\t$(MKHIVE_TARGET) bootdata %s bootdata" SSEP "livecd.inf bootdata" SSEP "hiveinst.inf\n",
2805 reactosSystem32ConfigDirectory.c_str () );
2806 }
2807
2808 void
2809 MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
2810 {
2811 string livecdDirectory = "livecd";
2812 string livecd = PassThruCacheDirectory (
2813 NormalizeFilename ( livecdDirectory + SSEP ),
2814 backend->outputDirectory );
2815 string isoboot = PassThruCacheDirectory (
2816 NormalizeFilename ( "boot" SSEP "freeldr" SSEP "bootsect" SSEP "isoboot.o" ),
2817 backend->outputDirectory );
2818 string reactosDirectory = "reactos";
2819 string livecdReactosNoFixup = livecdDirectory + SSEP + reactosDirectory;
2820 string livecdReactos = NormalizeFilename ( PassThruCacheDirectory (
2821 NormalizeFilename ( livecdReactosNoFixup + SSEP ),
2822 backend->outputDirectory ) );
2823 CLEAN_FILE ( livecdReactos );
2824
2825 fprintf ( fMakefile, ".PHONY: %s\n\n",
2826 module.name.c_str ());
2827 fprintf ( fMakefile,
2828 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
2829 module.name.c_str (),
2830 isoboot.c_str (),
2831 livecdReactos.c_str () );
2832 OutputModuleCopyCommands ( livecdDirectory,
2833 reactosDirectory );
2834 OutputNonModuleCopyCommands ( livecdDirectory,
2835 reactosDirectory );
2836 OutputProfilesDirectoryCommands ( livecdDirectory );
2837 OutputLoaderCommands ( livecdDirectory );
2838 OutputRegistryCommands ( livecdDirectory );
2839 fprintf ( fMakefile, "\t$(ECHO_CDMAKE)\n" );
2840 fprintf ( fMakefile,
2841 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS ReactOS-LiveCD.iso\n",
2842 isoboot.c_str (),
2843 livecd.c_str () );
2844 fprintf ( fMakefile,
2845 "\n" );
2846 }
2847
2848
2849 MingwTestModuleHandler::MingwTestModuleHandler (
2850 const Module& module_ )
2851
2852 : MingwModuleHandler ( module_ )
2853 {
2854 }
2855
2856 void
2857 MingwTestModuleHandler::Process ()
2858 {
2859 GenerateTestModuleTarget ();
2860 }
2861
2862 void
2863 MingwTestModuleHandler::GenerateTestModuleTarget ()
2864 {
2865 string targetMacro ( GetTargetMacro ( module ) );
2866 string workingDirectory = GetWorkingDirectory ( );
2867 string objectsMacro = GetObjectsMacro ( module );
2868 string linkDepsMacro = GetLinkingDependenciesMacro ();
2869 string libsMacro = GetLibsMacro ();
2870
2871 GenerateImportLibraryTargetIfNeeded ();
2872
2873 if ( module.non_if_data.files.size () > 0 )
2874 {
2875 GenerateRules ();
2876
2877 string dependencies = linkDepsMacro + " " + objectsMacro;
2878
2879 string linker;
2880 if ( module.cplusplus )
2881 linker = "${gpp}";
2882 else
2883 linker = "${gcc}";
2884
2885 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2886 module.entrypoint.c_str (),
2887 module.baseaddress.c_str () );
2888 GenerateLinkerCommand ( dependencies,
2889 linker,
2890 linkerParameters,
2891 objectsMacro,
2892 libsMacro );
2893 }
2894 else
2895 {
2896 GeneratePhonyTarget();
2897 }
2898 }
2899
2900
2901 MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (
2902 const Module& module_ )
2903
2904 : MingwModuleHandler ( module_ )
2905 {
2906 }
2907
2908 void
2909 MingwRpcServerModuleHandler::Process ()
2910 {
2911 GenerateRules ();
2912 }
2913
2914 MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (
2915 const Module& module_ )
2916
2917 : MingwModuleHandler ( module_ )
2918 {
2919 }
2920
2921 void
2922 MingwRpcClientModuleHandler::Process ()
2923 {
2924 GenerateRules ();
2925 }