daff5b883b147aa3a38a0ba48867945e078c12d5
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
);
53 MingwModuleHandler::SetUsePch ( use_pch
);
57 MingwBackend::CloseMakefile () const
64 MingwBackend::GenerateHeader () const
66 fprintf ( fMakefile
, "# THIS FILE IS AUTOMATICALLY GENERATED, EDIT 'ReactOS.xml' INSTEAD\n\n" );
70 MingwBackend::GenerateProjectCFlagsMacro ( const char* assignmentOperation
,
71 IfableData
& data
) const
78 assignmentOperation
);
79 for ( i
= 0; i
< data
.includes
.size(); i
++ )
84 data
.includes
[i
]->directory
.c_str() );
87 for ( i
= 0; i
< data
.defines
.size(); i
++ )
89 Define
& d
= *data
.defines
[i
];
100 fprintf ( fMakefile
, "\n" );
104 MingwBackend::GenerateGlobalCFlagsAndProperties (
105 const char* assignmentOperation
,
106 IfableData
& data
) const
110 for ( i
= 0; i
< data
.properties
.size(); i
++ )
112 Property
& prop
= *data
.properties
[i
];
113 fprintf ( fMakefile
, "%s := %s\n",
115 prop
.value
.c_str() );
118 if ( data
.includes
.size() || data
.defines
.size() )
120 GenerateProjectCFlagsMacro ( assignmentOperation
,
124 for ( i
= 0; i
< data
.ifs
.size(); i
++ )
126 If
& rIf
= *data
.ifs
[i
];
127 if ( rIf
.data
.defines
.size()
128 || rIf
.data
.includes
.size()
129 || rIf
.data
.ifs
.size() )
133 "ifeq (\"$(%s)\",\"%s\")\n",
134 rIf
.property
.c_str(),
136 GenerateGlobalCFlagsAndProperties (
147 MingwBackend::GenerateProjectLFLAGS () const
150 for ( size_t i
= 0; i
< ProjectNode
.linkerFlags
.size (); i
++ )
152 LinkerFlag
& linkerFlag
= *ProjectNode
.linkerFlags
[i
];
153 if ( lflags
.length () > 0 )
155 lflags
+= linkerFlag
.flag
;
161 MingwBackend::GenerateGlobalVariables () const
163 #define TOOL_PREFIX "$(Q)." SSEP "tools" SSEP
164 fprintf ( fMakefile
, "mkdir = " TOOL_PREFIX
"rmkdir" EXEPOSTFIX
"\n" );
165 fprintf ( fMakefile
, "winebuild = " TOOL_PREFIX
"winebuild" SSEP
"winebuild" EXEPOSTFIX
"\n" );
166 fprintf ( fMakefile
, "bin2res = " TOOL_PREFIX
"bin2res" SSEP
"bin2res" EXEPOSTFIX
"\n" );
167 fprintf ( fMakefile
, "cabman = " TOOL_PREFIX
"cabman" SSEP
"cabman" EXEPOSTFIX
"\n" );
168 fprintf ( fMakefile
, "cdmake = " TOOL_PREFIX
"cdmake" SSEP
"cdmake" EXEPOSTFIX
"\n" );
169 fprintf ( fMakefile
, "rsym = " TOOL_PREFIX
"rsym" EXEPOSTFIX
"\n" );
170 fprintf ( fMakefile
, "wrc = " TOOL_PREFIX
"wrc" SSEP
"wrc" EXEPOSTFIX
"\n" );
171 fprintf ( fMakefile
, "\n" );
172 GenerateGlobalCFlagsAndProperties (
174 ProjectNode
.non_if_data
);
175 fprintf ( fMakefile
, "PROJECT_RCFLAGS = $(PROJECT_CFLAGS)\n" );
176 fprintf ( fMakefile
, "PROJECT_LFLAGS = %s\n",
177 GenerateProjectLFLAGS ().c_str () );
178 fprintf ( fMakefile
, "\n" );
182 MingwBackend::IncludeInAllTarget ( const Module
& module
) const
184 if ( module
.type
== ObjectLibrary
)
186 if ( module
.type
== BootSector
)
188 if ( module
.type
== Iso
)
194 MingwBackend::GenerateAllTarget () const
196 fprintf ( fMakefile
, "all:" );
198 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
200 Module
& module
= *ProjectNode
.modules
[i
];
201 if ( IncludeInAllTarget ( module
) )
203 if ( wrap_count
++ == 5 )
204 fprintf ( fMakefile
, " \\\n\t\t" ), wrap_count
= 0;
207 FixupTargetFilename ( module
.GetPath () ).c_str () );
210 fprintf ( fMakefile
, "\n\t\n\n" );
214 MingwBackend::GetBuildToolDependencies () const
217 for ( size_t i
= 0; i
< ProjectNode
.modules
.size (); i
++ )
219 Module
& module
= *ProjectNode
.modules
[i
];
220 if ( module
.type
== BuildTool
)
222 if ( dependencies
.length () > 0 )
224 dependencies
+= module
.GetDependencyPath ();
231 MingwBackend::GenerateInitTarget () const
236 " $(ROS_INTERMEDIATE)." SSEP
"tools" );
239 GetBuildToolDependencies ().c_str () );
242 "include" SSEP
"reactos" SSEP
"buildno.h" );
247 "$(ROS_INTERMEDIATE)." SSEP
"tools:\n" );
249 "ifneq ($(ROS_INTERMEDIATE),)\n" );
251 "\t${nmkdir} $(ROS_INTERMEDIATE)\n" );
255 "\t${nmkdir} $(ROS_INTERMEDIATE)." SSEP
"tools\n" );
261 MingwBackend::GenerateXmlBuildFilesMacro() const
264 "XMLBUILDFILES = %s \\\n",
265 ProjectNode
.GetProjectFilename ().c_str () );
266 string xmlbuildFilenames
;
267 int numberOfExistingFiles
= 0;
268 for ( size_t i
= 0; i
< ProjectNode
.xmlbuildfiles
.size (); i
++ )
270 XMLInclude
& xmlbuildfile
= *ProjectNode
.xmlbuildfiles
[i
];
271 if ( !xmlbuildfile
.fileExists
)
273 numberOfExistingFiles
++;
274 if ( xmlbuildFilenames
.length () > 0 )
275 xmlbuildFilenames
+= " ";
276 xmlbuildFilenames
+= NormalizeFilename ( xmlbuildfile
.topIncludeFilename
);
277 if ( numberOfExistingFiles
% 5 == 4 || i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
281 xmlbuildFilenames
.c_str ());
282 if ( i
== ProjectNode
.xmlbuildfiles
.size () - 1 )
291 xmlbuildFilenames
.c_str () );
293 xmlbuildFilenames
.resize ( 0 );
295 numberOfExistingFiles
++;
302 MingwBackend::CheckAutomaticDependencies ()
304 AutomaticDependency
automaticDependency ( ProjectNode
);
305 automaticDependency
.Process ();
306 automaticDependency
.CheckAutomaticDependencies ();
310 MingwBackend::ProcessModule ( Module
& module
) const
312 MingwModuleHandler
* h
= MingwModuleHandler::LookupHandler (
313 module
.node
.location
,
315 MingwModuleHandler::string_list clean_files
;
316 if ( module
.host
== HostDefault
)
318 module
.host
= h
->DefaultHost();
319 assert ( module
.host
!= HostDefault
);
321 h
->Process ( module
, clean_files
);
322 h
->GenerateCleanTarget ( module
, clean_files
);
323 h
->GenerateDirectoryTargets ();
327 FixupTargetFilename ( const string
& targetFilename
)
329 return string("$(ROS_INTERMEDIATE)") + NormalizeFilename ( targetFilename
);
333 MingwBackend::DetectPCHSupport()
335 string path
= "tools" SSEP
"rbuild" SSEP
"backend" SSEP
"mingw" SSEP
"pch_detection.h";
336 system ( ssprintf("gcc -c %s", path
.c_str()).c_str() );
339 FILE* f
= fopen ( path
.c_str(), "rb" );
344 unlink ( path
.c_str() );
349 // TODO FIXME - eventually check for ROS_USE_PCH env var and
350 // allow that to override use_pch if true