################################################################
# Makefile: static creating and uploading to web server
#
# $Id: Makefile,v 1.11 2000/12/08 15:28:15 tom Exp $
################################################################

################
# for static mode
HTML_SUFFIX	=	html
RECENT_HTML	=	index.${HTML_SUFFIX}

################
# for uploading
# change monthly
YEAR		=	2000
MONTH		=	10

## server setting
FTP_SERVER		=	foo.bar.com
## absolute path
USER_DIR		=	public_html
SERVER_WEB_DIARY_DIR	=	~/${USER_DIR}/d
SERVER_DIARY_DIR	=	~/${USER_DIR}/d/diary

## local dir
DIARY_DIR		=	diary

## FTP client
# dos telnet (ignore .netrc)
FTP		=	ftp -n -s:${TMPFILE}
# enable .netrc
#FTP		=	cat ${TMPFILE} | ftp

## select your mode
MODE		=	dynamic
#MODE		=	static

## you don't need change
TARGET_STATIC	=	${RECENT_HTML} d[1-9]*.${HTML_SUFFIX} \
			summary.${HTML_SUFFIX} dictionary.${HTML_SUFFIX} \
			url.${HTML_SUFFIX}
TARGET_DYNAMIC	=	*skelton.html
TMPFILE		=	ftp.tmp

################################################################
all:
	perl static.pl

recent:
	perl static.pl -r

this:
	perl static.pl -t

sig:
	perl update_sig.pl

split:
	# for monthly devided tdf
	perl split.pl

split_static:
	perl split.pl
	perl static.pl -t

autosplit:
	perl autosplit.pl

passwd: password
password:
	perl mkpasswd.pl

cust: customize
customizer: customize
customize:
	perl customizer.pl

clean-cache:
	if [ -d cache ] ; then\
		rm -f cache/*; \
	fi
	if [ -d cache_static ] ; then \
		rm -f cache_static/*; \
	fi

clean:  clean-cache
	rm -f *~ ${RECENT_HTML} d[1-9]*.${HTML_SUFFIX} *-old \
	dictionary.${HTML_SUFFIX} url.${HTML_SUFFIX} summry.${HTML_SUFFIX} \
	hina.di


################
# uploading

# default is static
# if you choose dynamic mode, then change comment-out
upload: upload_${MODE}


# static
upload_static: init_tmp ${TARGET_STATIC}
	echo cd ${SERVER_WEB_DIARY_DIR} >> ${TMPFILE}
	(for f in $? ; do echo put $$f; done) >> ${TMPFILE}
	echo quit >> ${TMPFILE}
	${FTP} ${FTP_SERVER}
	rm -f ${TMPFILE}
	touch $@

# dynamic
upload_dynamic : init_tmp upload_datadir upload_confdir upload_month upload_tdf upload_dynamic_web
	# diary dir/
	echo quit >> ${TMPFILE}
	${FTP} ${FTP_SERVER}
	rm -f ${TMPFILE}
	touch $@

upload_dynamic_web : ${TARGET_DYNAMIC}
	# web diary dir
	echo cd ${SERVER_WEB_DIARY_DIR} >> ${TMPFILE}
	(for f in $? ; do echo put $$f; done) >> ${TMPFILE}
	touch $@	

upload_datadir : ${DIARY_DIR}/dat/*.dat
	#  dat/
	echo cd ${SERVER_DIARY_DIR}/dat >> ${TMPFILE}
	echo nmap ${DIARY_DIR}/dat/\$$1 \$$1 >> ${TMPFILE}
	(for f in $? ; do echo put $$f; done) >> ${TMPFILE}	
	echo nmap >> ${TMPFILE}
	touch $@

upload_confdir : ${DIARY_DIR}/conf/*.txt
	#  conf/
	echo cd ${SERVER_DIARY_DIR}/conf >> ${TMPFILE}
	echo nmap ${DIARY_DIR}/conf/\$$1 \$$1 >> ${TMPFILE}
	(for f in $? ; do echo put $$f; done) >> ${TMPFILE}	
	echo nmap >> ${TMPFILE}
	touch $@

upload_month: ${DIARY_DIR}/${YEAR}/${MONTH}
	echo cd ${SERVER_DIARY_DIR}/${YEAR} >>${TMP}
	echo mkdir ${MONTH} >> ${TMP}
	touch $@

upload_tdf : ${DIARY_DIR}/${YEAR}/${MONTH}/*.tdf
	echo cd ${SERVER_DIARY_DIR}/${YEAR}/${MONTH} >> ${TMPFILE}
	echo nmap ${DIARY_DIR}/${YEAR}/${MONTH}/\$$1 \$$1 >> ${TMPFILE}
	(for f in $? ; do echo put $$f; done) >> ${TMPFILE}	
	echo nmap >> ${TMPFILE}
	touch $@

init_tmp:
	# .ftp_login is needed if MS-DOS
	if [ "${WINDIR}" = "" ] ; then \
		touch .ftp_login; \
	fi
	if [ ! -f .ftp_login ] ; then \
		echo "ERROR: create .ftp_login, such as "; \
		echo "user your-name"; \
		echo "your-password"; \
		exit 1; \
	fi
	cp .ftp_login ${TMPFILE};
	echo bin >> ${TMPFILE}

clean-tmp:
	rm ftp.tmp

###
# for tom
cmt: commit

commit:
	cvs commit -m nul

tdf:
	(cd ../../diary ; make cmt)

server:
	(cd ../../diary; make server)

# end of Makefile
################################################################
