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