-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile.common
105 lines (80 loc) · 2.74 KB
/
Makefile.common
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Build path
ifdef BOARD
export BUILD_DIR = build/$(BOARD_FILE_NAME)/build
else
export BUILD_DIR = build/$(MCU_FILE_NAME)/build
endif
export TARGET_DIR = $(BUILD_DIR)/..
C_DEFS += \
-DGIT_BRANCH=\"$(BRANCH)\" \
-DGIT_HASH=\"$(HASH)\" \
-DGIT_TAG=\"$(TAG)\"
# Check if the linker data script (LDS) is RAM version
ifeq (RAM, $(findstring RAM, $(LDSCRIPT)))
C_DEFS += \
-DLDS_RAM_VERSION \
-DVECT_TAB_SRAM
endif
# compile gcc flags
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
ifeq ($(DEBUG), 1)
CFLAGS += -g -gdwarf-2 -D$(MCU_FILE_NAME) -D$(FLASH)
endif
ifdef BOARD
CFLAGS += -D$(BOARD)
TARGET := $(TARGET)_$(BOARD_FILE_NAME)
else
TARGET := $(TARGET)_$(MCU_FILE_NAME)
endif
# Check secure flag
ifeq ($(secure), true)
C_DEFS += \
-DSECURED
endif
# Generate dependency information
CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
#linker
LD_NAME = $(basename $(LDSCRIPT))
LD_SUFFIX = $(suffix $(LDSCRIPT))
# libraries
LIBS = -lc -lm -lnosys
LIBDIR =
LDFLAGS = $(MCU) -specs=nano.specs -TLinker/$(LD_NAME)$(LD_SUFFIX) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
LDFLAGS_SIGNATURE = $(MCU) -specs=nano.specs -TLinker/$(LD_NAME)_SIGNATURE$(LD_SUFFIX) $(LIBDIR) $(LIBS) -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections
# default action: build all
all: debug signed
debug: $(TARGET_DIR)/$(TARGET).elf $(TARGET_DIR)/$(TARGET).hex $(TARGET_DIR)/$(TARGET).bin
signed: $(TARGET_DIR)/$(TARGET)_signed.elf $(TARGET_DIR)/$(TARGET)_signed.bin
#######################################
# build the application
#######################################
# list of objects
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
# list of ASM program objects
OBJECTS += $(addprefix $(BUILD_DIR)/,$(notdir $(ASM_SOURCES:.s=.o)))
vpath %.s $(sort $(dir $(ASM_SOURCES)))
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
$(BUILD_DIR)/%.o: %.s Makefile | $(BUILD_DIR)
$(AS) -c $(CFLAGS) $< -o $@
$(TARGET_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS) -o $@
$(SZ) $@
$(TARGET_DIR)/$(TARGET)_signed.elf: $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS_SIGNATURE) -o $@
$(SZ) $@
$(TARGET_DIR)/%.hex: $(TARGET_DIR)/%.elf | $(BUILD_DIR)
$(HEX) $< $@
$(TARGET_DIR)/%.bin: $(TARGET_DIR)/%.elf | $(BUILD_DIR)
$(BIN) $< $@
$(TARGET_DIR)/%_signed.bin: $(TARGET_DIR)/%_signed.elf | $(BUILD_DIR)
$(BIN) $< $@
$(BUILD_DIR):
mkdir -p $@
#######################################
# dependencies
#######################################
-include $(wildcard $(BUILD_DIR)/*.d)
# ** EOF **