* KernelModeDriver module support
* Build afd.sys
Modified: branches/xmlbuildsystem/reactos/ReactOS.xml
Modified: branches/xmlbuildsystem/reactos/drivers/directory.xml
Added: branches/xmlbuildsystem/reactos/drivers/net/afd/afd.xml
Added: branches/xmlbuildsystem/reactos/drivers/net/directory.xml
Modified: branches/xmlbuildsystem/reactos/include/ndis.h
Modified: branches/xmlbuildsystem/reactos/ntoskrnl/ntoskrnl.xml
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler.cpp
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler.h
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/include.cpp
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/module.cpp
Modified: branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h

Modified: branches/xmlbuildsystem/reactos/ReactOS.xml
--- branches/xmlbuildsystem/reactos/ReactOS.xml	2005-01-16 11:52:30 UTC (rev 13077)
+++ branches/xmlbuildsystem/reactos/ReactOS.xml	2005-01-16 13:51:33 UTC (rev 13078)
@@ -19,6 +19,7 @@
 
 	<include>include</include>
 	<include>w32api/include</include>
+	<include>w32api/include/ddk</include>
 
 	<directory name="drivers">
 		<xi:include href="drivers/directory.xml" />

Modified: branches/xmlbuildsystem/reactos/drivers/directory.xml
--- branches/xmlbuildsystem/reactos/drivers/directory.xml	2005-01-16 11:52:30 UTC (rev 13077)
+++ branches/xmlbuildsystem/reactos/drivers/directory.xml	2005-01-16 13:51:33 UTC (rev 13078)
@@ -1,3 +1,6 @@
 <directory name="lib">
 	<xi:include href="lib/directory.xml" />
-</directory>
\ No newline at end of file
+</directory>
+<directory name="net">
+	<xi:include href="net/directory.xml" />
+</directory>

Added: branches/xmlbuildsystem/reactos/drivers/net/afd/afd.xml
--- branches/xmlbuildsystem/reactos/drivers/net/afd/afd.xml	2005-01-16 11:52:30 UTC (rev 13077)
+++ branches/xmlbuildsystem/reactos/drivers/net/afd/afd.xml	2005-01-16 13:51:33 UTC (rev 13078)
@@ -0,0 +1,24 @@
+<module name="afd" type="kernelmodedriver">
+	<importlibrary definition="afd.def" />
+	<include base="afd">include</include>
+	<include base="ReactOS">include/afd</include>
+	<define name="__USE_W32API" />
+	<library>ntoskrnl</library>
+	<library>hal</library>
+	<library>pseh</library>
+	<directory name="afd">
+		<file>bind.c</file>
+		<file>connect.c</file>
+		<file>context.c</file>
+		<file>info.c</file>
+		<file>listen.c</file>
+		<file>lock.c</file>
+		<file>main.c</file>
+		<file>read.c</file>
+		<file>select.c</file>
+		<file>tdi.c</file>
+		<file>tdiconn.c</file>
+		<file>write.c</file>
+	</directory>
+	<file>afd.rc</file>
+</module>

Added: branches/xmlbuildsystem/reactos/drivers/net/directory.xml
--- branches/xmlbuildsystem/reactos/drivers/net/directory.xml	2005-01-16 11:52:30 UTC (rev 13077)
+++ branches/xmlbuildsystem/reactos/drivers/net/directory.xml	2005-01-16 13:51:33 UTC (rev 13078)
@@ -0,0 +1,3 @@
+<directory name="afd">
+	<xi:include href="afd/afd.xml" />
+</directory>

Modified: branches/xmlbuildsystem/reactos/include/ndis.h
--- branches/xmlbuildsystem/reactos/include/ndis.h	2005-01-16 11:52:30 UTC (rev 13077)
+++ branches/xmlbuildsystem/reactos/include/ndis.h	2005-01-16 13:51:33 UTC (rev 13078)
@@ -1 +1,5 @@
+#ifdef __USE_W32API
+#include_next <ndis.h>
+#else
 #include "net/ndis.h"
+#endif

