Skip to content
This repository was archived by the owner on Jan 30, 2024. It is now read-only.

Commit a7b75b6

Browse files
committed
Split Makefile up.
To facilitate adding unit testing.
1 parent 7a83ef8 commit a7b75b6

File tree

6 files changed

+115
-90
lines changed

6 files changed

+115
-90
lines changed

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*.map
88
*.lss
99
build/programming.mk
10+
build/env-settings.mk
1011
.cproject
1112
.project
1213
.settings/*

Diff for: build/Makefile

+16-86
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,27 @@
1-
PROJECT=panel1642
2-
3-
# In debug mode the suffix _debug is added to targets and objects to prevent contamination.
4-
ifeq ($(MODE),DEBUG)
5-
SUFFIX=_debug
6-
else
7-
SUFFIX=
8-
endif
9-
10-
# Add suffix to create target name
11-
TARGET:=$(PROJECT)$(SUFFIX)
12-
13-
# Hardware-specific settings
14-
include hw-settings.mk
15-
16-
# Path to toolchain binaries, or blank to use system path
17-
TOOLPATH:=
18-
19-
# Add all source directories, use trailing slash
1+
CFLAGS :=
2+
CXXFLAGS :=
3+
ASFLAGS :=
4+
COMMON_FLAGS :=
205
SRCDIRS :=
21-
SRCDIRS += ../src/
22-
SRCDIRS += ../system/semihosting-cortexm-uos/src/
23-
SRCDIRS += ../system/STM32F0xx_HAL_Driver/Src/
24-
SRCDIRS += ../system/CMSIS_STM32F0/Device/ST/STM32F0xx/Source/Templates/
25-
26-
# Assembly startup file for MCU, specified in hw-settings.mk
27-
STARTUP_DIR = ../system/CMSIS_STM32F0/Device/ST/STM32F0xx/Source/Templates/gcc/
28-
AS_SRCS = $(STARTUP_DIR)startup_$(STARTUP_FILE)
29-
30-
# Object dirs contain .o and .d files.
31-
OBJDIRS := $(patsubst ../%/,%/,$(SRCDIRS))
32-
OBJDIRS += $(patsubst ../%/,%/,$(STARTUP_DIR))
33-
OBJDIRS += $(patsubst ../%/,%/,$(FREERTOS_MEMDIR))
34-
35-
# Find all sources
36-
C_SRCS := $(wildcard $(addsuffix *.c,$(SRCDIRS)))
37-
CXX_SRCS := $(wildcard $(addsuffix *.cpp,$(SRCDIRS)))
38-
39-
# Add all include directories
6+
OBJDIRS :=
7+
C_SRCS :=
8+
CXX_SRCS :=
409
INCDIRS :=
41-
INCDIRS += ../system/CMSIS_STM32F0/Include
42-
INCDIRS += ../system/CMSIS_STM32F0/Device/ST/STM32F0xx/Include
43-
INCDIRS += ../system/STM32F0xx_HAL_Driver/Inc
44-
INCDIRS += ../inc
45-
INCDIRS += ../system/semihosting-cortexm-uos/inc
46-
47-
# Add library/linker script search paths
48-
LIBDIRS := ../ldscripts
49-
50-
# Add libraries:
10+
LIBDIRS :=
5111
LDLIBS :=
12+
LDSCRIPTS :=
5213

53-
# Compilation flags common to .c .cpp and .s files
54-
COMMON_FLAGS := -mthumb -fmessage-length=0 -fsigned-char -ffunction-sections
55-
COMMON_FLAGS += -fdata-sections -Wall -Wextra -g3
56-
COMMON_FLAGS += -std=gnu99
57-
COMMON_FLAGS += -DUSE_HAL_DRIVER
58-
COMMON_FLAGS += $(HWFLAGS) # add hardware settings (from hw-settings.mk)
59-
60-
# Disable some specific warnings:
61-
COMMON_FLAGS += -Wno-unused-parameter
62-
63-
# Linker options (g++ used for linking, so Xlinker for arguments straight to ld)
64-
LDFLAGS := -Xlinker --gc-sections --specs=nano.specs
65-
66-
# Disable startup files (comment out to allow startup files)
67-
LDFLAGS += -nostartfiles
68-
COMMON_FLAGS += -DLD_NOSTARTFILES # for conditional code based on startup files
6914

70-
# Language-specific compiler flags
71-
CFLAGS := -MMD -MP
72-
CXXFLAGS := -MMD -MP -fabi-version=0 -fno-exceptions -fno-rtti -fno-use-cxa-atexit -fno-threadsafe-statics
73-
ASFLAGS := -x assembler-with-cpp
15+
# Local environment settings
16+
include env-settings.mk
7417

75-
# Set up debug specific options
76-
ifeq ($(MODE),DEBUG)
77-
COMMON_FLAGS += -DDEBUG -DUSE_FULL_ASSERT -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -Og
78-
COMMON_FLAGS += -DUDEBUG_LEVEL=2
79-
CFLAGS +=
80-
CXXFLAGS +=
81-
LDFLAGS+= --specs=rdimon.specs # rdimon.specs needed for semihosting
82-
else
83-
COMMON_FLAGS += -DUDEBUG_LEVEL=0 -O3 -flto
84-
CFLAGS +=
85-
CXXFLAGS +=
86-
LDFLAGS +=
87-
endif
18+
# Source paths and flags common for both Tests and Target
19+
include common-src.mk
8820

89-
# Add in all the common flags
90-
CFLAGS += $(COMMON_FLAGS)
91-
CXXFLAGS += $(COMMON_FLAGS)
92-
ASFLAGS += $(COMMON_FLAGS)
21+
# Paths and flags for running on Target (rather than Testing locally)
22+
include target.mk
9323

94-
# Compilation rules set up here
24+
# Target compilation rules set up here
9525
include arm-gcc-buildtree.mk
9626

9727
# Custom rules for programming and debugging

Diff for: build/arm-gcc-buildtree.mk

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,28 @@
11
# Requires the following variables to exist:
22
# PROJECT
33
# SUFFIX
4-
# TARGET
54
# LDLIBS
65
# LDSCRIPTS
76
# LIBDIRS
87
# SRCDIRS
98
# INCDIRS
109
# CFLAGS
1110
# CXXFLAGS
11+
# ASFLAGS
1212
# LDFLAGS
13-
# C_SRCS
14-
# CXX_SRCS
15-
# AS_SRCS
13+
# C_SRCS
14+
# CXX_SRCS
15+
# AS_SRCS
16+
17+
# In debug mode the suffix _debug is added to targets and objects to prevent contamination.
18+
ifeq ($(MODE),DEBUG)
19+
SUFFIX=_debug
20+
else
21+
SUFFIX=
22+
endif
23+
24+
# Add suffix to create target name
25+
TARGET:=$(PROJECT)$(SUFFIX)
1626

1727
# Objects will be in mirrored folder tree in build folder
1828
OBJS := $(patsubst ../%.c,%$(SUFFIX).o,$(C_SRCS))

Diff for: build/common-src.mk

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
PROJECT=panel1642
2+
3+
# Compilation flags common to Tests and Target
4+
COMMON_FLAGS += -DUSE_HAL_DRIVER
5+
COMMON_FLAGS += -DSTM32F031x6
6+
7+
# Add all source directories, use trailing slash
8+
SRCDIRS += ../src/
9+
SRCDIRS += ../system/semihosting-cortexm-uos/src/
10+
SRCDIRS += ../system/STM32F0xx_HAL_Driver/Src/
11+
SRCDIRS += ../system/CMSIS_STM32F0/Device/ST/STM32F0xx/Source/Templates/
12+
13+
STARTUP_DIR = ../system/CMSIS_STM32F0/Device/ST/STM32F0xx/Source/Templates/gcc/
14+
AS_SRCS = $(STARTUP_DIR)startup_$(STARTUP_FILE)
15+
16+
# Object dirs contain .o and .d files.
17+
OBJDIRS += $(patsubst ../%/,%/,$(SRCDIRS))
18+
OBJDIRS += $(patsubst ../%/,%/,$(STARTUP_DIR))
19+
OBJDIRS += $(patsubst ../%/,%/,$(FREERTOS_MEMDIR))
20+
21+
# Find all sources
22+
C_SRCS += $(wildcard $(addsuffix *.c,$(SRCDIRS)))
23+
CXX_SRCS += $(wildcard $(addsuffix *.cpp,$(SRCDIRS)))
24+
25+
# Add all include directories
26+
INCDIRS += ../system/CMSIS_STM32F0/Include
27+
INCDIRS += ../system/CMSIS_STM32F0/Device/ST/STM32F0xx/Include
28+
INCDIRS += ../system/STM32F0xx_HAL_Driver/Inc
29+
INCDIRS += ../inc
30+
INCDIRS += ../system/semihosting-cortexm-uos/inc
31+
INCDIRS += ../system/FreeRTOS_STM32/Source/include
32+
INCDIRS += ../system/FreeRTOS_STM32/Source/portable/GCC/ARM_CM0
33+
INCDIRS += ../system/FreeRTOS_STM32/Source/CMSIS_RTOS
34+
35+
# Add library/linker script search paths
36+
LIBDIRS += ../ldscripts
37+
38+
# Add libraries:
39+
LDLIBS +=
40+

Diff for: build/env-settings.mk.example

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Path to toolchain binaries, or blank to use system path
2+
TOOLPATH:=

Diff for: build/target.mk

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Target startup and linker
2+
STARTUP_FILE := stm32f031x6.s
3+
LDSCRIPTS += STM32F031G6_FLASH.ld
4+
5+
# Compilation flags common to .c .cpp and .s files
6+
COMMON_FLAGS += -mcpu=cortex-m0
7+
COMMON_FLAGS += -mthumb -fmessage-length=0 -fsigned-char -ffunction-sections
8+
COMMON_FLAGS += -fdata-sections -Wall -Wextra -g3
9+
10+
# Disable some specific warnings:
11+
COMMON_FLAGS += -Wno-unused-parameter
12+
13+
# Linker options (g++ used for linking, so Xlinker for arguments straight to ld)
14+
LDFLAGS := -Xlinker --gc-sections --specs=nano.specs
15+
16+
# Disable startup files (comment out to allow startup files)
17+
LDFLAGS += -nostartfiles
18+
COMMON_FLAGS += -DLD_NOSTARTFILES # for conditional code based on startup files
19+
20+
# Language-specific compiler flags
21+
CFLAGS += -MMD -MP -std=gnu11
22+
CXXFLAGS += -MMD -MP -fabi-version=0 -fno-exceptions -fno-rtti -fno-use-cxa-atexit -fno-threadsafe-statics
23+
ASFLAGS += -x assembler-with-cpp
24+
25+
# Set up debug specific options
26+
ifeq ($(MODE),DEBUG)
27+
COMMON_FLAGS += -DDEBUG -DUSE_FULL_ASSERT -DTRACE -DOS_USE_TRACE_SEMIHOSTING_DEBUG -Og
28+
COMMON_FLAGS += -DUDEBUG_LEVEL=2
29+
CFLAGS +=
30+
CXXFLAGS +=
31+
LDFLAGS+= --specs=rdimon.specs # rdimon.specs needed for semihosting
32+
else
33+
COMMON_FLAGS += -DUDEBUG_LEVEL=0 -O3 -flto
34+
CFLAGS +=
35+
CXXFLAGS +=
36+
LDFLAGS +=
37+
endif
38+
39+
# Add in all the common flags
40+
CFLAGS += $(COMMON_FLAGS)
41+
CXXFLAGS += $(COMMON_FLAGS)
42+
ASFLAGS += $(COMMON_FLAGS)

0 commit comments

Comments
 (0)