mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-23 16:29:34 +00:00
218 lines
6.2 KiB
Makefile
218 lines
6.2 KiB
Makefile
ifndef CONTIKI
|
|
${error CONTIKI not defined! You must specify where CONTIKI resides}
|
|
endif
|
|
|
|
ifeq ($(TARGET),)
|
|
-include Makefile.target
|
|
ifeq ($(TARGET),)
|
|
${info TARGET not defined, using target 'native'}
|
|
TARGET=native
|
|
else
|
|
${info using saved target '$(TARGET)'}
|
|
endif
|
|
endif
|
|
|
|
ifeq ($(DEFINES),)
|
|
-include Makefile.$(TARGET).defines
|
|
ifneq ($(DEFINES),)
|
|
${info using saved defines '$(DEFINES)'}
|
|
endif
|
|
endif
|
|
|
|
usage:
|
|
@echo "make MAKETARGETS... [TARGET=(TARGET)] [savetarget] [targets]"
|
|
|
|
targets:
|
|
@ls -1 $(CONTIKI)/platform | grep -v CVS
|
|
|
|
savetarget:
|
|
-@rm -f Makefile.target
|
|
@echo "saving Makefile.target"
|
|
@echo >Makefile.target "TARGET = $(TARGET)"
|
|
|
|
savedefines:
|
|
-@rm -f Makefile.$(TARGET).defines
|
|
@echo "saving Makefile.$(TARGET).defines"
|
|
@echo >Makefile.$(TARGET).defines "DEFINES = $(DEFINES)"
|
|
|
|
OBJECTDIR = obj_$(TARGET)
|
|
ifeq (${wildcard $(OBJECTDIR)},)
|
|
DUMMY := ${shell mkdir $(OBJECTDIR)}
|
|
endif
|
|
|
|
LOWERCASE = -abcdefghijklmnopqrstuvwxyz
|
|
UPPERCASE = _ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
|
TARGET_UPPERCASE := ${shell echo $(TARGET) | sed 'y!$(LOWERCASE)!$(UPPERCASE)!'}
|
|
CFLAGS += -DCONTIKI_TARGET_$(TARGET_UPPERCASE)
|
|
|
|
include $(CONTIKI)/core/net/rime/Makefile.rime
|
|
include $(CONTIKI)/core/net/mac/Makefile.mac
|
|
SYSTEM = process.c procinit.c autostart.c elfloader.c profile.c \
|
|
timetable.c timetable-aggregate.c compower.c serial-line.c
|
|
THREADS = mt.c
|
|
LIBS = memb.c timer.c list.c etimer.c energest.c rtimer.c stimer.c \
|
|
print-stats.c ifft.c crc16.c random.c checkpoint.c ringbuf.c
|
|
|
|
ifdef UIP_CONF_IPV6
|
|
CFLAGS += -DUIP_CONF_IPV6
|
|
UIP = uip6.c tcpip.c psock.c uip-udp-packet.c uip-split.c \
|
|
uip-over-mesh.c resolv.c hc.c tcpdump.c uiplib.c
|
|
NET = $(UIP) uip-icmp6.c uip-nd6.c uip-nd6-io.c uip-netif.c sicslowpan.c
|
|
else # UIP_CONF_IPV6
|
|
UIP = uip.c uiplib.c resolv.c tcpip.c psock.c hc.c uip-split.c uip-fw.c \
|
|
uip-fw-drv.c uip_arp.c tcpdump.c uip-neighbor.c uip-udp-packet.c \
|
|
uip-over-mesh.c #rawpacket-udp.c
|
|
NET = $(UIP) uaodv.c uaodv-rt.c
|
|
endif # UIP_CONF_IPV6
|
|
|
|
CTK = ctk.c
|
|
CTKVNC = $(CTK) ctk-vncserver.c libconio.c vnc-server.c vnc-out.c ctk-vncfont.c
|
|
|
|
ifndef CONTIKI_NO_NET
|
|
CONTIKIFILES = $(SYSTEM) $(LIBS) $(NET) $(THREADS) $(DHCP)
|
|
else
|
|
CONTIKIFILES = $(SYSTEM) $(LIBS) $(THREADS) sicslowpan.c fakeuip.c
|
|
endif
|
|
|
|
CONTIKI_SOURCEFILES += $(CONTIKIFILES)
|
|
|
|
CONTIKIDIRS += ${addprefix $(CONTIKI)/core/,dev lib net net/mac net/rime sys \
|
|
cfs ctk lib/ctk loader . }
|
|
|
|
oname = ${patsubst %.c,%.o,${patsubst %.S,%.o,$(1)}}
|
|
|
|
CONTIKI_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(CONTIKI_SOURCEFILES)}}
|
|
|
|
PROJECT_OBJECTFILES = ${addprefix $(OBJECTDIR)/,${call oname, $(PROJECT_SOURCEFILES)}}
|
|
|
|
### Include application makefiles
|
|
ifdef APPS
|
|
APPDIRS += ${wildcard ${addprefix $(CONTIKI)/apps/, $(APPS)} \
|
|
${addprefix $(CONTIKI)/platform/$(TARGET)/apps/, $(APPS)}}
|
|
APPINCLUDES = ${foreach APP, $(APPS), ${wildcard \
|
|
$(CONTIKI)/apps/$(APP)/Makefile.$(APP) \
|
|
$(CONTIKI)/platform/$(TARGET)/apps/$(APP)/Makefile.$(APP)}}
|
|
-include $(APPINCLUDES)
|
|
APP_SOURCES = ${foreach APP, $(APPS), $($(APP)_src)}
|
|
DSC_SOURCES = ${foreach APP, $(APPS), $($(APP)_dsc)}
|
|
CONTIKI_SOURCEFILES += $(APP_SOURCES) $(DSC_SOURCES)
|
|
endif
|
|
|
|
### Include target makefile (TODO Unsafe?)
|
|
target_makefile := $(wildcard $(CONTIKI)/platform/$(TARGET)/Makefile.$(TARGET))
|
|
|
|
# Check if the target makefile exists
|
|
ifeq ($(strip $(target_makefile)),)
|
|
${error The target platform "$(TARGET)" does not exist (maybe it was misspelled?)}
|
|
else
|
|
include $(CONTIKI)/platform/$(TARGET)/Makefile.$(TARGET)
|
|
endif
|
|
|
|
### Forward comma-separated list of arbitrary defines to the compiler
|
|
|
|
COMMA := ,
|
|
CFLAGS += ${addprefix -D,${subst $(COMMA), ,$(DEFINES)}}
|
|
|
|
### Setup directory search path for source and header files
|
|
|
|
CONTIKI_TARGET_DIRS_CONCAT = ${addprefix $(CONTIKI)/platform/$(TARGET)/, \
|
|
$(CONTIKI_TARGET_DIRS)}
|
|
CONTIKI_CPU_DIRS_CONCAT = ${addprefix $(CONTIKI_CPU)/, \
|
|
$(CONTIKI_CPU_DIRS)}
|
|
|
|
SOURCEDIRS = . $(PROJECTDIRS) $(CONTIKI_TARGET_DIRS_CONCAT) \
|
|
$(CONTIKI_CPU_DIRS_CONCAT) $(CONTIKIDIRS) $(APPDIRS)
|
|
|
|
vpath %.c $(SOURCEDIRS)
|
|
vpath %.S $(SOURCEDIRS)
|
|
|
|
CFLAGS += ${addprefix -I,$(SOURCEDIRS)}
|
|
|
|
### Automatic dependency generation
|
|
|
|
ifneq ($(MAKECMDGOALS),clean)
|
|
-include ${addprefix $(OBJECTDIR)/,$(CONTIKI_SOURCEFILES:.c=.d) \
|
|
$(PROJECT_SOURCEFILES:.c=.d)}
|
|
endif
|
|
|
|
clean:
|
|
rm -f *~ *core core *.srec \
|
|
*.lst *.map \
|
|
*.cprg *.bin *.data contiki*.a *.firmware core-labels.S *.ihex *.ini \
|
|
*.ce *.co $(CLEAN)
|
|
-rm -rf $(OBJECTDIR)
|
|
|
|
ifndef CUSTOM_RULE_C_TO_CE
|
|
%.ce: %.c
|
|
$(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@
|
|
$(STRIP) --strip-unneeded -g -x $@
|
|
endif
|
|
|
|
ifndef CUSTOM_RULE_C_TO_OBJECTDIR_O
|
|
$(OBJECTDIR)/%.o: %.c
|
|
$(CC) $(CFLAGS) -c $< -o $@
|
|
endif
|
|
|
|
ifndef CUSTOM_RULE_S_TO_OBJECTDIR_O
|
|
$(OBJECTDIR)/%.o: %.S
|
|
$(AS) $(ASFLAGS) -o $@ $<
|
|
endif
|
|
|
|
ifndef CUSTOM_RULE_C_TO_O
|
|
%.o: %.c
|
|
$(CC) $(CFLAGS) -c $< -o $@
|
|
endif
|
|
|
|
ifndef CUSTOM_RULE_C_TO_CO
|
|
%.co: %.c
|
|
$(CC) $(CFLAGS) -DAUTOSTART_ENABLE -c $< -o $@
|
|
endif
|
|
|
|
ifndef AROPTS
|
|
AROPTS = rcf
|
|
endif
|
|
|
|
ifndef CUSTOM_RULE_ALLOBJS_TO_TARGETLIB
|
|
contiki-$(TARGET).a: $(CONTIKI_OBJECTFILES)
|
|
$(AR) $(AROPTS) $@ $^
|
|
endif
|
|
|
|
ifndef CCDEP
|
|
CCDEP = $(CC)
|
|
endif
|
|
ifndef CDEPFLAGS
|
|
CDEPFLAGS = $(CFLAGS)
|
|
endif
|
|
|
|
ifndef CUSTOM_RULE_C_TO_OBJECTDIR_D
|
|
$(OBJECTDIR)/%.d: %.c
|
|
@echo Making dependencies for $<; set -e; rm -f $@; \
|
|
$(CCDEP) -MM $(CDEPFLAGS) $< > $@.$$$$; \
|
|
sed 's,\($*\)\.o[ :]*,$(OBJECTDIR)/\1.o $@ : ,g' < $@.$$$$ > $@; \
|
|
rm -f $@.$$$$
|
|
endif
|
|
|
|
ifndef LD
|
|
LD = $(CC)
|
|
endif
|
|
|
|
ifndef CUSTOM_RULE_LINK
|
|
%.$(TARGET): %.co $(PROJECT_OBJECTFILES) $(PROJECT_LIBRARIES) contiki-$(TARGET).a
|
|
$(LD) $(LDFLAGS) $(TARGET_STARTFILES) ${filter-out %.a,$^} ${filter %.a,$^} $(TARGET_LIBFILES) -o $@
|
|
endif
|
|
|
|
# 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.
|
|
%: %.$(TARGET)
|
|
@
|