Merge 14551:14980 from trunk
[reactos.git] / reactos / tools / rbuild / backend / mingw / modulehandler.cpp
1 #include "../../pch.h"
2 #include <assert.h>
3
4 #include "../../rbuild.h"
5 #include "mingw.h"
6 #include "modulehandler.h"
7
8 using std::string;
9 using std::vector;
10
11 #define CLEAN_FILE(f) clean_files.push_back ( f );
12
13 static string ros_temp = "$(TEMPORARY)";
14 MingwBackend*
15 MingwModuleHandler::backend = NULL;
16 FILE*
17 MingwModuleHandler::fMakefile = NULL;
18 bool
19 MingwModuleHandler::use_pch = false;
20
21 string
22 PrefixFilename (
23 const string& filename,
24 const string& prefix )
25 {
26 if ( !prefix.length() )
27 return filename;
28 string out;
29 const char* pfilename = filename.c_str();
30 const char* p1 = strrchr ( pfilename, '/' );
31 const char* p2 = strrchr ( pfilename, '\\' );
32 if ( p1 || p2 )
33 {
34 if ( p2 > p1 )
35 p1 = p2;
36 out += string(pfilename,p1-pfilename) + CSEP;
37 pfilename = p1 + 1;
38 }
39 out += prefix + pfilename;
40 return out;
41 }
42
43 string
44 GetTargetMacro ( const Module& module, bool with_dollar )
45 {
46 string s ( module.name );
47 strupr ( &s[0] );
48 s += "_TARGET";
49 if ( with_dollar )
50 return ssprintf ( "$(%s)", s.c_str() );
51 return s;
52 }
53
54 MingwModuleHandler::MingwModuleHandler (
55 const Module& module_ )
56
57 : module(module_)
58 {
59 }
60
61 MingwModuleHandler::~MingwModuleHandler()
62 {
63 }
64
65 /*static*/ void
66 MingwModuleHandler::SetBackend ( MingwBackend* backend_ )
67 {
68 backend = backend_;
69 }
70
71 /*static*/ void
72 MingwModuleHandler::SetMakefile ( FILE* f )
73 {
74 fMakefile = f;
75 }
76
77 /*static*/ void
78 MingwModuleHandler::SetUsePch ( bool b )
79 {
80 use_pch = b;
81 }
82
83 /* static*/ string
84 MingwModuleHandler::RemoveVariables ( string path)
85 {
86 size_t i = path.find ( '$' );
87 if ( i != string::npos )
88 {
89 size_t j = path.find ( ')', i );
90 if ( j != string::npos )
91 {
92 if ( j + 2 < path.length () && path[j + 1] == CSEP )
93 return path.substr ( j + 2);
94 else
95 return path.substr ( j + 1);
96 }
97 }
98 return path;
99 }
100
101 /*static*/ string
102 MingwModuleHandler::PassThruCacheDirectory (
103 const string &file,
104 Directory* directoryTree )
105 {
106 string directory ( GetDirectory ( RemoveVariables ( file ) ) );
107 string generatedFilesDirectory = backend->AddDirectoryTarget ( directory,
108 directoryTree );
109 if ( directory.find ( generatedFilesDirectory ) != string::npos )
110 /* This path already includes the generated files directory variable */
111 return file;
112 else
113 return generatedFilesDirectory + SSEP + file;
114 }
115
116 /*static*/ 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 string
953 MingwModuleHandler::GetWidlFlags ( const File& file )
954 {
955 return file.switches;
956 }
957
958 void
959 MingwModuleHandler::GenerateWidlCommandsServer (
960 const File& file,
961 const string& widlflagsMacro )
962 {
963 string dependencies = file.name;
964 dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
965
966 string basename = GetBasename ( file.name );
967
968 /*string generatedHeaderFilename = PassThruCacheDirectory (
969 basename + ".h",
970 backend->intermediateDirectory );
971 CLEAN_FILE(generatedHeaderFilename);
972 */
973 string generatedHeaderFilename = basename + "_s.h";
974 CLEAN_FILE(generatedHeaderFilename);
975
976 string generatedServerFilename = PassThruCacheDirectory (
977 basename + "_s.c",
978 backend->intermediateDirectory );
979 CLEAN_FILE(generatedServerFilename);
980
981 fprintf ( fMakefile,
982 "%s %s: %s $(WIDL_TARGET) | %s\n",
983 generatedServerFilename.c_str (),
984 generatedHeaderFilename.c_str (),
985 dependencies.c_str (),
986 GetDirectory ( generatedServerFilename ).c_str () );
987 fprintf ( fMakefile, "\t$(ECHO_WIDL)\n" );
988 fprintf ( fMakefile,
989 "\t%s %s %s -h -H %s -s -S %s %s\n",
990 "$(Q)$(WIDL_TARGET)",
991 GetWidlFlags ( file ).c_str (),
992 widlflagsMacro.c_str (),
993 generatedHeaderFilename.c_str (),
994 generatedServerFilename.c_str (),
995 file.name.c_str () );
996 }
997
998 void
999 MingwModuleHandler::GenerateWidlCommandsClient (
1000 const File& file,
1001 const string& widlflagsMacro )
1002 {
1003 string dependencies = file.name;
1004 dependencies += " " + NormalizeFilename ( module.xmlbuildFile );
1005
1006 string basename = GetBasename ( file.name );
1007
1008 /*string generatedHeaderFilename = PassThruCacheDirectory (
1009 basename + ".h",
1010 backend->intermediateDirectory );
1011 CLEAN_FILE(generatedHeaderFilename);
1012 */
1013 string generatedHeaderFilename = basename + "_c.h";
1014 CLEAN_FILE(generatedHeaderFilename);
1015
1016 string generatedClientFilename = PassThruCacheDirectory (
1017 basename + "_c.c",
1018 backend->intermediateDirectory );
1019 CLEAN_FILE(generatedClientFilename);
1020
1021 fprintf ( fMakefile,
1022 "%s %s: %s $(WIDL_TARGET) | %s\n",
1023 generatedClientFilename.c_str (),
1024 generatedHeaderFilename.c_str (),
1025 dependencies.c_str (),
1026 GetDirectory ( generatedClientFilename ).c_str () );
1027 fprintf ( fMakefile, "\t$(ECHO_WIDL)\n" );
1028 fprintf ( fMakefile,
1029 "\t%s %s %s -h -H %s -c -C %s %s\n",
1030 "$(Q)$(WIDL_TARGET)",
1031 GetWidlFlags ( file ).c_str (),
1032 widlflagsMacro.c_str (),
1033 generatedHeaderFilename.c_str (),
1034 generatedClientFilename.c_str (),
1035 file.name.c_str () );
1036 }
1037
1038 void
1039 MingwModuleHandler::GenerateWidlCommands (
1040 const File& file,
1041 const string& widlflagsMacro )
1042 {
1043 if ( module.type == RpcServer )
1044 GenerateWidlCommandsServer ( file,
1045 widlflagsMacro );
1046 else
1047 GenerateWidlCommandsClient ( file,
1048 widlflagsMacro );
1049 }
1050
1051 void
1052 MingwModuleHandler::GenerateCommands (
1053 const File& file,
1054 const string& cc,
1055 const string& cppc,
1056 const string& cflagsMacro,
1057 const string& nasmflagsMacro,
1058 const string& windresflagsMacro,
1059 const string& widlflagsMacro )
1060 {
1061 string extension = GetExtension ( file.name );
1062 if ( extension == ".c" || extension == ".C" )
1063 {
1064 GenerateGccCommand ( file.name,
1065 cc,
1066 cflagsMacro );
1067 return;
1068 }
1069 else if ( extension == ".cc" || extension == ".CC" ||
1070 extension == ".cpp" || extension == ".CPP" ||
1071 extension == ".cxx" || extension == ".CXX" )
1072 {
1073 GenerateGccCommand ( file.name,
1074 cppc,
1075 cflagsMacro );
1076 return;
1077 }
1078 else if ( extension == ".s" || extension == ".S" )
1079 {
1080 GenerateGccAssemblerCommand ( file.name,
1081 cc,
1082 cflagsMacro );
1083 return;
1084 }
1085 else if ( extension == ".asm" || extension == ".ASM" )
1086 {
1087 GenerateNasmCommand ( file.name,
1088 nasmflagsMacro );
1089 return;
1090 }
1091 else if ( extension == ".rc" || extension == ".RC" )
1092 {
1093 GenerateWindresCommand ( file.name,
1094 windresflagsMacro );
1095 return;
1096 }
1097 else if ( extension == ".spec" || extension == ".SPEC" )
1098 {
1099 GenerateWinebuildCommands ( file.name );
1100 GenerateGccCommand ( GetActualSourceFilename ( file.name ),
1101 cc,
1102 cflagsMacro );
1103 return;
1104 }
1105 else if ( extension == ".idl" || extension == ".IDL" )
1106 {
1107 GenerateWidlCommands ( file,
1108 widlflagsMacro );
1109 GenerateGccCommand ( GetActualSourceFilename ( file.name ),
1110 cc,
1111 cflagsMacro );
1112 return;
1113 }
1114
1115 throw InvalidOperationException ( __FILE__,
1116 __LINE__,
1117 "Unsupported filename extension '%s' in file '%s'",
1118 extension.c_str (),
1119 file.name.c_str () );
1120 }
1121
1122 void
1123 MingwModuleHandler::GenerateBuildMapCode ()
1124 {
1125 fprintf ( fMakefile,
1126 "ifeq ($(ROS_BUILDMAP),full)\n" );
1127
1128 string mapFilename = PassThruCacheDirectory (
1129 GetBasename ( module.GetPath () ) + ".map",
1130 backend->outputDirectory );
1131 CLEAN_FILE ( mapFilename );
1132
1133 fprintf ( fMakefile,
1134 "\t$(ECHO_OBJDUMP)\n" );
1135 fprintf ( fMakefile,
1136 "\t$(Q)${objdump} -d -S $@ > %s\n",
1137 mapFilename.c_str () );
1138
1139 fprintf ( fMakefile,
1140 "else\n" );
1141 fprintf ( fMakefile,
1142 "ifeq ($(ROS_BUILDMAP),yes)\n" );
1143
1144 fprintf ( fMakefile,
1145 "\t$(ECHO_NM)\n" );
1146 fprintf ( fMakefile,
1147 "\t$(Q)${nm} --numeric-sort $@ > %s\n",
1148 mapFilename.c_str () );
1149
1150 fprintf ( fMakefile,
1151 "endif\n" );
1152
1153 fprintf ( fMakefile,
1154 "endif\n" );
1155 }
1156
1157 void
1158 MingwModuleHandler::GenerateBuildNonSymbolStrippedCode ()
1159 {
1160 fprintf ( fMakefile,
1161 "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" );
1162
1163 string filename = module.GetPath ();
1164 string outputFilename = PassThruCacheDirectory (
1165 filename,
1166 backend->outputDirectory );
1167 string nostripFilename = PassThruCacheDirectory (
1168 GetBasename ( filename ) + ".nostrip" + GetExtension ( filename ),
1169 backend->outputDirectory );
1170 CLEAN_FILE ( nostripFilename );
1171
1172 fprintf ( fMakefile,
1173 "\t$(ECHO_CP)\n" );
1174 fprintf ( fMakefile,
1175 "\t${cp} %s %s 1>$(NUL)\n",
1176 outputFilename.c_str (),
1177 nostripFilename.c_str () );
1178
1179 fprintf ( fMakefile,
1180 "endif\n" );
1181 }
1182
1183 void
1184 MergeStringVector ( const vector<string>& input,
1185 vector<string>& output )
1186 {
1187 int wrap_at = 25;
1188 string s;
1189 int wrap_count = -1;
1190 for ( size_t i = 0; i < input.size (); i++ )
1191 {
1192 if ( input[i].size () == 0 )
1193 continue;
1194 if ( wrap_count++ == wrap_at )
1195 {
1196 output.push_back ( s );
1197 s = "";
1198 wrap_count = 0;
1199 }
1200 else if ( s.size () > 0)
1201 s += " ";
1202 s += input[i];
1203 }
1204 if ( s.length () > 0 )
1205 output.push_back ( s );
1206 }
1207
1208 void
1209 MingwModuleHandler::GetObjectsVector ( const IfableData& data,
1210 vector<string>& objectFiles ) const
1211 {
1212 for ( size_t i = 0; i < data.files.size (); i++ )
1213 {
1214 File& file = *data.files[i];
1215 objectFiles.push_back ( GetObjectFilename ( file.name, NULL ) );
1216 }
1217 }
1218
1219 void
1220 MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const
1221 {
1222 if ( backend->cleanAsYouGo )
1223 {
1224 vector<string> objectFiles;
1225 GetObjectsVector ( module.non_if_data,
1226 objectFiles );
1227 vector<string> lines;
1228 MergeStringVector ( objectFiles,
1229 lines );
1230 for ( size_t i = 0; i < lines.size (); i++ )
1231 {
1232 fprintf ( fMakefile,
1233 "\t-@${rm} %s 2>$(NUL)\n",
1234 lines[i].c_str () );
1235 }
1236 }
1237 }
1238
1239 void
1240 MingwModuleHandler::GenerateLinkerCommand (
1241 const string& dependencies,
1242 const string& linker,
1243 const string& linkerParameters,
1244 const string& objectsMacro,
1245 const string& libsMacro )
1246 {
1247 string target ( GetTargetMacro ( module ) );
1248 string target_folder ( GetDirectory ( GetTargetFilename ( module, NULL ) ) );
1249
1250 fprintf ( fMakefile,
1251 "%s: %s $(RSYM_TARGET) | %s\n",
1252 target.c_str (),
1253 dependencies.c_str (),
1254 target_folder.c_str () );
1255 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
1256 string targetName ( module.GetTargetName () );
1257 if ( module.importLibrary != NULL )
1258 {
1259 string base_tmp = ros_temp + module.name + ".base.tmp";
1260 CLEAN_FILE ( base_tmp );
1261 string junk_tmp = ros_temp + module.name + ".junk.tmp";
1262 CLEAN_FILE ( junk_tmp );
1263 string temp_exp = ros_temp + module.name + ".temp.exp";
1264 CLEAN_FILE ( temp_exp );
1265 string def_file = GetDefinitionFilename ();
1266
1267 fprintf ( fMakefile,
1268 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
1269 linker.c_str (),
1270 linkerParameters.c_str (),
1271 base_tmp.c_str (),
1272 junk_tmp.c_str (),
1273 objectsMacro.c_str (),
1274 libsMacro.c_str (),
1275 GetLinkerMacro ().c_str () );
1276
1277 fprintf ( fMakefile,
1278 "\t-@${rm} %s 2>$(NUL)\n",
1279 junk_tmp.c_str () );
1280
1281 string killAt = module.mangledSymbols ? "" : "--kill-at";
1282 fprintf ( fMakefile,
1283 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
1284 targetName.c_str (),
1285 base_tmp.c_str (),
1286 def_file.c_str (),
1287 temp_exp.c_str (),
1288 killAt.c_str () );
1289
1290 fprintf ( fMakefile,
1291 "\t-@${rm} %s 2>$(NUL)\n",
1292 base_tmp.c_str () );
1293
1294 fprintf ( fMakefile,
1295 "\t%s %s %s -o %s %s %s %s\n",
1296 linker.c_str (),
1297 linkerParameters.c_str (),
1298 temp_exp.c_str (),
1299 target.c_str (),
1300 objectsMacro.c_str (),
1301 libsMacro.c_str (),
1302 GetLinkerMacro ().c_str () );
1303
1304 fprintf ( fMakefile,
1305 "\t-@${rm} %s 2>$(NUL)\n",
1306 temp_exp.c_str () );
1307
1308 GenerateCleanObjectsAsYouGoCode ();
1309 }
1310 else
1311 {
1312 fprintf ( fMakefile,
1313 "\t%s %s -o %s %s %s %s\n",
1314 linker.c_str (),
1315 linkerParameters.c_str (),
1316 target.c_str (),
1317 objectsMacro.c_str (),
1318 libsMacro.c_str (),
1319 GetLinkerMacro ().c_str () );
1320
1321 GenerateCleanObjectsAsYouGoCode ();
1322 }
1323
1324 GenerateBuildMapCode ();
1325
1326 GenerateBuildNonSymbolStrippedCode ();
1327
1328 fprintf ( fMakefile,
1329 "\t$(ECHO_RSYM)\n" );
1330 fprintf ( fMakefile,
1331 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1332 }
1333
1334 void
1335 MingwModuleHandler::GeneratePhonyTarget() const
1336 {
1337 string targetMacro ( GetTargetMacro(module) );
1338 fprintf ( fMakefile, ".PHONY: %s\n\n",
1339 targetMacro.c_str ());
1340 fprintf ( fMakefile, "%s: | %s\n",
1341 targetMacro.c_str (),
1342 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
1343 }
1344
1345 void
1346 MingwModuleHandler::GenerateObjectFileTargets (
1347 const IfableData& data,
1348 const string& cc,
1349 const string& cppc,
1350 const string& cflagsMacro,
1351 const string& nasmflagsMacro,
1352 const string& windresflagsMacro,
1353 const string& widlflagsMacro )
1354 {
1355 size_t i;
1356
1357 const vector<File*>& files = data.files;
1358 for ( i = 0; i < files.size (); i++ )
1359 {
1360 GenerateCommands ( *files[i],
1361 cc,
1362 cppc,
1363 cflagsMacro,
1364 nasmflagsMacro,
1365 windresflagsMacro,
1366 widlflagsMacro );
1367 fprintf ( fMakefile,
1368 "\n" );
1369 }
1370
1371 const vector<If*>& ifs = data.ifs;
1372 for ( i = 0; i < ifs.size(); i++ )
1373 {
1374 GenerateObjectFileTargets ( ifs[i]->data,
1375 cc,
1376 cppc,
1377 cflagsMacro,
1378 nasmflagsMacro,
1379 windresflagsMacro,
1380 widlflagsMacro );
1381 }
1382 }
1383
1384 void
1385 MingwModuleHandler::GenerateObjectFileTargets (
1386 const string& cc,
1387 const string& cppc,
1388 const string& cflagsMacro,
1389 const string& nasmflagsMacro,
1390 const string& windresflagsMacro,
1391 const string& widlflagsMacro )
1392 {
1393 if ( module.pch )
1394 {
1395 const string& pch_file = module.pch->header;
1396 string gch_file = pch_file + ".gch";
1397 CLEAN_FILE(gch_file);
1398 if ( use_pch )
1399 {
1400 fprintf (
1401 fMakefile,
1402 "%s: %s\n",
1403 gch_file.c_str(),
1404 pch_file.c_str() );
1405 fprintf ( fMakefile, "\t$(ECHO_PCH)\n" );
1406 fprintf (
1407 fMakefile,
1408 "\t%s -o %s %s -g %s\n\n",
1409 ( module.cplusplus ? cppc.c_str() : cc.c_str() ),
1410 gch_file.c_str(),
1411 cflagsMacro.c_str(),
1412 pch_file.c_str() );
1413 }
1414 }
1415
1416 GenerateObjectFileTargets ( module.non_if_data,
1417 cc,
1418 cppc,
1419 cflagsMacro,
1420 nasmflagsMacro,
1421 windresflagsMacro,
1422 widlflagsMacro );
1423 fprintf ( fMakefile, "\n" );
1424 }
1425
1426 string
1427 MingwModuleHandler::GenerateArchiveTarget ( const string& ar,
1428 const string& objs_macro ) const
1429 {
1430 string archiveFilename ( GetModuleArchiveFilename () );
1431
1432 fprintf ( fMakefile,
1433 "%s: %s | %s\n",
1434 archiveFilename.c_str (),
1435 objs_macro.c_str (),
1436 GetDirectory(archiveFilename).c_str() );
1437
1438 fprintf ( fMakefile, "\t$(ECHO_AR)\n" );
1439
1440 fprintf ( fMakefile,
1441 "\t%s -rc $@ %s\n",
1442 ar.c_str (),
1443 objs_macro.c_str ());
1444
1445 GenerateCleanObjectsAsYouGoCode ();
1446
1447 fprintf ( fMakefile, "\n" );
1448
1449 return archiveFilename;
1450 }
1451
1452 string
1453 MingwModuleHandler::GetCFlagsMacro () const
1454 {
1455 return ssprintf ( "$(%s_CFLAGS)",
1456 module.name.c_str () );
1457 }
1458
1459 /*static*/ string
1460 MingwModuleHandler::GetObjectsMacro ( const Module& module )
1461 {
1462 return ssprintf ( "$(%s_OBJS)",
1463 module.name.c_str () );
1464 }
1465
1466 string
1467 MingwModuleHandler::GetLinkingDependenciesMacro () const
1468 {
1469 return ssprintf ( "$(%s_LINKDEPS)", module.name.c_str () );
1470 }
1471
1472 string
1473 MingwModuleHandler::GetLibsMacro () const
1474 {
1475 return ssprintf ( "$(%s_LIBS)", module.name.c_str () );
1476 }
1477
1478 string
1479 MingwModuleHandler::GetLinkerMacro () const
1480 {
1481 return ssprintf ( "$(%s_LFLAGS)",
1482 module.name.c_str () );
1483 }
1484
1485 string
1486 MingwModuleHandler::GetModuleTargets ( const Module& module )
1487 {
1488 if ( ReferenceObjects ( module ) )
1489 return GetObjectsMacro ( module );
1490 else
1491 return GetTargetFilename ( module, NULL );
1492 }
1493
1494 void
1495 MingwModuleHandler::GenerateObjectMacro ()
1496 {
1497 objectsMacro = ssprintf ("%s_OBJS", module.name.c_str ());
1498
1499 GenerateObjectMacros (
1500 "=",
1501 module.non_if_data,
1502 &module.compilerFlags,
1503 &module.linkerFlags );
1504
1505 // future references to the macro will be to get its values
1506 objectsMacro = ssprintf ("$(%s)", objectsMacro.c_str ());
1507 }
1508
1509 void
1510 MingwModuleHandler::GenerateTargetMacro ()
1511 {
1512 fprintf ( fMakefile,
1513 "%s := %s\n",
1514 GetTargetMacro ( module, false ).c_str (),
1515 GetModuleTargets ( module ).c_str () );
1516 }
1517
1518 void
1519 MingwModuleHandler::GenerateOtherMacros ()
1520 {
1521 cflagsMacro = ssprintf ("%s_CFLAGS", module.name.c_str ());
1522 nasmflagsMacro = ssprintf ("%s_NASMFLAGS", module.name.c_str ());
1523 windresflagsMacro = ssprintf ("%s_RCFLAGS", module.name.c_str ());
1524 widlflagsMacro = ssprintf ("%s_WIDLFLAGS", module.name.c_str ());
1525 linkerflagsMacro = ssprintf ("%s_LFLAGS", module.name.c_str ());
1526 libsMacro = ssprintf("%s_LIBS", module.name.c_str ());
1527 linkDepsMacro = ssprintf ("%s_LINKDEPS", module.name.c_str ());
1528
1529 GenerateMacros (
1530 "=",
1531 module.non_if_data,
1532 &module.compilerFlags,
1533 &module.linkerFlags );
1534
1535 if ( module.importLibrary )
1536 {
1537 string_list s;
1538 const vector<File*>& files = module.non_if_data.files;
1539 for ( size_t i = 0; i < files.size (); i++ )
1540 {
1541 File& file = *files[i];
1542 string extension = GetExtension ( file.name );
1543 if ( extension == ".spec" || extension == ".SPEC" )
1544 GetSpecObjectDependencies ( s, file.name );
1545 }
1546 if ( s.size () > 0 )
1547 {
1548 fprintf (
1549 fMakefile,
1550 "%s +=",
1551 linkDepsMacro.c_str() );
1552 for ( size_t i = 0; i < s.size(); i++ )
1553 fprintf ( fMakefile,
1554 " %s",
1555 s[i].c_str () );
1556 fprintf ( fMakefile, "\n" );
1557 }
1558 }
1559
1560 string globalCflags = "-g";
1561 if ( backend->usePipe )
1562 globalCflags += " -pipe";
1563 if ( !module.enableWarnings )
1564 globalCflags += " -Werror";
1565
1566 fprintf (
1567 fMakefile,
1568 "%s += $(PROJECT_CFLAGS) %s\n",
1569 cflagsMacro.c_str (),
1570 globalCflags.c_str () );
1571
1572 fprintf (
1573 fMakefile,
1574 "%s += $(PROJECT_RCFLAGS)\n",
1575 windresflagsMacro.c_str () );
1576
1577 fprintf (
1578 fMakefile,
1579 "%s += $(PROJECT_WIDLFLAGS)\n",
1580 widlflagsMacro.c_str () );
1581
1582 fprintf (
1583 fMakefile,
1584 "%s_LFLAGS += $(PROJECT_LFLAGS) -g\n",
1585 module.name.c_str () );
1586
1587 fprintf (
1588 fMakefile,
1589 "%s += $(%s)\n",
1590 linkDepsMacro.c_str (),
1591 libsMacro.c_str () );
1592
1593 string cflags = TypeSpecificCFlags();
1594 if ( cflags.size() > 0 )
1595 {
1596 fprintf ( fMakefile,
1597 "%s += %s\n\n",
1598 cflagsMacro.c_str (),
1599 cflags.c_str () );
1600 }
1601
1602 string nasmflags = TypeSpecificNasmFlags();
1603 if ( nasmflags.size () > 0 )
1604 {
1605 fprintf ( fMakefile,
1606 "%s += %s\n\n",
1607 nasmflagsMacro.c_str (),
1608 nasmflags.c_str () );
1609 }
1610
1611 string linkerflags = TypeSpecificLinkerFlags();
1612 if ( linkerflags.size() > 0 )
1613 {
1614 fprintf ( fMakefile,
1615 "%s += %s\n\n",
1616 linkerflagsMacro.c_str (),
1617 linkerflags.c_str () );
1618 }
1619
1620 fprintf ( fMakefile, "\n\n" );
1621
1622 // future references to the macros will be to get their values
1623 cflagsMacro = ssprintf ("$(%s)", cflagsMacro.c_str ());
1624 nasmflagsMacro = ssprintf ("$(%s)", nasmflagsMacro.c_str ());
1625 widlflagsMacro = ssprintf ("$(%s)", widlflagsMacro.c_str ());
1626 }
1627
1628 void
1629 MingwModuleHandler::GenerateRules ()
1630 {
1631 string cc = ( module.host == HostTrue ? "${host_gcc}" : "${gcc}" );
1632 string cppc = ( module.host == HostTrue ? "${host_gpp}" : "${gpp}" );
1633 string ar = ( module.host == HostTrue ? "${host_ar}" : "${ar}" );
1634
1635 string targetMacro = GetTargetMacro ( module );
1636
1637 CLEAN_FILE ( targetMacro );
1638
1639 // generate phony target for module name
1640 fprintf ( fMakefile, ".PHONY: %s\n",
1641 module.name.c_str () );
1642 fprintf ( fMakefile, "%s: %s\n\n",
1643 module.name.c_str (),
1644 GetTargetMacro ( module ).c_str () );
1645
1646 if ( !ReferenceObjects ( module ) )
1647 {
1648 string ar_target ( GenerateArchiveTarget ( ar, objectsMacro ) );
1649 if ( targetMacro != ar_target )
1650 {
1651 CLEAN_FILE ( ar_target );
1652 }
1653 }
1654
1655 GenerateObjectFileTargets ( cc,
1656 cppc,
1657 cflagsMacro,
1658 nasmflagsMacro,
1659 windresflagsMacro,
1660 widlflagsMacro );
1661 }
1662
1663 void
1664 MingwModuleHandler::GetInvocationDependencies (
1665 const Module& module,
1666 string_list& dependencies )
1667 {
1668 for ( size_t i = 0; i < module.invocations.size (); i++ )
1669 {
1670 Invoke& invoke = *module.invocations[i];
1671 if ( invoke.invokeModule == &module )
1672 /* Protect against circular dependencies */
1673 continue;
1674 invoke.GetTargets ( dependencies );
1675 }
1676 }
1677
1678 void
1679 MingwModuleHandler::GenerateInvocations () const
1680 {
1681 if ( module.invocations.size () == 0 )
1682 return;
1683
1684 size_t iend = module.invocations.size ();
1685 for ( size_t i = 0; i < iend; i++ )
1686 {
1687 const Invoke& invoke = *module.invocations[i];
1688
1689 if ( invoke.invokeModule->type != BuildTool )
1690 {
1691 throw InvalidBuildFileException ( module.node.location,
1692 "Only modules of type buildtool can be invoked." );
1693 }
1694
1695 string invokeTarget = module.GetInvocationTarget ( i );
1696 string_list invoke_targets;
1697 assert ( invoke_targets.size() );
1698 invoke.GetTargets ( invoke_targets );
1699 fprintf ( fMakefile,
1700 ".PHONY: %s\n\n",
1701 invokeTarget.c_str () );
1702 fprintf ( fMakefile,
1703 "%s:",
1704 invokeTarget.c_str () );
1705 size_t j, jend = invoke_targets.size();
1706 for ( j = 0; j < jend; j++ )
1707 {
1708 fprintf ( fMakefile,
1709 " %s",
1710 invoke_targets[i].c_str () );
1711 }
1712 fprintf ( fMakefile, "\n\n%s", invoke_targets[0].c_str () );
1713 for ( j = 1; j < jend; j++ )
1714 fprintf ( fMakefile,
1715 " %s",
1716 invoke_targets[i].c_str () );
1717 fprintf ( fMakefile,
1718 ": %s\n",
1719 NormalizeFilename ( invoke.invokeModule->GetPath () ).c_str () );
1720 fprintf ( fMakefile, "\t$(ECHO_INVOKE)\n" );
1721 fprintf ( fMakefile,
1722 "\t%s %s\n\n",
1723 NormalizeFilename ( invoke.invokeModule->GetPath () ).c_str (),
1724 invoke.GetParameters ().c_str () );
1725 }
1726 }
1727
1728 string
1729 MingwModuleHandler::GetPreconditionDependenciesName () const
1730 {
1731 return module.name + "_precondition";
1732 }
1733
1734 void
1735 MingwModuleHandler::GetDefaultDependencies (
1736 string_list& dependencies ) const
1737 {
1738 /* Avoid circular dependency */
1739 if ( module.type != BuildTool
1740 && module.name != "zlib"
1741 && module.name != "hostzlib" )
1742
1743 dependencies.push_back ( "$(INIT)" );
1744 }
1745
1746 void
1747 MingwModuleHandler::GeneratePreconditionDependencies ()
1748 {
1749 string preconditionDependenciesName = GetPreconditionDependenciesName ();
1750 string_list sourceFilenames;
1751 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames );
1752 string_list dependencies;
1753 GetDefaultDependencies ( dependencies );
1754 GetModuleDependencies ( dependencies );
1755
1756 GetInvocationDependencies ( module, dependencies );
1757
1758 if ( dependencies.size() )
1759 {
1760 fprintf ( fMakefile,
1761 "%s =",
1762 preconditionDependenciesName.c_str () );
1763 for ( size_t i = 0; i < dependencies.size(); i++ )
1764 fprintf ( fMakefile,
1765 " %s",
1766 dependencies[i].c_str () );
1767 fprintf ( fMakefile, "\n\n" );
1768 }
1769
1770 for ( size_t i = 0; i < sourceFilenames.size(); i++ )
1771 {
1772 fprintf ( fMakefile,
1773 "%s: ${%s}\n",
1774 sourceFilenames[i].c_str(),
1775 preconditionDependenciesName.c_str ());
1776 }
1777 fprintf ( fMakefile, "\n" );
1778 }
1779
1780 bool
1781 MingwModuleHandler::IsWineModule () const
1782 {
1783 if ( module.importLibrary == NULL)
1784 return false;
1785
1786 size_t index = module.importLibrary->definition.rfind ( ".spec.def" );
1787 return ( index != string::npos );
1788 }
1789
1790 string
1791 MingwModuleHandler::GetDefinitionFilename () const
1792 {
1793 string defFilename = module.GetBasePath () + SSEP + module.importLibrary->definition;
1794 if ( IsWineModule () )
1795 return PassThruCacheDirectory ( NormalizeFilename ( defFilename ),
1796 backend->intermediateDirectory );
1797 else
1798 return defFilename;
1799 }
1800
1801 void
1802 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
1803 {
1804 if ( module.importLibrary != NULL )
1805 {
1806 string library_target (
1807 GetImportLibraryFilename ( module, &clean_files ) );
1808
1809 string_list deps;
1810 GetDefinitionDependencies ( deps );
1811
1812 fprintf ( fMakefile, "# IMPORT LIBRARY RULE:\n" );
1813
1814 fprintf ( fMakefile, "%s:",
1815 library_target.c_str () );
1816
1817 size_t i, iend = deps.size();
1818 for ( i = 0; i < iend; i++ )
1819 fprintf ( fMakefile, " %s",
1820 deps[i].c_str () );
1821
1822 fprintf ( fMakefile, " | %s\n",
1823 GetDirectory ( GetTargetFilename ( module, NULL ) ).c_str () );
1824
1825 fprintf ( fMakefile, "\t$(ECHO_DLLTOOL)\n" );
1826
1827 string killAt = module.mangledSymbols ? "" : "--kill-at";
1828 fprintf ( fMakefile,
1829 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1830 module.GetTargetName ().c_str (),
1831 GetDefinitionFilename ().c_str (),
1832 library_target.c_str (),
1833 killAt.c_str () );
1834 }
1835 }
1836
1837 void
1838 MingwModuleHandler::GetSpecObjectDependencies (
1839 string_list& dependencies,
1840 const string& filename ) const
1841 {
1842 string basename = GetBasename ( filename );
1843 string defDependency = PassThruCacheDirectory (
1844 NormalizeFilename ( basename + ".spec.def" ),
1845 backend->intermediateDirectory );
1846 dependencies.push_back ( defDependency );
1847 string stubsDependency = PassThruCacheDirectory (
1848 NormalizeFilename ( basename + ".stubs.c" ),
1849 backend->intermediateDirectory );
1850 dependencies.push_back ( stubsDependency );
1851 }
1852
1853 void
1854 MingwModuleHandler::GetWidlObjectDependencies (
1855 string_list& dependencies,
1856 const string& filename ) const
1857 {
1858 string basename = GetBasename ( filename );
1859 string serverDependency = PassThruCacheDirectory (
1860 NormalizeFilename ( basename + "_s.c" ),
1861 backend->intermediateDirectory );
1862 dependencies.push_back ( serverDependency );
1863 }
1864
1865 void
1866 MingwModuleHandler::GetDefinitionDependencies (
1867 string_list& dependencies ) const
1868 {
1869 string dkNkmLibNoFixup = "dk/nkm/lib";
1870 const vector<File*>& files = module.non_if_data.files;
1871 for ( size_t i = 0; i < files.size (); i++ )
1872 {
1873 File& file = *files[i];
1874 string extension = GetExtension ( file.name );
1875 if ( extension == ".spec" || extension == ".SPEC" )
1876 {
1877 GetSpecObjectDependencies ( dependencies, file.name );
1878 }
1879 if ( extension == ".idl" || extension == ".IDL" )
1880 {
1881 GetWidlObjectDependencies ( dependencies, file.name );
1882 }
1883 }
1884 }
1885
1886
1887 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module& module_ )
1888 : MingwModuleHandler ( module_ )
1889 {
1890 }
1891
1892 void
1893 MingwBuildToolModuleHandler::Process ()
1894 {
1895 GenerateBuildToolModuleTarget ();
1896 }
1897
1898 void
1899 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
1900 {
1901 string targetMacro ( GetTargetMacro (module) );
1902 string objectsMacro = GetObjectsMacro ( module );
1903 string linkDepsMacro = GetLinkingDependenciesMacro ();
1904 string libsMacro = GetLibsMacro ();
1905
1906 GenerateRules ();
1907
1908 string linker;
1909 if ( module.cplusplus )
1910 linker = "${host_gpp}";
1911 else
1912 linker = "${host_gcc}";
1913
1914 fprintf ( fMakefile, "%s: %s %s | %s\n",
1915 targetMacro.c_str (),
1916 objectsMacro.c_str (),
1917 linkDepsMacro.c_str (),
1918 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
1919 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
1920 fprintf ( fMakefile,
1921 "\t%s %s -o $@ %s %s\n\n",
1922 linker.c_str (),
1923 GetLinkerMacro ().c_str (),
1924 objectsMacro.c_str (),
1925 libsMacro.c_str () );
1926 }
1927
1928
1929 MingwKernelModuleHandler::MingwKernelModuleHandler (
1930 const Module& module_ )
1931
1932 : MingwModuleHandler ( module_ )
1933 {
1934 }
1935
1936 void
1937 MingwKernelModuleHandler::Process ()
1938 {
1939 GenerateKernelModuleTarget ();
1940 }
1941
1942 void
1943 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
1944 {
1945 string targetName ( module.GetTargetName () ); // i.e. "ntoskrnl.exe"
1946 string targetMacro ( GetTargetMacro ( module ) ); // i.e. "$(NTOSKRNL_TARGET)"
1947 string workingDirectory = GetWorkingDirectory ();
1948 string objectsMacro = GetObjectsMacro ( module );
1949 string linkDepsMacro = GetLinkingDependenciesMacro ();
1950 string libsMacro = GetLibsMacro ();
1951 string base_tmp = ros_temp + module.name + ".base.tmp";
1952 CLEAN_FILE ( base_tmp );
1953 string junk_tmp = ros_temp + module.name + ".junk.tmp";
1954 CLEAN_FILE ( junk_tmp );
1955 string temp_exp = ros_temp + module.name + ".temp.exp";
1956 CLEAN_FILE ( temp_exp );
1957 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",
1958 module.GetBasePath ().c_str (),
1959 module.entrypoint.c_str (),
1960 module.baseaddress.c_str () );
1961
1962 GenerateRules ();
1963
1964 GenerateImportLibraryTargetIfNeeded ();
1965
1966 fprintf ( fMakefile, "%s: %s %s $(RSYM_TARGET) | %s\n",
1967 targetMacro.c_str (),
1968 objectsMacro.c_str (),
1969 linkDepsMacro.c_str (),
1970 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
1971 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
1972 fprintf ( fMakefile,
1973 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1974 GetLinkerMacro ().c_str (),
1975 gccOptions.c_str (),
1976 base_tmp.c_str (),
1977 junk_tmp.c_str (),
1978 objectsMacro.c_str (),
1979 linkDepsMacro.c_str () );
1980 fprintf ( fMakefile,
1981 "\t-@${rm} %s 2>$(NUL)\n",
1982 junk_tmp.c_str () );
1983 string killAt = module.mangledSymbols ? "" : "--kill-at";
1984 fprintf ( fMakefile,
1985 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1986 targetName.c_str (),
1987 base_tmp.c_str (),
1988 temp_exp.c_str (),
1989 killAt.c_str () );
1990 fprintf ( fMakefile,
1991 "\t-@${rm} %s 2>$(NUL)\n",
1992 base_tmp.c_str () );
1993 fprintf ( fMakefile,
1994 "\t${gcc} %s %s -Wl,%s -o $@ %s %s\n",
1995 GetLinkerMacro ().c_str (),
1996 gccOptions.c_str (),
1997 temp_exp.c_str (),
1998 objectsMacro.c_str (),
1999 linkDepsMacro.c_str () );
2000 fprintf ( fMakefile,
2001 "\t-@${rm} %s 2>$(NUL)\n",
2002 temp_exp.c_str () );
2003 fprintf ( fMakefile, "\t$(ECHO_RSYM)\n" );
2004 fprintf ( fMakefile,
2005 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
2006 }
2007
2008
2009 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
2010 const Module& module_ )
2011
2012 : MingwModuleHandler ( module_ )
2013 {
2014 }
2015
2016 void
2017 MingwStaticLibraryModuleHandler::Process ()
2018 {
2019 GenerateStaticLibraryModuleTarget ();
2020 }
2021
2022 void
2023 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
2024 {
2025 GenerateRules ();
2026 }
2027
2028
2029 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
2030 const Module& module_ )
2031
2032 : MingwModuleHandler ( module_ )
2033 {
2034 }
2035
2036 void
2037 MingwObjectLibraryModuleHandler::Process ()
2038 {
2039 GenerateObjectLibraryModuleTarget ();
2040 }
2041
2042 void
2043 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
2044 {
2045 GenerateRules ();
2046 }
2047
2048
2049 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
2050 const Module& module_ )
2051
2052 : MingwModuleHandler ( module_ )
2053 {
2054 }
2055
2056 void
2057 MingwKernelModeDLLModuleHandler::Process ()
2058 {
2059 GenerateKernelModeDLLModuleTarget ();
2060 }
2061
2062 void
2063 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
2064 {
2065 string targetMacro ( GetTargetMacro ( module ) );
2066 string workingDirectory = GetWorkingDirectory ( );
2067 string objectsMacro = GetObjectsMacro ( module );
2068 string linkDepsMacro = GetLinkingDependenciesMacro ();
2069 string libsMacro = GetLibsMacro ();
2070
2071 GenerateImportLibraryTargetIfNeeded ();
2072
2073 if ( module.non_if_data.files.size () > 0 )
2074 {
2075 GenerateRules ();
2076
2077 string dependencies = linkDepsMacro + " " + objectsMacro;
2078
2079 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
2080 module.entrypoint.c_str (),
2081 module.baseaddress.c_str () );
2082 GenerateLinkerCommand ( dependencies,
2083 "${gcc}",
2084 linkerParameters,
2085 objectsMacro,
2086 libsMacro );
2087 }
2088 else
2089 {
2090 GeneratePhonyTarget();
2091 }
2092 }
2093
2094
2095 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
2096 const Module& module_ )
2097
2098 : MingwModuleHandler ( module_ )
2099 {
2100 }
2101
2102 void
2103 MingwKernelModeDriverModuleHandler::Process ()
2104 {
2105 GenerateKernelModeDriverModuleTarget ();
2106 }
2107
2108
2109 void
2110 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
2111 {
2112 string targetMacro ( GetTargetMacro (module) );
2113 string workingDirectory = GetWorkingDirectory ();
2114 string objectsMacro = GetObjectsMacro ( module );
2115 string linkDepsMacro = GetLinkingDependenciesMacro ();
2116 string libsMacro = GetLibsMacro ();
2117
2118 GenerateImportLibraryTargetIfNeeded ();
2119
2120 if ( module.non_if_data.files.size () > 0 )
2121 {
2122 GenerateRules ();
2123
2124 string dependencies = linkDepsMacro + " " + objectsMacro;
2125
2126 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
2127 module.entrypoint.c_str (),
2128 module.baseaddress.c_str () );
2129 GenerateLinkerCommand ( dependencies,
2130 "${gcc}",
2131 linkerParameters,
2132 objectsMacro,
2133 libsMacro );
2134 }
2135 else
2136 {
2137 GeneratePhonyTarget();
2138 }
2139 }
2140
2141
2142 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
2143 const Module& module_ )
2144
2145 : MingwModuleHandler ( module_ )
2146 {
2147 }
2148
2149 void
2150 MingwNativeDLLModuleHandler::Process ()
2151 {
2152 GenerateNativeDLLModuleTarget ();
2153 }
2154
2155 void
2156 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
2157 {
2158 string targetMacro ( GetTargetMacro (module) );
2159 string workingDirectory = GetWorkingDirectory ( );
2160 string objectsMacro = GetObjectsMacro ( module );
2161 string linkDepsMacro = GetLinkingDependenciesMacro ();
2162 string libsMacro = GetLibsMacro ();
2163
2164 GenerateImportLibraryTargetIfNeeded ();
2165
2166 if ( module.non_if_data.files.size () > 0 )
2167 {
2168 GenerateRules ();
2169
2170 string dependencies = linkDepsMacro + " " + objectsMacro;
2171
2172 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
2173 module.entrypoint.c_str (),
2174 module.baseaddress.c_str () );
2175 GenerateLinkerCommand ( dependencies,
2176 "${gcc}",
2177 linkerParameters,
2178 objectsMacro,
2179 libsMacro );
2180 }
2181 else
2182 {
2183 GeneratePhonyTarget();
2184 }
2185 }
2186
2187
2188 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
2189 const Module& module_ )
2190
2191 : MingwModuleHandler ( module_ )
2192 {
2193 }
2194
2195 void
2196 MingwNativeCUIModuleHandler::Process ()
2197 {
2198 GenerateNativeCUIModuleTarget ();
2199 }
2200
2201 void
2202 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
2203 {
2204 string targetMacro ( GetTargetMacro (module) );
2205 string workingDirectory = GetWorkingDirectory ( );
2206 string objectsMacro = GetObjectsMacro ( module );
2207 string linkDepsMacro = GetLinkingDependenciesMacro ();
2208 string libsMacro = GetLibsMacro ();
2209
2210 GenerateImportLibraryTargetIfNeeded ();
2211
2212 if ( module.non_if_data.files.size () > 0 )
2213 {
2214 GenerateRules ();
2215
2216 string dependencies = linkDepsMacro + " " + objectsMacro;
2217
2218 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
2219 module.entrypoint.c_str (),
2220 module.baseaddress.c_str () );
2221 GenerateLinkerCommand ( dependencies,
2222 "${gcc}",
2223 linkerParameters,
2224 objectsMacro,
2225 libsMacro );
2226 }
2227 else
2228 {
2229 GeneratePhonyTarget();
2230 }
2231 }
2232
2233
2234 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
2235 const Module& module_ )
2236
2237 : MingwModuleHandler ( module_ )
2238 {
2239 }
2240
2241 void
2242 MingwWin32DLLModuleHandler::Process ()
2243 {
2244 GenerateExtractWineDLLResourcesTarget ();
2245 GenerateWin32DLLModuleTarget ();
2246 }
2247
2248 void
2249 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ()
2250 {
2251 fprintf ( fMakefile, ".PHONY: %s_extractresources\n\n",
2252 module.name.c_str () );
2253 fprintf ( fMakefile, "%s_extractresources: $(BIN2RES_TARGET)\n",
2254 module.name.c_str () );
2255 const vector<File*>& files = module.non_if_data.files;
2256 for ( size_t i = 0; i < files.size (); i++ )
2257 {
2258 File& file = *files[i];
2259 string extension = GetExtension ( file.name );
2260 if ( extension == ".rc" || extension == ".RC" )
2261 {
2262 string resource = NormalizeFilename ( file.name );
2263 fprintf ( fMakefile, "\t$(ECHO_BIN2RES)\n" );
2264 fprintf ( fMakefile, "\t@:echo ${bin2res} -f -x %s\n",
2265 resource.c_str () );
2266 }
2267 }
2268 fprintf ( fMakefile, "\n");
2269 }
2270
2271 void
2272 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
2273 {
2274 string targetMacro ( GetTargetMacro (module) );
2275 string workingDirectory = GetWorkingDirectory ( );
2276 string objectsMacro = GetObjectsMacro ( module );
2277 string linkDepsMacro = GetLinkingDependenciesMacro ();
2278 string libsMacro = GetLibsMacro ();
2279
2280 GenerateImportLibraryTargetIfNeeded ();
2281
2282 if ( module.non_if_data.files.size () > 0 )
2283 {
2284 GenerateRules ();
2285
2286 string dependencies = linkDepsMacro + " " + objectsMacro;
2287
2288 string linker;
2289 if ( module.cplusplus )
2290 linker = "${gpp}";
2291 else
2292 linker = "${gcc}";
2293
2294 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
2295 module.entrypoint.c_str (),
2296 module.baseaddress.c_str () );
2297 GenerateLinkerCommand ( dependencies,
2298 linker,
2299 linkerParameters,
2300 objectsMacro,
2301 libsMacro );
2302 }
2303 else
2304 {
2305 GeneratePhonyTarget();
2306 }
2307 }
2308
2309
2310 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
2311 const Module& module_ )
2312
2313 : MingwModuleHandler ( module_ )
2314 {
2315 }
2316
2317 void
2318 MingwWin32CUIModuleHandler::Process ()
2319 {
2320 GenerateWin32CUIModuleTarget ();
2321 }
2322
2323 void
2324 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
2325 {
2326 string targetMacro ( GetTargetMacro (module) );
2327 string workingDirectory = GetWorkingDirectory ( );
2328 string objectsMacro = GetObjectsMacro ( module );
2329 string linkDepsMacro = GetLinkingDependenciesMacro ();
2330 string libsMacro = GetLibsMacro ();
2331
2332 GenerateImportLibraryTargetIfNeeded ();
2333
2334 if ( module.non_if_data.files.size () > 0 )
2335 {
2336 GenerateRules ();
2337
2338 string dependencies = linkDepsMacro + " " + objectsMacro;
2339
2340 string linker;
2341 if ( module.cplusplus )
2342 linker = "${gpp}";
2343 else
2344 linker = "${gcc}";
2345
2346 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2347 module.entrypoint.c_str (),
2348 module.baseaddress.c_str () );
2349 GenerateLinkerCommand ( dependencies,
2350 linker,
2351 linkerParameters,
2352 objectsMacro,
2353 libsMacro );
2354 }
2355 else
2356 {
2357 GeneratePhonyTarget();
2358 }
2359 }
2360
2361
2362 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
2363 const Module& module_ )
2364
2365 : MingwModuleHandler ( module_ )
2366 {
2367 }
2368
2369 void
2370 MingwWin32GUIModuleHandler::Process ()
2371 {
2372 GenerateWin32GUIModuleTarget ();
2373 }
2374
2375 void
2376 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
2377 {
2378 string targetMacro ( GetTargetMacro (module) );
2379 string workingDirectory = GetWorkingDirectory ( );
2380 string objectsMacro = GetObjectsMacro ( module );
2381 string linkDepsMacro = GetLinkingDependenciesMacro ();
2382 string libsMacro = GetLibsMacro ();
2383
2384 GenerateImportLibraryTargetIfNeeded ();
2385
2386 if ( module.non_if_data.files.size () > 0 )
2387 {
2388 GenerateRules ();
2389
2390 string dependencies = linkDepsMacro + " " + objectsMacro;
2391
2392 string linker;
2393 if ( module.cplusplus )
2394 linker = "${gpp}";
2395 else
2396 linker = "${gcc}";
2397
2398 string linkerParameters = ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2399 module.entrypoint.c_str (),
2400 module.baseaddress.c_str () );
2401 GenerateLinkerCommand ( dependencies,
2402 linker,
2403 linkerParameters,
2404 objectsMacro,
2405 libsMacro );
2406 }
2407 else
2408 {
2409 GeneratePhonyTarget();
2410 }
2411 }
2412
2413
2414 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
2415 const Module& module_ )
2416
2417 : MingwModuleHandler ( module_ )
2418 {
2419 }
2420
2421 void
2422 MingwBootLoaderModuleHandler::Process ()
2423 {
2424 GenerateBootLoaderModuleTarget ();
2425 }
2426
2427 void
2428 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
2429 {
2430 string targetName ( module.GetTargetName () );
2431 string targetMacro ( GetTargetMacro (module) );
2432 string workingDirectory = GetWorkingDirectory ();
2433 string junk_tmp = ros_temp + module.name + ".junk.tmp";
2434 CLEAN_FILE ( junk_tmp );
2435 string objectsMacro = GetObjectsMacro ( module );
2436 string linkDepsMacro = GetLinkingDependenciesMacro ();
2437 string libsMacro = GetLibsMacro ();
2438
2439 GenerateRules ();
2440
2441 fprintf ( fMakefile, "%s: %s %s | %s\n",
2442 targetMacro.c_str (),
2443 objectsMacro.c_str (),
2444 linkDepsMacro.c_str (),
2445 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
2446
2447 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
2448
2449 fprintf ( fMakefile,
2450 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
2451 GetLinkerMacro ().c_str (),
2452 junk_tmp.c_str (),
2453 objectsMacro.c_str (),
2454 linkDepsMacro.c_str () );
2455 fprintf ( fMakefile,
2456 "\t${objcopy} -O binary %s $@\n",
2457 junk_tmp.c_str () );
2458 fprintf ( fMakefile,
2459 "\t-@${rm} %s 2>$(NUL)\n",
2460 junk_tmp.c_str () );
2461 }
2462
2463
2464 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
2465 const Module& module_ )
2466
2467 : MingwModuleHandler ( module_ )
2468 {
2469 }
2470
2471 void
2472 MingwBootSectorModuleHandler::Process ()
2473 {
2474 GenerateBootSectorModuleTarget ();
2475 }
2476
2477 void
2478 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
2479 {
2480 string objectsMacro = GetObjectsMacro ( module );
2481
2482 GenerateRules ();
2483
2484 fprintf ( fMakefile, ".PHONY: %s\n\n",
2485 module.name.c_str ());
2486 fprintf ( fMakefile,
2487 "%s: %s\n",
2488 module.name.c_str (),
2489 objectsMacro.c_str () );
2490 }
2491
2492
2493 MingwIsoModuleHandler::MingwIsoModuleHandler (
2494 const Module& module_ )
2495
2496 : MingwModuleHandler ( module_ )
2497 {
2498 }
2499
2500 void
2501 MingwIsoModuleHandler::Process ()
2502 {
2503 GenerateIsoModuleTarget ();
2504 }
2505
2506 void
2507 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
2508 const string& bootcdDirectory )
2509 {
2510 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2511 {
2512 const Module& m = *module.project.modules[i];
2513 if ( m.bootstrap != NULL )
2514 {
2515 string sourceFilename = PassThruCacheDirectory (
2516 NormalizeFilename ( m.GetPath () ),
2517 backend->outputDirectory );
2518 string targetFilenameNoFixup ( bootcdDirectory + SSEP + m.bootstrap->base + SSEP + m.bootstrap->nameoncd );
2519 string targetFilename = MingwModuleHandler::PassThruCacheDirectory (
2520 NormalizeFilename ( targetFilenameNoFixup ),
2521 backend->outputDirectory );
2522 fprintf ( fMakefile,
2523 "\t$(ECHO_CP)\n" );
2524 fprintf ( fMakefile,
2525 "\t${cp} %s %s 1>$(NUL)\n",
2526 sourceFilename.c_str (),
2527 targetFilename.c_str () );
2528 }
2529 }
2530 }
2531
2532 void
2533 MingwIsoModuleHandler::OutputCdfileCopyCommands (
2534 const string& bootcdDirectory )
2535 {
2536 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2537 {
2538 const CDFile& cdfile = *module.project.cdfiles[i];
2539 string targetFilenameNoFixup = bootcdDirectory + SSEP + cdfile.base + SSEP + cdfile.nameoncd;
2540 string targetFilename = MingwModuleHandler::PassThruCacheDirectory (
2541 NormalizeFilename ( targetFilenameNoFixup ),
2542 backend->outputDirectory );
2543 fprintf ( fMakefile,
2544 "\t$(ECHO_CP)\n" );
2545 fprintf ( fMakefile,
2546 "\t${cp} %s %s 1>$(NUL)\n",
2547 cdfile.GetPath ().c_str (),
2548 targetFilename.c_str () );
2549 }
2550 }
2551
2552 string
2553 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string& bootcdDirectory )
2554 {
2555 string directories;
2556 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2557 {
2558 const Module& m = *module.project.modules[i];
2559 if ( m.bootstrap != NULL )
2560 {
2561 string targetDirectory ( bootcdDirectory + SSEP + m.bootstrap->base );
2562 if ( directories.size () > 0 )
2563 directories += " ";
2564 directories += PassThruCacheDirectory (
2565 NormalizeFilename ( targetDirectory ),
2566 backend->outputDirectory );
2567 }
2568 }
2569 return directories;
2570 }
2571
2572 string
2573 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string& bootcdDirectory )
2574 {
2575 string directories;
2576 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2577 {
2578 const CDFile& cdfile = *module.project.cdfiles[i];
2579 string targetDirectory ( bootcdDirectory + SSEP + cdfile.base );
2580 if ( directories.size () > 0 )
2581 directories += " ";
2582 directories += PassThruCacheDirectory (
2583 NormalizeFilename ( targetDirectory ),
2584 backend->outputDirectory );
2585 }
2586 return directories;
2587 }
2588
2589 string
2590 MingwIsoModuleHandler::GetCdDirectories ( const string& bootcdDirectory )
2591 {
2592 string directories = GetBootstrapCdDirectories ( bootcdDirectory );
2593 directories += " " + GetNonModuleCdDirectories ( bootcdDirectory );
2594 return directories;
2595 }
2596
2597 void
2598 MingwIsoModuleHandler::GetBootstrapCdFiles (
2599 vector<string>& out ) const
2600 {
2601 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2602 {
2603 const Module& m = *module.project.modules[i];
2604 if ( m.bootstrap != NULL )
2605 {
2606 string filename = PassThruCacheDirectory (
2607 NormalizeFilename ( m.GetPath () ),
2608 backend->outputDirectory );
2609 out.push_back ( filename );
2610 }
2611 }
2612 }
2613
2614 void
2615 MingwIsoModuleHandler::GetNonModuleCdFiles (
2616 vector<string>& out ) const
2617 {
2618 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2619 {
2620 const CDFile& cdfile = *module.project.cdfiles[i];
2621 out.push_back ( cdfile.GetPath () );
2622 }
2623 }
2624
2625 void
2626 MingwIsoModuleHandler::GetCdFiles (
2627 vector<string>& out ) const
2628 {
2629 GetBootstrapCdFiles ( out );
2630 GetNonModuleCdFiles ( out );
2631 }
2632
2633 void
2634 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
2635 {
2636 string bootcdDirectory = "cd";
2637 string bootcd = PassThruCacheDirectory (
2638 NormalizeFilename ( bootcdDirectory + SSEP ),
2639 backend->outputDirectory );
2640 string isoboot = PassThruCacheDirectory (
2641 NormalizeFilename ( "boot" SSEP "freeldr" SSEP "bootsect" SSEP "isoboot.o" ),
2642 backend->outputDirectory );
2643 string bootcdReactosNoFixup = bootcdDirectory + SSEP "reactos";
2644 string bootcdReactos = PassThruCacheDirectory (
2645 NormalizeFilename ( bootcdReactosNoFixup + SSEP ),
2646 backend->outputDirectory );
2647 CLEAN_FILE ( bootcdReactos );
2648 string reactosInf = PassThruCacheDirectory (
2649 NormalizeFilename ( bootcdReactosNoFixup + SSEP "reactos.inf" ),
2650 backend->outputDirectory );
2651 string reactosDff = NormalizeFilename ( "bootdata" SSEP "packages" SSEP "reactos.dff" );
2652 string cdDirectories = GetCdDirectories ( bootcdDirectory );
2653 vector<string> vCdFiles;
2654 GetCdFiles ( vCdFiles );
2655 string cdFiles = v2s ( vCdFiles, 5 );
2656
2657 fprintf ( fMakefile, ".PHONY: %s\n\n",
2658 module.name.c_str ());
2659 fprintf ( fMakefile,
2660 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
2661 module.name.c_str (),
2662 isoboot.c_str (),
2663 bootcdReactos.c_str (),
2664 cdDirectories.c_str (),
2665 cdFiles.c_str () );
2666 fprintf ( fMakefile, "\t$(ECHO_CABMAN)\n" );
2667 fprintf ( fMakefile,
2668 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I -P $(OUTPUT)\n",
2669 reactosDff.c_str (),
2670 bootcdReactos.c_str () );
2671 fprintf ( fMakefile,
2672 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2673 reactosDff.c_str (),
2674 reactosInf.c_str (),
2675 bootcdReactos.c_str ());
2676 fprintf ( fMakefile,
2677 "\t-@${rm} %s 2>$(NUL)\n",
2678 reactosInf.c_str () );
2679 OutputBootstrapfileCopyCommands ( bootcdDirectory );
2680 OutputCdfileCopyCommands ( bootcdDirectory );
2681 fprintf ( fMakefile, "\t$(ECHO_CDMAKE)\n" );
2682 fprintf ( fMakefile,
2683 "\t$(Q)$(CDMAKE_TARGET) -v -m -b %s %s REACTOS ReactOS.iso\n",
2684 isoboot.c_str (),
2685 bootcd.c_str () );
2686 fprintf ( fMakefile,
2687 "\n" );
2688 }
2689
2690
2691 MingwLiveIsoModuleHandler::MingwLiveIsoModuleHandler (
2692 const Module& module_ )
2693
2694 : MingwModuleHandler ( module_ )
2695 {
2696 }
2697
2698 void
2699 MingwLiveIsoModuleHandler::Process ()
2700 {
2701 GenerateLiveIsoModuleTarget ();
2702 }
2703
2704 void
2705 MingwLiveIsoModuleHandler::CreateDirectory ( const string& directory )
2706 {
2707 string normalizedDirectory = MingwModuleHandler::PassThruCacheDirectory (
2708 NormalizeFilename ( directory ) + SSEP,
2709 backend->outputDirectory );
2710 }
2711
2712 void
2713 MingwLiveIsoModuleHandler::OutputCopyCommand ( const string& sourceFilename,
2714 const string& targetFilename,
2715 const string& targetDirectory )
2716 {
2717 string normalizedTargetFilename = MingwModuleHandler::PassThruCacheDirectory (
2718 NormalizeFilename ( targetDirectory + SSEP + targetFilename ),
2719 backend->outputDirectory );
2720 fprintf ( fMakefile,
2721 "\t$(ECHO_CP)\n" );
2722 fprintf ( fMakefile,
2723 "\t${cp} %s %s 1>$(NUL)\n",
2724 sourceFilename.c_str (),
2725 normalizedTargetFilename.c_str () );
2726 }
2727
2728 void
2729 MingwLiveIsoModuleHandler::OutputModuleCopyCommands ( string& livecdDirectory,
2730 string& reactosDirectory )
2731 {
2732 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2733 {
2734 const Module& m = *module.project.modules[i];
2735 if ( m.installName.length () > 0 )
2736 {
2737 string sourceFilename = MingwModuleHandler::PassThruCacheDirectory (
2738 NormalizeFilename ( m.GetPath () ),
2739 backend->outputDirectory );
2740 OutputCopyCommand ( sourceFilename,
2741 m.installName,
2742 livecdDirectory + SSEP + reactosDirectory + SSEP + m.installBase );
2743 }
2744 }
2745 }
2746
2747 void
2748 MingwLiveIsoModuleHandler::OutputNonModuleCopyCommands ( string& livecdDirectory,
2749 string& reactosDirectory )
2750 {
2751 for ( size_t i = 0; i < module.project.installfiles.size (); i++ )
2752 {
2753 const InstallFile& installfile = *module.project.installfiles[i];
2754 OutputCopyCommand ( installfile.GetPath (),
2755 installfile.newname,
2756 livecdDirectory + SSEP + reactosDirectory + SSEP + installfile.base );
2757 }
2758 }
2759
2760 void
2761 MingwLiveIsoModuleHandler::OutputProfilesDirectoryCommands ( string& livecdDirectory )
2762 {
2763 CreateDirectory ( livecdDirectory + SSEP "Profiles" );
2764 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "All Users") ;
2765 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "All Users" SSEP "Desktop" );
2766 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "Default User" );
2767 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "Default User" SSEP "Desktop" );
2768 CreateDirectory ( livecdDirectory + SSEP "Profiles" SSEP "Default User" SSEP "My Documents" );
2769
2770 string livecdIni = "bootdata" SSEP "livecd.ini";
2771 OutputCopyCommand ( livecdIni,
2772 "freeldr.ini",
2773 livecdDirectory );
2774 }
2775
2776 void
2777 MingwLiveIsoModuleHandler::OutputLoaderCommands ( string& livecdDirectory )
2778 {
2779 string freeldr = PassThruCacheDirectory (
2780 NormalizeFilename ( "boot" SSEP "freeldr" SSEP "freeldr" SSEP "freeldr.sys" ),
2781 backend->outputDirectory );
2782 CreateDirectory ( livecdDirectory + SSEP "loader" );
2783 OutputCopyCommand ( freeldr,
2784 "setupldr.sys",
2785 livecdDirectory + SSEP + "loader" );
2786 }
2787
2788 void
2789 MingwLiveIsoModuleHandler::OutputRegistryCommands ( string& livecdDirectory )
2790 {
2791 string reactosSystem32ConfigDirectory = NormalizeFilename (
2792 MingwModuleHandler::PassThruCacheDirectory (
2793 livecdDirectory + SSEP "reactos" SSEP "system32" SSEP "config" SSEP,
2794 backend->outputDirectory ) );
2795 fprintf ( fMakefile,
2796 "\t$(ECHO_MKHIVE)\n" );
2797 fprintf ( fMakefile,
2798 "\t$(MKHIVE_TARGET) bootdata %s bootdata" SSEP "livecd.inf bootdata" SSEP "hiveinst.inf\n",
2799 reactosSystem32ConfigDirectory.c_str () );
2800 }
2801
2802 void
2803 MingwLiveIsoModuleHandler::GenerateLiveIsoModuleTarget ()
2804 {
2805 string livecdDirectory = "livecd";
2806 string livecd = PassThruCacheDirectory (
2807 NormalizeFilename ( livecdDirectory + SSEP ),
2808 backend->outputDirectory );
2809 string isoboot = PassThruCacheDirectory (
2810 NormalizeFilename ( "boot" SSEP "freeldr" SSEP "bootsect" SSEP "isoboot.o" ),
2811 backend->outputDirectory );
2812 string reactosDirectory = "reactos";
2813 string livecdReactosNoFixup = livecdDirectory + SSEP + reactosDirectory;
2814 string livecdReactos = NormalizeFilename ( PassThruCacheDirectory (
2815 NormalizeFilename ( livecdReactosNoFixup + SSEP ),
2816 backend->outputDirectory ) );
2817 CLEAN_FILE ( livecdReactos );
2818
2819 fprintf ( fMakefile, ".PHONY: %s\n\n",
2820 module.name.c_str ());
2821 fprintf ( fMakefile,
2822 "%s: all %s %s $(MKHIVE_TARGET) $(CDMAKE_TARGET)\n",
2823 module.name.c_str (),
2824 isoboot.c_str (),
2825 livecdReactos.c_str () );
2826 OutputModuleCopyCommands ( livecdDirectory,
2827 reactosDirectory );
2828 OutputNonModuleCopyCommands ( livecdDirectory,
2829 reactosDirectory );
2830 OutputProfilesDirectoryCommands ( livecdDirectory );
2831 OutputLoaderCommands ( livecdDirectory );
2832 OutputRegistryCommands ( livecdDirectory );
2833 fprintf ( fMakefile, "\t$(ECHO_CDMAKE)\n" );
2834 fprintf ( fMakefile,
2835 "\t$(Q)$(CDMAKE_TARGET) -v -m -j -b %s %s REACTOS ReactOS-LiveCD.iso\n",
2836 isoboot.c_str (),
2837 livecd.c_str () );
2838 fprintf ( fMakefile,
2839 "\n" );
2840 }
2841
2842
2843 MingwTestModuleHandler::MingwTestModuleHandler (
2844 const Module& module_ )
2845
2846 : MingwModuleHandler ( module_ )
2847 {
2848 }
2849
2850 void
2851 MingwTestModuleHandler::Process ()
2852 {
2853 GenerateTestModuleTarget ();
2854 }
2855
2856 void
2857 MingwTestModuleHandler::GenerateTestModuleTarget ()
2858 {
2859 string targetMacro ( GetTargetMacro ( module ) );
2860 string workingDirectory = GetWorkingDirectory ( );
2861 string objectsMacro = GetObjectsMacro ( module );
2862 string linkDepsMacro = GetLinkingDependenciesMacro ();
2863 string libsMacro = GetLibsMacro ();
2864
2865 GenerateImportLibraryTargetIfNeeded ();
2866
2867 if ( module.non_if_data.files.size () > 0 )
2868 {
2869 GenerateRules ();
2870
2871 string dependencies = linkDepsMacro + " " + objectsMacro;
2872
2873 string linker;
2874 if ( module.cplusplus )
2875 linker = "${gpp}";
2876 else
2877 linker = "${gcc}";
2878
2879 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2880 module.entrypoint.c_str (),
2881 module.baseaddress.c_str () );
2882 GenerateLinkerCommand ( dependencies,
2883 linker,
2884 linkerParameters,
2885 objectsMacro,
2886 libsMacro );
2887 }
2888 else
2889 {
2890 GeneratePhonyTarget();
2891 }
2892 }
2893
2894
2895 MingwRpcServerModuleHandler::MingwRpcServerModuleHandler (
2896 const Module& module_ )
2897
2898 : MingwModuleHandler ( module_ )
2899 {
2900 }
2901
2902 void
2903 MingwRpcServerModuleHandler::Process ()
2904 {
2905 GenerateRules ();
2906 }
2907
2908 MingwRpcClientModuleHandler::MingwRpcClientModuleHandler (
2909 const Module& module_ )
2910
2911 : MingwModuleHandler ( module_ )
2912 {
2913 }
2914
2915 void
2916 MingwRpcClientModuleHandler::Process ()
2917 {
2918 GenerateRules ();
2919 }