| Line 4... |
Line 4... |
|
|
import petscconf
|
import petscconf
|
import log
|
import log
|
|
|
def LinkWithOutput(functions,callbacks,flags):
|
def LinkWithOutput(functions,callbacks,flags):
|
os.chdir('config')
|
code = '#include "petsc.h"\n'
|
cfile = open('checklink.c','w')
|
code += 'EXTERN_C_BEGIN\n'
|
cfile.write('#include "petsc.h"\n')
|
|
|
|
cfile.write('EXTERN_C_BEGIN\n')
|
|
for f in functions:
|
for f in functions:
|
cfile.write('EXTERN int\n')
|
code += 'EXTERN int\n' + f + '();\n'
|
cfile.write(f)
|
code += 'EXTERN_C_END\n'
|
cfile.write('();\n')
|
|
cfile.write('EXTERN_C_END\n')
|
|
|
|
for c in callbacks:
|
for c in callbacks:
|
cfile.write('int ')
|
code += 'int '+ c + '() { return 0; } \n'
|
cfile.write(c)
|
|
cfile.write('() { return 0; } \n')
|
|
|
|
cfile.write('int main() {\n')
|
code += 'int main() {\n'
|
for f in functions:
|
for f in functions:
|
cfile.write(f)
|
code += f + '();\n'
|
cfile.write('();\n')
|
code += 'return 0;\n}\n'
|
cfile.write('return 0;\n}\n')
|
|
|
os.chdir('config')
|
|
cfile = open('checklink.c','w')
|
|
cfile.write(code)
|
cfile.close()
|
cfile.close()
|
(result, output) = commands.getstatusoutput(petscconf.MAKE + ' checklink TESTFLAGS="'+str.join(' ',flags)+'"')
|
(result, output) = commands.getstatusoutput(petscconf.MAKE + ' checklink TESTFLAGS="'+str.join(' ',flags)+'"')
|
os.chdir(os.pardir)
|
os.chdir(os.pardir)
|
if result:
|
if result:
|
return (0, output)
|
return (0,code + output)
|
else:
|
else:
|
return (1, output)
|
return (1,code + output)
|
|
|
def Link(functions,callbacks,flags):
|
def Link(functions,callbacks,flags):
|
(result, output) = LinkWithOutput(functions,callbacks,flags)
|
(result, output) = LinkWithOutput(functions,callbacks,flags)
|
if result == 0:
|
log.Write(output)
|
log.Write(output)
|
|
return result
|
return result
|
|
|
def FortranLink(functions,callbacks,flags):
|
def FortranLink(functions,callbacks,flags):
|
|
output = '\n=== With linker flags: '+str.join(' ',flags)
|
|
|
f = []
|
f = []
|
for i in functions:
|
for i in functions:
|
f.append(i+'_')
|
f.append(i+'_')
|
c = []
|
c = []
|
for i in callbacks:
|
for i in callbacks:
|
c.append(i+'_')
|
c.append(i+'_')
|
(result, output1) = LinkWithOutput(f,c,flags)
|
(result, output1) = LinkWithOutput(f,c,flags)
|
if result: return ('UNDERSCORE','')
|
output1 = '\n====== With underscore Fortran names\n' + output1
|
|
if result: return ('UNDERSCORE',output1)
|
|
|
f = []
|
f = []
|
for i in functions:
|
for i in functions:
|
f.append(i.upper())
|
f.append(i.upper())
|
c = []
|
c = []
|
for i in callbacks:
|
for i in callbacks:
|
c.append(i.upper())
|
c.append(i.upper())
|
(result, output2) = LinkWithOutput(f,c,flags)
|
(result, output2) = LinkWithOutput(f,c,flags)
|
if result: return ('CAPS','')
|
output2 = '\n====== With capital Fortran names\n' + output2
|
|
if result: return ('CAPS',output2)
|
|
|
(result, output3) = LinkWithOutput(functions,callbacks,flags)
|
(result, output3) = LinkWithOutput(functions,callbacks,flags)
|
if result: return ('STDCALL','')
|
output3 = '\n====== With unmodified Fortran names\n' + output3
|
|
if result: return ('STDCALL',output3)
|
|
|
output = '=== With linker flags: '+str.join(' ',flags)
|
return ('',output + output1 + output2 + output3)
|
output += '\n====== With underscore Fortran names\n'
|
|
output += output1
|
|
output += '\n====== With capital Fortran names\n'
|
|
output += output2
|
|
output += '\n====== With unmodified Fortran names\n'
|
|
output += output3+'\n'
|
|
return ('',output)
|
|
|
|
def GenerateGuesses(name):
|
def GenerateGuesses(name):
|
installdirs = ['/usr/local','/opt']
|
installdirs = ['/usr/local','/opt']
|
if 'HOME' in os.environ:
|
if 'HOME' in os.environ:
|
installdirs.insert(0,os.environ['HOME'])
|
installdirs.insert(0,os.environ['HOME'])
|
| Line 91... |
Line 83... |
dirs.remove(d)
|
dirs.remove(d)
|
dirs = [''] + dirs
|
dirs = [''] + dirs
|
return dirs
|
return dirs
|
|
|
def FortranLib(conf,name,dirs,libs,functions,callbacks = []):
|
def FortranLib(conf,name,dirs,libs,functions,callbacks = []):
|
|
log.Write('='*80)
|
log.Println('Checking '+name+' library...')
|
log.Println('Checking '+name+' library...')
|
|
|
error = ''
|
error = ''
|
mangling = ''
|
mangling = ''
|
for d in dirs:
|
for d in dirs:
|
| Line 106... |
Line 99... |
(mangling, output) = FortranLink(functions,callbacks,flags)
|
(mangling, output) = FortranLink(functions,callbacks,flags)
|
error += output
|
error += output
|
if mangling: break
|
if mangling: break
|
if mangling: break
|
if mangling: break
|
|
|
if not mangling:
|
if mangling:
|
|
log.Write(output);
|
|
else:
|
log.Write(error);
|
log.Write(error);
|
print 'ERROR: Unable to link with library',name
|
print 'ERROR: Unable to link with library',name
|
print 'ERROR: In directories',dirs
|
print 'ERROR: In directories',dirs
|
print 'ERROR: With flags',libs
|
print 'ERROR: With flags',libs
|
print 'ERROR: See "configure_log_' + petscconf.ARCH + '" file for details'
|
print 'ERROR: See "configure_log_' + petscconf.ARCH + '" file for details'
|