#!/bin/env python from sys import * from os import * from string import find, replace # fields are: module name, options difxModules = [ \ [ 'difxio', 'library', 'spice' ], \ [ 'difxmessage', 'library' ], \ [ 'mark5access', 'library' ], \ [ 'vdifio', 'library' ], \ [ 'mpifxcorr', 'mpicxx' ], \ [ 'difx2fits', 'application' ], \ [ 'difx2mark4', 'application' ], \ [ 'calcif2', 'application' ], \ [ 'mk5daemon', 'application' ], \ [ 'difxfilterbank', 'application', 'mpicxx' ], \ [ 'vex2difx', 'application' ], \ [ 'vdif_server', 'application', 'mpicxx' ], \ [ 'vis2screen', 'utility', 'mpicxx' ], \ [ 'difx2profile', 'utility', 'mpicxx' ], \ [ 'calcserver', 'application' ] \ ] def existSubdirs(dir): return path.isdir(dir+'/libraries') and \ path.isdir(dir+'/utilities') and \ path.isdir(dir+'/applications') and \ path.isdir(dir+'/mpifxcorr') def buildDifx(modules): cwd = getcwd() hasSubdirs = existSubdirs(cwd) for m in modules: print '\n\n----- %s -----\n\n' % m[0] if 'norecompile' in m[1:]: print 'Skipping' continue if not hasSubdirs: subDir = '' elif 'library' in m[1:]: subDir = 'libraries/' elif 'application' in m[1:]: subDir = 'applications/' elif 'utility' in m[1:]: subDir = 'utilities/' else: subDir = '' newDir = cwd + '/' + subDir + m[0] try: chdir(newDir) except OSError: print 'Cannot enter %s. Bailing' % newDir break system('make -j 3') system('make install') chdir(cwd) print '\n\n----- ALL DONE -----\n' def makeDifxBuildDir(modules, srcDir): cwd = getcwd() difxroot = getenv('DIFXROOT') if difxroot == None: print 'DIFXROOT not defined. Quitting.' return mpicxx = getenv('MPICXX') if mpicxx == None: print 'MPICXX not defined. Quitting.' return buildDir = cwd + '/build' hasSubdirs = existSubdirs(buildDir) for m in modules: print '\n\n----- %s -----\n\n' % m[0] if not hasSubdirs: subDir = '' elif 'library' in m[1:]: subDir = 'libraries/' elif 'application' in m[1:]: subDir = 'applications/' elif 'utility' in m[1:]: subDir = 'utilities/' else: subDir = '' newDir = buildDir + '/' + subDir + m[0] try: makedirs(newDir) except OSError: print 'directory %s already exists' % newDir if 'norecompile' in m[1:]: continue chdir(newDir) if path.isfile('Makefile'): print 'Makefile already exists in %s' % newDir continue extra = '' if 'mpicxx' in m[1:]: extra += ' CXX=%s' % mpicxx if 'heterogeneous' in m[1:]: extra += ' --enable-heterogeneous' # FIXME: add test for spice cmd = '%s/%s/configure --prefix=%s%s' % (srcDir, m[0], difxroot, extra) print 'Configuring with %s\n' % cmd system(cmd) system('make -j 3') system('make install') chdir(cwd) print '\n\n----- ALL DONE -----\n' cwd = getcwd() if find(cwd, '/src/') > 0: f = find(cwd, "/src/") buildDir = getenv("DIFXROOT")+"/build/"+cwd[f+5:] print '\n----- Entering %s -----\n' % buildDir chdir(buildDir) system('make -j 3') system('make install') chdir(cwd) elif len(argv) == 1: buildDifx(difxModules) else: makeDifxBuildDir(difxModules, argv[1])