-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
75 lines (58 loc) · 1.96 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
#######
# makefile for STM8S_StdPeriph_Lib and SDCC compiler
#
# Customized by MightyPork 1/2017
#
# usage:
# 1. if SDCC not in PATH set path -> CC_ROOT
# 2. set correct STM8 device -> DEVICE
# 3. set project paths -> PRJ_ROOT, PRJ_SRC_DIR, PRJ_INC_DIR
# 4. set SPL root path -> SPL_ROOT
# 5. include required SPL modules -> SPL_SOURCE
#
#######
# STM8 device (default is STM8 discovery board)
DEVICE=STM8S103
DEVICE_FLASH=stm8s103f3
# trap handling requires SDCC >=v3.4.3
SKIP_TRAPS = 0
# set compiler path & parameters
CC_ROOT = /home/dimka/apps/sdcc/bin
CC = $(CC_ROOT)/sdcc
CFLAGS = -mstm8 -lstm8 --opt-code-size --std-sdcc99
# required for some examples for STM8S EVAL board
#CFLAGS += -DUSE_STM8_128_EVAL
# set output folder and target name
OUTPUT_DIR = ./build
TARGET = $(OUTPUT_DIR)/$(DEVICE).hex
# set project folder and files (all *.c)
PRJ_ROOT = .
PRJ_SRC_DIR = $(PRJ_ROOT)/src
PRJ_INC_DIR = $(PRJ_ROOT)/inc
# all project sources included by default
PRJ_SOURCE = $(notdir $(wildcard $(PRJ_SRC_DIR)/*.c))
PRJ_OBJECTS := $(addprefix $(OUTPUT_DIR)/, $(PRJ_SOURCE:.c=.rel))
# set SPL paths
SPL_SRC_DIR = ./STM8S_StdPeriph_Driver/src
SPL_INC_DIR = ./STM8S_StdPeriph_Driver/inc
# add all library sources used here
SPL_SOURCE = stm8s_gpio.c stm8s_i2c.c
SPL_OBJECTS := $(addprefix $(OUTPUT_DIR)/, $(SPL_SOURCE:.c=.rel))
# collect all include folders
INCLUDE = -I$(PRJ_INC_DIR) -I$(SPL_INC_DIR)
# collect all source directories
VPATH=$(PRJ_SRC_DIR):$(SPL_SRC_DIR)
.PHONY: clean flash
all: $(TARGET)
$(OUTPUT_DIR)/%.rel: %.c
$(CC) $(CFLAGS) -D$(DEVICE) $(INCLUDE) -DSKIP_TRAPS=$(SKIP_TRAPS) -c $?
$(OUTPUT_DIR)/%.rel: %.c
$(CC) $(CFLAGS) -D$(DEVICE) $(INCLUDE) -DSKIP_TRAPS=$(SKIP_TRAPS) -c $? -o $@
$(TARGET): $(PRJ_OBJECTS) $(SPL_OBJECTS)
$(CC) $(CFLAGS) -o $(TARGET) $^
flash: all
~/apps/stm8flash -c stlinkv2 -p $(DEVICE_FLASH) -s flash -w $(TARGET)
clean:
rm $(OUTPUT_DIR)/*
size:
$(CC_ROOT)/sdnm -A --print-size --size-sort --radix=d $(OUTPUT_DIR)/*rel