示例#1
0
def GenCconfigFile(env, BuildOptions):
    import rtconfig

    print("genconfig")

    if rtconfig.PLATFORM == 'gcc':
        contents = ''
        if not os.path.isfile('cconfig.h'):
            import gcc
            gcc.GenerateGCCConfig(rtconfig)

        # try again
        if os.path.isfile('cconfig.h'):
            f = open('cconfig.h', 'r')
            if f:
                contents = f.read()
                f.close()

                prep = PatchedPreProcessor()
                prep.process_contents(contents)
                options = prep.cpp_namespace

                BuildOptions.update(options)

                # add HAVE_CCONFIG_H definition
                env.AppendUnique(CPPDEFINES=['HAVE_CCONFIG_H'])
示例#2
0
def PrepareBuilding(env,
                    root_directory,
                    has_libcpu=False,
                    remove_components=[]):
    import SCons.cpp
    import rtconfig

    global BuildOptions
    global Projects
    global Env
    global Rtt_Root

    Env = env
    Rtt_Root = os.path.abspath(root_directory)
    # set RTT_ROOT in ENV
    Env['RTT_ROOT'] = Rtt_Root
    # set BSP_ROOT in ENV
    Env['BSP_ROOT'] = Dir('#').abspath

    sys.path = sys.path + [os.path.join(Rtt_Root, 'tools')]

    # add compability with Keil MDK 4.6 which changes the directory of armcc.exe
    if rtconfig.PLATFORM == 'armcc':
        if not os.path.isfile(os.path.join(rtconfig.EXEC_PATH, 'armcc.exe')):
            if rtconfig.EXEC_PATH.find('bin40') > 0:
                rtconfig.EXEC_PATH = rtconfig.EXEC_PATH.replace(
                    'bin40', 'armcc/bin')
                Env['LINKFLAGS'] = Env['LINKFLAGS'].replace('RV31', 'armcc')

        # reset AR command flags
        env['ARCOM'] = '$AR --create $TARGET $SOURCES'
        env['LIBPREFIX'] = ''
        env['LIBSUFFIX'] = '.lib'
        env['LIBLINKPREFIX'] = ''
        env['LIBLINKSUFFIX'] = '.lib'
        env['LIBDIRPREFIX'] = '--userlibpath '

    # patch for win32 spawn
    if env['PLATFORM'] == 'win32':
        win32_spawn = Win32Spawn()
        win32_spawn.env = env
        env['SPAWN'] = win32_spawn.spawn

    if env['PLATFORM'] == 'win32':
        os.environ['PATH'] = rtconfig.EXEC_PATH + ";" + os.environ['PATH']
    else:
        os.environ['PATH'] = rtconfig.EXEC_PATH + ":" + os.environ['PATH']

    # add program path
    env.PrependENVPath('PATH', rtconfig.EXEC_PATH)
    # add rtconfig.h path
    env.Append(CPPPATH=[str(Dir('#').abspath)])

    # add library build action
    act = SCons.Action.Action(BuildLibInstallAction,
                              'Install compiled library... $TARGET')
    bld = Builder(action=act)
    Env.Append(BUILDERS={'BuildLib': bld})

    # parse rtconfig.h to get used component
    PreProcessor = PatchedPreProcessor()
    f = file('rtconfig.h', 'r')
    contents = f.read()
    f.close()
    PreProcessor.process_contents(contents)
    BuildOptions = PreProcessor.cpp_namespace

    if rtconfig.PLATFORM == 'gcc':
        contents = ''
        if not os.path.isfile('cconfig.h'):
            import gcc
            gcc.GenerateGCCConfig(rtconfig)

        # try again
        if os.path.isfile('cconfig.h'):
            f = file('cconfig.h', 'r')
            if f:
                contents = f.read()
                f.close()

                prep = PatchedPreProcessor()
                prep.process_contents(contents)
                options = prep.cpp_namespace

                BuildOptions.update(options)

                # add HAVE_CCONFIG_H definition
                env.AppendUnique(CPPDEFINES=['HAVE_CCONFIG_H'])

        if str(env['LINKFLAGS']).find('nano.specs') != -1:
            env.AppendUnique(CPPDEFINES=['_REENT_SMALL'])

    # add copy option
    AddOption('--copy',
              dest='copy',
              action='store_true',
              default=False,
              help='copy rt-thread directory to local.')
    AddOption('--copy-header',
              dest='copy-header',
              action='store_true',
              default=False,
              help='copy header of rt-thread directory to local.')
    AddOption('--dist',
              dest='make-dist',
              action='store_true',
              default=False,
              help='make distribution')
    AddOption(
        '--cscope',
        dest='cscope',
        action='store_true',
        default=False,
        help='Build Cscope cross reference database. Requires cscope installed.'
    )
    AddOption('--clang-analyzer',
                      dest='clang-analyzer',
                      action='store_true',
                      default=False,
                      help='Perform static analyze with Clang-analyzer. '+\
                           'Requires Clang installed.\n'+\
                           'It is recommended to use with scan-build like this:\n'+\
                           '`scan-build scons --clang-analyzer`\n'+\
                           'If things goes well, scan-build will instruct you to invoke scan-view.')

    if GetOption('clang-analyzer'):
        # perform what scan-build does
        env.Replace(
            CC='ccc-analyzer',
            CXX='c++-analyzer',
            # skip as and link
            LINK='true',
            AS='true',
        )
        env["ENV"].update(x for x in os.environ.items()
                          if x[0].startswith("CCC_"))
        # only check, don't compile. ccc-analyzer use CCC_CC as the CC.
        # fsyntax-only will give us some additional warning messages
        env['ENV']['CCC_CC'] = 'clang'
        env.Append(
            CFLAGS=['-fsyntax-only', '-Wall', '-Wno-invalid-source-encoding'])
        env['ENV']['CCC_CXX'] = 'clang++'
        env.Append(CXXFLAGS=[
            '-fsyntax-only', '-Wall', '-Wno-invalid-source-encoding'
        ])
        # remove the POST_ACTION as it will cause meaningless errors(file not
        # found or something like that).
        rtconfig.POST_ACTION = ''

    # add build library option
    AddOption('--buildlib',
              dest='buildlib',
              type='string',
              help='building library of a component')
    AddOption('--cleanlib',
              dest='cleanlib',
              action='store_true',
              default=False,
              help='clean up the library by --buildlib')

    # add target option
    AddOption('--target',
              dest='target',
              type='string',
              help='set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk')

    #{target_name:(CROSS_TOOL, PLATFORM)}
    tgt_dict = {
        'mdk': ('keil', 'armcc'),
        'mdk4': ('keil', 'armcc'),
        'mdk5': ('keil', 'armcc'),
        'iar': ('iar', 'iar'),
        'vs': ('msvc', 'cl'),
        'vs2012': ('msvc', 'cl'),
        'vsc': ('gcc', 'gcc'),
        'cb': ('keil', 'armcc'),
        'ua': ('gcc', 'gcc'),
        'cdk': ('gcc', 'gcc')
    }
    tgt_name = GetOption('target')

    if tgt_name:
        # --target will change the toolchain settings which clang-analyzer is
        # depend on
        if GetOption('clang-analyzer'):
            print '--clang-analyzer cannot be used with --target'
            sys.exit(1)

        SetOption('no_exec', 1)
        try:
            rtconfig.CROSS_TOOL, rtconfig.PLATFORM = tgt_dict[tgt_name]
        except KeyError:
            print 'Unknow target: %s. Avaible targets: %s' % \
                    (tgt_name, ', '.join(tgt_dict.keys()))
            sys.exit(1)
    elif (GetDepend('RT_USING_NEWLIB') == False and GetDepend('RT_USING_NOLIBC') == False) \
        and rtconfig.PLATFORM == 'gcc':
        AddDepend('RT_USING_MINILIBC')

    AddOption('--genconfig',
              dest='genconfig',
              action='store_true',
              default=False,
              help='Generate .config from rtconfig.h')
    if GetOption('genconfig'):
        from genconf import genconfig
        genconfig()
        exit(0)

    if env['PLATFORM'] != 'win32':
        AddOption('--menuconfig',
                  dest='menuconfig',
                  action='store_true',
                  default=False,
                  help='make menuconfig for RT-Thread BSP')
        if GetOption('menuconfig'):
            from menuconfig import menuconfig
            menuconfig(Rtt_Root)
            exit(0)

    AddOption('--useconfig',
              dest='useconfig',
              type='string',
              help='make rtconfig.h from config file.')
    configfn = GetOption('useconfig')
    if configfn:
        from menuconfig import mk_rtconfig
        mk_rtconfig(configfn)
        exit(0)

    # add comstr option
    AddOption('--verbose',
              dest='verbose',
              action='store_true',
              default=False,
              help='print verbose information during build')

    if not GetOption('verbose'):
        # override the default verbose command string
        env.Replace(ARCOMSTR='AR $TARGET',
                    ASCOMSTR='AS $TARGET',
                    ASPPCOMSTR='AS $TARGET',
                    CCCOMSTR='CC $TARGET',
                    CXXCOMSTR='CXX $TARGET',
                    LINKCOMSTR='LINK $TARGET')

    # fix the linker for C++
    if GetDepend('RT_USING_CPLUSPLUS'):
        if env['LINK'].find('gcc') != -1:
            env['LINK'] = env['LINK'].replace('gcc', 'g++')

    # we need to seperate the variant_dir for BSPs and the kernels. BSPs could
    # have their own components etc. If they point to the same folder, SCons
    # would find the wrong source code to compile.
    bsp_vdir = 'build'
    kernel_vdir = 'build/kernel'
    # board build script
    objs = SConscript('SConscript', variant_dir=bsp_vdir, duplicate=0)
    # include kernel
    objs.extend(
        SConscript(Rtt_Root + '/src/SConscript',
                   variant_dir=kernel_vdir + '/src',
                   duplicate=0))
    # include libcpu
    if not has_libcpu:
        objs.extend(
            SConscript(Rtt_Root + '/libcpu/SConscript',
                       variant_dir=kernel_vdir + '/libcpu',
                       duplicate=0))

    # include components
    objs.extend(
        SConscript(Rtt_Root + '/components/SConscript',
                   variant_dir=kernel_vdir + '/components',
                   duplicate=0,
                   exports='remove_components'))

    return objs