rbuild: correct MSVC project file generation:
- don't define _DEBUG and NDEBUG at the same time
- fix compiler flags for VC7/8
Modified: trunk/reactos/tools/rbuild/backend/msvc/msvcmaker.cpp
Modified: trunk/reactos/tools/rbuild/backend/msvc/vcprojmaker.cpp

Modified: trunk/reactos/tools/rbuild/backend/msvc/msvcmaker.cpp
--- trunk/reactos/tools/rbuild/backend/msvc/msvcmaker.cpp	2006-01-29 10:39:19 UTC (rev 27)
+++ trunk/reactos/tools/rbuild/backend/msvc/msvcmaker.cpp	2006-01-29 10:41:48 UTC (rev 28)
@@ -23,6 +23,7 @@
 
 #include <string>
 #include <vector>
+#include <set>
 
 #include <stdio.h>
 
@@ -30,7 +31,10 @@
 
 using std::string;
 using std::vector;
+using std::set;
 
+typedef set<string> StringSet;
+
 #ifdef OUT
 #undef OUT
 #endif//OUT
@@ -79,13 +83,14 @@
 
 	// TODO FIXME - what's diff. betw. 'c_srcs' and 'source_files'?
 	string dsp_path = module.GetBasePath();
-	vector<string> c_srcs, source_files, resource_files, includes, libraries, defines;
+	vector<string> c_srcs, source_files, resource_files, includes, libraries;
+	StringSet common_defines;
 	vector<const IfableData*> ifs_list;
 	ifs_list.push_back ( &module.project.non_if_data );
 	ifs_list.push_back ( &module.non_if_data );
 
 	// this is a define in MinGW w32api, but not Microsoft's headers
-	defines.push_back ( "STDCALL=__stdcall" );
+	common_defines.insert ( "STDCALL=__stdcall" );
 
 	while ( ifs_list.size() )
 	{
@@ -132,9 +137,9 @@
 		for ( i = 0; i < defs.size(); i++ )
 		{
 			if ( defs[i]->value[0] )
-				defines.push_back ( defs[i]->name + "=" + defs[i]->value );
+				common_defines.insert( defs[i]->name + "=" + defs[i]->value );
 			else
-				defines.push_back ( defs[i]->name );
+				common_defines.insert( defs[i]->name );
 		}
 	}
 	// TODO FIXME - we don't include header files in our build system
@@ -318,44 +323,46 @@
 		if ( dll ) fprintf ( OUT, "# PROP Ignore_Export_Lib 0\r\n" );
 		fprintf ( OUT, "# PROP Target_Dir \"\"\r\n" );
 
+		StringSet defines = common_defines;
+
 		if ( debug )
 		{
-			defines.push_back ( "_DEBUG" );
+			defines.insert ( "_DEBUG" );
 			if ( lib || exe )
 			{
 				fprintf ( OUT, "# ADD BASE CPP /nologo /W3 /Gm /GX /Zi /Od" );
-				defines.push_back ( "_LIB" );
+				defines.insert ( "_LIB" );
 			}
 			else
 			{
 				fprintf ( OUT, "# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /Zi /Od" );
-				defines.push_back ( "_WINDOWS" );
-				defines.push_back ( "_USRDLL" );
+				defines.insert ( "_WINDOWS" );
+				defines.insert ( "_USRDLL" );
 				// TODO FIXME - wine hack?
-				//defines.push_back ( string("\U") + module.name + "\E_EXPORTS" );
+				//defines.insert ( string("\U") + module.name + "\E_EXPORTS" );
 			}
 		}
 		else
 		{
-			defines.push_back ( "NDEBUG" );
+			defines.insert ( "NDEBUG" );
 			if ( lib || exe )
 			{
 				fprintf ( OUT, "# ADD BASE CPP /nologo /W3 /GX /O2" );
-				defines.push_back ( "_LIB" );
+				defines.insert ( "_LIB" );
 			}
 			else
 			{
 				fprintf ( OUT, "# ADD BASE CPP /nologo /MT /W3 /GX /O2" );
-				defines.push_back ( "_WINDOWS" );
-				defines.push_back ( "_USRDLL" );
+				defines.insert ( "_WINDOWS" );
+				defines.insert ( "_USRDLL" );
 				// TODO FIXME - wine hack?
-				//defines.push_back ( string("\U") + module.name + "\E_EXPORTS" );
+				//defines.insert ( string("\U") + module.name + "\E_EXPORTS" );
 			}
 		}
 
