nes-proj/platform/cooja/Makefile.cooja
Peter A. Bigot 5fc0575e99 Makefile.include: support make clean all
Historically $(OBJECTDIR) was created when Makefile.include is read.  A
consequence is that combining "clean" with "all" (or any other build
target) results in an error because the clean removes the object
directory that is required to exist when building dependencies.
Creating $(OBJECTDIR) on-demand ensures it is present when needed.

Removed creation of $(OBJECTDIR) on initial read, and added an order-only
dependency forcing its creation all Makefile* rules where the target is
explicitly or implicitly in $(OBJECTDIR).
2013-06-20 17:45:41 -05:00

132 lines
3.9 KiB
Makefile

# $Id: Makefile.cooja,v 1.42 2010/11/10 13:11:43 fros4943 Exp $
## The COOJA Simulator Contiki platform Makefile
##
## This makefile should normally never be called directly, but
## rather from inside the COOJA simulator.
## The purpose of this file is to compile a shared library that
## can be loaded into the Java part of COOJA.
ifndef CONTIKI
$(error CONTIKI not defined!)
endif
### Assuming simulator quickstart if no JNI library name set from Cooja
ifndef LIBNAME
QUICKSTART=1
endif
### Quickstart simulator
ifdef QUICKSTART
# Create COOJA JAR rule
$(CONTIKI)/tools/cooja/dist/cooja.jar:
@echo "Creating COOJA Java archive..."
(cd $(CONTIKI)/tools/cooja && ant jar)
# Quickstart rule
ifneq ($(MAKECMDGOALS),clean)
.PHONY: $(MAKECMDGOALS)
.PRECIOUS: $(MAKECMDGOALS)
$(MAKECMDGOALS): $(CONTIKI)/tools/cooja/dist/cooja.jar
java -mx512m -jar $< -quickstart='$(firstword $(MAKECMDGOALS))' -contiki='$(CONTIKI)'
endif
endif ## QUICKSTART
#MAIN_SRC = $(OBJECTDIR)/$(LIBNAME).c
MAIN_OBJ = $(OBJECTDIR)/$(LIBNAME).o
ARCHIVE = $(OBJECTDIR)/$(LIBNAME).a
JNILIB = $(OBJECTDIR)/$(LIBNAME).cooja
CONTIKI_APP_OBJ = $(CONTIKI_APP).co
### COOJA platform sources
COOJA = $(CONTIKI)/platform/$(TARGET)
CONTIKI_TARGET_DIRS = . dev lib sys cfs net
# (COOJA_SOURCEDIRS contains additional sources dirs set from simulator)
vpath %.c $(COOJA_SOURCEDIRS)
COOJA_BASE = simEnvChange.c cooja_mt.c cooja_mtarch.c rtimer-arch.c slip.c watchdog.c
COOJA_INTFS = beep.c button-sensor.c ip.c leds-arch.c moteid.c \
pir-sensor.c rs232.c vib-sensor.c \
clock.c log.c cfs-cooja.c cooja-radio.c
COOJA_CORE = random.c sensors.c leds.c symbols.c
COOJA_NET = uip-driver.c
# (COOJA_SOURCEFILES contains additional sources set from simulator)
CONTIKI_TARGET_SOURCEFILES = \
$(COOJA_BASE) $(COOJA_INTFS) $(COOJA_CORE) $(COOJA_NET) $(COOJA_SOURCEFILES)
CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)
.SUFFIXES:
### Define the CPU directory
CONTIKI_CPU=$(CONTIKI)/cpu/x86
### Compiler arguments
#CC = gcc
CFLAGSNO = $(EXTRA_CC_ARGS) -Wall -g -I/usr/local/include -DCLASSNAME=$(CLASSNAME)
CFLAGS += $(CFLAGSNO)
ifeq ($(UIP_CONF_IPV6),1)
CFLAGS += -DWITH_UIP6=1
endif
ifdef WITH_UIP
CFLAGS += -DWITH_UIP=1
endif
## Copied from Makefile.include, since Cooja overrides CFLAGS et al
ifeq ($(UIP_CONF_IPV6),1)
CFLAGS += -DUIP_CONF_IPV6=1
ifneq ($(UIP_CONF_RPL),0)
CFLAGS += -DUIP_CONF_IPV6_RPL=1
endif # UIP_CONF_RPL
endif # UIP_CONF_IPV6
REDEF_PRINTF=1 # Redefine functions to enable printf()s inside Cooja
### Define custom targets
# NB: Assumes ARCHIVE was not overridden and is in $(OBJECTDIR)
$(ARCHIVE): ${addprefix $(OBJECTDIR)/, $(CONTIKI_SOURCEFILES:.c=.o)} | $(OBJECTDIR)
$(AR_COMMAND_1) $^ $(AR_COMMAND_2)
# NB: Assumes JNILIB was not overridden and is in $(OBJECTDIR)
$(JNILIB): $(CONTIKI_APP_OBJ) $(MAIN_OBJ) $(PROJECT_OBJECTFILES) $(ARCHIVE) | $(OBJECTDIR)
ifdef SYMBOLS
@echo Generating symbols
# Recreate symbols file and relink with final memory layout (twice)
${CONTIKI}/tools/make-symbols-nm $(JNILIB)
$(CC) $(CFLAGS) -c symbols.c -o $(OBJECTDIR)/symbols.o
$(LINK_COMMAND_1) $^ $(LINK_COMMAND_2)
${CONTIKI}/tools/make-symbols-nm $(JNILIB)
$(CC) $(CFLAGS) -c symbols.c -o $(OBJECTDIR)/symbols.o
endif ## SYMBOLS
ifdef REDEF_PRINTF
@echo Redefining printf
-$(foreach OBJ,$^, $(OBJCOPY) --redefine-sym printf=log_printf $(OBJ); )
-$(foreach OBJ,$^, $(OBJCOPY) --redefine-sym puts=log_puts $(OBJ); )
-$(foreach OBJ,$^, $(OBJCOPY) --redefine-sym putchar=log_putchar $(OBJ); )
endif ## REDEF_PRINTF
$(LINK_COMMAND_1) $^ $(LINK_COMMAND_2)
.PHONY: $(CONTIKI_APP).cooja
$(CONTIKI_APP).cooja: $(JNILIB)
cp $(JNILIB) $@
rm $(CONTIKI_APP_OBJ)
# Trickiness: GNU make matches this against the file base name.
# Assume that the directory part is the standard location.
mtype%.o: contiki-cooja-main.o | $(OBJECTDIR)
mv contiki-cooja-main.o $@
symbols.c:
# Create initial symbol files if not existing
cp ${CONTIKI}/tools/empty-symbols.c symbols.c
cp ${CONTIKI}/tools/empty-symbols.h symbols.h