include ../config.mk
include ../config.in

SHELL=/bin/sh

BINDIR=$(TARGETDIR)/usr/sbin
ETCDIR=$(TARGETDIR)/etc

##
## Variables
##

# Final executable
EXEC=gproxy

# Directories
TOP_DIR=.
SRCDIR:=$(TOP_DIR)/src

# Compiler flags
#CFLAGS+=-D@OS@ 
CFLAGS+=-O2 -Wall 
CFLAGS+= -I$(SRCDIR)/include -I../../acos/include -I../../acos/shared

ifeq ($(CONFIG_STATIC_PPPOE),y)
CFLAGS  += -DSTATIC_PPPOE
else
CFLAGS  += -USTATIC_PPPOE
endif

#-I/usr/include
#CC=@CC@

THREAD_LIBS= -lpthread

# Linker flags
LDFLAGS += $(THREAD_LIBS)
LDFLAGS	+= -L$(ROUTERDIR)/nvram -L$(INSTALLDIR)/nvram/usr/lib -lnvram
LDFLAGS += -L../../acos/shared -L../../acos/acos_nat_cli -L$(TARGETDIR)/shared/usr/lib -lacos_shared -lnat

ifeq ($(CONFIG_PLC_SUPPORT),y)
LDFLAGS += -L$(TARGETDIR)/usr/lib/ -lcurl
endif

#Foxconn add start by Hank 07/30/2012
#For Kernel 2.6.36
ifeq ($(CONFIG_KERNEL_2_6_36),y)
LDFLAGS	+= -lgcc_s
endif
#Foxconn add end by Hank 07/30/2012

# Object files
OBJ_ALL=*.o
SRC=$(wildcard $(SRCDIR)/*.c)
# The following will expand to the full path of every .o file:
OBJS=$(SRC:.c=.o)


##
## Targets
##

# We're only interested in .o and .c prefixes (the following two lines make this
# Makefile more portable)
.SUFFIXES:
.SUFFIXES:.o .c

# .PHONY targets : will be executed even if up to date. See GNU 
# Make Manual section 4.6 for further details
.PHONY: clean all mrproper generate $(DIRS) rec_exec install help
# Of course $(EXEC) isn't phony ! ("and I know phony, I'm a clown-fish" - Marlin :-))

# Default target :
all: $(EXEC)


$(EXEC): $(OBJS)
	$(CC) $(LDFLAGS) -o $(EXEC) $(OBJS)


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


help:
	@ echo "Available targets :" 
	@ echo "  help : this message."
	@ echo "  all : build everything and produce $(EXEC) executable."
	@ echo "  clean : remove all objects file."
	@ echo "  mrproper : same as clean + remove $(EXEC) + remove files generated by ./configure + remove doc.\
You'll need to run ./configure again after that."
	@ echo "  generate : (UNIX )re-create Makefile's in subdirectories. Execute this after deep \
modificaton of the code when dependencies have changed. This will recreate them."
	@ echo "  install : does nothing."
	@ echo "  doc : run doxygen to generate HTML n TeX doc of the code."
	@ echo "  <DIR> : where <DIR> is one of the sub-dir, to recompile only this very subdir."

doc:
	@ doxygen $(TOP_DIR)/Doxyfile

install:
	@ echo "This target does currently nothing. The executable remain in"
	@ echo "this directory for greater convinience when used in conjunction"
	$(STRIP) $(EXEC)
	cp $(EXEC) ${BINDIR}
	cp ./etc/igmprt.conf ${ETCDIR}

clean:
	-rm -rf $(TOP_DIR)/src/*.o $(TOP_DIR)/$(EXEC)
# Make ignore return status of commands begining with '-'
mrproper: clean
	-rm $(TOP_DIR)/$(EXEC) 
	-rm $(TOP_DIR)/*~ 
	-rm $(TOP_DIR)/src/*~ 
	-rm $(SRCDIR)/include/conf.h 
	-rm $(TOP_DIR)/Makefile 
	-rm $(TOP_DIR)/config.cache
	-rm -rf $(TOP_DIR)/doc
