forked from am32-firmware/AM32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
119 lines (88 loc) · 3.01 KB
/
makefile
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
QUIET = @
# tools
CC = $(ARM_SDK_PREFIX)gcc
CP = $(ARM_SDK_PREFIX)objcopy
ECHO = echo
# common variables
IDENTIFIER := AM32
# Folders
HAL_FOLDER := Mcu
MAIN_SRC_DIR := Src
MAIN_INC_DIR := Inc
SRC_DIRS_COMMON := $(MAIN_SRC_DIR)
# Include processor specific makefiles
include f051makefile.mk
include g071makefile.mk
include f031makefile.mk
include f421makefile.mk
include e230makefile.mk
include f415makefile.mk
# Default MCU type to F051
MCU_TYPE ?= F051
# additional libs
LIBS := -lc -lm -lnosys
# Compiler options
CFLAGS_COMMON := -DUSE_MAKE
CFLAGS_COMMON += -I$(MAIN_INC_DIR) -O3 -Wall -ffunction-sections
CFLAGS_COMMON += -D$(TARGET)
# Linker options
LDFLAGS_COMMON := -specs=nano.specs $(LIBS) -Wl,--gc-sections -Wl,--print-memory-usage
# Working directories
ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
# Search source files
SRC_COMMON := $(foreach dir,$(SRC_DIRS_COMMON),$(wildcard $(dir)/*.[cs]))
VERSION_MAJOR := $(shell grep "#define VERSION_MAJOR" $(MAIN_SRC_DIR)/main.c | awk '{print $$3}' )
VERSION_MINOR := $(shell grep "#define VERSION_MINOR" $(MAIN_SRC_DIR)/main.c | awk '{print $$3}' )
FIRMWARE_VERSION := $(VERSION_MAJOR).$(VERSION_MINOR)
TARGET_BASENAME = $(BIN_DIR)/$(IDENTIFIER)_$(TARGET)_$(FIRMWARE_VERSION)
# Build tools, so we all share the same versions
# import macros common to all supported build systems
include $(ROOT)/make/system-id.mk
# configure some directories that are relative to wherever ROOT_DIR is located
BIN_DIR := $(ROOT)/obj
TOOLS_DIR ?= $(ROOT)/tools
DL_DIR := $(ROOT)/downloads
.PHONY : clean all binary f051 g071 f031 e230 f421 f415
all : $(TARGETS_F051) $(TARGETS_G071) $(TARGETS_F031) $(TARGETS_E230) $(TARGETS_F421) $(TARGETS_F415)
f051 : $(TARGETS_F051)
g071 : $(TARGETS_G071)
f031 : $(TARGETS_F031)
e230 : $(TARGETS_E230)
f421 : $(TARGETS_F421)
f415 : $(TARGETS_F415)
clean :
rm -rf $(BIN_DIR)/*
binary : $(TARGET_BASENAME).bin
@$(ECHO) All done
$(TARGETS_F051) :
@$(MAKE) -s MCU_TYPE=F051 TARGET=$@ binary
$(TARGETS_G071) :
@$(MAKE) -s MCU_TYPE=G071 TARGET=$@ binary
$(TARGETS_F031) :
@$(MAKE) -s MCU_TYPE=F031 TARGET=$@ binary
$(TARGETS_E230) :
@$(MAKE) -s MCU_TYPE=E230 TARGET=$@ binary
$(TARGETS_F421) :
@$(MAKE) -s MCU_TYPE=F421 TARGET=$@ binary
$(TARGETS_F415) :
@$(MAKE) -s MCU_TYPE=F415 TARGET=$@ binary
# Compile target
$(TARGET_BASENAME).elf: SRC := $(SRC_COMMON) $(SRC_$(MCU_TYPE))
$(TARGET_BASENAME).elf: CFLAGS := $(MCU_F051) $(CFLAGS_$(MCU_TYPE)) $(CFLAGS_COMMON)
$(TARGET_BASENAME).elf: LDFLAGS := $(LDFLAGS_COMMON) $(LDFLAGS_$(MCU_TYPE)) -T$(LDSCRIPT_$(MCU_TYPE))
$(TARGET_BASENAME).elf: $(SRC)
@$(ECHO) Compiling $(notdir $@)
$(QUIET)mkdir -p $(dir $@)
$(QUIET)$(CC) $(CFLAGS) $(LDFLAGS) -MMD -MP -MF $(@:.elf=.d) -o $(@) $(SRC)
# Generate bin and hex files
$(TARGET_BASENAME).bin: $(TARGET_BASENAME).elf
@$(ECHO) Generating $(notdir $@)
$(QUIET)$(CP) -O binary $(<) $@
$(QUIET)$(CP) $(<) -O ihex $(@:.bin=.hex)
# mkdirs
$(DL_DIR):
$(QUIET)mkdir -p $@
$(TOOLS_DIR):
$(QUIET)mkdir -p $@
# include the tools makefile
include $(ROOT)/make/tools.mk