mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
248a8531a5
Sometimes boards/*/Makefile.include (e. g. in case of the msba2) gets included twice somehow, leading the TERMFLAG to be set twice and faulty. This fixes that.
215 lines
6.3 KiB
Makefile
215 lines
6.3 KiB
Makefile
# Provide a shallow sanity check. You cannot call `make` in a module directory.
|
|
export __RIOTBUILD_FLAG := RIOT
|
|
|
|
# set undefined variables
|
|
RIOTBASE ?= $(shell dirname "$(lastword $(MAKEFILE_LIST))")
|
|
RIOTBASE := $(abspath $(RIOTBASE))
|
|
|
|
RIOTCPU ?= $(RIOTBASE)/cpu
|
|
RIOTCPU := $(abspath $(RIOTCPU))
|
|
|
|
RIOTBOARD ?= $(RIOTBASE)/boards
|
|
RIOTBOARD := $(abspath $(RIOTBOARD))
|
|
|
|
ifeq (,$(filter buildtest,$(MAKECMDGOALS)))
|
|
ifneq (,$(BOARD_WHITELIST))
|
|
ifeq (,$(filter $(BOARD),$(BOARD_WHITELIST)))
|
|
$(error This application only runs on following boards: $(BOARD_WHITELIST))
|
|
endif
|
|
endif
|
|
|
|
ifneq (,$(filter $(BOARD),$(BOARD_BLACKLIST)))
|
|
$(error This application does not run on following boards: $(BOARD_BLACKLIST))
|
|
endif
|
|
endif
|
|
|
|
BINDIRBASE ?= $(CURDIR)/bin
|
|
BINDIR ?= $(abspath $(BINDIRBASE)/$(BOARD))/
|
|
|
|
ifeq ($(QUIET),1)
|
|
AD=@
|
|
MAKEFLAGS += --no-print-directory
|
|
else
|
|
AD=
|
|
endif
|
|
|
|
BOARD := $(strip $(BOARD))
|
|
|
|
# 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
|
|
|
|
# mandatory includes!
|
|
include $(RIOTBASE)/Makefile.modules
|
|
include $(RIOTBOARD)/$(BOARD)/Makefile.include
|
|
include $(RIOTCPU)/$(CPU)/Makefile.include
|
|
include $(RIOTBASE)/Makefile.dep
|
|
|
|
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)
|
|
|
|
# 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
|
|
|
|
# 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
|
|
|
|
# Feature test default CFLAGS and LINKFLAGS for the set compiled.
|
|
include $(RIOTBASE)/Makefile.cflags
|
|
|
|
# make the RIOT version available to the program
|
|
ifeq ($(origin RIOT_VERSION), undefined)
|
|
GIT_STRING := $(shell git describe --always --abbrev=4 --dirty=-`hostname` 2> /dev/null)
|
|
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
|
|
else
|
|
RIOT_VERSION := UNKNOWN (builddir: $(RIOTBASE))
|
|
endif
|
|
endif
|
|
export CFLAGS += -DRIOT_VERSION='"$(RIOT_VERSION)"'
|
|
|
|
# the binaries to link
|
|
BASELIBS += $(BINDIR)$(BOARD)_base.a
|
|
BASELIBS += $(BINDIR)${APPLICATION}.a
|
|
BASELIBS += $(USEPKG:%=${BINDIR}%.a)
|
|
|
|
.PHONY: all clean flash doc term
|
|
|
|
ELFFILE ?= $(BINDIR)$(APPLICATION).elf
|
|
HEXFILE ?= $(ELFFILE:.elf=.hex)
|
|
|
|
# variables used to complie and link c++
|
|
CPPMIX ?= $(if $(wildcard *.cpp),1,)
|
|
|
|
# We assume $(LINK) to be gcc-like. Use `LINKFLAGPREFIX :=` for ld-like linker options.
|
|
LINKFLAGPREFIX ?= -Wl,
|
|
|
|
## make script for your application. Build RIOT-base here!
|
|
all: ..build-message $(USEPKG:%=${BINDIR}%.a) $(APPDEPS)
|
|
$(AD)DIRS="$(DIRS)" "$(MAKE)" -C $(CURDIR) -f $(RIOTBASE)/Makefile.application
|
|
ifeq (,$(RIOTNOLINK))
|
|
ifeq ($(BUILDOSXNATIVE),1)
|
|
$(AD)$(if $(CPPMIX),$(CXX),$(LINK)) $(UNDEF) -o $(ELFFILE) $(BASELIBS) $(LINKFLAGS) $(LINKFLAGPREFIX)-no_pie
|
|
else
|
|
$(AD)$(if $(CPPMIX),$(CXX),$(LINK)) $(UNDEF) -o $(ELFFILE) $(LINKFLAGPREFIX)--start-group $(BASELIBS) -lm $(LINKFLAGPREFIX)--end-group $(LINKFLAGPREFIX)-Map=$(BINDIR)$(APPLICATION).map $(LINKFLAGS)
|
|
endif
|
|
$(AD)$(SIZE) $(ELFFILE)
|
|
$(AD)$(OBJCOPY) $(OFLAGS) $(ELFFILE) $(HEXFILE)
|
|
endif
|
|
|
|
..build-message:
|
|
@echo "Building application $(APPLICATION) for $(BOARD) w/ MCU $(MCU)."
|
|
|
|
# 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%)
|
|
|
|
# The `clean` needs to be serialized before everything else.
|
|
ifneq (, $(filter clean, $(MAKECMDGOALS)))
|
|
all $(BASELIBS) $(USEPKG:%=$(RIOTBASE)/pkg/%/Makefile.include): clean
|
|
endif
|
|
|
|
# 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)
|
|
|
|
.PHONY: $(USEPKG:%=${BINDIR}%.a)
|
|
$(USEPKG:%=${BINDIR}%.a):
|
|
@mkdir -p ${BINDIR}
|
|
"$(MAKE)" -C $(RIOTBASE)/pkg/$(patsubst ${BINDIR}%.a,%,$@)
|
|
|
|
clean:
|
|
@for i in $(USEPKG) ; do "$(MAKE)" -C $(RIOTBASE)/pkg/$$i clean || exit 1; done
|
|
rm -rf $(BINDIR) $(CLEANFILES)
|
|
|
|
flash: all
|
|
$(FLASHER) $(FFLAGS)
|
|
|
|
term:
|
|
$(TERMPROG) $(TERMFLAGS)
|
|
|
|
doc:
|
|
make -BC $(RIOTBASE) doc
|
|
|
|
debug:
|
|
$(DEBUGGER) $(DEBUGGER_FLAGS)
|
|
|
|
debug-server:
|
|
$(DEBUGSERVER) $(DEBUGSERVER_FLAGS)
|
|
|
|
reset:
|
|
$(RESET) $(RESET_FLAGS)
|
|
|
|
# Extra make goals for testing and comparing changes.
|
|
include $(RIOTBASE)/Makefile.buildtests
|
|
|
|
# Export variables used throughout the whole make system:
|
|
include $(RIOTBASE)/Makefile.vars
|