def mconfig(argv): kconfig = os.path.join("tools", "menuconfig", "extra", "Configs", "Config.in") display_style = "default selection=fg:white,bg:blue" target_conf = os.path.join(".config") header = "# Generated by Huawei LiteOS Kconfig Tool" mconf_set_env(display_style, target_conf, header) kconf = Kconfig(filename=kconfig) if len(argv) == 2 and argv[1] == 'savemenuconfig': kconf.load_config() print(kconf.write_config()) # savemenuconfig elif len(argv) == 2 and argv[1] == 'defconfig': kconf.load_allconfig("alldef.config") print(kconf.write_config()) # defconfig elif len(argv) == 2 and argv[1] == 'allyesconfig': kconf.warn = False for sym in kconf.unique_defined_syms: sym.set_value(1 if sym.choice else 2) for choice in kconf.unique_choices: choice.set_value(2) kconf.warn = True kconf.load_allconfig("allyes.config") print(kconf.write_config()) # allyesconfig elif len(argv) == 2 and argv[1] == 'allnoconfig': kconf.warn = False for sym in kconf.unique_defined_syms: sym.set_value(2 if sym.is_allnoconfig_y else 0) kconf.warn = True kconf.load_allconfig("allno.config") print(kconf.write_config()) # allnoconfig else: menuconfig(kconf) # menuconfig kconf.write_autoconf()
def hi_mconfig(): kconfig = os.path.join("tools", "menuconfig", "Kconfig") display_style = "default selection=fg:white,bg:red" target_conf = os.path.join("build", "config", "usr_config.mk") header = "# Generated by HiSilicon menuconfig tool" mconf_set_env(display_style, target_conf, header) kconf = Kconfig(filename=kconfig) menuconfig(kconf)
def PrepareBuilding(env, root_directory, has_libcpu=False, remove_components=[]): import rtconfig global BuildOptions global Projects global Env global Rtt_Root # ===== Add option to SCons ===== AddOption('--dist', dest='make-dist', action='store_true', default=False, help='make distribution') AddOption('--dist-strip', dest='make-dist-strip', action='store_true', default=False, help='make distribution and strip useless files') 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.') 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') AddOption( '--target', dest='target', type='string', help= 'set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk/ses/makefile/eclipse' ) AddOption('--genconfig', dest='genconfig', action='store_true', default=False, help='Generate .config from rtconfig.h') AddOption('--useconfig', dest='useconfig', type='string', help='make rtconfig.h from config file.') AddOption('--verbose', dest='verbose', action='store_true', default=False, help='print verbose information during build') Env = env Rtt_Root = os.path.abspath(root_directory) # make an absolute root directory RTT_ROOT = Rtt_Root Export('RTT_ROOT') # 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')] # {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'), 'makefile': ('gcc', 'gcc'), 'eclipse': ('gcc', 'gcc'), 'ses': ('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] # replace the 'RTT_CC' to 'CROSS_TOOL' os.environ['RTT_CC'] = rtconfig.CROSS_TOOL utils.ReloadModule(rtconfig) except KeyError: print('Unknow target: ' + tgt_name + '. Avaible targets: ' + ', '.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') # auto change the 'RTT_EXEC_PATH' when 'rtconfig.EXEC_PATH' get failed if not os.path.exists(rtconfig.EXEC_PATH): if 'RTT_EXEC_PATH' in os.environ: # del the 'RTT_EXEC_PATH' and using the 'EXEC_PATH' setting on rtconfig.py del os.environ['RTT_EXEC_PATH'] utils.ReloadModule(rtconfig) # 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 ' elif rtconfig.PLATFORM == 'iar': env['LIBPREFIX'] = '' env['LIBSUFFIX'] = '.a' env['LIBLINKPREFIX'] = '' env['LIBLINKSUFFIX'] = '.a' env['LIBDIRPREFIX'] = '--search ' # 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/BSP path into Kernel group DefineGroup("Kernel", [], [], 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 = open('rtconfig.h', 'r') contents = f.read() f.close() PreProcessor.process_contents(contents) BuildOptions = PreProcessor.cpp_namespace 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 = '' # generate cconfig.h file GenCconfigFile(env, BuildOptions) # auto append '_REENT_SMALL' when using newlib 'nano.specs' option if rtconfig.PLATFORM == 'gcc' and str( env['LINKFLAGS']).find('nano.specs') != -1: env.AppendUnique(CPPDEFINES=['_REENT_SMALL']) 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('--pyconfig', dest='pyconfig', action='store_true', default=False, help='make menuconfig for RT-Thread BSP') AddOption('--pyconfig-silent', dest='pyconfig_silent', action='store_true', default=False, help='Don`t show pyconfig window') if GetOption('pyconfig_silent'): from menuconfig import pyconfig_silent pyconfig_silent(Rtt_Root) exit(0) elif GetOption('pyconfig'): from menuconfig import pyconfig pyconfig(Rtt_Root) exit(0) configfn = GetOption('useconfig') if configfn: from menuconfig import mk_rtconfig mk_rtconfig(configfn) exit(0) 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
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) 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 ' if rtconfig.PLATFORM == 'gcc': if str(env['LINKFLAGS']).find('nano.specs'): env.AppendUnique(CPPDEFINES = ['_REENT_SMALL']) # 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 # 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/iar/vs/ua') #{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'), 'cb':('keil', 'armcc'), 'ua':('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
#!/usr/bin/env python3 """ Menuconfig variant which uses RiotKconfig as base class """ import menuconfig from riot_kconfig import standard_riot_kconfig # keep documentation from the original tool __doc__ = menuconfig.__doc__ if __name__ == "__main__": menuconfig.menuconfig(standard_riot_kconfig(__doc__))
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) os.environ['PATH'] = rtconfig.EXEC_PATH + ":" + os.environ['PATH'] env.PrependENVPath("PATH", rtconfig.EXEC_PATH) #add rtconfig.h path env.Append(CPPPATH=[str(Dir('#').abspath)]) #add lib 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 components PreProcessor = PatchedPreProcessor() try: f = file('rtconfig.h', 'r') contents = f.read() f.close() except: raise PreProcessor.process_contents(contents) BuildOptions = PreProcessor.cpp_namespace # add copy option AddOption("--copy", dest="copy", action="store_true", default=False, help="copy rt-thread dir to local") AddOption("--copy-header", dest="copy-header", action="store_true", default=False, help="copy header of rt-thread dir 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, require cscope installed") AddOption("--buildlib", dest="buildlib", type="string", help="building lib of a component") AddOption("--cleanlib", dest="cleanlib", action="store_true", default=False, help="clean up the lib ") AddOption("--target", dest="target", type="string", help="set target project") tgt_dict = {"ua": ('gcc', 'gcc')} tgt_name = GetOption('target') if tgt_name: SetOption('no_exec', 1) try: rtconfig.CROSS_TOOL, rtconfig.PLATFORM = tgt_dict[tgt_name] except KeyError: print "unknown target" sys.exit(1) AddOption("--genconfig", dest="genconfig", action="store_true", default=False, help="generate .config from rtconfig.h") 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) AddOption("--verbose", dest="verbose", action="store_true", default=False, help="print verbose info during build") if not GetOption("verbose"): env.Replace(ARCOMSTR="AR $TARGET", ASCOMSTR="AS $TARGET", ASPPCOMSTR="AS $TARGET", CCCOMSTR="CC $TARGET", CXXCOMSTR="CXX $TARGET", LINKCOMSTR="LINK $TARGET") bsp_vdir = "build" kernel_vdir = "build/kernel" # board build script objs = SConscript("SConscript", variant_dir=bsp_vdir, duplicate=0) # objs = SConscript("SConscript", duplicate=0) # include kernel objs.extend( SConscript(Rtt_Root + "/src/SConscript", variant_dir=kernel_vdir + "/src", duplicate=0)) 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
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) # 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 # 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/iar/vs/ua') #{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'), 'cb': ('keil', 'armcc'), 'ua': ('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) # 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') # 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
def generate_make(dest): kconfig.load_config('.config') kconfig.write_config(dest) def defconfig(): kconfig.write_config() if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('--genheader', action='store', default=None) parser.add_argument('--genmake', action='store', default=None) parser.add_argument('--menuconfig', action='store_true') parser.add_argument('--defconfig', action='store_true') args = parser.parse_args() if args.genheader is not None: generate_header(args.genheader) if args.genmake is not None: generate_make(args.genmake) if args.menuconfig: menuconfig.menuconfig(kconfig) if args.defconfig: defconfig()
def main(): global prjname parser = argparse.ArgumentParser(usage=usage_str, add_help=False) parser.add_argument("-w", "--workspace", nargs=2) parser.add_argument("-f", "--force", action='store_true') parser.add_argument('-m', '--menuconfig', action='store_true') parser.add_argument("-s", "--set", nargs="+") parser.add_argument("-v", "--value", nargs="+") parser.add_argument("--add", nargs="+") parser.add_argument("--inc-l", nargs="+") parser.add_argument("--inc-g", nargs="+") parser.add_argument("--cflags-l", nargs="+") parser.add_argument("--cflags-g", nargs="+") parser.add_argument('-h', '--help', action='store_true') args = parser.parse_args() if args.help: parser.print_usage() print(help_str) quit() if args.workspace: prjname = args.workspace[0] # create project or get project form current dir project = libconf.parse_workspace(args.workspace, args.force) if args.add: project["src"] += args.add if args.inc_l: project["inc-l"] += args.inc_l if args.inc_g: project["inc-g"] += args.inc_g if args.cflags_l: project["cflags-l"] += ["-" + x for x in args.cflags_l] if args.cflags_g: project["cflags-g"] += ["-" + x for x in args.cflags_g] # sort options (include paths, flags etc.) for i in project: if project[i] and isinstance(project[i], list): project[i].sort() # set the kconfig configuration file name in system env kconf = libconf.get_kconfig() # handle "-s CONFIG_XX=x" or "--set CONFIG_XX=x", component set command libconf.kconfig_set(args.set) if not os.path.isfile("config/kconfig.mk"): kconf.write_config("config/kconfig.mk") # menu config if args.menuconfig: menuconfig(kconf) # sync settings incase user quited menuconfig without saving, if we do # not do this, the kconfig.mk will be not aligned with kconf which is # updated by menuconfig but not saved! kconf.load_config("config/kconfig.mk", False) # update/create kconfig.h if not os.path.isfile("config/kconfig.h"): kconf.write_autoconf("config/kconfig.h") elif os.path.getmtime("config/kconfig.mk") > os.path.getmtime( "config/kconfig.h"): kconf.write_autoconf("config/kconfig.h") # hande "-v" or "--value", get value if args.value: for v in args.value: match = re.match("CONFIG_([^=]+)", v) if not match: print(v + " not match the 'CONFIG_XX' format, value read ignored.") continue name = match.groups()[0] if name not in kconf.syms: print("kconfig symbol CONFIG_" + name + " not exist, value read ignored.") else: print(v + "=" + kconf.syms[name].str_value) if kconf.syms["USER_APP"].str_value == "y": if not os.path.isfile("syscall_stub.c"): project["src"].append("syscall_stub.c") # update build.mk with open("build.mk", "w", encoding="utf-8") as f: f.write("# created by project maintenance tool, do not edit it!\n") if kconf.syms["USER_APP"].str_value == "y": f.write("usr-y") else: f.write("src-y") f.write(" := " + " ".join(list(set(project["src"]))) + "\n") f.write("inc-l-y := " + " ".join(list(set(project["inc-l"]))) + "\n") f.write("inc-g-y := " + " ".join(list(set(project["inc-g"]))) + "\n") f.write("cflags-l := " + " ".join(list(set(project["cflags-l"]))) + "\n") f.write("cflags-g := " + " ".join(list(set(project["cflags-g"]))) + "\n") # make must be issued after build.mk created if kconf.syms["USER_APP"].str_value == "y": if not os.path.isfile("syscall_stub.c"): with open("main.c", "w", encoding="utf-8") as f: f.write(user_main) with open(prjname + ".prj", "wb") as f: pickle.dump(project, f) os.system("make syscall_stub.c") # save prj if not os.path.isfile(prjname + ".prj"): with open(prjname + ".prj", "wb") as f: pickle.dump(project, f) elif args.add or args.inc_l or args.inc_g or args.cflags_l or args.cflags_g: with open(prjname + ".prj", "wb") as f: pickle.dump(project, f) # quit if NOIDE selected if kconf.syms["NOIDE"].str_value == "y": return # generate/update IDE project if any IDE support is enabled if not os.path.isfile(prjname + "." + kconf.syms["IDE_EXT"].str_value): os.system("make gen-ide GENIDE=1") quit() if os.path.getmtime("config/kconfig.mk") > os.path.getmtime( prjname + "." + kconf.syms["IDE_EXT"].str_value): os.system("make gen-ide GENIDE=1")