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