##  Copyright 2005 Sveasoft Inc.
##  
##     Licensed under the Apache License, Version 2.0 (the "License")
##     with the following addendum:
##     
##     ADDENDUM
##     
##     10. This code may not be used, distributed, aggregated, or 
##     relicensed under any other license that restricts its use 
##     further than the stipulations of the Apache License, Version 2.0.
##     Specifically this code may not be relicensed under any version of 
##     the GPL or LGPL licenses. 
##     
##     The Apache License, Version 2.0 will apply to the entire work for
##     any derived, aggregated, compiled, or other works, in source or 
##     binary form, of this source code when combined with source code or  
##     binary compilationslicensed under a more restrictive license, such 
##     as the GPL or LGPL.
##     
##     END OF ADDENDUM
##     
##     You may not use this file except in compliance with the License.
##     You may obtain a copy of the License at
##  
##         http://www.apache.org/licenses/LICENSE-2.0
##  
##     Unless required by applicable law or agreed to in writing, software
##     distributed under the License is distributed on an "AS IS" BASIS,
##     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
##     See the License for the specific language governing permissions and
##     limitations under the License.
## 

include $(TOP)/.config

ifneq ($(wildcard $(SRCBASE)/cy_conf.mak),)
  include $(SRCBASE)/cy_conf.mak
endif

CFLAGS	+= -I. -I$(TOP)/shared -I$(SRCBASE)/include -Wall -I$(SRCBASE)/
CFLAGS  += -I$(TOP)/iptables/include -I$(TOP)/iptables/include/libipq -I$(TOP)/libnet/include -DL_ENDIAN -DLIBNET_LIL_ENDIAN -DLIB1X_LIL_ENDIAN
CFLAGS	+= -s -O1
LDFLAGS	+= -L$(TOP)/nvram -L$(INSTALLDIR)/nvram/usr/lib -lnvram -L$(TOP)/shared -L$(INSTALLDIR)/shared/usr/lib -lshared -L$(SRCBASE)/router/libnet/lib -lnet -L$(TOP)/matrixssl/src -lmatrixssl  -lcrypt 

OBJS := rc.o init.o interface.o network.o services.o udhcpc.o ppp.o http.o stats.o crc.o mtd.o
OBJS += firewall.o writeimage.o resetbutton.o ntp.o gpio.o iptable.o ddns.o listen.o check_ps.o process_monitor.o wshaper.o wland.o mkfiles.o sendudp.o


OBJS += heartbeat.o
OBJS += site_suvery.o

ifeq ($(CONFIG_NETCONF),y)
OBJS += firewall.o
endif

ifeq ($(CONFIG_PPTPD),y)
OBJS += pptpd.o
CFLAGS += -DHAVE_PPTPD
endif

ifeq ($(CONFIG_BOOT_WAIT_ON),y)
CFLAGS += -DBOOT_WAIT_ON
endif

ifeq ($(CONFIG_DROPBEAR_SSHD),y)
OBJS += sshd.o
CFLAGS += -DHAVE_SSHD
endif

ifeq ($(CONFIG_RADVD),y)
CFLAGS += -DHAVE_RADVD
endif

ifeq ($(CONFIG_CHILLISPOT),y)
CFLAGS += -DHAVE_CHILLI
endif

ifeq ($(CONFIG_BIRD),y)
CFLAGS += -DHAVE_BIRD
endif

ifeq ($(CONFIG_PPP),y)
CFLAGS += -DHAVE_PPP
endif

ifeq ($(CONFIG_ZEBRA),y)
CFLAGS += -DHAVE_ZEBRA
endif

ifeq ($(CONFIG_WSHAPER),y)
CFLAGS += -DHAVE_WSHAPER
endif

ifeq ($(CONFIG_SVQOS),y)
CFLAGS += -DHAVE_SVQOS
endif

ifeq ($(CONFIG_SNMP),y)
CFLAGS += -DHAVE_SNMP
OBJS += snmp.o
endif

ifeq ($(CONFIG_WOL),y)
CFLAGS += -DHAVE_WOL
OBJS += wol.o
endif

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

all: rc

clean:
	rm -f *.o rc

install: all
	install -d $(INSTALLDIR)/sbin
	install rc $(INSTALLDIR)/sbin
	$(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 restore
	cd $(INSTALLDIR)/sbin && ln -sf rc stats
	cd $(INSTALLDIR)/sbin && ln -sf rc hotplug

	cd $(INSTALLDIR)/sbin && ln -sf rc filter
	cd $(INSTALLDIR)/sbin && ln -sf rc resetbutton
	cd $(INSTALLDIR)/sbin && ln -sf rc filtersync
	cd $(INSTALLDIR)/sbin && ln -sf rc ntpd
	cd $(INSTALLDIR)/sbin && ln -sf rc ipupdated
	cd $(INSTALLDIR)/sbin && ln -sf rc redial
	cd $(INSTALLDIR)/sbin && ln -sf rc hb_connect
	cd $(INSTALLDIR)/sbin && ln -sf rc hb_disconnect
	cd $(INSTALLDIR)/sbin && ln -sf rc gpio
	cd $(INSTALLDIR)/sbin && ln -sf rc listen
	cd $(INSTALLDIR)/sbin && ln -sf rc check_ps
	cd $(INSTALLDIR)/sbin && ln -sf rc ddns_success
	cd $(INSTALLDIR)/sbin && ln -sf rc process_monitor
	cd $(INSTALLDIR)/sbin && ln -sf rc site_survey
	cd $(INSTALLDIR)/sbin && ln -sf rc sendudp
	cd $(INSTALLDIR)/sbin && ln -sf rc check_ses_led	
	cd $(INSTALLDIR)/sbin && ln -sf rc setpasswd
	cd $(INSTALLDIR)/sbin && ln -sf rc wland
ifeq ($(CONFIG_PPTPD),y)
	cd $(INSTALLDIR)/sbin && ln -sf rc poptop
endif

ifeq ($(CONFIG_SNMP),y)
	cd $(INSTALLDIR)/sbin && ln -sf rc wol
endif

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

$(OBJS): $(CY_DEPS)
