eliminate rmkdir and generate directory dependencies the right way.
[reactos.git] / reactos / tools / rbuild / module.cpp
index 5fa77ad..992dcf1 100644 (file)
@@ -19,6 +19,24 @@ FixSeparator ( const string& s )
        return s2;\r
 }\r
 \r
+string\r
+ReplaceExtension (\r
+       const string& filename,\r
+       const string& newExtension )\r
+{\r
+       size_t index = filename.find_last_of ( '/' );\r
+       if ( index == string::npos )\r
+               index = 0;\r
+       size_t index2 = filename.find_last_of ( '\\' );\r
+       if ( index2 != string::npos && index2 > index )\r
+               index = index2;\r
+       string tmp = filename.substr( index /*, filename.size() - index*/ );\r
+       size_t ext_index = tmp.find_last_of( '.' );\r
+       if ( ext_index != string::npos )\r
+               return filename.substr ( 0, index + ext_index ) + newExtension;\r
+       return filename + newExtension;\r
+}\r
+\r
 string\r
 GetSubPath (\r
        const string& location,\r
@@ -542,11 +560,12 @@ Module::GetDependencyPath () const
 {\r
        if ( HasImportLibrary () )\r
        {\r
-               return ssprintf ( "dk%cnkm%clib%clib%s.a",\r
+               return ReplaceExtension ( GetPath(), ".a" );\r
+               /*return ssprintf ( "dk%cnkm%clib%clib%s.a",\r
                                  CSEP,\r
                                  CSEP,\r
                                  CSEP,\r
-                                 name.c_str () );\r
+                                 name.c_str () );*/\r
        }\r
        else\r
                return GetPath();\r
@@ -570,23 +589,19 @@ Module::GetPathWithPrefix ( const string& prefix ) const
        return path + CSEP + prefix + GetTargetName ();\r
 }\r
 \r
-string\r
-Module::GetTargets () const\r
+void\r
+Module::GetTargets ( string_list& targets ) const\r
 {\r
        if ( invocations.size () > 0 )\r
        {\r
-               string targets ( "" );\r
                for ( size_t i = 0; i < invocations.size (); i++ )\r
                {\r
                        Invoke& invoke = *invocations[i];\r
-                       if ( targets.length () > 0 )\r
-                               targets += " ";\r
-                       targets += invoke.GetTargets ();\r
+                       invoke.GetTargets ( targets );\r
                }\r
-               return targets;\r
        }\r
        else\r
-               return GetPath ();\r
+               targets.push_back ( GetPath () );\r
 }\r
 \r
 string\r
@@ -751,23 +766,20 @@ Invoke::ProcessXMLSubElementOutput ( const XMLElement& e )
                subs_invalid = true;\r
        }\r
        if ( subs_invalid && e.subElements.size() > 0 )\r
-               throw InvalidBuildFileException ( e.location,\r
-                                                 "<%s> cannot have sub-elements",\r
-                                                 e.name.c_str() );\r
+               throw InvalidBuildFileException (\r
+                       e.location,\r
+                       "<%s> cannot have sub-elements",\r
+                       e.name.c_str() );\r
 }\r
 \r
-string\r
-Invoke::GetTargets () const\r
+void\r
+Invoke::GetTargets ( string_list& targets ) const\r
 {\r
-       string targets ( "" );\r
        for ( size_t i = 0; i < output.size (); i++ )\r
        {\r
                InvokeFile& file = *output[i];\r
-               if ( targets.length () > 0 )\r
-                       targets += " ";\r
-               targets += NormalizeFilename ( file.name );\r
+               targets.push_back ( NormalizeFilename ( file.name ) );\r
        }\r
-       return targets;\r
 }\r
 \r
 string\r
@@ -782,8 +794,7 @@ Invoke::GetParameters () const
                InvokeFile& invokeFile = *output[i];\r
                if ( invokeFile.switches.length () > 0 )\r
                {\r
-                       parameters += invokeFile.switches;\r
-                       parameters += " ";\r
+                       parameters += invokeFile.switches + " ";\r
                }\r
                parameters += invokeFile.name;\r
        }\r