def _parse_default_command_line_options(): """Parses the command line options controlling various build settings @remarks This contains variables that work across all builds. Build-specific variables are discouraged, but would be irgnored by SCons' Variables class.""" command_line_variables = Variables(None, ARGUMENTS) # Build configuration (also called build type in many SCons examples) command_line_variables.Add( BoolVariable( 'DEBUG', 'Whether to do an unoptimized debug build', False ) ) # Default architecture for the binaries. We follow the Debian practices, # which, while clueless and chaotic, are at least widely used. default_arch = 'amd64' if 'armv7' in platform.uname()[4]: default_arch = 'armhf' if 'aarch64' in platform.uname()[4]: default_arch = 'arm64' # CPU architecture to target command_line_variables.Add( EnumVariable( 'TARGET_ARCH', 'CPU architecture the binary will run on', default_arch, allowed_values=('armhf', 'arm64', 'x86', 'amd64', 'any') ) ) # Directory for intermediate files command_line_variables.Add( PathVariable( 'INTERMEDIATE_DIRECTORY', 'Directory in which intermediate build files will be stored', 'obj', PathVariable.PathIsDirCreate ) ) # Directory for intermediate files command_line_variables.Add( PathVariable( 'ARTIFACT_DIRECTORY', 'Directory in which build artifacts (outputs) will be stored', 'bin', PathVariable.PathIsDirCreate ) ) return command_line_variables
def generate(env, configGroup): # add parameters to configurate toolchain params = Variables(env['PARAMETER_SOURCE'], ARGUMENTS) params.Add(('gcc_compiler', 'GCC cross compiler prefix', '')) params.Add(('gcc_cppflags', 'GCC cross compiler cpp flags', '')) params.Add(('gcc_linkflags', 'GCC cross compiler link flags', '')) params.Add( PathVariable('gcc_sysroot', 'GCC cross compiler system root', '', PathVariable.Accept)) params.Update(env) try: configReport = env.configReport configReport.add('GCC cross compiler prefix', 'gcc_compiler', configGroup) configReport.add('GCC cross compiler cpp flags', 'gcc_cppflags', configGroup) configReport.add('GCC cross compiler link flags', 'gcc_linkflags', configGroup) configReport.add('GCC cross compiler system root', 'gcc_sysroot', configGroup) except: pass # get configuration parameters compiler = env.subst(env['gcc_compiler']) sysroot = env.subst(env['gcc_sysroot']) cppflags = env['gcc_cppflags'] env['CC'] = compiler + 'gcc' env['CXX'] = compiler + 'g++' env['LD'] = compiler + 'ld' env['STRIP'] = compiler + 'strip' env['OBJCOPY'] = compiler + 'objcopy' env['AS'] = compiler + 'as' env['AR'] = compiler + 'ar' env['RANLIB'] = compiler + 'ranlib' env.Append(CROSSCOMPILE_CPPFLAGS=cppflags) env.Append(CROSSCOMPILE_LINKFLAGS=linkflags) env.Append(CROSSCOMPILE_CPPFLAGS=['--sysroot={}'.format(sysroot)]) env.Append(CROSSCOMPILE_LINKFLAGS=['--sysroot={}'.format(sysroot)]) # apply cross compile flags to build environment env.Append(CFLAGS=env['CROSSCOMPILE_CFLAGS']) env.Append(CPPFLAGS=env['CROSSCOMPILE_CPPFLAGS']) env.Append(CXXFLAGS=env['CROSSCOMPILE_CXXFLAGS']) env.Append(LINKFLAGS=env['CROSSCOMPILE_LINKFLAGS'])
def generate(env): params = Variables(env['PARAMETER_SOURCE'], ARGUMENTS) params.Add(EnumVariable('crosscompile', 'Enable cross compile', 'no', ['no', 'android', 'mingw', 'gcc'])) params.Update(env) configGroup = None try: configReport = env.configReport configGroup = 'Cross-Compile' configReport.add('Enable cross compile', crosscompile, configGroup) except: pass env.SetDefault(CROSSCOMPILE_CFLAGS = '') env.SetDefault(CROSSCOMPILE_CPPFLAGS = '') env.SetDefault(CROSSCOMPILE_CXXFLAGS = '') env.SetDefault(CROSSCOMPILE_LINKFLAGS = '') env.SetDefault(CROSSCOMPILE_LIBS = '') env.SetDefault(CROSSCOMPILE_PROGRAM_LIBS = '') if env['crosscompile'] == 'android': android.generate(env, configGroup) elif env['crosscompile'] == 'mingw': mingw.generate(env, configGroup) elif env['crosscompile'] == 'gcc': gcc.generate(env, configGroup)
def _GetConfigurationVariables(self): """ Retrieve and define help variables for configuration variables. """ cmd_line_args = ARGUMENTS cfgVars = Variables(None, cmd_line_args) [ cfgVars.Add(BoolVariable(name, helptext, default)) for name, helptext, default in self._boolean_variables ] [ cfgVars.Add(EnumVariable(name, helptext, default, valid)) for name, helptext, default, valid in self._enumerable_variables ] [cfgVars.Add(option) for option in self._numerical_variables] return cfgVars
def Add(self, key, help="", default=None, validator=None, converter=None, required=False): SVariables.Add(self, key, help, default, validator, converter) if required: print("adding required option ", key[0]) self.required.append(key[0])
def updateVariables(self): """ Retrieve and define help options for configuration variables. """ rootdir = Dir('#').abspath cfg_files = [ rootdir + "/library/configuration/" + self._cfg_name + "/" + self._module_name + ".py", ] cfgVars = Variables(cfg_files, self._cmd_line_args) [ cfgVars.Add(BoolVariable(name, helptext, default)) for name, helptext, default in self._bool_vars ] [ cfgVars.Add(EnumVariable(name, helptext, default, valid)) for name, helptext, default, valid in self._enum_vars ] [cfgVars.Add(option) for option in self._other_vars] self._variables = cfgVars
def build(wd, sources): destdir = '../SBA/' global opts flags = [] switches = [] boost = 0 # MACROS wordsz = 64 WORDSZ = 'WORDSZ=' + str(wordsz) GL = 'GPRM_LANGUAGE' NEW = '' VERBOSE = '' #V='VERBOSE' # Compile for VM (otherwise compiles to model HW) SEQVM = 'SEQVM=0' USE_THREADS = 'USE_THREADS=0' DISTR = 'DISTR=0' use_pthreads = False # B ashkan USE_TILERA = '' #X= 'USE_TILERA' use_tilera = False USE_MIC = '' use_mic = False # E ashkan STEAL = '' KERNEL_HAS_STATE = '' KERNEL_LOCK = '' THREADED_CORE = '' # 'THREADED_CORE=0' threaded_core = False # Count CPU cycles CYCLES = '' # 'CYCLES' TIMINGS = '' # 'TIMINGS' STATIC_ALLOC = 'STATIC_ALLOC' # Flags #Smash= '-fstack-protector '# Ashkan WARN = '' #'-Wall ' CXX0X = '-std=c++11' PTHREADS = '-pthread' OPTSPEED = '-O3 -fno-exceptions -fno-rtti ' OPTSIZE = '-Os -fno-exceptions -fno-rtti ' OPTTHREADS = '-O2 ' # '-ansi-alias ' DEBUG = '' ARCH = '' NO_SOCKET = '' OPT = '-O2 ' CYGWIN = 0 PIC = '' #'-fPIC ' # These are used by the build script to generate flags/switches OSX = 0 # Flag for cross-compilation XC = 0 # Use LLVM # LLVM=1: x86, LLVM=2: ppc LLVM = 0 # SystemC SC = 0 H = 0 # Help LIB = False SHLIB = False MACROS = [] # ['INTERFACE_OBJ'] yaml_config = '../../SystemConfigurations/SBA.yml' #use options without leading '-': scons v=0 gui=QtGui opts = Variables() opts.Add('v', 'Verbose', 0) opts.Add('w', 'Warnings', 0) opts.Add('new', 'New', 0) opts.Add('xc', 'Crosscompile', 'NONE') opts.Add('llvm', 'Use LLVM', 0) opts.Add('win', 'CygWin', 0) opts.Add('vm', 'Virtual Machine', 0) opts.Add('sock', 'Use POSIX socket interface', 1) opts.Add('svm', 'Sequential Virtual Machine', 0) # options can't take . or / in the strings!! # opts.Add('yml','YAML configuration file','') #'../../SBA.yml') opts.Add('cycles', 'Count CPU cycles', 0) opts.Add('timings', 'Time program execution', 0) opts.Add('dyn', 'Dynamic memory', 0) opts.Add('pthreads', 'Use POSIX Threads', 0) opts.Add('lib', 'Compile as a library named gannet ', 0) opts.Add('shlib', 'Compile as a shared library named gannet ', 0) opts.Add('steal', 'Enable task stealing', 0) opts.Add('stateful', 'For stateful kernels', 0) opts.Add('locking', 'Always lock access to stateful kernels', 0) opts.Add('wordsz', 'Set WORDSZ', 64) opts.Add('ptcore', 'Use POSIX Threaded Core', 0) opts.Add('dbg', 'Debug', 0) opts.Add('nogen', "Don't generate C++ sources from Ruby code", 0) opts.Add('opt', 'Optimise', 'speed') # or 'size' opts.Add( 'D', 'Macros (add as a string: D="MACRO1:1 MACRO2 MACRO3:whatever"\nSCons is too stupid to allow "=")', '') # add additional macros as a string opts.Add('h', 'Help', 0) args = sys.argv[1:] #import getopt #rest = getopt.getopt(args,"hABCD") for arg in args: if re.match("(\w+)=(\w+)", arg): (k, v) = arg.split('=') opts.args[k] = v #exit(opts.options) for param in os.environ.keys(): if param == "VERBOSE": VERBOSE = 'VERBOSE' if param == "GPRM_YML_CONFIG": yaml_config = os.environ["GPRM_YML_CONFIG"] for option in opts.options: if option.key == 'v' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: VERBOSE = 'VERBOSE' if option.key == 'w' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: WARN = '-Wall ' if option.key == 'new' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: NEW = 'NEW=1' if option.key == 'xc' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: XC = 1 # B ashkan if opts.args[option.key] == 'Tilera': use_tilera = True USE_TILERA = 'USE_TILERA' elif opts.args[option.key] == 'MIC': use_mic = True USE_MIC = 'USE_MIC' '-ansi-alias ' # E ashkan OPT = OPTSPEED if option.key == 'llvm' and opts.args.has_key( option.key): # and opts.args[option.key]!=option.default: if opts.args[option.key] == '1': LLVM = 1 elif opts.args[option.key] == '2': LLVM = 2 else: LLVM = 0 OPT = OPTSPEED if option.key == 'win' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: CYGWIN = 1 if option.key == 'vm' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: VM = 'VM=1' if option.key == 'svm' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: VM = 'VM=1' SEQVM = 'SEQVM=1' # doesn't work if the path has dots or slashes! # if option.key == 'yml' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: # print "YAML!" # yaml_config=opts.args[option.key] if option.key == 'sock' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: NO_SOCKET = 'NO_SOCKET' sockpatt = re.compile('^\.\.\/GannetSocket') nsources = filter(lambda s: not (sockpatt.search(s)), sources) sources = nsources if option.key == 'wordsz' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: wordsz = opts.args[option.key] WORDSZ = 'WORDSZ=' + str(wordsz) if option.key == 'lib' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: LIB = True if option.key == 'shlib' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: SHLIB = True if option.key == 'steal' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: STEAL = 'STEAL=1' if option.key == 'stateful' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: KERNEL_HAS_STATE = 'KERNEL_HAS_STATE=1' if option.key == 'locking' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: KERNEL_LOCK = 'KERNEL_LOCK=1' if option.key == 'pthreads' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: USE_THREADS = 'USE_THREADS=1' use_pthreads = True OPT = OPTTHREADS if option.key == 'ptcore' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: THREADED_CORE = 'THREADED_CORE=1' threaded_core = True OPT = OPTTHREADS if option.key == 'distr' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: DISTR = 'DISTR=1' OPT = OPTSPEED if option.key == 'cycles' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: CYCLES = 'CYCLES' if option.key == 'timings' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: TIMINGS = 'TIMINGS' if option.key == 'dyn' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: STATIC_ALLOC = '' if option.key == 'dbg' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: DEBUG = '-g -O0 ' #'-g -fno-exceptions -fno-rtti ' OPT = '' if option.key == 'opt' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: OPT = OPTSPEED if option.key == 'D' and opts.args.has_key( option.key) and opts.args[option.key] != option.default: macrostr = re.sub('\s*:\s*', '=', opts.args[option.key]) MACROS = macrostr.split(' ') if option.key == 'h' and opts.args.has_key(option.key): H = 1 if commands.getoutput("uname") == "Darwin": OSX = 1 switches += ['DARWIN'] PTHREADS = '' if SC == 1: ARCH = '-arch i386' # Ashkan commented this out #if XC==1: # switches.append('__ppc__') FLAGS = '' SWITCHES = '' flags += [CXX0X, WARN, DEBUG, ARCH, PIC, OPT, PTHREADS] # Ashkan added USE_TILERA switches += [ VERBOSE, SEQVM, WORDSZ, CYCLES, TIMINGS, STATIC_ALLOC, NO_SOCKET, USE_THREADS, THREADED_CORE, DISTR, STEAL, KERNEL_HAS_STATE, KERNEL_LOCK, USE_TILERA, USE_MIC ] + MACROS for flag in flags: if flag != '': FLAGS += flag + ' ' for switch in switches: if re.search('BOOST', switch): boost = 1 if switch != '': SWITCHES += '-D' + switch + ' ' GPRM_DIR = os.environ["GPRM_DIR"] # print "GPRM_DIR:"+GPRM_DIR bin = 'gannetvm' + str(wordsz) if LIB: sources.append(GPRM_DIR + '/GPRM/src/gannet.cc') else: sources.append(GPRM_DIR + '/GPRM/src/gannetvm.cc') #------------------------------------------------------------------------------ cxx = os.environ['CXX'] # gcc_version = os.popen('g++ -dumpversion').read().rstrip("\n\r") # gcc_version_tuple = [int(x) for x in gcc_version.split('.')] ## WV: HACK! TOO SPECIFIC! USE ENV VAR! # if (gcc_version_tuple[1]<6): # cxx='/opt/local/bin/g++-mp-4.8' # else: # cxx='g++' ##Ashkan" none of them, icpc! # cxx='/home/ashkan/intel/composer_xe_2013_sp1.2.144/bin/intel64/icpc -no-offload -vec-report6' if XC == 1: # cxx='powerpc-405-linux-gnu-g++' if use_tilera: # cxx='tile-c++' cxx = 'tile-g++' elif use_mic: cxx = '/home/ashkan/intel/composer_xe_2013_sp1.2.144/bin/intel64/icpc -mmic -no-offload -vec-report6' else: print "WARNING: NO VALID CROSS COMPILATION TARGET, using host CXX" if LLVM == 1: cxx = 'i686-pc-linux-gnu-g++' env = Environment(variables=opts, CXX=cxx, CXXFLAGS=FLAGS + SWITCHES, LINKFLAGS=[PTHREADS]) # env.VariantDir(wd+'build/',GPRM_DIR+'/GPRM/build/', duplicate=0) # Help(opts.GenerateHelpText(env)) if H == 1: print(opts.GenerateHelpText(env)) exit(1) if XC == 1: HOME = os.environ['HOME'] env['ENV'][ 'PATH'] = os.environ["GPRM_XC_PATH"] + ":" + env['ENV']['PATH'] print env['ENV']['PATH'] if LLVM == 1: env['ENV'][ 'PATH'] = os.environ["GPRM_LLVM_PATH"] + ":" + env['ENV']['PATH'] print env['ENV']['PATH'] #FIXME: dl only needed for dynamic loading! #libs=['m','dl'] libs = ['m'] if use_pthreads or threaded_core: libs += ['pthread'] # Ashkan added tmc if use_tilera: libs += [] # libs+=['tmc'] #libs+=['pthread','boost_thread-mt'] # SBA classes should not use boost shared libraries, only header files if boost == 1: libs += ['boost_program_options'] INCpaths = ['.', '../', GPRM_DIR + '/GPRM/src/SBA/' ] # ,GPRM_DIR+'/GPRM/SBA/ServiceCoreLibraries/'] LIBpaths = [] if boost == 1: INCpaths += [os.environ['BOOST_INC']] if OSX == 1 or OSX == 0: # UGLY HACK! INCpaths = [ wd + '/gensrc/', wd + '/src/GPRM/Kernel/', wd + '/src/', '.', '../', GPRM_DIR + '/GPRM/src/SBA/', GPRM_DIR + '/GPRM/src/' ] # LIBpaths=['/opt/local/lib/gcc48/','/opt/local/lib/','/usr/local/lib/'] # libs=['m'] if boost == 1: INCpaths += [os.environ['BOOST_INC']] libs += [os.environ['BOOST_LIB']] #WV: to have multiple targets, we just need to set bin : bin is short for #env.Program(target=bin,...) if LIB: glib = env.Library('gannet', sources, LIBS=libs, LIBPATH=LIBpaths, CPPPATH=INCpaths) elif SHLIB: glib = env.SharedLibrary('gannet', sources, LIBS=libs, LIBPATH=LIBpaths, CPPPATH=INCpaths) else: prog = env.Program(bin, sources, LIBS=libs, LIBPATH=LIBpaths, CPPPATH=INCpaths) env.Install(wd + '/bin', prog) env.Alias('install', wd + '/bin') # make this wd+'/bin' ?
def generate(env, configGroup): # add parameters to configurate toolchain params = Variables(env['PARAMETER_SOURCE'], ARGUMENTS) params.Add( PathVariable( 'android_ndkroot', 'Path to Android NDK toolchain (NDK_ROOT env-param by default)', os.path.expanduser(os.environ['NDK_ROOT']), PathVariable.PathAccept)) params.Add( EnumVariable('android_arch', 'Android architecture to build for', 'armv7a', ['armv7', 'armv7a', 'armv8', 'x86', 'x86_64'])) params.Add(('android_apilevel', 'Android API level', '18')) params.Add(('android_gccversion', 'Android NDK GCC version', '4.9')) params.Update(env) try: configReport = env.configReport configReport.add('Path to Android NDK toolchain', 'android_ndkroot', configGroup) configReport.add('Android architecture to build for', 'android_arch', configGroup) configReport.add('Android API level', 'android_apilevel', configGroup) configReport.add('Android NDK GCC version', 'android_gccversion', configGroup) except: pass # get configuration parameters ndkroot = env.subst(env['android_ndkroot']) arch = env['android_arch'] apilevel = env['android_apilevel'] gccVersion = env['android_gccversion'] # set construction variables stlsupport = 'gnu-libstdc++' if env['android_arch'] == 'armv7': abi = 'androideabi' fullarch = 'armeabi-v7' hardfp = False elif env['android_arch'] == 'armv7a': abi = 'androideabi' fullarch = 'armeabi-v7a' hardfp = True elif env['android_arch'] == 'armv8': abi = 'androideabi' fullarch = 'armeabi-v8' hardfp = True elif env['android_arch'] == 'x86': abi = 'android' fullarch = 'x86' hardfp = False elif env['android_arch'] == 'x86_64': abi = 'android' fullarch = 'x86_64' hardfp = False else: raise Exception('Invalid architecture {}'.format(env['android_arch'])) compilerPrefix = '{}-{}-{}{}-'.format(arch, platform.system().lower(), abi, apilevel) compilerPrefix2 = '{}-{}-{}-'.format(arch, platform.system().lower(), abi) pathToolchain = os.path.join( ndkroot, 'toolchains', 'llvm', 'prebuilt', '-'.join([platform.system().lower(), platform.machine()])) env['ANDROID_TOOLCHAIN'] = pathToolchain pathBin = os.path.join(pathToolchain, 'bin') env['ANDROID_BIN'] = pathBin compiler = os.path.join(pathBin, compilerPrefix) compiler2 = os.path.join(pathBin, compilerPrefix2) env['ANDROID_COMPILER'] = compiler env['ANDROID_FULLARCH'] = fullarch env['ANDROID_HARDFP'] = hardfp env['CC'] = compiler + 'clang' env['CXX'] = compiler + 'clang++' env['LD'] = compiler2 + 'ld' env['STRIP'] = compiler2 + 'strip' env['OBJCOPY'] = compiler2 + 'objcopy' env['AS'] = compiler2 + 'as' env['AR'] = compiler2 + 'ar' env['RANLIB'] = compiler2 + 'ranlib' env['NASM'] = compiler2 + 'yasm' # libraries to link against required for libraries and binaries to load on android. # additional libraries can be required. android is in general quite picky about # these libraries and the loading order env.Append(CROSSCOMPILE_IBS=['m', 'z', 'log', 'c', 'android']) # libs.append( 'gnustl_static' ) # stl support using static gnustl env.Append(CROSSCOMPILE_CPPFLAGS=[ '-O3' ]) # default is -O2 so try to squeeze out a bit more speed if possible # hardware floating point support if hardfp: env.Append(CROSSCOMPILE_CPPFLAGS=['-D_NDK_MATH_NO_SOFTFP=1']) # apply cross compile flags to build environment env.Append(LIBS=env['CROSSCOMPILE_LIBS']) env.Append(CFLAGS=env['CROSSCOMPILE_CFLAGS']) env.Append(CPPFLAGS=env['CROSSCOMPILE_CPPFLAGS']) env.Append(CXXFLAGS=env['CROSSCOMPILE_CXXFLAGS']) env.Append(LINKFLAGS=env['CROSSCOMPILE_LINKFLAGS'])
import os from eiffel_loop.eiffel import project from eiffel_loop.eiffel.ecf import EIFFEL_CONFIG_FILE from eiffel_loop.eiffel.ecf import FREEZE_BUILD from SCons.Environment import Base from SCons.Variables import Variables from glob import glob var = Variables() var.Add('cpu', '', 'x64') var.Add('project', '', glob('*.ecf')[0]) os.environ['ISE_LIBRARY'] = os.environ['ISE_EIFFEL'] env = Base() var.Update(env) env.Append(ENV=os.environ) env.Append(ISE_PLATFORM=os.environ['ISE_PLATFORM']) project_py = project.read_project_py() project_py.set_build_environment(env.get('cpu')) ecf_path = env.get('project') config = EIFFEL_CONFIG_FILE(ecf_path) build = FREEZE_BUILD(config, project_py)
# The build environment. env = Environment(ENV = { 'PATH' : os.environ[ 'PATH' ], 'HOME' : os.environ[ 'HOME' ] }, toolpath = [askaptoolpath], tools = ['default', 'askap_package', 'doxybuilder', 'functestbuilder', 'icebuilder', 'cloptions' ] ) # Importing TERM allows programs (such as clang) to produce colour output # if the terminal supports it if 'TERM' in os.environ: env['ENV']['TERM'] = os.environ['TERM'] opts = Variables('sconsopts.cfg', ARGUMENTS) opts.Add(BoolVariable("nompi", "Disable MPI", False)) opts.Add(BoolVariable("openmp", "Use OpenMP", False)) opts.Add(BoolVariable("update", "svn update?", False)) opts.Update(env) # Standard compiler flags env.AppendUnique(CCFLAGS=['-Wall']) env.AppendUnique(CCFLAGS=['-O2']) env.AppendUnique(CCFLAGS=['-g']) env.AppendUnique(CCFLAGS=['-DASKAP_DEBUG']) # If the system has environment modules support we need to import # the whole environment if has_environment_modules(): env["ENV"] = os.environ
def build(wd,sources,flibs): destdir='../SBA/' global opts flags=[] switches=[] boost=0 # MACROS wordsz=32 WORDSZ='WORDSZ='+str(wordsz) GL='GANNET_LANGUAGE' NEW='' VERBOSE='' #V='VERBOSE' # No SystemC by default SYSC='' SC_IDP='' SYSC_FIXME='' # Compile for VM (otherwise compiles to model HW) VM='VM=0' SEQVM='SEQVM=0' # OLDVM='OLDVM=1' USE_THREADS='USE_THREADS=0' DISTR='DISTR=0' use_pthreads = False # B ashkan USE_TILERA='' #X= 'USE_TILERA' use_tilera = False # E ashkan THREADED_CORE='' # 'THREADED_CORE=0' threaded_core = False # Count CPU cycles CYCLES='' # 'CYCLES' TIMINGS='' # 'TIMINGS' STATIC_ALLOC='STATIC_ALLOC' # Flags #Smash= '-fstack-protector '# Ashkan WARN='' #'-Wall ' CXX11 = '-std=c++11' OPTSPEED = '-O3 -fno-exceptions -fno-rtti ' OPTSIZE = '-Os -fno-exceptions -fno-rtti ' OPTTHREADS = '-O3 ' DEBUG = '' ARCH='' NO_SOCKET='' OPT = '-O3 ' CYGWIN=0 PIC = '' #'-fPIC ' # These are used by the build script to generate flags/switches OSX=0 # Flag for cross-compilation XC=0 # Use LLVM # LLVM=1: x86, LLVM=2: ppc LLVM=0 # SystemC SC=0 H=0 # Help LIB=False MACROS = ['INTERFACE_OBJ'] yaml_config='../../SystemConfigurations/SBA.yml' #use options without leading '-': scons v=0 gui=QtGui opts = Variables() opts.Add('v', 'Verbose', 0) opts.Add('w', 'Warnings', 0) opts.Add('new', 'New', 0) opts.Add('xc', 'Crosscompile',0) opts.Add('llvm', 'Use LLVM',0) opts.Add('win','CygWin',0) opts.Add('vm', 'Virtual Machine',0) opts.Add('sock', 'Use POSIX socket interface',1) opts.Add('svm', 'Sequential Virtual Machine',0) # options can't take . or / in the strings!! # opts.Add('yml','YAML configuration file','') #'../../SBA.yml') opts.Add('cycles', 'Count CPU cycles',0) opts.Add('timings', 'Time program execution',0) opts.Add('dyn', 'Dynamic memory',0) opts.Add('pthreads', 'Use POSIX Threads',0) opts.Add('lib', 'Compile as library',0) opts.Add('wordsz', 'Set WORDSZ',32) opts.Add('ptcore', 'Use POSIX Threaded Core',0) opts.Add('dbg', 'Debug',0) opts.Add('nogen',"Don't generate C++ sources from Ruby code",0) opts.Add('opt', 'Optimise','speed') # or 'size' opts.Add('D','Macros (add as a string: D="MACRO1:1 MACRO2 MACRO3:whatever"\nSCons is too stupid to allow "=")','') # add additional macros as a string opts.Add('h', 'Help',0) args=sys.argv[1:] #import getopt #rest = getopt.getopt(args,"hABCD") for arg in args: if re.match("(\w+)=(\w+)",arg): (k,v)=arg.split('=') opts.args[k]=v #exit(opts.options) for param in os.environ.keys(): if param == "VERBOSE": VERBOSE='VERBOSE' if param == "GANNET_YML_CONFIG": yaml_config=os.environ["GANNET_YML_CONFIG"] for option in opts.options: if option.key == 'v' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: VERBOSE='VERBOSE' if option.key == 'w' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: WARN='-Wall ' if option.key == 'new' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: NEW='NEW=1' if option.key == 'xc' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: XC=1 # B ashkan use_tilera=True USE_TILERA='USE_TILERA' # E ashkan OPT=OPTSPEED if option.key == 'llvm' and opts.args.has_key(option.key): # and opts.args[option.key]!=option.default: if opts.args[option.key]=='1': LLVM=1 elif opts.args[option.key]=='2': LLVM=2 else: LLVM=0 OPT=OPTSPEED if option.key == 'win' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: CYGWIN=1 if option.key == 'vm' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: VM='VM=1' if option.key == 'svm' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: VM='VM=1' SEQVM='SEQVM=1' # doesn't work if the path has dots or slashes! # if option.key == 'yml' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: # print "YAML!" # yaml_config=opts.args[option.key] if option.key == 'sock' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: NO_SOCKET='NO_SOCKET' sockpatt=re.compile('^\.\.\/GannetSocket') nsources=filter(lambda s: not(sockpatt.search(s)),sources) sources=nsources if option.key == 'wordsz' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: wordsz=opts.args[option.key] WORDSZ='WORDSZ='+str(wordsz) if option.key == 'lib' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: LIB=True if option.key == 'pthreads' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: USE_THREADS='USE_THREADS=1' use_pthreads=True OPT=OPTTHREADS if option.key == 'ptcore' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: THREADED_CORE='THREADED_CORE=1' threaded_core=True OPT=OPTTHREADS if option.key == 'distr' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: DISTR='DISTR=1' OPT=OPTSPEED if option.key == 'cycles' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: CYCLES='CYCLES' if option.key == 'timings' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: TIMINGS='TIMINGS' if option.key == 'dyn' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: STATIC_ALLOC='' if option.key == 'dbg' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: DEBUG='-g -O0 -DGMCF_DEBUG ' #'-g -fno-exceptions -fno-rtti ' OPT='' if option.key == 'opt' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: OPT=OPTSPEED if option.key == 'D' and opts.args.has_key(option.key) and opts.args[option.key]!=option.default: macrostr=re.sub('\s*:\s*','=',opts.args[option.key]) MACROS=macrostr.split(' ') if option.key == 'h' and opts.args.has_key(option.key): H=1 if commands.getoutput("uname") == "Darwin": OSX=1 switches+=['DARWIN'] if SC==1: ARCH='-arch i386' # ashkan commented it #if XC==1: # switches.append('__ppc__') FLAGS='' SWITCHES='' flags+=[CXX11,WARN,DEBUG,ARCH,PIC,OPT] # Ashkan added USE_TILERA switches+=[SYSC,SC_IDP,SYSC_FIXME,VERBOSE,NEW,VM,SEQVM,WORDSZ,CYCLES,TIMINGS,STATIC_ALLOC,NO_SOCKET,USE_THREADS,THREADED_CORE,DISTR, USE_TILERA]+MACROS for flag in flags: if flag !='': FLAGS+=flag+' ' for switch in switches: if re.search('BOOST',switch): boost=1 if switch != '': SWITCHES+='-D'+switch+' ' GANNET_DIR=os.environ["GANNET_DIR"] print "GANNET_DIR:"+GANNET_DIR bin='gmcfCoupler' if LIB: sources.append(GANNET_DIR+'/GPRM/src/gmcf.cc') else: sources.append(GANNET_DIR+'/GPRM/src/gmcfCoupler.cc') #------------------------------------------------------------------------------ CXX = os.environ['CXX'] gcc_version = os.popen(CXX+' -dumpversion').read().rstrip("\n\r") gcc_version_tuple = [int(x) for x in gcc_version.split('.')] # WV: HACK! TOO SPECIFIC! if (gcc_version_tuple[1]<6): raise Exception('You need at least g++ 4.6 for this!') else: cxx=CXX if XC==1: # B ashkan # cxx='powerpc-405-linux-gnu-g++' cxx='tile-c++' # E ashkan if LLVM==1: cxx='i686-pc-linux-gnu-g++' env = Environment(variables = opts, CXX = cxx, CXXFLAGS = FLAGS+SWITCHES) # env.VariantDir(wd+'build/',GANNET_DIR+'/GPRM/build/', duplicate=0) # Help(opts.GenerateHelpText(env)) if H==1: print(opts.GenerateHelpText(env)) exit(1) if XC==1: HOME=os.environ['HOME'] env['ENV']['PATH']=os.environ["GANNET_XC_PATH"]+":"+env['ENV']['PATH'] print env['ENV']['PATH'] if LLVM==1: env['ENV']['PATH']=os.environ["GANNET_LLVM_PATH"]+":"+env['ENV']['PATH'] print env['ENV']['PATH'] #FIXME: dl only needed for dynamic loading! #libs=['m','dl'] # In order to link a fortran library compiled with gfortran, we must include the gfortran library. Wonder what the equivalent is for ifort, pgfortran? #FIXME! libs=flibs+['gfortran','m'] libs = ['m'] if use_pthreads or threaded_core: libs+=['pthread'] INCpaths=[wd+'/gensrc/',wd+'/gensrc/GMCF/Models/',wd+'/src/','.','../',GANNET_DIR+'/GPRM/src/SBA/',GANNET_DIR+'/GPRM/src/'] LIBpaths=[wd+'/gensrc/GMCF/Models/'] if OSX==1: LIBpaths=[wd+'/gensrc/GMCF/Models/','/opt/local/lib/gcc49/','/opt/local/lib/','/usr/local/lib/'] #WV: to have multiple targets, we just need to set bin : bin is short for #env.Program(target=bin,...) if LIB: glib=env.Library('gmcf',sources,LIBS=libs,LIBPATH=LIBpaths,CPPPATH=INCpaths) # env.Alias('install_gmcf',env.Install(wd+'/lib',glib)) else: prog=env.Program(bin,sources,LIBS=libs,LIBPATH=LIBpaths,CPPPATH=INCpaths) env.Alias('install',env.Install(wd+'/bin',prog))
def GetNumpyOptions(args): """Call this with args=ARGUMENTS to take into account command line args.""" from SCons.Variables import Variables, EnumVariable, BoolVariable opts = Variables(None, args) opts.Add('scons_tool_path', 'comma-separated list of directories to look '\ 'for tools (take precedence over internal ones)', '') # Add directories related info opts.Add('pkg_name', 'name of the package (including parent package if any)', '') opts.Add('src_dir', 'src dir relative to top called', '.') opts.Add('build_prefix', 'build prefix (NOT including the package name)', get_scons_build_dir()) opts.Add('distutils_libdir', 'build dir for libraries of distutils (NOT including '\ 'the package name)', pjoin('build', 'lib')) opts.Add('distutils_clibdir', 'build dir for pure C libraries (clib), NOT including '\ 'the package name)', pjoin('build', 'lib')) opts.Add('distutils_install_prefix', 'install directory prefix (the one from --prefix)', None) opts.Add('include_bootstrap', "include directories for boostraping numpy (if you do not know" \ " what that means, you don't need it)" , '') opts.Add('pkg_path', "UNDOCUMENTED", '') opts.Add( BoolVariable('inplace', "true if building in place numpy, false if not", 0)) # Add compiler related info opts.Add('cc_opt', 'name of C compiler', '') opts.Add('cc_opt_path', 'path of the C compiler set in cc_opt', '') opts.Add('f77_opt', 'name of F77 compiler', '') opts.Add('f77_opt_path', 'path of the F77 compiler set in cc_opt', '') opts.Add('cxx_opt', 'name of C compiler', '') opts.Add('cxx_opt_path', 'path of the C compiler set in cc_opt', '') opts.Add( BoolVariable('bypass', "true if bypassing compiler detection by distutils", 0)) opts.Add( BoolVariable('import_env', "true if importing user env into numscons env['ENV'].", 0)) opts.Add(BoolVariable('debug', "True if debug mode", 0)) # Silent mode opts.Add(EnumVariable('silent', '0 means max verbose, 1 less verbose, and 2 '\ 'almost nothing', '0', allowed_values = ('0', '1', '2', '3'))) opts.Add( BoolVariable('bootstrapping', "true if bootrapping numpy, false if not", 0)) # Logging option opts.Add('log_level', '0 means max log, Any positive integer is OK '\ '(logging value)', numscons.core.trace.CRITICAL) return opts
# The build environment. env = Environment(ENV = { 'PATH' : os.environ[ 'PATH' ], 'HOME' : os.environ[ 'HOME' ] }, toolpath = [askaptoolpath], tools = ['default', 'askap_package', 'doxybuilder', 'functestbuilder', 'icebuilder', 'cloptions' ] ) # Importing TERM allows programs (such as clang) to produce colour output # if the terminal supports it if 'TERM' in os.environ: env['ENV']['TERM'] = os.environ['TERM'] opts = Variables('sconsopts.cfg', ARGUMENTS) opts.Add(BoolVariable("nompi", "Disable MPI", False)) opts.Add(BoolVariable("openmp", "Use OpenMP", False)) opts.Add(BoolVariable("squash", "Squash some compiler warnings",False)) opts.Add(BoolVariable("usepgi", "Use Portland Group Compiler",False)) opts.Add(BoolVariable("cpp11", "Use c++11",False)) opts.Add(BoolVariable("oldcpp11", "Use c++11 (old flag)",False)) opts.Add(BoolVariable("update", "svn update?", False)) opts.Update(env) # Standard compiler flags env.AppendUnique(CCFLAGS=['-O2']) env.AppendUnique(CCFLAGS=['-g']) env.AppendUnique(CCFLAGS=['-DASKAP_DEBUG']) # Compiler flags related to the upgrade to C++11 support # For most of these, we should reinstate the warnings and fix the code,