Skip to content

Commit

Permalink
build: move arch/vendor/mcu specific makefiles into their own dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
paradajz committed Jan 29, 2022
1 parent 2a22640 commit dbe06d0
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 95 deletions.
2 changes: 1 addition & 1 deletion scripts/gen_target.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ GEN_DIR=$2
YAML_PARSER="dasel -n -p yaml --plain -f"
TARGET_NAME=$(basename "$YAML_FILE" .yml)
OUT_HEADER="$GEN_DIR"/Target.h
OUT_MAKEFILE="$GEN_DIR"/Defines.mk
OUT_MAKEFILE="$GEN_DIR"/Makefile

#generated header contains cpp code
#generate USB names in dedicated header since this one is included in .c files
Expand Down
52 changes: 23 additions & 29 deletions src/Defines.mk
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
SW_VERSION_MAJOR := $(shell git describe --tags --abbrev=0 | cut -c 2- | cut -d. -f1)
SW_VERSION_MINOR := $(shell git describe --tags --abbrev=0 | cut -c 2- | cut -d. -f2)
SW_VERSION_REVISION := $(shell git describe --tags --abbrev=0 | cut -c 2- | cut -d. -f3)

GEN_DIR_BASE := board/gen
GEN_DIR_TARGET_BASE := $(GEN_DIR_BASE)/target
GEN_DIR_MCU_BASE := $(GEN_DIR_BASE)/mcu
GEN_DIR_VENDOR_BASE := $(GEN_DIR_BASE)/vendor
GEN_DIR_ARCH_BASE := $(GEN_DIR_BASE)/arch
GEN_DIR_TARGET := $(GEN_DIR_TARGET_BASE)/$(TARGET)
GEN_DIR_TSCREEN_BASE := application/io/touchscreen/gen

-include $(MAKEFILE_INCLUDE_PREFIX)$(GEN_DIR_TARGET)/Makefile

#these makefiles are specific only to firmware, which is why they don't have MAKEFILE_INCLUDE_PREFIX
#the prefix is used to specify the directory of main, target makefile
#needed for tests since they are outside of src/
-include board/arch/$(ARCH)/$(VENDOR)/Makefile
-include board/arch/$(ARCH)/$(VENDOR)/variants/$(MCU_FAMILY)/$(MCU)/Makefile
-include board/arch/$(ARCH)/Makefile

COMMAND_FW_UPDATE_START := 0x4F70456E6E45704F
COMMAND_FW_UPDATE_END := 0x4465436B
SYSEX_MANUFACTURER_ID_0 := 0x00
Expand All @@ -14,13 +28,14 @@ FW_METADATA_SIZE := 4
UART_BAUDRATE_MIDI_STD := 31250
UART_BAUDRATE_USB := 38400
UART_BAUDRATE_TOUCHSCREEN := 38400
USB_OVER_SERIAL_BUFFER_SIZE := 16
I2C_TX_BUFFER_SIZE := 64
ESTA_ID := 0x6555

SW_VERSION_MAJOR := $(shell git describe --tags --abbrev=0 | cut -c 2- | cut -d. -f1)
SW_VERSION_MINOR := $(shell git describe --tags --abbrev=0 | cut -c 2- | cut -d. -f2)
SW_VERSION_REVISION := $(shell git describe --tags --abbrev=0 | cut -c 2- | cut -d. -f3)
#these can be overriden by target/vendor/arch/mcu etc.
USB_OVER_SERIAL_BUFFER_SIZE ?= 16
I2C_TX_BUFFER_SIZE ?= 64
UART_TX_BUFFER_SIZE ?= 128
UART_RX_BUFFER_SIZE ?= 128
MIDI_SYSEX_ARRAY_SIZE ?= 100

DEFINES += \
UART_BAUDRATE_MIDI_STD=$(UART_BAUDRATE_MIDI_STD) \
Expand All @@ -29,6 +44,7 @@ UART_BAUDRATE_TOUCHSCREEN=$(UART_BAUDRATE_TOUCHSCREEN) \
USB_OVER_SERIAL_BUFFER_SIZE=$(USB_OVER_SERIAL_BUFFER_SIZE) \
TSCREEN_CDC_PASSTHROUGH_BUFFER_SIZE=$(USB_OVER_SERIAL_BUFFER_SIZE) \
I2C_TX_BUFFER_SIZE=$(I2C_TX_BUFFER_SIZE) \
MIDI_SYSEX_ARRAY_SIZE=$(MIDI_SYSEX_ARRAY_SIZE) \
FIXED_NUM_CONFIGURATIONS=1 \
SYSEX_MANUFACTURER_ID_0=$(SYSEX_MANUFACTURER_ID_0) \
SYSEX_MANUFACTURER_ID_1=$(SYSEX_MANUFACTURER_ID_1) \
Expand All @@ -44,30 +60,8 @@ ifeq ($(DEBUG), 1)
DEFINES += DEBUG
endif

