Fix if clauses which are always false
[TortoiseGit.git] / ext / OGDF / makeVCXProj.py
blob5e0a00db14e7da3ab2aca3900147701feb7de461
1 #!/usr/bin/env python
2 # Make VCXProj
4 # May 2010
5 # Markus Chimani, markus.chimani@cs.tu-dortmund.de
6 # Carsten Gutwenger, carsten.gutwenger@cs.tu-dortmund.de
7 #########################################################
10 import os, sys, fnmatch, ConfigParser
12 class stuff:
13 def __init__(self, ttag, tpath, tpats, tcommand, tfilter):
14 self.tag, self.path, self.pats, self.command, self.filter = ttag, tpath, tpats, tcommand, tfilter
16 def bailout(msg):
17 print msg
18 print 'Please use the original makeVCXProj.config as a template'
19 sys.exit()
21 def loadConfig(sect, key, noError = False ):
22 if config.has_option(sect, key):
23 v = config.get(sect, key)
24 print ' [', sect, ']', key, '=', v
25 return v
26 else:
27 if noError:
28 return None
29 else:
30 bailout('Option "' + key + '" in section "' + sect + '" is missing')
32 #########################################################
33 # LOAD CONFIGURATION
35 config = ConfigParser.ConfigParser()
37 makecfg = 'makeVCXProj.config'
38 for x in sys.argv[1:]:
39 if x[:7] == "config=":
40 makecfg = x[7:]
42 print 'Loading ' + makecfg + '...'
44 try:
45 config.readfp( open(makecfg))
46 except IOError:
47 bailout(makecfg + ' not found')
49 if not config.has_section('GENERAL'):
50 bailout('Section "GENERAL" is missing')
51 if not config.has_section('COIN'):
52 bailout('Section "COIN" is missing')
54 #########################################################
55 # CONFIGS
57 # Filenames
58 filename_vcxproj = loadConfig('GENERAL', 'projectFile')
59 filename_template = loadConfig('GENERAL', 'templateFile')
60 filename_vcxfilters = loadConfig('GENERAL', 'projectFiltersFile')
61 filename_template_filters = loadConfig('GENERAL', 'templateFiltersFile')
62 addIncludes = ''
63 addDefines = ''
64 addLibs = ''
65 addLibPathsDebugWin32 = ''
66 addLibPathsReleaseWin32 = ''
67 addLibPathsDebugX64 = ''
68 addLibPathsReleaseX64 = ''
70 useOwnLpSolver = loadConfig('GENERAL', 'useOwnLpSolver', 'false').startswith('t')
71 if useOwnLpSolver:
72 addDefines += 'OGDF_OWN_LPSOLVER;'
74 useCoin = loadConfig('COIN', 'useCoin').startswith('t')
75 if useCoin:
76 coinIncl = loadConfig('COIN', 'coinIncl')
77 coinLib = loadConfig('COIN', 'coinLib')
78 solver_name = loadConfig('COIN', 'solver_name')
79 solver_incl = loadConfig('COIN', 'solver_incl')
81 addDefines += 'USE_COIN;'+solver_name+';'
82 addIncludes += coinIncl+';'
83 if solver_incl.strip() != '':
84 addIncludes += solver_incl+';'
85 addLibs += 'libCoinUtils.lib libOsi.lib '
86 addLibs += 'libClp.lib libOsiClp.lib '
87 addLibPathsDebugWin32 += coinLib+'/win32/Debug;'
88 addLibPathsReleaseWin32 += coinLib+'/win32/Release;'
89 addLibPathsDebugX64 += coinLib+'/x64/Debug;'
90 addLibPathsReleaseX64 += coinLib+'/x64/Release;'
92 addDefines = addDefines[:-1]
93 addIncludes = addIncludes[:-1]
94 addLibs = addLibs[:-1]
95 addLibPathsDebugWin32 = addLibPathsDebugWin32[:-1]
96 addLibPathsReleaseWin32 = addLibPathsReleaseWin32[:-1]
97 addLibPathsDebugX64 = addLibPathsDebugX64[:-1]
98 addLibPathsReleaseX64 = addLibPathsReleaseX64[:-1]
99 defineTag = '<<DEFINETAG>>'
100 includeTag = '<<INCLUDETAG>>'
101 libTag = '<<LIBTAG>>'
102 libPathsTagDebugWin32 = '<<LIBPATHSDEBUGWIN32TAG>>'
103 libPathsTagReleaseWin32 = '<<LIBPATHSRELEASEWIN32TAG>>'
104 libPathsTagDebugX64 = '<<LIBPATHSDEBUGX64TAG>>'
105 libPathsTagReleaseX64 = '<<LIBPATHSRELEASEX64TAG>>'
106 filtersTag = '<<FTAG>>'
108 # Params are:
109 # - Tag in template-File
110 # - Directory to start search & subfilters from
111 # - File Patterns
112 cppStuff = stuff( '<<CPPTAG>>', 'src', [ '*.c', '*.cpp' ], 'ClCompile', 'Source Files' )
113 hStuff = stuff( '<<HTAG>>', 'ogdf', [ '*.h' ], 'ClInclude', 'Header Files' )
114 hLegacyStuff = stuff( '<<HLEGACYTAG>>', 'ogdf_legacy', [ '*.h' ], 'ClInclude', 'Header Files Legacy' )
116 includeStuff = stuff
118 stuff = [ cppStuff, hStuff, hLegacyStuff ]
121 #########################################################
122 #########################################################
123 ## only code below...
125 # just the def. nothing happens yet
126 def Walk( curdir, pats, command ):
127 names = os.listdir( curdir)
128 names.sort()
130 for name in names:
131 if name.startswith('.') or name.startswith('_') or (name=='legacy' and not includeLegacyCode):
132 continue
134 outpath = curdir + '\\' + name
135 fullname = os.path.normpath(outpath)
137 if os.path.isdir(fullname) and not os.path.islink(fullname):
138 Walk( outpath, pats, command)
139 else:
140 for pat in pats:
141 if fnmatch.fnmatch(name, pat):
142 vcxproj.write(' <' + command + ' Include="' + outpath + '" />\n')
144 def WalkFilterFiles( curdir, pats, command, filter ):
145 names = os.listdir( curdir)
146 names.sort()
148 for name in names:
149 if name.startswith('.') or name.startswith('_') or (name=='legacy' and not includeLegacyCode):
150 continue
152 outpath = curdir + '\\' + name
153 fullname = os.path.normpath(outpath)
155 if os.path.isdir(fullname) and not os.path.islink(fullname):
156 WalkFilterFiles( outpath, pats, command, filter + '\\' + name )
157 else:
158 for pat in pats:
159 if fnmatch.fnmatch(name, pat):
160 vcxfilters.write(' <' + command + ' Include="' + outpath + '">\n')
161 vcxfilters.write(' <Filter>' + filter + '</Filter>\n')
162 vcxfilters.write(' </' + command + '>\n')
164 def WalkFilters( curdir, filter ):
165 names = os.listdir( curdir)
166 names.sort()
168 for name in names:
169 if name.startswith('.') or name.startswith('_') or (name=='legacy' and not includeLegacyCode):
170 continue
172 outpath = curdir + '\\' + name
173 fullname = os.path.normpath(outpath)
175 if os.path.isdir(fullname) and not os.path.islink(fullname):
176 filtername = filter + '\\' + name
177 vcxfilters.write(' <Filter Include="' + filtername + '">\n')
178 vcxfilters.write(' </Filter>\n')
179 WalkFilters( outpath, filtername )
182 ##########################################
183 ## Main below...
185 print 'Generating VCXProj...'
187 includeLegacyCode = 0;
188 if len(sys.argv)>1 and sys.argv[1]=='legacy':
189 includeLegacyCode = 1
190 print '(including legacy code)'
192 vcxproj = open(filename_vcxproj,'w')
193 template = open(filename_template)
195 check = 0
196 for line in template:
197 if check < len(stuff) and line.find(stuff[check].tag) > -1:
198 if (stuff[check].tag!='<<HLEGACYTAG>>' or includeLegacyCode):
199 Walk(stuff[check].path, stuff[check].pats, stuff[check].command)
200 check = check + 1
201 elif line.find(defineTag) > -1:
202 vcxproj.write(line.replace(defineTag,addDefines,1))
203 elif line.find(includeTag) > -1:
204 vcxproj.write(line.replace(includeTag,addIncludes,1))
205 elif line.find(libTag) > -1:
206 vcxproj.write(line.replace(libTag,addLibs,1))
207 elif line.find(libPathsTagDebugWin32) > -1:
208 vcxproj.write(line.replace(libPathsTagDebugWin32,addLibPathsDebugWin32,1))
209 elif line.find(libPathsTagReleaseWin32) > -1:
210 vcxproj.write(line.replace(libPathsTagReleaseWin32,addLibPathsReleaseWin32,1))
211 elif line.find(libPathsTagDebugX64) > -1:
212 vcxproj.write(line.replace(libPathsTagDebugX64,addLibPathsDebugX64,1))
213 elif line.find(libPathsTagReleaseX64) > -1:
214 vcxproj.write(line.replace(libPathsTagReleaseX64,addLibPathsReleaseX64,1))
215 else:
216 vcxproj.write(line)
218 template.close()
219 vcxproj.close()
221 # Creation of filters file...
223 vcxfilters = open(filename_vcxfilters,'w')
224 template_filters = open(filename_template_filters)
226 check = 0
227 for line in template_filters:
228 if check < len(stuff) and line.find(stuff[check].tag) > -1:
229 if (stuff[check].tag!='<<HLEGACYTAG>>' or includeLegacyCode):
230 WalkFilterFiles(stuff[check].path, stuff[check].pats, stuff[check].command, stuff[check].filter)
231 check = check + 1
232 elif line.find(filtersTag) > -1:
233 for s in stuff:
234 if (s.tag!='<<HLEGACYTAG>>' or includeLegacyCode):
235 WalkFilters(s.path, s.filter)
236 else:
237 vcxfilters.write(line)
240 template_filters.close()
241 vcxfilters.close()
244 print 'VCXProj generated'