DueTime.QuadPart = -(LONGLONG)IP_TIMEOUT * 10000;
KeSetTimerEx(&IPTimer, DueTime, IP_TIMEOUT, &IPTimeoutDpc);
- PREPARE_TESTS
-
return STATUS_SUCCESS;
}
break;
}
- PREPARE_TESTS
-
return TRUE;
}
CreateStockObjects();
CreateSysColorObjects();
- PREPARE_TESTS
-
return STATUS_SUCCESS;
}
GenerateHeader ();\r
GenerateGlobalVariables ();\r
GenerateAllTarget ();\r
+ GenerateInitTarget ();\r
for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )\r
{\r
Module& module = *ProjectNode.modules[i];\r
fprintf ( fMakefile, "host_ar = ar\n" );\r
fprintf ( fMakefile, "host_objcopy = objcopy\n" );\r
#ifdef WIN32\r
+ fprintf ( fMakefile, "nmkdir = mkdir\n" );\r
fprintf ( fMakefile, "rm = del /f /q\n" );\r
fprintf ( fMakefile, "gcc = gcc\n" );\r
fprintf ( fMakefile, "gpp = g++\n" );\r
fprintf ( fMakefile, "dlltool = dlltool\n" );\r
fprintf ( fMakefile, "windres = windres\n" );\r
#else\r
+ fprintf ( fMakefile, "nmkdir = mkdir -p\n" );\r
fprintf ( fMakefile, "rm = rm -f\n" );\r
fprintf ( fMakefile, "gcc = mingw32-gcc\n" );\r
fprintf ( fMakefile, "gpp = mingw32-g++\n" );\r
fprintf ( fMakefile, "\n\t\n\n" );\r
}\r
\r
+string\r
+MingwBackend::GetBuildToolDependencies () const\r
+{\r
+ string dependencies;\r
+ for ( size_t i = 0; i < ProjectNode.modules.size (); i++ )\r
+ {\r
+ Module& module = *ProjectNode.modules[i];\r
+ if ( module.type == BuildTool )\r
+ {\r
+ if ( dependencies.length () > 0 )\r
+ dependencies += " ";\r
+ dependencies += module.GetDependencyPath ();\r
+ }\r
+ }\r
+ return dependencies;\r
+}\r
+ \r
+void\r
+MingwBackend::GenerateInitTarget () const\r
+{\r
+ fprintf ( fMakefile,\r
+ "init:");\r
+ fprintf ( fMakefile,\r
+ " $(ROS_INTERMEDIATE)." SSEP "tools" );\r
+ fprintf ( fMakefile,\r
+ " %s",\r
+ GetBuildToolDependencies ().c_str () );\r
+ fprintf ( fMakefile,\r
+ " %s",\r
+ "include" SSEP "reactos" SSEP "buildno.h" );\r
+ fprintf ( fMakefile,\r
+ "\n\t\n\n" );\r
+\r
+ fprintf ( fMakefile,\r
+ "$(ROS_INTERMEDIATE)." SSEP "tools:\n" );\r
+ fprintf ( fMakefile,\r
+ "ifneq ($(ROS_INTERMEDIATE),)\n" );\r
+ fprintf ( fMakefile,\r
+ "\t${nmkdir} $(ROS_INTERMEDIATE)\n" );\r
+ fprintf ( fMakefile,\r
+ "endif\n" );\r
+ fprintf ( fMakefile,\r
+ "\t${nmkdir} $(ROS_INTERMEDIATE)." SSEP "tools\n" );\r
+ fprintf ( fMakefile,\r
+ "\n" );\r
+}\r
+\r
void\r
MingwBackend::CheckAutomaticDependencies ()\r
{\r
void GenerateGlobalVariables () const;\r
bool IncludeInAllTarget ( const Module& module ) const;\r
void GenerateAllTarget () const;\r
+ std::string GetBuildToolDependencies () const;\r
+ void GenerateInitTarget () const;\r
void CheckAutomaticDependencies ();\r
FILE* fMakefile;\r
};\r
return objectFilenames;\r
}\r
\r
+bool\r
+MingwModuleHandler::IncludeDirectoryTarget ( const string& directory ) const\r
+{\r
+ if ( directory == "$(ROS_INTERMEDIATE)." SSEP "tools")\r
+ return false;\r
+ else\r
+ return true;\r
+}\r
+\r
void\r
MingwModuleHandler::GenerateDirectoryTargets () const\r
{\r
i != directory_set.end ();\r
i++ )\r
{\r
- fprintf ( fMakefile, " %s", i->c_str () );\r
+ if ( IncludeDirectoryTarget ( *i ) )\r
+ {\r
+ fprintf ( fMakefile,\r
+ " %s",\r
+ i->c_str () );\r
+ }\r
}\r
\r
fprintf ( fMakefile, "\n\n" );\r
i != directory_set.end ();\r
i++ )\r
{\r
- fprintf ( fMakefile, "%s ", i->c_str () );\r
+ if ( IncludeDirectoryTarget ( *i ) )\r
+ {\r
+ fprintf ( fMakefile,\r
+ "%s ",\r
+ i->c_str () );\r
+ }\r
}\r
\r
fprintf ( fMakefile, \r
return dependencies;\r
}\r
\r
-string\r
-MingwModuleHandler::GetInvocationParameters ( const Invoke& invoke ) const\r
-{\r
- string parameters ( "" );\r
- size_t i;\r
- for (i = 0; i < invoke.output.size (); i++)\r
- {\r
- if (parameters.length () > 0)\r
- parameters += " ";\r
- InvokeFile& invokeFile = *invoke.output[i];\r
- if (invokeFile.switches.length () > 0)\r
- {\r
- parameters += invokeFile.switches;\r
- parameters += " ";\r
- }\r
- parameters += invokeFile.name;\r
- }\r
-\r
- for (i = 0; i < invoke.input.size (); i++)\r
- {\r
- if (parameters.length () > 0)\r
- parameters += " ";\r
- InvokeFile& invokeFile = *invoke.input[i];\r
- if (invokeFile.switches.length () > 0)\r
- {\r
- parameters += invokeFile.switches;\r
- parameters += " ";\r
- }\r
- parameters += invokeFile.name ;\r
- }\r
-\r
- return parameters;\r
-}\r
-\r
void\r
MingwModuleHandler::GenerateInvocations ( const Module& module ) const\r
{\r
fprintf ( fMakefile,\r
"\t%s %s\n\n",\r
FixupTargetFilename ( invoke.invokeModule->GetPath () ).c_str (),\r
- GetInvocationParameters ( invoke ).c_str () );\r
+ invoke.GetParameters ().c_str () );\r
}\r
}\r
\r
module.name.c_str () );\r
}\r
\r
+string\r
+MingwModuleHandler::GetDefaultDependencies ( const Module& module ) const\r
+{\r
+ /* Avoid circular dependency */\r
+ if ( module.type == BuildTool || module.name == "zlib" )\r
+ return "$(ROS_INTERMEDIATE)." SSEP "tools $(ROS_INTERMEDIATE)." SSEP "lib" SSEP "zlib";\r
+ else\r
+ return "init";\r
+}\r
+\r
void\r
MingwModuleHandler::GeneratePreconditionDependencies ( const Module& module ) const\r
{\r
string preconditionDependenciesName = GetPreconditionDependenciesName ( module );\r
string sourceFilenames = GetSourceFilenamesWithoutGeneratedFiles ( module );\r
- string dependencies = GetModuleDependencies ( module );\r
- string s = GetInvocationDependencies ( module );\r
+ string dependencies = GetDefaultDependencies ( module );\r
+ string s = GetModuleDependencies ( module );\r
+ if ( s.length () > 0 )\r
+ {\r
+ if ( dependencies.length () > 0 )\r
+ dependencies += " ";\r
+ dependencies += s;\r
+ }\r
+\r
+ s = GetInvocationDependencies ( module );\r
if ( s.length () > 0 )\r
{\r
if ( dependencies.length () > 0 )\r
MingwModuleHandler::GetDefinitionDependencies ( const Module& module ) const\r
{\r
string dependencies;\r
+ string dkNkmLibNoFixup = "dk/nkm/lib";\r
+ dependencies += FixupTargetFilename ( dkNkmLibNoFixup );\r
+ PassThruCacheDirectory ( dkNkmLibNoFixup + SSEP );\r
for ( size_t i = 0; i < module.files.size (); i++ )\r
{\r
File& file = *module.files[i];\r
static MingwModuleHandler* LookupHandler ( const std::string& location,\r
ModuleType moduletype_ );\r
virtual void Process ( const Module& module ) = 0;\r
+ bool IncludeDirectoryTarget ( const std::string& directory ) const;\r
void GenerateDirectoryTargets () const;\r
static std::string GetObjectFilename ( const std::string& sourceFilename );\r
protected:\r
const std::string* cflags,\r
const std::string* nasmflags ) const;\r
std::string GetInvocationDependencies ( const Module& module ) const;\r
- std::string GetInvocationParameters ( const Invoke& invoke ) const;\r
void GenerateInvocations ( const Module& module ) const;\r
\r
std::string GetPreconditionDependenciesName ( const Module& module ) const;\r
const std::string* clags,\r
const std::string* nasmflags ) const;\r
std::string GetSpecObjectDependencies ( const std::string& filename ) const;\r
+ std::string GetDefaultDependencies ( const Module& module ) const;\r
};\r
\r
\r
}\r
\r
\r
+OutOfMemoryException::OutOfMemoryException ()\r
+ : Exception ( "Out of memory" )\r
+{\r
+}\r
+\r
+\r
InvalidOperationException::InvalidOperationException ( const char* filename,\r
const int linenumber )\r
{\r
{\r
}\r
\r
+\r
UnknownModuleTypeException::UnknownModuleTypeException ( const string& location,\r
int moduletype )\r
: InvalidBuildFileException ( location,\r
moduletype )\r
{\r
}\r
+\r
+\r
+InvocationFailedException::InvocationFailedException ( const std::string& command,\r
+ int exitcode )\r
+ : Exception ( "Failed to execute '%s' (exit code %d)",\r
+ command.c_str (),\r
+ exitcode )\r
+{\r
+ Command = command;\r
+ ExitCode = exitcode;\r
+}\r
};\r
\r
\r
+class OutOfMemoryException : public Exception\r
+{\r
+public:\r
+ OutOfMemoryException ();\r
+};\r
+\r
+\r
class FileNotFoundException : public Exception\r
{\r
public:\r
int moduletype );\r
};\r
\r
+\r
+class InvocationFailedException : public Exception\r
+{\r
+public:\r
+ InvocationFailedException ( const std::string& command,\r
+ int exitcode );\r
+ std::string Command;\r
+ int ExitCode;\r
+};\r
+\r
#endif /* __EXCEPTION_H */\r
return false;\r
}\r
\r
+void\r
+Module::InvokeModule () const\r
+{\r
+ for ( size_t i = 0; i < invocations.size (); i++ )\r
+ {\r
+ Invoke& invoke = *invocations[i];\r
+ string command = invoke.invokeModule->GetPath () + " " + invoke.GetParameters ();\r
+ printf ( "Executing '%s'\n\n", command.c_str () );\r
+ int exitcode = system ( command.c_str () );\r
+ if ( exitcode != 0 )\r
+ throw InvocationFailedException ( command,\r
+ exitcode );\r
+ }\r
+}\r
+\r
\r
File::File ( const string& _name, bool _first )\r
: name(_name), first(_first)\r
return targets;\r
}\r
\r
+string\r
+Invoke::GetParameters () const\r
+{\r
+ string parameters ( "" );\r
+ size_t i;\r
+ for ( i = 0; i < output.size (); i++ )\r
+ {\r
+ if ( parameters.length () > 0)\r
+ parameters += " ";\r
+ InvokeFile& invokeFile = *output[i];\r
+ if ( invokeFile.switches.length () > 0 )\r
+ {\r
+ parameters += invokeFile.switches;\r
+ parameters += " ";\r
+ }\r
+ parameters += invokeFile.name;\r
+ }\r
+\r
+ for ( i = 0; i < input.size (); i++ )\r
+ {\r
+ if ( parameters.length () > 0 )\r
+ parameters += " ";\r
+ InvokeFile& invokeFile = *input[i];\r
+ if ( invokeFile.switches.length () > 0 )\r
+ {\r
+ parameters += invokeFile.switches;\r
+ parameters += " ";\r
+ }\r
+ parameters += invokeFile.name ;\r
+ }\r
+\r
+ return parameters;\r
+}\r
+\r
\r
InvokeFile::InvokeFile ( const XMLElement& _node,\r
const string& _name )\r
using std::string;\r
using std::vector;\r
\r
-/*Project::Project()\r
- : node(NULL), head(NULL)\r
-{\r
-}*/\r
-\r
Project::Project ( const string& filename )\r
- : xmlfile(filename),\r
- node(NULL),\r
- head(NULL)\r
+ : xmlfile (filename),\r
+ node (NULL),\r
+ head (NULL)\r
{\r
ReadXml();\r
}\r
size_t i;\r
for ( i = 0; i < modules.size (); i++ )\r
delete modules[i];\r
- for ( i = 0; i < includes.size(); i++ )\r
+ for ( i = 0; i < includes.size (); i++ )\r
delete includes[i];\r
- for ( i = 0; i < defines.size(); i++ )\r
+ for ( i = 0; i < defines.size (); i++ )\r
delete defines[i];\r
- for ( i = 0; i < linkerFlags.size(); i++ )\r
+ for ( i = 0; i < linkerFlags.size (); i++ )\r
delete linkerFlags[i];\r
- for ( i = 0; i < properties.size(); i++ )\r
+ for ( i = 0; i < properties.size (); i++ )\r
delete properties[i];\r
- for ( i = 0; i < ifs.size(); i++ )\r
+ for ( i = 0; i < ifs.size (); i++ )\r
delete ifs[i];\r
delete head;\r
}\r
\r
+const Property*\r
+Project::LookupProperty ( const string& name ) const\r
+{\r
+ for ( size_t i = 0; i < properties.size (); i++ )\r
+ {\r
+ const Property* property = properties[i];\r
+ if ( property->name == name )\r
+ return property;\r
+ }\r
+ return NULL;\r
+}\r
+\r
+void\r
+Project::WriteIfChanged ( char* outbuf,\r
+ string filename )\r
+{\r
+ FILE* out;\r
+ unsigned int end;\r
+ char* cmpbuf;\r
+ unsigned int stat;\r
+ \r
+ out = fopen ( filename.c_str (), "rb" );\r
+ if ( out == NULL )\r
+ {\r
+ out = fopen ( filename.c_str (), "wb" );\r
+ if ( out == NULL )\r
+ throw AccessDeniedException ( filename );\r
+ fputs ( outbuf, out );\r
+ fclose ( out );\r
+ return;\r
+ }\r
+ \r
+ fseek ( out, 0, SEEK_END );\r
+ end = ftell ( out );\r
+ cmpbuf = (char*) malloc ( end );\r
+ if ( cmpbuf == NULL )\r
+ {\r
+ fclose ( out );\r
+ throw OutOfMemoryException ();\r
+ }\r
+ \r
+ fseek ( out, 0, SEEK_SET );\r
+ stat = fread ( cmpbuf, 1, end, out );\r
+ if ( stat != end )\r
+ {\r
+ free ( cmpbuf );\r
+ fclose ( out );\r
+ throw AccessDeniedException ( filename );\r
+ }\r
+ if ( end == strlen ( outbuf ) && memcmp ( cmpbuf, outbuf, end ) == 0 )\r
+ {\r
+ free ( cmpbuf );\r
+ fclose ( out );\r
+ return;\r
+ }\r
+ \r
+ free ( cmpbuf );\r
+ fclose ( out );\r
+ out = fopen ( filename.c_str (), "wb" );\r
+ if ( out == NULL )\r
+ {\r
+ throw AccessDeniedException ( filename );\r
+ }\r
+ \r
+ stat = fwrite ( outbuf, 1, strlen ( outbuf ), out);\r
+ if ( strlen ( outbuf ) != stat )\r
+ {\r
+ fclose ( out );\r
+ throw AccessDeniedException ( filename );\r
+ }\r
+\r
+ fclose ( out );\r
+}\r
+\r
void\r
-Project::ReadXml()\r
+Project::SetConfigurationOption ( char* s,\r
+ string name,\r
+ string* alternativeName )\r
+{\r
+ const Property* property = LookupProperty ( name );\r
+ if ( property != NULL && property->value.length () > 0 )\r
+ {\r
+ s = s + sprintf ( s,\r
+ "#define %s=%s\n",\r
+ property->name.c_str (),\r
+ property->value.c_str () );\r
+ }\r
+ else if ( property != NULL )\r
+ {\r
+ s = s + sprintf ( s,\r
+ "#define %s\n",\r
+ property->name.c_str () );\r
+ }\r
+ else if ( alternativeName != NULL )\r
+ {\r
+ s = s + sprintf ( s,\r
+ "#define %s\n",\r
+ alternativeName->c_str () );\r
+ }\r
+}\r
+\r
+void\r
+Project::SetConfigurationOption ( char* s,\r
+ string name )\r
+{\r
+ SetConfigurationOption ( s, name, NULL );\r
+}\r
+\r
+void\r
+Project::WriteConfigurationFile ()\r
+{\r
+ char* buf;\r
+ char* s;\r
+\r
+ buf = (char*) malloc ( 10*1024 );\r
+ if ( buf == NULL )\r
+ throw OutOfMemoryException ();\r
+ \r
+ s = buf;\r
+ s = s + sprintf ( s, "/* Automatically generated. " );\r
+ s = s + sprintf ( s, "Edit config.xml to change configuration */\n" );\r
+ s = s + sprintf ( s, "#ifndef __INCLUDE_CONFIG_H\n" );\r
+ s = s + sprintf ( s, "#define __INCLUDE_CONFIG_H\n" );\r
+\r
+ SetConfigurationOption ( s, "ARCH" );\r
+ SetConfigurationOption ( s, "OPTIMIZED" );\r
+ SetConfigurationOption ( s, "MP", new string ( "UP" ) );\r
+ SetConfigurationOption ( s, "ACPI" );\r
+ SetConfigurationOption ( s, "_3GB" );\r
+\r
+ s = s + sprintf ( s, "#endif /* __INCLUDE_CONFIG_H */\n" );\r
+\r
+ WriteIfChanged ( buf, "include" SSEP "roscfg.h" );\r
+\r
+ free ( buf );\r
+}\r
+\r
+void\r
+Project::ExecuteInvocations ()\r
+{\r
+ for ( size_t i = 0; i < modules.size (); i++ )\r
+ modules[i]->InvokeModule ();\r
+}\r
+\r
+void\r
+Project::ReadXml ()\r
{\r
Path path;\r
head = XMLLoadFile ( xmlfile, path );\r
node = NULL;\r
- for ( size_t i = 0; i < head->subElements.size(); i++ )\r
+ for ( size_t i = 0; i < head->subElements.size (); i++ )\r
{\r
if ( head->subElements[i]->name == "project" )\r
{\r
{\r
for ( size_t i = 0; i < modules.size (); i++ )\r
{\r
- if (modules[i]->name == name)\r
+ if ( modules[i]->name == name )\r
return modules[i];\r
}\r
\r
{\r
string projectFilename ( "ReactOS.xml" );\r
Project project ( projectFilename );\r
+ project.WriteConfigurationFile ();\r
+ project.ExecuteInvocations ();\r
Backend* backend = Backend::Factory::Create ( buildtarget,\r
project );\r
backend->Process ();\r
#include <sys/utime.h>\r
#else\r
#include <utime.h>\r
+#include <process.h>\r
#endif\r
\r
#include "ssprintf.h"\r
\r
Project ( const std::string& filename );\r
~Project ();\r
+ void WriteConfigurationFile ();\r
+ void ExecuteInvocations ();\r
void ProcessXML ( const std::string& path );\r
Module* LocateModule ( const std::string& name );\r
const Module* LocateModule ( const std::string& name ) const;\r
private:\r
+ const Property* LookupProperty ( const std::string& name ) const;\r
+ void SetConfigurationOption ( char* s,\r
+ std::string name,\r
+ std::string* alternativeName );\r
+ void SetConfigurationOption ( char* s,\r
+ std::string name );\r
+ void WriteIfChanged ( char* outbuf,\r
+ std::string filename );\r
void ReadXml ();\r
void ProcessXMLSubElement ( const XMLElement& e,\r
const std::string& path,\r
std::string GetInvocationTarget ( const int index ) const;\r
bool HasFileWithExtensions ( const std::string& extension1,\r
const std::string& extension2 ) const;\r
- void ProcessXML();\r
+ void InvokeModule () const;\r
+ void ProcessXML ();\r
private:\r
std::string GetDefaultModuleExtension () const;\r
std::string GetDefaultModuleEntrypoint () const;\r
\r
void ProcessXML();\r
std::string GetTargets () const;\r
+ std::string GetParameters () const;\r
private:\r
void ProcessXMLSubElement ( const XMLElement& e );\r
void ProcessXMLSubElementInput ( const XMLElement& e );\r