12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250 |
- """
- * PYCASSO - PYthon Compile And Setup Scripts Organizer *
- INSTALL FOR YOUR APPLICATION
- Assume you have an application named 'yourmodel'.
- To create a compile/setup script for this application,
- copy the template setup script to a name that you and other users
- will recoqnize as the main setup script:
- cp pycasso/py/pycasso_setup_template setup_yourmodel
- Edit the 'Settings' section in this new script to set the location
- of the PYCASSO scripts. Also specify the name of the module file
- with user scripts. If these are in a subdirectory './base/py', use fore example:
- # path to the PYCASSO modules:
- base_py = os.path.join('.','pycasso','py')
- # name of file with PYCASSO user scripts for this setup:
- pycasso_user_scripts = 'pycasso_user_scripts_tm5'
- Copy the template settings file 'pycasso__template.rc'
- to a suitable name:
- cp pycasso/rc/pycasso_template.rc yourmodel.rc
- Edit the settings if necessary, and start with:
- ./setup_yourmodel yourmodel.rc
- LOGGING
- Logging is implemented via the standard python 'logging' module.
-
- By default, one logger is defined that writes to the standard output;
- usually this is the terminal window, but in a batch environment this
- could be redirected to a file.
- In addition, a second logger could be setup if the 'logfile'
- option in the rc file is set.
-
- To add a new message to one of the logs, follow the examples in the code:
- logging.info( 'rc-file read successfully' )
- This would create a log-message of level INFO.
- Other options for log messages are:
- logging.debug (msg) # extra information to debug the scripts
- logging.warning (msg) # warnings about undesired behaviour
- logging.info (msg) # the standard messages
- logging.exception(msg) # something wrong, not fatal
- logging.error (msg) # something wrong, nearly fatal
- logging.critical (msg) # something wrong, probably fatal
- The threshold level for messages to be included is DEBUG for the file output.
- The threshold level for messages to be included is INFO for the screen,
- unless 'options.verbose' is True (set by '-v' or '--verbose' on the
- command line).
- """
- def Main( args, pycasso_user_scripts ) :
- """
- Start the compilation and setup of the application.
- args
- List of unparsed arguments, probalby from 'sys.argv[1:]'.
- pycasso_user_scripts
- Name of file with user scripts for this particular setup.
- """
-
- import sys
- import os
- import exceptions
- import subprocess
- import shutil
- import logging
- import traceback
- import datetime
-
-
- import rc
- import pycasso_tools
-
-
-
-
-
-
- try:
- pycus = __import__( pycasso_user_scripts )
- except ImportError :
- logging.error( 'could not import module : %s' % pycasso_user_scripts )
- logging.error( 'check definition of "pycasso_user_scripts" in "setup" script' )
- raise Exception
- except :
- logging.error( traceback.format_exc() )
- logging.error( 'error in user scripts module ?' )
- logging.error( 'check content of module : %s' % pycasso_user_scripts )
- raise Exception
-
-
-
-
-
-
-
-
-
-
-
- try :
- options,rcfile = ParseArguments( args, pycasso_user_scripts )
- except exceptions.SystemExit :
-
- return
- except :
-
- logging.error( sys.exc_info()[1] )
- logging.error( 'exception from pycasso.Main' )
- raise Exception
-
-
-
-
-
-
- logger = Start_Logger()
-
-
- stdout_handler = Start_StdOut_Log(logger)
-
-
- logging.info( '' )
- tnow = datetime.datetime.now().isoformat(' ').split('.',1)[0]
- logging.info( 'Started script at %s ...' % tnow )
- logging.info( '' )
-
-
- logging.info( 'options and arguments ...' )
- logging.info( ' parsed options : %s' % options )
- logging.info( ' parsed rcfile argument : %s' % rcfile )
-
- owd = os.getcwd()
-
-
-
-
- logging.info( 'read settings from %s ...' % rcfile )
-
-
-
- rcf = rc.RcFile(rcfile, raw=False)
-
-
-
-
-
-
- nx=rcf.get('par.nx', 'int')
- ny=rcf.get('par.ny', 'int')
- if rcf.has_key('par.ntask') :
- rcf.replace('par.ntask',nx*ny)
- else:
- rcf.add('par.ntask',nx*ny)
- rcf.WriteFile( rcfile )
-
-
-
-
- if len(options) == 0 :
-
- logging.info( 'no rcfile settings to be added or changed by options' )
- else :
-
- logging.info( 'change rcfile settings given options ...' )
-
- for key,val in options.iteritems() :
-
- if rcf.has_key(key) :
-
- logging.info( ' reset "%s" to "%s" ...' % (key,str(val)) )
- rcf.replace( key, str(val) )
- else :
-
- logging.info( ' set "%s" to "%s" ...' % (key,str(val)) )
- rcf.add( key, str(val), comment='new key added after options passed to setup script' )
-
-
-
-
-
- logging.info( 'setup logging according to settings ...')
-
-
- flag = rcf.get( 'verbose', 'bool', default=False )
- if flag :
- logging.info( ' verbose mode for standard output; print all messages ...' )
- stdout_handler.setLevel(logging.DEBUG)
- else :
- logging.info( ' quiet mode for standard output; print info messages only ...' )
-
-
- key = 'logfile'
- if rcf.has_key(key) :
- logfile = rcf.get(key)
- logging.info( ' open additional log file : %s' % logfile )
- logfile_handler = Start_File_Log( logger, logfile )
- else :
- logging.info( ' no log file; print to standard output only ...' )
- logfile_handler = None
-
- logging.info (' test messages ...')
- logging.debug (' testing debug message ...')
- logging.info (' testing info message ...')
- logging.warning (' testing warning message ...')
- logging.error (' testing error message ...')
- logging.critical(' testing critical message ...')
-
-
-
-
-
-
- logging.debug( '' )
- logging.debug( 'Content of rc dictionary:' )
- for key in rcf.keys() :
- logging.debug( ' %s : %s' % (key,rcf.get(key)) )
- logging.debug( '[done]' )
-
-
-
-
-
-
- flag = rcf.get('build.copy','bool')
- if flag :
- logging.info( 'copy sources to build directory ...' )
- Build_Copy( rcf, pycasso_user_scripts )
- else :
- logging.info( 'no source to be copied ...' )
-
- flag = rcf.get('build.configure','bool')
- if flag :
- logging.info( 'configure source ...' )
- Build_Configure( rcf, pycasso_user_scripts )
- else :
- logging.info( 'no source to be configured ...' )
-
- flag = rcf.get('build.make','bool')
- if flag :
- logging.info( 'compile source ...' )
- Build_Make( rcf, pycasso_user_scripts )
- else :
- logging.info( 'no source to be made ...' )
-
- if rcf.get('norunsetup','bool', default=False): return
-
- rundir = rcf.get('rundir')
- if len(rundir) > 0 :
-
- pycasso_tools.CreateDirs( rundir )
- logging.info( 'change to run directory %s ...' % rundir )
-
- os.chdir(rundir)
- else :
- logging.info( 'no run directory specified; stay here ...' )
-
- ifiles = rcf.get('install.copy')
- if len(ifiles) > 0 :
- logging.info( 'install files ...' )
-
- for ifile in ifiles.split() :
-
- if ':' in ifile :
-
- sour,targ = ifile.split(':')
- else :
-
- sour,targ = ifile,os.path.curdir
- logging.info( ' copy "%s" to "%s" ...' % (sour,targ) )
-
- if not os.path.exists(sour) :
- logging.error( 'source file not found : %s' % sour )
- raise IOError
-
-
- shutil.copy( sour, targ )
- else :
- logging.info( 'no files to be installed ...' )
-
-
- newrc = rcf.get('install.rc')
- if len(newrc) > 0 :
- logging.info( ' install processed rcfile ...' )
-
- rcf.WriteFile( newrc )
-
- rawrc = rcf.get('install.raw.rc','bool',default=False)
- if rawrc :
- rawrc = os.path.join(owd,rcfile)
- targ = "%s.%s" % (rcfile, datetime.datetime.now().isoformat('-'))
-
- logging.info( ' install "%s" to "%s"...' % (rawrc, targ) )
-
- shutil.copy(rawrc,targ)
-
-
-
-
-
- submit_script = rcf.get( 'submit.script' )
- submit_command = rcf.get( 'submit.command' )
-
- build_prefix = rcf.get('build.prefix')
-
- if rcf.get('submit.relpaths','bool') :
-
- if sys.version_info[0]+0.1*sys.version_info[1] >= 2.6 :
- build_prefix = os.path.relpath(build_prefix,start=rundir)
- else :
- logging.warning( "Option `submit.relpaths` requires at least python version 2.6 ; use absolute path instead" )
-
- submit_script_path = os.path.join( rundir, submit_script )
-
- if not os.path.exists(submit_script_path) :
- logging.error( 'submit script not found:' )
- logging.error( ' %s' % submit_script_path )
- logging.error( 'not included in "install.copy" list ?' )
- raise Exception
-
- submit_bin_path = rcf.get( 'submit.bin.path', default=build_prefix)
- pycasso_tools.modify_text_file( submit_script_path,
- "pypath_default = os.path.join( os.pardir, 'build', 'bin' )",
- "pypath_default = os.path.join('%s','bin')" % submit_bin_path )
-
-
- logging.info( '' )
- logging.info( 'To submit a job:' )
- logging.info( '' )
- indent = ' '
-
- if len(rundir) > 0 :
- logging.info( indent+'# change to the run directory:' )
- logging.info( indent+'cd %s' % rundir )
- logging.info( '' )
-
- logging.info( indent+'# submit a job (use --help for more information):' )
- logging.info( indent+'%s' % submit_command )
-
- logging.info( '' )
- logging.info( 'For first glance on settings and results:' )
- logging.info( '' )
- logging.info( indent+'# run diadem postprocessor:' )
- logging.info( indent+'./tools/diadem/py/diadem %s' % rcfile )
-
-
- flag = rcf.get( 'submit.auto', 'bool' )
- if flag :
-
- os.chdir( rundir )
-
- logging.info( '' )
- logging.info( 'submit automatically ...' )
- logging.info( ' %s' % submit_command )
- logging.info( '' )
-
- retcode = subprocess.call( submit_command.split() )
- if retcode != 0 :
- logging.error( 'from submission of : %s' % submit_command )
- raise Exception
-
-
-
-
-
- logging.info( '' )
- tnow = datetime.datetime.now().isoformat(' ').split('.',1)[0]
- logging.info( 'End of script at %s .' % tnow )
- logging.info( '' )
-
-
- if logfile_handler != None : logfile_handler.close()
- stdout_handler.close()
-
- return
- def ParseArguments( args, pycasso_user_scripts ) :
- """
- Define the arguments accepted by a pycasso run script.
- Usage:
- options,rcfile = ParseArguments( args )
- Arguments:
- args
- Passed from the calling script, probably equal to : sys.argv[1:]
- pycasso_user_scripts
- Name of file with user scripts for this particular setup.
- Return values:
- options # object with following data fields:
- .verbose # (boolean) gives extra logging messages to the screen
- rcfile # name of settings file
-
- """
-
- import logging
- import optparse
-
-
- pycus = __import__( pycasso_user_scripts )
-
-
- usage = "\n %prog [options] rcfile\n %prog -h|--help"
-
-
- description = "Driver script to compile and setup a model application. "\
- "The 'rcfile' is a textfile with settings read by the scripts or "\
- "the application, a template should be available with this script."
-
-
- parser = optparse.OptionParser( usage=usage, description=description )
-
-
- parser.add_option( "-v", "--verbose",
- help="Print extra logging messages to standard output. "
- "This option will set rcfile key 'verbose' to 'True'.",
- dest="verbose", action="store_true", default=False )
-
- parser.add_option( "-m", "--make",
- help="Only compilation. All build.* keys are True (except build.new). Run setup is skipped.",
- dest="force_comp", action="store_true", default=False )
-
- parser.add_option( "-r","--no-compile",
- help="Skip compilation. All build.* keys are False.",
- dest="no_build", action="store_true", default=False )
-
- parser.add_option( "-n", "--new",
- help="Create new build; remove old build directory. "
- "This option will set rcfile key 'build.new' to 'True'.",
- dest="build_new", action="store_true", default=False )
-
- parser.add_option( "-j", "--jobs",
- help="Number of jobs (commands) to run simultaneously. "
- "Empty value '' indicates unlimitted number. "
- "Now only used to (re)set the number of jobs used by the maker ('gmake -j JOBS')."
- "This flag will replace the value of 'build.jobs' in the rcfile.",
- dest="jobs", action="store", default=None )
-
- parser.add_option( "-s", "--submit",
- help="Submit the job after setup. "
- "See also the section on 'Submit options' below for "
- "options passed directly to the submit script. "
- "This option will set rcfile key 'submit.auto' to 'True'.",
- dest="submit_auto", action="store_true", default=False )
-
- group = optparse.OptionGroup( parser, "Submit options",
- description="Options passed directly to the submit script, see its help text for details." )
-
- group.add_option( "-f", "--foreground",
- help="Run job in foreground.",
- dest="submit_to", action="store_const", const='foreground' )
- group.add_option( "-b", "--background",
- help="Run job in background.",
- dest="submit_to", action="store_const", const='background' )
- group.add_option( "-q", "--queue",
- help="Submit job to a queue system.",
- dest="submit_to", action="store_const", const='queue' )
-
- group.add_option( "-d", "--debugger",
- help="Run executable in a debugger.",
- dest="submit_debugger", action="store_true" )
-
- parser.add_option_group( group )
-
-
- group = optparse.OptionGroup( parser, "User model options",
- description="These options are defined and handled in the 'pycasso_user_scripts_*' module." )
- pycus.DefineOptions( group )
- parser.add_option_group( group )
-
- values,args = parser.parse_args( args=args )
-
-
-
- if len(args) != 1 :
- parser.error("incorrect number of arguments\n")
-
-
-
- opts = {}
- if values.verbose : opts['verbose' ] = True
- if values.build_new : opts['build.new' ] = True
- if values.jobs != None : opts['build.jobs' ] = values.jobs
- if values.submit_auto : opts['submit.auto' ] = True
- if values.submit_to != None : opts['submit.to' ] = values.submit_to
- if values.submit_debugger != None : opts['submit.debugger'] = values.submit_debugger
- if values.no_build :
- opts['build.copy' ] = False
- opts['build.configure' ] = False
- opts['build.new' ] = False
- opts['build.make' ] = False
- if values.force_comp :
- opts['build.copy' ] = True
- opts['build.configure' ] = True
- opts['build.make' ] = True
- opts['norunsetup' ] = True
-
- pycus.StoreOptions( opts, values )
-
-
- rcfile = args[0]
-
- return opts,rcfile
-
- def Start_Logger() :
- """
- logger = Start_Logger()
- """
-
- import logging
-
- logger = logging.getLogger('')
- logger.setLevel(logging.DEBUG)
-
-
- return logger
- def Start_StdOut_Log(logger) :
- """
- stdout_handler = Start_StdOut_Log(logger)
- """
-
- import sys
- import logging
-
- logformat = '[%(levelname)-8s] %(message)s'
-
- formatter = logging.Formatter(logformat)
-
-
- stdout_handler = logging.StreamHandler(sys.stdout)
- stdout_handler.setLevel(logging.INFO)
- stdout_handler.setFormatter(formatter)
- logger.addHandler(stdout_handler)
-
-
-
-
-
- return stdout_handler
- def Start_File_Log(logger,logfile) :
- """
- logfile_handler = Start_File_Log(logger,logfile)
-
- Create handler for log file.
- Initial level is 'DEBUG', thus all messages will be written to the file.
- """
-
-
- import sys
- import logging
-
-
- if sys.version_info < (2, 5):
- logformat = "%(asctime)s %(name)-10s, line %(lineno)4i [%(levelname)-10s] %(message)s"
- else:
- logformat = '%(lineno)4i %(filename)-30s -> %(funcName)-30s [%(levelname)-8s] %(message)s'
-
-
- formatter = logging.Formatter(logformat)
-
-
-
- logfile_handler = logging.FileHandler(filename=logfile,mode='w')
- logfile_handler.setLevel(logging.DEBUG)
- logfile_handler.setFormatter(formatter)
- logger.addHandler(logfile_handler)
-
-
-
-
-
-
- return logfile_handler
- def Build_Copy( rcf, pycasso_user_scripts ) :
-
- import os
- import sys
- import shutil
- import logging
- import pycasso_tools
- import re
-
-
- pycus = __import__( pycasso_user_scripts )
-
-
- remove_existing_build = rcf.get('build.new','bool')
-
- prefix = rcf.get('build.prefix')
- logging.info( ' build prefix : %s ' % prefix )
-
-
- if rcf.get('build.prefix.extend','bool') :
-
- prefix_ext = prefix
-
- flags = pycus.Build_FlagGroups( rcf )
-
- if len(flags) > 0 :
- for flag in flags : prefix_ext = prefix_ext+'_'+flag
- else :
- prefix_ext = prefix_ext+'_'
- logging.info( ' build prefix extended : %s ' % prefix_ext )
-
- pycasso_tools.CreateDirs( prefix_ext, forceclean=remove_existing_build )
-
- if os.path.lexists(prefix) :
-
- if os.path.islink(prefix) :
-
- os.remove( prefix )
- else :
- logging.error( 'could not replace "'+prefix+'" by a symbolic link; remove first' )
- raise Exception
-
- os.symlink( os.path.basename(prefix_ext), prefix )
- else :
-
- pycasso_tools.CreateDirs( prefix, forceclean=remove_existing_build )
-
-
- subdirs = rcf.get('build.copy.subdirs').split()
-
- for subdir in subdirs :
-
- sdir = os.path.join(prefix,subdir)
-
- pycasso_tools.CreateDirs( sdir )
-
-
- sourcedirs = rcf.get('build.copy.dirs')
- if len(sourcedirs) > 0 :
-
- logging.info( ' copy files from source directories...' )
-
- flag_remove__part = rcf.get('build.copy.remove.__part','bool')
- if flag_remove__part :
- logging.info( ' remove "__<name>" parts from sources files ...' )
-
-
- for sourcedir in sourcedirs.split() :
- found_some_files = False
-
- logging.info( ' scanning %s ...' % sourcedir)
-
- if not os.path.isdir(sourcedir) :
- logging.error( 'specified source dir is not an existing directory : %s' % sourcedir )
- raise IOError
-
-
- if len(subdirs) == 0 : subdirs = os.path.curdir
-
- for subdir in subdirs :
-
- if subdir == '.' :
-
- sourcepath = sourcedir
- else :
-
- sourcepath = os.path.join(sourcedir,subdir)
-
- logging.debug( ' scanning %s ...' % sourcepath )
-
-
- try :
-
- sourcefiles = os.listdir(sourcepath)
- except :
-
- continue
-
-
- for sfile in sourcefiles :
- found_some_files = True
-
- sourcefile = os.path.join(sourcepath,sfile)
-
- if os.path.isdir(sourcefile) : continue
-
- name,ext = os.path.splitext(sfile)
- skipit = False
- for pattern in rcf.get('build.copy.skip.ext').split() :
- if re.search(pattern, ext) :
- logging.debug( ' %-50s %-30s [%-8s]' % (sourcefile,'','skip') )
- skipit = True
- if skipit :
- continue
-
- outfile = sfile
-
- if flag_remove__part :
-
- if '__' in sfile :
-
- name,ext = os.path.splitext(sfile)
- outfile = name.split('__')[0]+ext
-
- if outfile in rcf.get('build.copy.skip.file').split() :
- logging.debug( ' %-50s %-30s [%-8s]' % (sourcefile,'','skip') )
- continue
-
-
- targetfile = os.path.join( prefix, subdir, outfile )
-
- if os.path.exists(targetfile) :
-
- if pycasso_tools.diff_text_files(sourcefile,targetfile) :
- stat = 'differs'
- else:
- stat = '...'
-
- else:
- stat = 'new'
-
-
- logging.debug( ' %-50s -> %-30s [%-8s]' % (sourcefile,os.path.join(subdir,outfile),stat) )
-
- shutil.copy2( sourcefile, targetfile )
-
- if found_some_files == False :
- logging.warning(' found no source files in standard subdirs %s of %s. Mistake in source.dirs?' % (str(subdirs),sourcedir))
-
- else :
- logging.info( ' no source directories specified ...' )
-
- flag = rcf.get('build.copy.pypath','bool')
- if flag :
- logging.info( ' add subdir <prefix>/py to python path ...' )
-
- newdir = os.path.join(prefix,'py')
-
- sys.path.insert(0,newdir)
- else :
- logging.info( ' no request for extension of the python path ...' )
- def Build_Configure( rcf, pycasso_user_scripts ) :
- import os
- import sys
- import logging
- import subprocess
- import glob
-
-
- import go
- import pycasso_tools
-
-
- pycus = __import__( pycasso_user_scripts )
-
-
- current_dir = os.getcwd()
- configure_dir = rcf.get('build.sourcedir')
- logging.debug( ' change to %s ...' % configure_dir )
- os.chdir( configure_dir )
-
-
-
-
-
- fc,f77,linker = pycus.Build_Compiler( rcf )
-
-
- fflags = ''
- ldflags = ''
- libs = ''
-
-
- fflags_basic = ''
-
-
- flaggroups = pycus.Build_FlagGroups( rcf )
-
- for flaggroup in flaggroups :
-
- fflags = fflags.strip()+' '+rcf.get('compiler.flags.'+flaggroup+'.fflags' )
- ldflags = ldflags.strip()+' '+rcf.get('compiler.flags.'+flaggroup+'.ldflags')
-
- logging.info( ' fflags : %s' % fflags )
- logging.info( ' ldflags : %s' % ldflags )
-
-
- flaggroups_basic = pycus.Build_FlagGroups( rcf, basic=True )
-
- for flaggroup in flaggroups_basic :
-
- fflags_basic = fflags_basic.strip()+' '+rcf.get('compiler.flags.'+flaggroup+'.fflags' )
- logging.info( ' fflags basic : %s' % fflags_basic )
-
-
-
-
-
- macros_def = rcf.get('build.configure.macro.define' ).split()
-
- groups = rcf.get('build.configure.macro.groups').split()
-
- for group in groups :
-
- macros_def = pycus.Build_Define( rcf, group, macros_def )
-
-
- macros_defined = []
- for m in macros_def :
- if m not in macros_defined : macros_defined = macros_defined + macros_def
-
- macros_supported = []
-
- for group in groups :
-
- keybase = 'build.configure.macro.'+group
-
- macros_all = rcf.get(keybase+'.all' ).split()
- macros_hfile = rcf.get(keybase+'.hfile' )
-
- if len(macros_hfile) > 0 :
-
- logging.info( ' update %s (include file with macro definitions) ...' % macros_hfile )
-
-
- src = []
- src.append( '!\n' )
- src.append( '! Include file with macro definitions.\n' )
- src.append( '!\n' )
-
- for mdef in macros_def :
-
- if '=' in mdef :
-
- mname,mval = mdef.split('=')
-
- if mname in macros_all :
-
- src.append( '#define %s %s\n' % (mname,mval) )
-
- else :
-
- if mdef in macros_all :
-
- src.append( '#define %s\n' % mdef )
-
-
-
-
- pycasso_tools.update_text_file( macros_hfile, src )
-
-
- for m in macros_all :
- if m not in macros_supported : macros_supported = macros_supported + macros_all
-
-
- any_error = False
- for macr in macros_defined :
-
- if macr not in macros_supported :
-
- if not any_error :
-
- logging.error( "one or more macro's have been defined that are not listed" )
- logging.error( "in any 'build.configure.macro.*.all' lists:" )
-
-
- logging.error( " %s" % macr )
-
- any_error = True
-
- if any_error : raise Exception
-
- fc_defs = ''
- mk_defs = ''
-
- define_D = rcf.get( 'build.configure.define.D', 'bool' )
- if define_D :
-
- fc_D = rcf.get('compiler.defineflag',default='-D')
- mk_D = '-D'
-
- for mdef in macros_defined :
-
- fc_defs = fc_defs.strip()+(' %s%s' % (fc_D,mdef) )
- mk_defs = mk_defs.strip()+(' %s%s' % (mk_D,mdef) )
-
-
-
- fflags = fflags.strip()+' '+fc_defs
-
- fflags_basic = fflags_basic.strip()+' '+fc_defs
-
-
-
-
-
-
- libnames = rcf.get( 'build.configure.libs' )
-
-
- logging.debug( ' libraries to be used:' )
- if len(libnames) > 0 : logging.debug( ' %s (default)' % libnames )
-
-
- libnames = libnames.split()
-
- for mdef in macros_defined :
-
- libnames_ifdef = rcf.get( 'build.configure.libs.ifdef.%s' % mdef, default='' )
-
- if len(libnames_ifdef) > 0 :
-
- libnames = libnames+libnames_ifdef.split()
-
- logging.debug( ' %s (macro `%s` defined)' % (libnames_ifdef,mdef) )
-
-
- libnames_all = rcf.get( 'build.configure.libs.all' ).split()
-
-
- for libname in libnames :
- if libname not in libnames_all :
- logging.error( 'library name `%s` not in `build.configure.libs.all` list ...' % libname )
- raise Exception
-
-
- logging.debug( ' libraries linked (in this order):' )
-
-
- for libname in libnames_all :
-
- if libname not in libnames : continue
-
- logging.debug( ' %s' % libname )
-
- to_include = rcf.get('compiler.lib.'+libname+'.fflags')
- if to_include !='-I' and to_include !='-I/':
- logging.debug(' add Fflag for "%s": %s' % (libname,to_include))
- fflags = fflags.strip()+' '+to_include
-
- try:
- lib2add = rcf.get('compiler.lib.'+libname+'.libs')
- except KeyError:
-
- logging.info("try 'compiler.lib.%s.lib_dir instead" % libname)
- libdir = rcf.get('compiler.lib.'+libname+'.lib_dir')
- libnol = rcf.get('compiler.lib.'+libname+'.libs_no_l')
- if libdir =='-L' or libdir =='-L/':
- libdir=''
- if len(libnol)!=0:
- lib2add = libdir+' '.join([' -l'+f for f in libnol.split()])
- logging.debug(' add Lflag for "%s": %s' % (libname,lib2add))
- libs = libs.strip()+' '+lib2add
-
- to_include = rcf.get('compiler.lib.'+libname+'.fflags')
- if to_include !='-I' and to_include !='-I/':
- logging.debug(' add FflagBasic for "%s": %s' % (libname,to_include))
- fflags_basic = fflags_basic.strip()+' '+to_include
-
-
-
-
-
- makefile_flags = rcf.get('build.configure.flags.includefile')
-
- logging.info( ' write %s (compiler and flags) ...' % makefile_flags )
- logging.info( ' compiler fflags : '+fflags )
- logging.info( ' ldflags : '+ldflags )
- logging.info( ' libs : '+libs )
-
- src = []
- src.append( '#\n' )
- src.append( '# include file with compiler flags for Makefile.\n' )
- src.append( '#\n' )
- src.append( '\n' )
- src.append( '# compiler and linker:\n' )
- src.append( 'FC = %s\n' % fc )
- src.append( 'F77 = %s\n' % f77 )
- src.append( 'LINKER = %s\n' % linker )
- src.append( '\n' )
- src.append( '# compile flags:\n' )
- src.append( 'FFLAGS = %s\n' % fflags )
- src.append( '\n' )
- src.append( '# compile flags without optim:\n' )
- src.append( 'FFLAGS_BASIC = %s\n' % fflags_basic )
- src.append( '\n' )
- src.append( '# linker flags:\n' )
- src.append( 'LDFLAGS = %s\n' % ldflags )
- src.append( '\n' )
- src.append( '# library flags:\n' )
- src.append( 'LIBS = %s\n' % libs )
- src.append( '\n' )
-
- pycasso_tools.write_text_file( makefile_flags, src )
-
-
-
-
-
-
- logging.info( ' remove files ...' )
- for sfile in rcf.get('build.configure.remove').split() :
-
- logging.debug( ' %s ...' % sfile )
-
- if os.path.exists(sfile) : os.remove( sfile )
-
-
- logging.info( ' remove files for defined macro\'s ...' )
- for macr in macros_defined :
-
- patterns = rcf.get( 'build.configure.remove.ifdef.%s' % macr, default='' )
-
- if len(patterns) > 0:
- for pattern in patterns.split():
- for sfile in glob.glob(pattern) :
- if os.path.exists(sfile) :
- logging.debug( ' %s ...' % sfile )
- os.remove(sfile)
-
- logging.info( ' remove files for undefined macro\'s ...' )
- for macr in macros_supported :
-
- if macr in macros_defined : continue
-
- patterns = rcf.get( 'build.configure.remove.ifndef.%s' % macr, default='' )
-
- if len(patterns) > 0:
- for pattern in patterns.split():
- for sfile in glob.glob(pattern) :
- if os.path.exists(sfile) :
- logging.debug( ' %s ...' % sfile )
- os.remove(sfile)
-
-
-
-
- pycus.Build_Configure( rcf )
-
-
-
-
-
- flag = rcf.get('build.configure.makedep','bool')
- if flag :
-
-
- makefile_deps = rcf.get('build.configure.makedep.includefile')
-
- logging.info( ' create %s ...' % makefile_deps )
-
- exe = rcf.get( 'build.make.exec' )
-
- files = rcf.get('build.configure.makedep.files')
-
- ecearth_makedepf90 = rcf.get( 'mkdepf90' )
-
-
-
-
-
- command = '%s -l \'$(FC) -o $@ $(LDFLAGS) $(FOBJ) $(LIBS)\' %s -o %s %s' % (ecearth_makedepf90,mk_defs,exe,files)
-
- logging.debug( ' run command: %s' % command )
-
- try :
-
- p = go.subprocess.call( command, shell=True )
- except go.subprocess.CallingError, err :
- logging.error( err )
- raise Exception
- except go.subprocess.StatusError, err :
- for line in err.stderr : logging.error(line)
- logging.error( err )
- raise Exception
-
-
- f = open( makefile_deps, 'w' )
- for line in p.stdout : f.write(line+'\n')
- f.close()
-
- logging.debug( '' )
- logging.debug( '---[%s]------------------------------------------------------------' % makefile_deps )
- for line in p.stdout : logging.debug(line)
- logging.debug( '-------------------------------------------------------------------' )
- logging.debug( '' )
-
-
-
-
-
-
-
- logging.debug( ' change back to %s ...' % current_dir )
- os.chdir( current_dir )
-
- return
-
- def Build_Make( rcf, pycasso_user_scripts ) :
- import os
- import logging
-
-
- pycus = __import__( pycasso_user_scripts )
-
-
- logging.info( 'make executable ...' )
-
-
- Make_dir = rcf.get('build.make.dir')
- logging.debug( ' change to %s ...' % Make_dir )
- os.chdir( Make_dir )
-
- pycus.Build_Make( rcf )
-
|