include ../.config
include ../../.config
CONFIG_NEW_GUI=$(shell cat ${WWW_PATH}/www/.config|grep CONFIG_NEW_GUI|awk 'BEGIN {FS="="} {print $$2}')
CONFIG_AP=$(shell cat ${WWW_PATH}/www/.config|grep CONFIG_AP|awk 'BEGIN {FS="="} {print $$2}')
CONFIG_WEB_ACCESS_FILE=$(shell cat ${WWW_PATH}/www/.config|grep CONFIG_WEB_ACCESS_FILE|awk 'BEGIN {FS="="} {print $$2}')
CONFIG_WEB_ACCESS_FILE=$(shell cat ${WWW_PATH}/www/.config|grep CONFIG_WEB_ACCESS_FILE|awk 'BEGIN {FS="="} {print $$2}')
CONFIG_WEB_ACCESS_FILE_HTML5=$(shell cat ${WWW_PATH}/www/.config|grep CONFIG_WEB_ACCESS_FILE_HTML5|awk 'BEGIN {FS="="} {print $$2}')

MODS=mod_access.so mod_cgi.so mod_indexfile.so mod_accesslog.so mod_dirlisting.so mod_staticfile.so mod_graph_auth.so mod_auth.so mod_expire.so mod_evasive.so mod_flv_streaming.so mod_setenv.so
ifeq (y,$(filter y,$(CONFIG_PARENTAL_CONTROL) $(CONFIG_WEB_ACCESS_FILE_HTML5)))
MODS += mod_alias.so
endif

ifeq ($(CONFIG_PARENTAL_CONTROL),y) && ($(CONFIG_WEB_ACCESS_FILE_HTML5),y)  
MODS += mod_alias.so
endif

ifeq ($(CONFIG_DOMAIN_SHAREPORT),y)
MODS += mod_redirect.so
MODS += mod_ssldeny.so
endif

ifeq ($(CONFIG_STREAMBOOST), y)
MODS += mod_fastcgi.so
endif

