SHELL_PATH = etc/init.d

SBIN_PATH = sbin
BIN_PATH = home/httpd/cgi-bin/network
ERROR_PATH = home/httpd/errors
INC_UNICODE_PATH = ${BIN_PATH}/inc
#INC_CODEPAGE_PATH = ${BIN_PATH}/inc-CODEPAGE
HTML_PATH = ${BIN_PATH}/html
HELP_PATH = ${BIN_PATH}/help

CC = ${CROSS_COMPILE}gcc
OBJFLAGS = -fPIC -Wall -c
APPCFLAGS = -s -O2
DEBUGFLAGS = -g -DDEBUG
CGIPROGS = network.cgi
PROGS = init_nic
LIBS = -L${TARGET_PREFIX}/usr/lib -luLinux_Storage -luLinux_NAS -luLinux_cgi -luLinux_config -luLinux_PDC -luLinux_statistics -luLinux_quota -luLinux_Util -lpthread
#-luLinux_NAS -luLinux_cgi -luLinux_config -lpthread
INCLUDE = -I${NAS_LIB_PATH}/NAS -I${NAS_LIB_PATH}/config -I${NAS_LIB_PATH}/include -I${NAS_LIB_PATH}/uLinux -I${NAS_LIB_PATH}/cgi
OBJS = network.o nic_wan.o nic_lan.o nic_ms.o nic_apple.o nic_nfs.o nic_webfs.o nic_getinfo.o nic_view.o wlan_chk.o nic_web.o nic_photo.o nic_download.o

SHELL = /bin/sh
srcdir = .

SUBDIR = lan_setting prn_setting ftp_setting dns_setting netware ddns_setting wlan_setting
INSTALL = install
TAGFILE = tags
Make = make

all:	$(PROGS) $(CGIPROGS) ${SUBDIR}

${SUBDIR} :	FRC
		cd $@; ${Make} ${MFLAGS} CC="${CC}"

FRC :

tags :
			for i in ${SUBDIR}; do \
				(cd $$i; ${MAKE} ${MFLAGS} DEFS="${DEFS}" \
				TAGSFILE=../${TAGSFILE} tags); \
			done


%.o:			%.c %.h
			$(CC) -O -Wall -c $< $(INCLUDE)

test.o:			test.c 
			$(CC) -c test.c $(INCLUDE)

test:			$(OBJS) test.o
			$(CC) test.o $(LIBS) -o $@

network.cgi :		$(OBJS) network.o
			$(CC) $(DEBUGFLAGS) $(APPCFLAGS) $(OBJS) $(LIBS) -o $@

nic_getinfo.o:		nic_getinfo.c
			$(CC) $(INCLUDE) -c $<

wlan_chk.o:		wlan_chk.c
			$(CC) $(INCLUDE) -c $<

init_nic.o:		init_nic.c
			$(CC) -c init_nic.c $(INCLUDE)

init_nic :		$(OBJS) init_nic.o
			$(CC) $(APPCFLAGS) wlan_chk.o nic_getinfo.o init_nic.o $(LIBS) -o $@

.PHONY : clean install 

install :
		$(SHELL) $(srcdir)/install.sh ${ROOT_PATH}/${BIN_PATH} ${ROOT_PATH}/${BIN_PATH}/images ${ROOT_PATH}/${ERROR_PATH} ${ROOT_PATH}/${INC_UNICODE_PATH} ${ROOT_PATH}/${INC_CODEPAGE_PATH} ${ROOT_PATH}/${HTML_PATH} ${ROOT_PATH}/$(HELP_PATH) ${ROOT_PATH}
#		install -o root -g root -m 755 -s /bin/cut ${ROOT_PATH}/${SBIN_PATH}
#		install -o root -g root -m 755 -s /bin/echo ${ROOT_PATH}/bin
		install -o root -g root -m 755 $(PROGS) ${ROOT_PATH}/${SBIN_PATH}
		install -o root -g root -m 755 $(CGIPROGS) ${ROOT_PATH}/${BIN_PATH}
		install -o root -g root -m 644 *.def ${ROOT_PATH}/${BIN_PATH}
		rm ${ROOT_PATH}/${SBIN_PATH}/nic_getinfo -f
		rm ${ROOT_PATH}/${SBIN_PATH}/wlan_chk -f
		ln -s $(PROGS) ${ROOT_PATH}/${SBIN_PATH}/nic_getinfo
		ln -s $(PROGS) ${ROOT_PATH}/${SBIN_PATH}/wlan_chk
		install -o root -g root -m 644 html/*.html ${ROOT_PATH}/${HTML_PATH}
		install -o root -g root -m 644 inc/*.js ${ROOT_PATH}/${INC_UNICODE_PATH}
		#install -o root -g root -m 755 setup_smb.sh ${ROOT_PATH}/usr/bin
#		install -o root -g root -m 644 inc-CODEPAGE/*.js ${ROOT_PATH}/${INC_CODEPAGE_PATH}
#		/bin/ln -sf /${INC_CODEPAGE_PATH} ${ROOT_PATH}/${BIN_PATH}/inc
#		install -o root -g root -m 755 network.sh ${ROOT_PATH}/${SHELL_PATH}
#		install -o root -g root -m 755 pptp.sh ${ROOT_PATH}/${SHELL_PATH}
#		install -o root -g root -m 755 dhcpcd.sh ${ROOT_PATH}/${SHELL_PATH}
		for i in ${SUBDIR}; do \
			(cd $$i; ${MAKE} ${MFLAGS} CC="${CC}" \
			INSTALL="${INSTALL}" DESDIR="${DESDIR}" install); \
		done
clean :
	echo 'cleaning ...'
	$(RM) $(PROGS) core *.o $(CGIPROGS)
	for i in ${SUBDIR}; do \
		(cd $$i; ${MAKE} ${MFLAGS} clean); \
	done

       
