Last active
December 23, 2015 08:09
-
-
Save inequation/6605530 to your computer and use it in GitHub Desktop.
A tool to extract file names from Visual Studio project files to makefile includes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
import os | |
if (len(sys.argv) < 3): | |
print("Usage: {0} <VC++ project file> <output directory>".format(sys.argv[0])) | |
exit() | |
f = open(sys.argv[1], 'r') | |
sources = [] | |
headers = [] | |
others = [] | |
line = 'foo' | |
while (line != ''): | |
line = f.readline().strip() | |
if (line.startswith('<ClCompile Include')): | |
leading = line.find('\"') + 1 | |
closing = line.find('\"', leading) | |
sources.append(line[leading:closing].replace('\\', '/')) | |
elif (line.startswith('<ClInclude Include')): | |
leading = line.find('\"') + 1 | |
closing = line.find('\"', leading) | |
headers.append(line[leading:closing].replace('\\', '/')) | |
elif (line.startswith('<None Include')): | |
leading = line.find('\"') + 1 | |
closing = line.find('\"', leading) | |
others.append(line[leading:closing].replace('\\', '/')) | |
f.close() | |
#print(sources) | |
#print(headers) | |
#print(others) | |
f = open(os.path.join(sys.argv[2], 'sources.mk'), 'w') | |
for s in sources: | |
if (s.endswith('.cpp') or s.endswith('.cxx')): | |
f.write('CPP_SOURCES+={0}\n'.format(s)) | |
elif (s.endswith('.c')): | |
f.write('C_SOURCES+={0}\n'.format(s)) | |
else: | |
f.write('MISC_SOURCES+={0}\n'.format(s)) | |
f.close() | |
f = open(os.path.join(sys.argv[2], 'headers.mk'), 'w') | |
for h in headers: | |
f.write('HEADERS+={0}\n'.format(h)) | |
f.close() | |
f = open(os.path.join(sys.argv[2], 'others.mk'), 'w') | |
for o in others: | |
f.write('OTHERS+={0}\n'.format(o)) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment