Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Tool for Converting VC++2005 Project to Linux Makefile

, 13 Jul 2012 CPOL
Convert .sln/.vcproj (VC++2005) to Linux makefile
sln2mak.zip
sln2mak
sln2mak
Properties
sln2mak.csproj.user
sln2mak_bin.zip
sln2mak.exe
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Xml;
using Microsoft.VisualStudio.VCProjectEngine;

namespace sln2mak
{
    class Parser
    {
        #region Members
        /****************************************************************/
        private static Regex     m_ProjectGuid     ;
        private static Regex     m_SlnExtention    ;
        private static Regex     m_VcprojExtention ;
        private static Regex     m_ProjectRegex    ;
        /****************************************************************/
        #endregion /* Members */

        #region LifeCycle
        /****************************************************************/
        static Parser()
        {
            m_ProjectGuid       = new Regex (@"ProjectGUID=""\{(.*)\}"""        ) ;
            m_SlnExtention      = new Regex (@"(.*)(.[Ss][Ll][Nn])$"            ) ;
            m_VcprojExtention   = new Regex (@"(.*)(.[Vv][Cc][Pp][Rr][Oo][Jj])$") ;
            m_ProjectRegex      = new Regex (@"Project\(""\{(.*)\}""\) = ""(.*)"", ""(.*)"", ""\{(.*)\}""") ;
        }
        /****************************************************************/
        #endregion /* LifeCycle */

        #region Access  Region
        /****************************************************************/
        public static Regex ProjectGuidRegex 
        {
            get { return m_ProjectGuid; }
        }

        public static Regex SlnExtentionRegex
        {
            get { return m_SlnExtention; }
        }

        public static Regex VcprojExtentionRegex
        {
            get { return m_VcprojExtention; }
        }

        public static Regex ProjectRegex
        {
            get { return m_ProjectRegex ; }
        }
        /*===================================================================*/
        #endregion /* Access  Region */

        #region Public Operations
        /*===================================================================*/
        /// <summary>
        /// After .vcproj files list parsed call to CreateMakefile 
        /// for Makefile generation
        /// </summary>
        public static void CreateMakefile  (List<string> projectsList, 
                                            string[]     mainProjectDependencies  )
        {
            StreamReader                sr;
            Match                       matchProjInfo;
            string                      line;
            Dictionary<string, string>  projectNameGuid = new Dictionary<string, string>();


            //Initialize dictionary with project guid and name
            foreach(string project in projectsList)
            {
                sr = new StreamReader(project);
                while ((line = sr.ReadLine()) != null)
                {
                    matchProjInfo = ProjectGuidRegex.Match(line);
                    if (matchProjInfo.Success)
                    {
                        projectNameGuid.Add(matchProjInfo.Groups[1].Value, project);
                    }
                }

            }

            //Instantinate VcSlnInfo object with main project name
            VcSlnInfo slnInfo = new VcSlnInfo(projectsList[0]);
            //Initialize all dictioanries for VcSlnInfo object
            slnInfo.InitDictionaries(projectNameGuid, mainProjectDependencies);
            slnInfo.GenerateMakefile(false);
            
        }

        /// <summary>
        /// Generate makefile after object slnInfo with main project name and 
        /// .sln file name(full path) instantinated 
        /// </summary>
        /// <param name="projName">main project name </param>
        /// <param name="slnFName">.sln file name(full path)</param>
        public static void ParseSln (string projName, 
                                     string  slnFName    )
        {                                    
           
            VcSlnInfo slnInfo = new VcSlnInfo(projName, slnFName);

            slnInfo.GenerateMakefile();                    
        }
        /*===================================================================*/
        #endregion /* Public Operations */          
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Maria Adamsky
Software Developer EFC Real Solutions on Time,LTD
Israel Israel
Software developer at EFC Real Solutions on Time,LTD(Israel) in infrastructure team.
Developing Grid computing application for data communication simulations.
Writing Cross-Platform Software (Windows and Linux).

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141216.1 | Last Updated 13 Jul 2012
Article Copyright 2008 by Maria Adamsky
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid