###############################################################
## Makefile for hns 2.10
## $Id: Makefile.in,v 1.64 2000/10/16 13:38:58 kenji Exp $

# diary title
NIKKITITLE	= HNS: Hoge's Diary
# mail address for web diary page
USERMAIL        = hoge@foo.bar.jp
# Author
AUTHOR		= 
# mail address for receiving message (null is no receiving)
MESMAIL		= 
# To: address for mail2nikki (only used in webif)
DIARYMAIL	= hoge@foo.bar.jp
# From: address for mail2nikki
FROMADDR	= hoge@foo.bar.jp
# password to update for mail2nikki 
PASSWORD	= hirakegoma
# ON if want Form of Namazu for hns
UNAGIUSE        = OFF
# diary URL
MYDIARYURI	= http://www.foo.bar.jp/~hoge/diary/
# theme name (default = japanese)
THEME		= japanese
# Permit Hoshino Antenna(http://www.h14m.org/hoshino/) Registration?
# OK or NG
ANTENNA		= NG
# new reverse display? 0 -> No, 1 -> Yes 
NEWREVERSE	= 0
# starting year of your diary
STARTYEAR	= 1998

PERL_PATH       = /usr/local/bin/perl
SENDMAIL_PATH	= /usr/sbin/sendmail
NKF_PATH	= /usr/local/bin/nkf
FTP_PATH	= /usr/bin/ftp

# ftp server name (used only in webif ftp mode)
FTPHOST		= localhost
# ftp user name (used only in webif ftp mode)
FTPUSER		= hoge

HOMEDIR		= $(HOME)
DIARYDIR	= $(HOMEDIR)/diary
HTMLDIR		= $(HOMEDIR)/public_html/diary
CONFDIR		= $(DIARYDIR)/conf
LOGDIR		= $(DIARYDIR)/log
BINDIR		= $(DIARYDIR)/bin
POSPEDIR	= $(DIARYDIR)/pospe
ICONDIR		= $(HTMLDIR)/icons
CATDIR		= $(HTMLDIR)/cat
# diary directory path at ftp login
# (used only webif ftp mode)
FTPDIARYDIR	= $(HOMEDIR)/diary

ISYSTEMDIR	= contrib/isystem
IDIR		= $(HTMLDIR)/i

HNS		= config.ph mail2nikki.pl log.cgi title.cgi clear_cache.cgi\
		  title_wrapper.cgi rotate_log.cgi admini.cgi webif.cgi\
		  view.cgi make-rurimap.cgi pospe2hnf.pl index.cgi \
		  make-diary.pl di.cgi logging.pl
ISYSTEM		= i-system-config.ph i-system-index.cgi

hns:		$(HNS)
isystem:	$(ISYSTEM)
all:		hns isystem

config.ph:
	rm -f public_html/diary/$@
	sed -e "s!%NIKKITITLE%!$(NIKKITITLE)!g" \
	    -e 's!%USERMAIL%!$(USERMAIL)!g' \
	    -e 's!%DIARYDIR%!$(DIARYDIR)!g' \
	    -e 's!%UNAGIUSE%!$(UNAGIUSE)!g' \
	    -e 's!%MYDIARYURI%!$(MYDIARYURI)!g' \
	    -e 's!%THEME%!$(THEME)!g' \
	    -e 's!%ANTENNA%!$(ANTENNA)!g' \
	    -e 's!%HTMLDIR%!$(HTMLDIR)!g' \
	    -e 's!%AUTHOR%!$(AUTHOR)!g' \
	    -e 's!%MESMAIL%!$(MESMAIL)!g' \
	    -e 's!%NEWREVERSE%!$(NEWREVERSE)!g' \
	    -e 's!%STARTYEAR%!$(STARTYEAR)!g' \
	    public_html/diary/config.ph.in > public_html/diary/$@

index.cgi:
	rm -f public_html/diary/$@
	sed -e 's!%PERL_PATH%!$(PERL_PATH)!g' \
	    -e 's!%HTMLDIR%!$(HTMLDIR)!g' \
	    public_html/diary/index.cgi.in > public_html/diary/$@

log.cgi:
	rm -f tools/log/$@
	sed -e 's!%PERL_PATH%!$(PERL_PATH)!g' \
	    -e 's!%DIARYDIR%!$(DIARYDIR)!g' \
	    tools/log/log.cgi.in > tools/log/$@

