#include $(TOP)/.config


#CFLAGS	+= -I. -I$(TOP)/shared -I$(TOP)/busybox -I$(SRCBASE)/include -Wall
#LDFLAGS	+= -L$(TOP)/shared -L$(INSTALLDIR)/shared/usr/lib -lshared
#+++ GTK July 24, 2007.
MFLAGS := -D__KERNEL__ -DMODULE -I$(KERNEL_DIR)/include -Wall -Wstrict-prototypes -Wno-trigraphs -O2 -fno-strict-aliasing -fno-common -fomit-frame-pointer -I$(PATHCONF) -I$(KERNEL_DIR)/include/asm/gcc -G 0 -mno-abicalls -fno-pic -pipe  -finline-limit=100000 -mlong-calls -march=mips2 -mabi=32 -Wa,--trap -DEXPORT_SYMTAB -iwithprefix -DMODVERSIONS -include $(KERNEL_DIR)/include/linux/modversions.h
#--- GTK


CFLAGS	+= -s -O2
CFLAGS  += $(PATHUSER)
CFLAGS	+= $(PATHNVRAM)
CFLAGS	+= $(PATHCONF)
CFLAGS	+= $(PATHUTILITY)
CFLAGS  += $(PATHFACTORY)


LDFLAGS += $(LIBUTILILTY)
LDFLAGS	+= $(LIBNVRAM)
LDFLAGS	+= $(LIBFACTORY)
LDFLAGS	+= -lpthread
LDFLAGS += $(LIBFLASH)

#OBJS := rc.o init.o http.o crc.o mtd.o interface.o dhcpc.o services.o ppp.o usb_hotplug.o factory.o convert.o gpio_control.o
#+++ GTK January 2, 2008. Integrated init support.
#OBJS := rc.o init.o interface.o dhcpc.o services.o ppp.o factory.o convert.o gpio_control.o psmon.o
OBJS := rc.o init.o interface.o dhcpc.o services.o ppp.o factory.o convert.o gpio_control.o psmon.o ResetDefault.o
#--- GTK
WANOBJS	= wan_connect.o services.o monitor_pppoe.o
UDHCPD_DUMPLEASE_OBJS	:= udhcpd_dumplease.o

#vpath %.c $(TOP)/shared $(SRCBASE)/rts/src

vpath %.h $(SRCBASE)/user/conf/$(VENDOR)_$(MODEL)

#+++ GTK July 24, 2007.
#all: rc wan_connect
all: rc wan_connect udhcpd_dumplease phy_control icplus


phy_control:	phy_control.o
	#$(CC) $(MFLAGS) -c -o phy_control.o phy_control.c

icplus: icplus.o
	$(CC) -o icplus icplus.o $(LDLIBS)
	$(STRIP) icplus
#--- GTK

clean:
#+++ GTK July 24, 2007.
#	rm -f *.o rc .*.depend wan_connect
	rm -f rc .*.depend wan_connect udhcpd_dumplease icplus
#--- GTK

install:
	install -d $(INSTALLDIR)/sbin
	install rc $(INSTALLDIR)/sbin
	install -D wan_connect $(INSTALLDIR)/sbin/wan_connect
	install -D udhcpd_dumplease $(INSTALLDIR)/sbin/udhcpd_dumplease	
	$(STRIP) $(INSTALLDIR)/sbin/rc
	cd $(INSTALLDIR)/sbin && ln -sf rc init
	cd $(INSTALLDIR)/sbin && ln -sf rc erase
	cd $(INSTALLDIR)/sbin && ln -sf rc write
	cd $(INSTALLDIR)/sbin && ln -sf rc stats
	cd $(INSTALLDIR)/sbin && ln -sf rc hotplug
	cd $(INSTALLDIR)/sbin && ln -sf rc hotdiskadd
	cd $(INSTALLDIR)/sbin && ln -sf rc hotdiskremove
#	cd $(INSTALLDIR)/sbin && ln -sf rc rc_notifications
	cd $(INSTALLDIR)/sbin && ln -sf rc autobridge.sh
	cd $(INSTALLDIR)/sbin && ln -sf rc wanup.sh
	cd $(INSTALLDIR)/sbin && ln -sf rc subwan_up.sh	
	cd $(INSTALLDIR)/sbin && ln -sf rc udhcpc.sh

romfs:
	cp rc $(ROMFSDIR)/sbin
	cp wan_connect $(ROMFSDIR)/sbin/
	cp udhcpd_dumplease $(ROMFSDIR)/sbin/
	cd $(ROMFSDIR)/sbin && ln -sf rc init
#	cd $(ROMFSDIR)/sbin && ln -sf rc erase
#	cd $(ROMFSDIR)/sbin && ln -sf rc write
#	cd $(ROMFSDIR)/sbin && ln -sf rc stats
#	cd $(ROMFSDIR)/sbin && ln -sf rc hotplug
#	cd $(ROMFSDIR)/sbin && ln -sf rc hotdiskadd
#	cd $(ROMFSDIR)/sbin && ln -sf rc hotdiskremove
#	cd $(ROMFSDIR)/sbin && ln -sf rc rc_notifications
	cd $(ROMFSDIR)/sbin && ln -sf rc autobridge.sh
	cd $(ROMFSDIR)/sbin && ln -sf rc wanup.sh
	cd $(ROMFSDIR)/sbin && ln -sf rc subwan_up.sh	
	cd $(ROMFSDIR)/sbin && ln -sf rc udhcpc.sh
#+++ GTK July 9, 2007.
	cd $(ROMFSDIR)/sbin && ln -sf rc free_mem
#--- GTK
#+++ GTK July 24, 2007.
	cp phy_control.o $(ROMFSDIR)/etc/phy_control.o
	cp icplus $(ROMFSDIR)/bin/icplus
	chmod 777 $(ROMFSDIR)/bin/icplus
#--- GTK

rc: $(OBJS)
	$(CC) -o $@ $(OBJS) $(LDFLAGS)
	$(STRIP) rc

wan_connect: $(WANOBJS) 
	$(CC) $(CFLAGS) -o $@ $(WANOBJS) $(LDFLAGS)
	$(STRIP) wan_connect	

udhcpd_dumplease: $(UDHCPD_DUMPLEASE_OBJS)
	$(CC) $(CFLAGS) -o $@ $(UDHCPD_DUMPLEASE_OBJS) $(LDFLAGS)

rc.o : vendor_default.h

-include $(OBJS:%.o=.%.depend)

.PHONY: all
