5 # Markus Chimani, markus.chimani@cs.uni-dortmund.de
6 #########################################################
8 import os
, sys
, fnmatch
, ConfigParser
, posixpath
12 return '$(' + self
.var
+ ')'
14 return self
.call() + '/' + libName
15 def sharedlibrary(self
):
16 return self
.call() + '/' + sharedlibName
18 return '$(' +self
.var
+ '_OBJS)'
24 print 'Please use the original makeMakefile.config as a template'
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
36 bailout('Option "' + key
+ '" in section "' + sect
+ '" is missing')
38 #########################################################
41 config
= ConfigParser
.ConfigParser()
42 print 'Loading makeMakefile.config...'
45 config
.readfp( open('makeMakefile.config') )
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:
74 gccMessageLength
= loadConfig('GENERAL', 'gccMessageLength', True)
75 if gccMessageLength
== None:
78 gccMessageLength
= '-fmessage-length=' + gccMessageLength
80 compiler
= ' '.join( [ compilerCommand
, gccMessageLength
, compilerParams
] )
85 compiler
= ' '.join( [compiler
, '-DOGDF_DLL -DOGDF_INSTALL' ] )
86 if sys
.platform
== 'win32' or sys
.platform
== 'cygwin':
87 libs
= ' '.join( [libs
, '-lpsapi'] )
89 compiler
= ' '.join( [compiler
, '-fPIC'] )
92 compiler
= ' '.join( [compiler
, '-DOGDF_OWN_LPSOLVER' ] )
94 useCoin
= loadConfig('COIN', 'useCoin').startswith('t')
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')
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')
108 abacusDef
= loadConfig('ABACUS', 'abacusDef')
109 abacusIncl
= loadConfig('ABACUS', 'abacusIncl')
110 # abacusLib = loadConfig('ABACUS', 'abacusLib')
111 compiler
= ' '.join( [ compiler
, abacusDef
, '-I'+abacusIncl
, '-DUSE_ABACUS', ' ' ] )
114 V
= config
.items('VERSIONS')
116 bailout('Versions missing')
121 print ' [ VERSIONS ] Name:', v
.var
, ', Cmd:',v
.params
124 print 'Resulting compiler call:', compiler
126 print 'Finished loading makeMakefile.config'
128 #########################################################
131 print 'Analyzing sources & generating Makefile...'
133 makefile
= open('Makefile','w')
136 header
= open('Makefile.header')
137 headercontent
= header
.read()
139 makefile
.write(headercontent
)
141 # define release & debug
144 makefile
.write(v
.var
+ ' = ' + v
.path() + '\n')
145 makefile
.write('\n');
147 # just the def. nothing happens yet
151 names
= os
.listdir( curdir
)
155 if name
.startswith('.') or name
.startswith('_') or (name
=='legacy' and not includeLegacyCode
):
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
)
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()
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')
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
188 callForDepsBase
= compiler
+ ' -MM ';
190 callForDepsBase
+= '-DUSE_COIN -D' + solver_name
+ ' '
192 callForDepsBase
+= '-DUSE_ABACUS -DABACUS_COMPILER_GCC '
194 # Call recursive function
197 os
.system(rmCommand
+ ' targetAndDepend')
199 # List all Objs for use in lib-generation and clear
201 makefile
.write(v
.objects()[2:-1] + ' = \\\n')
203 makefile
.write(v
.call() + '/' + o
+ ' \\\n')
206 # generate alls and cleans etc...
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')
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')
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')
229 print 'Makefile generated'