Skip to content

Commit

Permalink
[build] Map all file prefixes to relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
salkinium committed Feb 15, 2021
1 parent deb250f commit 2d5c6c2
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) 2018, Sergiy Yevtushenko
# Copyright (c) 2018-2019, Niklas Hauser
# Copyright (c) 2018-2019, 2021, Niklas Hauser
#
# This file is part of the modm project.
#
Expand All @@ -13,7 +13,9 @@ endif()

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
%% if platform == "hosted"
find_package(PkgConfig)
%% endif

if(NOT TOOL_EXECUTABLE_PREFIX)
%% if core.startswith("cortex-m")
Expand Down Expand Up @@ -44,11 +46,11 @@ set(CMAKE_C_COMPILER "${TOOL_EXECUTABLE_PREFIX}gcc${TOOL_EXECUTABLE_SUFFIX}" CAC
set(CMAKE_CXX_COMPILER "${TOOL_EXECUTABLE_PREFIX}g++${TOOL_EXECUTABLE_SUFFIX}" CACHE INTERNAL "c++")
set(CMAKE_ASM_COMPILER "${CMAKE_C_COMPILER}" CACHE INTERNAL "asm")

set(CMAKE_AR "${TOOL_EXECUTABLE_PREFIX}ar" CACHE INTERNAL "ar")
set(CMAKE_RANLIB "${TOOL_EXECUTABLE_PREFIX}ranlib" CACHE INTERNAL "ranlib")
if(TOOL_EXECUTABLE_SUFFIX STREQUAL "")
set(CMAKE_AS "${TOOL_EXECUTABLE_PREFIX}as" CACHE INTERNAL "as")
set(CMAKE_NM "${TOOL_EXECUTABLE_PREFIX}nm" CACHE INTERNAL "nm")
set(CMAKE_AR "${TOOL_EXECUTABLE_PREFIX}ar" CACHE INTERNAL "ar")
set(CMAKE_RANLIB "${TOOL_EXECUTABLE_PREFIX}ranlib" CACHE INTERNAL "ranlib")
else()
set(CMAKE_AS "${CMAKE_CXX_COMPILER}" CACHE INTERNAL "as")
set(CMAKE_NM "${TOOL_EXECUTABLE_PREFIX}gcc-nm${TOOL_EXECUTABLE_SUFFIX}" CACHE INTERNAL "nm")
Expand All @@ -71,6 +73,12 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

# Used to make stdlibc++ paths in ELF relative to compiler
find_program(MODM_GCC_PATH NAMES ${CMAKE_C_COMPILER})
get_filename_component(MODM_GCC_PATH ${MODM_GCC_PATH} REALPATH)
get_filename_component(MODM_GCC_PATH ${MODM_GCC_PATH} DIRECTORY)
get_filename_component(MODM_GCC_PATH ${MODM_GCC_PATH} DIRECTORY)

if(APPLE)
%% if platform == "hosted"
# Using homebrew include and lib paths on macOS
Expand Down
1 change: 1 addition & 0 deletions tools/build_script_generator/cmake/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def build(env):
subs = {
"target_base": "${CMAKE_PROJECT_NAME}",
"project_source_dir": "${CMAKE_CURRENT_SOURCE_DIR}",
"gccpath": "${MODM_GCC_PATH}",
}
if "{" in flag:
return flag.format(**subs)
Expand Down
3 changes: 2 additions & 1 deletion tools/build_script_generator/cmake/resources/Makefile.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Copyright (c) 2018, Sergiy Yevtushenko
# Copyright (c) 2018-2019, Niklas Hauser
# Copyright (c) 2018-2019, 2021, Niklas Hauser
#
# This file is part of the modm project.
#
Expand Down Expand Up @@ -59,6 +59,7 @@ program-bmp: build
ui?=tui
debug: build
@python3 modm/modm_tools/gdb.py -x modm/gdbinit -x modm/openocd_gdbinit \
-ex "dir $(dir $(realpath $(dir $(realpath $(shell which arm-none-eabi-gcc)))))" \
$(ELF_FILE) -ui=$(ui) \
openocd -f modm/openocd.cfg

Expand Down
2 changes: 2 additions & 0 deletions tools/build_script_generator/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ def common_compiler_flags(compiler, target):
"-funsigned-char",
"-fwrapv",
# "-fmerge-all-constants",
"-ffile-prefix-map={project_source_dir}=.",
"-ffile-prefix-map={gccpath}=.",

"-g3",
"-gdwarf-3",
Expand Down
5 changes: 3 additions & 2 deletions tools/build_script_generator/scons/module.lb
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ def build(env):

def flag_format(flag):
subs = {
"target_base": "\"${TARGET.base}\"",
"project_source_dir": "abspath(\"..\")",
"target_base": '"${TARGET.base}"',
"project_source_dir": 'env["BASEPATH"]',
"gccpath": 'env["GCC_PATH"]'
}
flag = '"{}"'.format(flag)
vals = ["{}={}".format(t, r) for t, r in subs.items() if "{{{}}}".format(t) in flag]
Expand Down
5 changes: 4 additions & 1 deletion tools/build_script_generator/scons/resources/SConscript.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

#!/usr/bin/env python3

from os.path import join, abspath
from os.path import join, abspath, realpath, dirname
import shutil
Import("env")

profile = ARGUMENTS.get("profile", "release")
Expand Down Expand Up @@ -36,6 +37,7 @@ env.Append(toolpath=[
%% for tool in tools | sort
env.Tool("{{tool}}")
%% endfor
env["GCC_PATH"] = dirname(dirname(realpath(shutil.which(env["CC"]))))

%% macro generate_flags_for_profile(name, profile, append=False)
env{% if append %}.Append({{name | upper}}{% else %}["{{name | upper}}"]{% endif %} = [
Expand Down Expand Up @@ -121,6 +123,7 @@ env["CONFIG_AVRDUDE_BAUDRATE"] = "{{ avrdude_baudrate }}"
env.Append(MODM_OPENOCD_CONFIGFILES = "$BASEPATH/modm/openocd.cfg")
env.Append(MODM_OPENOCD_GDBINIT = "$BASEPATH/modm/openocd_gdbinit")
env.Append(MODM_GDBINIT = "$BASEPATH/modm/gdbinit")
env.Append(MODM_GDB_COMMANDS = "dir $GCC_PATH")
%% if platform == "sam"
%% if bossac_offset
env.Append(MODM_BOSSAC_OFFSET = {{ bossac_offset }})
Expand Down
5 changes: 3 additions & 2 deletions tools/build_script_generator/scons/site_tools/bmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ def call_bmp_program(target, source, env):
def black_magic_probe_debug(env, source, alias='black_magic_probe_debug'):
def call_bmp_debug(target, source, env):
backend = bmp.BlackMagicProbeBackend(port=ARGUMENTS.get("port", "auto"))
gdb.call(source=source[0].abspath, backend=backend,
ui=ARGUMENTS.get("ui", "tui"))
gdb.call(source=source[0].abspath, backend=backend, ui=ARGUMENTS.get("ui", "tui"),
config=map(env.subst, env.Listify(env.get("MODM_GDBINIT", []))),
commands=map(env.subst, env.Listify(env.get("MODM_GDB_COMMANDS", []))))

action = Action(call_bmp_debug, cmdstr="$BMP_DEBUG_COMSTR")
return env.AlwaysBuild(env.Alias(alias, source, action))
Expand Down
3 changes: 2 additions & 1 deletion tools/build_script_generator/scons/site_tools/crashdebug.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def run_post_mortem_gdb(target, source, env):
binary_path=env.subst("$BASEPATH/modm/ext/crashcatcher/bins"),
coredump=coredump_txt)
gdb.call(source=source, backend=backend, ui=ARGUMENTS.get("ui", "tui"),
config=map(env.subst, env.Listify(env.get("MODM_GDBINIT", []))))
config=map(env.subst, env.Listify(env.get("MODM_GDBINIT", []))),
commands=map(env.subst, env.Listify(env.get("MODM_GDB_COMMANDS", []))))

return 0

Expand Down
9 changes: 5 additions & 4 deletions tools/build_script_generator/scons/site_tools/openocd.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ def debug_openocd(env, source, alias="debug_openocd"):
def call_debug_openocd(target, source, env):
config_openocd = env.Listify(env.get("MODM_OPENOCD_CONFIGFILES", []))
config_searchdirs = env.Listify(env.get("MODM_OPENOCD_SEARCHDIRS", []))
config = env.Listify(env.get("MODM_OPENOCD_GDBINIT", []))
config += env.Listify(env.get("MODM_GDBINIT", []))
backend = OpenOcdBackend(config=map(env.subst, config_openocd),
search=map(env.subst, config_searchdirs))
gdb.call(source=source[0], backend=backend,
config=map(env.subst, config), ui=ARGUMENTS.get("ui", "tui"))
config = env.Listify(env.get("MODM_OPENOCD_GDBINIT", []))
config += env.Listify(env.get("MODM_GDBINIT", []))
commands = env.Listify(env.get("MODM_GDB_COMMANDS", []))
gdb.call(source=source[0], backend=backend, config=map(env.subst, config),
commands=map(env.subst, commands), ui=ARGUMENTS.get("ui", "tui"))

action = Action(call_debug_openocd, cmdstr="$DEBUG_OPENOCD_COMSTR")
return env.AlwaysBuild(env.Alias(alias, source, action))
Expand Down

0 comments on commit 2d5c6c2

Please sign in to comment.