-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
42 lines (34 loc) · 1.11 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
SHELL:=/usr/bin/env bash
SDCC?=sdcc
SDAR?=sdar
SRCDIR=./src
BINDIR=./bin
INCLUDES=\
./vendor/stm8s/inc\
./vendor/button_debounce/inc
CFLAGS= --std-c11 --nolospre $(addprefix -I,$(INCLUDES))
LDFLAGS=--out-fmt-ihx
ENTRY_SOURCE_FILE=$(shell find $(SRCDIR) -maxdepth 1 -name "main.c")
APP_SOURCE_FILES=$(filter-out $(ENTRY_SOURCE_FILE), $(shell find $(SRCDIR) -name "*.c"))
LIB_SOURCE_FILES=$(shell find $(INCLUDES) -name "*.c")
ENTRY_OBJECT=$(subst /./,/,$(addprefix $(BINDIR)/,$(ENTRY_SOURCE_FILE:.c=.rel)))
APP_OBJECTS=$(subst /./,/,$(addprefix $(BINDIR)/,$(APP_SOURCE_FILES:.c=.rel)))
LIB_OBJECTS=$(subst /./,/,$(addprefix $(BINDIR)/,$(LIB_SOURCE_FILES:.c=.rel)))
.PHONY: build clean
build: $(BINDIR)/program.hex
clean:
rm -rf $(BINDIR)/
$(BINDIR)/program.hex: $(ENTRY_OBJECT) $(BINDIR)/vendor.lib $(BINDIR)/app.lib
$(SDCC) -mstm8 -lstm8 -o $@ $(LDFLAGS) $^
$(BINDIR)/%.rel: %.c
mkdir -p $(dir $@) &&\
$(SDCC) -mstm8 -o $@ -c $(CFLAGS) $^
$(BINDIR)/vendor.lib: $(LIB_OBJECTS)
[[ ! -z "$^" ]] &&\
$(SDAR) -rc $@ $^ ||\
touch $@
$(BINDIR)/app.lib: $(APP_OBJECTS)
[[ ! -z "$^" ]] &&\
$(SDAR) -rc $@ $^ ||\
touch $@
%.c: %.h