5,699,431 members and growing! (21,723 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Cross Platform » General     Intermediate License: The Code Project Open License (CPOL)

Tool for converting VC++2005 project to linux makefile

By Maria Adamsky

convert .sln/.vcproj(VC++2005) to linux makefile
C++ (VC8.0, C++, VC9.0), C# (C# 2.0, C# 3.0, C#), Visual Studio (Visual Studio, VS2008, VS2005)

Posted: 28 Aug 2008
Updated: 16 Sep 2008
Views: 10,958
Bookmarked: 54 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
32 votes for this Article.
Popularity: 6.74 Rating: 4.48 out of 5
2 votes, 6.3%
1
0 votes, 0.0%
2
2 votes, 6.3%
3
4 votes, 12.5%
4
24 votes, 75.0%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Download sources - sln2mak.zip - 16.77 KB

Introduction

This tool automatically converts Visual C++ 8.0 or 9.0 projects to Linux makefile. Important note, there is no loss during the conversion: source code and .sln/.vcproj files are left unchanged. The tool implemented in C# VS 2005.

Why?

  • Your application is cross-platform based.
  • Now you are facing a decision to migrate from Visual C++ 6 to 8 or 9.

This both reasons force you to create makefile manually and each small change in your project requires hard physical labor in makefile maintenance.

This tool will do it for you automatically and will provide you ability to keep .sln/.vcproj and .mak files synchronized.

Using the Tool

The tool is a command line (console application).
Argument format is like following:

  1. In case an active project name is similar to solution name
    sln2mak [Solution_FullPath_File_Name].sln
    example:
    sln2mak c:/myprojects/test/unit_test.sln
  2. In case an active project name differs from solution name
    sln2mak -l [Main_Project_Name] [Solution_FullPath_File_Name].sln

    example:

    sln2mak -l unit_test c:/myprojects/test/test.sln
  3. In case you would like to convert list of .vcproj files, type in this list, when first one is main lead project, and then use -d flag for additional dependencies, like libs, for a main project if exists.
    sln2mak [Main_Project_FullPath_Name].vcproj [Project_FullPath_Name_2].vcproj ... 
             [Project_FullPath_Name_n].vcproj -d [lib_Name_1] ... [lib_Name_n]

    example:

    sln2mak c:/myprojects/tets/unit_test.vcproj c:/myprojects/tets/test_lib.vcproj 
        -d mystaticlib1 mystaticlib2 mystaticlib3 

    For usage, call sln2mak with no arguments.

    After application run you'll find .mak file in path where .vcproj is located with the same name as the project.

    .mak files has all additional libraries path, sources, flags for compiler, linker, preprocessor and target path. 

In .sln path you'll find Makefile that will handle all target rules (clean, make) and dependencies.

Makefile.JPG

Points of Interest

Parser Class

This class has a static constructor in aim to be known for all classes without instantiation.

It holds regular expression that serves all other classes for parsing .sln and .vcproj files.

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

VcSlnInfo Class

This class parses solution file and creates Makefile with target rules.

This class uses stream reader for reading .sln file line by line. During reading .sln file it recognize an active project (its name similar to solution name) and create 4 dictionaries that hold info about all main and dependent project:

  • Key = Guid number , Value = ProjectName
  • Key = ProjectName , Value = ProjectFullPath
  • Key = ProjectName , Value = MakeFileName
  • Key = ProjectName , Value = ProjectDependencies
Dictionary<string, string>  m_ProjGuidName = new Dictionary<string, string>() ;

Then method ParseVcproj called - public VcProjInfo class's function, but first for each .vcproj  instance of VcProjInfo object created with projectName, projectFullPath and projectMakFileName.

VcProjInfo Class

In this class VCProjectEngine object used for retrieving all the necessary information about .vcproj, like target type and name, compiler flags, additional libraries, linker flags, sources and filters, preprocessor definitions, configurations and etc.

using Microsoft.VisualStudio.VCProjectEngine;
VCProjectEngine vcprojEngine = new VCProjectEngineObject();
//Init VCProject vcProj object
VCProject m_VcProj = (VCProject)vcprojEngine.LoadProject(vcProjFile);

//Init vcproj configurations list 
IVCCollection m_ConfigCollection = (IVCCollection)m_VcProj.Configurations;

All these served me to create .mak file with CFLAGS, LDFLAGS, OBJS and like this.

Important Notes

  • There is no loss during the conversion: source code stays unchanged.  
  • Probably I did not cover all flags during parsing from .vcproj to .mak, but now you have all necessary information to be able to add anything I've missed.
  • During my work I inspact that there are few differencies between VC++ 8 solution/vcproj and VC++ 9, so you can use this tool for both.
  • If you convert this source code to Visual Studio 2008, please use proper Microsoft.VisualStudio.VCProjectEngine reference version 9.0.0.0 instead of 8.0.0.0.

History  

Prior to writing the application I tried to find some similar tool on the internet, but was only successful in finding other people's questions on online forums regarding the issue.
Then I attempted to understand XML-schema of a VC++8 solution and project, but the schema wasn't clear enough.

Suddenly I found a Microsoft.VisualStudio.VCProjectEngine reference with VCProjectEngine object within .NET components which helped me to understand the structure of a VC++ 2005 project. I used this object in my application for .vcproj parsing instead of using System.Xml for xml tree reading, and this without proper xml schema documentation.

reference.JPG

Disclaimer 

The information provided on this page comes without any warranty whatsoever.  

This tool has been extensively tested before being published, but always there is possibility to find some weakness. I strongly recommend that you back up your project before using this tool. Moreover, though I am willing to know if there is anything I can do in order to improve it, let me clearly say that it's not my fault if your project is corrupted by this tool.

Update History  

  • 6/9/2008 Bug fixes - using sln2mak.exe from the same path as .sln/.vcproj.
  • 16/9/2008 Bug fixes - handling null reference for VC compiler tool, recursive file filters expanding during sources list creation.

License

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

About the Author

Maria Adamsky


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).
Occupation: Software Developer
Company: EFC Real Solutions on Time,LTD
Location: Israel Israel

