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