-include $(MAKEFILE_INCLUDE_PREFIX)$(GEN_DIR_TARGET)/Defines.mk

ifneq (,$(findstring USB_LINK_MCU,$(DEFINES)))
ifeq ($(MCU), atmega16u2)
ifeq ($(TYPE),boot)
#save flash - this feature doesn't fit into 4k
DEFINES := $(filter-out LED_INDICATORS_CTL,$(DEFINES))
DEFINES += UART_TX_BUFFER_SIZE=32
DEFINES += UART_RX_BUFFER_SIZE=32
else ifeq ($(TYPE),app)
DEFINES += UART_TX_BUFFER_SIZE=64
DEFINES += UART_RX_BUFFER_SIZE=64
endif
endif
else
DEFINES += UART_TX_BUFFER_SIZE=128
DEFINES += UART_RX_BUFFER_SIZE=128
DEFINES += MIDI_SYSEX_ARRAY_SIZE=100
endif

ifeq ($(CPU),cortex-m4)
DEFINES += \
CORE_ARM_M4
endif
DEFINES += UART_TX_BUFFER_SIZE=$(UART_TX_BUFFER_SIZE)
DEFINES += UART_RX_BUFFER_SIZE=$(UART_RX_BUFFER_SIZE)

ifeq ($(TYPE),boot)
DEFINES += FW_BOOT
Expand Down
67 changes: 2 additions & 65 deletions src/Sources.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,17 @@ vpath modules/%.cpp ../
vpath modules/%.c ../

#common include dirs
INCLUDE_DIRS := \
INCLUDE_DIRS += \
-I"../modules/" \
-I"$(GEN_DIR_MCU_BASE)/$(MCU)" \
-I"$(GEN_DIR_TARGET)/" \
-I"application/" \
-I"bootloader/" \
-I"board/arch/$(ARCH)/$(VENDOR)/variants/$(MCU_FAMILY)" \
-I"board/arch/$(ARCH)/$(VENDOR)" \
-I"board/common" \
-I"./"

ifeq (,$(findstring gen,$(TYPE)))
ifeq ($(VENDOR), atmel)
INCLUDE_DIRS += \
-I"../modules/lufa/" \
-I"../modules/avr-libstdcpp/include"
else ifeq ($(VENDOR),st)
INCLUDE_DIRS += \
$(addprefix -I,$(shell $(FIND) ./board/arch/$(ARCH)/$(VENDOR)/gen/common -type d -not -path "*Src*")) \
$(addprefix -I,$(shell $(FIND) ./board/arch/$(ARCH)/$(VENDOR)/gen/$(MCU_FAMILY)/common -type d -not -path "*Src*")) \
$(addprefix -I,$(shell $(FIND) ./board/arch/$(ARCH)/$(VENDOR)/gen/$(MCU_FAMILY)/$(MCU_BASE)/Drivers -type d -not -path "*Src*"))
endif

ifeq ($(TYPE),boot)
INCLUDE_DIRS += \
-I"bootloader/"
endif
endif

LINKER_FILE := $(MCU_DIR)/$(MCU).ld
TARGET_GEN_HEADER := $(GEN_DIR_TARGET)/Target.h

Expand All @@ -40,52 +23,6 @@ endif
ifeq (,$(findstring gen,$(TYPE)))
SOURCES += $(TSCREEN_GEN_SOURCE)

