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