eliminate rmkdir and generate directory dependencies the right way.
[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 ); /*if ( module.name == "crt" ) printf ( "%s(%i): clean: %s\n", __FILE__, __LINE__, f.c_str() )*/
12
13 static string ros_temp = "$(ROS_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 v2s ( const string_list& v, int wrap_at )
45 {
46 if ( !v.size() )
47 return "";
48 string s;
49 int wrap_count = 0;
50 for ( size_t i = 0; i < v.size(); i++ )
51 {
52 if ( !v[i].size() )
53 continue;
54 if ( wrap_at > 0 && wrap_count++ == wrap_at )
55 s += " \\\n\t\t";
56 else if ( s.size() )
57 s += " ";
58 s += v[i];
59 }
60 return s;
61 }
62
63 string
64 GetTargetMacro ( const Module& module, bool with_dollar )
65 {
66 string s ( module.name );
67 strupr ( &s[0] );
68 s += "_TARGET";
69 if ( with_dollar )
70 return ssprintf ( "$(%s)", s.c_str() );
71 return s;
72 }
73
74 MingwModuleHandler::MingwModuleHandler (
75 const Module& module_ )
76
77 : module(module_)
78 {
79 }
80
81 MingwModuleHandler::~MingwModuleHandler()
82 {
83 }
84
85 /*static*/ void
86 MingwModuleHandler::SetBackend ( MingwBackend* backend_ )
87 {
88 backend = backend_;
89 }
90
91 /*static*/ void
92 MingwModuleHandler::SetMakefile ( FILE* f )
93 {
94 fMakefile = f;
95 }
96
97 /*static*/ void
98 MingwModuleHandler::SetUsePch ( bool b )
99 {
100 use_pch = b;
101 }
102
103 /*static*/ string
104 MingwModuleHandler::PassThruCacheDirectory (
105 const string &file, bool out )
106 {
107 string dir ( GetDirectory ( file ) );
108 return backend->AddDirectoryTarget ( dir, out ) + SSEP + file;
109 }
110
111 /*static*/ string
112 MingwModuleHandler::GetTargetFilename (
113 const Module& module,
114 string_list* pclean_files )
115 {
116 string target = PassThruCacheDirectory (
117 FixupTargetFilename ( module.GetPath () ),
118 true );
119 if ( pclean_files )
120 {
121 string_list& clean_files = *pclean_files;
122 CLEAN_FILE ( target );
123 }
124 return target;
125 }
126
127 /*static*/ string
128 MingwModuleHandler::GetImportLibraryFilename (
129 const Module& module,
130 string_list* pclean_files )
131 {
132 string target = PassThruCacheDirectory (
133 FixupTargetFilename ( module.GetDependencyPath () ),
134 true );
135 if ( pclean_files )
136 {
137 string_list& clean_files = *pclean_files;
138 CLEAN_FILE ( target );
139 }
140 return target;
141 }
142
143 /*static*/ MingwModuleHandler*
144 MingwModuleHandler::InstanciateHandler (
145 const Module& module,
146 MingwBackend* backend )
147 {
148 MingwModuleHandler* handler;
149 switch ( module.type )
150 {
151 case BuildTool:
152 handler = new MingwBuildToolModuleHandler ( module );
153 break;
154 case StaticLibrary:
155 handler = new MingwStaticLibraryModuleHandler ( module );
156 break;
157 case ObjectLibrary:
158 handler = new MingwObjectLibraryModuleHandler ( module );
159 break;
160 case Kernel:
161 handler = new MingwKernelModuleHandler ( module );
162 break;
163 case NativeCUI:
164 handler = new MingwNativeCUIModuleHandler ( module );
165 break;
166 case Win32CUI:
167 handler = new MingwWin32CUIModuleHandler ( module );
168 break;
169 case Win32GUI:
170 handler = new MingwWin32GUIModuleHandler ( module );
171 break;
172 case KernelModeDLL:
173 handler = new MingwKernelModeDLLModuleHandler ( module );
174 break;
175 case NativeDLL:
176 handler = new MingwNativeDLLModuleHandler ( module );
177 break;
178 case Win32DLL:
179 handler = new MingwWin32DLLModuleHandler ( module );
180 break;
181 case KernelModeDriver:
182 handler = new MingwKernelModeDriverModuleHandler ( module );
183 break;
184 case BootLoader:
185 handler = new MingwBootLoaderModuleHandler ( module );
186 break;
187 case BootSector:
188 handler = new MingwBootSectorModuleHandler ( module );
189 break;
190 case Iso:
191 handler = new MingwIsoModuleHandler ( module );
192 break;
193 case Test:
194 handler = new MingwTestModuleHandler ( module );
195 break;
196 default:
197 throw UnknownModuleTypeException (
198 module.node.location,
199 module.type );
200 break;
201 }
202 return handler;
203 }
204
205 string
206 MingwModuleHandler::GetWorkingDirectory () const
207 {
208 return ".";
209 }
210
211 string
212 MingwModuleHandler::GetBasename ( const string& filename ) const
213 {
214 size_t index = filename.find_last_of ( '.' );
215 if ( index != string::npos )
216 return filename.substr ( 0, index );
217 return "";
218 }
219
220 string
221 MingwModuleHandler::GetActualSourceFilename (
222 const string& filename ) const
223 {
224 string extension = GetExtension ( filename );
225 if ( extension == ".spec" || extension == "SPEC" )
226 {
227 string basename = GetBasename ( filename );
228 return basename + ".stubs.c";
229 }
230 else
231 return filename;
232 }
233
234 string
235 MingwModuleHandler::GetModuleArchiveFilename () const
236 {
237 if ( module.type == StaticLibrary )
238 return GetTargetFilename(module,NULL);
239 return PassThruCacheDirectory ( ReplaceExtension (
240 FixupTargetFilename ( module.GetPath () ),
241 ".temp.a" ), false );
242 }
243
244 bool
245 MingwModuleHandler::IsGeneratedFile ( const File& file ) const
246 {
247 string extension = GetExtension ( file.name );
248 return ( extension == ".spec" || extension == "SPEC" );
249 }
250
251 string
252 MingwModuleHandler::GetImportLibraryDependency (
253 const Module& importedModule )
254 {
255 string dep;
256 if ( importedModule.type == ObjectLibrary )
257 dep = GetTargetMacro ( importedModule );
258 else
259 dep = GetImportLibraryFilename ( importedModule, NULL );
260 return dep;
261 }
262
263 void
264 MingwModuleHandler::GetModuleDependencies (
265 string_list& dependencies )
266 {
267 size_t iend = module.dependencies.size ();
268
269 // TODO FIXME - do we *really* not want to call
270 // GetDefinitionDependencies() if dependencies.size() == 0 ???
271 if ( iend == 0 )
272 return;
273
274 for ( size_t i = 0; i < iend; i++ )
275 {
276 const Dependency& dependency = *module.dependencies[i];
277 const Module& dependencyModule = *dependency.dependencyModule;
278 dependencyModule.GetTargets ( dependencies );
279 }
280 GetDefinitionDependencies ( dependencies );
281 }
282
283 void
284 MingwModuleHandler::GetSourceFilenames (
285 string_list& list,
286 bool includeGeneratedFiles ) const
287 {
288 size_t i;
289
290 const vector<File*>& files = module.non_if_data.files;
291 for ( i = 0; i < files.size (); i++ )
292 {
293 if ( includeGeneratedFiles || !IsGeneratedFile ( *files[i] ) )
294 {
295 list.push_back (
296 GetActualSourceFilename ( files[i]->name ) );
297 }
298 }
299 // intentionally make a copy so that we can append more work in
300 // the middle of processing without having to go recursive
301 vector<If*> v = module.non_if_data.ifs;
302 for ( i = 0; i < v.size (); i++ )
303 {
304 size_t j;
305 If& rIf = *v[i];
306 // check for sub-ifs to add to list
307 const vector<If*>& ifs = rIf.data.ifs;
308 for ( j = 0; j < ifs.size (); j++ )
309 v.push_back ( ifs[j] );
310 const vector<File*>& files = rIf.data.files;
311 for ( j = 0; j < files.size (); j++ )
312 {
313 File& file = *files[j];
314 if ( includeGeneratedFiles || !IsGeneratedFile ( file ) )
315 {
316 list.push_back (
317 GetActualSourceFilename ( file.name ) );
318 }
319 }
320 }
321 }
322
323 void
324 MingwModuleHandler::GetSourceFilenamesWithoutGeneratedFiles (
325 string_list& list ) const
326 {
327 GetSourceFilenames ( list, false );
328 }
329
330 string
331 MingwModuleHandler::GetObjectFilename (
332 const string& sourceFilename,
333 string_list* pclean_files ) const
334 {
335 string newExtension;
336 string extension = GetExtension ( sourceFilename );
337 if ( extension == ".rc" || extension == ".RC" )
338 newExtension = ".coff";
339 else if ( extension == ".spec" || extension == ".SPEC" )
340 newExtension = ".stubs.o";
341 else
342 newExtension = ".o";
343 string obj_file = PassThruCacheDirectory (
344 FixupTargetFilename (
345 ReplaceExtension (
346 sourceFilename, //PrefixFilename(sourceFilename,module.prefix),
347 newExtension ) ),
348 false );
349 if ( pclean_files )
350 {
351 string_list& clean_files = *pclean_files;
352 CLEAN_FILE ( obj_file );
353 }
354 return obj_file;
355 }
356
357 void
358 MingwModuleHandler::GenerateCleanTarget () const
359 {
360 if ( 0 == clean_files.size() )
361 return;
362 fprintf ( fMakefile, ".PHONY: %s_clean\n", module.name.c_str() );
363 fprintf ( fMakefile, "%s_clean:\n\t-@$(rm)", module.name.c_str() );
364 for ( size_t i = 0; i < clean_files.size(); i++ )
365 {
366 if ( 9==((i+1)%10) )
367 fprintf ( fMakefile, " 2>$(NUL)\n\t-@$(rm)" );
368 fprintf ( fMakefile, " %s", clean_files[i].c_str() );
369 }
370 fprintf ( fMakefile, " 2>$(NUL)\n" );
371 fprintf ( fMakefile, "clean: %s_clean\n\n", module.name.c_str() );
372 }
373
374 string
375 MingwModuleHandler::GetObjectFilenames ()
376 {
377 const vector<File*>& files = module.non_if_data.files;
378 if ( files.size () == 0 )
379 return "";
380
381 string objectFilenames ( "" );
382 for ( size_t i = 0; i < files.size (); i++ )
383 {
384 if ( objectFilenames.size () > 0 )
385 objectFilenames += " ";
386 objectFilenames +=
387 GetObjectFilename ( files[i]->name, NULL );
388 }
389 return objectFilenames;
390 }
391
392 string
393 MingwModuleHandler::GenerateGccDefineParametersFromVector (
394 const vector<Define*>& defines ) const
395 {
396 string parameters;
397 for ( size_t i = 0; i < defines.size (); i++ )
398 {
399 Define& define = *defines[i];
400 if (parameters.length () > 0)
401 parameters += " ";
402 parameters += "-D";
403 parameters += define.name;
404 if (define.value.length () > 0)
405 {
406 parameters += "=";
407 parameters += define.value;
408 }
409 }
410 return parameters;
411 }
412
413 string
414 MingwModuleHandler::GenerateGccDefineParameters () const
415 {
416 string parameters = GenerateGccDefineParametersFromVector ( module.project.non_if_data.defines );
417 string s = GenerateGccDefineParametersFromVector ( module.non_if_data.defines );
418 if ( s.length () > 0 )
419 {
420 parameters += " ";
421 parameters += s;
422 }
423 return parameters;
424 }
425
426 string
427 MingwModuleHandler::ConcatenatePaths (
428 const string& path1,
429 const string& path2 ) const
430 {
431 if ( ( path1.length () == 0 ) || ( path1 == "." ) || ( path1 == "./" ) )
432 return path2;
433 if ( path1[path1.length ()] == CSEP )
434 return path1 + path2;
435 else
436 return path1 + CSEP + path2;
437 }
438
439 string
440 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector<Include*>& includes ) const
441 {
442 string parameters;
443 for ( size_t i = 0; i < includes.size (); i++ )
444 {
445 Include& include = *includes[i];
446 if ( parameters.length () > 0 )
447 parameters += " ";
448 parameters += "-I" + include.directory;
449 }
450 return parameters;
451 }
452
453 string
454 MingwModuleHandler::GenerateGccIncludeParameters () const
455 {
456 string parameters = GenerateGccIncludeParametersFromVector ( module.non_if_data.includes );
457 string s = GenerateGccIncludeParametersFromVector ( module.project.non_if_data.includes );
458 if ( s.length () > 0 )
459 {
460 parameters += " ";
461 parameters += s;
462 }
463 return parameters;
464 }
465
466
467 string
468 MingwModuleHandler::GenerateCompilerParametersFromVector ( const vector<CompilerFlag*>& compilerFlags ) const
469 {
470 string parameters;
471 for ( size_t i = 0; i < compilerFlags.size (); i++ )
472 {
473 CompilerFlag& compilerFlag = *compilerFlags[i];
474 if ( parameters.length () > 0 )
475 parameters += " ";
476 parameters += compilerFlag.flag;
477 }
478 return parameters;
479 }
480
481 string
482 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector<LinkerFlag*>& linkerFlags ) const
483 {
484 string parameters;
485 for ( size_t i = 0; i < linkerFlags.size (); i++ )
486 {
487 LinkerFlag& linkerFlag = *linkerFlags[i];
488 if ( parameters.length () > 0 )
489 parameters += " ";
490 parameters += linkerFlag.flag;
491 }
492 return parameters;
493 }
494
495 string
496 MingwModuleHandler::GenerateImportLibraryDependenciesFromVector (
497 const vector<Library*>& libraries )
498 {
499 string dependencies ( "" );
500 int wrap_count = 0;
501 for ( size_t i = 0; i < libraries.size (); i++ )
502 {
503 if ( wrap_count++ == 5 )
504 dependencies += " \\\n\t\t", wrap_count = 0;
505 else if ( dependencies.size () > 0 )
506 dependencies += " ";
507 dependencies += GetImportLibraryDependency ( *libraries[i]->imported_module );
508 }
509 return dependencies;
510 }
511
512 string
513 MingwModuleHandler::GenerateLinkerParameters () const
514 {
515 return GenerateLinkerParametersFromVector ( module.linkerFlags );
516 }
517
518 void
519 MingwModuleHandler::GenerateMacro (
520 const char* assignmentOperation,
521 const string& macro,
522 const IfableData& data,
523 const vector<CompilerFlag*>* compilerFlags )
524 {
525 size_t i;
526
527 fprintf (
528 fMakefile,
529 "%s %s",
530 macro.c_str(),
531 assignmentOperation );
532
533 if ( compilerFlags != NULL )
534 {
535 string compilerParameters = GenerateCompilerParametersFromVector ( *compilerFlags );
536 if ( compilerParameters.size () > 0 )
537 {
538 fprintf (
539 fMakefile,
540 " %s",
541 compilerParameters.c_str () );
542 }
543 }
544
545 for ( i = 0; i < data.includes.size(); i++ )
546 {
547 fprintf (
548 fMakefile,
549 " -I%s",
550 data.includes[i]->directory.c_str() );
551 }
552 for ( i = 0; i < data.defines.size(); i++ )
553 {
554 Define& d = *data.defines[i];
555 fprintf (
556 fMakefile,
557 " -D%s",
558 d.name.c_str() );
559 if ( d.value.size() )
560 fprintf (
561 fMakefile,
562 "=%s",
563 d.value.c_str() );
564 }
565 fprintf ( fMakefile, "\n" );
566 }
567
568 void
569 MingwModuleHandler::GenerateMacros (
570 const char* assignmentOperation,
571 const IfableData& data,
572 const vector<CompilerFlag*>* compilerFlags,
573 const vector<LinkerFlag*>* linkerFlags )
574 {
575 size_t i;
576
577 if ( data.includes.size () > 0 || data.defines.size () > 0 )
578 {
579 GenerateMacro ( assignmentOperation,
580 cflagsMacro,
581 data,
582 compilerFlags );
583 GenerateMacro ( assignmentOperation,
584 windresflagsMacro,
585 data,
586 compilerFlags );
587 }
588
589 if ( linkerFlags != NULL )
590 {
591 string linkerParameters = GenerateLinkerParametersFromVector ( *linkerFlags );
592 if ( linkerParameters.size () > 0 )
593 {
594 fprintf (
595 fMakefile,
596 "%s %s %s\n",
597 linkerflagsMacro.c_str (),
598 assignmentOperation,
599 linkerParameters.c_str() );
600 }
601 }
602
603 if ( data.libraries.size () > 0 )
604 {
605 string deps = GenerateImportLibraryDependenciesFromVector ( data.libraries );
606 if ( deps.size () > 0 )
607 {
608 fprintf (
609 fMakefile,
610 "%s %s %s\n",
611 libsMacro.c_str(),
612 assignmentOperation,
613 deps.c_str() );
614 }
615 }
616
617 const vector<File*>& files = data.files;
618 if ( files.size () > 0 )
619 {
620 for ( i = 0; i < files.size (); i++ )
621 {
622 File& file = *files[i];
623 if ( file.first )
624 {
625 fprintf ( fMakefile,
626 "%s := %s $(%s)\n",
627 objectsMacro.c_str(),
628 GetObjectFilename (
629 file.name, NULL ).c_str (),
630 objectsMacro.c_str() );
631 }
632 }
633 fprintf (
634 fMakefile,
635 "%s %s",
636 objectsMacro.c_str (),
637 assignmentOperation );
638 for ( i = 0; i < files.size(); i++ )
639 {
640 File& file = *files[i];
641 if ( !file.first )
642 {
643 fprintf (
644 fMakefile,
645 "%s%s",
646 ( i%10 == 9 ? " \\\n\t" : " " ),
647 GetObjectFilename (
648 file.name, NULL ).c_str () );
649 }
650 }
651 fprintf ( fMakefile, "\n" );
652 }
653
654 const vector<If*>& ifs = data.ifs;
655 for ( i = 0; i < ifs.size(); i++ )
656 {
657 If& rIf = *ifs[i];
658 if ( rIf.data.defines.size()
659 || rIf.data.includes.size()
660 || rIf.data.libraries.size()
661 || rIf.data.files.size()
662 || rIf.data.ifs.size() )
663 {
664 fprintf (
665 fMakefile,
666 "ifeq (\"$(%s)\",\"%s\")\n",
667 rIf.property.c_str(),
668 rIf.value.c_str() );
669 GenerateMacros (
670 "+=",
671 rIf.data,
672 NULL,
673 NULL );
674 fprintf (
675 fMakefile,
676 "endif\n\n" );
677 }
678 }
679 }
680
681 void
682 MingwModuleHandler::GenerateGccCommand (
683 const string& sourceFilename,
684 const string& cc,
685 const string& cflagsMacro )
686 {
687 string deps = sourceFilename;
688 if ( module.pch && use_pch )
689 deps += " " + module.pch->header + ".gch";
690 string objectFilename = GetObjectFilename (
691 sourceFilename, NULL );
692 fprintf ( fMakefile,
693 "%s: %s %s\n",
694 objectFilename.c_str (),
695 deps.c_str (),
696 GetDirectory ( objectFilename ).c_str () );
697 fprintf ( fMakefile, "\t$(ECHO_CC)\n" );
698 fprintf ( fMakefile,
699 "\t%s -c $< -o $@ %s\n",
700 cc.c_str (),
701 cflagsMacro.c_str () );
702 }
703
704 void
705 MingwModuleHandler::GenerateGccAssemblerCommand (
706 const string& sourceFilename,
707 const string& cc,
708 const string& cflagsMacro )
709 {
710 string objectFilename = GetObjectFilename (
711 sourceFilename, &clean_files );
712 fprintf ( fMakefile,
713 "%s: %s %s\n",
714 objectFilename.c_str (),
715 sourceFilename.c_str (),
716 GetDirectory ( objectFilename ).c_str () );
717 fprintf ( fMakefile, "\t$(ECHO_GAS)\n" );
718 fprintf ( fMakefile,
719 "\t%s -x assembler-with-cpp -c $< -o $@ -D__ASM__ %s\n",
720 cc.c_str (),
721 cflagsMacro.c_str () );
722 }
723
724 void
725 MingwModuleHandler::GenerateNasmCommand (
726 const string& sourceFilename,
727 const string& nasmflagsMacro )
728 {
729 string objectFilename = GetObjectFilename (
730 sourceFilename, &clean_files );
731 fprintf ( fMakefile,
732 "%s: %s %s\n",
733 objectFilename.c_str (),
734 sourceFilename.c_str (),
735 GetDirectory ( objectFilename ).c_str () );
736 fprintf ( fMakefile, "\t$(ECHO_NASM)\n" );
737 fprintf ( fMakefile,
738 "\t%s -f win32 $< -o $@ %s\n",
739 "$(Q)nasm",
740 nasmflagsMacro.c_str () );
741 }
742
743 void
744 MingwModuleHandler::GenerateWindresCommand (
745 const string& sourceFilename,
746 const string& windresflagsMacro )
747 {
748 string objectFilename =
749 GetObjectFilename ( sourceFilename, &clean_files );
750 string rciFilename = ros_temp +
751 ReplaceExtension ( sourceFilename, ".rci" );
752 string resFilename = ros_temp +
753 ReplaceExtension ( sourceFilename, ".res" );
754 fprintf ( fMakefile,
755 "%s: %s %s $(WRC_TARGET)\n",
756 objectFilename.c_str (),
757 sourceFilename.c_str (),
758 GetDirectory ( objectFilename ).c_str () );
759 fprintf ( fMakefile, "\t$(ECHO_WRC)\n" );
760 fprintf ( fMakefile,
761 "\t${gcc} -xc -E -DRC_INVOKED ${%s} %s > %s\n",
762 windresflagsMacro.c_str (),
763 sourceFilename.c_str (),
764 rciFilename.c_str () );
765 fprintf ( fMakefile,
766 "\t$(Q)$(WRC_TARGET) ${%s} %s %s\n",
767 windresflagsMacro.c_str (),
768 rciFilename.c_str (),
769 resFilename.c_str () );
770 fprintf ( fMakefile,
771 "\t-@${rm} %s 2>$(NUL)\n",
772 rciFilename.c_str () );
773 fprintf ( fMakefile,
774 "\t${windres} %s -o $@\n",
775 resFilename.c_str () );
776 fprintf ( fMakefile,
777 "\t-@${rm} %s 2>$(NUL)\n",
778 resFilename.c_str () );
779 }
780
781 void
782 MingwModuleHandler::GenerateWinebuildCommands (
783 const string& sourceFilename )
784 {
785 string basename = GetBasename ( sourceFilename );
786
787 string def_file = PassThruCacheDirectory (
788 basename + ".spec.def",
789 false );
790 CLEAN_FILE(def_file);
791
792 string stub_file = PassThruCacheDirectory (
793 basename + ".stubs.c",
794 false );
795 CLEAN_FILE(stub_file)
796
797 fprintf ( fMakefile,
798 "%s: %s $(WINEBUILD_TARGET)\n",
799 def_file.c_str (),
800 sourceFilename.c_str () );
801 fprintf ( fMakefile, "\t$(ECHO_WINEBLD)\n" );
802 fprintf ( fMakefile,
803 "\t%s --def=%s -o %s\n",
804 "$(Q)$(WINEBUILD_TARGET)",
805 sourceFilename.c_str (),
806 def_file.c_str () );
807
808 fprintf ( fMakefile,
809 "%s: %s\n",
810 stub_file.c_str (),
811 sourceFilename.c_str () );
812 fprintf ( fMakefile, "\t$(ECHO_WINEBLD)\n" );
813 fprintf ( fMakefile,
814 "\t%s --pedll=%s -o %s\n",
815 "$(Q)$(WINEBUILD_TARGET)",
816 sourceFilename.c_str (),
817 stub_file.c_str () );
818 }
819
820 void
821 MingwModuleHandler::GenerateCommands (
822 const string& sourceFilename,
823 const string& cc,
824 const string& cppc,
825 const string& cflagsMacro,
826 const string& nasmflagsMacro,
827 const string& windresflagsMacro )
828 {
829 string extension = GetExtension ( sourceFilename );
830 if ( extension == ".c" || extension == ".C" )
831 {
832 GenerateGccCommand ( sourceFilename,
833 cc,
834 cflagsMacro );
835 return;
836 }
837 else if ( extension == ".cc" || extension == ".CC" ||
838 extension == ".cpp" || extension == ".CPP" ||
839 extension == ".cxx" || extension == ".CXX" )
840 {
841 GenerateGccCommand ( sourceFilename,
842 cppc,
843 cflagsMacro );
844 return;
845 }
846 else if ( extension == ".s" || extension == ".S" )
847 {
848 GenerateGccAssemblerCommand ( sourceFilename,
849 cc,
850 cflagsMacro );
851 return;
852 }
853 else if ( extension == ".asm" || extension == ".ASM" )
854 {
855 GenerateNasmCommand ( sourceFilename,
856 nasmflagsMacro );
857 return;
858 }
859 else if ( extension == ".rc" || extension == ".RC" )
860 {
861 GenerateWindresCommand ( sourceFilename,
862 windresflagsMacro );
863 return;
864 }
865 else if ( extension == ".spec" || extension == ".SPEC" )
866 {
867 GenerateWinebuildCommands ( sourceFilename );
868 GenerateGccCommand ( GetActualSourceFilename ( sourceFilename ),
869 cc,
870 cflagsMacro );
871 return;
872 }
873
874 throw InvalidOperationException ( __FILE__,
875 __LINE__,
876 "Unsupported filename extension '%s' in file '%s'",
877 extension.c_str (),
878 sourceFilename.c_str () );
879 }
880
881 void
882 MingwModuleHandler::GenerateLinkerCommand (
883 const string& dependencies,
884 const string& linker,
885 const string& linkerParameters,
886 const string& objectsMacro,
887 const string& libsMacro )
888 {
889 string target ( GetTargetMacro ( module ) );
890 string target_folder ( GetDirectory(GetTargetFilename(module,NULL)) );
891
892 fprintf ( fMakefile,
893 "%s: %s %s $(RSYM_TARGET)\n",
894 target.c_str (),
895 dependencies.c_str (),
896 target_folder.c_str () );
897 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
898 string targetName ( module.GetTargetName () );
899 if ( module.importLibrary != NULL )
900 {
901 string base_tmp = ros_temp + module.name + ".base.tmp";
902 CLEAN_FILE ( base_tmp );
903 string junk_tmp = ros_temp + module.name + ".junk.tmp";
904 CLEAN_FILE ( junk_tmp );
905 string temp_exp = ros_temp + module.name + ".temp.exp";
906 CLEAN_FILE ( temp_exp );
907 string def_file = module.GetBasePath () + SSEP + module.importLibrary->definition;
908
909 fprintf ( fMakefile,
910 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
911 linker.c_str (),
912 linkerParameters.c_str (),
913 base_tmp.c_str (),
914 junk_tmp.c_str (),
915 objectsMacro.c_str (),
916 libsMacro.c_str (),
917 GetLinkerMacro ().c_str () );
918
919 fprintf ( fMakefile,
920 "\t-@${rm} %s 2>$(NUL)\n",
921 junk_tmp.c_str () );
922
923 string killAt = module.mangledSymbols ? "" : "--kill-at";
924 fprintf ( fMakefile,
925 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s %s\n",
926 targetName.c_str (),
927 base_tmp.c_str (),
928 def_file.c_str (),
929 temp_exp.c_str (),
930 killAt.c_str () );
931
932 fprintf ( fMakefile,
933 "\t-@${rm} %s 2>$(NUL)\n",
934 base_tmp.c_str () );
935
936 fprintf ( fMakefile,
937 "\t%s %s %s -o %s %s %s %s\n",
938 linker.c_str (),
939 linkerParameters.c_str (),
940 temp_exp.c_str (),
941 target.c_str (),
942 objectsMacro.c_str (),
943 libsMacro.c_str (),
944 GetLinkerMacro ().c_str () );
945
946 fprintf ( fMakefile,
947 "\t-@${rm} %s 2>$(NUL)\n",
948 temp_exp.c_str () );
949 }
950 else
951 {
952 fprintf ( fMakefile,
953 "\t%s %s -o %s %s %s %s\n",
954 linker.c_str (),
955 linkerParameters.c_str (),
956 target.c_str (),
957 objectsMacro.c_str (),
958 libsMacro.c_str (),
959 GetLinkerMacro ().c_str () );
960 }
961
962 fprintf ( fMakefile, "\t$(ECHO_RSYM)\n" );
963 fprintf ( fMakefile,
964 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
965 }
966
967 void
968 MingwModuleHandler::GeneratePhonyTarget() const
969 {
970 string targetMacro ( GetTargetMacro(module) );
971 fprintf ( fMakefile, ".PHONY: %s\n\n",
972 targetMacro.c_str ());
973 fprintf ( fMakefile, "%s: %s\n",
974 targetMacro.c_str (),
975 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
976 }
977
978 void
979 MingwModuleHandler::GenerateObjectFileTargets (
980 const IfableData& data,
981 const string& cc,
982 const string& cppc,
983 const string& cflagsMacro,
984 const string& nasmflagsMacro,
985 const string& windresflagsMacro )
986 {
987 size_t i;
988
989 const vector<File*>& files = data.files;
990 for ( i = 0; i < files.size (); i++ )
991 {
992 string sourceFilename = files[i]->name;
993 GenerateCommands ( sourceFilename,
994 cc,
995 cppc,
996 cflagsMacro,
997 nasmflagsMacro,
998 windresflagsMacro );
999 fprintf ( fMakefile,
1000 "\n" );
1001 }
1002
1003 const vector<If*>& ifs = data.ifs;
1004 for ( i = 0; i < ifs.size(); i++ )
1005 {
1006 GenerateObjectFileTargets ( ifs[i]->data,
1007 cc,
1008 cppc,
1009 cflagsMacro,
1010 nasmflagsMacro,
1011 windresflagsMacro );
1012 }
1013 }
1014
1015 void
1016 MingwModuleHandler::GenerateObjectFileTargets (
1017 const string& cc,
1018 const string& cppc,
1019 const string& cflagsMacro,
1020 const string& nasmflagsMacro,
1021 const string& windresflagsMacro )
1022 {
1023 if ( module.pch )
1024 {
1025 const string& pch_file = module.pch->header;
1026 string gch_file = pch_file + ".gch";
1027 CLEAN_FILE(gch_file);
1028 if ( use_pch )
1029 {
1030 fprintf (
1031 fMakefile,
1032 "%s: %s\n",
1033 gch_file.c_str(),
1034 pch_file.c_str() );
1035 fprintf ( fMakefile, "\t$(ECHO_PCH)\n" );
1036 fprintf (
1037 fMakefile,
1038 "\t%s -o %s %s -g %s\n\n",
1039 ( module.cplusplus ? cppc.c_str() : cc.c_str() ),
1040 gch_file.c_str(),
1041 cflagsMacro.c_str(),
1042 pch_file.c_str() );
1043 }
1044 }
1045
1046 GenerateObjectFileTargets ( module.non_if_data,
1047 cc,
1048 cppc,
1049 cflagsMacro,
1050 nasmflagsMacro,
1051 windresflagsMacro );
1052 fprintf ( fMakefile, "\n" );
1053 }
1054
1055 string
1056 MingwModuleHandler::GenerateArchiveTarget ( const string& ar,
1057 const string& objs_macro ) const
1058 {
1059 string archiveFilename ( GetModuleArchiveFilename () );
1060
1061 fprintf ( fMakefile,
1062 "%s: %s %s\n",
1063 archiveFilename.c_str (),
1064 objs_macro.c_str (),
1065 GetDirectory(archiveFilename).c_str() );
1066
1067 fprintf ( fMakefile, "\t$(ECHO_AR)\n" );
1068
1069 fprintf ( fMakefile,
1070 "\t%s -rc $@ %s\n\n",
1071 ar.c_str (),
1072 objs_macro.c_str ());
1073
1074 return archiveFilename;
1075 }
1076
1077 string
1078 MingwModuleHandler::GetCFlagsMacro () const
1079 {
1080 return ssprintf ( "$(%s_CFLAGS)",
1081 module.name.c_str () );
1082 }
1083
1084 /*static*/ string
1085 MingwModuleHandler::GetObjectsMacro ( const Module& module )
1086 {
1087 return ssprintf ( "$(%s_OBJS)",
1088 module.name.c_str () );
1089 }
1090
1091 string
1092 MingwModuleHandler::GetLinkingDependenciesMacro () const
1093 {
1094 return ssprintf ( "$(%s_LINKDEPS)", module.name.c_str () );
1095 }
1096
1097 string
1098 MingwModuleHandler::GetLibsMacro () const
1099 {
1100 return ssprintf ( "$(%s_LIBS)", module.name.c_str () );
1101 }
1102
1103 string
1104 MingwModuleHandler::GetLinkerMacro () const
1105 {
1106 return ssprintf ( "$(%s_LFLAGS)",
1107 module.name.c_str () );
1108 }
1109
1110 void
1111 MingwModuleHandler::GenerateTargetMacro ()
1112 {
1113 fprintf ( fMakefile,
1114 "%s := %s\n",
1115 GetTargetMacro(module,false).c_str (),
1116 GetTargetFilename(module,NULL).c_str () );
1117 }
1118
1119 void
1120 MingwModuleHandler::GenerateOtherMacros ()
1121 {
1122 cflagsMacro = ssprintf ("%s_CFLAGS", module.name.c_str ());
1123 nasmflagsMacro = ssprintf ("%s_NASMFLAGS", module.name.c_str ());
1124 windresflagsMacro = ssprintf ("%s_RCFLAGS", module.name.c_str ());
1125 linkerflagsMacro = ssprintf ("%s_LFLAGS", module.name.c_str ());
1126 objectsMacro = ssprintf ("%s_OBJS", module.name.c_str ());
1127 libsMacro = ssprintf("%s_LIBS", module.name.c_str ());
1128 linkDepsMacro = ssprintf ("%s_LINKDEPS", module.name.c_str ());
1129
1130 GenerateMacros (
1131 "=",
1132 module.non_if_data,
1133 &module.compilerFlags,
1134 &module.linkerFlags );
1135
1136 if ( module.importLibrary )
1137 {
1138 string_list s;
1139 const vector<File*>& files = module.non_if_data.files;
1140 for ( size_t i = 0; i < files.size (); i++ )
1141 {
1142 File& file = *files[i];
1143 string extension = GetExtension ( file.name );
1144 if ( extension == ".spec" || extension == ".SPEC" )
1145 GetSpecObjectDependencies ( s, file.name );
1146 }
1147 if ( s.size () > 0 )
1148 {
1149 fprintf (
1150 fMakefile,
1151 "%s +=",
1152 linkDepsMacro.c_str() );
1153 for ( size_t i = 0; i < s.size(); i++ )
1154 fprintf ( fMakefile,
1155 " %s",
1156 s[i].c_str () );
1157 fprintf ( fMakefile, "\n" );
1158 }
1159 }
1160
1161 fprintf (
1162 fMakefile,
1163 "%s += $(PROJECT_CFLAGS)\n",
1164 cflagsMacro.c_str () );
1165
1166 fprintf (
1167 fMakefile,
1168 "%s += $(PROJECT_RCFLAGS)\n",
1169 windresflagsMacro.c_str () );
1170
1171 fprintf (
1172 fMakefile,
1173 "%s_LFLAGS += $(PROJECT_LFLAGS)\n",
1174 module.name.c_str () );
1175
1176 fprintf (
1177 fMakefile,
1178 "%s += $(%s)",
1179 linkDepsMacro.c_str (),
1180 libsMacro.c_str () );
1181
1182 string cflags = TypeSpecificCFlags();
1183 if ( cflags.size() > 0 )
1184 {
1185 fprintf ( fMakefile,
1186 "%s += %s\n\n",
1187 cflagsMacro.c_str (),
1188 cflags.c_str () );
1189 }
1190
1191 string nasmflags = TypeSpecificNasmFlags();
1192 if ( nasmflags.size () > 0 )
1193 {
1194 fprintf ( fMakefile,
1195 "%s += %s\n\n",
1196 nasmflagsMacro.c_str (),
1197 nasmflags.c_str () );
1198 }
1199
1200 fprintf ( fMakefile, "\n\n" );
1201
1202 // future references to the macros will be to get their values
1203 cflagsMacro = ssprintf ("$(%s)", cflagsMacro.c_str ());
1204 nasmflagsMacro = ssprintf ("$(%s)", nasmflagsMacro.c_str ());
1205 objectsMacro = ssprintf ("$(%s)", objectsMacro.c_str ());
1206 }
1207
1208 void
1209 MingwModuleHandler::GenerateRules ()
1210 {
1211 string cc = ( module.host == HostTrue ? "${host_gcc}" : "${gcc}" );
1212 string cppc = ( module.host == HostTrue ? "${host_gpp}" : "${gpp}" );
1213 string ar = ( module.host == HostTrue ? "${host_ar}" : "${ar}" );
1214
1215 string targetMacro = GetTargetMacro ( module );
1216
1217 CLEAN_FILE ( targetMacro );
1218
1219 // generate phony target for module name
1220 fprintf ( fMakefile, ".PHONY: %s\n",
1221 module.name.c_str () );
1222 fprintf ( fMakefile, "%s: %s\n\n",
1223 module.name.c_str (),
1224 GetTargetMacro ( module ).c_str () );
1225
1226 if ( module.type != ObjectLibrary )
1227 {
1228 string ar_target =
1229 GenerateArchiveTarget ( ar, objectsMacro );
1230
1231 GenerateObjectFileTargets ( cc,
1232 cppc,
1233 cflagsMacro,
1234 nasmflagsMacro,
1235 windresflagsMacro );
1236
1237 if ( targetMacro != ar_target )
1238 {
1239 CLEAN_FILE ( ar_target );
1240 }
1241 }
1242 }
1243
1244 void
1245 MingwModuleHandler::GetInvocationDependencies (
1246 const Module& module,
1247 string_list& dependencies )
1248 {
1249 for ( size_t i = 0; i < module.invocations.size (); i++ )
1250 {
1251 Invoke& invoke = *module.invocations[i];
1252 if ( invoke.invokeModule == &module )
1253 /* Protect against circular dependencies */
1254 continue;
1255 invoke.GetTargets ( dependencies );
1256 }
1257 }
1258
1259 void
1260 MingwModuleHandler::GenerateInvocations () const
1261 {
1262 if ( module.invocations.size () == 0 )
1263 return;
1264
1265 size_t iend = module.invocations.size ();
1266 for ( size_t i = 0; i < iend; i++ )
1267 {
1268 const Invoke& invoke = *module.invocations[i];
1269
1270 if ( invoke.invokeModule->type != BuildTool )
1271 {
1272 throw InvalidBuildFileException ( module.node.location,
1273 "Only modules of type buildtool can be invoked." );
1274 }
1275
1276 string invokeTarget = module.GetInvocationTarget ( i );
1277 string_list invoke_targets;
1278 assert ( invoke_targets.size() );
1279 invoke.GetTargets ( invoke_targets );
1280 fprintf ( fMakefile,
1281 ".PHONY: %s\n\n",
1282 invokeTarget.c_str () );
1283 fprintf ( fMakefile,
1284 "%s:",
1285 invokeTarget.c_str () );
1286 size_t j, jend = invoke_targets.size();
1287 for ( j = 0; j < jend; j++ )
1288 {
1289 fprintf ( fMakefile,
1290 " %s",
1291 invoke_targets[i].c_str () );
1292 }
1293 fprintf ( fMakefile, "\n\n%s", invoke_targets[0].c_str () );
1294 for ( j = 1; j < jend; j++ )
1295 fprintf ( fMakefile,
1296 " %s",
1297 invoke_targets[i].c_str () );
1298 fprintf ( fMakefile,
1299 ": %s\n",
1300 FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str () );
1301 fprintf ( fMakefile, "\t$(ECHO_INVOKE)\n" );
1302 fprintf ( fMakefile,
1303 "\t%s %s\n\n",
1304 FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str (),
1305 invoke.GetParameters ().c_str () );
1306 }
1307 }
1308
1309 string
1310 MingwModuleHandler::GetPreconditionDependenciesName () const
1311 {
1312 return module.name + "_precondition";
1313 }
1314
1315 void
1316 MingwModuleHandler::GetDefaultDependencies (
1317 string_list& dependencies ) const
1318 {
1319 /* Avoid circular dependency */
1320 if ( module.type != BuildTool
1321 && module.name != "zlib"
1322 && module.name != "hostzlib" )
1323
1324 dependencies.push_back ( "$(INIT)" );
1325 }
1326
1327 void
1328 MingwModuleHandler::GeneratePreconditionDependencies ()
1329 {
1330 string preconditionDependenciesName = GetPreconditionDependenciesName ();
1331 string_list sourceFilenames;
1332 GetSourceFilenamesWithoutGeneratedFiles ( sourceFilenames );
1333 string_list dependencies;
1334 GetDefaultDependencies ( dependencies );
1335 GetModuleDependencies ( dependencies );
1336
1337 GetInvocationDependencies ( module, dependencies );
1338
1339 if ( dependencies.size() )
1340 {
1341 fprintf ( fMakefile,
1342 "%s =",
1343 preconditionDependenciesName.c_str () );
1344 for ( size_t i = 0; i < dependencies.size(); i++ )
1345 fprintf ( fMakefile,
1346 " %s",
1347 dependencies[i].c_str () );
1348 fprintf ( fMakefile, "\n\n" );
1349 }
1350
1351 for ( size_t i = 0; i < sourceFilenames.size(); i++ )
1352 {
1353 fprintf ( fMakefile,
1354 "%s: ${%s}\n",
1355 sourceFilenames[i].c_str(),
1356 preconditionDependenciesName.c_str ());
1357 }
1358 fprintf ( fMakefile, "\n" );
1359 }
1360
1361 void
1362 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ()
1363 {
1364 if ( module.importLibrary != NULL )
1365 {
1366 string library_target (
1367 GetImportLibraryFilename ( module, &clean_files ) );
1368
1369 string_list deps;
1370 GetDefinitionDependencies ( deps );
1371
1372 fprintf ( fMakefile, "# IMPORT LIBRARY RULE:\n" );
1373
1374 fprintf ( fMakefile, "%s:",
1375 library_target.c_str () );
1376
1377 size_t i, iend = deps.size();
1378 for ( i = 0; i < iend; i++ )
1379 fprintf ( fMakefile, " %s",
1380 deps[i].c_str () );
1381
1382 fprintf ( fMakefile, " %s\n",
1383 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
1384
1385 fprintf ( fMakefile, "\t$(ECHO_DLLTOOL)\n" );
1386
1387 string killAt = module.mangledSymbols ? "" : "--kill-at";
1388 fprintf ( fMakefile,
1389 "\t${dlltool} --dllname %s --def %s --output-lib %s %s\n\n",
1390 module.GetTargetName ().c_str (),
1391 ( module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),
1392 library_target.c_str (),
1393 killAt.c_str () );
1394 }
1395 }
1396
1397 void
1398 MingwModuleHandler::GetSpecObjectDependencies (
1399 string_list& dependencies,
1400 const string& filename ) const
1401 {
1402 string basename = GetBasename ( filename );
1403 dependencies.push_back ( basename + ".spec.def" );
1404 dependencies.push_back ( basename + ".stubs.c" );
1405 }
1406
1407 void
1408 MingwModuleHandler::GetDefinitionDependencies (
1409 string_list& dependencies ) const
1410 {
1411 string dkNkmLibNoFixup = "dk/nkm/lib";
1412 // TODO FIXME - verify this is the correct dependency...
1413 // easiest way to tell is to remove it and see what breaks
1414 /*dependencies += PassThruCacheDirectory (
1415 FixupTargetFilename ( dkNkmLibNoFixup ),
1416 false, NULL );*/
1417 const vector<File*>& files = module.non_if_data.files;
1418 for ( size_t i = 0; i < files.size (); i++ )
1419 {
1420 File& file = *files[i];
1421 string extension = GetExtension ( file.name );
1422 if ( extension == ".spec" || extension == ".SPEC" )
1423 {
1424 GetSpecObjectDependencies ( dependencies, file.name );
1425 }
1426 }
1427 }
1428
1429 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler ( const Module& module_ )
1430 : MingwModuleHandler ( module_ )
1431 {
1432 }
1433
1434 void
1435 MingwBuildToolModuleHandler::Process ()
1436 {
1437 GenerateBuildToolModuleTarget ();
1438 }
1439
1440 void
1441 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ()
1442 {
1443 string targetMacro ( GetTargetMacro (module) );
1444 string objectsMacro = GetObjectsMacro ( module );
1445 string linkDepsMacro = GetLinkingDependenciesMacro ();
1446 string libsMacro = GetLibsMacro ();
1447
1448 GenerateRules ();
1449
1450 string linker;
1451 if ( module.cplusplus )
1452 linker = "${host_gpp}";
1453 else
1454 linker = "${host_gcc}";
1455
1456 fprintf ( fMakefile, "%s: %s %s %s\n",
1457 targetMacro.c_str (),
1458 objectsMacro.c_str (),
1459 linkDepsMacro.c_str (),
1460 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
1461 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
1462 fprintf ( fMakefile,
1463 "\t%s %s -o $@ %s %s\n\n",
1464 linker.c_str (),
1465 GetLinkerMacro ().c_str (),
1466 objectsMacro.c_str (),
1467 libsMacro.c_str () );
1468 }
1469
1470
1471 MingwKernelModuleHandler::MingwKernelModuleHandler (
1472 const Module& module_ )
1473
1474 : MingwModuleHandler ( module_ )
1475 {
1476 }
1477
1478 void
1479 MingwKernelModuleHandler::Process ()
1480 {
1481 GenerateKernelModuleTarget ();
1482 }
1483
1484 void
1485 MingwKernelModuleHandler::GenerateKernelModuleTarget ()
1486 {
1487 string targetName ( module.GetTargetName () ); // i.e. "ntoskrnl.exe"
1488 string targetMacro ( GetTargetMacro (module) ); // i.e. "$(NTOSKRNL_TARGET)"
1489 string workingDirectory = GetWorkingDirectory ();
1490 string objectsMacro = GetObjectsMacro ( module );
1491 string linkDepsMacro = GetLinkingDependenciesMacro ();
1492 string libsMacro = GetLibsMacro ();
1493 string base_tmp = ros_temp + module.name + ".base.tmp";
1494 CLEAN_FILE ( base_tmp );
1495 string junk_tmp = ros_temp + module.name + ".junk.tmp";
1496 CLEAN_FILE ( junk_tmp );
1497 string temp_exp = ros_temp + module.name + ".temp.exp";
1498 CLEAN_FILE ( temp_exp );
1499 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",
1500 module.GetBasePath ().c_str (),
1501 module.entrypoint.c_str (),
1502 module.baseaddress.c_str () );
1503
1504 GenerateRules ();
1505
1506 GenerateImportLibraryTargetIfNeeded ();
1507
1508 fprintf ( fMakefile, "%s: %s %s %s $(RSYM_TARGET)\n",
1509 targetMacro.c_str (),
1510 objectsMacro.c_str (),
1511 linkDepsMacro.c_str (),
1512 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
1513 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
1514 fprintf ( fMakefile,
1515 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1516 GetLinkerMacro ().c_str (),
1517 gccOptions.c_str (),
1518 base_tmp.c_str (),
1519 junk_tmp.c_str (),
1520 objectsMacro.c_str (),
1521 linkDepsMacro.c_str () );
1522 fprintf ( fMakefile,
1523 "\t-@${rm} %s 2>$(NUL)\n",
1524 junk_tmp.c_str () );
1525 string killAt = module.mangledSymbols ? "" : "--kill-at";
1526 fprintf ( fMakefile,
1527 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s %s\n",
1528 targetName.c_str (),
1529 base_tmp.c_str (),
1530 temp_exp.c_str (),
1531 killAt.c_str () );
1532 fprintf ( fMakefile,
1533 "\t-@${rm} %s 2>$(NUL)\n",
1534 base_tmp.c_str () );
1535 fprintf ( fMakefile,
1536 "\t${gcc} %s %s -Wl,%s -o $@ %s %s\n",
1537 GetLinkerMacro ().c_str (),
1538 gccOptions.c_str (),
1539 temp_exp.c_str (),
1540 objectsMacro.c_str (),
1541 linkDepsMacro.c_str () );
1542 fprintf ( fMakefile,
1543 "\t-@${rm} %s 2>$(NUL)\n",
1544 temp_exp.c_str () );
1545 fprintf ( fMakefile, "\t$(ECHO_RSYM)\n" );
1546 fprintf ( fMakefile,
1547 "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" );
1548 }
1549
1550
1551 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler (
1552 const Module& module_ )
1553
1554 : MingwModuleHandler ( module_ )
1555 {
1556 }
1557
1558 void
1559 MingwStaticLibraryModuleHandler::Process ()
1560 {
1561 GenerateStaticLibraryModuleTarget ();
1562 }
1563
1564 void
1565 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ()
1566 {
1567 GenerateRules ();
1568 }
1569
1570
1571 MingwObjectLibraryModuleHandler::MingwObjectLibraryModuleHandler (
1572 const Module& module_ )
1573
1574 : MingwModuleHandler ( module_ )
1575 {
1576 }
1577
1578 void
1579 MingwObjectLibraryModuleHandler::Process ()
1580 {
1581 GenerateObjectLibraryModuleTarget ();
1582 }
1583
1584 void
1585 MingwObjectLibraryModuleHandler::GenerateObjectLibraryModuleTarget ()
1586 {
1587 GenerateRules ();
1588 }
1589
1590
1591 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler (
1592 const Module& module_ )
1593
1594 : MingwModuleHandler ( module_ )
1595 {
1596 }
1597
1598 void
1599 MingwKernelModeDLLModuleHandler::Process ()
1600 {
1601 GenerateKernelModeDLLModuleTarget ();
1602 }
1603
1604 void
1605 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ()
1606 {
1607 string targetMacro ( GetTargetMacro (module) );
1608 string workingDirectory = GetWorkingDirectory ( );
1609 string objectsMacro = GetObjectsMacro ( module );
1610 string linkDepsMacro = GetLinkingDependenciesMacro ();
1611 string libsMacro = GetLibsMacro ();
1612
1613 GenerateImportLibraryTargetIfNeeded ();
1614
1615 if ( module.non_if_data.files.size () > 0 )
1616 {
1617 GenerateRules ();
1618
1619 string dependencies =
1620 objectsMacro + " " + linkDepsMacro;
1621
1622 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1623 module.entrypoint.c_str (),
1624 module.baseaddress.c_str () );
1625 GenerateLinkerCommand ( dependencies,
1626 "${gcc}",
1627 linkerParameters,
1628 objectsMacro,
1629 libsMacro );
1630 }
1631 else
1632 {
1633 GeneratePhonyTarget();
1634 }
1635 }
1636
1637
1638 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler (
1639 const Module& module_ )
1640
1641 : MingwModuleHandler ( module_ )
1642 {
1643 }
1644
1645 void
1646 MingwKernelModeDriverModuleHandler::Process ()
1647 {
1648 GenerateKernelModeDriverModuleTarget ();
1649 }
1650
1651
1652 void
1653 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ()
1654 {
1655 string targetMacro ( GetTargetMacro (module) );
1656 string workingDirectory = GetWorkingDirectory ();
1657 string objectsMacro = GetObjectsMacro ( module );
1658 string linkDepsMacro = GetLinkingDependenciesMacro ();
1659 string libsMacro = GetLibsMacro ();
1660
1661 GenerateImportLibraryTargetIfNeeded ();
1662
1663 if ( module.non_if_data.files.size () > 0 )
1664 {
1665 GenerateRules ();
1666
1667 string dependencies =
1668 objectsMacro + " " + linkDepsMacro;
1669
1670 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1671 module.entrypoint.c_str (),
1672 module.baseaddress.c_str () );
1673 GenerateLinkerCommand ( dependencies,
1674 "${gcc}",
1675 linkerParameters,
1676 objectsMacro,
1677 libsMacro );
1678 }
1679 else
1680 {
1681 GeneratePhonyTarget();
1682 }
1683 }
1684
1685
1686 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler (
1687 const Module& module_ )
1688
1689 : MingwModuleHandler ( module_ )
1690 {
1691 }
1692
1693 void
1694 MingwNativeDLLModuleHandler::Process ()
1695 {
1696 GenerateNativeDLLModuleTarget ();
1697 }
1698
1699 void
1700 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ()
1701 {
1702 string targetMacro ( GetTargetMacro (module) );
1703 string workingDirectory = GetWorkingDirectory ( );
1704 string objectsMacro = GetObjectsMacro ( module );
1705 string linkDepsMacro = GetLinkingDependenciesMacro ();
1706 string libsMacro = GetLibsMacro ();
1707
1708 GenerateImportLibraryTargetIfNeeded ();
1709
1710 if ( module.non_if_data.files.size () > 0 )
1711 {
1712 GenerateRules ();
1713
1714 string dependencies =
1715 objectsMacro + " " + linkDepsMacro;
1716
1717 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll",
1718 module.entrypoint.c_str (),
1719 module.baseaddress.c_str () );
1720 GenerateLinkerCommand ( dependencies,
1721 "${gcc}",
1722 linkerParameters,
1723 objectsMacro,
1724 libsMacro );
1725 }
1726 else
1727 {
1728 GeneratePhonyTarget();
1729 }
1730 }
1731
1732
1733 MingwNativeCUIModuleHandler::MingwNativeCUIModuleHandler (
1734 const Module& module_ )
1735
1736 : MingwModuleHandler ( module_ )
1737 {
1738 }
1739
1740 void
1741 MingwNativeCUIModuleHandler::Process ()
1742 {
1743 GenerateNativeCUIModuleTarget ();
1744 }
1745
1746 void
1747 MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget ()
1748 {
1749 string targetMacro ( GetTargetMacro (module) );
1750 string workingDirectory = GetWorkingDirectory ( );
1751 string objectsMacro = GetObjectsMacro ( module );
1752 string linkDepsMacro = GetLinkingDependenciesMacro ();
1753 string libsMacro = GetLibsMacro ();
1754
1755 GenerateImportLibraryTargetIfNeeded ();
1756
1757 if ( module.non_if_data.files.size () > 0 )
1758 {
1759 GenerateRules ();
1760
1761 string dependencies =
1762 objectsMacro + " " + linkDepsMacro;
1763
1764 string linkerParameters = ssprintf ( "-Wl,--subsystem,native -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib",
1765 module.entrypoint.c_str (),
1766 module.baseaddress.c_str () );
1767 GenerateLinkerCommand ( dependencies,
1768 "${gcc}",
1769 linkerParameters,
1770 objectsMacro,
1771 libsMacro );
1772 }
1773 else
1774 {
1775 GeneratePhonyTarget();
1776 }
1777 }
1778
1779
1780 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler (
1781 const Module& module_ )
1782
1783 : MingwModuleHandler ( module_ )
1784 {
1785 }
1786
1787 void
1788 MingwWin32DLLModuleHandler::Process ()
1789 {
1790 GenerateExtractWineDLLResourcesTarget ();
1791 GenerateWin32DLLModuleTarget ();
1792 }
1793
1794 void
1795 MingwWin32DLLModuleHandler::GenerateExtractWineDLLResourcesTarget ()
1796 {
1797 fprintf ( fMakefile, ".PHONY: %s_extractresources\n\n",
1798 module.name.c_str () );
1799 fprintf ( fMakefile, "%s_extractresources: $(BIN2RES_TARGET)\n",
1800 module.name.c_str () );
1801 const vector<File*>& files = module.non_if_data.files;
1802 for ( size_t i = 0; i < files.size (); i++ )
1803 {
1804 File& file = *files[i];
1805 string extension = GetExtension ( file.name );
1806 if ( extension == ".rc" || extension == ".RC" )
1807 {
1808 string resource = FixupTargetFilename ( file.name );
1809 fprintf ( fMakefile, "\t$(ECHO_BIN2RES)\n" );
1810 fprintf ( fMakefile, "\t@:echo ${bin2res} -f -x %s\n",
1811 resource.c_str () );
1812 }
1813 }
1814 fprintf ( fMakefile, "\n");
1815 }
1816
1817 void
1818 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ()
1819 {
1820 string targetMacro ( GetTargetMacro (module) );
1821 string workingDirectory = GetWorkingDirectory ( );
1822 string objectsMacro = GetObjectsMacro ( module );
1823 string linkDepsMacro = GetLinkingDependenciesMacro ();
1824 string libsMacro = GetLibsMacro ();
1825
1826 GenerateImportLibraryTargetIfNeeded ();
1827
1828 if ( module.non_if_data.files.size () > 0 )
1829 {
1830 GenerateRules ();
1831
1832 string dependencies = objectsMacro + " " + linkDepsMacro;
1833
1834 string linker;
1835 if ( module.cplusplus )
1836 linker = "${gpp}";
1837 else
1838 linker = "${gcc}";
1839
1840 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll",
1841 module.entrypoint.c_str (),
1842 module.baseaddress.c_str () );
1843 GenerateLinkerCommand ( dependencies,
1844 linker,
1845 linkerParameters,
1846 objectsMacro,
1847 libsMacro );
1848 }
1849 else
1850 {
1851 GeneratePhonyTarget();
1852 }
1853 }
1854
1855
1856 MingwWin32CUIModuleHandler::MingwWin32CUIModuleHandler (
1857 const Module& module_ )
1858
1859 : MingwModuleHandler ( module_ )
1860 {
1861 }
1862
1863 void
1864 MingwWin32CUIModuleHandler::Process ()
1865 {
1866 GenerateWin32CUIModuleTarget ();
1867 }
1868
1869 void
1870 MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget ()
1871 {
1872 string targetMacro ( GetTargetMacro (module) );
1873 string workingDirectory = GetWorkingDirectory ( );
1874 string objectsMacro = GetObjectsMacro ( module );
1875 string linkDepsMacro = GetLinkingDependenciesMacro ();
1876 string libsMacro = GetLibsMacro ();
1877
1878 GenerateImportLibraryTargetIfNeeded ();
1879
1880 if ( module.non_if_data.files.size () > 0 )
1881 {
1882 GenerateRules ();
1883
1884 string dependencies =
1885 objectsMacro + " " + linkDepsMacro;
1886
1887 string linker;
1888 if ( module.cplusplus )
1889 linker = "${gpp}";
1890 else
1891 linker = "${gcc}";
1892
1893 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1894 module.entrypoint.c_str (),
1895 module.baseaddress.c_str () );
1896 GenerateLinkerCommand ( dependencies,
1897 linker,
1898 linkerParameters,
1899 objectsMacro,
1900 libsMacro );
1901 }
1902 else
1903 {
1904 GeneratePhonyTarget();
1905 }
1906 }
1907
1908
1909 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler (
1910 const Module& module_ )
1911
1912 : MingwModuleHandler ( module_ )
1913 {
1914 }
1915
1916 void
1917 MingwWin32GUIModuleHandler::Process ()
1918 {
1919 GenerateWin32GUIModuleTarget ();
1920 }
1921
1922 void
1923 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ()
1924 {
1925 string targetMacro ( GetTargetMacro (module) );
1926 string workingDirectory = GetWorkingDirectory ( );
1927 string objectsMacro = GetObjectsMacro ( module );
1928 string linkDepsMacro = GetLinkingDependenciesMacro ();
1929 string libsMacro = GetLibsMacro ();
1930
1931 GenerateImportLibraryTargetIfNeeded ();
1932
1933 if ( module.non_if_data.files.size () > 0 )
1934 {
1935 GenerateRules ();
1936
1937 string dependencies =
1938 objectsMacro + " " + linkDepsMacro;
1939
1940 string linker;
1941 if ( module.cplusplus )
1942 linker = "${gpp}";
1943 else
1944 linker = "${gcc}";
1945
1946 string linkerParameters = ssprintf ( "-Wl,--subsystem,windows -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
1947 module.entrypoint.c_str (),
1948 module.baseaddress.c_str () );
1949 GenerateLinkerCommand ( dependencies,
1950 linker,
1951 linkerParameters,
1952 objectsMacro,
1953 libsMacro );
1954 }
1955 else
1956 {
1957 GeneratePhonyTarget();
1958 }
1959 }
1960
1961
1962 MingwBootLoaderModuleHandler::MingwBootLoaderModuleHandler (
1963 const Module& module_ )
1964
1965 : MingwModuleHandler ( module_ )
1966 {
1967 }
1968
1969 void
1970 MingwBootLoaderModuleHandler::Process ()
1971 {
1972 GenerateBootLoaderModuleTarget ();
1973 }
1974
1975 void
1976 MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget ()
1977 {
1978 string targetName ( module.GetTargetName () );
1979 string targetMacro ( GetTargetMacro (module) );
1980 string workingDirectory = GetWorkingDirectory ();
1981 string junk_tmp = ros_temp + module.name + ".junk.tmp";
1982 CLEAN_FILE ( junk_tmp );
1983 string objectsMacro = GetObjectsMacro ( module );
1984 string linkDepsMacro = GetLinkingDependenciesMacro ();
1985 string libsMacro = GetLibsMacro ();
1986
1987 GenerateRules ();
1988
1989 fprintf ( fMakefile, "%s: %s %s %s\n",
1990 targetMacro.c_str (),
1991 objectsMacro.c_str (),
1992 linkDepsMacro.c_str (),
1993 GetDirectory(GetTargetFilename(module,NULL)).c_str () );
1994
1995 fprintf ( fMakefile, "\t$(ECHO_LD)\n" );
1996
1997 fprintf ( fMakefile,
1998 "\t${ld} %s -N -Ttext=0x8000 -o %s %s %s\n",
1999 GetLinkerMacro ().c_str (),
2000 junk_tmp.c_str (),
2001 objectsMacro.c_str (),
2002 linkDepsMacro.c_str () );
2003 fprintf ( fMakefile,
2004 "\t${objcopy} -O binary %s $@\n",
2005 junk_tmp.c_str () );
2006 fprintf ( fMakefile,
2007 "\t-@${rm} %s 2>$(NUL)\n",
2008 junk_tmp.c_str () );
2009 }
2010
2011
2012 MingwBootSectorModuleHandler::MingwBootSectorModuleHandler (
2013 const Module& module_ )
2014
2015 : MingwModuleHandler ( module_ )
2016 {
2017 }
2018
2019 void
2020 MingwBootSectorModuleHandler::Process ()
2021 {
2022 GenerateBootSectorModuleTarget ();
2023 }
2024
2025 void
2026 MingwBootSectorModuleHandler::GenerateBootSectorModuleTarget ()
2027 {
2028 string objectsMacro = GetObjectsMacro ( module );
2029
2030 GenerateRules ();
2031
2032 fprintf ( fMakefile, ".PHONY: %s\n\n",
2033 module.name.c_str ());
2034 fprintf ( fMakefile,
2035 "%s: %s\n",
2036 module.name.c_str (),
2037 objectsMacro.c_str () );
2038 }
2039
2040
2041 MingwIsoModuleHandler::MingwIsoModuleHandler (
2042 const Module& module_ )
2043
2044 : MingwModuleHandler ( module_ )
2045 {
2046 }
2047
2048 void
2049 MingwIsoModuleHandler::Process ()
2050 {
2051 GenerateIsoModuleTarget ();
2052 }
2053
2054 void
2055 MingwIsoModuleHandler::OutputBootstrapfileCopyCommands (
2056 const string& bootcdDirectory )
2057 {
2058 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2059 {
2060 const Module& m = *module.project.modules[i];
2061 if ( m.bootstrap != NULL )
2062 {
2063 string targetFilenameNoFixup ( bootcdDirectory + SSEP + m.bootstrap->base + SSEP + m.bootstrap->nameoncd );
2064 string targetFilename ( GetTargetMacro ( module ) );
2065 fprintf ( fMakefile,
2066 "\t${cp} %s %s\n",
2067 m.GetPath ().c_str (),
2068 targetFilename.c_str () );
2069 }
2070 }
2071 }
2072
2073 void
2074 MingwIsoModuleHandler::OutputCdfileCopyCommands (
2075 const string& bootcdDirectory )
2076 {
2077 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2078 {
2079 const CDFile& cdfile = *module.project.cdfiles[i];
2080 string targetFilenameNoFixup = bootcdDirectory + SSEP + cdfile.base + SSEP + cdfile.nameoncd;
2081 string targetFilename = GetTargetMacro(module);
2082 fprintf ( fMakefile,
2083 "\t${cp} %s %s\n",
2084 cdfile.GetPath ().c_str (),
2085 targetFilename.c_str () );
2086 }
2087 }
2088
2089 string
2090 MingwIsoModuleHandler::GetBootstrapCdDirectories ( const string& bootcdDirectory )
2091 {
2092 string directories;
2093 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2094 {
2095 const Module& m = *module.project.modules[i];
2096 if ( m.bootstrap != NULL )
2097 {
2098 string targetDirectory ( bootcdDirectory + SSEP + m.bootstrap->base );
2099 if ( directories.size () > 0 )
2100 directories += " ";
2101 directories += PassThruCacheDirectory (
2102 FixupTargetFilename ( targetDirectory ),
2103 true );
2104 }
2105 }
2106 return directories;
2107 }
2108
2109 string
2110 MingwIsoModuleHandler::GetNonModuleCdDirectories ( const string& bootcdDirectory )
2111 {
2112 string directories;
2113 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2114 {
2115 const CDFile& cdfile = *module.project.cdfiles[i];
2116 string targetDirectory ( bootcdDirectory + SSEP + cdfile.base );
2117 if ( directories.size () > 0 )
2118 directories += " ";
2119 directories += PassThruCacheDirectory (
2120 FixupTargetFilename ( targetDirectory ),
2121 true );
2122 }
2123 return directories;
2124 }
2125
2126 string
2127 MingwIsoModuleHandler::GetCdDirectories ( const string& bootcdDirectory )
2128 {
2129 string directories = GetBootstrapCdDirectories ( bootcdDirectory );
2130 directories += " " + GetNonModuleCdDirectories ( bootcdDirectory );
2131 return directories;
2132 }
2133
2134 void
2135 MingwIsoModuleHandler::GetBootstrapCdFiles (
2136 vector<string>& out ) const
2137 {
2138 for ( size_t i = 0; i < module.project.modules.size (); i++ )
2139 {
2140 const Module& m = *module.project.modules[i];
2141 if ( m.bootstrap != NULL )
2142 out.push_back ( FixupTargetFilename ( m.GetPath () ) );
2143 }
2144 }
2145
2146 void
2147 MingwIsoModuleHandler::GetNonModuleCdFiles (
2148 vector<string>& out ) const
2149 {
2150 for ( size_t i = 0; i < module.project.cdfiles.size (); i++ )
2151 {
2152 const CDFile& cdfile = *module.project.cdfiles[i];
2153 out.push_back ( NormalizeFilename ( cdfile.GetPath () ) );
2154 }
2155 }
2156
2157 void
2158 MingwIsoModuleHandler::GetCdFiles (
2159 vector<string>& out ) const
2160 {
2161 GetBootstrapCdFiles ( out );
2162 GetNonModuleCdFiles ( out );
2163 }
2164
2165 void
2166 MingwIsoModuleHandler::GenerateIsoModuleTarget ()
2167 {
2168 string bootcdDirectory = "cd";
2169 string isoboot = FixupTargetFilename ( "boot/freeldr/bootsect/isoboot.o" );
2170 string bootcdReactosNoFixup = bootcdDirectory + "/reactos";
2171 string bootcdReactos = PassThruCacheDirectory (
2172 FixupTargetFilename ( bootcdReactosNoFixup ),
2173 true );
2174 CLEAN_FILE ( bootcdReactos );
2175 string reactosInf = ros_temp + FixupTargetFilename ( bootcdReactosNoFixup + "/reactos.inf" );
2176 string reactosDff = NormalizeFilename ( "bootdata/packages/reactos.dff" );
2177 string cdDirectories = GetCdDirectories ( bootcdDirectory );
2178 vector<string> vCdFiles;
2179 GetCdFiles ( vCdFiles );
2180 string cdFiles = v2s ( vCdFiles, 5 );
2181
2182 fprintf ( fMakefile, ".PHONY: %s\n\n",
2183 module.name.c_str ());
2184 fprintf ( fMakefile,
2185 "%s: all %s %s %s %s $(CABMAN_TARGET) $(CDMAKE_TARGET)\n",
2186 module.name.c_str (),
2187 isoboot.c_str (),
2188 bootcdReactos.c_str (),
2189 cdDirectories.c_str (),
2190 cdFiles.c_str () );
2191 fprintf ( fMakefile, "\t$(ECHO_CABMAN)\n" );
2192 fprintf ( fMakefile,
2193 "\t$(Q)$(CABMAN_TARGET) -C %s -L %s -I\n",
2194 reactosDff.c_str (),
2195 bootcdReactos.c_str () );
2196 fprintf ( fMakefile,
2197 "\t$(Q)$(CABMAN_TARGET) -C %s -RC %s -L %s -N -P $(OUTPUT)\n",
2198 reactosDff.c_str (),
2199 reactosInf.c_str (),
2200 bootcdReactos.c_str ());
2201 fprintf ( fMakefile,
2202 "\t-@${rm} %s 2>$(NUL)\n",
2203 reactosInf.c_str () );
2204 OutputBootstrapfileCopyCommands ( bootcdDirectory );
2205 OutputCdfileCopyCommands ( bootcdDirectory );
2206 fprintf ( fMakefile, "\t$(ECHO_CDMAKE)\n" );
2207 fprintf ( fMakefile,
2208 "\t$(Q)$(CDMAKE_TARGET) -v -m -b %s %s REACTOS ReactOS.iso\n",
2209 isoboot.c_str (),
2210 bootcdDirectory.c_str () );
2211 fprintf ( fMakefile,
2212 "\n" );
2213 }
2214
2215
2216 MingwTestModuleHandler::MingwTestModuleHandler (
2217 const Module& module_ )
2218
2219 : MingwModuleHandler ( module_ )
2220 {
2221 }
2222
2223 void
2224 MingwTestModuleHandler::Process ()
2225 {
2226 GenerateTestModuleTarget ();
2227 }
2228
2229 void
2230 MingwTestModuleHandler::GenerateTestModuleTarget ()
2231 {
2232 string targetMacro ( GetTargetMacro (module) );
2233 string workingDirectory = GetWorkingDirectory ( );
2234 string objectsMacro = GetObjectsMacro ( module );
2235 string linkDepsMacro = GetLinkingDependenciesMacro ();
2236 string libsMacro = GetLibsMacro ();
2237
2238 GenerateImportLibraryTargetIfNeeded ();
2239
2240 if ( module.non_if_data.files.size () > 0 )
2241 {
2242 GenerateRules ();
2243
2244 string dependencies = objectsMacro + " " + linkDepsMacro;
2245
2246 string linker;
2247 if ( module.cplusplus )
2248 linker = "${gpp}";
2249 else
2250 linker = "${gcc}";
2251
2252 string linkerParameters = ssprintf ( "-Wl,--subsystem,console -Wl,--entry,%s -Wl,--image-base,%s -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000",
2253 module.entrypoint.c_str (),
2254 module.baseaddress.c_str () );
2255 GenerateLinkerCommand ( dependencies,
2256 linker,
2257 linkerParameters,
2258 objectsMacro,
2259 libsMacro );
2260 }
2261 else
2262 {
2263 GeneratePhonyTarget();
2264 }
2265 }