forked from spqr/umichmoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
59 lines (47 loc) · 1.54 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
include config.mk
include build.mk
ifeq ($(TARGET),debug)
CFLAGS+=-ggdb3
endif
SOURCES := flash.c moo.c rfid.c build_send_to_reader.c build_port1_isr.c timerA1_isr.c sensor.c sensor_read.c
TARGET_FULL=$(TARGET)-$(MOO_VERSION)
OUTDIR_BASE=build
OUTDIR=$(OUTDIR_BASE)/$(TARGET_FULL)
DEPDIR_BASE=.dep
DEPDIR=$(DEPDIR_BASE)/$(TARGET_FULL)
define include_sensors
SOURCES_SAVE := $$(SOURCES)
SOURCES :=
d := sensors/$(strip $(1))
include $(addsuffix /Rules.mk, $$(d))
SENSOR_SOURCES += $$(foreach file, $$(SOURCES), $$(d)/$$(file))
SOURCES := $$(SOURCES_SAVE)
endef
### Include sensor code ###
SENSOR_SOURCES :=
$(foreach sensor, $(SENSORS), $(eval $(call include_sensors, $(sensor))))
SENSOR_OBJECTS := $(SENSOR_SOURCES:%.c=$(OUTDIR)/%.o)
### End sensor code ###
OBJECTS=$(addprefix $(OUTDIR)/, $(notdir $(SOURCES:.c=.o)))
EXECUTABLE=moo-prog
HEX=$(EXECUTABLE).hex
all: $(OUTDIR)/$(HEX)
$(OUTDIR)/$(HEX): $(OUTDIR)/$(EXECUTABLE).elf
@$(OBJCOPY) -O ihex $< $@
@printf "%-30s [HEX]\n" "$(notdir $@)"
$(OUTDIR)/$(EXECUTABLE).elf: $(OBJECTS) $(SENSOR_OBJECTS)
@$(CC) $(ALL_LDFLAGS) $(ALL_CFLAGS) $(OBJECTS) $(SENSOR_OBJECTS) -o $@
@printf "%-30s [LD]\n" "$(notdir $@)"
$(SENSOR_OBJECTS) $(OBJECTS): $(OUTDIR)/%.o : %.c
@$(MKDIR) $(dir $@)
@$(MKDIR) $(dir $(DEPDIR)/$*.d)
@$(CC) -c -MD -MP -MF '$(DEPDIR)/$*.d' $(ALL_CFLAGS) $< -o $@
@printf "%-30s [CC]\n" "$(notdir $@)"
clean:
-$(RM) -r $(OUTDIR)/*
-$(RM) -r $(DEPDIR)/*
nuke:
-$(RM) -r $(OUTDIR_BASE)/*
-$(RM) -r $(DEPDIR_BASE)/*
-include $(addprefix $(DEPDIR)/, $(notdir $(OBJECTS:.o=.d)))
.PHONY: all clean