Other popular Cross Platform articles:

  • Introduction to Mono - Your first Mono app
    The first in a series of articles about Mono. This article explains how to install Mono and shows how to compile your first Cross Platform application.
  • MONO: an alternative for the .NET framework
    This article presents possibilities for development of .NET applications running on operating systems other than Windows, using the MONO platform. Advantages and challenges will be presented. Also presented are some common issues encountered while developing applications using the .NET technology.
  • Embed ActiveX controls inside Java GUI
    With this your Java projects can take advantage of ActiveX controls and Office documents such as spreadsheets, charts, calendars, word processors, specialized graphics, and many more.
  • Introduction to Mono - ASP.NET with XSP and Apache
    The second article in a series of articles about Mono. This article explains how to host and serve ASP.NET Web Applications and Web Services on Linux using XSP and Apache with the help of Mono.
  • Phalanger, PHP for .NET: Introduction for .NET developers
    Phalanger is a PHP language compiler for the .NET Framework which introduces PHP as a first-class .NET citizen.
Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 22 of 22 (Total in Forum: 22) (Refresh)FirstPrevNext
GeneralWhich make do you use? [modified]memberDan Macumber10:05 26 Nov '08  
Generalabout "Post-Build Event" ?memberfreesoftvip23:15 6 Nov '08  
Generalhm..member5sxz73421:48 23 Sep '08  
GeneralRe: hm..memberJoe Pizzi16:40 1 Oct '08  
GeneralProgram crashesmembermentrup1:39 23 Sep '08  
GeneralRe: Program crashesmemberMaria Adamsky3:22 23 Sep '08  
GeneralExcellent toolmemberhadaryona5:22 13 Sep '08  
GeneralNicemembersaiful_vonair20:29 8 Sep '08  
GeneralWhat about the reverse?memberJoshua Pincus2:36 8 Sep '08  
GeneralRe: What about the reverse?memberMaria Adamsky7:33 8 Sep '08  
GeneralObviouslymemberVitaly Tomilov15:45 6 Sep '08  
GeneralRe: Obviously [modified]memberMaria Adamsky21:11 6 Sep '08  
GeneralRe: Obviouslymembergajatko11:53 16 Sep '08  
GeneralCoolmemberMember 420165223:49 4 Sep '08  
GeneralWowmemberAnton Bredikhin22:24 2 Sep '08  
GeneralRe: WowmemberAnton Bredikhin23:26 2 Sep '08  
GeneralRe: WowmemberMaria Adamsky0:04 3 Sep '08  
GeneralRe: WowmemberAnton Bredikhin23:28 2 Sep '08  
GeneralRe: WowmemberMaria Adamsky0:03 3 Sep '08  
GeneralLooks useful.memberwtwhite19:58 2 Sep '08  
GeneralGood ToolmemberJustin200717:26 2 Sep '08  
GeneralRe: Good ToolmemberMaria Adamsky2:24 3 Sep '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 16 Sep 2008
Editor: Sean Ewington
Copyright 2008 by Maria Adamsky
Everything else Copyright © CodeProject, 1999-2008
Web15 | Advertise on the Code Project