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