-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules.mk
67 lines (44 loc) · 1.51 KB
/
rules.mk
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
# Chopstx make rules.
CSRC += $(CHOPSTX)/entry.c $(CHOPSTX)/chopstx.c
ifneq ($(USE_EVENTFLAG),)
CSRC += $(CHOPSTX)/eventflag.c
endif
INCDIR += $(CHOPSTX)
BUILDDIR = build
OUTFILES = $(BUILDDIR)/$(PROJECT).elf $(BUILDDIR)/$(PROJECT).bin
ifneq ($(ENABLE_OUTPUT_HEX),)
OUTFILES += $(BUILDDIR)/$(PROJECT).hex
endif
OPT += -ffunction-sections -fdata-sections -fno-common
OBJS = $(addprefix $(BUILDDIR)/, $(notdir $(CSRC:.c=.o)))
IINCDIR = $(patsubst %,-I%,$(INCDIR))
LLIBDIR = $(patsubst %,-L%,$(LIBDIR))
VPATH = $(sort $(dir $(CSRC)))
###
MCFLAGS = -mcpu=$(MCU)
CFLAGS = $(MCFLAGS) $(OPT) $(CWARN) -Wa,-alms=$(BUILDDIR)/$(notdir $(<:.c=.lst)) $(DEFS)
LDFLAGS = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT) -Wl,-Map=$(BUILDDIR)/$(PROJECT).map,--cref,--no-warn-mismatch,--gc-sections $(LLIBDIR)
CFLAGS += -mthumb -mno-thumb-interwork -DTHUMB
LDFLAGS += -mthumb -mno-thumb-interwork
CFLAGS += -MD -MP -MF .dep/$(@F).d
all: $(OUTFILES)
$(OBJS): | $(BUILDDIR)
$(BUILDDIR):
mkdir -p $(BUILDDIR)
$(OBJS) : $(BUILDDIR)/%.o : %.c Makefile
@echo
$(CC) -c $(CFLAGS) -I. $(IINCDIR) $< -o $@
%.elf: $(OBJS) $(OBJS_ADD) $(LDSCRIPT)
@echo
$(LD) $(OBJS) $(OBJS_ADD) $(LDFLAGS) $(LIBS) -o $@
%.bin: %.elf $(LDSCRIPT)
$(OBJCOPY) -O binary $< $@
%.hex: %.elf $(LDSCRIPT)
$(OBJCOPY) -O ihex $< $@
write: all openocd.cfg
openocd -f ./openocd.cfg -c "program $(BUILDDIR)/$(PROJECT).elf"
clean:
-rm -f -r .dep $(BUILDDIR)
-rm -f DATS/*.c
# Include dependency files.
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)