2 * Copyright (C) 2005 Casper S. Hornstrup
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include "backend/backend.h"
30 #include "backend/mingw/mingw.h"
35 static string BuildSystem
;
36 static string RootXmlFile
;
37 static Configuration configuration
;
38 static std::map
<string
, string
> properties
;
41 ParseAutomaticDependencySwitch (
45 switch ( switchChar2
)
48 configuration
.Dependencies
= NoDependencies
;
51 configuration
.Dependencies
= AutomaticDependencies
;
54 configuration
.Dependencies
= FullDependencies
;
57 if ( strlen ( switchStart
) <= 3 )
59 printf ( "Switch -dm requires a module name\n" );
62 configuration
.CheckDependenciesForModuleOnly
= true;
63 configuration
.CheckDependenciesForModuleOnlyModule
= string(&switchStart
[3]);
66 printf ( "Unknown switch -d%c\n",
74 ParseCompilationUnitSwitch (
78 switch ( switchChar2
)
81 configuration
.CompilationUnitsEnabled
= false;
84 printf ( "Unknown switch -u%c\n",
92 ParsePrecompiledHeaderSwitch (
96 switch ( switchChar2
)
99 configuration
.PrecompiledHeadersEnabled
= false;
102 printf ( "Unknown switch -h%c\n",
110 ParseVCProjectSwitch (
116 switch ( switchChar2
)
119 if ( strlen ( switchStart
) <= 3 )
121 printf ( "Switch -dm requires a module name\n" );
124 configuration
.VSProjectVersion
= string(&switchStart
[3]);
126 if (configuration
.VSProjectVersion
.at(0) == '{') {
127 printf ( "Error: invalid char {\n" );
131 if (configuration
.VSProjectVersion
.length() == 1) //7,8
132 configuration
.VSProjectVersion
.append(".00");
134 if (configuration
.VSProjectVersion
.length() == 3) //7.1
135 configuration
.VSProjectVersion
.append("0");
137 //We should set this here because in the end we will use
138 //msc sompiler so we need to parse msc specidic
139 //definitions and includes
140 configuration
.Compiler
= MicrosoftC
;
144 configuration
.VSConfigurationType
= string (&switchStart
[3]);
145 configuration
.InstallFiles
= true;
148 if ( strlen ( switchStart
) <= 3 )
150 printf ( "Invalid switch\n" );
153 temp
= string (&switchStart
[3]);
154 if ( temp
.find ("configuration") != string::npos
)
155 configuration
.UseConfigurationInPath
= true;
157 if ( temp
.find ("version") != string::npos
)
158 configuration
.UseVSVersionInPath
= true;
161 printf ( "Unknown switch -d%c\n",
169 ParseMingwSwitch ( char* switchStart
)
173 if ( *switchStart
== 'c' )
177 if ( strcmp ( switchStart
, "msc" ) == 0 )
178 configuration
.Compiler
= MicrosoftC
;
179 else if ( strcmp ( switchStart
, "gcc" ) == 0 )
180 configuration
.Compiler
= GnuGcc
;
183 printf ( "Unknown value of -Mc: %s\n", switchStart
);
187 else if ( *switchStart
== 'l' )
191 if ( strcmp ( switchStart
, "mslink" ) == 0 )
192 configuration
.Linker
= MicrosoftLink
;
193 else if ( strcmp ( switchStart
, "ld" ) == 0 )
194 configuration
.Linker
= GnuLd
;
197 printf ( "Unknown value of -Ml: %s\n", switchStart
);
201 else if ( strcmp ( switchStart
, "microsoft" ) == 0 )
203 configuration
.Compiler
= MicrosoftC
;
204 configuration
.Linker
= MicrosoftLink
;
206 else if ( strcmp ( switchStart
, "gnu" ) == 0 )
208 configuration
.Compiler
= GnuGcc
;
209 configuration
.Linker
= GnuLd
;
213 printf ( "Unknown value of -M: %s\n", switchStart
);
221 ParseMakeSwitch ( char switchChar2
)
223 switch ( switchChar2
)
226 configuration
.MakeHandlesInstallDirectories
= true;
229 printf ( "Unknown switch -m%c\n",
237 ParseProxyMakefileSwitch ( char switchChar2
)
239 switch ( switchChar2
)
242 configuration
.GenerateProxyMakefilesInSourceTree
= true;
245 printf ( "Unknown switch -p%c\n",
253 ParseDefineSwitch ( char* switchStart
)
255 string s
= string ( switchStart
+ 2 );
256 string::size_type separator
= s
.find ( '=' );
257 if ( separator
== string::npos
|| separator
== 0 )
259 printf ( "Invalid define switch: '%s'\n", switchStart
);
262 if ( s
.find ( '=', separator
+ 1 ) != string::npos
)
264 printf ( "Invalid define switch: '%s'\n", switchStart
);
268 string var
= s
.substr ( 0, separator
);
269 string val
= s
.substr ( separator
+ 1 );
270 properties
.insert ( std::pair
<string
, string
> ( var
, val
) );
275 ParseSwitch ( int argc
, char** argv
, int index
)
277 char switchChar
= strlen ( argv
[index
] ) > 1 ? argv
[index
][1] : ' ';
278 char switchChar2
= strlen ( argv
[index
] ) > 2 ? argv
[index
][2] : ' ';
279 switch ( switchChar
)
282 if (switchChar2
== 's' || switchChar2
== 'c' || switchChar2
== 'o')
284 return ParseVCProjectSwitch (
289 configuration
.Verbose
= true;
292 configuration
.CleanAsYouGo
= true;
295 return ParseAutomaticDependencySwitch (
299 return ParsePrecompiledHeaderSwitch (
304 return ParseCompilationUnitSwitch (
308 RootXmlFile
= string(&argv
[index
][2]);
311 return ParseMakeSwitch ( switchChar2
);
313 return ParseMingwSwitch ( argv
[index
] );
315 return ParseProxyMakefileSwitch ( switchChar2
);
317 return ParseDefineSwitch ( argv
[index
] );
320 "Unknown switch -%c\n",
328 ParseArguments ( int argc
, char** argv
)
333 for ( int i
= 1; i
< argc
; i
++ )
335 if ( argv
[i
][0] == '-' )
337 if ( !ParseSwitch ( argc
, argv
, i
) )
341 BuildSystem
= argv
[i
];
348 main ( int argc
, char** argv
)
350 InitializeEnvironment ();
352 if ( !ParseArguments ( argc
, argv
) )
354 printf ( "Generates project files for buildsystems\n\n" );
355 printf ( " rbuild [switches] -r{rootfile.rbuild} buildsystem\n\n" );
356 printf ( "Switches:\n" );
357 printf ( " -v Be verbose.\n" );
358 printf ( " -c Clean as you go. Delete generated files as soon as they are not\n" );
359 printf ( " needed anymore.\n" );
360 printf ( " -dd Disable automatic dependencies.\n" );
361 printf ( " -da Enable automatic dependencies.\n" );
362 printf ( " -df Enable full dependencies.\n" );
363 printf ( " -dm{module} Check only automatic dependencies for this module.\n" );
364 printf ( " -ud Disable multiple source files per compilation unit.\n" );
365 printf ( " -mi Let make handle creation of install directories. Rbuild will\n" );
366 printf ( " not generate the directories.\n" );
367 printf ( " -ps Generate proxy makefiles in source tree instead of the output.\n" );
368 printf ( " tree.\n" );
369 printf ( " -vs{version} Version of MS VS project files. Default is %s.\n", MS_VS_DEF_VERSION
);
370 printf ( " -vo{version|configuration} Adds subdirectory path to the default Intermediate-Outputdirectory.\n" );
371 printf ( " -Mc{compiler} Compiler to use for mingw backend. Can be one of:\n" );
372 printf ( " %-10s %s (default)\n", "gcc", "GNU compiler collection (gcc, g++)\n");
373 printf ( " %-10s %s\n", "msc", "Microsoft Visual C++ (cl)\n");
374 printf ( " -Ml{compiler} Linker to use for mingw backend. Can be one of:\n" );
375 printf ( " %-10s %s (default)\n", "ld", "GNU binutils (ld, dlltool)\n");
376 printf ( " %-10s %s\n", "mslink", "Microsoft Linker (link, lib)\n");
377 printf ( " -Mmicrosoft Same as -Mcmsc -Mlmslink\n" );
378 printf ( " -Mgnu Same as -Mcgcc -Mlld\n" );
379 printf ( " -Dvar=val Set the value of 'var' variable to 'val'.\n" );
381 printf ( " buildsystem Target build system. Can be one of:\n" );
383 std::map
<std::string
,Backend::Factory
*>::iterator iter
;
384 for (iter
= Backend::Factory::map_begin(); iter
!= Backend::Factory::map_end(); iter
++)
386 Backend::Factory
*factory
= iter
->second
;
387 printf ( " %-10s %s\n", factory
->Name(), factory
->Description());
393 if ( RootXmlFile
.length () == 0 )
394 throw MissingArgumentException ( "-r" );
396 string
projectFilename ( RootXmlFile
);
398 printf ( "Reading build files..." );
399 Project
project ( configuration
, projectFilename
, &properties
);
402 project
.SetBackend ( Backend::Factory::Create (
407 project
.ExecuteInvocations ();
408 project
.GetBackend().Process();
412 catch ( Exception
& ex
)
414 printf ( "%s\n", (*ex
).c_str () );
417 catch ( XMLException
& ex
)
419 printf ( "%s\n", (*ex
).c_str () );