mail2nikki.pl:
	rm -f tools/mail2nikki/$@
	sed -e 's!%PERL_PATH%!$(PERL_PATH)!g' \
	    -e 's!%HTMLDIR%!$(HTMLDIR)!g' \
	    -e 's!%DIARYDIR%!$(DIARYDIR)!g' \
	    -e 's!%FROMADDR%!$(FROMADDR)!g' \
	    -e 's!%PASSWORD%!$(PASSWORD)!g' \
	    -e 's!%SENDMAIL_PATH%!$(SENDMAIL_PATH)!g' \
	    -e 's!%NKF_PATH%!$(NKF_PATH)!g' \
	    tools/mail2nikki/mail2nikki.pl.in > tools/mail2nikki/$@

pospe2hnf.pl:
	rm -f tools/pospe2hnf/$@
	sed -e 's!%PERL_PATH%!$(PERL_PATH)!g' \
	    -e 's!%DIARYDIR%!$(DIARYDIR)!g' \
	    -e 's!%HTMLDIR%!$(HTMLDIR)!g' \
	    -e 's!%NKF_PATH%!$(NKF_PATH)!g' \
	    tools/pospe2hnf/pospe2hnf.pl.in > tools/pospe2hnf/$@

title.cgi:
	rm -f tools/title/$@
	sed -e 's!%PERL_PATH%!$(PERL_PATH)!g' \
	    -e 's!%DIARYDIR%!$(DIARYDIR)!g' \
	    -e 's!%HTMLDIR%!$(HTMLDIR)!g' \
	    -e 's!%NKF_PATH%!$(NKF_PATH)!g' \
	    tools/title/title.cgi.in > tools/title/$@

title_wrapper.cgi:
	rm -f tools/title_wrapper/$@
	sed -e 's!%PERL_PATH%!$(PERL_PATH)!g' \
	    tools/title_wrapper/title_wrapper.cgi.in > tools/title_wrapper/$@

rotate_log.cgi:
	rm -f tools/rotate_log/$@
	sed -e 's!%PERL_PATH%!$(PERL_PATH)!g' \
	    -e 's!%DIARYDIR%!$(DIARYDIR)!g' \
	    tools/rotate_log/rotate_log.cgi.in > tools/rotate_log/$@

admini.cgi:
	rm -f tools/admini/$@
	sed -e 's!%PERL_PATH%!$(PERL_PATH)!g' \
	    tools/admini/admini.cgi.in > tools/admini/$@

view.cgi:
	rm -f tools/view/$@
	sed -e 's!%PERL_PATH%!$(PERL_PATH)!g' \
	    tools/view/view.cgi.in > tools/view/$@

make-rurimap.cgi:
	rm -f tools/make-rurimap/$@
	sed -e 's!%PERL_PATH%!$(PERL_PATH)!g' \
	    -e 's!%SENDMAIL_PATH%!$(SENDMAIL_PATH)!g' \
	    tools/make-rurimap/make-rurimap.cgi.in > tools/make-rurimap/$@

webif.cgi:
	rm -f tools/webif/$@
	sed -e 's!%PERL_PATH%!$(PERL_PATH)!g' \
	    -e 's!%DIARYDIR%!$(DIARYDIR)!g' \
	    -e 's!%FROMADDR%!$(FROMADDR)!g' \
	    -e 's!%DIARYMAIL%!$(DIARYMAIL)!g' \
	    -e 's!%SENDMAIL_PATH%!$(SENDMAIL_PATH)!g' \
	    -e 's!%FTP_PATH%!$(FTP_PATH)!g' \
	    -e 's!%FTP_HOST%!$(FTPHOST)!g' \
	    -e 's!%FTP_USER%!$(FTPUSER)!g' \
	    -e 's!%FTP_DIARY_DIR%!$(FTPDIARYDIR)!g' \
	    tools/webif/webif.cgi.in > tools/webif/$@

clear_cache.cgi:
	rm -f tools/clear_cache/$@
	sed -e 's!%PERL_PATH%!$(PERL_PATH)!g' \
	    tools/clear_cache/clear_cache.cgi.in > tools/clear_cache/$@

