-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
88 lines (64 loc) · 1.93 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
TARGET=main
# toolchain
TOOLCHAIN_PREFIX=sdcc
CC=$(TOOLCHAIN_PREFIX)
PROGRAMMER = stlinkv2
DEVICE = stm8s003f3
F_CPU = 16000000
MCU = stm8
MCFLAGS = -m$(MCU)
################## User Sources ####################
SRCS = src/main.c
SRCS += src/ws2812_driver.c
SRCS += src/buttons.c
SRCS += src/timer.c
SRCS += src/color_utils.c
SRCS += src/flash.c
################## Objects ####################
OBJS = build/main.rel
OBJS += build/ws2812_driver.rel
OBJS += build/buttons.rel
OBJS += build/timer.rel
OBJS += build/color_utils.rel
OBJS += build/flash.rel
################## Includes ########################
INCLS = -I. -Iinc
################## Libs ########################
LDFLAGS = -lstm8 --out-fmt-ihx
LDFLAGS += $(MCFLAGS)
################ Compiler Flags ######################
CFLAGS = --std-sdcc11
CFLAGS += $(MCFLAGS)
CFLAGS += -DF_CPU=$(F_CPU)UL
CFLAGS += --stack-auto --noinduction --use-non-free
############# CFLAGS for Optimization ##################
################### Recipe to make all (build and burn) ####################
.PHONY: all
all: build
################### Recipe to build ####################
.PHONY: build
build: build/$(TARGET).hex
################### Recipe to burn ####################
.PHONY: burn
burn:
@echo "[Flashing] build/$(TARGET).hex"
@stm8flash -c $(PROGRAMMER) -p $(DEVICE) -w build/$(TARGET).hex
################### Recipe to make .hex ####################
build/$(TARGET).hex: $(OBJS)
@echo "[Linking] $@"
@$(CC) $(LDFLAGS) $^ -o $@
################### Recipe to make .rel ####################
build/%.rel: src/%.c
@echo "[Building] $@"
@$(CC) $(INCLS) $(CFLAGS) -c -o $@ $<
################### Recipe to get size ####################
size:
@$(OBJCOPY) -I ihex --output-target=binary build/$(TARGET).hex
@echo "----------"
@echo "Image size:"
@stat -L -c %s build/$(TARGET).hex
################### Recipe to clean all ####################
.PHONY: clean
clean:
@echo "[Cleaning]"
@rm -rf build/*