Subversion Repositories slepc-dev

Rev

Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
808 dsic.upv.es!antodo 1
import os
2
import sys
912 dsic.upv.es!antodo 3
import commands
808 dsic.upv.es!antodo 4
 
912 dsic.upv.es!antodo 5
import petscconf
923 dsic.upv.es!antodo 6
import log
1071 slepc 7
 
8
def LinkWithOutput(functions,callbacks,flags):
1100 slepc 9
  code = '#include "petscksp.h"\n'
1072 slepc 10
  code += 'EXTERN_C_BEGIN\n'
860 dsic.upv.es!antodo 11
  for f in functions:
1072 slepc 12
    code += 'EXTERN int\n' + f + '();\n'
13
  code += 'EXTERN_C_END\n'
860 dsic.upv.es!antodo 14
 
808 dsic.upv.es!antodo 15
  for c in callbacks:
1072 slepc 16
    code += 'int '+ c + '() { return 0; } \n'
860 dsic.upv.es!antodo 17
 
1072 slepc 18
  code += 'int main() {\n'
1093 slepc 19
  code += 'PetscInitialize(PETSC_NULL,PETSC_NULL,PETSC_NULL,PETSC_NULL);\n'
1097 slepc 20
  code += 'VecCreate(PETSC_NULL,PETSC_NULL);\n'
21
  code += 'MatCreate(PETSC_NULL,PETSC_NULL);\n'
22
  code += 'KSPCreate(PETSC_NULL,PETSC_NULL);\n'
808 dsic.upv.es!antodo 23
  for f in functions:
1072 slepc 24
    code += f + '();\n'
25
  code += 'return 0;\n}\n'
26
 
27
  os.chdir('config')
28
  cfile = open('checklink.c','w')
29
  cfile.write(code)
808 dsic.upv.es!antodo 30
  cfile.close()
912 dsic.upv.es!antodo 31
  (result, output) = commands.getstatusoutput(petscconf.MAKE + ' checklink TESTFLAGS="'+str.join(' ',flags)+'"')
1232 slepc 32
  if os.path.exists('checklink.o'):
33
    os.unlink('checklink.o')
808 dsic.upv.es!antodo 34
  os.chdir(os.pardir)
35
  if result:
1072 slepc 36
    return (0,code + output)
1071 slepc 37
  else:
1072 slepc 38
    return (1,code + output)  
1071 slepc 39
 
40
def Link(functions,callbacks,flags):
41
  (result, output) = LinkWithOutput(functions,callbacks,flags)
1072 slepc 42
  log.Write(output)
1071 slepc 43
  return result
808 dsic.upv.es!antodo 44
 
912 dsic.upv.es!antodo 45
def FortranLink(functions,callbacks,flags):
1072 slepc 46
  output =  '\n=== With linker flags: '+str.join(' ',flags)
1071 slepc 47
 
808 dsic.upv.es!antodo 48
  f = []
49
  for i in functions:
50
    f.append(i+'_')
51
  c = []
52
  for i in callbacks:
1071 slepc 53
    c.append(i+'_')
54
  (result, output1) = LinkWithOutput(f,c,flags)
1072 slepc 55
  output1 = '\n====== With underscore Fortran names\n' + output1
56
  if result: return ('UNDERSCORE',output1)
1071 slepc 57
 
808 dsic.upv.es!antodo 58
  f = []
59
  for i in functions:
60
    f.append(i.upper())
61
  c = []
62
  for i in callbacks:
63
    c.append(i.upper())  
1071 slepc 64
  (result, output2) = LinkWithOutput(f,c,flags)
1072 slepc 65
  output2 = '\n====== With capital Fortran names\n' + output2
66
  if result: return ('CAPS',output2)
808 dsic.upv.es!antodo 67
 
1071 slepc 68
  (result, output3) = LinkWithOutput(functions,callbacks,flags)
1072 slepc 69
  output3 = '\n====== With unmodified Fortran names\n' + output3
70
  if result: return ('STDCALL',output3)
1071 slepc 71
 
1072 slepc 72
  return ('',output + output1 + output2 + output3)
1071 slepc 73
 
912 dsic.upv.es!antodo 74
def GenerateGuesses(name):
808 dsic.upv.es!antodo 75
  installdirs = ['/usr/local','/opt']
76
  if 'HOME' in os.environ:
77
    installdirs.insert(0,os.environ['HOME'])
78
 
79
  dirs = []
80
  for i in installdirs:
81
    dirs = dirs + [i + '/lib']
82
    for d in [name,name.upper(),name.lower()]:
83
      dirs = dirs + [i + '/' + d]
84
      dirs = dirs + [i + '/' + d + '/lib']
85
      dirs = dirs + [i + '/lib/' + d]
86
 
860 dsic.upv.es!antodo 87
  for d in dirs[:]:
808 dsic.upv.es!antodo 88
    if not os.path.exists(d):
89
      dirs.remove(d)
90
  dirs = [''] + dirs
91
  return dirs
92
 
912 dsic.upv.es!antodo 93
def FortranLib(conf,name,dirs,libs,functions,callbacks = []):
1072 slepc 94
  log.Write('='*80)
923 dsic.upv.es!antodo 95
  log.Println('Checking '+name+' library...')
912 dsic.upv.es!antodo 96
 
1071 slepc 97
  error = ''
98
  mangling = ''
808 dsic.upv.es!antodo 99
  for d in dirs:
100
    for l in libs:
101
      if d:
102
        flags = ['-L' + d] + l
103
      else:
104
        flags = l
1071 slepc 105
      (mangling, output) = FortranLink(functions,callbacks,flags)
106
      error += output
808 dsic.upv.es!antodo 107
      if mangling: break
108
    if mangling: break    
109
 
1072 slepc 110
  if mangling:
1105 slepc 111
    log.Write(output)
1072 slepc 112
  else:
1105 slepc 113
    log.Write(error)
114
    log.Println('ERROR: Unable to link with library '+ name)
912 dsic.upv.es!antodo 115
    print 'ERROR: In directories',dirs
1105 slepc 116
    print 'ERROR: With flags',libs,
117
    log.Exit('')
912 dsic.upv.es!antodo 118
 
808 dsic.upv.es!antodo 119
 
120
  conf.write('SLEPC_HAVE_' + name + ' = -DSLEPC_HAVE_' + name + ' -DSLEPC_' + name + '_HAVE_'+mangling+'\n')
121
  conf.write(name + '_LIB = '+str.join(' ',flags)+'\n')
1071 slepc 122
  return flags