aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 9e8c79610a89a642cb43b02b0e237928411532b7 (plain)
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# Try "make help" first

.DEFAULT_GOAL := sketch

##
## Useful paths, constants, etc.
##

ifeq ($(LIB_MAPLE_HOME),)
SRCROOT := .
else
SRCROOT := $(LIB_MAPLE_HOME)
endif
BUILD_PATH = build
LIBMAPLE_PATH := $(SRCROOT)/libmaple
WIRISH_PATH := $(SRCROOT)/wirish
SUPPORT_PATH := $(SRCROOT)/support
# Support files for linker
LDDIR := $(SUPPORT_PATH)/ld
# Support files for this Makefile
MAKEDIR := $(SUPPORT_PATH)/make
BOARD_INCLUDE_DIR := $(MAKEDIR)/board-includes

##
## Target-specific configuration.  This determines some compiler and
## linker options/flags.
##

# Try "make help" for more information on BOARD and MEMORY_TARGET;
# these default to a Maple Flash build.
BOARD ?= maple
MEMORY_TARGET ?= flash

# $(BOARD)- and $(MEMORY_TARGET)-specific configuration
include $(MAKEDIR)/target-config.mk

##
## Compilation flags
##

# FIXME: the following allows for deprecated include style, e.g.:
#     #include "libmaple.h"
# or
#     #include "wirish.h"
# It slows compilation noticeably; remove after 1 release.
TARGET_FLAGS    += -I$(LIBMAPLE_PATH)/include/libmaple                       \
                   -I$(WIRISH_PATH)/include/wirish
GLOBAL_CFLAGS   := -Os -g3 -gdwarf-2  -mcpu=cortex-m3 -mthumb -march=armv7-m \
		   -nostdlib -ffunction-sections -fdata-sections	     \
		   -Wl,--gc-sections $(TARGET_FLAGS)
GLOBAL_CXXFLAGS := -fno-rtti -fno-exceptions -Wall $(TARGET_FLAGS)
GLOBAL_ASFLAGS  := -mcpu=cortex-m3 -march=armv7-m -mthumb		     \
		   -x assembler-with-cpp $(TARGET_FLAGS)
LDFLAGS  =  $(TARGET_LDFLAGS) -mcpu=cortex-m3 -mthumb -Xlinker \
            --gc-sections --print-gc-sections --march=armv7-m -Wall

##
## Build rules and useful templates
##

include $(MAKEDIR)/build-rules.mk
include $(MAKEDIR)/build-templates.mk

##
## Set all submodules here
##

# Try to keep LIBMAPLE_MODULES a simply-expanded variable
ifeq ($(LIBMAPLE_MODULES),)
	LIBMAPLE_MODULES := $(SRCROOT)/libmaple
else
	LIBMAPLE_MODULES += $(SRCROOT)/libmaple
endif
LIBMAPLE_MODULES += $(SRCROOT)/libmaple/usb   # The USB module is kept separate
LIBMAPLE_MODULES += $(LIBMAPLE_MODULE_SERIES) # STM32 series submodule in libmaple
LIBMAPLE_MODULES += $(SRCROOT)/wirish
# Official libraries:
# LIBMAPLE_MODULES += $(SRCROOT)/libraries/Servo
# LIBMAPLE_MODULES += $(SRCROOT)/libraries/LiquidCrystal
# LIBMAPLE_MODULES += $(SRCROOT)/libraries/Wire

# Experimental libraries:
# LIBMAPLE_MODULES += $(SRCROOT)/libraries/FreeRTOS

# Call each module's rules.mk:
$(foreach m,$(LIBMAPLE_MODULES),$(eval $(call LIBMAPLE_MODULE_template,$(m))))

##
## Targets
##

# main target
include $(SRCROOT)/build-targets.mk

.PHONY: install sketch clean help cscope tags ctags ram flash jtag doxygen mrproper list-boards