-		for ( i = 0; i < defines.size(); i++ )
+		for ( StringSet::const_iterator it1=defines.begin(); it1!=defines.end(); it1++ )
 		{
-			fprintf ( OUT, " /D \"%s\"", defines[i].c_str() );
+			fprintf ( OUT, " /D \"%s\"", it1->c_str() );
 		}
 		if ( lib || exe ) fprintf ( OUT, " /YX" );
 		fprintf ( OUT, " /FD" );
@@ -367,33 +374,32 @@
 		fprintf ( OUT, " /c" );
 		fprintf ( OUT, "\r\n" );
 
-		vector<string> defines2 = defines;
 		if ( debug )
 		{
-			defines2.push_back ( "_DEBUG" );
+			defines.insert ( "_DEBUG" );
 			if(lib)
 			{
 				fprintf ( OUT, "# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od" );
-				defines2.push_back ( "_LIB" );
+				defines.insert ( "_LIB" );
 			}
 			else
 			{
 				fprintf ( OUT, "# ADD CPP /nologo /MTd /W3 /Gm /GX /Zi /Od" );
-				defines2.push_back ( "_USRDLL" );
+				defines.insert ( "_USRDLL" );
 			}
 		}
 		else
 		{
-			defines2.push_back ( "NDEBUG" );
+			defines.insert ( "NDEBUG" );
 			if(lib)
 			{
 				fprintf ( OUT, "# ADD CPP /nologo /MT /W3 /GX /O2" );
-				defines2.push_back ( "_LIB" );
+				defines.insert ( "_LIB" );
 			}
 			else
 			{
 				fprintf ( OUT, "# ADD CPP /nologo /MT /W3 /GX /O2" );
-				defines2.push_back ( "_USRDLL" );
+				defines.insert ( "_USRDLL" );
 			}
 		}
 
