-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
110 lines (86 loc) · 3.23 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Universal C Makefile for MCU targets
LIBNAME=libalpaca
# Path to project root (for top-level, so the project is in ./; first-level, ../; etc.)
ROOT=.
# Binary output directory
BINDIR=$(ROOT)/bin
# Subdirectories to include in the build
SUBDIRS=src
# Nothing below here needs to be modified by typical users
# Include common aspects of this project
-include $(ROOT)/common.mk
ASMSRC:=$(wildcard *.$(ASMEXT))
ASMOBJ:=$(patsubst %.o,$(BINDIR)/%.o,$(ASMSRC:.$(ASMEXT)=.o))
HEADERS:=$(wildcard *.$(HEXT))
CSRC=$(wildcard *.$(CEXT))
COBJ:=$(patsubst %.o,$(BINDIR)/%.o,$(CSRC:.$(CEXT)=.o))
CPPSRC:=$(wildcard *.$(CPPEXT))
CPPOBJ:=$(patsubst %.o,$(BINDIR)/%.o,$(CPPSRC:.$(CPPEXT)=.o))
OUT:=$(BINDIR)/$(OUTNAME)
.PHONY: all clean documentation library template flash upload upload-legacy _force_look release develop
# default version just uses the latest tag
VERSION := `git describe --abbrev=0`
# By default, compile program
all: $(BINDIR) $(OUT)
release:
$(eval CCFLAGS += -D FW_VERSION="$(VERSION)")
develop:
$(eval VERSION := `git describe --abbrev=1`)
$(eval CCFLAGS += -D FW_VERSION="$(VERSION)")
# Remove all intermediate object files (remove the binary directory)
clean:
-rm -f $(OUT)
-rm -rf $(BINDIR)
# Uploads program to device
upload: all
$(FLASH)
# Alias to upload, more consistent with our terminology
flash: upload
# Uploads program to device using legacy uniflasher JAR file
upload-legacy: all
$(UPLOAD)
# Phony force-look target
_force_look:
@true
# Compiles library for general HS use
library: clean $(BINDIR) $(SUBDIRS) $(ASMOBJ) $(COBJ) $(CPPOBJ)
# Get rid of junk that the user should be doing
-rm -f $(BINDIR)/opcontrol.o
-rm -f $(BINDIR)/init.o
-rm -f $(BINDIR)/auto.o
$(MCUPREFIX)ar rvs $(BINDIR)/$(LIBNAME)_sym.a $(BINDIR)/*.o
$(MCUPREFIX)objcopy -S -g $(BINDIR)/$(LIBNAME)_sym.a $(BINDIR)/$(LIBNAME).a
TEMPLATEFILES:=src/auto.cpp src/init.cpp src/opcontrol.cpp src/Makefile include/API.hpp include/main.hpp include/alpaca firmware common.mk
template: library
-rm -rf $(addprefix $(ROOT)/template/,$(TEMPLATEFILES))
mkdir -p $(ROOT)/template/src $(ROOT)/template/include $(ROOT)/template/firmware
$(foreach f,$(TEMPLATEFILES),cp -r $(ROOT)/$(f) $(ROOT)/template/$(f); )
cp $(BINDIR)/$(LIBNAME).a $(ROOT)/template/firmware/$(LIBNAME).a
mv template/firmware/firmware/* template/firmware/
rm template/firmware/firmware/ -rf
# Builds the documentation
documentation:
doxygen Doxyfile
# Looks in subdirectories for things to make
$(SUBDIRS): %: _force_look
@$(MAKE) --no-print-directory -C $@
# Ensure binary directory exists
$(BINDIR):
-@mkdir -p $(BINDIR)
# Compile program
$(OUT): $(SUBDIRS) $(ASMOBJ) $(COBJ) $(CPPOBJ)
@echo LN $(BINDIR)/*.o $(LIBRARIES) to $@
@$(CC) $(LDFLAGS) $(BINDIR)/*.o $(LIBRARIES) -o $@
@$(MCUPREFIX)size $(SIZEFLAGS) $(OUT)
$(MCUPREPARE)
# Assembly source file management
$(ASMOBJ): $(BINDIR)/%.o: %.$(ASMEXT) $(HEADERS)
@echo AS $<
@$(AS) $(AFLAGS) -o $@ $<
# Object management
$(COBJ): $(BINDIR)/%.o: %.$(CEXT) $(HEADERS)
@echo CC $(INCLUDE) $<
@$(CC) $(INCLUDE) $(CFLAGS) -o $@ $<
$(CPPOBJ): $(BINDIR)/%.o: %.$(CPPEXT) $(HEADERS)
@echo CPC $(INCLUDE) $<
@$(CPPCC) $(INCLUDE) $(CPPFLAGS) -o $@ $<