mirror of https://github.com/ArduPilot/ardupilot
waf: boards: use classes for boards definition
In order to provide board-specific behavior. For example, the incoming PX4 build will require custom build behavior.
This commit is contained in:
parent
49a4bde5d9
commit
393bea8945
|
@ -5,34 +5,38 @@ import sys
|
|||
|
||||
import waflib
|
||||
|
||||
BOARDS = {}
|
||||
_board_classes = {}
|
||||
|
||||
PROJECT_ENV = waflib.ConfigSet.ConfigSet()
|
||||
class BoardMeta(type):
|
||||
def __init__(cls, name, bases, dct):
|
||||
super(BoardMeta, cls).__init__(name, bases, dct)
|
||||
if name == 'Board':
|
||||
return
|
||||
_board_classes[name] = cls
|
||||
|
||||
def define_board(func, name, parent_name=None):
|
||||
if parent_name is None:
|
||||
parent = PROJECT_ENV
|
||||
elif parent_name not in BOARDS:
|
||||
print("Undefined parent board '%s' for '%s'" % (parent_name, name))
|
||||
sys.exit(1)
|
||||
class Board:
|
||||
def configure(self, cfg):
|
||||
env = waflib.ConfigSet.ConfigSet()
|
||||
self.configure_env(env)
|
||||
|
||||
d = env.get_merged_dict()
|
||||
# Always prepend so that arguments passed in the command line get
|
||||
# the priority.
|
||||
for k, val in d.items():
|
||||
# Dictionaries (like 'DEFINES') are converted to lists to
|
||||
# conform to waf conventions.
|
||||
if isinstance(val, dict):
|
||||
for item in val.items():
|
||||
cfg.env.prepend_value(k, '%s=%s' % item)
|
||||
else:
|
||||
parent = BOARDS[parent_name]
|
||||
cfg.env.prepend_value(k, val)
|
||||
|
||||
env = parent.derive().detach()
|
||||
if name in BOARDS:
|
||||
print("Multiple definitions of " + name)
|
||||
sys.exit(1)
|
||||
BOARDS[name] = env
|
||||
func(env)
|
||||
def configure_env(self, env):
|
||||
# Use a dictionary instead of the convetional list for definitions to
|
||||
# make easy to override them. Convert back to list before consumption.
|
||||
env.DEFINES = {}
|
||||
|
||||
def get_boards_names():
|
||||
return sorted(list(BOARDS.keys()))
|
||||
|
||||
# Use a dictionary instead of the convetional list for definitions to
|
||||
# make easy to override them. Convert back to list before consumption.
|
||||
PROJECT_ENV.DEFINES = {}
|
||||
|
||||
PROJECT_ENV.CFLAGS += [
|
||||
env.CFLAGS += [
|
||||
'-ffunction-sections',
|
||||
'-fdata-sections',
|
||||
'-fsigned-char',
|
||||
|
@ -46,9 +50,9 @@ PROJECT_ENV.CFLAGS += [
|
|||
'-Wno-missing-field-initializers',
|
||||
'-Wno-unused-parameter',
|
||||
'-Wno-redundant-decls',
|
||||
]
|
||||
]
|
||||
|
||||
PROJECT_ENV.CXXFLAGS += [
|
||||
env.CXXFLAGS += [
|
||||
'-std=gnu++11',
|
||||
|
||||
'-fdata-sections',
|
||||
|
@ -72,26 +76,35 @@ PROJECT_ENV.CXXFLAGS += [
|
|||
'-Werror=uninitialized',
|
||||
'-Werror=init-self',
|
||||
'-Wfatal-errors',
|
||||
]
|
||||
]
|
||||
|
||||
PROJECT_ENV.LINKFLAGS += [
|
||||
env.LINKFLAGS += [
|
||||
'-Wl,--gc-sections',
|
||||
]
|
||||
]
|
||||
|
||||
Board = BoardMeta('Board', Board.__bases__, dict(Board.__dict__))
|
||||
|
||||
def get_boards_names():
|
||||
return sorted(list(_board_classes.keys()))
|
||||
|
||||
def get_board(name):
|
||||
return _board_classes[name]()
|
||||
|
||||
# NOTE: Keeping all the board definitions together so we can easily
|
||||
# identify opportunities to simplify common flags. In the future might
|
||||
# be worthy to keep board definitions in files of their own.
|
||||
|
||||
def sitl(env):
|
||||
class sitl(Board):
|
||||
def configure_env(self, env):
|
||||
super(sitl, self).configure_env(env)
|
||||
|
||||
env.DEFINES.update(
|
||||
CONFIG_HAL_BOARD = 'HAL_BOARD_SITL',
|
||||
CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_NONE',
|
||||
)
|
||||
|
||||
env.CXXFLAGS += [
|
||||
'-O3',
|
||||
]
|
||||
|
||||
env.LIB += [
|
||||
'm',
|
||||
]
|
||||
|
@ -101,19 +114,17 @@ def sitl(env):
|
|||
'SITL',
|
||||
]
|
||||
|
||||
define_board(sitl, 'sitl')
|
||||
class linux(Board):
|
||||
def configure_env(self, env):
|
||||
super(linux, self).configure_env(env)
|
||||
|
||||
|
||||
def linux(env):
|
||||
env.DEFINES.update(
|
||||
CONFIG_HAL_BOARD = 'HAL_BOARD_LINUX',
|
||||
CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_NONE',
|
||||
)
|
||||
|
||||
env.CXXFLAGS += [
|
||||
'-O3',
|
||||
]
|
||||
|
||||
env.LIB += [
|
||||
'm',
|
||||
'rt',
|
||||
|
@ -123,114 +134,102 @@ def linux(env):
|
|||
'AP_HAL_Linux',
|
||||
]
|
||||
|
||||
define_board(linux, 'linux')
|
||||
class minlure(linux):
|
||||
def configure_env(self, env):
|
||||
super(minlure, self).configure_env(env)
|
||||
|
||||
|
||||
def minlure(env):
|
||||
env.DEFINES.update(
|
||||
CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_MINLURE',
|
||||
)
|
||||
|
||||
define_board(minlure, 'minlure', 'linux')
|
||||
|
||||
class erleboard(linux):
|
||||
def configure_env(self, env):
|
||||
super(erleboard, self).configure_env(env)
|
||||
|
||||
def erleboard(env):
|
||||
env.TOOLCHAIN = 'arm-linux-gnueabihf'
|
||||
|
||||
env.DEFINES.update(
|
||||
CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_ERLEBOARD',
|
||||
)
|
||||
|
||||
define_board(erleboard, 'erleboard', 'linux')
|
||||
class navio(linux):
|
||||
def configure_env(self, env):
|
||||
super(navio, self).configure_env(env)
|
||||
|
||||
|
||||
def navio(env):
|
||||
env.TOOLCHAIN = 'arm-linux-gnueabihf'
|
||||
|
||||
env.DEFINES.update(
|
||||
CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_NAVIO',
|
||||
)
|
||||
|
||||
define_board(navio, 'navio', 'linux')
|
||||
class zynq(linux):
|
||||
def configure_env(self, env):
|
||||
super(zynq, self).configure_env(env)
|
||||
|
||||
|
||||
def zynq(env):
|
||||
env.TOOLCHAIN = 'arm-xilinx-linux-gnueabi'
|
||||
|
||||
env.DEFINES.update(
|
||||
CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_ZYNQ',
|
||||
)
|
||||
|
||||
define_board(zynq, 'zynq', 'linux')
|
||||
class bbbmini(linux):
|
||||
def configure_env(self, env):
|
||||
super(bbbmini, self).configure_env(env)
|
||||
|
||||
|
||||
def bbbmini(env):
|
||||
env.TOOLCHAIN = 'arm-linux-gnueabihf'
|
||||
|
||||
env.DEFINES.update(
|
||||
CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_BBBMINI',
|
||||
)
|
||||
|
||||
define_board(bbbmini, 'bbbmini', 'linux')
|
||||
class pxf(linux):
|
||||
def configure_env(self, env):
|
||||
super(pxf, self).configure_env(env)
|
||||
|
||||
|
||||
def pxf(env):
|
||||
env.TOOLCHAIN = 'arm-linux-gnueabihf'
|
||||
|
||||
env.DEFINES.update(
|
||||
CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_PXF',
|
||||
)
|
||||
|
||||
define_board(pxf, 'pxf', 'linux')
|
||||
class bebop(linux):
|
||||
def configure_env(self, env):
|
||||
super(bebop, self).configure_env(env)
|
||||
|
||||
|
||||
def bebop(env):
|
||||
env.TOOLCHAIN = 'arm-linux-gnueabihf'
|
||||
|
||||
env.DEFINES.update(
|
||||
CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_BEBOP',
|
||||
)
|
||||
|
||||
env.STATIC_LINKING = [True]
|
||||
|
||||
define_board(bebop, 'bebop', 'linux')
|
||||
class raspilot(linux):
|
||||
def configure_env(self, env):
|
||||
super(raspilot, self).configure_env(env)
|
||||
|
||||
|
||||
def raspilot(env):
|
||||
env.TOOLCHAIN = 'arm-linux-gnueabihf'
|
||||
|
||||
env.DEFINES.update(
|
||||
CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_RASPILOT',
|
||||
)
|
||||
|
||||
define_board(raspilot, 'raspilot', 'linux')
|
||||
class erlebrain2(linux):
|
||||
def configure_env(self, env):
|
||||
super(erlebrain2, self).configure_env(env)
|
||||
|
||||
|
||||
def erlebrain2(env):
|
||||
env.TOOLCHAIN = 'arm-linux-gnueabihf'
|
||||
|
||||
env.DEFINES.update(
|
||||
CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2',
|
||||
)
|
||||
|
||||
define_board(erlebrain2, 'erlebrain2', 'linux')
|
||||
class bhat(linux):
|
||||
def configure_env(self, env):
|
||||
super(bhat, self).configure_env(env)
|
||||
|
||||
|
||||
def bhat(env):
|
||||
env.TOOLCHAIN = 'arm-linux-gnueabihf'
|
||||
|
||||
env.DEFINES.update(
|
||||
CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_BH',
|
||||
)
|
||||
|
||||
define_board(bhat, 'bhat', 'linux')
|
||||
class pxfmini(linux):
|
||||
def configure_env(self, env):
|
||||
super(pxfmini, self).configure_env(env)
|
||||
|
||||
|
||||
def pxfmini(env):
|
||||
env.TOOLCHAIN = 'arm-linux-gnueabihf'
|
||||
|
||||
env.DEFINES.update(
|
||||
CONFIG_HAL_BOARD_SUBTYPE = 'HAL_BOARD_SUBTYPE_LINUX_PXFMINI',
|
||||
)
|
||||
|
||||
define_board(pxfmini, 'pxfmini', 'linux')
|
||||
|
|
14
wscript
14
wscript
|
@ -61,19 +61,7 @@ def configure(cfg):
|
|||
|
||||
cfg.msg('Setting board to', cfg.options.board)
|
||||
cfg.env.BOARD = cfg.options.board
|
||||
board_dict = boards.BOARDS[cfg.env.BOARD].get_merged_dict()
|
||||
|
||||
# Always prepend so that arguments passed in the command line get
|
||||
# the priority.
|
||||
for k in board_dict:
|
||||
val = board_dict[k]
|
||||
# Dictionaries (like 'DEFINES') are converted to lists to
|
||||
# conform to waf conventions.
|
||||
if isinstance(val, dict):
|
||||
for item in val.items():
|
||||
cfg.env.prepend_value(k, '%s=%s' % item)
|
||||
else:
|
||||
cfg.env.prepend_value(k, val)
|
||||
boards.get_board(cfg.env.BOARD).configure(cfg)
|
||||
|
||||
cfg.load('toolchain')
|
||||
cfg.load('compiler_cxx compiler_c')
|
||||
|
|
Loading…
Reference in New Issue