Generate make rules for creating directories if they don't exist
authorCasper Hornstrup <chorns@users.sourceforge.net>
Thu, 12 May 2005 19:32:15 +0000 (19:32 +0000)
committerCasper Hornstrup <chorns@users.sourceforge.net>
Thu, 12 May 2005 19:32:15 +0000 (19:32 +0000)
svn path=/branches/xmlbuildsystem/; revision=15244

reactos/tools/rbuild/backend/mingw/mingw.cpp
reactos/tools/rbuild/backend/mingw/mingw.h
reactos/tools/rbuild/backend/mingw/modulehandler.cpp

index 0a02169..93bb9e7 100644 (file)
@@ -179,7 +179,7 @@ Directory::GenerateTree ( const string& parent,
 {
        string path;
 
-       if ( parent.size() )
+       if ( parent.size () > 0 )
        {
                char buf[256];
                
@@ -191,11 +191,62 @@ Directory::GenerateTree ( const string& parent,
        else
                path = name;
 
+       for ( directory_map::iterator i = subdirs.begin ();
+               i != subdirs.end ();
+               ++i )
+       {
+               i->second->GenerateTree ( path, verbose );
+       }
+}
+
+string
+Directory::EscapeSpaces ( string path )
+{
+       string newpath;
+       char* p = &path[0];
+       while ( *p != 0 )
+       {
+               if ( *p == ' ' )
+                       newpath = newpath + "\\ ";
+               else
+                       newpath = newpath + *p;
+               *p++;
+       }
+       return newpath;
+}
+
+void
+Directory::CreateRule ( FILE* f,
+                           const string& parent )
+{
+       string path;
+
+       if ( parent.size() > 0 )
+       {
+               string escapedParent = EscapeSpaces ( parent );
+               fprintf ( f,
+                       "%s%c%s: | %s\n",
+                       escapedParent.c_str (),
+                       CSEP,
+                       EscapeSpaces ( name ).c_str (),
+                       escapedParent.c_str () );
+
+               fprintf ( f,
+                       "\t$(ECHO_MKDIR)\n" );
+
+               fprintf ( f,
+                       "\t${mkdir} $@\n" );
+
+               path = parent + SSEP + name;
+       }
+       else
+               path = name;
+
        for ( directory_map::iterator i = subdirs.begin();
                i != subdirs.end();
                ++i )
        {
-               i->second->GenerateTree ( path, verbose );
+               i->second->CreateRule ( f, path );
        }
 }
 
@@ -302,6 +353,7 @@ MingwBackend::Process ()
        GenerateXmlBuildFilesMacro ();
        ProcessModules ();
        GenerateInstallTarget ();
+       GenerateDirectoryTargets ();
        GenerateDirectories ();
        CheckAutomaticDependencies ();
        CloseMakefile ();
@@ -723,7 +775,7 @@ MingwBackend::OutputInstallTarget ( const string& sourceFilename,
                NormalizeFilename ( targetDirectory ),
                installDirectory );
        fprintf ( fMakefile,
-                 "%s: %s %s\n",
+                 "%s: %s %s\n",
                  normalizedTargetFilename.c_str (),
                  sourceFilename.c_str (),
                  normalizedTargetDirectory.c_str () );
@@ -832,3 +884,11 @@ MingwBackend::GenerateInstallTarget ()
        fprintf ( fMakefile,
                  "\n" );
 }
+
+void
+MingwBackend::GenerateDirectoryTargets ()
+{
+       intermediateDirectory->CreateRule ( fMakefile, "" );
+       outputDirectory->CreateRule ( fMakefile, "" );
+       installDirectory->CreateRule ( fMakefile, "" );
+}
index 84e706f..ac72c0b 100644 (file)
@@ -34,6 +34,9 @@ public:
        void Add ( const char* subdir );
        void GenerateTree ( const std::string& parent,
                            bool verbose );
+       std::string EscapeSpaces ( std::string path );
+       void CreateRule ( FILE* f,
+                         const std::string& parent );
 private:
        bool mkdir_p ( const char* path );
        std::string ReplaceVariable ( std::string name,
@@ -105,6 +108,7 @@ private:
        std::string GetRegistryTargetFiles ();
        void OutputRegistryInstallTarget ();
        void GenerateInstallTarget ();
+       void GenerateDirectoryTargets ();
        FILE* fMakefile;
        bool use_pch;
 };
index 14843b7..e318746 100644 (file)
@@ -129,7 +129,7 @@ MingwModuleHandler::GetTargetFilename (
 {
        string target = PassThruCacheDirectory (
                NormalizeFilename ( module.GetPath () ),
-               backend->intermediateDirectory );
+               GetTargetDirectoryTree ( module ) );
        if ( pclean_files )
        {
                string_list& clean_files = *pclean_files;