|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
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 IntroductionThis 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?
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 ToolThe tool is a command line (console application).
In .sln path you'll find Makefile that will handle all target rules (clean, make) and dependencies.
Points of InterestParser ClassThis 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 ClassThis 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:
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 ClassIn 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
HistoryPrior 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. 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. DisclaimerThe 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
|
||||||||||||||||||||||