2012-02-10 16:51:35 +00:00
|
|
|
# -*- makefile -*-
|
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
ifndef CONTIKI
|
2013-02-10 23:28:31 +00:00
|
|
|
${error CONTIKI not defined! You must specify where Contiki resides}
|
2006-06-17 22:41:10 +00:00
|
|
|
endif
|
|
|
|
|
2017-06-21 09:11:09 +00:00
|
|
|
# Enable Werror by default. To disable from command line, use make WERROR=0.
|
|
|
|
# Setting this option is also important for tests on Cooja motes to check for warnings.
|
|
|
|
WERROR ?= 1
|
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
ifeq ($(TARGET),)
|
|
|
|
-include Makefile.target
|
|
|
|
ifeq ($(TARGET),)
|
2008-10-14 20:31:46 +00:00
|
|
|
${info TARGET not defined, using target 'native'}
|
|
|
|
TARGET=native
|
2006-06-17 22:41:10 +00:00
|
|
|
else
|
2007-12-24 15:24:15 +00:00
|
|
|
${info using saved target '$(TARGET)'}
|
2006-06-17 22:41:10 +00:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2007-12-24 15:24:15 +00:00
|
|
|
ifeq ($(DEFINES),)
|
|
|
|
-include Makefile.$(TARGET).defines
|
2008-01-04 21:01:37 +00:00
|
|
|
ifneq ($(DEFINES),)
|
|
|
|
${info using saved defines '$(DEFINES)'}
|
|
|
|
endif
|
2007-12-24 15:24:15 +00:00
|
|
|
endif
|
|
|
|
|
2012-02-21 23:57:22 +00:00
|
|
|
ifndef HOST_OS
|
|
|
|
ifeq ($(OS),Windows_NT)
|
2012-02-24 10:21:48 +00:00
|
|
|
## TODO: detect more specific Windows set-ups,
|
|
|
|
## e.g. CygWin, MingW, VisualC, Watcom, Interix
|
2012-02-21 23:57:22 +00:00
|
|
|
HOST_OS := Windows
|
|
|
|
else
|
|
|
|
HOST_OS := $(shell uname)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2014-10-14 08:03:28 +00:00
|
|
|
#More debug information when running in CI
|
|
|
|
ifdef CI
|
|
|
|
ifeq ($(CI),true)
|
|
|
|
V = 1
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
usage:
|
2006-08-31 09:36:29 +00:00
|
|
|
@echo "make MAKETARGETS... [TARGET=(TARGET)] [savetarget] [targets]"
|
|
|
|
|
|
|
|
targets:
|
2017-09-01 14:16:16 +00:00
|
|
|
@ls -1 $(CONTIKI)/arch/platform $(TARGETDIRS)
|
2006-06-17 22:41:10 +00:00
|
|
|
|
|
|
|
savetarget:
|
|
|
|
-@rm -f Makefile.target
|
2007-12-24 15:24:15 +00:00
|
|
|
@echo "saving Makefile.target"
|
2006-06-17 22:41:10 +00:00
|
|
|
@echo >Makefile.target "TARGET = $(TARGET)"
|
2017-09-01 14:16:16 +00:00
|
|
|
ifneq ($(BOARD),)
|
|
|
|
@echo >>Makefile.target "BOARD = $(BOARD)"
|
|
|
|
endif
|
2006-06-17 22:41:10 +00:00
|
|
|
|
2007-12-24 15:24:15 +00:00
|
|
|
savedefines:
|
|
|
|
-@rm -f Makefile.$(TARGET).defines
|
|
|
|
@echo "saving Makefile.$(TARGET).defines"
|
|
|
|
@echo >Makefile.$(TARGET).defines "DEFINES = $(DEFINES)"
|
|
|
|
|
2008-11-14 21:37:45 +00:00
|
|
|
OBJECTDIR = obj_$(TARGET)
|
2006-06-17 22:41:10 +00:00
|
|
|
|
2017-09-01 14:16:16 +00:00
|
|
|
LOWERCASE = -abcdefghijklmnopqrstuvwxyz/
|
|
|
|
UPPERCASE = _ABCDEFGHIJKLMNOPQRSTUVWXYZ_
|
2013-03-16 07:48:36 +00:00
|
|
|
TARGET_UPPERCASE := ${strip ${shell echo $(TARGET) | sed y!$(LOWERCASE)!$(UPPERCASE)!}}
|
2010-10-24 22:31:17 +00:00
|
|
|
CFLAGS += -DCONTIKI=1 -DCONTIKI_TARGET_$(TARGET_UPPERCASE)=1
|
2017-09-01 14:16:16 +00:00
|
|
|
ifneq ($(BOARD),)
|
|
|
|
TARGET_BOARD_UPPERCASE := ${strip ${shell echo $(BOARD) | sed y!$(LOWERCASE)!$(UPPERCASE)!}}
|
|
|
|
CFLAGS += -DCONTIKI_BOARD_$(TARGET_BOARD_UPPERCASE)=1
|
|
|
|
endif
|
2008-11-14 21:37:45 +00:00
|
|
|
|
2017-09-01 18:04:53 +00:00
|
|
|
MODULES += os os/sys os/dev os/lib os/services
|
2013-11-28 13:05:29 +00:00
|
|
|
|
2017-06-22 16:27:04 +00:00
|
|
|
# Include IPv6, RPL
|
2014-11-12 09:18:29 +00:00
|
|
|
|
|
|
|
HAS_STACK = 0
|
|
|
|
|
|
|
|
# Make IPv6 the default stack
|
|
|
|
ifeq ($(HAS_STACK),0)
|
|
|
|
ifneq ($(CONTIKI_WITH_IPV6),0)
|
|
|
|
CONTIKI_WITH_IPV6 = 1
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(CONTIKI_WITH_IPV6),1)
|
2014-12-01 20:02:57 +00:00
|
|
|
CFLAGS += -DNETSTACK_CONF_WITH_IPV6=1
|
2017-06-10 12:35:39 +00:00
|
|
|
CONTIKI_WITH_RPL ?= 1
|
|
|
|
CONTIKI_WITH_RPL_LITE ?= 1
|
2017-09-01 13:29:00 +00:00
|
|
|
MODULES += os/net/ipv6 os/net/ip
|
2014-12-02 10:29:49 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(CONTIKI_WITH_RPL),1)
|
2014-11-12 09:18:29 +00:00
|
|
|
CFLAGS += -DUIP_CONF_IPV6_RPL=1
|
2017-06-10 12:35:39 +00:00
|
|
|
ifeq ($(CONTIKI_WITH_RPL_LITE),1)
|
|
|
|
CFLAGS += -DUIP_CONF_IPV6_RPL_LITE=1
|
2017-09-01 13:29:00 +00:00
|
|
|
MODULES += os/net/rpl-lite
|
2017-06-10 12:35:39 +00:00
|
|
|
else
|
2017-09-10 13:10:55 +00:00
|
|
|
MODULES += os/net/rpl-classic
|
2017-06-10 12:35:39 +00:00
|
|
|
endif
|
2014-12-02 10:29:49 +00:00
|
|
|
else
|
|
|
|
CFLAGS += -DUIP_CONF_IPV6_RPL=0
|
2014-11-12 09:18:29 +00:00
|
|
|
endif
|
|
|
|
|
2017-09-02 07:16:32 +00:00
|
|
|
MODULES += os os/net os/net/mac os/storage
|
2006-06-17 22:41:10 +00:00
|
|
|
|
2007-04-21 15:13:14 +00:00
|
|
|
oname = ${patsubst %.c,%.o,${patsubst %.S,%.o,$(1)}}
|
2006-12-31 13:54:24 +00:00
|
|
|
|
2007-04-21 15:13:14 +00:00
|
|
|
CONTIKI_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CONTIKI_SOURCEFILES)}}
|
2007-04-21 14:56:52 +00:00
|
|
|
|
2007-04-21 15:13:14 +00:00
|
|
|
PROJECT_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(PROJECT_SOURCEFILES)}}
|
2006-06-17 22:41:10 +00:00
|
|
|
|
2013-06-20 22:45:41 +00:00
|
|
|
# Provide way to create $(OBJECTDIR) if it has been removed by make clean
|
|
|
|
$(OBJECTDIR):
|
|
|
|
mkdir $@
|
|
|
|
|
2013-12-02 09:30:56 +00:00
|
|
|
uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
|
|
|
|
|
2009-03-17 20:08:56 +00:00
|
|
|
### Include target makefile (TODO Unsafe?)
|
2009-07-02 22:36:04 +00:00
|
|
|
|
2017-06-28 13:57:13 +00:00
|
|
|
target_makefile := $(wildcard $(CONTIKI)/arch/platform/$(TARGET)/Makefile.$(TARGET) ${foreach TDIR, $(TARGETDIRS), $(TDIR)/$(TARGET)/Makefile.$(TARGET)})
|
2009-03-17 20:08:56 +00:00
|
|
|
|
2011-03-10 19:59:21 +00:00
|
|
|
# Check if the target makefile exists, and create the object directory if necessary.
|
2009-03-17 20:08:56 +00:00
|
|
|
ifeq ($(strip $(target_makefile)),)
|
|
|
|
${error The target platform "$(TARGET)" does not exist (maybe it was misspelled?)}
|
|
|
|
else
|
2012-02-10 15:57:37 +00:00
|
|
|
ifneq (1, ${words $(target_makefile)})
|
|
|
|
${error More than one TARGET Makefile found: $(target_makefile)}
|
|
|
|
endif
|
|
|
|
include $(target_makefile)
|
2009-03-17 20:08:56 +00:00
|
|
|
endif
|
|
|
|
|
2013-11-22 08:46:11 +00:00
|
|
|
ifdef MODULES
|
2013-12-02 09:30:56 +00:00
|
|
|
UNIQUEMODULES = $(call uniq,$(MODULES))
|
|
|
|
MODULEDIRS = ${wildcard ${addprefix $(CONTIKI)/, $(UNIQUEMODULES)}}
|
2013-12-12 19:02:32 +00:00
|
|
|
MODULES_SOURCES = ${foreach d, $(MODULEDIRS), ${subst ${d}/,,${wildcard $(d)/*.c}}}
|
2017-09-01 14:17:07 +00:00
|
|
|
MODULES_INCLUDES = ${wildcard ${foreach d, $(MODULEDIRS), $(d)/Makefile.${notdir $(d)}}}
|
|
|
|
-include $(MODULE_INCLUDES)
|
2013-11-22 08:46:11 +00:00
|
|
|
CONTIKI_SOURCEFILES += $(MODULES_SOURCES)
|
|
|
|
endif
|
|
|
|
|
2013-07-29 18:34:07 +00:00
|
|
|
### Verbosity control. Use make V=1 to get verbose builds.
|
|
|
|
|
|
|
|
ifeq ($(V),1)
|
|
|
|
TRACE_CC =
|
|
|
|
TRACE_LD =
|
|
|
|
TRACE_AR =
|
|
|
|
TRACE_AS =
|
|
|
|
Q=
|
|
|
|
else
|
|
|
|
TRACE_CC = @echo " CC " $<
|
|
|
|
TRACE_LD = @echo " LD " $@
|
|
|
|
TRACE_AR = @echo " AR " $@
|
|
|
|
TRACE_AS = @echo " AS " $<
|
|
|
|
Q=@
|
|
|
|
endif
|
2013-03-17 22:24:03 +00:00
|
|
|
|
2007-12-21 10:16:45 +00:00
|
|
|
### Forward comma-separated list of arbitrary defines to the compiler
|
|
|
|
|
|
|
|
COMMA := ,
|
|
|
|
CFLAGS += ${addprefix -D,${subst $(COMMA), ,$(DEFINES)}}
|
|
|
|
|
2007-05-19 07:54:53 +00:00
|
|
|
### Setup directory search path for source and header files
|
2007-05-13 08:41:11 +00:00
|
|
|
|
2012-02-10 15:57:37 +00:00
|
|
|
CONTIKI_TARGET_DIRS_CONCAT = ${addprefix ${dir $(target_makefile)}, \
|
2007-05-13 08:41:11 +00:00
|
|
|
$(CONTIKI_TARGET_DIRS)}
|
|
|
|
CONTIKI_CPU_DIRS_CONCAT = ${addprefix $(CONTIKI_CPU)/, \
|
|
|
|
$(CONTIKI_CPU_DIRS)}
|
2017-06-28 13:57:13 +00:00
|
|
|
CONTIKI_ARCH_DIRS = ${addprefix $(CONTIKI)/, arch}
|
2007-05-13 08:41:11 +00:00
|
|
|
|
2017-06-28 13:57:13 +00:00
|
|
|
SOURCEDIRS = . $(PROJECTDIRS) $(CONTIKI_TARGET_DIRS_CONCAT) $(CONTIKI_ARCH_DIRS) \
|
2017-09-01 14:52:06 +00:00
|
|
|
$(CONTIKI_CPU_DIRS_CONCAT) $(CONTIKIDIRS) $(MODULEDIRS) $(EXTERNALDIRS) ${dir $(target_makefile)}
|
2007-05-13 08:41:11 +00:00
|
|
|
|
|
|
|
vpath %.c $(SOURCEDIRS)
|
|
|
|
vpath %.S $(SOURCEDIRS)
|
|
|
|
|
2013-11-28 13:54:07 +00:00
|
|
|
CFLAGS += ${addprefix -I,$(SOURCEDIRS) $(CONTIKI)}
|
2007-05-19 07:54:53 +00:00
|
|
|
|
2011-07-16 12:53:44 +00:00
|
|
|
### Check for a git repo and pass version if found
|
|
|
|
### git.exe in Windows cmd shells may require no stderr redirection
|
2014-10-14 08:00:28 +00:00
|
|
|
ifndef RELSTR
|
|
|
|
RELSTR:=${shell git --git-dir ${CONTIKI}/.git describe --tags --always}
|
|
|
|
endif
|
|
|
|
|
2011-07-16 12:53:44 +00:00
|
|
|
ifneq ($(RELSTR),)
|
|
|
|
CFLAGS += -DCONTIKI_VERSION_STRING=\"Contiki-$(RELSTR)\"
|
2017-05-18 10:03:50 +00:00
|
|
|
else
|
|
|
|
CFLAGS += -DCONTIKI_VERSION_STRING=\"Contiki-3.x\"
|
2011-07-16 12:53:44 +00:00
|
|
|
endif
|
|
|
|
|
2006-06-17 22:41:10 +00:00
|
|
|
### Automatic dependency generation
|
|
|
|
|
|
|
|
ifneq ($(MAKECMDGOALS),clean)
|
2007-04-14 18:37:06 +00:00
|
|
|
-include ${addprefix $(OBJECTDIR)/,$(CONTIKI_SOURCEFILES:.c=.d) \
|
2013-02-10 23:28:31 +00:00
|
|
|
$(PROJECT_SOURCEFILES:.c=.d)}
|
2006-06-17 22:41:10 +00:00
|
|
|
endif
|
|
|
|
|
2009-07-02 22:36:04 +00:00
|
|
|
### See http://make.paulandlesley.org/autodep.html#advanced
|
|
|
|
|
|
|
|
define FINALIZE_DEPENDENCY
|
|
|
|
cp $(@:.o=.d) $(@:.o=.$$$$); \
|
|
|
|
sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
|
|
|
|
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.$$$$) >> $(@:.o=.d); \
|
|
|
|
rm -f $(@:.o=.$$$$)
|
|
|
|
endef
|
|
|
|
|
2013-06-20 17:20:50 +00:00
|
|
|
clean:
|
2013-11-13 20:15:46 +00:00
|
|
|
-rm -f *~ *core core *.srec \
|
2006-06-17 22:41:10 +00:00
|
|
|
*.lst *.map \
|
2013-02-10 23:28:31 +00:00
|
|
|
*.cprg *.bin *.data contiki*.a *.firmware core-labels.S *.ihex *.ini \
|
2013-06-20 17:20:50 +00:00
|
|
|
*.ce *.co
|
|
|
|
rm -rf $(CLEAN)
|
2006-06-17 22:41:10 +00:00
|
|
|
-rm -rf $(OBJECTDIR)
|
|
|
|
|
2013-07-26 15:57:14 +00:00
|
|
|
distclean: clean
|
2014-03-18 10:22:27 +00:00
|
|
|
-rm -f ${addsuffix .$(TARGET),$(CONTIKI_PROJECT)}
|
2013-07-26 15:57:14 +00:00
|
|
|
|
2017-06-28 13:57:13 +00:00
|
|
|
-include $(CONTIKI)/arch/platform/$(TARGET)/Makefile.customrules-$(TARGET)
|
2013-12-09 13:56:45 +00:00
|
|
|
|
2006-06-26 02:01:30 +00:00
|
|
|
ifndef CUSTOM_RULE_C_TO_CE
|
2006-06-17 22:41:10 +00:00
|
|
|
%.ce: %.c
|
2013-07-29 18:34:07 +00:00
|
|
|
$(TRACE_CC)
|
|
|
|
$(Q)$(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@
|
2006-06-17 22:41:10 +00:00
|
|
|
$(STRIP) --strip-unneeded -g -x $@
|
2006-06-26 02:01:30 +00:00
|
|
|
endif
|
2006-06-17 22:41:10 +00:00
|
|
|
|
2006-06-26 02:01:30 +00:00
|
|
|
ifndef CUSTOM_RULE_C_TO_OBJECTDIR_O
|
2013-06-20 22:45:41 +00:00
|
|
|
$(OBJECTDIR)/%.o: %.c | $(OBJECTDIR)
|
2013-07-29 18:34:07 +00:00
|
|
|
$(TRACE_CC)
|
|
|
|
$(Q)$(CC) $(CFLAGS) -MMD -c $< -o $@
|
2009-07-02 22:36:04 +00:00
|
|
|
@$(FINALIZE_DEPENDENCY)
|
2006-06-26 02:01:30 +00:00
|
|
|
endif
|
2006-06-17 22:41:10 +00:00
|
|
|
|
2007-08-30 20:42:58 +00:00
|
|
|
ifndef CUSTOM_RULE_S_TO_OBJECTDIR_O
|
2013-06-20 22:45:41 +00:00
|
|
|
$(OBJECTDIR)/%.o: %.S | $(OBJECTDIR)
|
2013-07-29 18:34:07 +00:00
|
|
|
$(TRACE_AS)
|
|
|
|
$(Q)$(AS) $(ASFLAGS) -o $@ $<
|
2007-08-30 20:42:58 +00:00
|
|
|
endif
|
|
|
|
|
2006-06-26 02:01:30 +00:00
|
|
|
ifndef CUSTOM_RULE_C_TO_O
|
2006-06-17 22:41:10 +00:00
|
|
|
%.o: %.c
|
2013-07-29 18:34:07 +00:00
|
|
|
$(TRACE_CC)
|
|
|
|
$(Q)$(CC) $(CFLAGS) -c $< -o $@
|
2006-06-26 02:01:30 +00:00
|
|
|
endif
|
2006-06-17 22:41:10 +00:00
|
|
|
|
2013-07-29 18:34:07 +00:00
|
|
|
|
2006-06-26 02:01:30 +00:00
|
|
|
ifndef CUSTOM_RULE_C_TO_CO
|
2006-06-17 22:41:10 +00:00
|
|
|
%.co: %.c
|
2013-07-29 18:34:07 +00:00
|
|
|
$(TRACE_CC)
|
|
|
|
$(Q)$(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@
|
2006-06-26 02:01:30 +00:00
|
|
|
endif
|
2006-06-17 22:41:10 +00:00
|
|
|
|
2006-06-26 02:01:30 +00:00
|
|
|
ifndef AROPTS
|
|
|
|
AROPTS = rcf
|
|
|
|
endif
|
2006-06-17 22:41:10 +00:00
|
|
|
|
2006-06-26 02:01:30 +00:00
|
|
|
ifndef CUSTOM_RULE_ALLOBJS_TO_TARGETLIB
|
2006-12-31 13:54:24 +00:00
|
|
|
contiki-$(TARGET).a: $(CONTIKI_OBJECTFILES)
|
2013-07-29 18:34:07 +00:00
|
|
|
$(TRACE_AR)
|
|
|
|
$(Q)$(AR) $(AROPTS) $@ $^
|
2006-06-26 02:01:30 +00:00
|
|
|
endif
|
2006-06-17 22:41:10 +00:00
|
|
|
|
2006-06-26 02:01:30 +00:00
|
|
|
ifndef LD
|
|
|
|
LD = $(CC)
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifndef CUSTOM_RULE_LINK
|
2007-04-18 22:38:44 +00:00
|
|
|
%.$(TARGET): %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a
|
2013-07-29 18:34:07 +00:00
|
|
|
$(TRACE_LD)
|
|
|
|
$(Q)$(LD) $(LDFLAGS) $(TARGET_STARTFILES) ${filter-out %.a,$^} \
|
|
|
|
${filter %.a,$^} $(TARGET_LIBFILES) -o $@
|
2006-06-26 02:01:30 +00:00
|
|
|
endif
|
2006-06-17 22:41:10 +00:00
|
|
|
|
2012-03-26 20:55:57 +00:00
|
|
|
%.ramprof: %.$(TARGET)
|
2012-07-10 23:02:59 +00:00
|
|
|
$(NM) -S -td --size-sort $< | grep -i " [abdrw] " | cut -d' ' -f2,4
|
2012-03-26 20:55:57 +00:00
|
|
|
|
|
|
|
%.flashprof: %.$(TARGET)
|
2012-07-10 23:02:59 +00:00
|
|
|
$(NM) -S -td --size-sort $< | grep -i " [t] " | cut -d' ' -f2,4
|
2012-03-26 20:55:57 +00:00
|
|
|
|
2007-04-18 21:28:28 +00:00
|
|
|
# Don't treat %.$(TARGET) as an intermediate file because it is
|
|
|
|
# in fact the primary target.
|
|
|
|
.PRECIOUS: %.$(TARGET)
|
|
|
|
|
|
|
|
# Cancel the predefined implict rule for compiling and linking
|
|
|
|
# a single C source into a binary to force GNU make to consider
|
|
|
|
# the match-anything rule below instead.
|
|
|
|
%: %.c
|
|
|
|
|
|
|
|
# Match-anything pattern rule to allow the project makefiles to
|
|
|
|
# abstract from the actual binary name. It needs to contain some
|
|
|
|
# command in order to be a rule, not just a prerequisite.
|
2006-06-17 22:41:10 +00:00
|
|
|
%: %.$(TARGET)
|
|
|
|
@
|