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 IfableData
& data
) const
77 assignmentOperation
);
78 for ( i
= 0; i
< data
.includes
.size(); i
++ )
83 data
.includes
[i
]->directory
.c_str() );
86 for ( i
= 0; i
< data
.defines
.size(); i
++ )
88 Define
& d
= *data
.defines
[i
];
99 fprintf ( fMakefile
, "\n" );
103 MingwBackend::GenerateGlobalCFlagsAndProperties (
104 const char* assignmentOperation
,
105 IfableData
& data
) const
109 for ( i
= 0; i
< data
.properties
.size(); i
++ )
111 Property
& prop
= *data
.properties
[i
];
112 fprintf ( fMakefile
, "%s := %s\n",
114 prop
.value
.c_str() );
117 if ( data
.includes
.size() || data
.defines
.size() )
119 GenerateProjectCFlagsMacro ( assignmentOperation
,
123 for ( i
= 0; i
< data
.ifs
.size(); i
++ )
125 If
& rIf
= *data
.ifs
[i
];
126 if ( rIf
.data
.defines
.size()
127 || rIf
.data
.includes
.size()
128 || rIf
.data
.ifs
.size() )
132 "ifeq (\"$(%s)\",\"%s\")\n",
133 rIf
.property
.c_str(),
135 GenerateGlobalCFlagsAndProperties (
146 MingwBackend::GenerateProjectLFLAGS () const
149 for ( size_t i
= 0; i
< ProjectNode
.linkerFlags
.size (); i
++ )
151 LinkerFlag
& linkerFlag
= *ProjectNode
.linkerFlags
[i
];
152 if ( lflags
.length () > 0 )
154 lflags
+= linkerFlag
.flag
;
160 MingwBackend::GenerateGlobalVariables () const
162 fprintf ( fMakefile
, "mkdir = $(Q)tools" SSEP
"rmkdir" EXEPOSTFIX
"\n" );
163 fprintf ( fMakefile
, "winebuild = $(Q)tools" SSEP
"winebuild" SSEP
"winebuild" EXEPOSTFIX
"\n" );
164 fprintf ( fMakefile
, "bin2res = $(Q)tools" SSEP
"bin2res" SSEP
"bin2res" EXEPOSTFIX
"\n" );
165 fprintf ( fMakefile
, "cabman = $(Q)tools" SSEP
"cabman" SSEP
"cabman" EXEPOSTFIX
"\n" );
166 fprintf ( fMakefile
, "cdmake = $(Q)tools" SSEP
"cdmake" SSEP
"cdmake" EXEPOSTFIX
"\n" );
167 fprintf ( fMakefile
, "rsym = $(Q)tools" SSEP
"rsym" EXEPOSTFIX
"\n" );
168 fprintf ( fMakefile
, "wrc = $(Q)tools" SSEP
"wrc" SSEP
"wrc" EXEPOSTFIX
"\n" );
169 fprintf ( fMakefile
, "\n" );
170 GenerateGlobalCFlagsAndProperties (
172 ProjectNode
.non_if_data
);
173 fprintf ( fMakefile
, "PROJECT_RCFLAGS = $(PROJECT_CFLAGS)\n" );
174 fprintf ( fMakefile
, "PROJECT_LFLAGS = %s\n",
175 GenerateProjectLFLAGS ().c_str () );
176 fprintf ( fMakefile
, "\n" );
180 MingwBackend::IncludeInAllTarget ( const Module
& module
) const
182 if ( module
.type
== ObjectLibrary
)
184 if ( module
.type
== BootSector
)
186 if ( module
.type
== Iso
)
192 MingwBackend::GenerateAllTarget () const
194 fprintf ( fMakefile
, "all:" );
196 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
198 Module
& module
= *ProjectNode
.modules
[i
];
199 if ( IncludeInAllTarget ( module
) )
201 if ( wrap_count
++ == 5 )
202 fprintf ( fMakefile
, " \\\n\t\t" ), wrap_count
= 0;
205 FixupTargetFilename ( module
.GetPath () ).c_str () );
208 fprintf ( fMakefile
, "\n\t\n\n" );
212 MingwBackend::GetBuildToolDependencies () const
215 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
217 Module
& module
= *ProjectNode
.modules
[i
];
218 if ( module
.type
== BuildTool
)
220 if ( dependencies
.length () > 0 )
222 dependencies
+= module
.GetDependencyPath ();
229 MingwBackend::GenerateInitTarget () const
234 " $(ROS_INTERMEDIATE)." SSEP
"tools" );
237 GetBuildToolDependencies ().c_str () );
240 "include" SSEP
"reactos" SSEP
"buildno.h" );
245 "$(ROS_INTERMEDIATE)." SSEP
"tools:\n" );
247 "ifneq ($(ROS_INTERMEDIATE),)\n" );
249 "\t${nmkdir} $(ROS_INTERMEDIATE)\n" );
253 "\t${nmkdir} $(ROS_INTERMEDIATE)." SSEP
"tools\n" );
259 MingwBackend::GenerateXmlBuildFilesMacro() const
262 "XMLBUILDFILES = %s \\\n",
263 ProjectNode
.GetProjectFilename ().c_str () );
264 string xmlbuildFilenames
;
265 int numberOfExistingFiles
= 0;
266 for ( size_t i
= 0; i
< ProjectNode
.xmlbuildfiles
.size (); i
++ )
268 XMLInclude
& xmlbuildfile
= *ProjectNode
.xmlbuildfiles
[i
];
269 if ( !xmlbuildfile
.fileExists
)
271 numberOfExistingFiles
++;
272 if ( xmlbuildFilenames
.length () > 0 )
273 xmlbuildFilenames
+= " ";
274 xmlbuildFilenames
+= NormalizeFilename ( xmlbuildfile
.topIncludeFilename
);
275 if ( numberOfExistingFiles
% 5 == 4 || i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
279 xmlbuildFilenames
.c_str ());
280 if ( i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
289 xmlbuildFilenames
.c_str () );
291 xmlbuildFilenames
.resize ( 0 );
293 numberOfExistingFiles
++;
300 MingwBackend::CheckAutomaticDependencies ()
302 AutomaticDependency
automaticDependency ( ProjectNode
);
303 automaticDependency
.Process ();
304 automaticDependency
.CheckAutomaticDependencies ();
308 MingwBackend::ProcessModule ( Module
& module
) const
310 MingwModuleHandler
* h
= MingwModuleHandler::LookupHandler (
311 module
.node
.location
,
313 MingwModuleHandler::string_list clean_files
;
314 h
->Process ( module
, clean_files
);
315 h
->GenerateCleanTarget ( module
, clean_files
);
316 h
->GenerateDirectoryTargets ();
320 FixupTargetFilename ( const string
& targetFilename
)
322 return string("$(ROS_INTERMEDIATE)") + NormalizeFilename ( targetFilename
);
326 MingwBackend::DetectPCHSupport()
328 string path
= "tools" SSEP
"rbuild" SSEP
"backend" SSEP
"mingw" SSEP
"pch_detection.h";
329 system ( ssprintf("gcc -c %s", path
.c_str()).c_str() );
332 FILE* f
= fopen ( path
.c_str(), "rb" );
337 unlink ( path
.c_str() );
342 // TODO FIXME - eventually check for ROS_USE_PCH env var and
343 // allow that to override use_pch if true