Add missing includes
[contiki-2.x.git] / Makefile.include
blob73154fbc55544b5bc25d8d97ab4b78e0e99ab19b
1 ifndef CONTIKI
2   ${error CONTIKI not defined! You must specify where CONTIKI resides}
3 endif
5 ifeq ($(TARGET),)
6   -include Makefile.target
7   ifeq ($(TARGET),)
8     ${info TARGET not defined, using target 'native'}
9     TARGET=native
10   else
11     ${info using saved target '$(TARGET)'}
12   endif
13 endif
15 ifeq ($(DEFINES),)
16   -include Makefile.$(TARGET).defines
17   ifneq ($(DEFINES),)
18     ${info using saved defines '$(DEFINES)'}
19   endif
20 endif
22 usage:
23         @echo "make MAKETARGETS... [TARGET=(TARGET)] [savetarget] [targets]"
25 targets:
26         @ls -1 $(CONTIKI)/platform | grep -v CVS
28 savetarget:
29         -@rm -f Makefile.target
30         @echo "saving Makefile.target"
31         @echo >Makefile.target "TARGET = $(TARGET)"
33 savedefines:
34         -@rm -f Makefile.$(TARGET).defines
35         @echo "saving Makefile.$(TARGET).defines"
36         @echo >Makefile.$(TARGET).defines "DEFINES = $(DEFINES)"
38 OBJECTDIR = obj_$(TARGET)
39 ifeq (${wildcard $(OBJECTDIR)},)
40   DUMMY := ${shell mkdir $(OBJECTDIR)}
41 endif
43 LOWERCASE = -abcdefghijklmnopqrstuvwxyz
44 UPPERCASE = _ABCDEFGHIJKLMNOPQRSTUVWXYZ
45 TARGET_UPPERCASE := ${shell echo $(TARGET) | sed 'y!$(LOWERCASE)!$(UPPERCASE)!'}
46 CFLAGS += -DCONTIKI=1 -DCONTIKI_TARGET_$(TARGET_UPPERCASE)=1
48 include $(CONTIKI)/core/net/rime/Makefile.rime
49 include $(CONTIKI)/core/net/mac/Makefile.mac
50 SYSTEM  = process.c procinit.c autostart.c elfloader.c profile.c \
51           timetable.c timetable-aggregate.c compower.c serial-line.c
52 THREADS = mt.c
53 LIBS    = memb.c mmem.c timer.c list.c etimer.c ctimer.c energest.c rtimer.c stimer.c \
54           print-stats.c ifft.c crc16.c random.c checkpoint.c ringbuf.c
55 DEV     = nullradio.c
56 NET     = netstack.c uip-debug.c packetbuf.c queuebuf.c packetqueue.c
58 ifdef UIP_CONF_IPV6
59   CFLAGS += -DUIP_CONF_IPV6=1
60   UIP   = uip6.c tcpip.c psock.c uip-udp-packet.c uip-split.c \
61           resolv.c tcpdump.c uiplib.c
62   NET   += $(UIP) uip-icmp6.c uip-nd6.c uip-packetqueue.c \
63           sicslowpan.c neighbor-attr.c neighbor-info.c uip-ds6.c
64   include $(CONTIKI)/core/net/rpl/Makefile.rpl
65 else # UIP_CONF_IPV6
66   UIP   = uip.c uiplib.c resolv.c tcpip.c psock.c hc.c uip-split.c uip-fw.c \
67           uip-fw-drv.c uip_arp.c tcpdump.c uip-neighbor.c uip-udp-packet.c \
68           uip-over-mesh.c dhcpc.c #rawpacket-udp.c
69   NET   += $(UIP) uaodv.c uaodv-rt.c
70 endif # UIP_CONF_IPV6
72 CTK     = ctk.c
73 CTKVNC  = $(CTK) ctk-vncserver.c libconio.c vnc-server.c vnc-out.c ctk-vncfont.c
75 ifndef CONTIKI_NO_NET
76   CONTIKIFILES = $(SYSTEM) $(LIBS) $(NET) $(THREADS) $(DHCP) $(DEV)
77 else
78   CONTIKIFILES = $(SYSTEM) $(LIBS) $(THREADS) $(DEV) sicslowpan.c fakeuip.c
79 endif
81 CONTIKI_SOURCEFILES += $(CONTIKIFILES)
83 CONTIKIDIRS += ${addprefix $(CONTIKI)/core/,dev lib net net/mac net/rime \
84                  net/rpl sys cfs ctk lib/ctk loader . }
86 oname = ${patsubst %.c,%.o,${patsubst %.S,%.o,$(1)}}
88 CONTIKI_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CONTIKI_SOURCEFILES)}}
90 PROJECT_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(PROJECT_SOURCEFILES)}}
92 ### Include application makefiles
94 ifdef APPS
95   APPDIRS += ${wildcard ${addprefix $(CONTIKI)/apps/, $(APPS)} \
96                 ${addprefix $(CONTIKI)/platform/$(TARGET)/apps/, $(APPS)} \
97                 ${addprefix , $(APPS)}}
98   APPINCLUDES = ${foreach APP, $(APPS), ${wildcard \
99                  $(CONTIKI)/apps/$(APP)/Makefile.$(APP) \
100                  $(CONTIKI)/platform/$(TARGET)/apps/$(APP)/Makefile.$(APP) \
101                  $(APP)/Makefile.$(APP)}}
102   -include $(APPINCLUDES)
103   APP_SOURCES = ${foreach APP, $(APPS), $($(APP)_src)}
104   DSC_SOURCES = ${foreach APP, $(APPS), $($(APP)_dsc)}
105   CONTIKI_SOURCEFILES += $(APP_SOURCES) $(DSC_SOURCES)
106 endif
108 ### Include target makefile (TODO Unsafe?)
110 target_makefile := $(wildcard $(CONTIKI)/platform/$(TARGET)/Makefile.$(TARGET))
112 # Check if the target makefile exists
113 ifeq ($(strip $(target_makefile)),)
114   ${error The target platform "$(TARGET)" does not exist (maybe it was misspelled?)}
115 else
116   include $(CONTIKI)/platform/$(TARGET)/Makefile.$(TARGET)
117 endif
119 ### Forward comma-separated list of arbitrary defines to the compiler
121 COMMA := ,
122 CFLAGS += ${addprefix -D,${subst $(COMMA), ,$(DEFINES)}}
124 ### Setup directory search path for source and header files
126 CONTIKI_TARGET_DIRS_CONCAT = ${addprefix $(CONTIKI)/platform/$(TARGET)/, \
127                                $(CONTIKI_TARGET_DIRS)}
128 CONTIKI_CPU_DIRS_CONCAT    = ${addprefix $(CONTIKI_CPU)/, \
129                                $(CONTIKI_CPU_DIRS)}
131 SOURCEDIRS = . $(PROJECTDIRS) $(CONTIKI_TARGET_DIRS_CONCAT) \
132              $(CONTIKI_CPU_DIRS_CONCAT) $(CONTIKIDIRS) $(APPDIRS)
134 vpath %.c $(SOURCEDIRS)
135 vpath %.S $(SOURCEDIRS)
137 CFLAGS += ${addprefix -I,$(SOURCEDIRS)}
139 ### Automatic dependency generation
141 ifneq ($(MAKECMDGOALS),clean)
142 -include ${addprefix $(OBJECTDIR)/,$(CONTIKI_SOURCEFILES:.c=.d) \
143                                    $(PROJECT_SOURCEFILES:.c=.d)}
144 endif
146 ### See http://make.paulandlesley.org/autodep.html#advanced
148 define FINALIZE_DEPENDENCY
149 cp $(@:.o=.d) $(@:.o=.$$$$); \
150 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
151     -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.$$$$) >> $(@:.o=.d); \
152 rm -f $(@:.o=.$$$$)
153 endef
155 clean:
156         rm -f *~ *core core *.srec \
157         *.lst *.map \
158         *.cprg *.bin *.data contiki*.a *.firmware core-labels.S *.ihex *.ini \
159         *.ce *.co $(CLEAN)
160         -rm -rf $(OBJECTDIR)
162 ifndef CUSTOM_RULE_C_TO_CE
163 %.ce: %.c
164         $(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@
165         $(STRIP) --strip-unneeded -g -x $@
166 endif
168 ifndef CUSTOM_RULE_C_TO_OBJECTDIR_O
169 $(OBJECTDIR)/%.o: %.c
170         $(CC) $(CFLAGS) -MMD -c $< -o $@
171         @$(FINALIZE_DEPENDENCY)
172 endif
174 ifndef CUSTOM_RULE_S_TO_OBJECTDIR_O
175 $(OBJECTDIR)/%.o: %.S
176         $(AS) $(ASFLAGS) -o $@ $<
177 endif
179 ifndef CUSTOM_RULE_C_TO_O
180 %.o: %.c
181         $(CC) $(CFLAGS) -c $< -o $@
182 endif
184 ifndef CUSTOM_RULE_C_TO_CO
185 %.co: %.c
186         $(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@
187 endif
189 ifndef AROPTS
190   AROPTS = rcf
191 endif
193 ifndef CUSTOM_RULE_ALLOBJS_TO_TARGETLIB
194 contiki-$(TARGET).a: $(CONTIKI_OBJECTFILES)
195         $(AR) $(AROPTS) $@ $^
196 endif
198 ifndef LD
199   LD = $(CC)
200 endif
202 ifndef CUSTOM_RULE_LINK
203 %.$(TARGET): %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a
204         $(LD) $(LDFLAGS) $(TARGET_STARTFILES) ${filter-out %.a,$^} ${filter %.a,$^} $(TARGET_LIBFILES) -o $@
205 endif
207 # Don't treat %.$(TARGET) as an intermediate file because it is
208 # in fact the primary target.
209 .PRECIOUS: %.$(TARGET)
211 # Cancel the predefined implict rule for compiling and linking
212 # a single C source into a binary to force GNU make to consider
213 # the match-anything rule below instead.
214 %: %.c
216 # Match-anything pattern rule to allow the project makefiles to
217 # abstract from the actual binary name. It needs to contain some
218 # command in order to be a rule, not just a prerequisite.
219 %: %.$(TARGET)
220         @