2013-08-06 13:38:00 +00:00
|
|
|
"""
|
|
|
|
mbed SDK
|
|
|
|
Copyright (c) 2011-2013 ARM Limited
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
"""
|
2016-06-24 22:15:01 +00:00
|
|
|
from argparse import ArgumentParser
|
2016-06-09 20:34:53 +00:00
|
|
|
from tools.toolchains import TOOLCHAINS
|
|
|
|
from tools.targets import TARGET_NAMES
|
2016-08-15 19:44:23 +00:00
|
|
|
from tools.utils import argparse_force_uppercase_type, \
|
2016-09-01 10:41:19 +00:00
|
|
|
argparse_lowercase_hyphen_type, argparse_many, \
|
|
|
|
argparse_filestring_type
|
2013-02-18 15:32:11 +00:00
|
|
|
|
2016-09-01 10:41:19 +00:00
|
|
|
def get_default_options_parser(add_clean=True, add_options=True,
|
|
|
|
add_app_config=False):
|
2016-08-15 19:44:23 +00:00
|
|
|
"""Create a new options parser with the default compiler options added
|
|
|
|
|
|
|
|
Keyword arguments:
|
|
|
|
add_clean - add the clean argument?
|
|
|
|
add_options - add the options argument?
|
|
|
|
"""
|
2016-06-24 22:15:01 +00:00
|
|
|
parser = ArgumentParser()
|
2014-05-29 13:42:03 +00:00
|
|
|
|
2014-10-31 12:59:26 +00:00
|
|
|
targetnames = TARGET_NAMES
|
|
|
|
targetnames.sort()
|
|
|
|
toolchainlist = list(TOOLCHAINS)
|
|
|
|
toolchainlist.sort()
|
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("-m", "--mcu",
|
2016-08-15 19:44:23 +00:00
|
|
|
help=("build for the given MCU (%s)" %
|
|
|
|
', '.join(targetnames)),
|
|
|
|
metavar="MCU",
|
|
|
|
type=argparse_many(
|
|
|
|
argparse_force_uppercase_type(
|
|
|
|
targetnames, "MCU")))
|
2014-05-29 13:42:03 +00:00
|
|
|
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("-t", "--tool",
|
2016-08-15 19:44:23 +00:00
|
|
|
help=("build using the given TOOLCHAIN (%s)" %
|
|
|
|
', '.join(toolchainlist)),
|
|
|
|
metavar="TOOLCHAIN",
|
|
|
|
type=argparse_many(
|
|
|
|
argparse_force_uppercase_type(
|
|
|
|
toolchainlist, "toolchain")))
|
2014-05-29 13:42:03 +00:00
|
|
|
|
2016-07-07 16:40:04 +00:00
|
|
|
parser.add_argument("--color",
|
|
|
|
help="print Warnings, and Errors in color",
|
|
|
|
action="store_true", default=False)
|
|
|
|
|
2016-08-15 19:44:23 +00:00
|
|
|
parser.add_argument("--cflags", default=[], action="append",
|
|
|
|
help="Extra flags to provide to the C compiler")
|
|
|
|
|
|
|
|
parser.add_argument("--asmflags", default=[], action="append",
|
|
|
|
help="Extra flags to provide to the assembler")
|
|
|
|
|
|
|
|
parser.add_argument("--ldflags", default=[], action="append",
|
|
|
|
help="Extra flags to provide to the linker")
|
|
|
|
|
2016-06-09 21:05:35 +00:00
|
|
|
if add_clean:
|
2016-06-24 22:15:01 +00:00
|
|
|
parser.add_argument("-c", "--clean", action="store_true", default=False,
|
2016-08-15 19:44:23 +00:00
|
|
|
help="clean the build directory")
|
2014-05-29 13:42:03 +00:00
|
|
|
|
2016-06-09 21:05:35 +00:00
|
|
|
if add_options:
|
2016-06-29 22:13:38 +00:00
|
|
|
parser.add_argument("-o", "--options", action="append",
|
2016-08-15 19:44:23 +00:00
|
|
|
help=('Add a build argument ("save-asm": save the '
|
|
|
|
'asm generated by the compiler, "debug-info":'
|
|
|
|
' generate debugging information, "analyze": '
|
|
|
|
'run Goanna static code analyzer")'),
|
|
|
|
type=argparse_lowercase_hyphen_type(['save-asm',
|
|
|
|
'debug-info',
|
2016-08-10 08:48:04 +00:00
|
|
|
'analyze',
|
2016-08-17 12:16:07 +00:00
|
|
|
'small-lib',
|
|
|
|
'std-lib'],
|
2016-08-15 19:44:23 +00:00
|
|
|
"build option"))
|
2014-05-29 13:42:03 +00:00
|
|
|
|
2016-09-01 10:41:19 +00:00
|
|
|
if add_app_config:
|
|
|
|
parser.add_argument("--app-config", default=None, dest="app_config",
|
|
|
|
type=argparse_filestring_type,
|
|
|
|
help="Path of an app configuration file (Default is to look for 'mbed_app.json')")
|
|
|
|
|
2013-02-18 15:32:11 +00:00
|
|
|
return parser
|