#
# milli_httpd Makefile
#
# THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
# KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
# SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
#
# $Id$
#

# Usage : httpd serverip port
# serverip : httpd socket will bound on this ipaddress
# port : httpd socket will bound on this port
# example : httpd -i br0 -p 80 -s 1(-s https enabled/disabled(1/0) )
# example : httpd -i eth0 -p 443


# Uncomment this to support HTTPS (with OpenSSL)
# Bug : Wait for fix
# find out the current https solution and working flow, try to optimize the source code
#+++ GTK July 11, 2007.
# USE_SSL = y
#--- GTK


# Uncomment this to keep HTTP alive by forking a child process to handle normal HTTP,
# the parent process will watch the status of child process. If child process die, parent will
# revoke http by create new process
#+++ GTK July 10, 2007.
#KEEP_ALIVE = y
#--- GTK

# Uncomment this to display httpd debug message
# HTTPD_DEBUG = y

# Uncomment this to display CGI debug message
#CGI_DEBUG = n

# Uncomment this to make httpd deny access from wireless client
WL_ACL = y

CFLAGS	+=  -Wall -s -Os

ifdef KEEP_ALIVE
	CFLAGS += -DKEEP_ALIVE
endif

ifdef HTTPD_DEBUG
	CFLAGS += -DHTTPD_DEBUG
endif

ifdef CGI_DEBUG
	CFLAGS += -DCGI_DEBUG
endif

ifdef WL_ACL
	CFLAGS += -DWL_ACL
endif

ifdef USE_SSL
	CFLAGS	+= -DUSE_SSL  -DLINUX
	LDFLAGS += -L./matrixssl/src -lmatrixssl
endif

CFLAGS	+= $(PATHNVRAM)
CFLAGS	+= $(PATHUSER)
CFLAGS	+= $(PATHUTILITY)
CFLAGS	+= $(PATHCONF)
CFLAGS	+= $(PATHFLASH)

LDFLAGS += $(LIBUTILILTY)
LDFLAGS	+= $(LIBNVRAM)
LDFLAGS	+= $(LIBFLASH)


ifdef USE_SSL
	OBJS = httpd.o cgi.o ej.o convert.o gemtek.o webs_control.o gemtek_wep_passphrase.o ssl_util.o options.o sslSocket.o 
else
	OBJS = httpd.o cgi.o ej.o convert.o gemtek.o webs_control.o gemtek_wep_passphrase.o options.o
endif

# --- for HNAP ==================
OBJS += hnap/hnap_implementation.o hnap/hnap_host_WRT100N.o hnap/xml_tree.o hnap/linked_list.o hnap/stack.o hnap/xmlparse.o hnap/xmlrole.o hnap/xmltok.o
# --- Gemtek, Dream =============

all: clean matrix_ssl httpd

clean:
	make -C ./matrixssl/src clean
	rm -f *~ httpd

install:
	install -D httpd $(INSTALLDIR)/bin/httpd
	install -D matrixssl/certificate-Gemtek/privkeySrv.pem $(INSTALLDIR)/etc/privkeySrv.pem
	install -D matrixssl/certificate-Gemtek/certSrv.pem $(INSTALLDIR)/etc/certSrv.pem
#	cd $(INSTALLDIR)/bin && ln -sf httpd rmt_mgmt


romfs:
	$(STRIP) httpd
	cp httpd $(ROMFSDIR)/bin/httpd
	cp matrixssl/src/libmatrixssl.so $(ROMFSDIR)/lib
	cp matrixssl/certificate-Gemtek/privkeySrv.pem $(ROMFSDIR)/etc/privkeySrv.pem
	cp matrixssl/certificate-Gemtek/certSrv.pem $(ROMFSDIR)/etc/certSrv.pem

ifdef USE_SSL
#	cp mini_httpd.pem $(ROMFSDIR)/etc/mini_httpd.pem
	cp matrixssl/src/libmatrixssl.so $(ROMFSDIR)/lib
	cp matrixssl/certificate-Gemtek/privkeySrv.pem $(ROMFSDIR)/etc/privkeySrv.pem
	cp matrixssl/certificate-Gemtek/certSrv.pem $(ROMFSDIR)/etc/certSrv.pem
endif
#	cd $(ROMFSDIR)/bin && ln -sf httpd rmt_mgmt

matrix_ssl:
#ifdef USE_SSL
	cd matrixssl/src && $(MAKE) all
#endif

httpd: $(OBJS)
	$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
	$(STRIP) $@
	
%.o: %.c %.h Makefile
	 $(CC) $(CFLAGS) -c $< -o $@
