Send optional ADC2 measurement to 1284p
[contiki-2.x.git] / Makefile.include
blob71a93461b704869eec593d4e00400f1968ebf2ee
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_TARGET_$(TARGET_UPPERCASE)
48 include $(CONTIKI)/core/net/routing/Makefile.routing
49 include $(CONTIKI)/core/net/rime/Makefile.rime
50 include $(CONTIKI)/core/net/mac/Makefile.mac
51 SYSTEM  = process.c procinit.c autostart.c elfloader.c profile.c \
52           timetable.c timetable-aggregate.c compower.c serial-line.c
53 THREADS = mt.c
54 LIBS    = memb.c mmem.c timer.c list.c etimer.c energest.c rtimer.c stimer.c \
55           print-stats.c ifft.c crc16.c random.c checkpoint.c ringbuf.c
57 ifdef UIP_CONF_IPV6
58 CFLAGS += -DUIP_CONF_IPV6
59   UIP   = uip6.c tcpip.c psock.c uip-udp-packet.c uip-split.c \
60           resolv.c tcpdump.c uiplib.c
61   NET   = $(UIP) uip-icmp6.c uip-nd6.c uip-nd6-io.c uip-netif.c sicslowpan.c
62 else # UIP_CONF_IPV6
63   UIP   = uip.c uiplib.c resolv.c tcpip.c psock.c hc.c uip-split.c uip-fw.c \
64           uip-fw-drv.c uip_arp.c tcpdump.c uip-neighbor.c uip-udp-packet.c \
65           uip-over-mesh.c dhcpc.c #rawpacket-udp.c
66   NET   = $(UIP) uaodv.c uaodv-rt.c
67 endif # UIP_CONF_IPV6
69 CTK     = ctk.c
70 CTKVNC  = $(CTK) ctk-vncserver.c libconio.c vnc-server.c vnc-out.c ctk-vncfont.c
72 ifndef CONTIKI_NO_NET
73   CONTIKIFILES = $(SYSTEM) $(LIBS) $(NET) $(THREADS) $(DHCP)
74 else
75   CONTIKIFILES = $(SYSTEM) $(LIBS) $(THREADS) sicslowpan.c fakeuip.c
76 endif
78 CONTIKI_SOURCEFILES += $(CONTIKIFILES)
80 CONTIKIDIRS += ${addprefix $(CONTIKI)/core/,dev lib net net/mac net/rime \
81                  net/routing sys cfs ctk lib/ctk loader . }
83 oname = ${patsubst %.c,%.o,${patsubst %.S,%.o,$(1)}}
85 CONTIKI_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CONTIKI_SOURCEFILES)}}
87 PROJECT_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(PROJECT_SOURCEFILES)}}
89 ### Include application makefiles
91 ifdef APPS
92   APPDIRS += ${wildcard ${addprefix $(CONTIKI)/apps/, $(APPS)} \
93                 ${addprefix $(CONTIKI)/platform/$(TARGET)/apps/, $(APPS)}}
94   APPINCLUDES = ${foreach APP, $(APPS), ${wildcard \
95                  $(CONTIKI)/apps/$(APP)/Makefile.$(APP) \
96                  $(CONTIKI)/platform/$(TARGET)/apps/$(APP)/Makefile.$(APP)}}
97   -include $(APPINCLUDES)
98   APP_SOURCES = ${foreach APP, $(APPS), $($(APP)_src)}
99   DSC_SOURCES = ${foreach APP, $(APPS), $($(APP)_dsc)}
100   CONTIKI_SOURCEFILES += $(APP_SOURCES) $(DSC_SOURCES)
101 endif
103 ### Include target makefile (TODO Unsafe?)
105 target_makefile := $(wildcard $(CONTIKI)/platform/$(TARGET)/Makefile.$(TARGET))
107 # Check if the target makefile exists
108 ifeq ($(strip $(target_makefile)),)
109   ${error The target platform "$(TARGET)" does not exist (maybe it was misspelled?)}
110 else
111   include $(CONTIKI)/platform/$(TARGET)/Makefile.$(TARGET)
112 endif
114 ### Forward comma-separated list of arbitrary defines to the compiler
116 COMMA := ,
117 CFLAGS += ${addprefix -D,${subst $(COMMA), ,$(DEFINES)}}
119 ### Setup directory search path for source and header files
121 CONTIKI_TARGET_DIRS_CONCAT = ${addprefix $(CONTIKI)/platform/$(TARGET)/, \
122                                $(CONTIKI_TARGET_DIRS)}
123 CONTIKI_CPU_DIRS_CONCAT    = ${addprefix $(CONTIKI_CPU)/, \
124                                $(CONTIKI_CPU_DIRS)}
126 SOURCEDIRS = . $(PROJECTDIRS) $(CONTIKI_TARGET_DIRS_CONCAT) \
127              $(CONTIKI_CPU_DIRS_CONCAT) $(CONTIKIDIRS) $(APPDIRS)
129 vpath %.c $(SOURCEDIRS)
130 vpath %.S $(SOURCEDIRS)
132 CFLAGS += ${addprefix -I,$(SOURCEDIRS)}
134 ### Automatic dependency generation
136 ifneq ($(MAKECMDGOALS),clean)
137 -include ${addprefix $(OBJECTDIR)/,$(CONTIKI_SOURCEFILES:.c=.d) \
138                                    $(PROJECT_SOURCEFILES:.c=.d)}
139 endif
141 ### See http://make.paulandlesley.org/autodep.html#advanced
143 define FINALIZE_DEPENDENCY
144 cp $(@:.o=.d) $(@:.o=.$$$$); \
145 sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
146     -e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.$$$$) >> $(@:.o=.d); \
147 rm -f $(@:.o=.$$$$)
148 endef
150 clean:
151         rm -f *~ *core core *.srec \
152         *.lst *.map \
153         *.cprg *.bin *.data contiki*.a *.firmware core-labels.S *.ihex *.ini \
154         *.ce *.co $(CLEAN)
155         -rm -rf $(OBJECTDIR)
157 ifndef CUSTOM_RULE_C_TO_CE
158 %.ce: %.c
159         $(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@
160         $(STRIP) --strip-unneeded -g -x $@
161 endif
163 ifndef CUSTOM_RULE_C_TO_OBJECTDIR_O
164 $(OBJECTDIR)/%.o: %.c
165         $(CC) $(CFLAGS) -MMD -c $< -o $@
166         @$(FINALIZE_DEPENDENCY)
167 endif
169 ifndef CUSTOM_RULE_S_TO_OBJECTDIR_O
170 $(OBJECTDIR)/%.o: %.S
171         $(AS) $(ASFLAGS) -o $@ $<
172 endif
174 ifndef CUSTOM_RULE_C_TO_O
175 %.o: %.c
176         $(CC) $(CFLAGS) -c $< -o $@
177 endif
179 ifndef CUSTOM_RULE_C_TO_CO
180 %.co: %.c
181         $(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@
182 endif
184 ifndef AROPTS
185   AROPTS = rcf
186 endif
188 ifndef CUSTOM_RULE_ALLOBJS_TO_TARGETLIB
189 contiki-$(TARGET).a: $(CONTIKI_OBJECTFILES)
190         $(AR) $(AROPTS) $@ $^
191 endif
193 ifndef LD
194   LD = $(CC)
195 endif
197 ifndef CUSTOM_RULE_LINK
198 %.$(TARGET): %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a
199         $(LD) $(LDFLAGS) $(TARGET_STARTFILES) ${filter-out %.a,$^} ${filter %.a,$^} $(TARGET_LIBFILES) -o $@
200 endif
202 # Don't treat %.$(TARGET) as an intermediate file because it is
203 # in fact the primary target.
204 .PRECIOUS: %.$(TARGET)
206 # Cancel the predefined implict rule for compiling and linking
207 # a single C source into a binary to force GNU make to consider
208 # the match-anything rule below instead.
209 %: %.c
211 # Match-anything pattern rule to allow the project makefiles to
212 # abstract from the actual binary name. It needs to contain some
213 # command in order to be a rule, not just a prerequisite.
214 %: %.$(TARGET)
215         @