Modified: branches/xmlbuildsystem/reactos/ntoskrnl/ntoskrnl.xml
--- branches/xmlbuildsystem/reactos/ntoskrnl/ntoskrnl.xml	2005-01-16 11:52:30 UTC (rev 13077)
+++ branches/xmlbuildsystem/reactos/ntoskrnl/ntoskrnl.xml	2005-01-16 13:51:33 UTC (rev 13078)
@@ -1,4 +1,5 @@
 <module name="ntoskrnl" type="kernel">
+	<importlibrary definition="ntoskrnl.def" />
 	<dependency>buildno</dependency>
 	<dependency>genntdll</dependency>
 	<dependency>wmc</dependency>

Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler.cpp
--- branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler.cpp	2005-01-16 11:52:30 UTC (rev 13077)
+++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler.cpp	2005-01-16 13:51:33 UTC (rev 13078)
@@ -641,6 +641,13 @@
 }
 
 string
+MingwModuleHandler::GetCFlagsMacro ( const Module& module ) const
+{
+	return ssprintf ( "$(%s_CFLAGS)",
+	                  module.name.c_str () );
+}
+
+string
 MingwModuleHandler::GetObjectsMacro ( const Module& module ) const
 {
 	return ssprintf ( "$(%s_OBJS)",
@@ -658,7 +665,8 @@
 MingwModuleHandler::GenerateMacrosAndTargets (
 	const Module& module,
 	const string& cc,
-	const string& ar ) const
+	const string& ar,
+	const string* cflags ) const
 {
 	string cflagsMacro = ssprintf ("%s_CFLAGS", module.name.c_str ());
 	string nasmflagsMacro = ssprintf ("%s_NASMFLAGS", module.name.c_str ());
@@ -673,12 +681,20 @@
 	                linkerFlagsMacro,
 	                objectsMacro );
 
+	if ( cflags != NULL )
+	{
+		fprintf ( fMakefile,
+		          "%s += %s\n\n",
+		          cflagsMacro.c_str (),
+		          cflags->c_str () );
+	}
+	
 	// generate phony target for module name
 	fprintf ( fMakefile, ".PHONY: %s\n",
-		module.name.c_str() );
+		module.name.c_str () );
 	fprintf ( fMakefile, "%s: %s\n\n",
-		module.name.c_str(),
-		module.GetPath().c_str() );
+		module.name.c_str (),
+		module.GetPath ().c_str () );
 
 	// future references to the macros will be to get their values
 	cflagsMacro = ssprintf ("$(%s)", cflagsMacro.c_str ());
@@ -710,15 +726,23 @@
 void
 MingwModuleHandler::GenerateMacrosAndTargetsHost ( const Module& module ) const
 {
-	GenerateMacrosAndTargets ( module, "${host_gcc}", "${host_ar}" );
+	GenerateMacrosAndTargets ( module, "${host_gcc}", "${host_ar}", NULL );
 }
 
 void
 MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module& module ) const
 {
-	GenerateMacrosAndTargets ( module, "${gcc}", "${ar}" );
+	GenerateMacrosAndTargetsTarget ( module,
+	                                 NULL );
 }
 
+void
+MingwModuleHandler::GenerateMacrosAndTargetsTarget ( const Module& module,
+	                                                 const string* clags ) const
+{
+	GenerateMacrosAndTargets ( module, "${gcc}", "${ar}", clags );
+}
+
 string
 MingwModuleHandler::GetInvocationDependencies ( const Module& module ) const
 {
@@ -857,7 +881,23 @@
 	fprintf ( fMakefile, "\n" );
 }
 
+void
+MingwModuleHandler::GenerateImportLibraryTargetIfNeeded ( const Module& module ) const
+{
+	if ( module.importLibrary != NULL )
+	{
+		fprintf ( fMakefile, "%s:\n",
+		          module.GetDependencyPath ().c_str () );
 
+		fprintf ( fMakefile,
+		          "\t${dlltool} --dllname %s --def %s --output-lib %s --kill-at\n\n",
+		          module.GetTargetName ().c_str (),
+		          FixupTargetFilename ( module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),
+		          FixupTargetFilename ( module.GetDependencyPath () ).c_str () );
+	}
+}
+
+
 static MingwBuildToolModuleHandler buildtool_handler;
 
 MingwBuildToolModuleHandler::MingwBuildToolModuleHandler()
