Subversion Repositories slepc-dev

Rev

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

Rev Author Line No. Line
1377 slepc 1
#
2
#  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1672 slepc 3
#  SLEPc - Scalable Library for Eigenvalue Problem Computations
4
#  Copyright (c) 2002-2009, Universidad Politecnica de Valencia, Spain
1377 slepc 5
#
1672 slepc 6
#  This file is part of SLEPc.
7
#    
8
#  SLEPc is free software: you can redistribute it and/or modify it under  the
9
#  terms of version 3 of the GNU Lesser General Public License as published by
10
#  the Free Software Foundation.
11
#
12
#  SLEPc  is  distributed in the hope that it will be useful, but WITHOUT  ANY
13
#  WARRANTY;  without even the implied warranty of MERCHANTABILITY or  FITNESS
14
#  FOR  A  PARTICULAR PURPOSE. See the GNU Lesser General Public  License  for
15
#  more details.
16
#
17
#  You  should have received a copy of the GNU Lesser General  Public  License
18
#  along with SLEPc. If not, see <http://www.gnu.org/licenses/>.
1377 slepc 19
#  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
20
#
21
 
808 dsic.upv.es!antodo 22
import os
23
import sys
912 dsic.upv.es!antodo 24
import commands
808 dsic.upv.es!antodo 25
 
912 dsic.upv.es!antodo 26
import petscconf
923 dsic.upv.es!antodo 27
import log
1071 slepc 28
 
29
def LinkWithOutput(functions,callbacks,flags):
1100 slepc 30
  code = '#include "petscksp.h"\n'
1072 slepc 31
  code += 'EXTERN_C_BEGIN\n'
860 dsic.upv.es!antodo 32
  for f in functions:
1072 slepc 33
    code += 'EXTERN int\n' + f + '();\n'
34
  code += 'EXTERN_C_END\n'
860 dsic.upv.es!antodo 35
 
808 dsic.upv.es!antodo 36
  for c in callbacks:
1072 slepc 37
    code += 'int '+ c + '() { return 0; } \n'
860 dsic.upv.es!antodo 38
 
1072 slepc 39
  code += 'int main() {\n'
1093 slepc 40
  code += 'PetscInitialize(PETSC_NULL,PETSC_NULL,PETSC_NULL,PETSC_NULL);\n'
1097 slepc 41
  code += 'VecCreate(PETSC_NULL,PETSC_NULL);\n'
42
  code += 'MatCreate(PETSC_NULL,PETSC_NULL);\n'
43
  code += 'KSPCreate(PETSC_NULL,PETSC_NULL);\n'
808 dsic.upv.es!antodo 44
  for f in functions:
1072 slepc 45
    code += f + '();\n'
46
  code += 'return 0;\n}\n'
47
 
48
  os.chdir('config')
49
  cfile = open('checklink.c','w')
50
  cfile.write(code)
808 dsic.upv.es!antodo 51
  cfile.close()
912 dsic.upv.es!antodo 52
  (result, output) = commands.getstatusoutput(petscconf.MAKE + ' checklink TESTFLAGS="'+str.join(' ',flags)+'"')
1239 slepc 53
  if os.path.exists('checklink.o'):
54
    os.unlink('checklink.o')
808 dsic.upv.es!antodo 55
  os.chdir(os.pardir)
56
  if result:
1072 slepc 57
    return (0,code + output)
1071 slepc 58
  else:
1072 slepc 59
    return (1,code + output)  
1071 slepc 60
 
61
def Link(functions,callbacks,flags):
62
  (result, output) = LinkWithOutput(functions,callbacks,flags)
1072 slepc 63
  log.Write(output)
1071 slepc 64
  return result
808 dsic.upv.es!antodo 65
 
912 dsic.upv.es!antodo 66
def FortranLink(functions,callbacks,flags):
1072 slepc 67
  output =  '\n=== With linker flags: '+str.join(' ',flags)
1071 slepc 68
 
808 dsic.upv.es!antodo 69
  f = []
70
  for i in functions:
71
    f.append(i+'_')
72
  c = []
73
  for i in callbacks:
1071 slepc 74
    c.append(i+'_')
75
  (result, output1) = LinkWithOutput(f,c,flags)
1072 slepc 76
  output1 = '\n====== With underscore Fortran names\n' + output1
77
  if result: return ('UNDERSCORE',output1)
1071 slepc 78
 
808 dsic.upv.es!antodo 79
  f = []
80
  for i in functions:
81
    f.append(i.upper())
82
  c = []
83
  for i in callbacks:
84
    c.append(i.upper())  
1071 slepc 85
  (result, output2) = LinkWithOutput(f,c,flags)
1072 slepc 86
  output2 = '\n====== With capital Fortran names\n' + output2
87
  if result: return ('CAPS',output2)
808 dsic.upv.es!antodo 88
 
1071 slepc 89
  (result, output3) = LinkWithOutput(functions,callbacks,flags)
1072 slepc 90
  output3 = '\n====== With unmodified Fortran names\n' + output3
91
  if result: return ('STDCALL',output3)
1071 slepc 92
 
1072 slepc 93
  return ('',output + output1 + output2 + output3)
1071 slepc 94
 
912 dsic.upv.es!antodo 95
def GenerateGuesses(name):
808 dsic.upv.es!antodo 96
  installdirs = ['/usr/local','/opt']
97
  if 'HOME' in os.environ:
98
    installdirs.insert(0,os.environ['HOME'])
99
 
100
  dirs = []
101
  for i in installdirs:
102
    dirs = dirs + [i + '/lib']
103
    for d in [name,name.upper(),name.lower()]:
104
      dirs = dirs + [i + '/' + d]
105
      dirs = dirs + [i + '/' + d + '/lib']
106
      dirs = dirs + [i + '/lib/' + d]
107
 
860 dsic.upv.es!antodo 108
  for d in dirs[:]:
808 dsic.upv.es!antodo 109
    if not os.path.exists(d):
110
      dirs.remove(d)
111
  dirs = [''] + dirs
112
  return dirs
113
 
912 dsic.upv.es!antodo 114
def FortranLib(conf,name,dirs,libs,functions,callbacks = []):
1072 slepc 115
  log.Write('='*80)
923 dsic.upv.es!antodo 116
  log.Println('Checking '+name+' library...')
912 dsic.upv.es!antodo 117
 
1071 slepc 118
  error = ''
119
  mangling = ''
808 dsic.upv.es!antodo 120
  for d in dirs:
121
    for l in libs:
122
      if d:
123
        flags = ['-L' + d] + l
124
      else:
125
        flags = l
1071 slepc 126
      (mangling, output) = FortranLink(functions,callbacks,flags)
127
      error += output
808 dsic.upv.es!antodo 128
      if mangling: break
129
    if mangling: break    
130
 
1072 slepc 131
  if mangling:
1105 slepc 132
    log.Write(output)
1072 slepc 133
  else:
1105 slepc 134
    log.Write(error)
135
    log.Println('ERROR: Unable to link with library '+ name)
912 dsic.upv.es!antodo 136
    print 'ERROR: In directories',dirs
1105 slepc 137
    print 'ERROR: With flags',libs,
138
    log.Exit('')
912 dsic.upv.es!antodo 139
 
808 dsic.upv.es!antodo 140
 
141
  conf.write('SLEPC_HAVE_' + name + ' = -DSLEPC_HAVE_' + name + ' -DSLEPC_' + name + '_HAVE_'+mangling+'\n')
142
  conf.write(name + '_LIB = '+str.join(' ',flags)+'\n')
1071 slepc 143
  return flags