af30e8c5962997b59dba07f1cc552395634bf20f
11 typedef set
<string
> set_string
;
13 static class MingwFactory
: public Backend::Factory
16 MingwFactory() : Factory ( "mingw" ) {}
17 Backend
* operator() ( Project
& project
)
19 return new MingwBackend ( project
);
24 MingwBackend::MingwBackend ( Project
& project
)
30 MingwBackend::CreateDirectoryTargetIfNotYetCreated ( const string
& directory
)
32 directories
.insert ( directory
);
37 MingwBackend::Process ()
43 GenerateGlobalVariables ();
45 GenerateInitTarget ();
46 GenerateXmlBuildFilesMacro();
47 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
49 Module
& module
= *ProjectNode
.modules
[i
];
50 ProcessModule ( module
);
52 GenerateDirectoryTargets ();
53 CheckAutomaticDependencies ();
58 MingwBackend::CreateMakefile ()
60 fMakefile
= fopen ( ProjectNode
.makefile
.c_str (), "w" );
62 throw AccessDeniedException ( ProjectNode
.makefile
);
63 MingwModuleHandler::SetMakefile ( fMakefile
);
64 MingwModuleHandler::SetUsePch ( use_pch
);
68 MingwBackend::CloseMakefile () const
75 MingwBackend::GenerateHeader () const
77 fprintf ( fMakefile
, "# THIS FILE IS AUTOMATICALLY GENERATED, EDIT 'ReactOS.xml' INSTEAD\n\n" );
81 MingwBackend::GenerateProjectCFlagsMacro ( const char* assignmentOperation
,
82 IfableData
& data
) const
89 assignmentOperation
);
90 for ( i
= 0; i
< data
.includes
.size(); i
++ )
95 data
.includes
[i
]->directory
.c_str() );
98 for ( i
= 0; i
< data
.defines
.size(); i
++ )
100 Define
& d
= *data
.defines
[i
];
105 if ( d
.value
.size() )
111 fprintf ( fMakefile
, "\n" );
115 MingwBackend::GenerateGlobalCFlagsAndProperties (
116 const char* assignmentOperation
,
117 IfableData
& data
) const
121 for ( i
= 0; i
< data
.properties
.size(); i
++ )
123 Property
& prop
= *data
.properties
[i
];
124 fprintf ( fMakefile
, "%s := %s\n",
126 prop
.value
.c_str() );
129 if ( data
.includes
.size() || data
.defines
.size() )
131 GenerateProjectCFlagsMacro ( assignmentOperation
,
135 for ( i
= 0; i
< data
.ifs
.size(); i
++ )
137 If
& rIf
= *data
.ifs
[i
];
138 if ( rIf
.data
.defines
.size()
139 || rIf
.data
.includes
.size()
140 || rIf
.data
.ifs
.size() )
144 "ifeq (\"$(%s)\",\"%s\")\n",
145 rIf
.property
.c_str(),
147 GenerateGlobalCFlagsAndProperties (
158 MingwBackend::GenerateProjectLFLAGS () const
161 for ( size_t i
= 0; i
< ProjectNode
.linkerFlags
.size (); i
++ )
163 LinkerFlag
& linkerFlag
= *ProjectNode
.linkerFlags
[i
];
164 if ( lflags
.length () > 0 )
166 lflags
+= linkerFlag
.flag
;
172 MingwBackend::GenerateGlobalVariables () const
174 #define TOOL_PREFIX "$(Q)$(INTERMEDIATE)tools" SSEP
175 fprintf ( fMakefile
, "winebuild = " TOOL_PREFIX
"winebuild" SSEP
"winebuild" EXEPOSTFIX
"\n" );
176 fprintf ( fMakefile
, "bin2res = " TOOL_PREFIX
"bin2res" SSEP
"bin2res" EXEPOSTFIX
"\n" );
177 fprintf ( fMakefile
, "cabman = " TOOL_PREFIX
"cabman" SSEP
"cabman" EXEPOSTFIX
"\n" );
178 fprintf ( fMakefile
, "cdmake = " TOOL_PREFIX
"cdmake" SSEP
"cdmake" EXEPOSTFIX
"\n" );
179 fprintf ( fMakefile
, "rsym = " TOOL_PREFIX
"rsym" EXEPOSTFIX
"\n" );
180 fprintf ( fMakefile
, "wrc = " TOOL_PREFIX
"wrc" SSEP
"wrc" EXEPOSTFIX
"\n" );
181 fprintf ( fMakefile
, "\n" );
182 GenerateGlobalCFlagsAndProperties (
184 ProjectNode
.non_if_data
);
185 fprintf ( fMakefile
, "PROJECT_RCFLAGS = $(PROJECT_CFLAGS)\n" );
186 fprintf ( fMakefile
, "PROJECT_LFLAGS = %s\n",
187 GenerateProjectLFLAGS ().c_str () );
188 fprintf ( fMakefile
, "\n" );
192 MingwBackend::IncludeInAllTarget ( const Module
& module
) const
194 if ( module
.type
== ObjectLibrary
)
196 if ( module
.type
== BootSector
)
198 if ( module
.type
== Iso
)
204 MingwBackend::GenerateAllTarget () const
206 fprintf ( fMakefile
, "all:" );
208 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
210 Module
& module
= *ProjectNode
.modules
[i
];
211 if ( IncludeInAllTarget ( module
) )
213 if ( wrap_count
++ == 5 )
214 fprintf ( fMakefile
, " \\\n\t\t" ), wrap_count
= 0;
217 FixupTargetFilename ( module
.GetPath () ).c_str () );
220 fprintf ( fMakefile
, "\n\t\n\n" );
224 MingwBackend::GetBuildToolDependencies () const
227 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
229 Module
& module
= *ProjectNode
.modules
[i
];
230 if ( module
.type
== BuildTool
)
232 if ( dependencies
.length () > 0 )
234 dependencies
+= module
.GetDependencyPath ();
241 MingwBackend::GenerateInitTarget () const
245 GetBuildToolDependencies ().c_str () );
251 MingwBackend::GenerateXmlBuildFilesMacro() const
254 "XMLBUILDFILES = %s \\\n",
255 ProjectNode
.GetProjectFilename ().c_str () );
256 string xmlbuildFilenames
;
257 int numberOfExistingFiles
= 0;
258 for ( size_t i
= 0; i
< ProjectNode
.xmlbuildfiles
.size (); i
++ )
260 XMLInclude
& xmlbuildfile
= *ProjectNode
.xmlbuildfiles
[i
];
261 if ( !xmlbuildfile
.fileExists
)
263 numberOfExistingFiles
++;
264 if ( xmlbuildFilenames
.length () > 0 )
265 xmlbuildFilenames
+= " ";
266 xmlbuildFilenames
+= NormalizeFilename ( xmlbuildfile
.topIncludeFilename
);
267 if ( numberOfExistingFiles
% 5 == 4 || i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
271 xmlbuildFilenames
.c_str ());
272 if ( i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
281 xmlbuildFilenames
.c_str () );
283 xmlbuildFilenames
.resize ( 0 );
285 numberOfExistingFiles
++;
292 MingwBackend::CheckAutomaticDependencies ()
294 AutomaticDependency
automaticDependency ( ProjectNode
);
295 automaticDependency
.Process ();
296 automaticDependency
.CheckAutomaticDependencies ();
300 MingwBackend::ProcessModule ( Module
& module
)
302 MingwModuleHandler
* h
= MingwModuleHandler::InstanciateHandler (
303 module
.node
.location
,
306 MingwModuleHandler::string_list clean_files
;
307 if ( module
.host
== HostDefault
)
309 module
.host
= h
->DefaultHost();
310 assert ( module
.host
!= HostDefault
);
312 h
->Process ( module
, clean_files
);
313 h
->GenerateCleanTarget ( module
, clean_files
);
317 MingwBackend::IncludeDirectoryTarget ( const string
& directory
) const
319 if ( directory
== "$(INTERMEDIATE)tools")
326 MingwBackend::GenerateDirectoryTargets ()
328 if ( directories
.size () == 0 )
331 set_string::iterator i
;
332 for ( i
= directories
.begin ();
333 i
!= directories
.end ();
336 if ( IncludeDirectoryTarget ( *i
) )
347 directories
.clear ();
351 FixupTargetFilename ( const string
& targetFilename
)
353 return string("$(INTERMEDIATE)") + NormalizeFilename ( targetFilename
);
357 MingwBackend::DetectPCHSupport()
362 string sNUL
= "/dev/null";
364 string path
= "tools" SSEP
"rbuild" SSEP
"backend" SSEP
"mingw" SSEP
"pch_detection.h";
365 string cmd
= ssprintf(
369 system ( cmd
.c_str() );
372 FILE* f
= fopen ( path
.c_str(), "rb" );
377 unlink ( path
.c_str() );
382 // TODO FIXME - eventually check for ROS_USE_PCH env var and
383 // allow that to override use_pch if true