# Target upload commands
# USB ID for DFU upload -- FIXME: do something smarter with this
BOARD_USB_VENDOR_ID  := 1EAF
BOARD_USB_PRODUCT_ID := 0003
UPLOAD_ram   := $(SUPPORT_PATH)/scripts/reset.py && \
                sleep 1                  && \
                $(DFU) -a0 -d $(BOARD_USB_VENDOR_ID):$(BOARD_USB_PRODUCT_ID) -D $(BUILD_PATH)/$(BOARD).bin -R
UPLOAD_flash := $(SUPPORT_PATH)/scripts/reset.py && \
                sleep 1                  && \
                $(DFU) -a1 -d $(BOARD_USB_VENDOR_ID):$(BOARD_USB_PRODUCT_ID) -D $(BUILD_PATH)/$(BOARD).bin -R

# Conditionally upload to whatever the last build was
install: INSTALL_TARGET = $(shell cat $(BUILD_PATH)/build-type 2>/dev/null)
install: $(BUILD_PATH)/$(BOARD).bin
	@echo "Install target:" $(INSTALL_TARGET)
	$(UPLOAD_$(INSTALL_TARGET))

# Force a rebuild if the target changed
PREV_BUILD_TYPE = $(shell cat $(BUILD_PATH)/build-type 2>/dev/null)
build-check:
ifneq ($(PREV_BUILD_TYPE), $(MEMORY_TARGET))
	$(shell rm -rf $(BUILD_PATH))
endif

sketch: build-check MSG_INFO $(BUILD_PATH)/$(BOARD).bin

clean:
	rm -rf build

mrproper: clean
	rm -rf doxygen

help:
	@echo ""
	@echo "Basic usage (BOARD defaults to maple):"
	@echo "    $$ cp your-main.cpp main.cpp"
	@echo "    $$ make BOARD=your_board"
	@echo "    $$ make BOARD=your_board install"
	@echo ""
	@echo "(Multiple source files? Link with libmaple.a (\`$$ make library')"
	@echo "or hack build-targets.mk appropriately.)"
	@echo ""
	@echo "Important targets:"
	@echo "    sketch:   Compile for BOARD to MEMORY_TARGET (default)."
	@echo "    install:  Compile and upload over USB using Maple bootloader"
	@echo ""
	@echo "You *must* set BOARD if not compiling for Maple (e.g."
	@echo "use BOARD=maple_mini for mini, etc.), and MEMORY_TARGET"
	@echo "if not compiling to Flash. Run \`$$ make list-boards' for"
	@echo "a list of all boards."
	@echo ""
	@echo "Valid MEMORY_TARGETs (default=flash):"
	@echo "    ram:    Compile to RAM (doesn't touch Flash)"
	@echo "    flash:  Compile to Flash (for Maple bootloader)"
	@echo "    jtag:   Compile for JTAG/SWD upload (overwrites bootloader)"
	@echo ""
	@echo "Other targets:"
	@echo "    clean: Remove all build and object files"
	@echo "    doxygen: Build Doxygen HTML and XML documentation"
	@echo "    help: Show this message"
	@echo "    mrproper: Remove all generated files"
	@echo ""

cscope:
	rm -rf cscope.*
	find . -name '*.[hcS]' -o -name '*.cpp' | xargs cscope -b

tags:
	etags `find . -name "*.c" -o -name "*.cpp" -o -name "*.h"`
	@echo "Made TAGS file for EMACS code browsing"

ctags:
	ctags-exuberant -R .
	@echo "Made tags file for VIM code browsing"

ram:
	@$(MAKE) MEMORY_TARGET=ram --no-print-directory sketch

flash:
	@$(MAKE) MEMORY_TARGET=flash --no-print-directory sketch

jtag:
	@$(MAKE) MEMORY_TARGET=jtag --no-print-directory sketch

doxygen:
	doxygen $(SUPPORT_PATH)/doxygen/Doxyfile

# This output is kind of ugly, but I don't understand make very well.
list-boards:
	@echo " $(addsuffix "\\n",$(basename $(notdir $(wildcard $(BOARD_INCLUDE_DIR)/*.mk))))"