aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile325
1 files changed, 197 insertions, 128 deletions
diff --git a/Makefile b/Makefile
index 5255525..c632ee8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,134 +1,203 @@
-# Makefile for LeafLabs documentation (automatically generated by
-# Sphinx).
+# 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
+LIBRARIES_PATH := $(SRCROOT)/libraries
+# 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
+
+# Chooses the bootloader, available: maple and robotis
+BOOTLOADER ?= maple
+
+# This is the serial port used by robotis bootloader
+ROBOTIS_PORT ?= /dev/ttyACM0
+
+# $(BOARD)- and $(MEMORY_TARGET)-specific configuration
+include $(MAKEDIR)/target-config.mk
+
+##
+## Build rules and useful templates
+##
+
+include $(MAKEDIR)/build-rules.mk
+include $(MAKEDIR)/build-templates.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
+TARGET_FLAGS += -I$(LIBRARIES_PATH) # for internal lib. includes, e.g. <Wire/WireBase.h>
+GLOBAL_CFLAGS := -Os -g3 -gdwarf-2 -nostdlib \
+ -ffunction-sections -fdata-sections \
+ -Wl,--gc-sections $(TARGET_FLAGS) \
+ -DBOOTLOADER_$(BOOTLOADER)
+GLOBAL_CXXFLAGS := -fno-rtti -fno-exceptions -Wall $(TARGET_FLAGS)
+GLOBAL_ASFLAGS := -x assembler-with-cpp $(TARGET_FLAGS)
+LDFLAGS = $(TARGET_LDFLAGS) $(TOOLCHAIN_LDFLAGS) -mcpu=cortex-m3 -mthumb \
+ -Xlinker --gc-sections \
+ -Xassembler --march=armv7-m -Wall
+# -Xlinker --print-gc-sections \
+
+##
+## Set all submodules here
+##
+
+LIBMAPLE_MODULES += $(SRCROOT)/libmaple
+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
+
+# User modules:
+ifneq ($(USER_MODULES),)
+LIBMAPLE_MODULES += $(USER_MODULES)
+endif
+
+# 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
+
+ifeq ($(BOOTLOADER),maple)
+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
+endif
+
+ifeq ($(BOOTLOADER),robotis)
+UPLOAD_flash := $(SUPPORT_PATH)/scripts/robotis-loader.py $(ROBOTIS_PORT) $(BUILD_PATH)/$(BOARD).bin
+endif
+
+# 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
-# You can set these variables from the command line.
-SPHINXOPTS =
-SPHINXBUILD = sphinx-build
-PAPER =
-BUILDDIR = build
-
-# Internal variables.
-PAPEROPT_a4 = -D latex_paper_size=a4
-PAPEROPT_letter = -D latex_paper_size=letter
-ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
+clean:
+ rm -rf build
-.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest
+mrproper: clean
+ rm -rf doxygen
help:
- @echo "Please use \`make <target>' where <target> is one of"
- @echo " html to make standalone HTML files"
- @echo " dirhtml to make HTML files named index.html in directories"
- @echo " singlehtml to make a single large HTML file"
- @echo " pickle to make pickle files"
- @echo " json to make JSON files"
- @echo " htmlhelp to make HTML files and a HTML help project"
- @echo " qthelp to make HTML files and a qthelp project"
- @echo " devhelp to make HTML files and a Devhelp project"
- @echo " epub to make an epub"
- @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
- @echo " latexpdf to make LaTeX files and run them through pdflatex"
- @echo " text to make text files"
- @echo " man to make manual pages"
- @echo " changes to make an overview of all changed/added/deprecated items"
- @echo " linkcheck to check all external links for integrity"
- @echo " doctest to run all doctests embedded in the documentation (if enabled)"
-
-clean:
- -rm -rf $(BUILDDIR)/*
-
-html:
- $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
- @echo
- @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
-
-dirhtml:
- $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
- @echo
- @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
-
-singlehtml:
- $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
- @echo
- @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
-
-pickle:
- $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
- @echo
- @echo "Build finished; now you can process the pickle files."
-
-json:
- $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
- @echo
- @echo "Build finished; now you can process the JSON files."
-
-htmlhelp:
- $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
- @echo
- @echo "Build finished; now you can run HTML Help Workshop with the" \
- ".hhp project file in $(BUILDDIR)/htmlhelp."
-
-qthelp:
- $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
- @echo
- @echo "Build finished; now you can run "qcollectiongenerator" with the" \
- ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
- @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/libmaple.qhcp"
- @echo "To view the help file:"
- @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/libmaple.qhc"
-
-devhelp:
- $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
- @echo
- @echo "Build finished."
- @echo "To view the help file:"
- @echo "# mkdir -p $$HOME/.local/share/devhelp/libmaple"
- @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/libmaple"
- @echo "# devhelp"
-
-epub:
- $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
- @echo
- @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
-
-latex:
- $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
- @echo
- @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
- @echo "Run \`make' in that directory to run these through (pdf)latex" \
- "(use \`make latexpdf' here to do that automatically)."
-
-latexpdf:
- $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
- @echo "Running LaTeX files through pdflatex..."
- make -C $(BUILDDIR)/latex all-pdf
- @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
-
-text:
- $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
- @echo
- @echo "Build finished. The text files are in $(BUILDDIR)/text."
-
-man:
- $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
- @echo
- @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
-
-changes:
- $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
- @echo
- @echo "The overview file is in $(BUILDDIR)/changes."
-
-linkcheck:
- $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
- @echo
- @echo "Link check complete; look for any errors in the above output " \
- "or in $(BUILDDIR)/linkcheck/output.txt."
-
-doctest:
- $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
- @echo "Testing of doctests in the sources finished, look at the " \
- "results in $(BUILDDIR)/doctest/output.txt."
+ @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:
- @echo "Wrong! You need to run this from within libmaple!"
- false
+ 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))))"