waf: add --debug configuration option

That sets a variant <board>-debug.
This commit is contained in:
Gustavo Jose de Sousa 2016-05-06 18:44:12 -03:00 committed by Lucas De Marchi
parent 50330e22d4
commit ff46384258
3 changed files with 49 additions and 10 deletions

View File

@ -178,6 +178,13 @@ waf check --alltests
waf check-all waf check-all
``` ```
## Debugging ##
It's possible to pass the option `--debug` to the `configure` command. That
will set compiler flags to store debugging information in the binaries so that
you can use them with `gdb`, for example. The build directory will be set to
`build/<board>-debug/`. That option might come handy when using SITL.
## Make wrapper ## ## Make wrapper ##
There's also a make wrapper called `Makefile.waf`. You can use There's also a make wrapper called `Makefile.waf`. You can use

View File

@ -92,6 +92,12 @@ class Board:
'-Wno-c++11-narrowing' '-Wno-c++11-narrowing'
] ]
if cfg.env.DEBUG:
env.CFLAGS += [
'-g',
'-O0',
]
env.CXXFLAGS += [ env.CXXFLAGS += [
'-std=gnu++11', '-std=gnu++11',
@ -134,6 +140,12 @@ class Board:
'-Werror=unused-but-set-variable' '-Werror=unused-but-set-variable'
] ]
if cfg.env.DEBUG:
env.CXXFLAGS += [
'-g',
'-O0',
]
env.LINKFLAGS += [ env.LINKFLAGS += [
'-Wl,--gc-sections', '-Wl,--gc-sections',
] ]
@ -165,9 +177,12 @@ class sitl(Board):
CONFIG_HAL_BOARD = 'HAL_BOARD_SITL', CONFIG_HAL_BOARD = 'HAL_BOARD_SITL',
CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_NONE', CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_NONE',
) )
env.CXXFLAGS += [
'-O3', if not cfg.env.DEBUG:
] env.CXXFLAGS += [
'-O3',
]
env.LIB += [ env.LIB += [
'm', 'm',
] ]
@ -190,9 +205,12 @@ class linux(Board):
CONFIG_HAL_BOARD = 'HAL_BOARD_LINUX', CONFIG_HAL_BOARD = 'HAL_BOARD_LINUX',
CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_NONE', CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_NONE',
) )
env.CXXFLAGS += [
'-O3', if not cfg.env.DEBUG:
] env.CXXFLAGS += [
'-O3',
]
env.LIB += [ env.LIB += [
'm', 'm',
'rt', 'rt',

22
wscript
View File

@ -30,11 +30,14 @@ def init(ctx):
except: except:
return return
if 'VARIANT' not in env:
return
# define the variant build commands according to the board # define the variant build commands according to the board
for c in Context.classes: for c in Context.classes:
if not issubclass(c, Build.BuildContext): if not issubclass(c, Build.BuildContext):
continue continue
c.variant = env.BOARD c.variant = env.VARIANT
def options(opt): def options(opt):
opt.load('compiler_cxx compiler_c waf_unit_test python') opt.load('compiler_cxx compiler_c waf_unit_test python')
@ -67,13 +70,24 @@ def options(opt):
default=False, default=False,
help='Enable benchmarks') help='Enable benchmarks')
g.add_option('--debug',
action='store_true',
default=False,
help='Configure as debug variant')
def configure(cfg): def configure(cfg):
cfg.env.BOARD = cfg.options.board cfg.env.BOARD = cfg.options.board
# use a different variant for each board cfg.env.DEBUG = cfg.options.debug
cfg.setenv(cfg.env.BOARD)
cfg.env.VARIANT = cfg.env.BOARD
if cfg.env.DEBUG:
cfg.env.VARIANT += '-debug'
cfg.setenv(cfg.env.VARIANT)
cfg.env.BOARD = cfg.options.board
cfg.env.DEBUG = cfg.options.debug
cfg.msg('Setting board to', cfg.options.board) cfg.msg('Setting board to', cfg.options.board)
cfg.env.BOARD = cfg.options.board
boards.get_board(cfg.env.BOARD).configure(cfg) boards.get_board(cfg.env.BOARD).configure(cfg)
cfg.load('clang_compilation_database') cfg.load('clang_compilation_database')