5c5d22f0af0a8c9f3cc3572af11b9108d5def32b
[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 using std::map;
11 using std::set;
12
13 map<ModuleType,MingwModuleHandler*>*
14 MingwModuleHandler::handler_map = NULL;
15 set<string>
16 MingwModuleHandler::directory_set;
17 int
18 MingwModuleHandler::ref = 0;
19
20 FILE*
21 MingwModuleHandler::fMakefile = NULL;
22
23 MingwModuleHandler::MingwModuleHandler ( ModuleType moduletype )
24 {
25 if ( !ref++ )
26 handler_map = new map<ModuleType,MingwModuleHandler*>;
27 (*handler_map)[moduletype] = this;
28 }
29
30 MingwModuleHandler::~MingwModuleHandler()
31 {
32 if ( !--ref )
33 {
34 delete handler_map;
35 handler_map = NULL;
36 }
37 }
38
39 const string &
40 MingwModuleHandler::PassThruCacheDirectory( const string &file ) const
41 {
42 directory_set.insert( ReplaceExtension( GetDirectory( file ), "" ) );
43 return file;
44 }
45
46 void
47 MingwModuleHandler::SetMakefile ( FILE* f )
48 {
49 fMakefile = f;
50 }
51
52 MingwModuleHandler*
53 MingwModuleHandler::LookupHandler ( const string& location,
54 ModuleType moduletype )
55 {
56 if ( !handler_map )
57 throw Exception ( "internal tool error: no registered module handlers" );
58 MingwModuleHandler* h = (*handler_map)[moduletype];
59 if ( !h )
60 {
61 throw UnknownModuleTypeException ( location, moduletype );
62 return NULL;
63 }
64 return h;
65 }
66
67 string
68 MingwModuleHandler::GetWorkingDirectory () const
69 {
70 return ".";
71 }
72
73 string
74 MingwModuleHandler::GetDirectory ( const string& filename ) const
75 {
76 size_t index = filename.find_last_of ( '/' );
77 if (index == string::npos) return ".";
78 else return filename.substr ( 0, index );
79 }
80
81 string
82 MingwModuleHandler::GetExtension ( const string& filename ) const
83 {
84 size_t index = filename.find_last_of ( '/' );
85 if (index == string::npos) index = 0;
86 string tmp = filename.substr( index, filename.size() - index );
87 size_t ext_index = tmp.find_last_of( '.' );
88 if (ext_index != string::npos)
89 return filename.substr ( index + ext_index, filename.size() );
90 return "";
91 }
92
93 string
94 MingwModuleHandler::GetBasename ( const string& filename ) const
95 {
96 size_t index = filename.find_last_of ( '.' );
97 if (index != string::npos)
98 return filename.substr ( 0, index );
99 return "";
100 }
101
102 string
103 MingwModuleHandler::ReplaceExtension ( const string& filename,
104 const string& newExtension ) const
105 {
106 size_t index = filename.find_last_of ( '/' );
107 if (index == string::npos) index = 0;
108 string tmp = filename.substr( index, filename.size() - index );
109 size_t ext_index = tmp.find_last_of( '.' );
110 if (ext_index != string::npos)
111 return filename.substr ( 0, index + ext_index ) + newExtension;
112 return filename + newExtension;
113 }
114
115 string
116 MingwModuleHandler::GetActualSourceFilename ( const string& filename ) const
117 {
118 string extension = GetExtension ( filename );
119 if ( extension == ".spec" || extension == "SPEC" )
120 {
121 string basename = GetBasename( filename );
122 return basename + ".stubs.c";
123 }
124 else
125 return filename;
126 }
127
128 string
129 MingwModuleHandler::GetModuleArchiveFilename ( const Module& module ) const
130 {
131 return ReplaceExtension ( FixupTargetFilename ( module.GetPath () ),
132 ".a" );
133 }
134
135 string
136 MingwModuleHandler::GetImportLibraryDependencies ( const Module& module ) const
137 {
138 if ( module.libraries.size () == 0 )
139 return "";
140
141 string dependencies ( "" );
142 for ( size_t i = 0; i < module.libraries.size (); i++ )
143 {
144 if ( dependencies.size () > 0 )
145 dependencies += " ";
146 const Module* importedModule = module.project.LocateModule ( module.libraries[i]->name );
147 assert ( importedModule != NULL );
148 dependencies += PassThruCacheDirectory ( FixupTargetFilename ( importedModule->GetDependencyPath () ) ).c_str ();
149 }
150 return dependencies;
151 }
152
153 string
154 MingwModuleHandler::GetModuleDependencies ( const Module& module ) const
155 {
156 if ( module.dependencies.size () == 0 )
157 return "";
158
159 string dependencies ( "" );
160 for ( size_t i = 0; i < module.dependencies.size (); i++ )
161 {
162 if ( dependencies.size () > 0 )
163 dependencies += " ";
164 const Dependency* dependency = module.dependencies[i];
165 const Module* dependencyModule = dependency->dependencyModule;
166 dependencies += dependencyModule->GetTargets ();
167 }
168 string definitionDependencies = GetDefinitionDependencies ( module );
169 if ( dependencies.length () > 0 && definitionDependencies.length () > 0 )
170 dependencies += " " + definitionDependencies;
171 else if ( definitionDependencies.length () > 0 )
172 dependencies = definitionDependencies;
173 return dependencies;
174 }
175
176 string
177 MingwModuleHandler::GetAllDependencies ( const Module& module ) const
178 {
179 string dependencies = GetImportLibraryDependencies ( module );
180 string s = GetModuleDependencies ( module );
181 if (s.length () > 0)
182 {
183 dependencies += " ";
184 dependencies += s;
185 }
186 return dependencies;
187 }
188
189 string
190 MingwModuleHandler::GetSourceFilenames ( const Module& module ) const
191 {
192 size_t i;
193
194 string sourceFilenames ( "" );
195 for ( i = 0; i < module.files.size (); i++ )
196 sourceFilenames += " " + GetActualSourceFilename ( module.files[i]->name );
197 vector<If*> ifs = module.ifs;
198 for ( i = 0; i < ifs.size(); i++ )
199 {
200 size_t j;
201 If& rIf = *ifs[i];
202 for ( j = 0; j < rIf.ifs.size(); j++ )
203 ifs.push_back ( rIf.ifs[j] );
204 for ( j = 0; j < rIf.files.size(); j++ )
205 sourceFilenames += " " + GetActualSourceFilename ( rIf.files[j]->name );
206 }
207 return sourceFilenames;
208 }
209
210 string
211 MingwModuleHandler::GetObjectFilename ( const string& sourceFilename ) const
212 {
213 string newExtension;
214 string extension = GetExtension ( sourceFilename );
215 if ( extension == ".rc" || extension == ".RC" )
216 newExtension = ".coff";
217 else if ( extension == ".spec" || extension == ".SPEC" )
218 newExtension = ".stubs.o";
219 else
220 newExtension = ".o";
221 return PassThruCacheDirectory
222 ( FixupTargetFilename ( ReplaceExtension ( sourceFilename,
223 newExtension ) ) );
224 }
225
226 string
227 MingwModuleHandler::GetObjectFilenames ( const Module& module ) const
228 {
229 if ( module.files.size () == 0 )
230 return "";
231
232 string objectFilenames ( "" );
233 for ( size_t i = 0; i < module.files.size (); i++ )
234 {
235 if ( objectFilenames.size () > 0 )
236 objectFilenames += " ";
237 objectFilenames += GetObjectFilename ( module.files[i]->name );
238 }
239 return objectFilenames;
240 }
241
242 void
243 MingwModuleHandler::GenerateDirectoryTargets() const
244 {
245 fprintf( fMakefile, "ifneq ($(ROS_INTERMEDIATE),)\ndirectories::" );
246
247 for( set<string>::iterator i = directory_set.begin();
248 i != directory_set.end();
249 i++ )
250 fprintf( fMakefile, " %s", i->c_str() );
251
252 fprintf( fMakefile, "\n\n" );
253
254 for( set<string>::iterator i = directory_set.begin();
255 i != directory_set.end();
256 i++ )
257 fprintf( fMakefile, "%s ", i->c_str() );
258
259 fprintf ( fMakefile,
260 "::\n\t${mkdir} $@\n\n"
261 "else\n"
262 "directories::\n\n"
263 "endif\n\n" );
264
265 directory_set.clear();
266 }
267
268 string
269 MingwModuleHandler::GenerateGccDefineParametersFromVector ( const vector<Define*>& defines ) const
270 {
271 string parameters;
272 for (size_t i = 0; i < defines.size (); i++)
273 {
274 Define& define = *defines[i];
275 if (parameters.length () > 0)
276 parameters += " ";
277 parameters += "-D";
278 parameters += define.name;
279 if (define.value.length () > 0)
280 {
281 parameters += "=";
282 parameters += define.value;
283 }
284 }
285 return parameters;
286 }
287
288 string
289 MingwModuleHandler::GenerateGccDefineParameters ( const Module& module ) const
290 {
291 string parameters = GenerateGccDefineParametersFromVector ( module.project.defines );
292 string s = GenerateGccDefineParametersFromVector ( module.defines );
293 if (s.length () > 0)
294 {
295 parameters += " ";
296 parameters += s;
297 }
298 return parameters;
299 }
300
301 string
302 MingwModuleHandler::ConcatenatePaths ( const string& path1,
303 const string& path2 ) const
304 {
305 if ( ( path1.length () == 0 ) || ( path1 == "." ) || ( path1 == "./" ) )
306 return path2;
307 if ( path1[path1.length ()] == CSEP )
308 return path1 + path2;
309 else
310 return path1 + CSEP + path2;
311 }
312
313 string
314 MingwModuleHandler::GenerateGccIncludeParametersFromVector ( const vector<Include*>& includes ) const
315 {
316 string parameters;
317 for ( size_t i = 0; i < includes.size (); i++ )
318 {
319 Include& include = *includes[i];
320 if (parameters.length () > 0)
321 parameters += " ";
322 parameters += "-I" + include.directory;
323 }
324 return parameters;
325 }
326
327 string
328 MingwModuleHandler::GenerateGccIncludeParameters ( const Module& module ) const
329 {
330 string parameters = GenerateGccIncludeParametersFromVector ( module.includes );
331 string s = GenerateGccIncludeParametersFromVector ( module.project.includes );
332 if ( s.length () > 0 )
333 {
334 parameters += " ";
335 parameters += s;
336 }
337 return parameters;
338 }
339
340
341 string
342 MingwModuleHandler::GenerateLinkerParametersFromVector ( const vector<LinkerFlag*>& linkerFlags ) const
343 {
344 string parameters;
345 for ( size_t i = 0; i < linkerFlags.size (); i++ )
346 {
347 LinkerFlag& linkerFlag = *linkerFlags[i];
348 if ( parameters.length () > 0 )
349 parameters += " ";
350 parameters += linkerFlag.flag;
351 }
352 return parameters;
353 }
354
355 string
356 MingwModuleHandler::GenerateLinkerParameters ( const Module& module ) const
357 {
358 return GenerateLinkerParametersFromVector ( module.linkerFlags );
359 }
360
361 void
362 MingwModuleHandler::GenerateMacro ( const char* assignmentOperation,
363 const string& macro,
364 const vector<Include*>& includes,
365 const vector<Define*>& defines ) const
366 {
367 size_t i;
368
369 fprintf (
370 fMakefile,
371 "%s %s",
372 macro.c_str(),
373 assignmentOperation );
374 for ( i = 0; i < includes.size(); i++ )
375 {
376 fprintf (
377 fMakefile,
378 " -I%s",
379 includes[i]->directory.c_str() );
380 }
381 for ( i = 0; i < defines.size(); i++ )
382 {
383 Define& d = *defines[i];
384 fprintf (
385 fMakefile,
386 " -D%s",
387 d.name.c_str() );
388 if ( d.value.size() )
389 fprintf (
390 fMakefile,
391 "=%s",
392 d.value.c_str() );
393 }
394 fprintf ( fMakefile, "\n" );
395 }
396
397 void
398 MingwModuleHandler::GenerateMacros (
399 const char* assignmentOperation,
400 const vector<File*>& files,
401 const vector<Include*>& includes,
402 const vector<Define*>& defines,
403 const vector<LinkerFlag*>* linkerFlags,
404 const vector<If*>& ifs,
405 const string& cflags_macro,
406 const string& nasmflags_macro,
407 const string& windresflags_macro,
408 const string& linkerflags_macro,
409 const string& objs_macro) const
410 {
411 size_t i;
412
413 if ( includes.size() || defines.size() )
414 {
415 GenerateMacro ( assignmentOperation,
416 cflags_macro,
417 includes,
418 defines );
419 GenerateMacro ( assignmentOperation,
420 windresflags_macro,
421 includes,
422 defines );
423 }
424
425 if ( linkerFlags != NULL )
426 {
427 string linkerParameters = GenerateLinkerParametersFromVector ( *linkerFlags );
428 if ( linkerParameters.size () > 0 )
429 {
430 fprintf (
431 fMakefile,
432 "%s %s %s\n",
433 linkerflags_macro.c_str (),
434 assignmentOperation,
435 linkerParameters.c_str() );
436 }
437 }
438
439 if ( files.size() )
440 {
441 fprintf (
442 fMakefile,
443 "%s %s",
444 objs_macro.c_str(),
445 assignmentOperation );
446 for ( i = 0; i < files.size(); i++ )
447 {
448 string extension = GetExtension ( files[i]->name );
449 if ( extension != ".spec" && extension != ".SPEC" )
450 {
451 fprintf (
452 fMakefile,
453 "%s%s",
454 ( i%10 == 9 ? "\\\n\t" : " " ),
455 GetObjectFilename(files[i]->name).c_str() );
456 }
457 }
458 fprintf ( fMakefile, "\n" );
459 }
460
461 for ( i = 0; i < ifs.size(); i++ )
462 {
463 If& rIf = *ifs[i];
464 if ( rIf.defines.size() || rIf.includes.size() || rIf.files.size() || rIf.ifs.size() )
465 {
466 fprintf (
467 fMakefile,
468 "ifeq (\"$(%s)\",\"%s\")\n",
469 rIf.property.c_str(),
470 rIf.value.c_str() );
471 GenerateMacros (
472 "+=",
473 rIf.files,
474 rIf.includes,
475 rIf.defines,
476 NULL,
477 rIf.ifs,
478 cflags_macro,
479 nasmflags_macro,
480 windresflags_macro,
481 linkerflags_macro,
482 objs_macro );
483 fprintf (
484 fMakefile,
485 "endif\n\n" );
486 }
487 }
488 }
489
490 void
491 MingwModuleHandler::GenerateMacros (
492 const Module& module,
493 const string& cflags_macro,
494 const string& nasmflags_macro,
495 const string& windresflags_macro,
496 const string& linkerflags_macro,
497 const string& objs_macro) const
498 {
499 GenerateMacros (
500 "=",
501 module.files,
502 module.includes,
503 module.defines,
504 &module.linkerFlags,
505 module.ifs,
506 cflags_macro,
507 nasmflags_macro,
508 windresflags_macro,
509 linkerflags_macro,
510 objs_macro );
511 fprintf ( fMakefile, "\n" );
512
513 fprintf (
514 fMakefile,
515 "%s += $(PROJECT_CFLAGS)\n\n",
516 cflags_macro.c_str () );
517
518 fprintf (
519 fMakefile,
520 "%s += $(PROJECT_RCFLAGS)\n\n",
521 windresflags_macro.c_str () );
522
523 fprintf (
524 fMakefile,
525 "%s_LFLAGS += $(PROJECT_LFLAGS)\n\n",
526 module.name.c_str () );
527 }
528
529 void
530 MingwModuleHandler::GenerateGccCommand ( const Module& module,
531 const string& sourceFilename,
532 const string& cc,
533 const string& cflagsMacro ) const
534 {
535 string objectFilename = GetObjectFilename ( sourceFilename );
536 fprintf ( fMakefile,
537 "%s: %s\n",
538 objectFilename.c_str (),
539 sourceFilename.c_str () );
540 fprintf ( fMakefile,
541 "\t%s -c %s -o %s %s\n",
542 cc.c_str (),
543 sourceFilename.c_str (),
544 objectFilename.c_str (),
545 cflagsMacro.c_str () );
546 }
547
548 void
549 MingwModuleHandler::GenerateGccAssemblerCommand ( const Module& module,
550 const string& sourceFilename,
551 const string& cc,
552 const string& cflagsMacro ) const
553 {
554 string objectFilename = GetObjectFilename ( sourceFilename );
555 fprintf ( fMakefile,
556 "%s: %s\n",
557 objectFilename.c_str (),
558 sourceFilename.c_str () );
559 fprintf ( fMakefile,
560 "\t%s -x assembler-with-cpp -c %s -o %s -D__ASM__ %s\n",
561 cc.c_str (),
562 sourceFilename.c_str (),
563 objectFilename.c_str (),
564 cflagsMacro.c_str () );
565 }
566
567 void
568 MingwModuleHandler::GenerateNasmCommand ( const Module& module,
569 const string& sourceFilename,
570 const string& nasmflagsMacro ) const
571 {
572 string objectFilename = GetObjectFilename ( sourceFilename );
573 fprintf ( fMakefile,
574 "%s: %s\n",
575 objectFilename.c_str (),
576 sourceFilename.c_str () );
577 fprintf ( fMakefile,
578 "\t%s -f win32 %s -o %s %s\n",
579 "nasm",
580 sourceFilename.c_str (),
581 objectFilename.c_str (),
582 nasmflagsMacro.c_str () );
583 }
584
585 void
586 MingwModuleHandler::GenerateWindresCommand ( const Module& module,
587 const string& sourceFilename,
588 const string& windresflagsMacro ) const
589 {
590 string objectFilename = GetObjectFilename ( sourceFilename );
591 fprintf ( fMakefile,
592 "%s: %s\n",
593 objectFilename.c_str (),
594 sourceFilename.c_str () );
595 fprintf ( fMakefile,
596 "\t%s %s -o %s ${%s}\n",
597 "${windres}",
598 sourceFilename.c_str (),
599 objectFilename.c_str (),
600 windresflagsMacro.c_str () );
601 }
602
603 void
604 MingwModuleHandler::GenerateWinebuildCommands ( const Module& module,
605 const string& sourceFilename ) const
606 {
607 string basename = GetBasename ( sourceFilename );
608 fprintf ( fMakefile,
609 "%s.def: %s\n",
610 basename.c_str (),
611 sourceFilename.c_str () );
612 fprintf ( fMakefile,
613 "\t%s --def=%s -o %s.def\n",
614 "${winebuild}",
615 sourceFilename.c_str (),
616 basename.c_str () );
617
618 fprintf ( fMakefile,
619 "%s.stubs.c: %s\n",
620 basename.c_str (),
621 sourceFilename.c_str () );
622 fprintf ( fMakefile,
623 "\t%s --pedll=%s -o %s.stubs.c\n",
624 "${winebuild}",
625 sourceFilename.c_str (),
626 basename.c_str () );
627 }
628
629 void
630 MingwModuleHandler::GenerateCommands ( const Module& module,
631 const string& sourceFilename,
632 const string& cc,
633 const string& cflagsMacro,
634 const string& nasmflagsMacro,
635 const string& windresflagsMacro ) const
636 {
637 string extension = GetExtension ( sourceFilename );
638 if ( extension == ".c" || extension == ".C" )
639 {
640 GenerateGccCommand ( module,
641 sourceFilename,
642 cc,
643 cflagsMacro );
644 return;
645 }
646 else if ( extension == ".s" || extension == ".S" )
647 {
648 GenerateGccAssemblerCommand ( module,
649 sourceFilename,
650 cc,
651 cflagsMacro );
652 return;
653 }
654 else if ( extension == ".asm" || extension == ".ASM" )
655 {
656 GenerateNasmCommand ( module,
657 sourceFilename,
658 nasmflagsMacro );
659 return;
660 }
661 else if ( extension == ".rc" || extension == ".RC" )
662 {
663 GenerateWindresCommand ( module,
664 sourceFilename,
665 windresflagsMacro );
666 return;
667 }
668 else if ( extension == ".spec" || extension == ".SPEC" )
669 {
670 GenerateWinebuildCommands ( module,
671 sourceFilename );
672 GenerateGccCommand ( module,
673 GetActualSourceFilename ( sourceFilename ),
674 cc,
675 cflagsMacro );
676 return;
677 }
678
679 throw InvalidOperationException ( __FILE__,
680 __LINE__,
681 "Unsupported filename extension '%s' in file '%s'",
682 extension.c_str (),
683 sourceFilename.c_str () );
684 }
685
686 void
687 MingwModuleHandler::GenerateLinkerCommand ( const Module& module,
688 const string& linker,
689 const string& linkerParameters,
690 const string& objectFilenames ) const
691 {
692 string targetName ( module.GetTargetName () );
693 string target ( FixupTargetFilename ( module.GetPath () ) );
694 string importLibraryDependencies = GetImportLibraryDependencies ( module );
695 if ( module.importLibrary != NULL )
696 {
697 static string ros_junk ( "$(ROS_TEMPORARY)" );
698 string base_tmp = ros_junk + module.name + ".base.tmp";
699 string junk_tmp = ros_junk + module.name + ".junk.tmp";
700 string temp_exp = ros_junk + module.name + ".temp.exp";
701
702 fprintf ( fMakefile,
703 "\t%s %s -Wl,--base-file,%s -o %s %s %s %s\n",
704 linker.c_str (),
705 linkerParameters.c_str (),
706 base_tmp.c_str (),
707 junk_tmp.c_str (),
708 objectFilenames.c_str (),
709 importLibraryDependencies.c_str (),
710 GetLinkerMacro ( module ).c_str () );
711
712 fprintf ( fMakefile,
713 "\t${rm} %s\n",
714 junk_tmp.c_str () );
715
716 fprintf ( fMakefile,
717 "\t${dlltool} --dllname %s --base-file %s --def %s --output-exp %s --kill-at\n",
718 targetName.c_str (),
719 base_tmp.c_str (),
720 (module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),
721 temp_exp.c_str () );
722
723 fprintf ( fMakefile,
724 "\t${rm} %s\n",
725 base_tmp.c_str () );
726
727 fprintf ( fMakefile,
728 "\t%s %s %s -o %s %s %s %s\n\n",
729 linker.c_str (),
730 linkerParameters.c_str (),
731 temp_exp.c_str (),
732 target.c_str (),
733 objectFilenames.c_str (),
734 importLibraryDependencies.c_str (),
735 GetLinkerMacro ( module ).c_str () );
736
737 fprintf ( fMakefile,
738 "\t${rm} %s\n\n",
739 temp_exp.c_str () );
740 }
741 else
742 {
743 fprintf ( fMakefile,
744 "\t%s %s -o %s %s %s %s\n\n",
745 linker.c_str (),
746 linkerParameters.c_str (),
747 target.c_str (),
748 objectFilenames.c_str (),
749 importLibraryDependencies.c_str (),
750 GetLinkerMacro ( module ).c_str () );
751 }
752 }
753
754 void
755 MingwModuleHandler::GenerateObjectFileTargets ( const Module& module,
756 const vector<File*>& files,
757 const vector<If*>& ifs,
758 const string& cc,
759 const string& cflagsMacro,
760 const string& nasmflagsMacro,
761 const string& windresflagsMacro ) const
762 {
763 size_t i;
764
765 for ( i = 0; i < files.size (); i++ )
766 {
767 string sourceFilename = files[i]->name;
768 GenerateCommands ( module,
769 sourceFilename,
770 cc,
771 cflagsMacro,
772 nasmflagsMacro,
773 windresflagsMacro );
774 fprintf ( fMakefile,
775 "\n" );
776 }
777
778 for ( i = 0; i < ifs.size(); i++ )
779 GenerateObjectFileTargets ( module,
780 ifs[i]->files,
781 ifs[i]->ifs,
782 cc,
783 cflagsMacro,
784 nasmflagsMacro,
785 windresflagsMacro );
786 }
787
788 void
789 MingwModuleHandler::GenerateObjectFileTargets ( const Module& module,
790 const string& cc,
791 const string& cflagsMacro,
792 const string& nasmflagsMacro,
793 const string& windresflagsMacro ) const
794 {
795 GenerateObjectFileTargets ( module,
796 module.files,
797 module.ifs,
798 cc,
799 cflagsMacro,
800 nasmflagsMacro,
801 windresflagsMacro );
802 fprintf ( fMakefile, "\n" );
803 }
804
805 void
806 MingwModuleHandler::GetCleanTargets ( vector<string>& out,
807 const vector<File*>& files,
808 const vector<If*>& ifs ) const
809 {
810 size_t i;
811
812 for ( i = 0; i < files.size(); i++ )
813 out.push_back ( GetObjectFilename(files[i]->name) );
814
815 for ( i = 0; i < ifs.size(); i++ )
816 GetCleanTargets ( out, ifs[i]->files, ifs[i]->ifs );
817 }
818
819 string
820 MingwModuleHandler::GenerateArchiveTarget ( const Module& module,
821 const string& ar,
822 const string& objs_macro ) const
823 {
824 string archiveFilename = GetModuleArchiveFilename ( module );
825
826 fprintf ( fMakefile,
827 "%s: %s\n",
828 archiveFilename.c_str (),
829 objs_macro.c_str ());
830
831 fprintf ( fMakefile,
832 "\t%s -rc %s %s\n\n",
833 ar.c_str (),
834 archiveFilename.c_str (),
835 objs_macro.c_str ());
836
837 return archiveFilename;
838 }
839
840 string
841 MingwModuleHandler::GetCFlagsMacro ( const Module& module ) const
842 {
843 return ssprintf ( "$(%s_CFLAGS)",
844 module.name.c_str () );
845 }
846
847 string
848 MingwModuleHandler::GetObjectsMacro ( const Module& module ) const
849 {
850 return ssprintf ( "$(%s_OBJS)",
851 module.name.c_str () );
852 }
853
854 string
855 MingwModuleHandler::GetLinkerMacro ( const Module& module ) const
856 {
857 return ssprintf ( "$(%s_LFLAGS)",
858 module.name.c_str () );
859 }
860
861 void
862 MingwModuleHandler::GenerateMacrosAndTargets (
863 const Module& module,
864 const string& cc,
865 const string& ar,
866 const string* cflags ) const
867 {
868 string cflagsMacro = ssprintf ("%s_CFLAGS", module.name.c_str ());
869 string nasmflagsMacro = ssprintf ("%s_NASMFLAGS", module.name.c_str ());
870 string windresflagsMacro = ssprintf ("%s_RCFLAGS", module.name.c_str ());
871 string linkerFlagsMacro = ssprintf ("%s_LFLAGS", module.name.c_str ());
872 string objectsMacro = ssprintf ("%s_OBJS", module.name.c_str ());
873
874 GenerateMacros ( module,
875 cflagsMacro,
876 nasmflagsMacro,
877 windresflagsMacro,
878 linkerFlagsMacro,
879 objectsMacro );
880
881 if ( cflags != NULL )
882 {
883 fprintf ( fMakefile,
884 "%s += %s\n\n",
885 cflagsMacro.c_str (),
886 cflags->c_str () );
887 }
888
889 // generate phony target for module name
890 fprintf ( fMakefile, ".PHONY: %s\n",
891 module.name.c_str () );
892 fprintf ( fMakefile, "%s: %s\n\n",
893 module.name.c_str (),
894 module.GetPath ().c_str () );
895
896 // future references to the macros will be to get their values
897 cflagsMacro = ssprintf ("$(%s)", cflagsMacro.c_str ());
898 nasmflagsMacro = ssprintf ("$(%s)", nasmflagsMacro.c_str ());
899 objectsMacro = ssprintf ("$(%s)", objectsMacro.c_str ());
900
901 string ar_target = GenerateArchiveTarget ( module, ar, objectsMacro );
902 GenerateObjectFileTargets ( module,
903 cc,
904 cflagsMacro,
905 nasmflagsMacro,
906 windresflagsMacro );
907
908 vector<string> clean_files;
909 clean_files.push_back ( FixupTargetFilename(module.GetPath()) );
910 clean_files.push_back ( ar_target );
911 GetCleanTargets ( clean_files, module.files, module.ifs );
912
913 fprintf ( fMakefile, "clean::\n\t-@$(rm)" );
914 for ( size_t i = 0; i < clean_files.size(); i++ )
915 {
916 if ( 9==(i%10) )
917 fprintf ( fMakefile, " 2>$(NUL)\n\t-@$(rm)" );
918 fprintf ( fMakefile, " %s", clean_files[i].c_str() );
919 }
920 fprintf ( fMakefile, " 2>$(NUL)\n\n" );
921 }
922
923 void
924 MingwModuleHandler::GenerateMacrosAndTargetsHost ( const Module& module ) const
925 {
926 GenerateMacrosAndTargets ( module, "${host_gcc}", "${host_ar}", NULL );
927 }
928
929 void
930 MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module& module ) const
931 {
932 GenerateMacrosAndTargetsTarget ( module,
933 NULL );
934 }
935
936 void
937 MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module& module,
938 const string* clags ) const
939 {
940 GenerateMacrosAndTargets ( module, "${gcc}", "${ar}", clags );
941 }
942
943 string
944 MingwModuleHandler::GetInvocationDependencies ( const Module& module ) const
945 {
946 string dependencies;
947 for ( size_t i = 0; i < module.invocations.size (); i++ )
948 {
949 Invoke& invoke = *module.invocations[i];
950 if (invoke.invokeModule == &module)
951 /* Protect against circular dependencies */
952 continue;
953 if ( dependencies.length () > 0 )
954 dependencies += " ";
955 dependencies += invoke.GetTargets ();
956 }
957 return dependencies;
958 }
959
960 string
961 MingwModuleHandler::GetInvocationParameters ( const Invoke& invoke ) const
962 {
963 string parameters ( "" );
964 size_t i;
965 for (i = 0; i < invoke.output.size (); i++)
966 {
967 if (parameters.length () > 0)
968 parameters += " ";
969 InvokeFile& invokeFile = *invoke.output[i];
970 if (invokeFile.switches.length () > 0)
971 {
972 parameters += invokeFile.switches;
973 parameters += " ";
974 }
975 parameters += invokeFile.name;
976 }
977
978 for (i = 0; i < invoke.input.size (); i++)
979 {
980 if (parameters.length () > 0)
981 parameters += " ";
982 InvokeFile& invokeFile = *invoke.input[i];
983 if (invokeFile.switches.length () > 0)
984 {
985 parameters += invokeFile.switches;
986 parameters += " ";
987 }
988 parameters += invokeFile.name;
989 }
990
991 return parameters;
992 }
993
994 void
995 MingwModuleHandler::GenerateInvocations ( const Module& module ) const
996 {
997 if ( module.invocations.size () == 0 )
998 return;
999
1000 for ( size_t i = 0; i < module.invocations.size (); i++ )
1001 {
1002 const Invoke& invoke = *module.invocations[i];
1003
1004 if ( invoke.invokeModule->type != BuildTool )
1005 throw InvalidBuildFileException ( module.node.location,
1006 "Only modules of type buildtool can be invoked." );
1007
1008 string invokeTarget = module.GetInvocationTarget ( i );
1009 fprintf ( fMakefile,
1010 "%s: %s\n\n",
1011 invoke.GetTargets ().c_str (),
1012 invokeTarget.c_str () );
1013 fprintf ( fMakefile,
1014 "%s: %s\n",
1015 invokeTarget.c_str (),
1016 FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str () );
1017 fprintf ( fMakefile,
1018 "\t%s %s\n\n",
1019 FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str (),
1020 GetInvocationParameters ( invoke ).c_str () );
1021 fprintf ( fMakefile,
1022 ".PNONY: %s\n\n",
1023 invokeTarget.c_str () );
1024 }
1025 }
1026
1027 string
1028 MingwModuleHandler::GetPreconditionDependenciesName ( const Module& module ) const
1029 {
1030 return ssprintf ( "%s_precondition",
1031 module.name.c_str () );
1032 }
1033
1034 void
1035 MingwModuleHandler::GeneratePreconditionDependencies ( const Module& module ) const
1036 {
1037 string preconditionDependenciesName = GetPreconditionDependenciesName ( module );
1038 string sourceFilenames = GetSourceFilenames ( module );
1039 string dependencies = GetModuleDependencies ( module );
1040 string s = GetInvocationDependencies ( module );
1041 if ( s.length () > 0 )
1042 {
1043 if ( dependencies.length () > 0 )
1044 dependencies += " ";
1045 dependencies += s;
1046 }
1047
1048 fprintf ( fMakefile,
1049 ".PHONY: %s\n\n",
1050 preconditionDependenciesName.c_str () );
1051 fprintf ( fMakefile,
1052 "%s: %s\n\n",
1053 preconditionDependenciesName.c_str (),
1054 dependencies.c_str () );
1055 const char* p = sourceFilenames.c_str();
1056 const char* end = p + strlen(p);
1057 while ( p < end )
1058 {
1059 const char* p2 = &p[512];
1060 if ( p2 > end )
1061 p2 = end;
1062 while ( p2 > p && !isspace(*p2) )
1063 --p2;
1064 if ( p == p2 )
1065 {
1066 p2 = strpbrk ( p, " \t" );
1067 if ( !p2 )
1068 p2 = end;
1069 }
1070 fprintf ( fMakefile,
1071 "%.*s: %s\n",
1072 p2-p,
1073 p,
1074 preconditionDependenciesName.c_str ());
1075 p = p2;
1076 p += strspn ( p, " \t" );
1077 }
1078 fprintf ( fMakefile, "\n" );
1079 }
1080
1081 void
1082 MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ( const Module& module ) const
1083 {
1084 if ( module.importLibrary != NULL )
1085 {
1086 string definitionDependencies = GetDefinitionDependencies ( module );
1087 fprintf ( fMakefile, "%s: %s\n",
1088 FixupTargetFilename( module.GetDependencyPath () ).c_str (),
1089 definitionDependencies.c_str () );
1090
1091 fprintf ( fMakefile,
1092 "\t${dlltool} --dllname %s --def %s --output-lib %s --kill-at\n\n",
1093 module.GetTargetName ().c_str (),
1094 (module.GetBasePath () + SSEP + module.importLibrary->definition).c_str (),
1095 FixupTargetFilename ( module.GetDependencyPath () ).c_str () );
1096 }
1097 }
1098
1099 string
1100 MingwModuleHandler::GetSpecObjectDependencies ( const string& filename ) const
1101 {
1102 string basename = GetBasename ( filename );
1103 return basename + ".def" + " " + basename + ".stubs.c";
1104 }
1105
1106 string
1107 MingwModuleHandler::GetDefinitionDependencies ( const Module& module ) const
1108 {
1109 string dependencies;
1110 for ( size_t i = 0; i < module.files.size (); i++ )
1111 {
1112 File& file = *module.files[i];
1113 string extension = GetExtension ( file.name );
1114 if ( extension == ".spec" || extension == ".SPEC" )
1115 {
1116 if ( dependencies.length () > 0 )
1117 dependencies += " ";
1118 dependencies += GetSpecObjectDependencies ( file.name );
1119 }
1120 }
1121 return dependencies;
1122 }
1123
1124 string
1125 MingwModuleHandler::GetLinkingDependencies ( const Module& module ) const
1126 {
1127 string dependencies = GetImportLibraryDependencies ( module );
1128 string s = GetDefinitionDependencies ( module );
1129 if ( s.length () > 0 )
1130 {
1131 dependencies += " ";
1132 dependencies += s;
1133 }
1134 return dependencies;
1135 }
1136
1137
1138 static MingwBuildToolModuleHandler buildtool_handler;
1139
1140 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler()
1141 : MingwModuleHandler ( BuildTool )
1142 {
1143 }
1144
1145 void
1146 MingwBuildToolModuleHandler::Process ( const Module& module )
1147 {
1148 GeneratePreconditionDependencies ( module );
1149 GenerateBuildToolModuleTarget ( module );
1150 GenerateInvocations ( module );
1151 }
1152
1153 void
1154 MingwBuildToolModuleHandler::GenerateBuildToolModuleTarget ( const Module& module )
1155 {
1156 string target ( FixupTargetFilename ( module.GetPath () ) );
1157 string archiveFilename = GetModuleArchiveFilename ( module );
1158
1159 GenerateMacrosAndTargetsHost ( module );
1160
1161 fprintf ( fMakefile, "%s: %s\n",
1162 target.c_str (),
1163 archiveFilename.c_str () );
1164 fprintf ( fMakefile,
1165 "\t${host_gcc} %s -o %s %s\n\n",
1166 GetLinkerMacro ( module ).c_str (),
1167 target.c_str (),
1168 archiveFilename.c_str () );
1169 }
1170
1171 static MingwKernelModuleHandler kernelmodule_handler;
1172
1173 MingwKernelModuleHandler::MingwKernelModuleHandler ()
1174 : MingwModuleHandler ( Kernel )
1175 {
1176 }
1177
1178 void
1179 MingwKernelModuleHandler::Process ( const Module& module )
1180 {
1181 GeneratePreconditionDependencies ( module );
1182 GenerateKernelModuleTarget ( module );
1183 GenerateInvocations ( module );
1184 }
1185
1186 void
1187 MingwKernelModuleHandler::GenerateKernelModuleTarget ( const Module& module )
1188 {
1189 static string ros_junk ( "$(ROS_TEMPORARY)" );
1190 string targetName ( module.GetTargetName () );
1191 string target ( FixupTargetFilename (module.GetPath ()) );
1192 string workingDirectory = GetWorkingDirectory ();
1193 string objectsMacro = GetObjectsMacro ( module );
1194 string importLibraryDependencies = GetImportLibraryDependencies ( module );
1195 string base_tmp = ros_junk + module.name + ".base.tmp";
1196 string junk_tmp = ros_junk + module.name + ".junk.tmp";
1197 string temp_exp = ros_junk + module.name + ".temp.exp";
1198 string gccOptions = ssprintf ("-Wl,-T,%s" SSEP "ntoskrnl.lnk -Wl,--subsystem,native -Wl,--entry,_NtProcessStartup -Wl,--image-base,0xC0000000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll",
1199 module.GetBasePath ().c_str () );
1200
1201 GenerateMacrosAndTargetsTarget ( module );
1202
1203 GenerateImportLibraryTargetIfNeeded ( module );
1204
1205 fprintf ( fMakefile, "%s: %s %s\n",
1206 target.c_str (),
1207 objectsMacro.c_str (),
1208 importLibraryDependencies.c_str () );
1209 fprintf ( fMakefile,
1210 "\t${gcc} %s %s -Wl,--base-file,%s -o %s %s %s\n",
1211 GetLinkerMacro ( module ).c_str (),
1212 gccOptions.c_str (),
1213 base_tmp.c_str (),
1214 junk_tmp.c_str (),
1215 objectsMacro.c_str (),
1216 importLibraryDependencies.c_str () );
1217 fprintf ( fMakefile,
1218 "\t${rm} %s\n",
1219 junk_tmp.c_str () );
1220 fprintf ( fMakefile,
1221 "\t${dlltool} --dllname %s --base-file %s --def ntoskrnl/ntoskrnl.def --output-exp %s --kill-at\n",
1222 targetName.c_str (),
1223 base_tmp.c_str (),
1224 temp_exp.c_str () );
1225 fprintf ( fMakefile,
1226 "\t${rm} %s\n",
1227 base_tmp.c_str () );
1228 fprintf ( fMakefile,
1229 "\t${gcc} %s %s -Wl,%s -o %s %s %s\n",
1230 GetLinkerMacro ( module ).c_str (),
1231 gccOptions.c_str (),
1232 temp_exp.c_str (),
1233 target.c_str (),
1234 objectsMacro.c_str (),
1235 importLibraryDependencies.c_str () );
1236 fprintf ( fMakefile,
1237 "\t${rm} %s\n\n",
1238 temp_exp.c_str () );
1239 }
1240
1241
1242 static MingwStaticLibraryModuleHandler staticlibrary_handler;
1243
1244 MingwStaticLibraryModuleHandler::MingwStaticLibraryModuleHandler ()
1245 : MingwModuleHandler ( StaticLibrary )
1246 {
1247 }
1248
1249 void
1250 MingwStaticLibraryModuleHandler::Process ( const Module& module )
1251 {
1252 GeneratePreconditionDependencies ( module );
1253 GenerateStaticLibraryModuleTarget ( module );
1254 GenerateInvocations ( module );
1255 }
1256
1257 void
1258 MingwStaticLibraryModuleHandler::GenerateStaticLibraryModuleTarget ( const Module& module )
1259 {
1260 GenerateMacrosAndTargetsTarget ( module );
1261 }
1262
1263
1264 static MingwKernelModeDLLModuleHandler kernelmodedll_handler;
1265
1266 MingwKernelModeDLLModuleHandler::MingwKernelModeDLLModuleHandler ()
1267 : MingwModuleHandler ( KernelModeDLL )
1268 {
1269 }
1270
1271 void
1272 MingwKernelModeDLLModuleHandler::Process ( const Module& module )
1273 {
1274 GeneratePreconditionDependencies ( module );
1275 GenerateKernelModeDLLModuleTarget ( module );
1276 GenerateInvocations ( module );
1277 }
1278
1279 void
1280 MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget ( const Module& module )
1281 {
1282 static string ros_junk ( "$(ROS_TEMPORARY)" );
1283 string target ( FixupTargetFilename ( module.GetPath () ) );
1284 string workingDirectory = GetWorkingDirectory ( );
1285 string archiveFilename = GetModuleArchiveFilename ( module );
1286 string importLibraryDependencies = GetImportLibraryDependencies ( module );
1287
1288 GenerateImportLibraryTargetIfNeeded ( module );
1289
1290 if ( module.files.size () > 0 )
1291 {
1292 GenerateMacrosAndTargetsTarget ( module );
1293
1294 fprintf ( fMakefile, "%s: %s %s\n",
1295 target.c_str (),
1296 archiveFilename.c_str (),
1297 importLibraryDependencies.c_str () );
1298
1299 string linkerParameters ( "-Wl,--subsystem,native -Wl,--entry,_DriverEntry@8 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll" );
1300 GenerateLinkerCommand ( module,
1301 "${gcc}",
1302 linkerParameters,
1303 archiveFilename );
1304 }
1305 else
1306 {
1307 fprintf ( fMakefile, "%s:\n",
1308 target.c_str ());
1309 fprintf ( fMakefile, ".PHONY: %s\n\n",
1310 target.c_str ());
1311 }
1312 }
1313
1314
1315 static MingwKernelModeDriverModuleHandler kernelmodedriver_handler;
1316
1317 MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ()
1318 : MingwModuleHandler ( KernelModeDriver )
1319 {
1320 }
1321
1322 void
1323 MingwKernelModeDriverModuleHandler::Process ( const Module& module )
1324 {
1325 GeneratePreconditionDependencies ( module );
1326 GenerateKernelModeDriverModuleTarget ( module );
1327 GenerateInvocations ( module );
1328 }
1329
1330
1331 void
1332 MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ( const Module& module )
1333 {
1334 static string ros_junk ( "$(ROS_TEMPORARY)" );
1335 string target ( PassThruCacheDirectory( FixupTargetFilename ( module.GetPath () ) ) );
1336 string workingDirectory = GetWorkingDirectory ( );
1337 string archiveFilename = GetModuleArchiveFilename ( module );
1338 string importLibraryDependencies = GetImportLibraryDependencies ( module );
1339
1340 GenerateImportLibraryTargetIfNeeded ( module );
1341
1342 if ( module.files.size () > 0 )
1343 {
1344 string* cflags = new string ( "-D__NTDRIVER__" );
1345 GenerateMacrosAndTargetsTarget ( module,
1346 cflags );
1347 delete cflags;
1348
1349 fprintf ( fMakefile, "%s: %s %s\n",
1350 target.c_str (),
1351 archiveFilename.c_str (),
1352 importLibraryDependencies.c_str () );
1353
1354 string linkerParameters ( "-Wl,--subsystem,native -Wl,--entry,_DriverEntry@8 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll" );
1355 GenerateLinkerCommand ( module,
1356 "${gcc}",
1357 linkerParameters,
1358 archiveFilename );
1359 }
1360 else
1361 {
1362 fprintf ( fMakefile, "%s:\n",
1363 target.c_str () );
1364 fprintf ( fMakefile, ".PHONY: %s\n\n",
1365 target.c_str ());
1366 }
1367 }
1368
1369
1370 static MingwNativeDLLModuleHandler nativedll_handler;
1371
1372 MingwNativeDLLModuleHandler::MingwNativeDLLModuleHandler ()
1373 : MingwModuleHandler ( NativeDLL )
1374 {
1375 }
1376
1377 void
1378 MingwNativeDLLModuleHandler::Process ( const Module& module )
1379 {
1380 GeneratePreconditionDependencies ( module );
1381 GenerateNativeDLLModuleTarget ( module );
1382 GenerateInvocations ( module );
1383 }
1384
1385 void
1386 MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget ( const Module& module )
1387 {
1388 static string ros_junk ( "$(ROS_TEMPORARY)" );
1389 string target ( FixupTargetFilename ( module.GetPath () ) );
1390 string workingDirectory = GetWorkingDirectory ( );
1391 string objectFilenames = GetObjectFilenames ( module );
1392 string archiveFilename = GetModuleArchiveFilename ( module );
1393 string importLibraryDependencies = GetImportLibraryDependencies ( module );
1394
1395 GenerateImportLibraryTargetIfNeeded ( module );
1396
1397 if ( module.files.size () > 0 )
1398 {
1399
1400 fprintf ( fMakefile,
1401 "\t${dlltool} --dllname %s --def %s --output-lib %s --kill-at\n\n",
1402 module.GetTargetName ().c_str (),
1403 (module.GetBasePath () + SSEP + module.importLibrary->definition).c_str (),
1404 FixupTargetFilename ( module.GetDependencyPath () ).c_str () );
1405 }
1406
1407 if (module.files.size () > 0)
1408 {
1409 GenerateMacrosAndTargetsTarget ( module );
1410
1411 fprintf ( fMakefile, "%s: %s %s\n",
1412 target.c_str (),
1413 archiveFilename.c_str (),
1414 importLibraryDependencies.c_str () );
1415
1416 string linkerParameters ( "-Wl,--subsystem,native -Wl,--entry,_DllMainCRTStartup@12 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -nostdlib -mdll" );
1417 GenerateLinkerCommand ( module,
1418 "${gcc}",
1419 linkerParameters,
1420 objectFilenames );
1421 }
1422 else
1423 {
1424 fprintf ( fMakefile, "%s:\n\n",
1425 target.c_str ());
1426 fprintf ( fMakefile, ".PHONY: %s\n\n",
1427 target.c_str ());
1428 }
1429 }
1430
1431
1432 static MingwWin32DLLModuleHandler win32dll_handler;
1433
1434 MingwWin32DLLModuleHandler::MingwWin32DLLModuleHandler ()
1435 : MingwModuleHandler ( Win32DLL )
1436 {
1437 }
1438
1439 void
1440 MingwWin32DLLModuleHandler::Process ( const Module& module )
1441 {
1442 GeneratePreconditionDependencies ( module );
1443 GenerateWin32DLLModuleTarget ( module );
1444 GenerateInvocations ( module );
1445 }
1446
1447 void
1448 MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget ( const Module& module )
1449 {
1450 static string ros_junk ( "$(ROS_TEMPORARY)" );
1451 string target ( FixupTargetFilename ( module.GetPath () ) );
1452 string workingDirectory = GetWorkingDirectory ( );
1453 string objectFilenames = GetObjectFilenames ( module );
1454 string linkingDependencies = GetLinkingDependencies ( module );
1455
1456 GenerateImportLibraryTargetIfNeeded ( module );
1457 if ( module.files.size () > 0 )
1458 {
1459 GenerateMacrosAndTargetsTarget ( module );
1460
1461 fprintf ( fMakefile, "%s: %s %s\n",
1462 target.c_str (),
1463 objectFilenames.c_str (),
1464 linkingDependencies.c_str () );
1465
1466 string linkerParameters ( "-Wl,--subsystem,console -Wl,--entry,_DllMain@12 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -mdll" );
1467 GenerateLinkerCommand ( module,
1468 "${gcc}",
1469 linkerParameters,
1470 objectFilenames );
1471 }
1472 else
1473 {
1474 fprintf ( fMakefile, "%s:\n\n",
1475 target.c_str ());
1476 fprintf ( fMakefile, ".PHONY: %s\n\n",
1477 target.c_str ());
1478 }
1479 }
1480
1481
1482 static MingwWin32GUIModuleHandler win32gui_handler;
1483
1484 MingwWin32GUIModuleHandler::MingwWin32GUIModuleHandler ()
1485 : MingwModuleHandler ( Win32GUI )
1486 {
1487 }
1488
1489 void
1490 MingwWin32GUIModuleHandler::Process ( const Module& module )
1491 {
1492 GeneratePreconditionDependencies ( module );
1493 GenerateWin32GUIModuleTarget ( module );
1494 GenerateInvocations ( module );
1495 }
1496
1497 void
1498 MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget ( const Module& module )
1499 {
1500 static string ros_junk ( "$(ROS_TEMPORARY)" );
1501 string target ( FixupTargetFilename ( module.GetPath () ) );
1502 string workingDirectory = GetWorkingDirectory ( );
1503 string objectFilenames = GetObjectFilenames ( module );
1504 string importLibraryDependencies = GetImportLibraryDependencies ( module );
1505
1506 GenerateImportLibraryTargetIfNeeded ( module );
1507
1508 if ( module.files.size () > 0 )
1509 {
1510 GenerateMacrosAndTargetsTarget ( module );
1511
1512 fprintf ( fMakefile, "%s: %s %s\n",
1513 target.c_str (),
1514 objectFilenames.c_str (),
1515 importLibraryDependencies.c_str () );
1516
1517 string linkerParameters ( "-Wl,--subsystem,windows -Wl,--entry,_WinMainCRTStartup -Wl,--image-base,0x00400000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000" );
1518 GenerateLinkerCommand ( module,
1519 "${gcc}",
1520 linkerParameters,
1521 objectFilenames );
1522 }
1523 else
1524 {
1525 fprintf ( fMakefile, "%s:\n\n",
1526 target.c_str ());
1527 fprintf ( fMakefile, ".PHONY: %s\n\n",
1528 target.c_str ());
1529 }
1530 }