2014-06-18 11:00:33 +02:00
|
|
|
# Provide a shallow sanity check. You cannot call `make` in a module directory.
|
2014-05-15 17:12:42 +02:00
|
|
|
export __RIOTBUILD_FLAG := RIOT
|
|
|
|
|
2013-04-01 00:18:07 +02:00
|
|
|
# set undefined variables
|
2014-02-12 13:09:30 +01:00
|
|
|
RIOTBASE ?= $(shell dirname "$(lastword $(MAKEFILE_LIST))")
|
2014-05-05 21:53:37 +02:00
|
|
|
RIOTBASE := $(abspath $(RIOTBASE))
|
2014-02-11 18:15:43 +01:00
|
|
|
|
2014-02-12 13:09:30 +01:00
|
|
|
RIOTCPU ?= $(RIOTBASE)/cpu
|
2014-05-05 21:53:37 +02:00
|
|
|
RIOTCPU := $(abspath $(RIOTCPU))
|
2014-02-12 13:09:30 +01:00
|
|
|
|
|
|
|
RIOTBOARD ?= $(RIOTBASE)/boards
|
2014-05-05 21:53:37 +02:00
|
|
|
RIOTBOARD := $(abspath $(RIOTBOARD))
|
2013-11-06 19:39:25 +01:00
|
|
|
|
2014-01-21 14:05:56 +01:00
|
|
|
ifeq (,$(filter buildtest,$(MAKECMDGOALS)))
|
|
|
|
ifneq (,$(BOARD_WHITELIST))
|
|
|
|
ifeq (,$(filter $(BOARD),$(BOARD_WHITELIST)))
|
|
|
|
$(error This application only runs on following boards: $(BOARD_WHITELIST))
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2014-02-15 07:56:46 +01:00
|
|
|
ifneq (,$(filter $(BOARD),$(BOARD_BLACKLIST)))
|
2014-01-21 14:05:56 +01:00
|
|
|
$(error This application does not run on following boards: $(BOARD_BLACKLIST))
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2014-05-05 21:53:37 +02:00
|
|
|
BINDIRBASE ?= $(CURDIR)/bin
|
|
|
|
BINDIR ?= $(abspath $(BINDIRBASE)/$(BOARD))/
|
2013-12-21 15:02:53 +01:00
|
|
|
|
2014-01-05 11:33:34 +01:00
|
|
|
ifeq ($(QUIET),1)
|
|
|
|
AD=@
|
2014-06-18 11:00:33 +02:00
|
|
|
MAKEFLAGS += --no-print-directory
|
2014-01-05 11:33:34 +01:00
|
|
|
else
|
|
|
|
AD=
|
|
|
|
endif
|
|
|
|
|
2014-01-08 16:46:16 +01:00
|
|
|
BOARD := $(strip $(BOARD))
|
|
|
|
|
make: centralize wget/curl & unzip/7z feature test
With many open PRs that could benefit from loading SDKs when needed,
instead adding vast amounts of code to RIOTs master, this PR provides
the "functions" `$(DOWNLOAD_TO_STDOUT)`, `$(DOWNLOAD_TO_FILE)`, and
`$(UNZIP_HERE)`.
The first "function" takes one argument, the URL from where to download
the content. It is then piped to stdout. To be used e.g. with `tar xz`.
The second "function" taken two arguments, the destination file name,
and the source URL. If the previous invocation was interrupted, then the
download gets continued, if possible.
The last "function" takes one argument, the source ZIP file. The file
gets extracted into the cwd, so best use this "function" with
`cd $(SOME_WHERE) &&`.
The clumsy name `$(UNZIP_HERE)` is taken because the program "unzip"
takes the environment variable `UNZIP` as the source file, even if
another file name was given on the command line. The rationale for that
is that the hackers of "unzip" hate their users. Also they sacrifice
hamsters to Satan.
2014-07-16 00:29:18 +02:00
|
|
|
# provide common external programs for `Makefile.include`s
|
|
|
|
|
|
|
|
ifeq (,$(AXEL))
|
|
|
|
ifeq (0,$(shell which axel 2>&1 > /dev/null ; echo $$?))
|
|
|
|
AXEL := $(shell which axel)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
ifeq (,$(WGET))
|
|
|
|
ifeq (0,$(shell which wget 2>&1 > /dev/null ; echo $$?))
|
|
|
|
WGET := $(shell which wget)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
ifeq (,$(CURL))
|
|
|
|
ifeq (0,$(shell which curl 2>&1 > /dev/null ; echo $$?))
|
|
|
|
CURL := $(shell which curl)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
ifeq (,$(WGET)$(CURL))
|
|
|
|
$(error Neither wget nor curl is installed!)
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq (,$(DOWNLOAD_TO_STDOUT))
|
|
|
|
DOWNLOAD_TO_STDOUT := $(if $(CURL),$(CURL) -s,$(WGET) -q -O-)
|
|
|
|
endif
|
|
|
|
ifeq (,$(DOWNLOAD_TO_FILE))
|
|
|
|
ifneq (,$(AXEL))
|
|
|
|
DOWNLOAD_TO_FILE := $(AXEL) -n 4 -q -a -o
|
|
|
|
else
|
|
|
|
DOWNLOAD_TO_FILE := $(if $(WGET),$(WGET) -nv -c -O,$(CURL) -s -o)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq (,$(UNZIP_HERE))
|
|
|
|
ifeq (0,$(shell which unzip 2>&1 > /dev/null ; echo $$?))
|
|
|
|
UNZIP_HERE := $(shell which unzip) -q
|
|
|
|
else
|
|
|
|
ifeq (0,$(shell which 7z 2>&1 > /dev/null ; echo $$?))
|
|
|
|
UNZIP_HERE := $(shell which 7z) x -bd
|
|
|
|
else
|
|
|
|
$(error Neither unzip nor 7z is installed.)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2013-04-01 00:18:07 +02:00
|
|
|
# mandatory includes!
|
2013-12-24 14:50:26 +01:00
|
|
|
include $(RIOTBASE)/Makefile.modules
|
2013-03-10 16:51:40 +01:00
|
|
|
include $(RIOTBOARD)/$(BOARD)/Makefile.include
|
2013-12-22 20:02:59 +01:00
|
|
|
include $(RIOTCPU)/$(CPU)/Makefile.include
|
2014-02-07 21:24:42 +01:00
|
|
|
include $(RIOTBASE)/Makefile.dep
|
2013-03-10 16:51:40 +01:00
|
|
|
|
2014-08-01 02:33:22 +02:00
|
|
|
ifeq ($(strip $(MCU)),)
|
|
|
|
MCU = $(CPU)
|
|
|
|
endif
|
|
|
|
|
|
|
|
# if you want to publish the board into the sources as an uppercase #define
|
|
|
|
BOARDDEF := $(shell echo $(BOARD) | tr 'a-z' 'A-Z' | tr '-' '_')
|
|
|
|
CPUDEF := $(shell echo $(CPU) | tr 'a-z' 'A-Z' | tr '-' '_')
|
|
|
|
MCUDEF := $(shell echo $(MCU) | tr 'a-z' 'A-Z' | tr '-' '_')
|
|
|
|
CFLAGS += -DBOARD_$(BOARDDEF)='"$(BOARD)"' -DRIOT_BOARD=BOARD_$(BOARDDEF)
|
|
|
|
CFLAGS += -DCPU_$(CPUDEF)='"$(CPU)"' -DRIOT_CPU=CPU_$(CPUDEF)
|
|
|
|
CFLAGS += -DMCU_$(MCUDEF)='"$(MCU)"' -DRIOT_MCU=MCU_$(MCUDEF)
|
|
|
|
|
2014-06-19 13:13:06 +02:00
|
|
|
# OSX fails to create empty archives. Provide a wrapper to catch that error.
|
|
|
|
ifneq (0, $(shell mkdir -p $(BINDIR); $(AR) -rc $(BINDIR)empty-archive.a 2> /dev/null; echo $$?))
|
|
|
|
AR := $(RIOTBASE)/dist/ar-wrapper $(AR)
|
|
|
|
endif
|
|
|
|
|
2014-03-28 22:55:56 +01:00
|
|
|
# Test if there where dependencies against a module in DISABLE_MODULE.
|
|
|
|
ifneq (, $(filter $(DISABLE_MODULE), $(USEMODULE)))
|
|
|
|
$(error "Required modules were disabled using DISABLE_MODULE: $(sort $(filter $(DISABLE_MODULE), $(USEMODULE)))")
|
|
|
|
endif
|
|
|
|
|
2014-05-07 13:02:22 +02:00
|
|
|
# Feature test default CFLAGS and LINKFLAGS for the set compiled.
|
|
|
|
include $(RIOTBASE)/Makefile.cflags
|
2014-02-17 07:04:36 +01:00
|
|
|
|
2014-06-21 18:29:16 +02:00
|
|
|
# make the RIOT version available to the program
|
2014-07-27 13:44:52 +02:00
|
|
|
ifeq ($(origin RIOT_VERSION), undefined)
|
2014-07-30 15:33:07 +02:00
|
|
|
GIT_STRING := $(shell git describe --always --abbrev=4 --dirty=-`hostname` 2> /dev/null)
|
2014-07-27 13:44:52 +02:00
|
|
|
ifneq (,$(GIT_STRING))
|
|
|
|
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
|
|
|
|
ifeq ($(strip $(GIT_BRANCH)),master)
|
|
|
|
RIOT_VERSION := $(GIT_STRING)
|
|
|
|
else
|
|
|
|
RIOT_VERSION := $(GIT_STRING)-$(GIT_BRANCH)
|
|
|
|
endif
|
2014-07-10 21:48:22 +02:00
|
|
|
else
|
2014-07-30 15:44:31 +02:00
|
|
|
RIOT_VERSION := UNKNOWN (builddir: $(RIOTBASE))
|
2014-07-10 21:48:22 +02:00
|
|
|
endif
|
2014-06-21 18:29:16 +02:00
|
|
|
endif
|
2014-07-10 21:48:22 +02:00
|
|
|
export CFLAGS += -DRIOT_VERSION='"$(RIOT_VERSION)"'
|
2014-06-21 18:29:16 +02:00
|
|
|
|
2014-05-23 14:28:27 +02:00
|
|
|
# the binaries to link
|
2013-12-24 13:20:25 +01:00
|
|
|
BASELIBS += $(BINDIR)$(BOARD)_base.a
|
2014-05-23 10:33:02 +02:00
|
|
|
BASELIBS += $(BINDIR)${APPLICATION}.a
|
2014-01-28 17:58:39 +01:00
|
|
|
BASELIBS += $(USEPKG:%=${BINDIR}%.a)
|
2013-03-10 16:51:40 +01:00
|
|
|
|
2014-09-27 08:11:44 +02:00
|
|
|
.PHONY: all clean flash term doc debug debug-server reset objdump
|
2013-08-08 15:44:44 +02:00
|
|
|
|
2014-05-05 21:53:37 +02:00
|
|
|
ELFFILE ?= $(BINDIR)$(APPLICATION).elf
|
|
|
|
HEXFILE ?= $(ELFFILE:.elf=.hex)
|
2014-05-16 18:18:35 +02:00
|
|
|
|
2014-06-25 03:17:20 +02:00
|
|
|
# variables used to complie and link c++
|
2014-05-05 21:53:37 +02:00
|
|
|
CPPMIX ?= $(if $(wildcard *.cpp),1,)
|
2014-06-25 03:17:20 +02:00
|
|
|
|
2014-07-05 01:33:08 +02:00
|
|
|
# We assume $(LINK) to be gcc-like. Use `LINKFLAGPREFIX :=` for ld-like linker options.
|
|
|
|
LINKFLAGPREFIX ?= -Wl,
|
|
|
|
|
2014-05-23 10:33:02 +02:00
|
|
|
## make script for your application. Build RIOT-base here!
|
2014-06-18 11:00:33 +02:00
|
|
|
all: ..build-message $(USEPKG:%=${BINDIR}%.a) $(APPDEPS)
|
2014-06-18 11:21:05 +02:00
|
|
|
$(AD)DIRS="$(DIRS)" "$(MAKE)" -C $(CURDIR) -f $(RIOTBASE)/Makefile.application
|
2014-04-22 16:53:16 +02:00
|
|
|
ifeq (,$(RIOTNOLINK))
|
2014-05-16 18:18:35 +02:00
|
|
|
ifeq ($(BUILDOSXNATIVE),1)
|
2014-07-05 01:33:08 +02:00
|
|
|
$(AD)$(if $(CPPMIX),$(CXX),$(LINK)) $(UNDEF) -o $(ELFFILE) $(BASELIBS) $(LINKFLAGS) $(LINKFLAGPREFIX)-no_pie
|
2014-05-16 18:18:35 +02:00
|
|
|
else
|
2014-07-05 01:33:08 +02:00
|
|
|
$(AD)$(if $(CPPMIX),$(CXX),$(LINK)) $(UNDEF) -o $(ELFFILE) $(LINKFLAGPREFIX)--start-group $(BASELIBS) -lm $(LINKFLAGPREFIX)--end-group $(LINKFLAGPREFIX)-Map=$(BINDIR)$(APPLICATION).map $(LINKFLAGS)
|
2014-05-16 18:18:35 +02:00
|
|
|
endif
|
|
|
|
$(AD)$(SIZE) $(ELFFILE)
|
|
|
|
$(AD)$(OBJCOPY) $(OFLAGS) $(ELFFILE) $(HEXFILE)
|
2014-04-22 16:53:16 +02:00
|
|
|
endif
|
2013-03-10 16:51:40 +01:00
|
|
|
|
2014-06-18 11:00:33 +02:00
|
|
|
..build-message:
|
|
|
|
@echo "Building application $(APPLICATION) for $(BOARD) w/ MCU $(MCU)."
|
2013-04-22 00:55:11 +02:00
|
|
|
|
2014-02-26 23:23:15 +01:00
|
|
|
# add extra include paths for packages in $(USEMODULE)
|
|
|
|
export USEMODULE_INCLUDES =
|
|
|
|
|
|
|
|
include $(RIOTBASE)/sys/Makefile.include
|
|
|
|
include $(RIOTBASE)/drivers/Makefile.include
|
|
|
|
|
|
|
|
USEMODULE_INCLUDES_ = $(shell echo $(USEMODULE_INCLUDES) | tr ' ' '\n' | awk '!a[$$0]++' | tr '\n' ' ')
|
|
|
|
|
|
|
|
INCLUDES += $(USEMODULE_INCLUDES_:%=-I%)
|
|
|
|
|
2014-05-16 19:09:22 +02:00
|
|
|
# The `clean` needs to be serialized before everything else.
|
|
|
|
ifneq (, $(filter clean, $(MAKECMDGOALS)))
|
2014-06-18 11:00:33 +02:00
|
|
|
all $(BASELIBS) $(USEPKG:%=$(RIOTBASE)/pkg/%/Makefile.include): clean
|
2014-05-16 19:09:22 +02:00
|
|
|
endif
|
|
|
|
|
2014-01-28 21:12:55 +01:00
|
|
|
# include Makefile.includes for packages in $(USEPKG)
|
|
|
|
$(RIOTBASE)/pkg/%/Makefile.include::
|
|
|
|
$(AD)"$(MAKE)" -C $(RIOTBASE)/pkg/$* Makefile.include
|
|
|
|
|
|
|
|
.PHONY: $(USEPKG:%=$(RIOTBASE)/pkg/%/Makefile.include)
|
|
|
|
-include $(USEPKG:%=$(RIOTBASE)/pkg/%/Makefile.include)
|
|
|
|
|
2014-07-22 20:27:43 +02:00
|
|
|
.PHONY: $(USEPKG:%=${BINDIR}%.a)
|
2014-05-24 19:22:18 +02:00
|
|
|
$(USEPKG:%=${BINDIR}%.a):
|
2014-01-28 21:12:55 +01:00
|
|
|
@mkdir -p ${BINDIR}
|
|
|
|
"$(MAKE)" -C $(RIOTBASE)/pkg/$(patsubst ${BINDIR}%.a,%,$@)
|
|
|
|
|
2013-03-10 16:51:40 +01:00
|
|
|
clean:
|
2014-04-09 23:00:29 +02:00
|
|
|
@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTBASE)/pkg/$$i clean || exit 1; done
|
2014-05-03 15:06:08 +02:00
|
|
|
rm -rf $(BINDIR) $(CLEANFILES)
|
2013-03-10 16:51:40 +01:00
|
|
|
|
|
|
|
flash: all
|
2013-04-09 11:26:33 +02:00
|
|
|
$(FLASHER) $(FFLAGS)
|
2013-03-10 16:51:40 +01:00
|
|
|
|
|
|
|
term:
|
2014-08-10 05:20:57 +02:00
|
|
|
$(TERMPROG) $(TERMFLAGS)
|
2013-03-10 16:51:40 +01:00
|
|
|
|
|
|
|
doc:
|
|
|
|
make -BC $(RIOTBASE) doc
|
2013-07-12 12:31:16 +02:00
|
|
|
|
|
|
|
debug:
|
|
|
|
$(DEBUGGER) $(DEBUGGER_FLAGS)
|
2013-11-12 14:57:17 +01:00
|
|
|
|
2014-08-05 00:49:59 +02:00
|
|
|
debug-server:
|
|
|
|
$(DEBUGSERVER) $(DEBUGSERVER_FLAGS)
|
|
|
|
|
|
|
|
reset:
|
|
|
|
$(RESET) $(RESET_FLAGS)
|
|
|
|
|
2014-09-27 08:11:29 +02:00
|
|
|
objdump:
|
|
|
|
$(PREFIX)objdump -S -D -h $(ELFFILE) | less
|
|
|
|
|
2014-05-14 13:46:27 +02:00
|
|
|
# Extra make goals for testing and comparing changes.
|
|
|
|
include $(RIOTBASE)/Makefile.buildtests
|
2014-05-05 21:53:37 +02:00
|
|
|
|
|
|
|
# Export variables used throughout the whole make system:
|
|
|
|
include $(RIOTBASE)/Makefile.vars
|