Drop unused resource strings
[TortoiseGit.git] / ext / OGDF / makeMakefile.py
blob3e764e4471721697e56246d627dd68248c0aa438
1 #!/usr/bin/env python
2 # Make Makefile
4 # Jul 28, 2005
5 # Markus Chimani, markus.chimani@cs.uni-dortmund.de
6 #########################################################
8 import os, sys, fnmatch, ConfigParser, posixpath
10 class versionclass:
11 def call(self):
12 return '$(' + self.var + ')'
13 def library(self):
14 return self.call() + '/' + libName
15 def sharedlibrary(self):
16 return self.call() + '/' + sharedlibName
17 def objects(self):
18 return '$(' +self.var + '_OBJS)'
19 def path(self):
20 return '_' + self.var
22 def bailout(msg):
23 print msg
24 print 'Please use the original makeMakefile.config as a template'
25 sys.exit()
27 def loadConfig(sect, key, noError = False ):
28 if config.has_option(sect, key):
29 v = config.get(sect, key)
30 print ' [', sect, ']', key, '=', v
31 return v
32 else:
33 if noError:
34 return None
35 else:
36 bailout('Option "' + key + '" in section "' + sect + '" is missing')
38 #########################################################
39 # LOAD CONFIGURATION
41 config = ConfigParser.ConfigParser()
42 print 'Loading makeMakefile.config...'
44 try:
45 config.readfp( open('makeMakefile.config') )
46 except IOError:
47 bailout('makeMakefile.config not found')
49 if not config.has_section('GENERAL'):
50 bailout('Section "GENERAL" is missing')
51 if not config.has_section('VERSIONS'):
52 bailout('Section "VERSIONS" is missing')
53 if not config.has_section('COIN'):
54 bailout('Section "COIN" is missing')
55 if not config.has_section('ABACUS'):
56 bailout('Section "ABACUS" is missing')
58 sharedLib = loadConfig('GENERAL', 'sharedLib').startswith('t')
59 libName = loadConfig('GENERAL', 'libName')
60 sharedlibName = loadConfig('GENERAL', 'sharedlibName')
61 compilerCommand = loadConfig('GENERAL', 'compilerCommand')
62 compilerParams = loadConfig('GENERAL', 'compilerParams')
63 libCommand = loadConfig('GENERAL', 'libCommand')
64 sharedlibCommand = loadConfig('GENERAL', 'sharedlibCommand')
65 rmCommand = loadConfig('GENERAL', 'rmCommand')
66 mkdirCommand = loadConfig('GENERAL', 'mkdirCommand')
67 includeLegacyCode = loadConfig('GENERAL', 'includeLegacyCode').startswith('t')
68 useOwnLpSolver = loadConfig('GENERAL', 'useOwnLpSolver').startswith('t')
70 ranlibCommand = loadConfig('GENERAL', 'ranlibCommand', True)
71 if ranlibCommand == None:
72 ranlibCommand = ''
74 gccMessageLength = loadConfig('GENERAL', 'gccMessageLength', True)
75 if gccMessageLength == None:
76 gccMessageLength = ''
77 else:
78 gccMessageLength = '-fmessage-length=' + gccMessageLength
80 compiler = ' '.join( [ compilerCommand, gccMessageLength, compilerParams ] )
82 libs = ''
84 if sharedLib:
85 compiler = ' '.join( [compiler, '-DOGDF_DLL -DOGDF_INSTALL' ] )
86 if sys.platform == 'win32' or sys.platform == 'cygwin':
87 libs = ' '.join( [libs, '-lpsapi'] )
88 else:
89 compiler = ' '.join( [compiler, '-fPIC'] )
91 if useOwnLpSolver:
92 compiler = ' '.join( [compiler, '-DOGDF_OWN_LPSOLVER' ] )
94 useCoin = loadConfig('COIN', 'useCoin').startswith('t')
95 if useCoin:
96 coinIncl = loadConfig('COIN', 'coinIncl')
97 # coinLib = loadConfig('COIN', 'coinLib')
98 solver_name = loadConfig('COIN', 'solver_name')
99 solver_incl = loadConfig('COIN', 'solver_incl')
100 # solver_lib = loadConfig('COIN', 'solver_lib')
101 si2 = ' '
102 if solver_incl.strip() != '':
103 si2 = '-I'+solver_incl
104 compiler = ' '.join( [ compiler, '-I'+coinIncl, si2, '-D'+solver_name, '-DUSE_COIN', ' ' ] )
106 useAbacus = loadConfig('ABACUS', 'useAbacus').startswith('t')
107 if useAbacus:
108 abacusDef = loadConfig('ABACUS', 'abacusDef')
109 abacusIncl = loadConfig('ABACUS', 'abacusIncl')
110 # abacusLib = loadConfig('ABACUS', 'abacusLib')
111 compiler = ' '.join( [ compiler, abacusDef, '-I'+abacusIncl, '-DUSE_ABACUS', ' ' ] )
113 versions = []
114 V = config.items('VERSIONS')
115 if len(V) == 0:
116 bailout('Versions missing')
117 else:
118 for ve in V:
119 v = versionclass()
120 v.var, v.params = ve
121 print ' [ VERSIONS ] Name:', v.var, ', Cmd:',v.params
122 versions.append(v)
124 print 'Resulting compiler call:', compiler
126 print 'Finished loading makeMakefile.config'
128 #########################################################
129 # ANALYZE & GENERATE
131 print 'Analyzing sources & generating Makefile...'
133 makefile = open('Makefile','w')
135 # add header
136 header = open('Makefile.header')
137 headercontent = header.read()
138 header.close()
139 makefile.write(headercontent)
141 # define release & debug
143 for v in versions:
144 makefile.write(v.var + ' = ' + v.path() + '\n')
145 makefile.write('\n');
147 # just the def. nothing happens yet
148 def Walk( curdir ):
150 objs = []
151 names = os.listdir( curdir)
152 names.sort()
154 for name in names:
155 if name.startswith('.') or name.startswith('_') or (name=='legacy' and not includeLegacyCode):
156 continue
158 fullname = posixpath.normpath(posixpath.join(curdir, name))
160 if os.path.isdir(fullname) and not os.path.islink(fullname):
161 objs = objs + Walk( fullname )
162 else:
163 for pat in [ '*.c', '*.cpp' ]:
164 if fnmatch.fnmatch(name, pat):
165 objfullname = fullname[:-len(pat)+2] + 'o'
166 objs.append(objfullname)
168 callForDeps = callForDepsBase + fullname + ' > targetAndDepend'
169 os.system( callForDeps )
170 t = open('targetAndDepend')
171 targetAndDepend = t.read()
172 t.close()
174 for v in versions:
175 # print target&depend: add full path spec, incl. version & ignore extra line
176 path = v.call() + '/' +fullname[:-len(name)]
177 makefile.write(path + targetAndDepend[:-1] + '\n')
179 # ensure folder
180 makefile.write('\t' + mkdirCommand + ' ' + v.call() + '/' + fullname[:-len(name)-1] + '\n')
181 # what to do: call the compiler
182 makefile.write('\t' + compiler + ' ' + v.params + ' -o ' + v.call() + '/' + objfullname + ' -c ' + fullname + '\n\n')
184 # pattern found: don't try other suffix
185 break
186 return objs
188 callForDepsBase = compiler + ' -MM ';
189 if useCoin:
190 callForDepsBase += '-DUSE_COIN -D' + solver_name + ' '
191 if useAbacus:
192 callForDepsBase += '-DUSE_ABACUS -DABACUS_COMPILER_GCC '
194 # Call recursive function
195 objs = Walk( '.' )
196 # Clean up
197 os.system(rmCommand + ' targetAndDepend')
199 # List all Objs for use in lib-generation and clear
200 for v in versions:
201 makefile.write(v.objects()[2:-1] + ' = \\\n')
202 for o in objs:
203 makefile.write(v.call() + '/' + o + ' \\\n')
204 makefile.write('\n')
206 # generate alls and cleans etc...
208 for v in versions:
210 if sharedLib:
211 makefile.write(v.var + ': ' + v.sharedlibrary() + '\n\n')
212 makefile.write(v.sharedlibrary() + ': ' + v.objects() + '\n')
213 makefile.write('\t' + sharedlibCommand + ' -shared -o ' + v.sharedlibrary() + ' ' + v.objects() + ' ' + libs + ' $(LIBS)\n')
215 else:
216 makefile.write(v.var + ': ' + v.library() + '\n\n')
217 makefile.write(v.library() + ': ' + v.objects() + '\n')
218 makefile.write('\t' + libCommand + ' -r ' + v.library() + ' ' + v.objects() + ' $(LIBS)\n')
219 if ranlibCommand != '':
220 makefile.write('\t' + ranlibCommand + ' ' + v.library() + '\n')
222 makefile.write('\n')
223 makefile.write('clean' + v.var + ':\n')
224 # makefile.write('\t' + rmCommand + ' ' + v.objects() + ' ' + v.library() + '\n\n')
225 makefile.write('\t' + rmCommand + ' ' + v.path() + '\n\n')
227 makefile.close()
229 print 'Makefile generated'