make-diary.pl:
	rm -f tools/make-diary/$@
	sed -e 's!%HTMLDIR%!$(HTMLDIR)!g' \
            tools/make-diary/make-diary.pl.in > tools/make-diary/$@

di.cgi:
	rm -f tools/di/$@
	sed -e 's!%PERL_PATH%!$(PERL_PATH)!g' \
	    tools/di/di.cgi.in > tools/di/$@

logging.pl:
	rm -f tools/static/$@
	sed -e 's!%PERL_PATH%!$(PERL_PATH)!g' \
	    tools/static/logging.pl.in > tools/static/$@

i-system-config.ph:
	if [ -d $(ISYSTEMDIR) ]; then \
	rm -f $(ISYSTEMDIR)/config.ph; \
	sed -e "s!%USERMAIL%!$(USERMAIL)!g" \
	    -e "s!%SENDMAIL%!$(SENDMAIL_PATH)!g" \
	    -e "s!%MYDIARYURI%!$(MYDIARYURI)!g" \
	    -e "s!%DIARYDIR%!$(DIARYDIR)!g" \
	    -e "s!%DEFHTML%!$(IDIR)!g" \
	    -e "s!%NIKKITITLE%!$(NIKKITITLE)!g" \
	    $(ISYSTEMDIR)/config.ph.in > $(ISYSTEMDIR)/config.ph; \
	fi

i-system-index.cgi:
	if [ -d $(ISYSTEMDIR) ]; then \
	rm -f $(ISYSTEMDIR)/index.cgi; \
	sed -e "s!%PERL_PATH%!$(PERL_PATH)!g" \
	    $(ISYSTEMDIR)/index.cgi.in > $(ISYSTEMDIR)/index.cgi; \
	fi

################################################################
# install