@@ -401,16 +407,16 @@
 		if ( wine )
 		{
 			// TODO FIXME - wine hack?
-			//defines2.push_back ( string("_\U") + module.name + "\E_" );
+			//defines.insert ( string("_\U") + module.name + "\E_" );
 			// TODO FIXME - wine hack?
 			/*if ( module.name !~ /^(?:wine(?:build|test)|.*?_test)$/ )
-				defines2.push_back ( "__WINESRC__" );*/
+				defines.insert ( "__WINESRC__" );*/
 			if ( msvc_headers )
-				defines2.push_back ( "__WINE_USE_NATIVE_HEADERS" );
+				defines.insert ( "__WINE_USE_NATIVE_HEADERS" );
 			string output_dir2 = Replace(output_dir,"\\","\\\\");
-			defines2.push_back ( ssprintf("__WINETEST_OUTPUT_DIR=\\\"%s\\\"",output_dir.c_str()) );
-			defines2.push_back ( "__i386__" );
-			defines2.push_back ( "_X86_" );
+			defines.insert ( ssprintf("__WINETEST_OUTPUT_DIR=\\\"%s\\\"",output_dir.c_str()) );
+			defines.insert ( "__i386__" );
+			defines.insert ( "_X86_" );
 
 			// TODO FIXME - wine hacks?
 			/*if(module.name =~ /^gdi32_(?:enhmfdrv|mfdrv)$/) {
@@ -445,9 +451,9 @@
 		}
 
 		fprintf ( OUT, " /I \".\"" );
-		for ( i = 0; i < defines2.size(); i++ )
+		for ( StringSet::const_iterator it2=defines.begin(); it2!=defines.end(); it2++ )
 		{
-			const string& define = defines2[i];
+			const string& define = *it2;
 			if ( strpbrk ( define.c_str(), "[\\\"]" ) )
 			{
 				fprintf ( OUT, " /D \"%s\"", define.c_str() );
@@ -486,9 +492,9 @@
 				}
 			}
 
-			for ( i = 0; i < defines.size(); i++ )
+			for ( StringSet::const_iterator it3=defines.begin(); it3!=defines.end(); it3++ )
 			{
-				fprintf ( OUT, " /D \"%s\"", defines[i].c_str() );
+				fprintf ( OUT, " /D \"%s\"", it3->c_str() );
 			}
 			fprintf ( OUT, " /d \"_DEBUG\"\r\n" );
 		}
@@ -508,9 +514,9 @@
 					fprintf ( OUT, " /i \"%s\"", includes[i].c_str() );
 			}
 
-			for ( i = 0; i < defines.size(); i++ )
+			for ( StringSet::const_iterator it4=defines.begin(); it4!=defines.end(); it4++ )
 			{
-				fprintf ( OUT, " /D \"%s\"", defines[i].c_str() );
+				fprintf ( OUT, " /D \"%s\"", it4->c_str() );
 			}
 
 

Modified: trunk/reactos/tools/rbuild/backend/msvc/vcprojmaker.cpp
--- trunk/reactos/tools/rbuild/backend/msvc/vcprojmaker.cpp	2006-01-29 10:39:19 UTC (rev 27)
+++ trunk/reactos/tools/rbuild/backend/msvc/vcprojmaker.cpp	2006-01-29 10:41:48 UTC (rev 28)
@@ -23,6 +23,7 @@
 
 #include <string>
 #include <vector>
+#include <set>
 
 #include <stdio.h>
 
@@ -30,7 +31,10 @@
 
 using std::string;
 using std::vector;
+using std::set;
 
+typedef set<string> StringSet;
+
 #ifdef OUT
 #undef OUT
 #endif//OUT
@@ -91,16 +95,17 @@
 	//$output->progress("$dsp_file (file $progress_current of $progress_max)");
 
 	string vcproj_path = module.GetBasePath();
-	vector<string> source_files, resource_files, includes, libraries, defines;
+	vector<string> source_files, resource_files, includes, libraries;
+	StringSet common_defines;
 	vector<const IfableData*> ifs_list;
 	ifs_list.push_back ( &module.project.non_if_data );
 	ifs_list.push_back ( &module.non_if_data );
 
 	// MinGW doesn't have a safe-string library yet
-	defines.push_back ( "_CRT_SECURE_NO_DEPRECATE" );
-	defines.push_back ( "_CRT_NON_CONFORMING_SWPRINTFS" );
+	common_defines.insert ( "_CRT_SECURE_NO_DEPRECATE" );
+	common_defines.insert ( "_CRT_NON_CONFORMING_SWPRINTFS" );
 	// this is a define in MinGW w32api, but not Microsoft's headers
-	defines.push_back ( "STDCALL=__stdcall" );
+	common_defines.insert ( "STDCALL=__stdcall" );
 
 	string baseaddr;
 
@@ -158,9 +163,9 @@
 		for ( i = 0; i < defs.size(); i++ )
 		{
 			if ( defs[i]->value[0] )
-				defines.push_back ( defs[i]->name + "=" + defs[i]->value );
+				common_defines.insert( defs[i]->name + "=" + defs[i]->value );
 			else
-				defines.push_back ( defs[i]->name );
+				common_defines.insert( defs[i]->name );
 		}
 		for ( i = 0; i < data.properties.size(); i++ )
 		{
@@ -278,39 +283,45 @@
 		}
 		fprintf ( OUT, "\"\r\n " );
 
+		StringSet defines = common_defines;
+
 		if ( debug )
 		{
-			defines.push_back ( "_DEBUG" );
+			defines.insert ( "_DEBUG" );
 		}
 		else
 		{
-			defines.push_back ( "NDEBUG" );
+			defines.insert ( "NDEBUG" );
 		}
 
 		if ( lib || exe )
 		{
-			defines.push_back ( "_LIB" );
+			defines.insert ( "_LIB" );
 		}
 		else
 		{
-			defines.push_back ( "_WINDOWS" );
-			defines.push_back ( "_USRDLL" );
+			defines.insert ( "_WINDOWS" );
+			defines.insert ( "_USRDLL" );
 		}
 
 		fprintf ( OUT, "\t\t\t\tPreprocessorDefinitions=\"" );
-		for ( i = 0; i < defines.size(); i++ )
+		for ( StringSet::iterator it1=defines.begin(); it1!=defines.end(); it1++ )
 		{
 			if ( i > 0 )
 				fprintf ( OUT, ";" );
 
-			defines[i] = _replace_str(defines[i], "\"","&quot;"); 
-			fprintf ( OUT, "%s", defines[i].c_str() );
+			string unescaped = *it1;
+			defines.erase(unescaped);
+			const string& escaped = _replace_str(unescaped, "\"","&quot;");
+
+			defines.insert(escaped);
+			fprintf ( OUT, "%s", escaped.c_str() );
 		}
 		fprintf ( OUT, "\"\r\n" );
 
 		fprintf ( OUT, "\t\t\t\tMinimalRebuild=\"%s\"\r\n", speed ? "FALSE" : "TRUE" );
         fprintf ( OUT, "\t\t\t\tBasicRuntimeChecks=\"%s\"\r\n", sys ? 0 : (debug ? "3" : "0") );
-		fprintf ( OUT, "\t\t\t\tRuntimeLibrary=\"5\"\r\n" );
+		fprintf ( OUT, "\t\t\t\tRuntimeLibrary=\"%d\"\r\n", debug? 1: 5 );	// 1=/MTd 5=/MT
         fprintf ( OUT, "\t\t\t\tBufferSecurityCheck=\"%s\"\r\n", sys ? "FALSE" : (debug ? "TRUE" : "FALSE" ));
 		fprintf ( OUT, "\t\t\t\tEnableFunctionLevelLinking=\"%s\"\r\n", debug ? "TRUE" : "FALSE" );
 		
@@ -337,14 +348,13 @@
 			fprintf ( OUT, "\t\t\t\tStringPooling=\"true\"\r\n" );
 		}
 
-		fprintf ( OUT, "\t\t\t\tEnablePREfast=\"%s\"\r\n", debug ? "TRUE" : "FALSE");
 		fprintf ( OUT, "\t\t\t\tDisableSpecificWarnings=\"4201;4127;4214\"\r\n" );
 		fprintf ( OUT, "\t\t\t\tWarningLevel=\"%s\"\r\n", speed ? "0" : "4" );
 		fprintf ( OUT, "\t\t\t\tDetect64BitPortabilityProblems=\"%s\"\r\n", speed ? "FALSE" : "TRUE");
 		if ( !module.cplusplus )
 			fprintf ( OUT, "\t\t\t\tCompileAs=\"1\"\r\n" );
-        fprintf ( OUT, "\t\t\t\tCallingConvention=\"%d\"\r\n", (sys || (exe && module.type == Kernel)) ? 2: 1);
-		fprintf ( OUT, "\t\t\t\tDebugInformationFormat=\"%s\"/>\r\n", speed ? "0" : "4");
+        fprintf ( OUT, "\t\t\t\tCallingConvention=\"%d\"\r\n", (sys || (exe && module.type == Kernel)) ? 2: 0);	// 2=__stdcall 0=__cdecl
+		fprintf ( OUT, "\t\t\t\tDebugInformationFormat=\"%s\"/>\r\n", speed ? "0" : release ? "3": "4");	// 3=/Zi 4=ZI
 
 		fprintf ( OUT, "\t\t\t<Tool\r\n" );
 		fprintf ( OUT, "\t\t\t\tName=\"VCCustomBuildTool\"/>\r\n" );
@@ -382,6 +392,7 @@
 			fprintf ( OUT, "\t\t\t\tOutputFile=\"$(OutDir)/%s%s\"\r\n", module.name.c_str(), module_type.c_str() );
 			fprintf ( OUT, "\t\t\t\tLinkIncremental=\"%d\"\r\n", debug ? 2 : 1 );
 			fprintf ( OUT, "\t\t\t\tGenerateDebugInformation=\"%s\"\r\n", speed ? "FALSE" : "TRUE" );
+			fprintf ( OUT, "\t\t\t\tLinkTimeCodeGeneration=\"%d\"\r\n", release? 1: 0);	// whole program optimization
 
 			if ( debug )
 				fprintf ( OUT, "\t\t\t\tProgramDatabaseFile=\"$(OutDir)/%s.pdb\"\r\n", module.name.c_str() );