-
+/*
+ * Copyright (C) 2005 Casper S. Hornstrup
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
#include "pch.h"
#include <assert.h>
using std::string;
using std::vector;
+/* static */ string
+Environment::GetVariable ( const string& name )
+{
+ char* value = getenv ( name.c_str () );
+ if ( value != NULL && strlen ( value ) > 0 )
+ return ssprintf ( "%s",
+ value );
+ else
+ return "";
+}
+
+/* static */ string
+Environment::GetEnvironmentVariablePathOrDefault ( const string& name,
+ const string& defaultValue )
+{
+ const string& environmentVariableValue = Environment::GetVariable ( name );
+ if ( environmentVariableValue.length () > 0 )
+ return NormalizeFilename ( environmentVariableValue );
+ else
+ return defaultValue;
+}
+
+/* static */ string
+Environment::GetIntermediatePath ()
+{
+ return GetEnvironmentVariablePathOrDefault ( "ROS_INTERMEDIATE",
+ "obj-i386" );
+}
+
+/* static */ string
+Environment::GetOutputPath ()
+{
+ return GetEnvironmentVariablePathOrDefault ( "ROS_OUTPUT",
+ "output-i386" );
+}
+
+/* static */ string
+Environment::GetInstallPath ()
+{
+ return GetEnvironmentVariablePathOrDefault ( "ROS_INSTALL",
+ "reactos" );
+}
+
+
Project::Project ( const string& filename )
: xmlfile (filename),
node (NULL),
return NULL;
}
-void
-Project::WriteIfChanged ( char* outbuf,
- string filename )
+string
+Project::ResolveNextProperty ( string& s ) const
{
- FILE* out;
- unsigned int end;
- char* cmpbuf;
- unsigned int stat;
-
- out = fopen ( filename.c_str (), "rb" );
- if ( out == NULL )
- {
- out = fopen ( filename.c_str (), "wb" );
- if ( out == NULL )
- throw AccessDeniedException ( filename );
- fputs ( outbuf, out );
- fclose ( out );
- return;
- }
-
- fseek ( out, 0, SEEK_END );
- end = ftell ( out );
- cmpbuf = (char*) malloc ( end );
- if ( cmpbuf == NULL )
+ size_t i = s.find ( "${" );
+ if ( i == string::npos )
+ i = s.find ( "$(" );
+ if ( i != string::npos )
{
- fclose ( out );
- throw OutOfMemoryException ();
- }
-
- fseek ( out, 0, SEEK_SET );
- stat = fread ( cmpbuf, 1, end, out );
- if ( stat != end )
- {
- free ( cmpbuf );
- fclose ( out );
- throw AccessDeniedException ( filename );
- }
- if ( end == strlen ( outbuf ) && memcmp ( cmpbuf, outbuf, end ) == 0 )
- {
- free ( cmpbuf );
- fclose ( out );
- return;
- }
-
- free ( cmpbuf );
- fclose ( out );
- out = fopen ( filename.c_str (), "wb" );
- if ( out == NULL )
- {
- throw AccessDeniedException ( filename );
- }
-
- stat = fwrite ( outbuf, 1, strlen ( outbuf ), out);
- if ( strlen ( outbuf ) != stat )
- {
- fclose ( out );
- throw AccessDeniedException ( filename );
+ string endCharacter;
+ if ( s[i + 1] == '{' )
+ endCharacter = "}";
+ else
+ endCharacter = ")";
+ size_t j = s.find ( endCharacter );
+ if ( j != string::npos )
+ {
+ int propertyNameLength = j - i - 2;
+ string propertyName = s.substr ( i + 2, propertyNameLength );
+ const Property* property = LookupProperty ( propertyName );
+ if ( property != NULL )
+ return s.replace ( i, propertyNameLength + 3, property->value );
+ }
}
+ return s;
+}
- fclose ( out );
+string
+Project::ResolveProperties ( const string& s ) const
+{
+ string s2 = s;
+ string s3;
+ do
+ {
+ s3 = s2;
+ s2 = ResolveNextProperty ( s3 );
+ } while ( s2 != s3 );
+ return s2;
}
void
Project::SetConfigurationOption ( char* s,
- string name,
- string* alternativeName )
+ string name,
+ string* alternativeName )
{
const Property* property = LookupProperty ( name );
if ( property != NULL && property->value.length () > 0 )
s = s + sprintf ( s, "#endif /* __INCLUDE_CONFIG_H */\n" );
- WriteIfChanged ( buf, "include" SSEP "roscfg.h" );
+ FileSupportCode::WriteIfChanged ( buf, "include" + sSep + "roscfg.h" );
free ( buf );
}
}
}
+ if (node == NULL)
+ node = head->subElements[0];
+
throw InvalidBuildFileException (
node->location,
"Document contains no 'project' tag." );
}
else if ( e.name == "include" )
{
- Include* include = new Include ( *this, e );
+ Include* include = new Include ( *this, &e );
if ( pIf )
pIf->data.includes.push_back ( include );
else
non_if_data.ifs.push_back ( pIf );
subs_invalid = false;
}
+ else if ( e.name == "ifnot" )
+ {
+ If* pOldIf = pIf;
+ pIf = new If ( e, *this, NULL, true );
+ if ( pOldIf )
+ pOldIf->data.ifs.push_back ( pIf );
+ else
+ non_if_data.ifs.push_back ( pIf );
+ subs_invalid = false;
+ }
else if ( e.name == "property" )
{
Property* property = new Property ( e, *this, NULL );