Exemplo n.º 1
0
def set_install_targets(env):
    env.Alias('libs', env['buildLibDir'])
    env.Alias('install-libs', env['libDir'])

    if 'install' in SCons.Script.BUILD_TARGETS:
        if len(SCons.Script.BUILD_TARGETS) > 1:
            SCons.Script.BUILD_TARGETS.remove('install')
            newtargets = []
            for target in SCons.Script.BUILD_TARGETS:
                newtargets.append(os.path.join(env['binDir'], str(target)))
            SCons.Script.BUILD_TARGETS = newtargets
            if env['verbose'] > 3:
                print infostr('will only build and install targets:'),
                print tgtstr(SCons.Script.BUILD_TARGETS)
    else:
        remove_tgts = []
        add_tgts = []
        for tgt in SCons.Script.BUILD_TARGETS:
            if not '/' == tgt[0]:
                if not tgt in 'libs install-libs'.split():
                    remove_tgts += [tgt]
                    add_tgts += [os.path.join(env['buildBinDir'], tgt)]
        for tgt in remove_tgts:
            SCons.Script.BUILD_TARGETS.remove(tgt)
        for tgt in add_tgts:
            SCons.Script.BUILD_TARGETS += [tgt]
Exemplo n.º 2
0
def help_text(env, opt, help, default, actual, aliases=[]):
    help = help[::-1].replace(' (','(',1).replace(') ',')',1)[::-1]
    help = textwrap.dedent(help)
    fmt = '\n' + tgtstr(opt) + ': '
    fmt += textwrap.fill(infostr(help),60,subsequent_indent='\t')
    fmt += '\n\t' + infostr('default = ') + srcstr(default)
    if not str(actual) is str(default):
        fmt += '\n\t' + src2str('actual  = ' + str(actual))
    return fmt
Exemplo n.º 3
0
def jar(env, target, source=None, manifest=None):
    '''jar

    builds jar files from java source code.

    env
        The SCons.Environment
    target
        a string specifying the target jar file to be created.
        This is a required field. The '.jar' extension may be
        omitted (recommended).
    source
        list of source files (strings or SCons Nodes)
        if type None (default) the java compiler will use the
        current directory as the source-base for class files.
    manifest
        a string specifying the manifest file to be used in the jar.
        This manifest file MUST begin with 'Manifest-Version' to ensure
        SCons recognizes it.

    any jar files in the current directory will be automatically
    added to the JAVACLASSPATH SCons variable.
    '''

    if not target:
        raise Exception(alertstr('No target specified'))

    if not source:
        source = ['.']

    build_obj_dir = build_obj_directory(env)
    classdir = os.path.join(build_obj_dir, 'classes')
    target = os.path.join(env['buildJavaDir'], target)

    env.AppendUnique(JAVACLASSPATH=[str(x) for x in env.Glob('*.jar')])

    if env['verbose'] > 1:
        print infostr('  reading in library:'), tgt2str(target)
        if env['verbose'] > 3:
            print infostr('    classes directory:'), srcstr(classdir)

    class_files = env.Java(classdir, source)

    if manifest:
        class_files += [manifest]

    jar_file = env.Jar(target, class_files)

    env.Install(env['javaDir'], jar_file)

    return (jar_file, class_files)
Exemplo n.º 4
0
def print_install_dirs(env):
    print(
        infostr('==== install directories ====') + '''
  binDir:  ''' + infostr(env['binDir']) + '''
  libDir:  ''' + infostr(env['libDir']) + '''
  incDir:  ''' + infostr(env['incDir']) + '''
  scrDir:  ''' + infostr(env['scrDir']) + '''

  etcDir:  ''' + infostr(env['etcDir']) + '''
  dataDir: ''' + infostr(env['dataDir']) + '''
  docDir:  ''' + infostr(env['docDir']) + '''

  testDir: ''' + infostr(env['testDir']) + '''
  tutDir:  ''' + infostr(env['tutDir']) + '''
    ''')
Exemplo n.º 5
0
def cmd_abstract(s, target, source, env):
    '''s is the original command line, target and src
    are lists of target and source nodes respectively,
    and env is the environment.'''
    cmd = s.split()[0]
    if not cmd in _ignore_cmd_list:
        if cmd == 'Install':
            line = infostr('Installing:')
            for x in target:
                line += ' ' + tgt2str(x)
        else:
            line = infostr('Building:')
            for x in source:
                line += ' ' + src2str(str(x).split(os.sep)[-1])
            line += '   ' + infostr('--->') + '  '
            for x in target:
                line += ' ' + tgt2str(str(x).split(os.sep)[-1])
        line += '\n'
        sys.stdout.write(line)
Exemplo n.º 6
0
def sconstruct(env, dirs):
    '''sconstruct

    calls SConscript method on sconstruct files in directories
    listed in dirs.

    env
        The SCons environment.

    dirs
        A list of strings respresenting the directories which
        the SConscript method should be called in.
    '''
    dirs = SCons.Script.Flatten([dirs])
    scons_files = [os.path.join(d, 'sconstruct') for d in dirs]
    ret = {}
    for f in scons_files:
        if env['verbose'] > 3:
            print infostr('reading SConstruct file:'), src2str(f)
        env.SConscript(f, exports={'env': env, 'ret': ret})
    return ret
