1#
2# File      : options.py
3# This file is part of RT-Thread RTOS
4# COPYRIGHT (C) 2006 - 2015, RT-Thread Development Team
5#
6#  This program is free software; you can redistribute it and/or modify
7#  it under the terms of the GNU General Public License as published by
8#  the Free Software Foundation; either version 2 of the License, or
9#  (at your option) any later version.
10#
11#  This program is distributed in the hope that it will be useful,
12#  but WITHOUT ANY WARRANTY; without even the implied warranty of
13#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14#  GNU General Public License for more details.
15#
16#  You should have received a copy of the GNU General Public License along
17#  with this program; if not, write to the Free Software Foundation, Inc.,
18#  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19#
20# Change Logs:
21# Date           Author       Notes
22# 2022-04-20     WuGensheng  Add Options to SCons
23# 2025-03-02     ZhaoCake    Add Options about compile_commands
24
25from SCons.Script import AddOption
26import platform
27
28def AddOptions():
29    ''' ===== Add generic options to SCons ===== '''
30    AddOption('--dist',
31                dest = 'make-dist',
32                action = 'store_true',
33                default = False,
34                help = 'make distribution')
35    AddOption('--dist-ide', '--dist-rtstudio',
36                dest = 'make-dist-ide',
37                action = 'store_true',
38                default = False,
39                help = 'make distribution for RT-Thread Studio IDE')
40    AddOption('--project-path',
41                dest = 'project-path',
42                type = 'string',
43                default = None,
44                help = 'set project output path')
45    AddOption('--project-name',
46                dest = 'project-name',
47                type = 'string',
48                default = "project",
49                help = 'set project name')
50    AddOption('--cscope',
51                dest = 'cscope',
52                action = 'store_true',
53                default = False,
54                help = 'Build Cscope cross reference database. Requires cscope installed.')
55    AddOption('--clang-analyzer',
56                dest = 'clang-analyzer',
57                action = 'store_true',
58                default = False,
59                help = 'Perform static analyze with Clang-analyzer. ' + \
60                    'Requires Clang installed.' + \
61                    'It is recommended to use with scan-build like this:' + \
62                    '`scan-build scons --clang-analyzer`' + \
63                    'If things goes well, scan-build will instruct you to invoke scan-view.')
64    AddOption('--buildlib',
65                dest = 'buildlib',
66                type = 'string',
67                help = 'building library of a component')
68    AddOption('--cleanlib',
69                dest = 'cleanlib',
70                action = 'store_true',
71                default = False,
72                help = 'clean up the library by --buildlib')
73    AddOption('--target',
74                dest = 'target',
75                type = 'string',
76                help = 'set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/cdk/ses/makefile/eclipse/codelite/cmake/vsc_workspace')
77    AddOption('--cmsispack',
78                dest = 'cmsispack',
79                type = 'string',
80                help = 'set pack: <cmsispack path>')
81    AddOption('--strict',
82                dest='strict-compiling',
83                help='Compiling project with strict mode and ALL warning will be errors',
84                action='store_true',
85                default=False)
86    AddOption('--verbose',
87                dest = 'verbose',
88                action = 'store_true',
89                default = False,
90                help = 'print verbose information during build')
91    AddOption('--cc-prefix', '--exec-prefix',
92                dest = 'exec-prefix',
93                type = 'string',
94                help = 'set RTT_CC_PREFIX temperately')
95    AddOption('--cc-path', '--exec-path',
96                dest = 'exec-path',
97                type = 'string',
98                help = 'set RTT_EXEC_PATH temperately')
99    AddOption('--stackanalysis',
100                dest = 'stackanalysis',
101                action = 'store_true',
102                default = False,
103                help = 'thread stack static analysis')
104    AddOption('--genconfig',
105                dest = 'genconfig',
106                action = 'store_true',
107                default = False,
108                help = 'Generate .config from rtconfig.h')
109    AddOption('--useconfig',
110                dest = 'useconfig',
111                type = 'string',
112                help = 'make rtconfig.h from config file.')
113    AddOption('--global-macros',
114                dest = 'global-macros',
115                type = 'string',
116                help = 'attach global macros in the project. '+\
117                'e.g. scons --global-config=RT_USING_XX,RT_USING_YY'+\
118                ' or scons --global-config="RT_USING_XX, RT_USING_YY"')
119    AddOption('--reset-project-config',
120                dest = 'reset-project-config',
121                action = 'store_true',
122                default = False,
123                help = 'reset the project configurations to default')
124    AddOption('--guiconfig', '--pyconfig',
125                dest = 'guiconfig',
126                action = 'store_true',
127                default = False,
128                help = 'Python GUI menuconfig for RT-Thread BSP')
129    AddOption('--defconfig', '--pyconfig-silent',
130                dest = 'defconfig',
131                action = 'store_true',
132                default = False,
133                help = 'Don`t show Python GUI menuconfig window')
134    AddOption('--menuconfig',
135                dest = 'menuconfig',
136                action = 'store_true',
137                default = False,
138                help = 'make menuconfig for RT-Thread BSP')
139    AddOption('--cdb',
140                dest = 'cdb',
141                action = 'store_true',
142                default = False,
143                help = 'make compile_commands.json')
144    AddOption('--attach',
145                dest = 'attach',
146                type = 'string',
147                help = 'View attachconfig or add attach to.config.'+\
148                'e.g. scons --attach=? View all attachconfig for the current bsp.'+\
149                ' or scons --attach=component.cherryusb_cdc Set option component.cherryusb_cdc inside attachconfig to.config.'+\
150                ' or scons --attach=default Restore.config and rtconfig to before attch was set.')
151    AddOption('--dist-strip',
152              dest='dist_strip',
153              action='store_true',
154              default=False,
155              help='create minimal distribution based on compile_commands.json.'+\
156              'So you should run `bear -- scons` to generate compile_commands.json first.')