-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
98 lines (63 loc) · 2.73 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
#****************************************************************************
# Makefile
# SnapperGPS
# November 2020
#****************************************************************************
# Set the toolpath parameter to the location of the Arm GNU Toolchain
TOOLCHAIN_PATH = --- INSERT PATH TO ARM GNU TOOLCHAIN HERE (e.g., /Library/Toolchains/) ---
TOOLCHAIN_VERSION = gcc-arm-none-eabi-10-2020-q4-major
# Determine the path to the toolchain binary
TOOLPATH = $(TOOLCHAIN_PATH)/$(TOOLCHAIN_VERSION)/bin/
# Determine the path to the shared code
SHARED = ../../../shared_library/
# These are the locations of the source and header files
INC = $(SHARED)/cmsis $(SHARED)/device/inc $(SHARED)/emlib/inc $(SHARED)/emusb/inc $(SHARED)/inc ../inc
SRC = $(SHARED)/device/src $(SHARED)/emlib/src $(SHARED)/emusb/src $(SHARED)/src ../src
# Set the name of the output files
FILENAME = snapper
# This is the location of the resulting object files
OBJPATH = ./objects/
# Set the target EFM32HG to that used in Snapper
TARGET = EFM32HG310F64
# The following code generates the list of objects and the search path of source and header files
VPATH = $(SRC)
IFLAGS = $(foreach d, $(INC), -I$d)
_CSRC = $(notdir $(foreach d, $(SRC), $(wildcard $d/*.c)))
_SSRC = $(notdir $(foreach d, $(SRC), $(wildcard $d/*.s)))
_OBJ = $(_CSRC:.c=.o) $(_SSRC:.s=.o)
OBJ = $(sort $(foreach d, $(_OBJ), $(OBJPATH)$d))
DEP = $(OBJ:.o=.d)
# These are the compilation settings
CC = $(TOOLPATH)arm-none-eabi-gcc
CSIZE = $(TOOLPATH)arm-none-eabi-size
COBJCOPY = $(TOOLPATH)arm-none-eabi-objcopy
COBJDUMP = $(TOOLPATH)arm-none-eabi-objdump
CFLAGS = -mcpu=cortex-m0plus -mthumb -g0 -Wall '-D$(TARGET)=1' '-D__STACK_SIZE=512' '-D__HEAP_SIZE=128'
DFLAGS = -MMD
# Finally the build rules
$(OBJPATH)%.o: %.c
@mkdir -p $(OBJPATH)
@echo 'Building' $@
@$(CC) $(CFLAGS) $(DFLAGS) -O2 -ffunction-sections -fdata-sections -std=c99 -c -o "$@" "$<" $(IFLAGS)
$(OBJPATH)%.o: %.s
@mkdir -p $(OBJPATH)
@echo 'Building' $@
@$(CC) $(CFLAGS) $(DFLAGS) -x assembler-with-cpp -c -o "$@" "$<" $(IFLAGS)
$(FILENAME).bin: $(OBJ)
@echo 'Building' $(FILENAME).axf
@$(CC) $(CFLAGS) $(DFLAGS) -T "snapper.ld" -Xlinker --gc-sections -Xlinker -Map="$(FILENAME).map" --specs=nano.specs -o $(FILENAME).axf $(OBJ) -Wl,--start-group -lgcc -lc -lnosys -Wl,--end-group
@$(COBJDUMP) -d -t -S "$(FILENAME).axf" > "$(FILENAME).lst"
@echo 'Building' $(FILENAME).hex
@$(COBJCOPY) -O ihex "$(FILENAME).axf" "$(FILENAME).hex"
@echo 'Building' $(FILENAME).bin
@$(COBJCOPY) -O binary "$(FILENAME).axf" "$(FILENAME).bin"
@$(CSIZE) -A "$(FILENAME).axf"
-include $(DEP)
.PHONY: clean
clean:
rm -f $(OBJPATH)*.o
rm -f $(OBJPATH)*.d
rm -f $(FILENAME).axf
rm -f $(FILENAME).bin
rm -f $(FILENAME).hex
rm -f $(FILENAME).map