#arch specific
ifeq ($(ARCH),avr)
ifneq (,$(findstring USB_SUPPORTED,$(DEFINES)))
#common for bootloader and application
SOURCES += \
modules/lufa/LUFA/Drivers/USB/Core/AVR8/Device_AVR8.c \
modules/lufa/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.c \
modules/lufa/LUFA/Drivers/USB/Core/AVR8/Endpoint_AVR8.c \
modules/lufa/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.c \
modules/lufa/LUFA/Drivers/USB/Core/AVR8/Pipe_AVR8.c \
modules/lufa/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.c \
modules/lufa/LUFA/Drivers/USB/Core/AVR8/USBInterrupt_AVR8.c \
modules/lufa/LUFA/Drivers/USB/Core/ConfigDescriptors.c \
modules/lufa/LUFA/Drivers/USB/Core/DeviceStandardReq.c \
modules/lufa/LUFA/Drivers/USB/Core/Events.c \
modules/lufa/LUFA/Drivers/USB/Core/USBTask.c \
modules/lufa/LUFA/Drivers/USB/Class/Device/AudioClassDevice.c \
modules/lufa/LUFA/Drivers/USB/Class/Device/MIDIClassDevice.c \
modules/lufa/LUFA/Drivers/USB/Class/Device/CDCClassDevice.c
endif
else ifeq ($(ARCH),arm)
SOURCES += modules/EmuEEPROM/src/EmuEEPROM.cpp

#clang-specific defines
ifneq (,$(findstring clang,$(CC_ARM)))
TOOLCHAIN_DIR := $(shell dirname $(shell which arm-none-eabi-gcc) | rev | cut -c5- | rev)
CPP_VER := $(shell $(FIND) $(TOOLCHAIN_DIR)/arm-none-eabi/include/c++ -mindepth 1 -maxdepth 1 | rev | cut -d/ -f 1 | rev)

INCLUDE_DIRS += \
-isystem"$(TOOLCHAIN_DIR)/lib/gcc/arm-none-eabi/$(CPP_VER)/include" \
-isystem"$(TOOLCHAIN_DIR)/lib/gcc/arm-none-eabi/$(CPP_VER)/include-fixed" \
-isystem"$(TOOLCHAIN_DIR)/arm-none-eabi/include/c++/$(CPP_VER)" \
-isystem"$(TOOLCHAIN_DIR)/arm-none-eabi/include/c++/$(CPP_VER)/arm-none-eabi" \
-isystem"$(TOOLCHAIN_DIR)/arm-none-eabi/include/c++/$(CPP_VER)/backward" \
-isystem"$(TOOLCHAIN_DIR)/arm-none-eabi/include"
endif
endif

#vendor specific
ifeq ($(VENDOR),st)
SOURCES += $(shell $(FIND) ./board/arch/$(ARCH)/$(VENDOR)/gen/common -regex '.*\.\(s\|c\)')
SOURCES += $(shell $(FIND) ./board/arch/$(ARCH)/$(VENDOR)/gen/$(MCU_FAMILY)/common -regex '.*\.\(s\|c\)')
SOURCES += $(shell $(FIND) ./board/arch/$(ARCH)/$(VENDOR)/gen/$(MCU_FAMILY)/$(MCU_BASE) -regex '.*\.\(s\|c\)')
SOURCES += $(shell $(FIND) ./board/arch/$(ARCH)/$(VENDOR)/variants/$(MCU_FAMILY) -maxdepth 1 -name "*.cpp")
endif

SOURCES += $(shell $(FIND) ./board/common -maxdepth 1 -type f -name "*.cpp")
SOURCES += $(shell $(FIND) ./board/arch/$(ARCH)/common/ -type f -name "*.cpp")
SOURCES += $(shell $(FIND) ./board/arch/$(ARCH)/$(VENDOR)/common/ -type f -name "*.cpp")
Expand Down
22 changes: 22 additions & 0 deletions src/board/arch/arm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ifeq (,$(findstring gen,$(TYPE)))
SOURCES += modules/EmuEEPROM/src/EmuEEPROM.cpp

#clang-specific defines
ifneq (,$(findstring clang,$(CC_ARM)))
TOOLCHAIN_DIR := $(shell dirname $(shell which arm-none-eabi-gcc) | rev | cut -c5- | rev)
CPP_VER := $(shell $(FIND) $(TOOLCHAIN_DIR)/arm-none-eabi/include/c++ -mindepth 1 -maxdepth 1 | rev | cut -d/ -f 1 | rev)

