#!/usr/bin/env python3 import sys import os import tarfile import time import datetime import subprocess from shutil import copy2,move,copyfile def autotools_install_options(conffile, confsteps, HAVE_FORTRAN): makecmd = [] conffile.write('###################################################################\n') for confs in confsteps: for k,v in confs.items(): makecmd.append('-%s' % (v)) conffile.write(' -%s' % (v)) conffile.write('\n###################################################################\n') return makecmd def autotools_options(project_src, conffile, slaveos, confsteps, installfolder, HAVE_FORTRAN, HAVE_CXX, HAVE_JAVA, SHARED): project_configureFlags = [project_src + '/configure'] conffile.write('###################################################################\n') for confs in confsteps: k = confs v = confsteps[k] if 'fortran' == k.lower(): if 'enable' == v.lower(): if 'OFF' == HAVE_FORTRAN: project_configureFlags.append('--disable-{}'.format(k)) conffile.write(' --disable-fortran') else: project_configureFlags.append('--enable-{}'.format(k)) conffile.write(' --enable-fortran') else: project_configureFlags.append('--disable-{}'.format(k)) conffile.write(' --disable-fortran') elif 'cxx' == k.lower(): if 'enable' == v.lower(): if 'OFF' == HAVE_CXX: project_configureFlags.append('--disable-{}'.format(k)) conffile.write(' --disable-cxx') else: project_configureFlags.append('--enable-{}'.format(k)) conffile.write(' --enable-cxx') else: project_configureFlags.append('--disable-{}'.format(k)) conffile.write(' --disable-cxx') elif 'java' == k.lower(): if 'enable' == v.lower(): if 'OFF' == HAVE_JAVA: project_configureFlags.append('--disable-{}'.format(k)) conffile.write(' --disable-java') else: project_configureFlags.append('--enable-{}'.format(k)) conffile.write(' --enable-java') else: project_configureFlags.append('--disable-{}'.format(k)) conffile.write(' --disable-java') elif 'shared' == k.lower(): if 'enable' == v.lower(): SHARED = 'enable' else: SHARED = 'disable' project_configureFlags.append('--{}-{}'.format(v,k)) conffile.write(' --{}-{}'.format(v,k)) print ('SHARED was set in autotools_options to {}'.format(SHARED)) elif k.startswith('with'): if k.lower() in ['with-zlib','with-jpeg','with-szlib']: for vos in v: x = v[vos] if slaveos in x: sv = x[slaveos] project_configureFlags.append('--{}={}'.format(k,sv)) conffile.write(' --{}={}'.format(k,sv)) elif 'any' in vos: project_configureFlags.append('--{}={}'.format(k,installfolder)) conffile.write(' --{}={}'.format(k,installfolder)) elif 'disable' in vos: project_configureFlags.append('--{}=no'.format(k)) conffile.write(' --{}=no'.format(k)) else: project_configureFlags.append('--{}'.format(k)) conffile.write(' --{}'.format(k)) elif 'libdir' == k.lower(): project_configureFlags.append('--{}={}'.format(k,v)) conffile.write(' --{}={}'.format(k,v)) else: project_configureFlags.append('--{}-{}'.format(v,k)) conffile.write(' --{}-{}'.format(v,k)) project_configureFlags.append('--prefix={}'.format(installfolder)) conffile.write(' --prefix={}'.format(installfolder)) conffile.write('\n###################################################################\n') return project_configureFlags, SHARED def autotools_make_options(conffile, confsteps): makecmd = [] conffile.write('###################################################################\n') for confs in confsteps: k = confs v = confsteps[k] makecmd.append(' -{}'.format(v)) conffile.write(' -{}'.format(v)) conffile.write('\n###################################################################\n') return makecmd def autotools_check_options(conffile, confsteps): makecmd = [] conffile.write('###################################################################\n') for confs in confsteps: k = confs v = confsteps[k] makecmd.append(' {}'.format(k)) conffile.write(' {}'.format(k)) conffile.write('\n###################################################################\n') return makecmd def autotools_externallibs(scriptdir, project_src, slaveos, externallibs, installfolder, my_env, SHARED): project_ELibs = [project_src + 'ELibs'] currdir=os.getcwd() print ('current directory in autotools_externallibs: {}'.format(currdir)) extralibsdir = '{}/extralibs'.format(scriptdir) if os.path.exists(extralibsdir): os.system('rm -rf {}'.format(extralibsdir)) os.mkdir(extralibsdir) os.chdir(extralibsdir) print ('install directory for externallibs = {}'.format(installfolder)) print ('Configuration for external libs: {}'.format(SHARED)) for libs in externallibs: output = '' k = libs v = externallibs[k] if k.startswith('with'): if k.lower() in ['with-zlib','with-szlib','with-jpeg']: alib = k[5:] #find tar file for alib #copy it to extralibs #extract textout = '' texterr = '' if 'zlib' == alib.lower(): print ('Move, extract and build zlib if it is available.') if os.path.exists('{}/ZLib.tar.gz'.format(scriptdir)): copyfile('{}/ZLib.tar.gz'.format(scriptdir), '{}/ZLib.tar.gz'.format(extralibsdir)) cf = tarfile.open('ZLib.tar.gz', 'r:gz') cf.extractall() cf.close() os.chdir('ZLib') starttime = time.time() startdatetime = datetime.datetime.now() if 'disable' == SHARED: configurecommand=['./configure', '--static', '--prefix=' + installfolder] else: configurecommand=['./configure', '--prefix=' + installfolder] try: print ('Using this configure command for external lib: {}'.format(configurecommand)) test = subprocess.Popen(configurecommand, shell=False, env=my_env, universal_newlines=True) (textout, texterr) = test.communicate() thereturncode = test.returncode except Exception as e: print('Popen zlib configure Exception: {}'.format(e)) try: if textout is not None: output = '{}{}\n'.format(output, textout) if texterr is not None: output = '{} \n{}'.format(output, texterr) print(output) except Exception as e: print('Popen zlib configure output Exception: {}'.format(e)) starttime = time.time() startdatetime = datetime.datetime.now() makecommand=['make'] try: test = subprocess.Popen(makecommand, shell=False, stderr=subprocess.PIPE, env=my_env, universal_newlines=True) (textout, texterr) = test.communicate() thereturncode = test.returncode except Exception as e: print('Popen zlib make Exception: {}'.format(e)) try: if textout is not None: output = '{}{}\n'.format(output, textout) if texterr is not None: output = '{} \n{}'.format(output, texterr) print(output) except Exception as e: print('Popen zlib make output Exception: {}'.format(e)) # make install installcommand=['make', 'install'] try: test = subprocess.Popen(installcommand, shell=False, stderr=subprocess.PIPE, env=my_env, universal_newlines=True) (textout, texterr) = test.communicate() thereturncode = test.returncode except Exception as e: print('Popen zlib install Exception: {}'.format(e)) try: if textout is not None: output = '{}{}\n'.format(output, textout) if texterr is not None: output = '{} \n{}'.format(output, texterr) print(output) except Exception as e: print('Popen zlib install output Exception: {}'.format(e)) os.chdir('..') #### elif 'szlib' == alib.lower(): print ('Move, extract and build szip if it is available.') if os.path.exists('{}/SZip.tar.gz'.format(scriptdir)): copyfile('{}/SZip.tar.gz'.format(scriptdir), '{}/SZip.tar.gz'.format(extralibsdir)) cf = tarfile.open('SZip.tar.gz', 'r:gz') cf.extractall() cf.close() os.chdir('SZip') starttime = time.time() startdatetime = datetime.datetime.now() if 'disable' == SHARED: configurecommand=['./configure', '--disable-shared', '--prefix=' + installfolder] else: configurecommand=['./configure', '--prefix=' + installfolder] try: test = subprocess.Popen(configurecommand, shell=False, env=my_env, universal_newlines=True) (textout, texterr) = test.communicate() thereturncode = test.returncode except Exception as e: print('Popen szip configure Exception: {}'.format(e)) try: if textout is not None: output = '{}{}\n'.format(output, textout) if texterr is not None: output = '{} \n{}'.format(output, texterr) print(output) except Exception as e: print('Popen szip configure output Exception: {}'.format(e)) starttime = time.time() startdatetime = datetime.datetime.now() makecommand=['make'] try: test = subprocess.Popen(makecommand, shell=False, stderr=subprocess.PIPE, env=my_env, universal_newlines=True) (textout, texterr) = test.communicate() thereturncode = test.returncode except Exception as e: print('Popen szip make Exception: {}'.format(e)) try: if textout is not None: output = '{}{}\n'.format(output, textout) if texterr is not None: output = '{} \n{}'.format(output, texterr) print(output) except Exception as e: print('Popen szip make output Exception: {}'.format(e)) # make install installcommand=['make', 'install'] try: test = subprocess.Popen(installcommand, shell=False, stderr=subprocess.PIPE, env=my_env, universal_newlines=True) (textout, texterr) = test.communicate() thereturncode = test.returncode except Exception as e: print('Popen szip install Exception: {}'.format(e)) try: if textout is not None: output = '{}{}\n'.format(output, textout) if texterr is not None: output = '{} \n{}'.format(output, texterr) print(output) except Exception as e: print('Popen szip install output Exception: {}'.format(e)) os.chdir('..') #### elif 'jpeg' == alib.lower(): print ('Move, extract and build jpeg if it is available.') if os.path.exists('{}/JPEG.tar.gz'.format(scriptdir)): copyfile('{}/JPEG.tar.gz'.format(scriptdir), '{}/JPEG.tar.gz'.format(extralibsdir)) cf = tarfile.open('JPEG.tar.gz', 'r:gz') cf.extractall() cf.close() os.chdir('JPEG') starttime = time.time() startdatetime = datetime.datetime.now() if 'disable' == SHARED: configurecommand=['./configure', '--disable-shared', '--prefix=' + installfolder] else: configurecommand=['./configure', '--prefix=' + installfolder] try: test = subprocess.Popen(configurecommand, shell=False, env=my_env, universal_newlines=True) (textout, texterr) = test.communicate() thereturncode = test.returncode except Exception as e: print('Popen jpeg configure Exception: {}'.format(e)) try: if textout is not None: output = '{}{}\n'.format(output, textout) if texterr is not None: output = '{} \n{}'.format(output, texterr) print(output) except Exception as e: print('Popen jpeg configure output Exception: {}'.format(e)) starttime = time.time() startdatetime = datetime.datetime.now() makecommand=['make'] try: test = subprocess.Popen(makecommand, shell=False, stderr=subprocess.PIPE, env=my_env, universal_newlines=True) (textout, texterr) = test.communicate() thereturncode = test.returncode except Exception as e: print('Popen jpeg make Exception: {}'.format(e)) try: if textout is not None: output = '{}{}\n'.format(output, textout) if texterr is not None: output = '{} \n{}'.format(output, texterr) print(output) except Exception as e: print('Popen jpeg make output Exception: {}'.format(e)) # make install installcommand=['make', 'install'] try: test = subprocess.Popen(installcommand, shell=False, stderr=subprocess.PIPE, env=my_env, universal_newlines=True) (textout, texterr) = test.communicate() thereturncode = test.returncode except Exception as e: print('Popen jpeg install Exception: {}'.format(e)) try: if textout is not None: output = '{}{}\n'.format(output, textout) if texterr is not None: output = '{} \n{}'.format(output, texterr) print(output) except Exception as e: print('Popen jpeg install output Exception: {}'.format(e)) os.chdir('..') #### project_ELibs.append('{}'.format(alib)) print ('Current external libs: {}'.format(project_ELibs)) os.chdir(currdir) print ('Changed directory before exiting autotools_externallibs function to {}'.format(currdir)) return project_ELibs