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
, "regtests = " TOOL_PREFIX
"regtests" EXEPOSTFIX
"\n" );
180 fprintf ( fMakefile
, "rsym = " TOOL_PREFIX
"rsym" EXEPOSTFIX
"\n" );
181 fprintf ( fMakefile
, "wrc = " TOOL_PREFIX
"wrc" SSEP
"wrc" EXEPOSTFIX
"\n" );
182 fprintf ( fMakefile
, "\n" );
183 GenerateGlobalCFlagsAndProperties (
185 ProjectNode
.non_if_data
);
186 fprintf ( fMakefile
, "PROJECT_RCFLAGS = $(PROJECT_CFLAGS)\n" );
187 fprintf ( fMakefile
, "PROJECT_LFLAGS = %s\n",
188 GenerateProjectLFLAGS ().c_str () );
189 fprintf ( fMakefile
, "\n" );
193 MingwBackend::IncludeInAllTarget ( const Module
& module
) const
195 if ( module
.type
== ObjectLibrary
)
197 if ( module
.type
== BootSector
)
199 if ( module
.type
== Iso
)
205 MingwBackend::GenerateAllTarget () const
207 fprintf ( fMakefile
, "all:" );
209 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
211 Module
& module
= *ProjectNode
.modules
[i
];
212 if ( IncludeInAllTarget ( module
) )
214 if ( wrap_count
++ == 5 )
215 fprintf ( fMakefile
, " \\\n\t\t" ), wrap_count
= 0;
218 FixupTargetFilename ( module
.GetPath () ).c_str () );
221 fprintf ( fMakefile
, "\n\t\n\n" );
225 MingwBackend::GetBuildToolDependencies () const
228 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
230 Module
& module
= *ProjectNode
.modules
[i
];
231 if ( module
.type
== BuildTool
)
233 if ( dependencies
.length () > 0 )
235 dependencies
+= module
.GetDependencyPath ();
242 MingwBackend::GenerateInitTarget () const
246 GetBuildToolDependencies ().c_str () );
252 MingwBackend::GenerateXmlBuildFilesMacro() const
255 "XMLBUILDFILES = %s \\\n",
256 ProjectNode
.GetProjectFilename ().c_str () );
257 string xmlbuildFilenames
;
258 int numberOfExistingFiles
= 0;
259 for ( size_t i
= 0; i
< ProjectNode
.xmlbuildfiles
.size (); i
++ )
261 XMLInclude
& xmlbuildfile
= *ProjectNode
.xmlbuildfiles
[i
];
262 if ( !xmlbuildfile
.fileExists
)
264 numberOfExistingFiles
++;
265 if ( xmlbuildFilenames
.length () > 0 )
266 xmlbuildFilenames
+= " ";
267 xmlbuildFilenames
+= NormalizeFilename ( xmlbuildfile
.topIncludeFilename
);
268 if ( numberOfExistingFiles
% 5 == 4 || i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
272 xmlbuildFilenames
.c_str ());
273 if ( i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
282 xmlbuildFilenames
.c_str () );
284 xmlbuildFilenames
.resize ( 0 );
286 numberOfExistingFiles
++;
293 MingwBackend::CheckAutomaticDependencies ()
295 AutomaticDependency
automaticDependency ( ProjectNode
);
296 automaticDependency
.Process ();
297 automaticDependency
.CheckAutomaticDependencies ();
301 MingwBackend::ProcessModule ( Module
& module
)
303 MingwModuleHandler
* h
= MingwModuleHandler::InstanciateHandler (
304 module
.node
.location
,
307 MingwModuleHandler::string_list clean_files
;
308 if ( module
.host
== HostDefault
)
310 module
.host
= h
->DefaultHost();
311 assert ( module
.host
!= HostDefault
);
313 h
->Process ( module
, clean_files
);
314 h
->GenerateCleanTarget ( module
, clean_files
);
318 MingwBackend::IncludeDirectoryTarget ( const string
& directory
) const
320 if ( directory
== "$(INTERMEDIATE)tools")
327 MingwBackend::GenerateDirectoryTargets ()
329 if ( directories
.size () == 0 )
332 set_string::iterator i
;
333 for ( i
= directories
.begin ();
334 i
!= directories
.end ();
337 if ( IncludeDirectoryTarget ( *i
) )
340 "%s: $(RMKDIR_TARGET)\n",
348 directories
.clear ();
352 FixupTargetFilename ( const string
& targetFilename
)
354 return string("$(INTERMEDIATE)") + NormalizeFilename ( targetFilename
);
358 MingwBackend::DetectPCHSupport()
363 string sNUL
= "/dev/null";
365 string path
= "tools" SSEP
"rbuild" SSEP
"backend" SSEP
"mingw" SSEP
"pch_detection.h";
366 string cmd
= ssprintf(
370 system ( cmd
.c_str() );
373 FILE* f
= fopen ( path
.c_str(), "rb" );
378 unlink ( path
.c_str() );
383 // TODO FIXME - eventually check for ROS_USE_PCH env var and
384 // allow that to override use_pch if true