-
Notifications
You must be signed in to change notification settings - Fork 33
/
Makefile
45 lines (32 loc) · 1.19 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
TARGETS = firmware boot test_rig test_rig_boot
BUILD = build
all: $(TARGETS)
.PHONY: all clean update
ATMEL_PATH = deps/sam0
CMSIS_PATH = $(ATMEL_PATH)/cmsis/samd21
DRIVERS_PATH = $(ATMEL_PATH)/drivers
CC = arm-none-eabi-gcc
OBJCOPY = arm-none-eabi-objcopy
SIZE = arm-none-eabi-size
include $(addsuffix .mk,$(TARGETS))
$(BUILD)/version.c: .git/HEAD .git/index
@mkdir -p $(BUILD)
echo "const char *git_version = \"$(shell git describe --long)\";" > $@
define each_target
$(1): $(BUILD)/$(1).elf $(BUILD)/$(1).bin
.PHONY: $(1)
$(1)_OBJS := $$(addprefix $(BUILD)/$(1)/, $$(subst .c,.o, $$($(1)_SRC)))
-include $$($(1)_OBJS:.o=.d)
$$($(1)_OBJS): $(BUILD)/$(1)/%.o: %.c
@mkdir -p $$(shell dirname $$@)
$(Q)$(CC) $$($(1)_CFLAGS) $$($(1)_INCLUDE) $$($(1)_DEFINE) -c $$< -o $$@ -MMD -MP -MF $$(patsubst %.o,%.d,$$@)
$(BUILD)/$(1).bin $(BUILD)/$(1).elf: $$($(1)_OBJS)
$(Q)$(CC) $$($(1)_CFLAGS) $$($(1)_LDFLAGS) $$($(1)_OBJS) -Wl,-T$$($(1)_LDSCRIPT) -o $(BUILD)/$(1).elf
$(Q)$(OBJCOPY) -O binary -R .eeprom $(BUILD)/$(1).elf $(BUILD)/$(1).bin
endef
$(foreach t,$(TARGETS),$(eval $(call each_target,$(t))))
clean:
@-rm -rf $(BUILD)
update:
git submodule update --init --recursive
print-% : ; @echo $* = $($*)