-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
109 lines (90 loc) · 2.43 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
######################################
# target
######################################
TARGET = io-expander
######################################
# building variables
######################################
# debug build?
DEBUG = 1
# optimization
OPT = --opt-code-size
#######################################
# paths
#######################################
# Source path
SOURCE_DIR = src
SPL_SOURCE_DIR = /usr/src/stm8s_spl
# Build path
BUILD_DIR = build
# SPL Build path
SPL_BUILD_DIR = $(BUILD_DIR)/spl
######################################
# source
######################################
# C sources
LOCAL_SOURCES = \
main.c
SPL_SOURCES = \
$(SPL_SOURCE_DIR)/stm8s_gpio.c
#######################################
# binaries
#######################################
CC = sdcc
MKDIR = mkdir -p
STM8FLASH = stm8flash
#######################################
# CFLAGS
#######################################
# mcu
MCU = -mstm8
# C defines
C_DEFS = \
-DSTM8S103
# C includes
C_INCLUDES = \
-Iinc \
-I/usr/include/stm8s_spl \
-I/usr/local/share/sdcc/include
# compile gcc flags
CFLAGS = $(MCU) $(C_DEFS) $(C_INCLUDES) $(OPT)
#######################################
# LDFLAGS
#######################################
LDFLAGS = $(MCU) --out-fmt-ihx
.PHONY: all clean
# default action: build all
all: $(BUILD_DIR)/$(TARGET).ihx
#######################################
# build the application
#######################################
# list of objects
LOCAL_OBJ_FILES = $(LOCAL_SOURCES:.c=.rel)
LOCAL_OBJS = $(patsubst %,$(BUILD_DIR)/%,$(LOCAL_OBJ_FILES))
#LOCAL_OBJS = $(addprefix $(BUILD_DIR)/,$(notdir $(LOCAL_SOURCES:.c=.rel)))
#vpath %.c $(sort $(dir $(LOCAL_SOURCES)))
SPL_OBJ_FILES = $(SPL_SOURCES:.c=.rel)
SPL_OBJS = $(patsubst $(SPL_SOURCE_DIR)/%,$(SPL_BUILD_DIR)/%,$(SPL_OBJ_FILES))
# Link
# @echo "[LD] $(LDFLAGS) $< -o $@"
$(BUILD_DIR)/$(TARGET).ihx: $(LOCAL_OBJS) $(SPL_OBJS)
$(CC) $(LDFLAGS) $< $(SPL_OBJS) -o $@
# Compile
# @echo "[CC] -c $(CFLAGS) $< -o $@"
$(BUILD_DIR)/%.rel: $(SOURCE_DIR)/%.c
@$(MKDIR) $(dir $@)
$(CC) -c $(CFLAGS) $< -o $@
$(SPL_BUILD_DIR)/%.rel: $(SPL_SOURCE_DIR)/%.c
@$(MKDIR) $(dir $@)
$(CC) -c $(CFLAGS) $< -o $@
#######################################
# upload
#######################################
upload: $(BUILD_DIR)/$(TARGET).ihx
$(STM8FLASH) -c stlinkv2 -p stm8s103f3 -s flash -w $<
#######################################
# clean up
#######################################
clean:
-rm -fR $(BUILD_DIR)
# *** EOF ***