@@ -922,6 +962,8 @@
 
 	GenerateMacrosAndTargetsTarget ( module );
 
+	GenerateImportLibraryTargetIfNeeded ( module );
+
 	fprintf ( fMakefile, "%s: %s %s\n",
 	          target.c_str (),
 	          objectsMacro.c_str (),
@@ -1005,21 +1047,68 @@
 	string archiveFilename = GetModuleArchiveFilename ( module );
 	string importLibraryDependencies = GetImportLibraryDependencies ( module );
 
-	if (module.importLibrary != NULL)
+	GenerateImportLibraryTargetIfNeeded ( module );
+
+	if ( module.files.size () > 0 )
 	{
-		fprintf ( fMakefile, "%s:\n",
-		          module.GetDependencyPath ().c_str () );
+		GenerateMacrosAndTargetsTarget ( module );
 
+		fprintf ( fMakefile, "%s: %s %s\n",
+		          target.c_str (),
+		          archiveFilename.c_str (),
+		          importLibraryDependencies.c_str () );
+
+		string linkerParameters ( "-Wl,--subsystem,native -Wl,--entry,_DriverEntry@8 -Wl,--image-base,0x10000 -Wl,--file-alignment,0x1000 -Wl,--section-alignment,0x1000 -nostartfiles -mdll" );
+		string linkerCommand = GenerateLinkerCommand ( module,
+                                                       "${gcc}",
+                                                       linkerParameters,
+                                                       archiveFilename );
 		fprintf ( fMakefile,
-		          "\t${dlltool} --dllname %s --def %s --output-lib %s --kill-at\n\n",
-		          module.GetTargetName ().c_str (),
-		          FixupTargetFilename ( module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),
-		          FixupTargetFilename ( module.GetDependencyPath () ).c_str () );
+		          "\t%s\n\n",
+		          linkerCommand.c_str () );
 	}
+	else
+	{
+		fprintf ( fMakefile, "%s:\n",
+		          target.c_str ());
+		fprintf ( fMakefile, ".PHONY: %s\n\n",
+		          target.c_str ());
+	}
+}
 
