xref: /nrf52832-nimble/rt-thread/tools/tools/clang-analyze.py (revision 104654410c56c573564690304ae786df310c91fc)
1"""
2Tool-specific initialization for Clang static analyzer
3
4There normally shouldn't be any need to import this module directly.
5It will usually be imported through the generic SCons.Tool.Tool()
6selection method.
7"""
8
9__revision__ = "tools/clang-analyze.py 2013-09-06 grissiom"
10
11import os
12import os.path
13
14import SCons.Action
15import SCons.Builder
16import SCons.Defaults
17import SCons.Tool
18import SCons.Util
19
20import rtconfig
21
22def generate(env):
23    assert(rtconfig.CROSS_TOOL == 'clang-analyze')
24    # let gnu_tools setup a basic env(learnt from SCons/Tools/mingw.py)
25    gnu_tools = ['gcc', 'g++', 'gnulink', 'ar', 'gas', 'm4']
26    for tool in gnu_tools:
27        SCons.Tool.Tool(tool)(env)
28
29    # then we could stand on the shoulders of gaints
30    env['CC']   = 'ccc-analyzer'
31    env['CXX']  = 'c++-analyzer'
32    env['AS']   = 'true'
33    env['AR']   = 'true'
34    env['LINK'] = 'true'
35
36    env['CFLAGS']    = ['-fsyntax-only', '-Wall', '-Wno-invalid-source-encoding', '-m32']
37    env['LINKFLAGS'] = '-Wl,--gc-sections'
38    env['ARFLAGS']   = '-rc'
39
40    # only check, don't compile. ccc-analyzer use CCC_CC as the CC.
41    # fsyntax-only will give us some additional warning messages
42    env['ENV']['CCC_CC'] = 'clang'
43    env['ENV']['CCC_CXX'] = 'clang++'
44
45    # setup the output dir and format
46    env['ENV']['CCC_ANALYZER_HTML'] = './build/'
47    env['ENV']['CCC_ANALYZER_OUTPUT_FORMAT'] = 'html'
48
49    # Some setting from the platform also have to be overridden:
50    env['OBJSUFFIX'] = '.o'
51    env['LIBPREFIX'] = 'lib'
52    env['LIBSUFFIX'] = '.a'
53
54    if rtconfig.EXEC_PATH:
55        if not os.path.exists(rtconfig.EXEC_PATH):
56            print
57            print 'warning: rtconfig.EXEC_PATH(%s) does not exists.' % rtconfig.EXEC_PATH
58            print
59            return
60        env.AppendENVPath('PATH', rtconfig.EXEC_PATH)
61
62def exists(env):
63    return env.Detect(['ccc-analyzer', 'c++-analyzer'])
64
65# Local Variables:
66# tab-width:4
67# indent-tabs-mode:nil
68# End:
69# vim: set expandtab tabstop=4 shiftwidth=4:
70