xref: /petsc/config/BuildSystem/config/packages/fblaslapack.py (revision 7b5fd022a6ba26727040df7457b27566b4c6742d)
1import config.package
2
3class Configure(config.package.Package):
4  def __init__(self, framework):
5    config.package.Package.__init__(self, framework)
6    self.gitcommit              = 'v3.4.2-p3'
7    self.download               = ['git://https://bitbucket.org/petsc/pkg-fblaslapack','https://bitbucket.org/petsc/pkg-fblaslapack/get/'+self.gitcommit+'.tar.gz']
8    self.downloaddirnames       = ['petsc-pkg-fblaslapack']
9    self.precisions             = ['single','double']
10    self.downloadonWindows      = 1
11    self.skippackagewithoptions = 1
12    self.buildLanguages         = ['FC']
13
14  def setupDependencies(self, framework):
15    config.package.Package.setupDependencies(self, framework)
16    return
17
18  def configureLibrary(self):
19    if self.argDB['with-64-bit-blas-indices']:
20      raise RuntimeError('fblaslapack does not support -with-64-bit-blas-indices')
21    if hasattr(self.argDB,'known-64-bit-blas-indices') and self.argDB['known-64-bit-blas-indices']:
22      raise RuntimeError('fblaslapack does not support -known-64-bit-blas-indices')
23    config.package.Package.configureLibrary(self)
24
25  def Install(self):
26    import os
27
28    libdir = self.libDir
29    confdir = self.confDir
30    blasDir = self.packageDir
31
32    g = open(os.path.join(blasDir,'tmpmakefile'),'w')
33    f = open(os.path.join(blasDir,'makefile'),'r')
34    line = f.readline()
35    while line:
36      if line.startswith('CC  '):
37        cc = self.compilers.CC
38        line = 'CC = '+cc+'\n'
39      if line.startswith('COPTFLAGS '):
40        self.pushLanguage('C')
41        line = 'COPTFLAGS  = '+self.getCompilerFlags()
42        noopt = self.checkNoOptFlag()
43        self.popLanguage()
44      if line.startswith('CNOOPT'):
45        self.pushLanguage('C')
46        line = 'CNOOPT = '+noopt+ ' '+self.getSharedFlag(self.getCompilerFlags())+' '+self.getPointerSizeFlag(self.getCompilerFlags())+' '+self.getWindowsNonOptFlags(self.getCompilerFlags())
47        self.popLanguage()
48      if line.startswith('FC  '):
49        fc = self.compilers.FC
50        if fc.find('f90') >= 0 or fc.find('f95') >=0:
51          if config.setCompilers.Configure.isIBM(fc, self.log):
52            fc = os.path.join(os.path.dirname(fc),'xlf')
53            self.log.write('Using IBM f90 compiler, switching to xlf for compiling BLAS/LAPACK\n')
54        line = 'FC = '+fc+'\n'
55      if line.startswith('FOPTFLAGS '):
56        self.pushLanguage('FC')
57        line = 'FOPTFLAGS  = '+self.updatePackageFFlags(self.getCompilerFlags())+'\n'
58        noopt = self.checkNoOptFlag()
59        self.popLanguage()
60      if line.startswith('FNOOPT'):
61        self.pushLanguage('FC')
62        line = 'FNOOPT = '+noopt+' '+self.getSharedFlag(self.getCompilerFlags())+' '+self.getPointerSizeFlag(self.getCompilerFlags())+' '+self.getWindowsNonOptFlags(self.getCompilerFlags())+' '+self.updatePackageFFlags('')+'\n'
63        self.popLanguage()
64      if line.startswith('AR  '):
65        line = 'AR      = '+self.setCompilers.AR+'\n'
66      if line.startswith('AR_FLAGS  '):
67        line = 'AR_FLAGS      = '+self.setCompilers.AR_FLAGS+'\n'
68      if line.startswith('LIB_SUFFIX '):
69        line = 'LIB_SUFFIX = '+self.setCompilers.AR_LIB_SUFFIX+'\n'
70      if line.startswith('RANLIB  '):
71        line = 'RANLIB = '+self.setCompilers.RANLIB+'\n'
72      if line.startswith('RM  '):
73        line = 'RM = '+self.programs.RM+'\n'
74      if line.startswith('OMAKE  '):
75        line = 'OMAKE = '+self.make.make+'\n'
76
77      if line.startswith('include'):
78        line = '\n'
79      if line.find("-no-prec-div") >= 1:
80         raise RuntimeError('Some versions of the Intel compiler generate incorrect code on fblaslapack with the option -no-prec-div\nRun configure without this option')
81      g.write(line)
82      line = f.readline()
83    f.close()
84    g.close()
85
86    if not self.installNeeded('tmpmakefile'): return self.installDir
87
88    try:
89      self.logPrintBox('Compiling FBLASLAPACK; this may take several minutes')
90      output1,err1,ret  = config.package.Package.executeShellCommand('cd '+blasDir+' && rm -rf */*.c && make -f tmpmakefile cleanblaslapck cleanlib && '+self.make.make_jnp+' -f tmpmakefile', timeout=2500, log = self.log)
91    except RuntimeError as e:
92      self.logPrint('Error running make on '+blasDir+': '+str(e))
93      raise RuntimeError('Error running make on '+blasDir)
94    try:
95      output2,err2,ret  = config.package.Package.executeShellCommand('cd '+blasDir+' && mkdir -p '+libdir+' && cp -f libfblas.'+self.setCompilers.AR_LIB_SUFFIX+' libflapack.'+self.setCompilers.AR_LIB_SUFFIX+' '+ libdir, timeout=300, log = self.log)
96    except RuntimeError as e:
97      self.logPrint('Error moving '+blasDir+' libraries: '+str(e))
98      raise RuntimeError('Error moving '+blasDir+' libraries')
99    self.postInstall(output1+err1+output2+err2,'tmpmakefile')
100    return self.installDir
101