Skip to content

Commit

Permalink
build: rework various dir definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
paradajz committed Dec 27, 2022
1 parent dfb71b0 commit 8454671
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 42 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ Documentation/*
*Objects.mk
*.cortex-debug*
**/tests/test_run/*
**/board/gen/*
**/generated/*
*.profraw
**/cubemx/**/*
!**/cubemx/**/*.ioc
src/application/gen/*
**/*.ico
**/.clangd/*
**/clangd/*
Expand Down
9 changes: 7 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ $(BUILD_DIR)/%.S.o: %.S
format:
@echo Checking code formatting...
@$(FIND) . -regex '.*\.\(cpp\|hpp\|h\|cc\|cxx\|c\)' \
-not -path "**/deps/**/*" \
-not -path "**/$(DEPS_SUBDIR_BASE)/**/*" \
-not -path "**/$(GENERATED_SUBDIR_BASE)/**/*" \
-exec $(CLANG_FORMAT) -style=file -i {} +
ifeq ($(CF_FAIL_ON_DIFF), 1)
git diff
Expand All @@ -191,7 +192,11 @@ endif

clean:
@echo Cleaning up.
@rm -rf $(BUILD_DIR_BASE) $(BOARD_GEN_DIR_BASE) $(APP_GEN_DIR) compile_commands.json
@rm -rf \
$(BUILD_DIR_BASE) \
$(BOARD_GEN_DIR_BASE) \
$(APPLICATION_GEN_DIR_BASE) \
compile_commands.json

