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
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include "backend/backend.h"
30 #include "backend/mingw/mingw.h"
35 static string BuildSystem
;
36 static string RootXmlFile
;
37 static Configuration configuration
;
40 ParseAutomaticDependencySwitch (
44 switch ( switchChar2
)
47 configuration
.AutomaticDependencies
= false;
50 if ( strlen ( switchStart
) <= 3 )
52 printf ( "Switch -dm requires a module name\n" );
55 configuration
.CheckDependenciesForModuleOnly
= true;
56 configuration
.CheckDependenciesForModuleOnlyModule
= string(&switchStart
[3]);
59 printf ( "Unknown switch -d%c\n",
67 ParseCompilationUnitSwitch (
71 switch ( switchChar2
)
74 configuration
.CompilationUnitsEnabled
= false;
77 printf ( "Unknown switch -u%c\n",
85 ParseVCProjectSwitch (
91 switch ( switchChar2
)
94 if ( strlen ( switchStart
) <= 3 )
96 printf ( "Switch -dm requires a module name\n" );
99 configuration
.VSProjectVersion
= string(&switchStart
[3]);
101 if (configuration
.VSProjectVersion
.at(0) == '{') {
102 printf ( "Error: invalid char {\n" );
106 if (configuration
.VSProjectVersion
.length() == 1) //7,8
107 configuration
.VSProjectVersion
.append(".00");
109 if (configuration
.VSProjectVersion
.length() == 3) //7.1
110 configuration
.VSProjectVersion
.append("0");
114 configuration
.VSConfigurationType
= string (&switchStart
[3]);
115 configuration
.InstallFiles
= true;
118 if ( strlen ( switchStart
) <= 3 )
120 printf ( "Invalid switch\n" );
123 temp
= string (&switchStart
[3]);
124 if ( temp
.find ("configuration") != string::npos
)
125 configuration
.UseConfigurationInPath
= true;
127 if ( temp
.find ("version") != string::npos
)
128 configuration
.UseVSVersionInPath
= true;
131 printf ( "Unknown switch -d%c\n",
139 ParseMakeSwitch ( char switchChar2
)
141 switch ( switchChar2
)
144 configuration
.MakeHandlesInstallDirectories
= true;
147 printf ( "Unknown switch -m%c\n",
155 ParseProxyMakefileSwitch ( char switchChar2
)
157 switch ( switchChar2
)
160 configuration
.GenerateProxyMakefilesInSourceTree
= true;
163 printf ( "Unknown switch -p%c\n",
171 ParseSwitch ( int argc
, char** argv
, int index
)
173 char switchChar
= strlen ( argv
[index
] ) > 1 ? argv
[index
][1] : ' ';
174 char switchChar2
= strlen ( argv
[index
] ) > 2 ? argv
[index
][2] : ' ';
175 switch ( switchChar
)
178 if (switchChar2
== 's' || switchChar2
== 'c' || switchChar2
== 'o')
180 return ParseVCProjectSwitch (
185 configuration
.Verbose
= true;
188 configuration
.CleanAsYouGo
= true;
191 return ParseAutomaticDependencySwitch (
195 return ParseCompilationUnitSwitch (
199 RootXmlFile
= string(&argv
[index
][2]);
202 return ParseMakeSwitch ( switchChar2
);
204 return ParseProxyMakefileSwitch ( switchChar2
);
207 "Unknown switch -%c\n",
215 ParseArguments ( int argc
, char** argv
)
220 for ( int i
= 1; i
< argc
; i
++ )
222 if ( argv
[i
][0] == '-' )
224 if ( !ParseSwitch ( argc
, argv
, i
) )
228 BuildSystem
= argv
[i
];
235 main ( int argc
, char** argv
)
237 InitializeEnvironment ();
239 if ( !ParseArguments ( argc
, argv
) )
241 printf ( "Generates project files for buildsystems\n\n" );
242 printf ( " rbuild [switches] -r{rootfile.rbuild} buildsystem\n\n" );
243 printf ( "Switches:\n" );
244 printf ( " -v Be verbose.\n" );
245 printf ( " -c Clean as you go. Delete generated files as soon as they are not\n" );
246 printf ( " needed anymore.\n" );
247 printf ( " -dd Disable automatic dependencies.\n" );
248 printf ( " -dm{module} Check only automatic dependencies for this module.\n" );
249 printf ( " -ud Disable multiple source files per compilation unit.\n" );
250 printf ( " -mi Let make handle creation of install directories. Rbuild will\n" );
251 printf ( " not generate the directories.\n" );
252 printf ( " -ps Generate proxy makefiles in source tree instead of the output.\n" );
253 printf ( " tree.\n" );
254 printf ( " -vs{version} Version of MS VS project files. Default is %s.\n", MS_VS_DEF_VERSION
);
255 printf ( " -vo{version|configuration} Adds subdirectory path to the default Intermediate-Outputdirectory.\n" );
257 printf ( " buildsystem Target build system. Can be one of:\n" );
259 std::map
<std::string
,Backend::Factory
*>::iterator iter
;
260 for (iter
= Backend::Factory::map_begin(); iter
!= Backend::Factory::map_end(); iter
++)
262 Backend::Factory
*factory
= iter
->second
;
263 printf ( " %-10s %s\n", factory
->Name(), factory
->Description());
269 if ( RootXmlFile
.length () == 0 )
270 throw MissingArgumentException ( "-r" );
272 string
projectFilename ( RootXmlFile
);
274 printf ( "Reading build files..." );
275 Project
project ( configuration
, projectFilename
);
278 project
.SetBackend ( Backend::Factory::Create (
283 project
.WriteConfigurationFile ();
284 project
.ExecuteInvocations ();
285 project
.GetBackend().Process();
289 catch ( Exception
& ex
)
291 printf ( "%s\n", (*ex
).c_str () );
294 catch ( XMLException
& ex
)
296 printf ( "%s\n", (*ex
).c_str () );