Converting Visual Studio solutions to Makefiles
A python script to convert Microsoft Visual Studio 2005 solution files (*.sln) and the associated project files (*.vcproj) into a set of Makefile’s.
The class Sln2Make does all the work, parses the sln and vcproj files and generates a main Makefile and one Makefile.ag for every project in the solution. The Makefiles.ag generated will have two targets, ‘all’ and ‘clean’, the script also includes the dependent libraries if they are properly defined in the solution. To use it, just instantiate the class with the following parameters:
Sln2Make(slnpath, exlist, dirrepl, librepl)
where:
- slnpath is the path to the solution file
- exlist an optional list of files to exclude, optionally you can pass the content of an alternative make file using this syntax: [[dest, make_all_replacement, make_clean_replacement], …]
- dirrepl a list of directory replacement rules
- librepl library name replacement rules (when win library name doesn’t match OS’s library name)
example:
exlist = [('../extsrc/zlib/projects/visualc6/Makefile.ag',
' $(MAKE) -C $(dir_root)extsrc/zlib -f Makefile libz.a\n',
' $(MAKE) -C $(dir_root)extsrc/zlib -f Makefile clean\n')]
dirrepl = [['winnt', 'linux']]
librepl = [['zlib', 'z'], ['nspr', 'nspr4 -lplc4 -lplds4']]
#
Sln2Make("../winnt/test.sln", exlist, dirrepl, librepl)
To correct the path case, I’ve used a script published by Moshe Zadka here.
Download sln2make here. Use this code at your own risk, it is released under BSD license.

Guy, I would going to present you a BIG bottle or beer, but seems that I so stuped, and it’s not working well for me.
Finaly, I undestand how to run it properly, but seems my MAKE not like generated Makefile.
Here is a generated Makefile:
===================
# sln2make autogenerated Makefile.ag
dir_root=../
dir_tmp=tmp
dir_obj=$(dir_tmp)/obj
dir_lib=lib
all:
$(MAKE) -C consprog -f Makefile.ag
clean:
$(MAKE) -C consprog -f Makefile.ag clean
rm $(dir_lib)/Release/* bin/Release/*
===================
and here is a error mesage from make:
===================
$ make
Makefile:8: *** missing separator. Stop.
===================
Can you say me, where I’m wrong, and how I can fully enjoy this coolest script for the moment?
OOps, here a solution:
> The problem is that that white space at the start of line 8
> *must* be a TAB character, not ordinary spaces.
>
THANKS!
Dear fvicente,
Thanks for the tool, I am in great need of it but I have no python skills, and cannot resolve this error. Can you help? THANKS !
python sln2make.py
Traceback (most recent call last):
File “sln2make.py”, line 449, in ?
Sln2Make(“ug104.sln”, exlist, dirrepl, librepl)
File “sln2make.py”, line 153, in __init__
vcprojContent = self._getFileContent(casedir.correct(proj.path))
File “h:\myapps\ug104\pathcorrect.py”, line 14, in correct
ret = self._correct(file)
File “h:\myapps\ug104\pathcorrect.py”, line 22, in _correct
dir = self.correct(dir)
File “h:\myapps\ug104\pathcorrect.py”, line 14, in correct
ret = self._correct(file)
File “h:\myapps\ug104\pathcorrect.py”, line 22, in _correct
dir = self.correct(dir)
File “h:\myapps\ug104\pathcorrect.py”, line 14, in correct
ret = self._correct(file)
File “h:\myapps\ug104\pathcorrect.py”, line 22, in _correct
dir = self.correct(dir)
File “h:\myapps\ug104\pathcorrect.py”, line 14, in correct
ret = self._correct(file)
File “h:\myapps\ug104\pathcorrect.py”, line 22, in _correct
dir = self.correct(dir)
File “h:\myapps\ug104\pathcorrect.py”, line 14, in correct
ret = self._correct(file)
File “h:\myapps\ug104\pathcorrect.py”, line 28, in _correct
file = files[map(self.hash, files).index(self.hash(file))]
ValueError: list.index(x): x not in list
Hi kperlotto,
this seems to happen when the PathCorrent can not find the file, so make sure that ”ug104.sln” exist in the same directory of sln2make remember that you can use a relative path e.g. “..\\xxx\\ug104.sln”. Best regards.
I have the same problem as
kperlotto on February 27th, 2009 at 11:36 am
No matter what I do, it fails in the same fashion
C:\cwtrunk\tools\Sln2Make>c:\Python25\python sln2make.py ..\..\cwtrunk\sw\TCU-Co
mm\COM-provider\TcuCommProvider.sln
Traceback (most recent call last):
File “sln2make.py”, line 450, in
Sln2Make(sys.argv[1], exlist, dirrepl, librepl)
File “sln2make.py”, line 72, in __init__
file = open(casedir.correct(slnFile),”r”)
File “c:\cwtrunk\tools\Sln2Make\pathcorrect.py”, line 14, in correct
ret = self._correct(file)
File “c:\cwtrunk\tools\Sln2Make\pathcorrect.py”, line 22, in _correct
dir = self.correct(dir)
File “c:\cwtrunk\tools\Sln2Make\pathcorrect.py”, line 14, in correct
ret = self._correct(file)
File “c:\cwtrunk\tools\Sln2Make\pathcorrect.py”, line 22, in _correct
dir = self.correct(dir)
File “c:\cwtrunk\tools\Sln2Make\pathcorrect.py”, line 14, in correct
ret = self._correct(file)
File “c:\cwtrunk\tools\Sln2Make\pathcorrect.py”, line 22, in _correct
dir = self.correct(dir)
File “c:\cwtrunk\tools\Sln2Make\pathcorrect.py”, line 14, in correct
ret = self._correct(file)
File “c:\cwtrunk\tools\Sln2Make\pathcorrect.py”, line 22, in _correct
dir = self.correct(dir)
File “c:\cwtrunk\tools\Sln2Make\pathcorrect.py”, line 14, in correct
ret = self._correct(file)
File “c:\cwtrunk\tools\Sln2Make\pathcorrect.py”, line 28, in _correct
file = files[map(self.hash, files).index(self.hash(file))]
ValueError: list.index(x): x not in list
C:\cwtrunk\tools\Sln2Make>
Hi Craig,
Here is the problem: I didn’t make the script to use as a command line tool… It may sound silly but the reason is that I’m using it in another script in my project.
So instead of passing the path to your .sln as an argument, please open the sln2make.py and modify the last line of the script with the corresponding path.
Fernando.
How do I run the script after putting in the path on the last line?
Hi Adam,
I presume you’re trying to run the script in a Windows environment, so after you modified the last line of the just enter into a command line box and type “python.exe sln2make.py” (without quoting). Of course you must have python interpreter installed.