# Debugging
print-%:
Expand Down
49 changes: 26 additions & 23 deletions src/Setup.mk
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
PROJECT := OpenDeck
BUILD_DIR_BASE := ./build
TARGET := discovery
DEF_FILE_TARGET := ../config/target/$(TARGET).yml
DEF_FILE_TSCREEN := ../config/touchscreen/$(TARGET).json
TYPE := application
SCRIPTS_DIR := ../scripts
DEPS_DIR := deps
CLANG_TIDY_OUT := $(BUILD_DIR_BASE)/clang-tidy-fixes.yaml
ROOT_MAKEFILE_DIR := $(realpath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
PROJECT := $(shell basename $(shell dirname $(ROOT_MAKEFILE_DIR)))
BUILD_DIR_BASE := $(ROOT_MAKEFILE_DIR)/build
CONFIG_DIR_BASE := $(ROOT_MAKEFILE_DIR)/../config
TARGET_CONFIG_DIR_BASE := $(CONFIG_DIR_BASE)/target
TSCREEN_CONFIG_DIR_BASE := $(CONFIG_DIR_BASE)/touchscreen
TARGET := $(shell basename $(shell $(FIND) $(TARGET_CONFIG_DIR_BASE) -type f | sort | head -n 1) .yml)
DEF_FILE_TARGET := $(TARGET_CONFIG_DIR_BASE)/$(TARGET).yml
DEF_FILE_TSCREEN := $(TSCREEN_CONFIG_DIR_BASE)/$(TARGET).json
SCRIPTS_DIR := $(ROOT_MAKEFILE_DIR)/../scripts
DEPS_SUBDIR_BASE := deps
GENERATED_SUBDIR_BASE := generated
DEPS_DIR := $(ROOT_MAKEFILE_DIR)/$(DEPS_SUBDIR_BASE)
BOARD_GEN_DIR_BASE := $(ROOT_MAKEFILE_DIR)/board/$(GENERATED_SUBDIR_BASE)
BOARD_GEN_DIR_TARGET_BASE := $(BOARD_GEN_DIR_BASE)/target
BOARD_GEN_DIR_TARGET := $(BOARD_GEN_DIR_TARGET_BASE)/$(TARGET)
BOARD_GEN_DIR_MCU_BASE := $(BOARD_GEN_DIR_BASE)/mcu
BOARD_GEN_DIR_MCU = $(BOARD_GEN_DIR_MCU_BASE)/$(CORE_MCU_MODEL)
APPLICATION_GEN_DIR_BASE := $(ROOT_MAKEFILE_DIR)/application/$(GENERATED_SUBDIR_BASE)
APPLICATION_GEN_DIR_TARGET := $(APPLICATION_GEN_DIR_BASE)/$(TARGET)
CLANG_TIDY_OUT := $(BUILD_DIR_BASE)/clang-tidy-fixes.yaml

ifeq (,$(wildcard $(DEF_FILE_TARGET)))
$(error Target doesn't exist)
Expand All @@ -19,27 +31,18 @@ else
endif

BUILD_DIR := $(BUILD_DIR_BASE)/$(TARGET)/$(BUILD_TYPE)
TYPE := application

ifneq (,$(filter $(MAKECMDGOALS),concat))
BUILD_DIR := $(BUILD_DIR)/merged
else
BUILD_DIR := $(BUILD_DIR)/$(TYPE)
endif

OUTPUT := $(BUILD_DIR)/$(TARGET)
BUILD_TIME_FILE := $(BUILD_DIR_BASE)/lastbuild
LAST_BUILD_TIME := $(shell cat $(BUILD_TIME_FILE) 2>/dev/null | awk '{print$$1}END{if(NR==0)print 0}')
FLASH_BINARY_DIR := $(BUILD_DIR_BASE)/$(TARGET)/$(BUILD_TYPE)/merged
SYSEX_BINARY_SUFFIX := _sysex

BOARD_GEN_DIR_BASE := board/gen
BOARD_GEN_DIR_TARGET_BASE := $(BOARD_GEN_DIR_BASE)/target
BOARD_GEN_DIR_MCU_BASE := $(BOARD_GEN_DIR_BASE)/mcu
BOARD_GEN_DIR_VENDOR_BASE := $(BOARD_GEN_DIR_BASE)/vendor
BOARD_GEN_DIR_ARCH_BASE := $(BOARD_GEN_DIR_BASE)/arch
BOARD_GEN_DIR_TARGET := $(BOARD_GEN_DIR_TARGET_BASE)/$(TARGET)
APP_GEN_DIR_BASE := application/gen
APP_GEN_DIR_TARGET := $(APP_GEN_DIR_BASE)/$(TARGET)
OUTPUT := $(BUILD_DIR)/$(TARGET)
BUILD_TIME_FILE := $(BUILD_DIR_BASE)/lastbuild
LAST_BUILD_TIME := $(shell cat $(BUILD_TIME_FILE) 2>/dev/null | awk '{print$$1}END{if(NR==0)print 0}')
FLASH_BINARY_DIR := $(BUILD_DIR_BASE)/$(TARGET)/$(BUILD_TYPE)/merged

# Verbose builds
ifeq ($(V),1)
Expand Down
6 changes: 4 additions & 2 deletions src/Sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ vpath modules/%.S ../
# Common include dirs
INCLUDE_DIRS += \
-I"./" \
-I"$(BOARD_GEN_DIR_MCU_BASE)/$(CORE_MCU_MODEL)" \
-I"$(BOARD_GEN_DIR_MCU)" \
-I"$(BOARD_GEN_DIR_TARGET)/" \
-I"board/arch/$(CORE_MCU_ARCH)/$(CORE_MCU_VENDOR)/common" \
-I"board/arch/$(CORE_MCU_ARCH)/$(CORE_MCU_VENDOR)/variants/$(CORE_MCU_FAMILY)/common" \
Expand All @@ -26,9 +26,11 @@ LINKER_FILE := ../modules/core/src/arch/$(CORE_MCU_ARCH)/$(CORE_MCU_VENDOR
TARGET_GEN_HEADER := $(BOARD_GEN_DIR_TARGET)/Target.h

ifneq (,$(wildcard $(DEF_FILE_TSCREEN)))
TSCREEN_GEN_SOURCE += $(APP_GEN_DIR_TARGET)/Touchscreen.cpp
TSCREEN_GEN_SOURCE := $(APPLICATION_GEN_DIR_TARGET)/Touchscreen.cpp
endif

SYSEX_BINARY_SUFFIX := _sysex

GEN_FILES += \
$(TARGET_GEN_HEADER) \
$(TSCREEN_GEN_SOURCE)
Expand Down
4 changes: 2 additions & 2 deletions src/application/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ ifneq (,$(findstring HW_USB_OVER_SERIAL_HOST,$(DEFINES)))
# FW for USB hosts uses different set of sources than other targets
SOURCES += $(shell find usb-link -type f -name "*.cpp")
else
SOURCES += $(shell $(FIND) application -type f -not -path "*$(APP_GEN_DIR_BASE)*" -regex '.*\.\(s\|c\|cpp\)')
SOURCES += $(shell $(FIND) $(APP_GEN_DIR_TARGET) -type f -regex '.*\.\(s\|c\|cpp\)')
SOURCES += $(shell $(FIND) application -type f -not -path "*$(GENERATED_SUBDIR_BASE)*" -regex '.*\.\(s\|c\|cpp\)')
SOURCES += $(shell $(FIND) $(APPLICATION_GEN_DIR_TARGET) -type f -regex '.*\.\(s\|c\|cpp\)')
SOURCES += $(shell $(FIND) ../modules/dbms/src -maxdepth 1 -type f -name "*.cpp" | sed "s|^\.\./||")
SOURCES += $(shell $(FIND) ../modules/midi/src -type f -name "*.cpp" | sed "s|^\.\./||")
SOURCES += $(shell $(FIND) ../modules/sysex/src -maxdepth 1 -type f -name "*.cpp" | sed "s|^\.\./||")
Expand Down
6 changes: 3 additions & 3 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
# Important - do not change the order of inclusion!

include ../src/Toolchain.mk
include Setup.mk
include ../src/Setup.mk
-include ../src/$(BOARD_GEN_DIR_TARGET)/Makefile
-include $(BOARD_GEN_DIR_TARGET)/Makefile
-include ../src/board/arch/$(CORE_MCU_ARCH)/Makefile
-include ../src/board/arch/$(CORE_MCU_ARCH)/$(CORE_MCU_VENDOR)/Makefile
-include ../src/board/arch/$(CORE_MCU_ARCH)/$(CORE_MCU_VENDOR)/variants/$(CORE_MCU_FAMILY)/Makefile
-include ../src/board/arch/$(CORE_MCU_ARCH)/$(CORE_MCU_VENDOR)/variants/$(CORE_MCU_FAMILY)/$(CORE_MCU_MODEL)/Makefile
-include ../src/$(TYPE)/Makefile
include ../src/Defines.mk
-include $(MAKEFILE_INCLUDE_PREFIX)$(BOARD_GEN_DIR_TARGET)/HWTestDefines.mk
include Setup.mk
-include $(BOARD_GEN_DIR_TARGET)/HWTestDefines.mk
include Defines.mk
include Sources.mk
-include Objects.mk
Expand Down
12 changes: 6 additions & 6 deletions tests/Setup.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
TEST_BINARIES := $(addprefix -object ,$(shell $(FIND) $(BUILD_DIR_BASE) -name "*.out" 2>/dev/null))
FW_ROOT_DIR := ../src
SCRIPTS_DIR := ../scripts

# Override root path for includes in Makefiles located in src directory
MAKEFILE_INCLUDE_PREFIX := ../src/
ROOT_MAKEFILE_DIR := $(realpath $(dir $(realpath $(lastword $(MAKEFILE_LIST)))))
BUILD_DIR_BASE := $(ROOT_MAKEFILE_DIR)/build
BUILD_DIR := $(BUILD_DIR_BASE)/$(TARGET)
SCRIPTS_DIR := $(ROOT_MAKEFILE_DIR)/../scripts
FW_ROOT_DIR := $(ROOT_MAKEFILE_DIR)/../src
TEST_BINARIES := $(addprefix -object ,$(shell $(FIND) $(BUILD_DIR_BASE) -name "*.out" 2>/dev/null))
4 changes: 2 additions & 2 deletions tests/Sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ INCLUDE_DIRS_COMMON := \
-I"../src/application/" \
-I"../src/board/common" \
-I"../src/board/arch/$(CORE_MCU_ARCH)/$(CORE_MCU_VENDOR)/variants/$(CORE_MCU_FAMILY)" \
-I"../src/$(BOARD_GEN_DIR_MCU_BASE)/$(CORE_MCU_MODEL)" \
-I"../src/$(BOARD_GEN_DIR_TARGET)/"
-I"$(BOARD_GEN_DIR_MCU)" \
-I"$(BOARD_GEN_DIR_TARGET)"

0 comments on commit 8454671

Please sign in to comment.