-	if (module.files.size () > 0)
+
+static MingwKernelModeDriverModuleHandler kernelmodedriver_handler;
+
+MingwKernelModeDriverModuleHandler::MingwKernelModeDriverModuleHandler ()
+	: MingwModuleHandler ( KernelModeDriver )
+{
+}
+
+void
+MingwKernelModeDriverModuleHandler::Process ( const Module& module )
+{
+	GeneratePreconditionDependencies ( module );
+	GenerateKernelModeDriverModuleTarget ( module );
+	GenerateInvocations ( module );
+}
+
+void
+MingwKernelModeDriverModuleHandler::GenerateKernelModeDriverModuleTarget ( const Module& module )
+{
+	static string ros_junk ( "$(ROS_TEMPORARY)" );
+	string target ( FixupTargetFilename ( module.GetPath () ) );
+	string workingDirectory = GetWorkingDirectory ( );
+	string archiveFilename = GetModuleArchiveFilename ( module );
+	string importLibraryDependencies = GetImportLibraryDependencies ( module );
+
+	GenerateImportLibraryTargetIfNeeded ( module );
+
+	if ( module.files.size () > 0 )
 	{
-		GenerateMacrosAndTargetsTarget ( module );
+		string* cflags = new string ( "-D__NTDRIVER__" );
+		GenerateMacrosAndTargetsTarget ( module,
+		                                 cflags );
+		delete cflags;
 
 		fprintf ( fMakefile, "%s: %s %s\n",
 		          target.c_str (),
@@ -1068,21 +1157,11 @@
 	string workingDirectory = GetWorkingDirectory ( );
 	string archiveFilename = GetModuleArchiveFilename ( module );
 	string importLibraryDependencies = GetImportLibraryDependencies ( module );
+	
+	GenerateImportLibraryTargetIfNeeded ( module );
 
-	if (module.importLibrary != NULL)
+	if ( module.files.size () > 0 )
 	{
-		fprintf ( fMakefile, "%s:\n",
-		          module.GetDependencyPath ().c_str () );
-
-		fprintf ( fMakefile,
-		          "\t${dlltool} --dllname %s --def %s --output-lib %s --kill-at\n\n",
-		          module.GetTargetName ().c_str (),
-		          FixupTargetFilename ( module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),
-		          FixupTargetFilename ( module.GetDependencyPath () ).c_str () );
-	}
-
-	if (module.files.size () > 0)
-	{
 		GenerateMacrosAndTargetsTarget ( module );
 
 		fprintf ( fMakefile, "%s: %s %s\n",
@@ -1133,19 +1212,9 @@
 	string archiveFilename = GetModuleArchiveFilename ( module );
 	string importLibraryDependencies = GetImportLibraryDependencies ( module );
 
-	if (module.importLibrary != NULL)
-	{
-		fprintf ( fMakefile, "%s:\n",
-		          module.GetDependencyPath ().c_str () );
+	GenerateImportLibraryTargetIfNeeded ( module );
 
-		fprintf ( fMakefile,
-		          "\t${dlltool} --dllname %s --def %s --output-lib %s --kill-at\n\n",
-		          module.GetTargetName ().c_str (),
-		          FixupTargetFilename ( module.GetBasePath () + SSEP + module.importLibrary->definition ).c_str (),
-		          FixupTargetFilename ( module.GetDependencyPath () ).c_str () );
-	}
-
-	if (module.files.size () > 0)
+	if ( module.files.size () > 0 )
 	{
 		GenerateMacrosAndTargetsTarget ( module );
 
@@ -1197,7 +1266,9 @@
 	string objectFilenames = GetObjectFilenames ( module );
 	string importLibraryDependencies = GetImportLibraryDependencies ( module );
 
-	if (module.files.size () > 0)
+	GenerateImportLibraryTargetIfNeeded ( module );
+
+	if ( module.files.size () > 0 )
 	{
 		GenerateMacrosAndTargetsTarget ( module );
 

Modified: branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler.h
--- branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler.h	2005-01-16 11:52:30 UTC (rev 13077)
+++ branches/xmlbuildsystem/reactos/tools/rbuild/backend/mingw/modulehandler.h	2005-01-16 13:51:33 UTC (rev 13078)
@@ -32,16 +32,20 @@
 	std::string GetObjectFilenames ( const Module& module ) const;
 	void GenerateMacrosAndTargetsHost ( const Module& module ) const;
 	void GenerateMacrosAndTargetsTarget ( const Module& module ) const;
+	void GenerateMacrosAndTargetsTarget ( const Module& module,
+	                                      const std::string* clags ) const;
 	std::string GetInvocationDependencies ( const Module& module ) const;
 	std::string GetInvocationParameters ( const Invoke& invoke ) const;
 	void GenerateInvocations ( const Module& module ) const;
 	void GeneratePreconditionDependencies ( const Module& module ) const;
+	std::string GetCFlagsMacro ( const Module& module ) const;
 	std::string GetObjectsMacro ( const Module& module ) const;
 	std::string GetLinkerMacro ( const Module& module ) const;
 	std::string GenerateLinkerCommand ( const Module& module,
 	                                    const std::string& linker,
 	                                    const std::string& linkerParameters,
 	                                    const std::string& objectFilenames ) const;
+	void GenerateImportLibraryTargetIfNeeded ( const Module& module ) const;
 	static FILE* fMakefile;
 private:
 	std::string ConcatenatePaths ( const std::string& path1,
@@ -115,7 +119,8 @@
 	                                    const std::string& objs_macro ) const;
 	void GenerateMacrosAndTargets ( const Module& module,
 	                                const std::string& cc,
-	                                const std::string& ar ) const;
+	                                const std::string& ar,
+	                                const std::string* clags ) const;
 	std::string GetPreconditionDependenciesName ( const Module& module ) const;
 };
 
@@ -160,6 +165,16 @@
 };
 
 
+class MingwKernelModeDriverModuleHandler : public MingwModuleHandler
+{
+public:
+	MingwKernelModeDriverModuleHandler ();
+	virtual void Process ( const Module& module );
+private:
+	void GenerateKernelModeDriverModuleTarget ( const Module& module );
+};
+
+
 class MingwNativeDLLModuleHandler : public MingwModuleHandler
 {
 public:

Modified: branches/xmlbuildsystem/reactos/tools/rbuild/include.cpp
--- branches/xmlbuildsystem/reactos/tools/rbuild/include.cpp	2005-01-16 11:52:30 UTC (rev 13077)
+++ branches/xmlbuildsystem/reactos/tools/rbuild/include.cpp	2005-01-16 13:51:33 UTC (rev 13078)
@@ -8,10 +8,9 @@
 
 Include::Include ( const Project& project_,
                    const XMLElement& includeNode )
-	: project(project_),
-	  module(NULL),
-	  node(includeNode),
-	  base(NULL)
+	: project (project_),
+	  module (NULL),
+	  node (includeNode)
 {
 	Initialize();
 }
@@ -19,10 +18,9 @@
 Include::Include ( const Project& project_,
 	               const Module* module_,
 	               const XMLElement& includeNode )
-	: project(project_),
-	  module(module_),
-	  node(includeNode),
-	  base(NULL)
+	: project (project_),
+	  module (module_),
+	  node (includeNode)
 {
 	Initialize();
 }
@@ -48,13 +46,27 @@
 			throw InvalidBuildFileException (
 				node.location,
 				"'base' attribute illegal from global <include>" );
-		base = project.LocateModule ( att->value );
-		if ( !base )
+		bool referenceResolved = false;
+		if ( att->value == project.name )
+		{
+			basePath = ".";
+			referenceResolved = true;
+		}
+		else
+		{
+			const Module* base = project.LocateModule ( att->value );
+			if ( base != NULL )
+			{
+				basePath = base->GetBasePath ();
+				referenceResolved = true;
+			}
+		}
+		if ( !referenceResolved )
 			throw InvalidBuildFileException (
 				node.location,
-				"<include> attribute 'base' references non-existant module '%s'",
+				"<include> attribute 'base' references non-existant project or module '%s'",
 				att->value.c_str() );
-		directory = FixSeparator ( base->GetBasePath() + "/" + node.value );
+		directory = FixSeparator ( basePath + "/" + node.value );
 	}
 	else
 		directory = FixSeparator ( node.value );

Modified: branches/xmlbuildsystem/reactos/tools/rbuild/module.cpp
--- branches/xmlbuildsystem/reactos/tools/rbuild/module.cpp	2005-01-16 11:52:30 UTC (rev 13077)
+++ branches/xmlbuildsystem/reactos/tools/rbuild/module.cpp	2005-01-16 13:51:33 UTC (rev 13078)
@@ -214,6 +214,8 @@
 		return Kernel;
 	if ( attribute.value == "kernelmodedll" )
 		return KernelModeDLL;
+	if ( attribute.value == "kernelmodedriver" )
+		return KernelModeDriver;
 	if ( attribute.value == "nativedll" )
 		return NativeDLL;
 	if ( attribute.value == "win32dll" )
@@ -241,6 +243,8 @@
 		case NativeDLL:
 		case Win32DLL:
 			return ".dll";
+		case KernelModeDriver:
+			return ".sys";
 	}
 	throw InvalidOperationException ( __FILE__,
 	                                  __LINE__ );

Modified: branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h
--- branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h	2005-01-16 11:52:30 UTC (rev 13077)
+++ branches/xmlbuildsystem/reactos/tools/rbuild/rbuild.h	2005-01-16 13:51:33 UTC (rev 13078)
@@ -73,6 +73,7 @@
 	StaticLibrary,
 	Kernel,
 	KernelModeDLL,
+	KernelModeDriver,
 	NativeDLL,
 	Win32DLL,
 	Win32GUI
@@ -128,7 +129,7 @@
 	const Module* module;
 	const XMLElement& node;
 	std::string directory;
-	const Module* base;
+	std::string basePath;
 
 	Include ( const Project& project,
 	          const XMLElement& includeNode );