install-hns: hns
	if [ ! -d $(DIARYDIR) ]; then \
	  mkdir -p $(DIARYDIR); \
	fi
	if [ ! -d $(DIARYDIR)/mail ]; then \
	  mkdir -p $(DIARYDIR)/mail; \
	fi
	chmod 700 $(DIARYDIR)/mail
	if [ ! -d $(HTMLDIR) ]; then \
	  mkdir -p $(HTMLDIR); \
	fi
	if [ ! -d $(CONFDIR) ]; then \
	  mkdir -p $(CONFDIR); \
	fi
	if [ ! -d $(LOGDIR) ]; then \
	  mkdir -p $(LOGDIR); \
	fi
	if [ ! -d $(LOGDIR)/OLD ]; then \
	  mkdir -p $(LOGDIR)/OLD; \
	  chmod 757 $(LOGDIR)/OLD; \
	fi
	if [ ! -d $(LOGDIR)/LM ]; then \
	  mkdir -p $(LOGDIR)/LM; \
	  chmod 757 $(LOGDIR)/LM; \
	fi
	if [ ! -d $(BINDIR) ]; then \
	  mkdir -p $(BINDIR); \
	fi
	if [ ! -d $(POSPEDIR) ]; then \
	  mkdir -p $(POSPEDIR); \
	fi
	chmod 700 $(POSPEDIR)
	if [ ! -d $(ICONDIR) ]; then \
	  mkdir -p $(ICONDIR); \
	fi
	if [ ! -d $(CATDIR) ]; then \
	  mkdir -p $(CATDIR); \
	fi
	if [ ! -d $(DIARYDIR)/cache ]; then \
	  mkdir -p $(DIARYDIR)/cache; \
	fi
	chmod 757 $(DIARYDIR)/cache; 
	if [ ! -d $(DIARYDIR)/cache_static ]; then \
	  mkdir -p $(DIARYDIR)/cache_static; \
	fi

	################
	# diary/conf
	touch $(CONFDIR)/head.txt
	touch $(CONFDIR)/foot.txt
	if [ -f $(CONFDIR)/robotlist.txt ]; then \
	  mv $(CONFDIR)/robotlist.txt $(CONFDIR)/robotlist.txt-old; \
	fi
	cp -p diary/conf/robotlist.txt $(CONFDIR)
	if [ -f $(CONFDIR)/browser_list.txt ]; then \
	  mv $(CONFDIR)/browser_list.txt $(CONFDIR)/browser_list.txt-old; \
	fi
	cp -p diary/conf/browser_list.txt $(CONFDIR)
	if [ -f $(CONFDIR)/i_browser.txt ]; then \
	  mv $(CONFDIR)/i_browser.txt $(CONFDIR)/i_browser.txt-old; \
	fi
	cp -p diary/conf/i_browser.txt $(CONFDIR)
	if [ -f $(CONFDIR)/browser_style.txt ]; then \
	  mv $(CONFDIR)/browser_style.txt $(CONFDIR)/browser_style.txt-old; \
	fi
	cp -p diary/conf/browser_style.txt $(CONFDIR)
	touch $(CONFDIR)/ruri_map.txt
	touch $(CONFDIR)/auth_ruri.txt
	touch $(CONFDIR)/rlink.txt
	touch $(CONFDIR)/alias.txt
	touch $(CONFDIR)/group.txt

	################
	# diary/log
	touch $(LOGDIR)/LastModified
	chmod 646 $(LOGDIR)/LastModified
	touch $(LOGDIR)/referer_log
	chmod 646 $(LOGDIR)/referer_log
	touch $(LOGDIR)/denial_log
	chmod 646 $(LOGDIR)/denial_log
	touch $(LOGDIR)/cache_log
	chmod 646 $(LOGDIR)/cache_log
	if [ ! -f $(LOGDIR)/message-by-user.txt ]; then \
	  touch $(LOGDIR)/message-by-user.txt; \
	  chmod 646 $(LOGDIR)/message-by-user.txt; \
	fi
	if [ ! -f $(LOGDIR)/ruri-map-by-user.txt ]; then \
	  touch $(LOGDIR)/ruri-map-by-user.txt; \
	  chmod 646 $(LOGDIR)/ruri-map-by-user.txt; \
	fi
	touch $(LOGDIR)/dns_cache
	chmod 646 $(LOGDIR)/dns_cache
	touch $(LOGDIR)/link_log
	chmod 646 $(LOGDIR)/link_log

	################
	# diary/bin
	if [ -f $(BINDIR)/mail2nikki.pl ]; then \
	  mv $(BINDIR)/mail2nikki.pl $(BINDIR)/mail2nikki.pl-old; \
	fi
	cp -p tools/mail2nikki/mail2nikki.pl $(BINDIR)
	chmod 700 $(BINDIR)/mail2nikki.pl
	cp -p tools/make-diary/make-diary.pl $(BINDIR)/make-diary
	chmod 700 $(BINDIR)/make-diary

	################
	# diary/pospe
	if [ -f $(POSPEDIR)/pospe2hnf.pl ]; then \
	  mv $(POSPEDIR)/pospe2hnf.pl $(POSPEDIR)/pospe2hnf.pl-old; \
	fi
	cp -p tools/pospe2hnf/pospe2hnf.pl $(POSPEDIR)
	chmod 700 $(POSPEDIR)/pospe2hnf.pl

	################
	# tools
	cp -p tools/title/title.cgi $(HTMLDIR)
	chmod 705 $(HTMLDIR)/title.cgi
	if [ -f $(HTMLDIR)/log.cgi ]; then \
	  mv $(HTMLDIR)/log.cgi $(HTMLDIR)/log.cgi-old; \
	fi
	cp -p tools/log/log.cgi $(HTMLDIR)
	chmod 705 $(HTMLDIR)/log.cgi
	cp -p tools/title_wrapper/title_wrapper.cgi $(HTMLDIR)
	chmod 705 $(HTMLDIR)/title_wrapper.cgi
	cp -p tools/rotate_log/rotate_log.cgi $(HTMLDIR)
	chmod 705 $(HTMLDIR)/rotate_log.cgi
	cp -p tools/admini/admini.cgi $(HTMLDIR)
	chmod 705 $(HTMLDIR)/admini.cgi
	cp -p tools/view/view.cgi $(HTMLDIR)
	chmod 705 $(HTMLDIR)/view.cgi
	cp -p tools/make-rurimap/make-rurimap.cgi $(HTMLDIR)
	chmod 705 $(HTMLDIR)/make-rurimap.cgi
	cp -p tools/webif/webif.cgi $(HTMLDIR)
	chmod 705 $(HTMLDIR)/webif.cgi
	cp -p tools/clear_cache/clear_cache.cgi $(HTMLDIR)
	chmod 705 $(HTMLDIR)/clear_cache.cgi
	cp -p tools/di/di.cgi $(HTMLDIR)
	chmod 705 $(HTMLDIR)/di.cgi
	cp -p tools/static/logging.pl $(HTMLDIR)
	chmod 705 $(HTMLDIR)/logging.pl

	################
	# icons, cat, themes
	cp -p public_html/diary/icons/README* $(ICONDIR)
	cp -p public_html/diary/icons/*.png $(ICONDIR)
	cp -pr public_html/diary/anti-windoze $(HTMLDIR)
	cp -pr public_html/diary/ruribaka $(HTMLDIR)
	cp -pr public_html/diary/japanese $(HTMLDIR)
	cp -pr public_html/diary/english $(HTMLDIR)
	touch $(CATDIR)/cat.txt
	cp -p public_html/diary/cat/*.png $(CATDIR)

	################
	# hnf sample
	if [ ! -d $(DIARYDIR)/2000 ]; then \
	  mkdir -p $(DIARYDIR)/2000; \
	  cp -p diary/2000/d20001031.hnf $(DIARYDIR)/2000; \
	  cp -p diary/2000/y200010 $(DIARYDIR)/2000; \
	fi
	if [ ! -f $(DIARYDIR)/todo ]; then \
	  cp -p diary/todo $(DIARYDIR); \
	fi
	if [ ! -f $(DIARYDIR)/repeat ]; then \
	  cp -p diary/repeat $(DIARYDIR); \
	fi

	################
	# lib, cgi, config.ph, .htaccess
	if [ -f $(HTMLDIR)/config.ph ]; then \
	  mv -f $(HTMLDIR)/config.ph $(HTMLDIR)/config.ph-old; \
	fi
	cp -p public_html/diary/config.ph $(HTMLDIR)
	cp -pr public_html/diary/lib $(HTMLDIR)
	cp -p public_html/diary/*.html $(HTMLDIR)
	cp -p public_html/diary/*.cgi $(HTMLDIR)
	if [ -f $(HTMLDIR)/.htaccess ]; then \
	  cp -p $(HTMLDIR)/.htaccess $(HTMLDIR)/.htaccess-old; \
	fi
	cp -p public_html/diary/dot.htaccess $(HTMLDIR)/.htaccess
	chmod 705 $(HTMLDIR)/index.cgi
	rm -rf $(HTMLDIR)/*/CVS
	rm -rf $(HTMLDIR)/lib/*/CVS
	rm -rf $(HTMLDIR)/lib/*/*/CVS
	################
	# README
	cat README.ja

