-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
93 lines (71 loc) · 2.17 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
CONFIG_FILE = ./config.json
define GetFromConfig
$(shell node -p "require('$(CONFIG_FILE)').$(1)")
endef
DEVICE = $(strip $(call GetFromConfig,device))
DEVICE_FLASH = $(strip $(call GetFromConfig,flash.device))
STLINK = $(strip $(call GetFromConfig,flash.stlink))
F_CPU = 16000000
SKIP_TRAPS = 1
OUTPUT_DIR = ./build
LIB_DIR = ./lib
APP_DIR = ./app
TARGET = $(OUTPUT_DIR)/out
LIB ?= SPL
ifeq ($(OS),Windows_NT)
CC_ROOT = "/c/Program Files/SDCC"
else
CC_ROOT = /opt/sdcc
endif
CC = $(CC_ROOT)/bin/sdcc
C_DEFS = \
-D F_CPU=$(F_CPU) \
C_INCLUDES = \
-I app/inc \
C_INCLUDES += $(addprefix -I ,$(wildcard $(LIB_DIR)/**/inc))
C_FLAGS = \
-mstm8 \
-lstm8 \
--opt-code-size \
--std-sdcc99 \
--nogcse \
--all-callee-saves \
--stack-auto \
--fverbose-asm \
--float-reent \
--no-peep \
APP_SOURCES = $(notdir $(wildcard $(APP_DIR)/src/*.c))
APP_OBJECTS := $(addprefix $(OUTPUT_DIR)/, $(APP_SOURCES:.c=.rel))
APP_INCLUDES = $(wildcard $(APP_DIR)/inc/*.h)
APP_ASMS := $(addprefix $(OUTPUT_DIR)/, $(APP_SOURCES:.c=.asm))
LIB_SOURCES = $(notdir $(wildcard $(LIB_DIR)/**/src/*.c))
LIB_OBJECTS := $(addprefix $(OUTPUT_DIR)/, $(LIB_SOURCES:.c=.rel))
LIB_INCLUDES = $(wildcard $(LIB_DIR)/**/inc/*.h)
LIB_ASMS := $(addprefix $(OUTPUT_DIR)/, $(LIB_SOURCES:.c=.asm))
VPATH = $(APP_DIR)/src $(wildcard $(LIB_DIR)/**/src)
compile: $(TARGET).ihx
$(TARGET).ihx: $(APP_ASMS) $(LIB_ASMS)
.make/asms_to_objects $^
$(CC) $(C_FLAGS) $(C_DEFS) -o $(TARGET).ihx $(APP_OBJECTS) $(LIB_OBJECTS)
@node .make/size_calculation --files=$(TARGET).ihx
$(OUTPUT_DIR)/%.asm: %.c Makefile $(APP_INCLUDES) | $(OUTPUT_DIR)
$(CC) $(C_FLAGS) -I app/inc $(C_DEFS) -D$(DEVICE) $(C_INCLUDES) -DSKIP_TRAPS=$(SKIP_TRAPS) -c $< -o $@
$(OUTPUT_DIR):
@mkdir -p $(OUTPUT_DIR)
install:
bash .make/install
@node .make/update --library=$(LIB) --device=$(DEVICE)
update:
bash .make/install
@node .make/update --library=$(LIB) --device=$(DEVICE)
clean:
@rm -Rf $(OUTPUT_DIR)
flash:
@node .make/flash
test:
@echo -e $(APP_ASMS)
run:
make clean
make compile
make flash
.PHONY: clean