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))")
|
|
|
|
export RIOTBASE := $(abspath $(RIOTBASE))
|
2014-02-11 18:15:43 +01:00
|
|
|
|
2014-02-12 13:09:30 +01:00
|
|
|
RIOTCPU ?= $(RIOTBASE)/cpu
|
|
|
|
export RIOTCPU := $(abspath $(RIOTCPU))
|
|
|
|
|
|
|
|
RIOTBOARD ?= $(RIOTBASE)/boards
|
|
|
|
export RIOTBOARD := $(abspath $(RIOTBOARD))
|
2013-11-06 19:39:25 +01:00
|
|
|
|
2013-03-31 22:14:06 +02:00
|
|
|
ifeq ($(strip $(MCU)),)
|
|
|
|
MCU = $(CPU)
|
|
|
|
endif
|
2013-03-23 18:38:12 +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
|
|
|
|
|
2013-03-10 16:51:40 +01:00
|
|
|
# if you want to publish the board into the sources as an uppercase #define
|
2014-03-04 14:58:34 +01:00
|
|
|
BB = $(shell echo $(BOARD)|tr 'a-z' 'A-Z'|tr '-' '_')
|
|
|
|
CPUDEF = $(shell echo $(CPU)|tr 'a-z' 'A-Z'|tr '-' '_')
|
2014-03-04 15:52:44 +01:00
|
|
|
CFLAGS += -DBOARD_$(BB) -DCPU_$(CPUDEF)
|
2014-02-08 18:36:38 +01:00
|
|
|
|
2013-03-10 16:51:40 +01:00
|
|
|
export CFLAGS
|
|
|
|
|
2014-04-18 21:01:48 +02:00
|
|
|
export BINDIRBASE ?= $(CURDIR)/bin
|
|
|
|
export BINDIR ?= $(abspath $(BINDIRBASE)/$(BOARD))/
|
2013-12-21 15:02:53 +01:00
|
|
|
|
2014-01-05 11:33:34 +01:00
|
|
|
ifeq ($(QUIET),1)
|
|
|
|
AD=@
|
|
|
|
else
|
|
|
|
AD=
|
|
|
|
endif
|
|
|
|
export AD
|
|
|
|
|
2014-01-08 16:46:16 +01:00
|
|
|
BOARD := $(strip $(BOARD))
|
|
|
|
|
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-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
|
|
|
|
2013-03-10 16:51:40 +01:00
|
|
|
# your binaries to link
|
2013-12-24 13:20:25 +01:00
|
|
|
BASELIBS += $(BINDIR)$(BOARD)_base.a
|
|
|
|
BASELIBS += $(BINDIR)${PROJECT}.a
|
2014-01-28 17:58:39 +01:00
|
|
|
BASELIBS += $(USEPKG:%=${BINDIR}%.a)
|
2013-03-10 16:51:40 +01:00
|
|
|
|
2014-04-18 21:01:48 +02:00
|
|
|
.PHONY: all clean flash doc term objsize buildsize buildsizes buildsizes-diff
|
2013-08-08 15:44:44 +02:00
|
|
|
|
2014-02-10 15:28:55 +01:00
|
|
|
## make script for your application. Build RIOT-base here!
|
2013-12-24 13:20:25 +01:00
|
|
|
all: $(BINDIR)$(PROJECT).a
|
2014-02-10 15:28:55 +01:00
|
|
|
@echo "Building application $(PROJECT) for $(BOARD) w/ MCU $(MCU)."
|
2013-12-21 16:27:45 +01:00
|
|
|
"$(MAKE)" -C $(RIOTBOARD)/$(BOARD)
|
2013-08-06 18:58:24 +02:00
|
|
|
"$(MAKE)" -C $(RIOTBASE)
|
2014-02-11 18:15:43 +01:00
|
|
|
ifeq ($(BUILDOSXNATIVE),1)
|
2014-02-01 15:39:16 +01:00
|
|
|
$(AD)$(LINK) $(UNDEF) -o $(BINDIR)$(PROJECT).elf $(BASELIBS) $(LINKFLAGS) -Wl,-no_pie
|
2013-05-15 17:45:43 +02:00
|
|
|
else
|
2014-01-10 15:43:17 +01:00
|
|
|
$(AD)$(LINK) $(UNDEF) -o $(BINDIR)$(PROJECT).elf -Wl,--start-group $(BASELIBS) -lm -Wl,--end-group -Wl,-Map=$(BINDIR)$(PROJECT).map $(LINKFLAGS)
|
2014-02-01 15:39:16 +01:00
|
|
|
endif
|
2014-01-10 15:43:17 +01:00
|
|
|
$(AD)$(SIZE) $(BINDIR)$(PROJECT).elf
|
|
|
|
$(AD)$(OBJCOPY) $(OFLAGS) $(BINDIR)$(PROJECT).elf $(BINDIR)$(PROJECT).hex
|
2013-03-10 16:51:40 +01:00
|
|
|
|
|
|
|
## your make rules
|
2014-02-10 15:28:55 +01:00
|
|
|
## Only basic example - modify it for larger applications!!
|
2013-12-21 15:02:53 +01:00
|
|
|
#$(BINDIR)/$(PROJECT).a: $(BINDIR)/$(PROJECT).o
|
2014-02-11 18:15:43 +01:00
|
|
|
# $(AR) -rc $(BINDIR)/project.a $(BINDIR)/$(PROJECT).o
|
2013-04-22 00:55:11 +02:00
|
|
|
|
|
|
|
# string array of all names of c files in dir
|
|
|
|
SRC = $(wildcard *.c)
|
|
|
|
|
2014-02-11 18:15:43 +01:00
|
|
|
# string array of all names replaced .c with .o
|
2014-01-14 17:58:29 +01:00
|
|
|
OBJ = $(SRC:%.c=${BINDIR}${PROJECT}/%.o)
|
2013-04-22 00:55:11 +02:00
|
|
|
|
2014-01-28 21:12:55 +01:00
|
|
|
$(BINDIR)$(PROJECT).a: $(OBJ)
|
2014-01-03 19:00:41 +01:00
|
|
|
$(AD)$(AR) -rc $(BINDIR)$(PROJECT).a $(OBJ)
|
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-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)
|
|
|
|
|
2013-04-22 00:55:11 +02:00
|
|
|
# pull in dependency info for *existing* .o files
|
|
|
|
-include $(OBJ:.o=.d)
|
|
|
|
|
2014-01-28 21:12:55 +01:00
|
|
|
$(BINDIR)$(PROJECT)/%.o: %.c $(PROJDEPS) $(USEPKG:%=${BINDIR}%.a)
|
|
|
|
@mkdir -p ${BINDIR}
|
2013-04-22 00:55:11 +02:00
|
|
|
@echo; echo "Compiling.... $*.c"; echo
|
2014-01-14 17:58:29 +01:00
|
|
|
@test -d $(BINDIR)$(PROJECT) || mkdir -p $(BINDIR)$(PROJECT)
|
|
|
|
$(AD)$(CC) $(CFLAGS) $(INCLUDES) -c $*.c -o $(BINDIR)$(PROJECT)/$*.o
|
2013-03-10 16:51:40 +01:00
|
|
|
|
2014-01-28 21:12:55 +01:00
|
|
|
$(USEPKG:%=${BINDIR}%.a)::
|
|
|
|
@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
|
2013-12-21 15:02:53 +01:00
|
|
|
rm -rf $(BINDIR)
|
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:
|
2013-08-09 15:57:34 +02:00
|
|
|
$(TERMPROG) $(PORT)
|
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
|
|
|
|
|
|
|
buildtest:
|
2014-02-05 08:55:43 +01:00
|
|
|
@if [ -z "$${JENKINS_URL}" ] && tput colors 2>&1 > /dev/null; then \
|
|
|
|
GREEN='\033[1;32m'; RED='\033[1;31m'; RESET='\033[0m'; \
|
2014-04-09 12:40:58 +02:00
|
|
|
ECHO='/bin/echo -e'; \
|
2014-02-05 08:55:43 +01:00
|
|
|
else \
|
|
|
|
GREEN=''; RED=''; RESET=''; \
|
2014-04-09 12:40:58 +02:00
|
|
|
ECHO='/bin/echo'; \
|
2014-02-05 08:55:43 +01:00
|
|
|
fi; \
|
|
|
|
\
|
2014-01-21 14:05:56 +01:00
|
|
|
if [ -z "$(BOARD_WHITELIST)" ]; then \
|
|
|
|
BOARDS=$$(find $(RIOTBOARD) -mindepth 1 -maxdepth 1 -type d \! -name \*-common -printf '%f\n' ); \
|
|
|
|
else \
|
|
|
|
BOARDS="$(BOARD_WHITELIST)"; \
|
|
|
|
fi; \
|
|
|
|
\
|
|
|
|
for BOARD in $(BOARD_BLACKLIST); do \
|
|
|
|
echo "Ignoring $${BOARD} (blacklisted)"; \
|
|
|
|
BOARDS=$$(echo \ $${BOARDS}\ | sed -e 's/ '$${BOARD}' / /'); \
|
|
|
|
done; \
|
|
|
|
\
|
|
|
|
for BOARD in $${BOARDS}; do \
|
2014-02-05 08:55:43 +01:00
|
|
|
$${ECHO} -n "Building for $${BOARD} .. "; \
|
2014-03-03 10:31:55 +01:00
|
|
|
LOG=$$(env -i \
|
2014-02-05 08:53:54 +01:00
|
|
|
HOME=$${HOME} \
|
|
|
|
PATH=$${PATH} \
|
|
|
|
BOARD=$${BOARD} \
|
|
|
|
RIOTBASE=$${RIOTBASE} \
|
|
|
|
RIOTBOARD=$${RIOTBOARD} \
|
|
|
|
RIOTCPU=$${RIOTCPU} \
|
2014-04-18 21:01:48 +02:00
|
|
|
BINDIRBASE=$${BINDIRBASE} \
|
2014-03-03 10:31:55 +01:00
|
|
|
$(MAKE) -B clean all 2>&1 >/dev/null) ; \
|
2014-02-05 08:53:54 +01:00
|
|
|
if [ "$${?}" = "0" ]; then \
|
2014-02-05 08:55:43 +01:00
|
|
|
$${ECHO} "$${GREEN}success$${RESET}"; \
|
2014-02-05 08:53:54 +01:00
|
|
|
else \
|
2014-02-05 08:55:43 +01:00
|
|
|
$${ECHO} "$${RED}failed$${RESET}"; \
|
2014-03-03 10:31:55 +01:00
|
|
|
echo "$${LOG}" | grep -v -E '^make(\[[[:digit:]]])?:'; \
|
2014-02-05 08:56:15 +01:00
|
|
|
BUILDTESTFAILED=1; \
|
2014-02-05 08:53:54 +01:00
|
|
|
fi; \
|
|
|
|
done; \
|
2014-02-05 08:56:15 +01:00
|
|
|
if [ "$${BUILDTESTFAILED}" = "1" ]; then \
|
|
|
|
exit 1; \
|
|
|
|
fi
|
2014-04-18 18:23:27 +02:00
|
|
|
|
2014-04-18 18:49:11 +02:00
|
|
|
objsize:
|
|
|
|
@case "${SORTROW}" in \
|
|
|
|
text) SORTROW=1 ;; \
|
|
|
|
data) SORTROW=2 ;; \
|
|
|
|
bss) SORTROW=3 ;; \
|
|
|
|
dec) SORTROW=4 ;; \
|
|
|
|
"") SORTROW=4 ;; \
|
|
|
|
*) echo "Usage: $(MAKE) objsize SORTROW=[text|data|bss|dec]" ; return ;; \
|
|
|
|
esac; \
|
|
|
|
echo ' text\t data\t bss\t dec\t hex\tfilename'; \
|
|
|
|
$(SIZE) -dB $(BASELIBS) | \
|
|
|
|
tail -n+2 | \
|
|
|
|
sed -e 's#$(BINDIR)##' | \
|
|
|
|
sort -rnk$${SORTROW}
|
|
|
|
|
2014-04-18 18:23:27 +02:00
|
|
|
buildsize:
|
|
|
|
@$(SIZE) -dB $(BINDIR)$(PROJECT).elf
|
|
|
|
|
|
|
|
buildsizes: SHELL=bash
|
|
|
|
buildsizes:
|
|
|
|
@if [[ -z "$(BOARD_WHITELIST)" ]]; then \
|
|
|
|
BOARDS=$$(find $(RIOTBOARD) -mindepth 1 -maxdepth 1 -type d \! -name \*-common -printf '%f\n' ); \
|
|
|
|
else \
|
|
|
|
BOARDS="$(BOARD_WHITELIST)"; \
|
|
|
|
fi; \
|
|
|
|
for BOARD in $(BOARD_BLACKLIST); do \
|
|
|
|
BOARDS=$$(sed -e "s/ $${BOARD} / /" <<< " $${BOARDS} "); \
|
|
|
|
done; \
|
|
|
|
\
|
|
|
|
echo -e " text\t data\t bss\t dec\tboard"; \
|
|
|
|
for BOARD in $${BOARDS}; do \
|
|
|
|
echo "$$(env -i \
|
|
|
|
HOME=$${HOME} \
|
|
|
|
PATH=$${PATH} \
|
|
|
|
BOARD=$${BOARD} \
|
|
|
|
RIOTBASE=$${RIOTBASE} \
|
|
|
|
RIOTBOARD=$${RIOTBOARD} \
|
|
|
|
RIOTCPU=$${RIOTCPU} \
|
2014-04-18 21:01:48 +02:00
|
|
|
BINDIRBASE=$${BINDIRBASE} \
|
2014-04-18 18:23:27 +02:00
|
|
|
$(MAKE) buildsize 2>/dev/null | tail -n-1 | cut -f-4)" "$${BOARD}"; \
|
|
|
|
done;
|
2014-04-18 21:01:48 +02:00
|
|
|
|
|
|
|
buildsizes-diff: SHELL=bash
|
|
|
|
buildsizes-diff:
|
|
|
|
@if [[ -z "$(BOARD_WHITELIST)" ]]; then \
|
|
|
|
BOARDS=$$(find $(RIOTBOARD) -mindepth 1 -maxdepth 1 -type d \! -name \*-common -printf '%f\n' ); \
|
|
|
|
else \
|
|
|
|
BOARDS="$(BOARD_WHITELIST)"; \
|
|
|
|
fi; \
|
|
|
|
for BOARD in $(BOARD_BLACKLIST); do \
|
|
|
|
BOARDS=$$(sed -e "s/ $${BOARD} / /" <<< " $${BOARDS} "); \
|
|
|
|
done; \
|
|
|
|
\
|
|
|
|
GREEN='\033[1;32m'; RED='\033[1;31m'; RESET='\033[0m'; \
|
|
|
|
\
|
|
|
|
echo -e "text\tdata\tbss\tdec\tBOARD/BINDIRBASE\n"; \
|
|
|
|
for BOARD in $$(tr ' ' '\n' <<< $${BOARDS} | sort); do \
|
|
|
|
for BINDIRBASE in $${OLDBIN} $${NEWBIN}; do \
|
|
|
|
env -i \
|
|
|
|
HOME=$${HOME} \
|
|
|
|
PATH=$${PATH} \
|
|
|
|
BOARD=$${BOARD} \
|
|
|
|
RIOTBASE=$${RIOTBASE} \
|
|
|
|
RIOTBOARD=$${RIOTBOARD} \
|
|
|
|
RIOTCPU=$${RIOTCPU} \
|
|
|
|
BINDIRBASE=$${BINDIRBASE} \
|
|
|
|
$(MAKE) buildsize 2>/dev/null | tail -n-1 | cut -f-4; \
|
|
|
|
done | \
|
|
|
|
while read -a OLD && read -a NEW; do \
|
|
|
|
for I in 0 1 2 3; do \
|
|
|
|
if [[ -n "$${NEW[I]}" && -n "$${OLD[I]}" ]]; then \
|
|
|
|
DIFF=$$(($${NEW[I]} - $${OLD[I]})); \
|
|
|
|
if [[ "$${DIFF}" -gt 0 ]]; then echo -ne "$${RED}"; fi; \
|
|
|
|
if [[ "$${DIFF}" -lt 0 ]]; then echo -ne "$${GREEN}"; fi; \
|
|
|
|
else \
|
|
|
|
DIFF="$${RED}ERR"; \
|
|
|
|
fi; \
|
|
|
|
echo -ne "$${DIFF}\t$${RESET}"; \
|
|
|
|
done; \
|
|
|
|
echo "$${BOARD}"; \
|
|
|
|
for I in 0 1 2 3; do echo -ne "$${OLD[I]-$${RED}ERR$${RESET}}\t"; done; echo -e "$${OLDBIN}"; \
|
|
|
|
for I in 0 1 2 3; do echo -ne "$${NEW[I]-$${RED}ERR$${RESET}}\t"; done; echo -e "$${NEWBIN}\n"; \
|
|
|
|
done; \
|
|
|
|
done;
|