INCLUDE_DIRS += \
-isystem"$(TOOLCHAIN_DIR)/lib/gcc/arm-none-eabi/$(CPP_VER)/include" \
-isystem"$(TOOLCHAIN_DIR)/lib/gcc/arm-none-eabi/$(CPP_VER)/include-fixed" \
-isystem"$(TOOLCHAIN_DIR)/arm-none-eabi/include/c++/$(CPP_VER)" \
-isystem"$(TOOLCHAIN_DIR)/arm-none-eabi/include/c++/$(CPP_VER)/arm-none-eabi" \
-isystem"$(TOOLCHAIN_DIR)/arm-none-eabi/include/c++/$(CPP_VER)/backward" \
-isystem"$(TOOLCHAIN_DIR)/arm-none-eabi/include"
endif
endif

ifeq ($(CPU),cortex-m4)
DEFINES += \
CORE_ARM_M4
endif
11 changes: 11 additions & 0 deletions src/board/arch/arm/st/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ifeq (,$(findstring gen,$(TYPE)))
INCLUDE_DIRS += \
$(addprefix -I,$(shell $(FIND) ./board/arch/$(ARCH)/$(VENDOR)/gen/common -type d -not -path "*Src*")) \
$(addprefix -I,$(shell $(FIND) ./board/arch/$(ARCH)/$(VENDOR)/gen/$(MCU_FAMILY)/common -type d -not -path "*Src*")) \
$(addprefix -I,$(shell $(FIND) ./board/arch/$(ARCH)/$(VENDOR)/gen/$(MCU_FAMILY)/$(MCU_BASE)/Drivers -type d -not -path "*Src*"))

SOURCES += $(shell $(FIND) ./board/arch/$(ARCH)/$(VENDOR)/gen/common -regex '.*\.\(s\|c\)')
SOURCES += $(shell $(FIND) ./board/arch/$(ARCH)/$(VENDOR)/gen/$(MCU_FAMILY)/common -regex '.*\.\(s\|c\)')
SOURCES += $(shell $(FIND) ./board/arch/$(ARCH)/$(VENDOR)/gen/$(MCU_FAMILY)/$(MCU_BASE) -regex '.*\.\(s\|c\)')
SOURCES += $(shell $(FIND) ./board/arch/$(ARCH)/$(VENDOR)/variants/$(MCU_FAMILY) -maxdepth 1 -name "*.cpp")
endif
24 changes: 24 additions & 0 deletions src/board/arch/avr/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ifeq (,$(findstring gen,$(TYPE)))
INCLUDE_DIRS += \
-I"../modules/lufa/" \
-I"../modules/avr-libstdcpp/include"

ifneq (,$(findstring USB_SUPPORTED,$(DEFINES)))
#common for bootloader and application
SOURCES += \
modules/lufa/LUFA/Drivers/USB/Core/AVR8/Device_AVR8.c \
modules/lufa/LUFA/Drivers/USB/Core/AVR8/EndpointStream_AVR8.c \
modules/lufa/LUFA/Drivers/USB/Core/AVR8/Endpoint_AVR8.c \
modules/lufa/LUFA/Drivers/USB/Core/AVR8/PipeStream_AVR8.c \
modules/lufa/LUFA/Drivers/USB/Core/AVR8/Pipe_AVR8.c \
modules/lufa/LUFA/Drivers/USB/Core/AVR8/USBController_AVR8.c \
modules/lufa/LUFA/Drivers/USB/Core/AVR8/USBInterrupt_AVR8.c \
modules/lufa/LUFA/Drivers/USB/Core/ConfigDescriptors.c \
modules/lufa/LUFA/Drivers/USB/Core/DeviceStandardReq.c \
modules/lufa/LUFA/Drivers/USB/Core/Events.c \
modules/lufa/LUFA/Drivers/USB/Core/USBTask.c \
modules/lufa/LUFA/Drivers/USB/Class/Device/AudioClassDevice.c \
modules/lufa/LUFA/Drivers/USB/Class/Device/MIDIClassDevice.c \
modules/lufa/LUFA/Drivers/USB/Class/Device/CDCClassDevice.c
endif
endif
9 changes: 9 additions & 0 deletions src/board/arch/avr/atmel/variants/avr8/atmega16u2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ifeq ($(TYPE),boot)
#save flash - this feature doesn't fit into 4k
DEFINES := $(filter-out LED_INDICATORS_CTL,$(DEFINES))
UART_TX_BUFFER_SIZE := 32
UART_RX_BUFFER_SIZE := 32
else ifeq ($(TYPE),app)
UART_TX_BUFFER_SIZE := 64
UART_RX_BUFFER_SIZE := 64
endif

0 comments on commit dbe06d0

Please sign in to comment.