Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished Scons Debug/Release Configuration Task, added debug and release flags #350

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,31 @@ AddOption(
help="Specifies which application to flash. The bootloader, application or the entire flash bank"
)

AddOption(
'--build-type',
dest='build_type',
type='choice',
choices=('debug', 'release'),
default='debug',
help="Specifies the build type. One of 'debug' or 'release'. Defaults to 'debug'."
)

PLATFORM = GetOption('platform')
TARGET = GetOption('name')
FLASH_TYPE = GetOption('flash')

BUILD_TYPE = GetOption('build_type')
###########################################################
# Environment setup
###########################################################

# Retrieve the construction environment from the appropriate platform script
env = SConscript(f'platform/{PLATFORM}.py', exports='FLASH_TYPE')
env = SConscript(f'platform/{PLATFORM}.py', exports={'FLASH_TYPE': FLASH_TYPE, 'BUILD_TYPE': BUILD_TYPE})

VARS = {
"PLATFORM": PLATFORM,
"TARGET": TARGET,
"FLASH_TYPE": FLASH_TYPE,
"BUILD_TYPE": BUILD_TYPE,
"env": env,
}

Expand Down
58 changes: 38 additions & 20 deletions platform/arm.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
Import ('FLASH_TYPE')
Import ('FLASH_TYPE', 'BUILD_TYPE')

PLATFORM_DIR = os.getcwd()

Expand All @@ -25,27 +25,40 @@

cflags = [
'-ffreestanding',
'-Wall',
'-Wextra',
'-Werror',
'-g3',
'-Os',
'-Wno-discarded-qualifiers',
'-Wno-unused-variable',
'-Wall', # Enables all warnings
'-Wextra', # Enables extra warnings
'-Wno-discarded-qualifiers', # Disables warnings for qualifiers that are ignored
'-Wno-unused-variable', # Disables warnings for unused variables
'-Wno-unused-parameter',
'-Wsign-conversion',
'-Wpointer-arith',
'-Wundef',
'-Wundef', # Warns if an undefined identifier is evaluated in an #if directive
'-Wno-enum-conversion',
'-ffunction-sections',
'-fdata-sections',
'-flto',
'-fsingle-precision-constant',
'-fno-math-errno',
'-Wl,--gc-sections',
'-ffunction-sections', # Places each function in its own section
'-fdata-sections', # Places each data item in its own section
'-fsingle-precision-constant', # Treats floating-point constants as single precision
'-fno-math-errno', # Disables setting errno after math library functions
'-Wl,--gc-sections', # Removes unused sections
'-Wl,-Map=build/out.map',
'--specs=nosys.specs',
'--specs=nano.specs',
'-fno-common', # Treats global variables as defined symbols
]

debug_cflags = [
"-g3", # Generate extensive debugging information
"-Og", # Optimizes code for debugging
'-Werror', # Treats all warnings as errors
"-fstack-usage", # Generates stack usage information in .su files
# (commented out due to missing --lssp and --lssp_nonshared libraries)
#"-fstack-protector-strong", # Enables stack overflow protection

]
release_cflags = [
"-Os", # Optimize for size
'-flto', # Enables link-time optimization
"-DNDEBUG", # Disables assertions
"-fmerge-all-constants", # Merges identical constants
]

def get_link_flags(flash_type='default'):
Expand All @@ -60,19 +73,24 @@ def get_link_flags(flash_type='default'):
'-T{}'.format(script),
]

def create_arm_env(flash_type='default'):
def create_arm_env(flash_type='default', build_type='debug'):
combined_cflags = cflags + arch_cflags + define_flags
if build_type == 'debug':
combined_cflags += debug_cflags
else:
combined_cflags += release_cflags
return Environment(
ENV = { 'PATH': os.environ['PATH'] },

CC=compiler,
CCFLAGS=cflags + arch_cflags + define_flags,
CCFLAGS=combined_cflags,
CPPPATH=[],

AS=compiler,
ASFLAGS=['-c'] + cflags + arch_cflags + define_flags,
ASFLAGS=['-c'] + combined_cflags,

LINK=compiler,
LINKFLAGS=cflags + arch_cflags + get_link_flags(flash_type),
LINKFLAGS= combined_cflags + get_link_flags(flash_type),

AR=ar,
RANLIB=ranlib,
Expand All @@ -81,7 +99,7 @@ def create_arm_env(flash_type='default'):
)

bin_builder = Builder(action='{} -O binary $SOURCE $TARGET'.format(objcopy))
arm_env = create_arm_env(FLASH_TYPE)
arm_env = create_arm_env(FLASH_TYPE, BUILD_TYPE)
arm_env.Append(BUILDERS={'Bin': bin_builder})

Return('arm_env')