Advertisement
Guest User

Untitled

a guest
Jun 14th, 2017
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.20 KB | None | 0 0
  1. $(info XXXXXXXXXXXXXXXXXXXXXXXX Starting contiki/Makefile.include XXXXXXXXXXXXXXXXXXXXXXXX)
  2.  
  3. # -*- makefile -*-
  4.  
  5. ifndef CONTIKI
  6. ${error CONTIKI not defined! You must specify where Contiki resides}
  7. endif
  8.  
  9. ifeq ($(TARGET),)
  10. -include Makefile.target
  11. ifeq ($(TARGET),)
  12. ${info TARGET not defined, using target 'native'}
  13. TARGET=native
  14. else
  15. ${info using saved target '$(TARGET)'}
  16. endif
  17. endif
  18.  
  19. ifeq ($(DEFINES),)
  20. -include Makefile.$(TARGET).defines
  21. ifneq ($(DEFINES),)
  22. ${info using saved defines '$(DEFINES)'}
  23. endif
  24. endif
  25.  
  26. ifndef HOST_OS
  27. ifeq ($(OS),Windows_NT)
  28. ## TODO: detect more specific Windows set-ups,
  29. ## e.g. CygWin, MingW, VisualC, Watcom, Interix
  30. HOST_OS := Windows
  31. else
  32. HOST_OS := $(shell uname)
  33. endif
  34. endif
  35.  
  36. #More debug information when running in CI
  37. ifdef CI
  38. ifeq ($(CI),true)
  39. V = 1
  40. endif
  41. endif
  42.  
  43. usage:
  44. @echo "make MAKETARGETS... [TARGET=(TARGET)] [savetarget] [targets]"
  45.  
  46. targets:
  47. @ls -1 $(CONTIKI)/platform $(TARGETDIRS) | grep -v CVS
  48.  
  49. savetarget:
  50. -@rm -f Makefile.target
  51. @echo "saving Makefile.target"
  52. @echo >Makefile.target "TARGET = $(TARGET)"
  53.  
  54. savedefines:
  55. -@rm -f Makefile.$(TARGET).defines
  56. @echo "saving Makefile.$(TARGET).defines"
  57. @echo >Makefile.$(TARGET).defines "DEFINES = $(DEFINES)"
  58.  
  59. OBJECTDIR = obj_$(TARGET)
  60.  
  61. LOWERCASE = -abcdefghijklmnopqrstuvwxyz
  62. UPPERCASE = _ABCDEFGHIJKLMNOPQRSTUVWXYZ
  63. TARGET_UPPERCASE := ${strip ${shell echo $(TARGET) | sed y!$(LOWERCASE)!$(UPPERCASE)!}}
  64. CFLAGS += -DCONTIKI=1 -DCONTIKI_TARGET_$(TARGET_UPPERCASE)=1
  65.  
  66. MODULES += core/sys core/dev core/lib
  67.  
  68. # Include IPv6, IPv4, and/or Rime
  69.  
  70. HAS_STACK = 0
  71. ifeq ($(CONTIKI_WITH_IPV4),1)
  72. HAS_STACK = 1
  73. CFLAGS += -DNETSTACK_CONF_WITH_IPV4=1
  74. MODULES += core/net/ipv4 core/net/ip
  75. endif
  76.  
  77. ifeq ($(CONTIKI_WITH_RIME),1)
  78. HAS_STACK = 1
  79. CFLAGS += -DNETSTACK_CONF_WITH_RIME=1
  80. MODULES += core/net/rime
  81. endif
  82.  
  83. # Make IPv6 the default stack
  84. ifeq ($(HAS_STACK),0)
  85. ifneq ($(CONTIKI_WITH_IPV6),0)
  86. CONTIKI_WITH_IPV6 = 1
  87. endif
  88. endif
  89.  
  90. ifeq ($(CONTIKI_WITH_IPV6),1)
  91. CFLAGS += -DNETSTACK_CONF_WITH_IPV6=1
  92. ifneq ($(CONTIKI_WITH_RPL),0)
  93. CONTIKI_WITH_RPL = 1
  94. endif
  95. MODULES += core/net/ipv6 core/net/ip
  96. endif
  97.  
  98. ifeq ($(CONTIKI_WITH_RPL),1)
  99. CFLAGS += -DUIP_CONF_IPV6_RPL=1
  100. MODULES += core/net/rpl
  101. else
  102. CFLAGS += -DUIP_CONF_IPV6_RPL=0
  103. endif
  104.  
  105. CONTIKI_SOURCEFILES += $(CONTIKIFILES)
  106.  
  107. CONTIKIDIRS += ${addprefix $(CONTIKI)/core/,dev lib net net/llsec net/mac net/rime \
  108. net/rpl sys cfs ctk lib/ctk loader . }
  109.  
  110. oname = ${patsubst %.c,%.o,${patsubst %.S,%.o,$(1)}}
  111.  
  112. CONTIKI_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CONTIKI_SOURCEFILES)}}
  113.  
  114. PROJECT_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(PROJECT_SOURCEFILES)}}
  115.  
  116. # Provide way to create $(OBJECTDIR) if it has been removed by make clean
  117. $(OBJECTDIR):
  118. mkdir $@
  119.  
  120. uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
  121.  
  122. ### Include application makefiles
  123.  
  124. ifdef APPS
  125. APPDS = ${wildcard ${foreach DIR, $(APPDIRS), ${addprefix $(DIR)/, $(APPS)}}} \
  126. ${wildcard ${addprefix $(CONTIKI)/apps/, $(APPS)} \
  127. ${addprefix $(CONTIKI)/platform/$(TARGET)/apps/, $(APPS)} \
  128. $(APPS)}
  129. APPINCLUDES = ${foreach APP, $(APPS), ${wildcard ${foreach DIR, $(APPDS), $(DIR)/Makefile.$(APP)}}}
  130. -include $(APPINCLUDES)
  131. APP_SOURCES = ${foreach APP, $(APPS), $($(APP)_src)}
  132. DSC_SOURCES = ${foreach APP, $(APPS), $($(APP)_dsc)}
  133. CONTIKI_SOURCEFILES += $(APP_SOURCES) $(DSC_SOURCES)
  134. endif
  135.  
  136. ### Include target makefile (TODO Unsafe?)
  137.  
  138. target_makefile := $(wildcard $(CONTIKI)/platform/$(TARGET)/Makefile.$(TARGET) ${foreach TDIR, $(TARGETDIRS), $(TDIR)/$(TARGET)/Makefile.$(TARGET)})
  139.  
  140. # Check if the target makefile exists, and create the object directory if necessary.
  141. ifeq ($(strip $(target_makefile)),)
  142. ${error The target platform "$(TARGET)" does not exist (maybe it was misspelled?)}
  143. else
  144. ifneq (1, ${words $(target_makefile)})
  145. ${error More than one TARGET Makefile found: $(target_makefile)}
  146. endif
  147. include $(target_makefile)
  148. endif
  149.  
  150. ifdef MODULES
  151. UNIQUEMODULES = $(call uniq,$(MODULES))
  152. MODULEDIRS = ${wildcard ${addprefix $(CONTIKI)/, $(UNIQUEMODULES)}}
  153. MODULES_SOURCES = ${foreach d, $(MODULEDIRS), ${subst ${d}/,,${wildcard $(d)/*.c}}}
  154. CONTIKI_SOURCEFILES += $(MODULES_SOURCES)
  155. APPDS += $(MODULEDIRS)
  156. endif
  157.  
  158. ### Verbosity control. Use make V=1 to get verbose builds.
  159.  
  160. ifeq ($(V),1)
  161. TRACE_CC =
  162. TRACE_LD =
  163. TRACE_AR =
  164. TRACE_AS =
  165. Q=
  166. else
  167. TRACE_CC = @echo " CC " $<
  168. TRACE_LD = @echo " LD " $@
  169. TRACE_AR = @echo " AR " $@
  170. TRACE_AS = @echo " AS " $<
  171. Q=@
  172. endif
  173.  
  174. ### Forward comma-separated list of arbitrary defines to the compiler
  175.  
  176. COMMA := ,
  177. CFLAGS += ${addprefix -D,${subst $(COMMA), ,$(DEFINES)}}
  178.  
  179. ### Setup directory search path for source and header files
  180.  
  181. CONTIKI_TARGET_DIRS_CONCAT = ${addprefix ${dir $(target_makefile)}, \
  182. $(CONTIKI_TARGET_DIRS)}
  183. CONTIKI_CPU_DIRS_CONCAT = ${addprefix $(CONTIKI_CPU)/, \
  184. $(CONTIKI_CPU_DIRS)}
  185.  
  186. SOURCEDIRS = . $(PROJECTDIRS) $(CONTIKI_TARGET_DIRS_CONCAT) \
  187. $(CONTIKI_CPU_DIRS_CONCAT) $(CONTIKIDIRS) $(APPDS) ${dir $(target_makefile)}
  188.  
  189.  
  190. CFLAGS += ${addprefix -I,$(SOURCEDIRS) $(CONTIKI)}
  191.  
  192. ### Check for a git repo and pass version if found
  193. ### git.exe in Windows cmd shells may require no stderr redirection
  194. ifndef RELSTR
  195. RELSTR:=${shell git --git-dir ${CONTIKI}/.git describe --tags --always}
  196. endif
  197.  
  198. ifneq ($(RELSTR),)
  199. CFLAGS += -DCONTIKI_VERSION_STRING=\"Contiki-$(RELSTR)\"
  200. endif
  201.  
  202. ### Automatic dependency generation
  203.  
  204. ifneq ($(MAKECMDGOALS),clean)
  205. -include ${addprefix $(OBJECTDIR)/,$(CONTIKI_SOURCEFILES:.c=.d) \
  206. $(PROJECT_SOURCEFILES:.c=.d)}
  207. endif
  208.  
  209. ### See http://make.paulandlesley.org/autodep.html#advanced
  210.  
  211. define FINALIZE_DEPENDENCY
  212. cp $(@:.o=.d) $(@:.o=.$$$$); \
  213. sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
  214. -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.$$$$) >> $(@:.o=.d); \
  215. rm -f $(@:.o=.$$$$)
  216. endef
  217.  
  218. clean:
  219. -rm -f *~ *core core *.srec \
  220. *.lst *.map \
  221. *.cprg *.bin *.data contiki*.a *.firmware core-labels.S *.ihex *.ini \
  222. *.ce *.co
  223. rm -rf $(CLEAN)
  224. -rm -rf $(OBJECTDIR)
  225.  
  226. distclean: clean
  227. -rm -f ${addsuffix .$(TARGET),$(CONTIKI_PROJECT)}
  228.  
  229. -include $(CONTIKI)/platform/$(TARGET)/Makefile.customrules-$(TARGET)
  230.  
  231. ifndef CUSTOM_RULE_C_TO_CE
  232. %.ce: %.c
  233. $(TRACE_CC)
  234. $(Q)$(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@
  235. $(STRIP) --strip-unneeded -g -x $@
  236. endif
  237.  
  238. ifndef CUSTOM_RULE_C_TO_OBJECTDIR_O
  239. $(OBJECTDIR)/%.o: %.c | $(OBJECTDIR)
  240. $(TRACE_CC)
  241. $(Q)$(CC) $(CFLAGS) -MMD -c $< -o $@
  242. @$(FINALIZE_DEPENDENCY)
  243. endif
  244.  
  245. ifndef CUSTOM_RULE_S_TO_OBJECTDIR_O
  246. $(OBJECTDIR)/%.o: %.S | $(OBJECTDIR)
  247. $(TRACE_AS)
  248. $(Q)$(AS) $(ASFLAGS) -o $@ $<
  249. endif
  250.  
  251. ifndef CUSTOM_RULE_C_TO_O
  252. %.o: %.c
  253. $(TRACE_CC)
  254. $(Q)$(CC) $(CFLAGS) -c $< -o $@
  255. endif
  256.  
  257.  
  258. ifndef CUSTOM_RULE_C_TO_CO
  259. %.co: %.c
  260. $(TRACE_CC)
  261. $(Q)$(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@
  262. endif
  263.  
  264. ifndef AROPTS
  265. AROPTS = rcf
  266. endif
  267.  
  268. ifndef CUSTOM_RULE_ALLOBJS_TO_TARGETLIB
  269. contiki-$(TARGET).a: $(CONTIKI_OBJECTFILES)
  270. $(TRACE_AR)
  271. $(Q)$(AR) $(AROPTS) $@ $^
  272. endif
  273.  
  274. ifndef LD
  275. LD = $(CC)
  276. endif
  277.  
  278. ifndef CUSTOM_RULE_LINK
  279. %.$(TARGET): %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a
  280. $(TRACE_LD)
  281. $(Q)$(LD) $(LDFLAGS) $(TARGET_STARTFILES) ${filter-out %.a,$^} \
  282. ${filter %.a,$^} $(TARGET_LIBFILES) -o $@
  283. endif
  284.  
  285. %.ramprof: %.$(TARGET)
  286. $(NM) -S -td --size-sort $< | grep -i " [abdrw] " | cut -d' ' -f2,4
  287.  
  288. %.flashprof: %.$(TARGET)
  289. $(NM) -S -td --size-sort $< | grep -i " [t] " | cut -d' ' -f2,4
  290.  
  291. # Don't treat %.$(TARGET) as an intermediate file because it is
  292. # in fact the primary target.
  293. .PRECIOUS: %.$(TARGET)
  294.  
  295. # Cancel the predefined implict rule for compiling and linking
  296. # a single C source into a binary to force GNU make to consider
  297. # the match-anything rule below instead.
  298. %: %.c
  299.  
  300. # Match-anything pattern rule to allow the project makefiles to
  301. # abstract from the actual binary name. It needs to contain some
  302. # command in order to be a rule, not just a prerequisite.
  303. %: %.$(TARGET)
  304. @
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement