ifndef CONTIKI
  $(error CONTIKI not defined! You must specify where CONTIKI resides!)
endif

#contiki:	contiki-$(TARGET).a

CONTIKI_TARGET_DIRS = .
CONTIKI_TARGET_MAIN = ${addprefix $(OBJECTDIR)/,contiki-main.o}

UIPDRIVERS = ppp/ahdlc.c ppp/ipcp.c ppp/lcp.c ppp/pap.c ppp/ppp.c ppp/ppp_process.c
CONTIKI_TARGET_SOURCEFILES = ppp-arch.c contiki-main.c dlloader.c clock.c leds.c leds-arch.c $(UIPDRIVERS)

CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES)

.SUFFIXES:

### Define the CPU directory
CONTIKI_CPU=$(CONTIKI)/cpu/x86

### Compiler definitions
CC       = gcc
LD       = ld
AS       = as
OBJCOPY  = objcopy
STRIP    = strip
CFLAGSNO = -I. -I$(CONTIKI)/core -I$(CONTIKI_CPU) \
           -I$(CONTIKI)/platform/$(TARGET) \
           ${addprefix -I,$(APPDIRS)} $(APP_INCLUDES) \
          -DWITH_UIP -DWITH_ASCII \
          -Wall -g -I. -I/usr/local/include
CFLAGS  += $(CFLAGSNO)
LDFLAGS  = -Wl,-Map=contiki.map,-export-dynamic

### Setup directory search path for source files

CONTIKI_TARGET_DIRS_CONCAT = ${addprefix $(CONTIKI)/platform/$(TARGET)/, \
                               $(CONTIKI_TARGET_DIRS)}
vpath %.c $(PROJECTDIRS) \
	  $(CONTIKIDIRS) $(APPDIRS) $(CONTIKI_TARGET_DIRS_CONCAT) \
	  $(CONTIKI_CPU) $(APP_DIRS)

### Compilation rules

# $(OBJECTDIR)/%.o: %.c
# 	$(CC) $(CFLAGS) -c $< -o $@

%.so: $(OBJECTDIR)/%.o
	$(LD) -shared -o $@ $^

# %.ce: %.co
# 	$(LD) -shared -o $@ $^

# %.co: %.c
# 	$(CC) $(CFLAGS) -DPROCESS_LOADABLE -c $< -o $@
# 	$(STRIP) --strip-unneeded -g -x $@

# %: %.co $(CONTIKI_TARGET_MAIN) $(PROJECT_OBJECTFILES) contiki-$(TARGET).a
# 	$(CC) $(CFLAGS) -o $@.$(TARGET) $^ $(LDFLAGS)