Exemplo n.º 7
0
def initialize(project_name, deps):
    try:
        tmp = initialize.run_once
        raise Exception(
            alertstr(
                str(initialize) + ''' called twice.
            This should never happen.'''))
    except AttributeError:
        initialize.run_once = True

    optimization.init()

    env = SCons.Environment.Environment(ENV={'PATH': os.environ['PATH']})
    try:
        env.Append(ENV={'LD_LIBRARY_PATH': os.environ['LD_LIBRARY_PATH']})
    except:
        pass
    env.EnsurePythonVersion(2, 2)
    env.EnsureSConsVersion(1, 0)

    add_methods(env)

    if project_name:
        env['projectName'] = project_name
    else:
        env['projectName'] = False

    env['platformName'] = platform_string.platform_string(env)

    variables.set_config_file(env)
    variables.add(env)

    stylize.init(env)

    for tool in env['tools']:
        env.Tool(tool)

    if len(deps):
        dependency.add_variables(env, deps)

    env['verbose'] = int(env['verbose'])

    env['vars'].Save(env['configFile'], env)

    format.generate_help_text(env)
    format.cmd_output(env)

    variables.load(env)

    optimization.set_flags(env)
    set_install_targets(env)

    env.VariantDir(env['buildObjDir'], '.', duplicate=0)
    env['JAVACHDIR'] = True

    if env['verbose'] in [1, 2]:
        msg = infostr('evaluating targets')
        SCons.Script.Progress([
            '  -  ' + msg + '\r', '  \\  ' + msg + '\r', '  |  ' + msg + '\r',
            '  /  ' + msg + '\r'
        ],
                              interval=1)

    proc = Popen('which gcc',
                 env=os.environ,
                 shell=True,
                 stdout=PIPE,
                 stderr=PIPE)
    gccpath = proc.communicate()[0].split('\n')[0]
    if os.path.normpath(gccpath[:8]) != os.path.normpath('/usr/lib'):
        gccrpath = os.path.split(gccpath)[0].replace('bin', 'lib')
        if env['alignbits'] in ['native', '64']:
            gccrpath += '64'
        env.AppendUnique(RPATH=[gccrpath])

    return env
Exemplo n.º 8
0
def program(env, target=None, source=None, ignore=None, libs=None):
    '''program

    builds a C/C++/FORTRAN program from the given source files
    or those source files in the current directory.

    env
        The SCons environment.

    target
        a string specifying the name of the program to be created.

    source
        a list of source files which SCons will compile into a program.
        The first item of the list must be the source containing main().
        If left unspecified, SCons will Glob for all appropriate source files.

    ignore
        a list of files to ignore.

    libs
        a list of strings specifying libraries the program is dependent on.

    #static
    #    link statically to libraries (default is False which uses the
    #    compiler's default behavior)
    '''
    pre_build(env)

    target, src = find_target_and_source(env, target, source, ignore)

    build_obj_dir = build_obj_directory(env)

    if env['verbose'] > 1:
        print infostr('  reading in program:'), tgtstr(target)
        if env['verbose'] > 3:
            print infostr('    source:'),
            for s in src['source']:
                print srcstr(s),
            print ''
            print infostr('    object directory:'), srcstr(build_obj_dir)

    sources = src['source']
    src['source'] = []
    for s in sources:
        if str(s)[:len(build_obj_dir[1:])] != build_obj_dir[1:]:
            src['source'] += [os.path.join(build_obj_dir, str(s))]
        else:
            src['source'] += [s]
    target = os.path.join(env['buildBinDir'], target)

    env.PrependUnique(PATH=[env.Dir('.')],
                      CPPPATH=[env.Dir('.')],
                      FORTRANPATH=[env.Dir('.')])

    if libs:
        libs = SCons.Script.Flatten([libs])
        env.AppendUnique(LIBS=libs)

    static_objs = []
    try:
        for s in src['source']:
            static_objs += env.StaticObject(s)
    except:
        pass
    try:
        static_objs += src['static_objs']
    except:
        pass

    #if static:
    #    env.AppendUnique(LINKFLAGS = ['-static'])

    prog = env.Program(target, static_objs)
    env.Install(env['binDir'], prog)

    ret = {'prog': {str(prog): static_objs}}
    return ret