install romfs:
	#unset INSTALL;$(MAKE) install -C lighttpd-1.4.28
	$(INSTALL) -d $(TARGET)/sbin
	##KK: If not compile with libpcre, files will be put on different folder
	if [ -e lighttpd-1.4.28/src/lighttpd ]; then \
		$(INSTALL) -m 755 lighttpd-1.4.28/src/lighttpd $(TARGET)/sbin; \
	fi
	if [ -e lighttpd-1.4.28/src/lighttpd ]; then \
		$(INSTALL) -m 755 lighttpd-1.4.28/src/lighttpd-angel $(TARGET)/sbin; \
	fi
	if [ -e lighttpd-1.4.28/src/.libs/lighttpd ]; then \
		$(INSTALL) -m 755 lighttpd-1.4.28/src/.libs/lighttpd $(TARGET)/sbin; \
	fi
	if [ -e lighttpd-1.4.28/src/.libs/lighttpd-angel ]; then \
		$(INSTALL) -m 755 lighttpd-1.4.28/src/.libs/lighttpd-angel $(TARGET)/sbin; \
	fi
	$(INSTALL) -d $(TARGET)/lib
	for i in $(MODS);do \
		$(INSTALL) -m 755 lighttpd-1.4.28/src/.libs/$$i $(TARGET)/lib;	\
	done
	#$(INSTALL) -m 755 lighttpd-1.4.28/src/.libs/*.so $(TARGET)/lib
	$(INSTALL) -d $(TARGET)/www/cgi

	$(INSTALL) -m 644 rootfs/etc/*.conf $(TARGET)/etc
	$(INSTALL) -d $(TARGET)/etc/conf.d/
	$(INSTALL) -m 644 rootfs/etc/conf.d/*.conf $(TARGET)/etc/conf.d/
	$(INSTALL) -m 755 rootfs/etc/restart_lighttpd.sh $(TARGET)/etc
	ln -sf /tmp/lighttpd/lighttpd.conf $(TARGET)/etc/lighttpd.conf
	ln -sf /tmp/lighttpd/lighttpd.user $(TARGET)/etc/lighttpd.user
	$(INSTALL) -m 644 rootfs/etc/conf.d/*.conf $(TARGET)/etc/conf.d
	ln -sf /tmp/lighttpd/auth.conf $(TARGET)/etc/conf.d/auth.conf
	$(INSTALL) -d $(TARGET)/www
	$(INSTALL) -m 744 rootfs/www/*.cgi $(TARGET)/www
ifeq ($(CONFIG_NEW_GUI),y)
	$(INSTALL) -m 744 rootfs/www/hnap.cgi $(TARGET)/www
	sed -i '/".xml"  => "\/www\/cgi\/ssi",/d' $(TARGET)/etc/conf.d/cgi.conf
	sed -i 's/graph_auth.login_page = "login_pic.asp"/graph_auth.login_page = "Login.html"/g' $(TARGET)/etc/conf.d/graph_auth.conf 
	sed -i 's/graph_auth.wizard_page = "setup_wizard.asp"/graph_auth.wizard_page = "Wizard.html"/g' $(TARGET)/etc/conf.d/graph_auth.conf 
	touch $(TARGET)/www/fwupload.cgi
endif
	#ROUTER:
	touch $(TARGET)/www/reboot.cgi
	touch $(TARGET)/www/update_firmw.cgi
	touch $(TARGET)/www/upload_configure.cgi
	touch $(TARGET)/www/upload_tr_ca.cgi
	touch $(TARGET)/www/ping_response.cgi
	touch $(TARGET)/www/ping6_response.cgi
	touch $(TARGET)/www/log_first_page.cgi
	touch $(TARGET)/www/log_last_page.cgi
	touch $(TARGET)/www/log_next_page.cgi
	touch $(TARGET)/www/log_previous_page.cgi
	touch $(TARGET)/www/log_clear_page.cgi
	touch $(TARGET)/www/save_log_page.cgi
	touch $(TARGET)/www/send_log_email.cgi
	touch $(TARGET)/www/online_firmware_check.cgi
	touch $(TARGET)/www/dhcp_revoke.cgi
	touch $(TARGET)/www/upload_lang.cgi
	touch $(TARGET)/www/lp_clear.cgi
	#WIRELESS:
	touch $(TARGET)/www/set_sta_enrollee_pin.cgi
	touch $(TARGET)/www/restore_default_wireless.cgi
	touch $(TARGET)/www/secmark1524.cgi
ifeq ($(CONFIG_AP),y)
	#AP:
	$(INSTALL) -d $(TARGET)/www/ap
	touch $(TARGET)/www/ap/reboot.cgi
	touch $(TARGET)/www/ap/update_firmw.cgi
	touch $(TARGET)/www/ap/upload_lang.cgi
	touch $(TARGET)/www/ap/lp_clear.cgi
	touch $(TARGET)/www/ap/online_firmware_check.cgi
	touch $(TARGET)/www/ap/log_first_page.cgi
	touch $(TARGET)/www/ap/log_last_page.cgi
	touch $(TARGET)/www/ap/log_next_page.cgi
	touch $(TARGET)/www/ap/log_previous_page.cgi
	touch $(TARGET)/www/ap/log_clear_page.cgi
	touch $(TARGET)/www/ap/save_log_page.cgi
	touch $(TARGET)/www/ap/send_log_email.cgi
	touch $(TARGET)/www/ap/restore_default_wireless.cgi
	touch $(TARGET)/www/ap/ping_response.cgi
	touch $(TARGET)/www/ap/ping6_response.cgi
	ln -sf ../save_configure.cgi $(TARGET)/www/ap/save_configure.cgi
	ln -sf ../apply.cgi $(TARGET)/www/ap/apply.cgi
	ln -sf ../apply.cgi $(TARGET)/www/ap/apply_sec.cgi
	touch $(TARGET)/www/ap/upload_configure.cgi
	touch $(TARGET)/www/ap/save_log_page.cgi
	touch $(TARGET)/www/ap/send_log_email.cgi
	ln -sf ../set_sta_enrollee_pin.cgi $(TARGET)/www/ap/set_sta_enrollee_pin.cgi
	ln -sf ../restore_default_wireless.cgi $(TARGET)/www/ap/restore_default_wireless.cgi
	ln -sf ../hnap.cgi $(TARGET)/www/ap/hnap.cgi
endif
ifeq ($(CONFIG_WEB_ACCESS_FILE),y)
	$(INSTALL) -d $(TARGET)/www/file_access
	touch $(TARGET)/www/file_access/upload_file.cgi
	ln -sf ../apply.cgi $(TARGET)/www/file_access/apply.cgi
	ln -sf /tmp/lighttpd/fileaccess.user $(TARGET)/etc/fileaccess.user
	touch $(TARGET)/www/file_access/appaccess_upload_file.cgi
	touch $(TARGET)/www/file_access/appaccess_apply.cgi
endif
ifeq ($(CONFIG_PARENTAL_CONTROL),y)
	cp rootfs/etc/modules.conf.alias $(TARGET)/etc/modules.conf
endif	
ifeq ($(CONFIG_CUSTOMIZE_TR069),y)
	ln -sf /tmp/lighttpd/tr069.user $(TARGET)/etc/tr069.user
	$(INSTALL) -d $(TARGET)/www/tr
	ln -sf ../tr069.cgi $(TARGET)/www/tr/tr069.cgi
endif
ifeq ($(CONFIG_PARENTAL_CONTROL),y)	
	ln -sf /tmp/parentalcontrols $(TARGET)/www/parentalcontrols
	ln -sf /tmp/lighttpd/alias.conf $(TARGET)/etc/conf.d/alias.conf
endif
	#strip... ?
ifeq ($(CONFIG_STREAMBOOST), y)
	rm -f $(TARGET)/etc/conf.d/graph_auth.conf
	$(INSTALL) -m 644 rootfs/etc/conf.d/graph_auth.conf.streamboost $(TARGET)/etc/conf.d/graph_auth.conf
	rm -f $(TARGET)/etc/lighttpd_base.conf
	$(INSTALL) -m 644 rootfs/etc/lighttpd_base.conf.streamboost $(TARGET)/etc/lighttpd_base.conf
	rm -f $(TARGET)/etc/conf.d/cgi.conf
	$(INSTALL) -m 644 rootfs/etc/conf.d/cgi.conf.streamboost $(TARGET)/etc/conf.d/cgi.conf
# cgi.conf
#	rm -rf $(TARGET)/mnt/conf.d/cgi.conf
	mkdir -p $(TARGET)/mnt/conf.d
	$(INSTALL) -m 644 rootfs-wa/etc/conf.d/cgi.conf.streamboost $(TARGET)/mnt/conf.d/cgi.conf
#	rm -rf $(TARGET)/mnt/conf.d/auth_base.conf
#	$(INSTALL) -m 644 rootfs/etc/conf.d/auth_base.conf.streamboost $(TARGET)/etc/conf.d/auth_base.conf
	rm -rf $(TARGET)/etc/conf.d/expire.conf
	$(INSTALL) -m 644 rootfs/etc/conf.d/expire.conf.streamboost $(TARGET)/etc/conf.d/expire.conf
	rm -rf $(TARGET)/etc/conf.d/mime.conf
	$(INSTALL) -m 644 rootfs/etc/conf.d/mime.conf.streamboost $(TARGET)/etc/conf.d/mime.conf
else
	rm -f $(TARGET)/etc/conf.d/graph_auth.conf.streamboost
	rm -f $(TARGET)/etc/lighttpd_base.conf.streamboost
	rm -rf $(TARGET)/mnt/conf.d/cgi.conf.streamboost
#	rm -f $(TARGET)/etc/conf.d/auth_base.conf.streamboost
	rm -rf $(TARGET)/etc/conf.d/expire.conf.streamboost
	rm -rf $(TARGET)/etc/conf.d/mime.conf.streamboost
endif
ifeq ($(CONFIG_WEB_ACCESS_FILE),y)	
	$(INSTALL) -d $(TARGET)/mnt/conf.d
	$(INSTALL) -m 644 rootfs-wa/etc/*.conf $(TARGET)/mnt
	ln -sf /tmp/lighttpd-wa/lighttpd.conf $(TARGET)/mnt/lighttpd.conf
	ln -sf /tmp/lighttpd-wa/lighttpd.user $(TARGET)/mnt/lighttpd.user
	ln -sf /tmp/lighttpd-wa/fileaccess.user $(TARGET)/mnt/fileaccess.user
	$(INSTALL) -m 644 rootfs-wa/etc/conf.d/*.conf $(TARGET)/mnt/conf.d
	ln -sf /tmp/lighttpd-wa/auth.conf $(TARGET)/mnt/conf.d/auth.conf		
endif	
ifeq ($(CONFIG_WEB_ACCESS_FILE_HTML5),y)	
	$(INSTALL) -d $(TARGET)/mnt/conf.d
	$(INSTALL) -m 644 rootfs-waf/etc/*.conf $(TARGET)/mnt
	ln -sf /tmp/lighttpd-wa/lighttpd.conf $(TARGET)/mnt/lighttpd.conf
	ln -sf /tmp/lighttpd-wa/lighttpd.user $(TARGET)/mnt/lighttpd.user
	ln -sf /tmp/lighttpd-wa/fileaccess.user $(TARGET)/mnt/fileaccess.user
	$(INSTALL) -m 644 rootfs-waf/etc/conf.d/*.conf $(TARGET)/mnt/conf.d
	ln -sf /tmp/lighttpd-wa/auth.conf $(TARGET)/mnt/conf.d/auth.conf				
	$(INSTALL) -m 755 lighttpd-1.4.28/src/.libs/lighttpd-angel $(TARGET)/sbin/lighttpd-angel-wa			
endif		

clean:
	
