###############################################################
## Makefile for hns 2.00
## $Id: Makefile,v 1.25.2.5 2000/02/13 08:01:21 kenji Exp $

# diary title
NIKKITITLE	= HNS: Hoge's Diary
# mail address for web diary page
USERMAIL        = hoge@foo.bar.jp
# To: address for mail2nikki(only used in web2nikki)
DIARYMAIL	= hoge\\@foo.bar.jp
# From: address for mail2nikki
FROMADDR	= hoge\\@foo.bar.jp
# password to update for mail2nikki 
PASSWORD	= hirakegoma
# ON if want Namazu for hns Form
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		= OK

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

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

TARGET		= config.ph web2nikki.cgi mail2nikki.pl log.cgi title.cgi\
		  title_wrapper.cgi rotate_log.cgi admini.cgi\
		  view.cgi make-rurimap.cgi pospe2hnf.pl index.cgi


all:	$(TARGET)

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' \
	    public_html/diary/config.ph.in > public_html/diary/$@

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

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

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' \
	    tools/make-rurimap/make-rurimap.cgi.in > tools/make-rurimap/$@

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

install: all
	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 $(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

	################
	# 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_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

	################
	# diary/log
	touch $(LOGDIR)/LastModified
	chmod 646 $(LOGDIR)/LastModified
	#touch $(LOGDIR)/cookie_log
	#chmod 646 $(LOGDIR)/cookie_log
	touch $(LOGDIR)/referer_log
	chmod 646 $(LOGDIR)/referer_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

	################
	# 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/web2nikki/web2nikki.cgi $(HTMLDIR)
	chmod 705 $(HTMLDIR)/web2nikki.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

	################
	# 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; \
	fi
	if [ ! -f $(DIARYDIR)/2000/d20000218.hnf ]; then \
	  cp -p diary/2000/d20000218.hnf $(DIARYDIR)/2000; \
        fi
	if [ ! -f $(DIARYDIR)/2000/y200002 ]; then \
	  cp -p diary/2000/y200002 $(DIARYDIR)/2000; \
	fi
	if [ ! -f $(DIARYDIR)/todo ]; then \
	  cp -p diary/todo $(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)
	cp -p public_html/diary/dot.htaccess $(HTMLDIR)/.htaccess
	chmod 705 $(HTMLDIR)/index.cgi


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/web2nikki/web2nikki.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