Exemplo n.º 9
0
def library(env,
            target=None,
            source=None,
            ignore=None,
            headers=['.'],
            lib_type='both'):
    '''library

    creates a C/C++/FORTRAN library (static, shared, or both) from
    given source or source files found in the current directory.

    env
        The SCons.Environment
    target
        a string specifying the name of the target
        if type None (default) it will be determined
        from source files in find_target_and_source() method
    source
        list of source files (strings or SCons Nodes)
        if type None (default) SCons will Glob for all
        source-type files in the current directory.
    ignore
        list of source and header files to ignore if and only
        if source or header is not specified respectively.
    headers
        list of headers passed to install_headers method
    lib_type
        'both' (default)
        'shared'
        'static'
    '''
    pre_build(env)

    if not lib_type in ['both', 'static', 'shared']:
        raise Exception(
            alertstr('''types of libraries may only be one of:
            static, shared, both
            ("''' + lib_type + '''" was given for library "''' + target +
                     '''")'''))

    env.PrependUnique(PATH=[env.Dir('.')],
                      CPPPATH=[env.Dir('.')],
                      FORTRANPATH=[env.Dir('.')])

    target, src = find_target_and_source(env, target, source, ignore)

    build_obj_dir = build_obj_directory(env)

    if env['verbose'] > 1:
        print infostr('  reading in library:'), tgt2str(target)
        if env['verbose'] > 3:
            print infostr('    source:'),
            for t in ['source', 'static_objs', 'shared_objs']:
                try:
                    for s in src[t]:
                        print srcstr(s),
                except:
                    pass
            print ''
            print infostr('    target directory:'),
            print srcstr(build_obj_dir)

    src['source'] = [
        os.path.join(build_obj_dir, str(s)) for s in src['source']
    ]
    target = os.path.join(env['buildLibDir'], target)

    if not env['static']:
        if lib_type is 'both':
            lib_type = 'shared'
        else:
            lib_type = 'none'
    if not env['shared']:
        if lib_type is 'both':
            lib_type = 'static'
        else:
            lib_type = 'none'

    static_objs = []
    shared_objs = []

    if lib_type in ['both', 'static']:
        try:
            for s in src['source']:
                obj = env.StaticObject(s)
                if os.path.splitext(str(s))[-1] in ['.F', '.Fpp', '.fpp']:
                    fpp_incs = fpp_includes(env, env.File(s))
                    env.Depends(obj, fpp_incs)
                static_objs += obj
        except:
            pass
        try:
            static_objs += src['static_objs']
        except:
            pass
        if len(static_objs):
            static_lib = env.StaticLibrary(target, static_objs)
            env.Install(env['libDir'], static_lib)

    if lib_type in ['both', 'shared']:
        try:
            for s in src['source']:
                obj = env.SharedObject(s)
                if os.path.splitext(str(s))[-1] in ['.F', '.Fpp', '.fpp']:
                    fpp_incs = fpp_includes(env, env.File(s))
                    env.Depends(obj, fpp_incs)
                shared_objs += obj
        except:
            pass
        try:
            shared_objs += src['shared_objs']
        except:
            pass
        # WORKAROUND
        # shared libs created from shared objects
        # should not be linked to any other libraries
        # hence the LIBPATH=[], LIBS=[], RPATH=[]
        # this is might be an SCons bug
        if len(shared_objs):
            shared_lib = env.SharedLibrary(target,
                                           shared_objs,
                                           LIBPATH=[],
                                           LIBS=[],
                                           RPATH=[])
            env.Install(env['libDir'], shared_lib)

    install_headers(env, headers, ignore)

    ret = {'static_libs': {}, 'shared_libs': {}}
    if lib_type in ['both', 'static']:
        try:
            ret['static_libs'][str(static_lib[0])] = static_objs
        except:
            pass
    if lib_type in ['both', 'shared']:
        try:
            ret['shared_libs'][str(shared_lib[0])] = shared_objs
        except:
            pass
    return ret
Exemplo n.º 10
0
def print_build_dirs(env):
    print(
        infostr('==== build directories ====') + '''
  buildDir:     ''' + infostr(env['buildDir']) + '''

  buildBinDir:  ''' + infostr(env['buildBinDir']) + '''
  buildLibDir:  ''' + infostr(env['buildLibDir']) + '''
  buildIncDir:  ''' + infostr(env['buildIncDir']) + '''
  buildScrDir:  ''' + infostr(env['buildScrDir']) + '''

  buildEtcDir:  ''' + infostr(env['buildEtcDir']) + '''
  buildDataDir: ''' + infostr(env['buildDataDir']) + '''
  buildDocDir:  ''' + infostr(env['buildDocDir']) + '''

  buildTestDir: ''' + infostr(env['buildTestDir']) + '''
  buildTutDir:  ''' + infostr(env['buildTutDir']) + '''

  buildObjDir:  ''' + infostr(env['buildObjDir']) + '''
    ''')
Exemplo n.º 11
0
def print_loaded_dependencies(loaded):
    for dep in loaded:
        print infostr('  loaded external library:'), tgt2str(dep)
        if loaded[dep]['type'] in ['header_and_binary', 'header_only']:
            print infostr('    include dir:'), \
                srcstr(loaded[dep]['incdir'])
        if loaded[dep]['type'] in ['header_and_binary', 'binary_only']:
            print infostr('    library dir:'), \
                srcstr(loaded[dep]['libdir'])
            print infostr('    libraries:'), \
                srcstr(loaded[dep]['libs'])
        if loaded[dep]['flags']:
            print infostr('    flags:'), \
                srcstr(loaded[dep]['flags'][0])
            print infostr('    defines:'), \
                srcstr(loaded[dep]['flags'][1])
        if loaded[dep]['vars']:
            for var, val in loaded[dep]['vars']:
                print infostr('    ' + var + ':'), srcstr(val)