install-isystem: isystem
	################
	# i system
	if [ ! -d $(IDIR) ]; then \
	  mkdir $(IDIR); \
	fi
	if [ -d $(ISYSTEMDIR) ]; then \
	  cp -p $(ISYSTEMDIR)/onccnv.pl $(IDIR); \
	  cp -p $(ISYSTEMDIR)/config.ph $(IDIR); \
	  cp -p $(ISYSTEMDIR)/index.cgi $(IDIR); \
	  chmod +x $(IDIR)/index.cgi; \
	fi
	if [ ! -d $(LOGDIR)/lock ]; then \
	  mkdir $(LOGDIR)/lock; \
	fi
	touch $(LOGDIR)/isystem.cnt
	touch $(LOGDIR)/isystem.dat
	touch $(LOGDIR)/isystem.acc
	chmod 777 $(LOGDIR)/lock
	chmod 666 $(LOGDIR)/isystem.*

install:	all install-hns install-isystem
	
clean:
	rm -f public_html/diary/config.ph
	rm -f public_html/diary/index.cgi
	rm -f tools/mail2nikki/mail2nikki.pl
	rm -f tools/log/log.cgi
	rm -f tools/title/title.cgi
	rm -f tools/title_wrapper/title_wrapper.cgi
	rm -f tools/rotate_log/rotate_log.cgi
	rm -f tools/admini/admini.cgi
	rm -f tools/view/view.cgi
	rm -f tools/make-rurimap/make-rurimap.cgi
	rm -f tools/pospe2hnf/pospe2hnf.pl
	rm -f tools/webif/webif.cgi
	rm -f tools/clear_cache/clear_cache.cgi

