10 static class MingwFactory
: public Backend::Factory
13 MingwFactory() : Factory ( "mingw" ) {}
14 Backend
* operator() ( Project
& project
)
16 return new MingwBackend ( project
);
21 MingwBackend::MingwBackend ( Project
& project
)
27 MingwBackend::Process ()
33 GenerateGlobalVariables ();
35 GenerateInitTarget ();
36 GenerateXmlBuildFilesMacro();
37 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
39 Module
& module
= *ProjectNode
.modules
[i
];
40 ProcessModule ( module
);
42 CheckAutomaticDependencies ();
47 MingwBackend::CreateMakefile ()
49 fMakefile
= fopen ( ProjectNode
.makefile
.c_str (), "w" );
51 throw AccessDeniedException ( ProjectNode
.makefile
);
52 MingwModuleHandler::SetMakefile ( fMakefile
);
56 MingwBackend::CloseMakefile () const
63 MingwBackend::GenerateHeader () const
65 fprintf ( fMakefile
, "# THIS FILE IS AUTOMATICALLY GENERATED, EDIT 'ReactOS.xml' INSTEAD\n\n" );
69 MingwBackend::GenerateProjectCFlagsMacro ( const char* assignmentOperation
,
70 const vector
<Include
*>& includes
,
71 const vector
<Define
*>& defines
) const
78 assignmentOperation
);
79 for ( i
= 0; i
< includes
.size(); i
++ )
84 includes
[i
]->directory
.c_str() );
87 for ( i
= 0; i
< defines
.size(); i
++ )
89 Define
& d
= *defines
[i
];
100 fprintf ( fMakefile
, "\n" );
104 MingwBackend::GenerateGlobalCFlagsAndProperties (
105 const char* assignmentOperation
,
106 const vector
<Property
*>& properties
,
107 const vector
<Include
*>& includes
,
108 const vector
<Define
*>& defines
,
109 const vector
<If
*>& ifs
) const
113 for ( i
= 0; i
< properties
.size(); i
++ )
115 Property
& prop
= *properties
[i
];
116 fprintf ( fMakefile
, "%s := %s\n",
118 prop
.value
.c_str() );
121 if ( includes
.size() || defines
.size() )
123 GenerateProjectCFlagsMacro ( assignmentOperation
,
128 for ( i
= 0; i
< ifs
.size(); i
++ )
131 if ( rIf
.defines
.size() || rIf
.includes
.size() || rIf
.ifs
.size() )
135 "ifeq (\"$(%s)\",\"%s\")\n",
136 rIf
.property
.c_str(),
138 GenerateGlobalCFlagsAndProperties (
152 MingwBackend::GenerateProjectLFLAGS () const
155 for ( size_t i
= 0; i
< ProjectNode
.linkerFlags
.size (); i
++ )
157 LinkerFlag
& linkerFlag
= *ProjectNode
.linkerFlags
[i
];
158 if ( lflags
.length () > 0 )
160 lflags
+= linkerFlag
.flag
;
166 MingwBackend::GenerateGlobalVariables () const
168 fprintf ( fMakefile
, "mkdir = tools" SSEP
"rmkdir" EXEPOSTFIX
"\n" );
169 fprintf ( fMakefile
, "winebuild = tools" SSEP
"winebuild" SSEP
"winebuild" EXEPOSTFIX
"\n" );
170 fprintf ( fMakefile
, "bin2res = tools" SSEP
"bin2res" SSEP
"bin2res" EXEPOSTFIX
"\n" );
171 fprintf ( fMakefile
, "cabman = tools" SSEP
"cabman" SSEP
"cabman" EXEPOSTFIX
"\n" );
172 fprintf ( fMakefile
, "cdmake = tools" SSEP
"cdmake" SSEP
"cdmake" EXEPOSTFIX
"\n" );
173 fprintf ( fMakefile
, "rsym = tools" SSEP
"rsym" EXEPOSTFIX
"\n" );
174 fprintf ( fMakefile
, "wrc = tools" SSEP
"wrc" SSEP
"wrc" EXEPOSTFIX
"\n" );
175 fprintf ( fMakefile
, "\n" );
176 GenerateGlobalCFlagsAndProperties (
178 ProjectNode
.properties
,
179 ProjectNode
.includes
,
182 fprintf ( fMakefile
, "PROJECT_RCFLAGS = $(PROJECT_CFLAGS)\n" );
183 fprintf ( fMakefile
, "PROJECT_LFLAGS = %s\n",
184 GenerateProjectLFLAGS ().c_str () );
185 fprintf ( fMakefile
, "\n" );
189 MingwBackend::IncludeInAllTarget ( const Module
& module
) const
191 if ( module
.type
== ObjectLibrary
)
193 if ( module
.type
== BootSector
)
195 if ( module
.type
== Iso
)
201 MingwBackend::GenerateAllTarget () const
203 fprintf ( fMakefile
, "all:" );
204 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
206 Module
& module
= *ProjectNode
.modules
[i
];
207 if ( IncludeInAllTarget ( module
) )
211 FixupTargetFilename ( module
.GetPath () ).c_str () );
214 fprintf ( fMakefile
, "\n\t\n\n" );
218 MingwBackend::GetBuildToolDependencies () const
221 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
223 Module
& module
= *ProjectNode
.modules
[i
];
224 if ( module
.type
== BuildTool
)
226 if ( dependencies
.length () > 0 )
228 dependencies
+= module
.GetDependencyPath ();
235 MingwBackend::GenerateInitTarget () const
240 " $(ROS_INTERMEDIATE)." SSEP
"tools" );
243 GetBuildToolDependencies ().c_str () );
246 "include" SSEP
"reactos" SSEP
"buildno.h" );
251 "$(ROS_INTERMEDIATE)." SSEP
"tools:\n" );
253 "ifneq ($(ROS_INTERMEDIATE),)\n" );
255 "\t${nmkdir} $(ROS_INTERMEDIATE)\n" );
259 "\t${nmkdir} $(ROS_INTERMEDIATE)." SSEP
"tools\n" );
265 MingwBackend::GenerateXmlBuildFilesMacro() const
268 "XMLBUILDFILES = %s \\\n",
269 ProjectNode
.GetProjectFilename ().c_str () );
270 string xmlbuildFilenames
;
271 int numberOfExistingFiles
= 0;
272 for ( size_t i
= 0; i
< ProjectNode
.xmlbuildfiles
.size (); i
++ )
274 XMLInclude
& xmlbuildfile
= *ProjectNode
.xmlbuildfiles
[i
];
275 if ( !xmlbuildfile
.fileExists
)
277 numberOfExistingFiles
++;
278 if ( xmlbuildFilenames
.length () > 0 )
279 xmlbuildFilenames
+= " ";
280 xmlbuildFilenames
+= NormalizeFilename ( xmlbuildfile
.topIncludeFilename
);
281 if ( numberOfExistingFiles
% 5 == 4 || i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
285 xmlbuildFilenames
.c_str ());
286 if ( i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
295 xmlbuildFilenames
.c_str () );
297 xmlbuildFilenames
.resize ( 0 );
299 numberOfExistingFiles
++;
306 MingwBackend::CheckAutomaticDependencies ()
308 AutomaticDependency
automaticDependency ( ProjectNode
);
309 automaticDependency
.Process ();
310 automaticDependency
.CheckAutomaticDependencies ();
314 MingwBackend::ProcessModule ( Module
& module
) const
316 MingwModuleHandler
* h
= MingwModuleHandler::LookupHandler (
317 module
.node
.location
,
319 h
->Process ( module
);
320 h
->GenerateDirectoryTargets ();
324 FixupTargetFilename ( const string
& targetFilename
)
326 return string("$(ROS_INTERMEDIATE)") + NormalizeFilename ( targetFilename
);
330 MingwBackend::DetectPCHSupport()
332 string path
= "tools" SSEP
"rbuild" SSEP
"backend" SSEP
"mingw" SSEP
"pch_detection.h";
333 system ( ssprintf("gcc -c %s", path
.c_str()).c_str() );
336 FILE* f
= fopen ( path
.c_str(), "rb" );
341 unlink ( path
.c_str() );
346 // TODO FIXME - eventually check for ROS_USE_PCH env var and
347 // allow that to override use_pch if true