#
# ptexlive -- Japanese patche collection for TeX Live 2008
#  Nobuyuki Tsuchimura
#

# 'bash' is recommended
BASH	= `which bash`

TARGET	= ptexlive
VER	= `date +%Y%m%d`
TARS	= README README.en ChangeLog* LICENSE Makefile \
	  ptexlive.sample ptexlive.sample.en \
	  common.sh \
	  1check-archive.sh \
	  2extract-src.sh \
	  3make-install.sh \
	  4extract-texmf.sh \
	  5macro.sh \
	  6babel.sh \
	  7font-search.sh \
	  8test.sh \
	  9realloc.sh \

all: all2
all2: all0 fonty test
all3: all0 otf babel fonty test
all0: distclean
	@DATE=`date +%m%d-%H%M`; \
	$(MAKE) make 2>&1 | tee log-$$DATE; \
	echo; echo "Those messages are stored in 'log-$$DATE'."; echo; \
	grep "ptexlive make succeeded." log-$$DATE > /dev/null
make: stage1 stage2 stage3 stage4 stage5
	@echo "ptexlive make succeeded."
	@echo "Your next steps are following."
	@echo "  make otf babel (optional)"
	@echo "  make font (or 'fonty')"
	@echo "  make test"
	@echo "  make install (by root)"
check:stage1
x:    stage2
c:    stage3
texmf:stage4
macro:stage5
otf:  stage5o
babel:stage6
font: stage7
fonty:stage7y
test: stage8
install: stage9

clean:
	rm -rf ptexlive-test-* ptexlive-tmp.* ptexlive-nkf.* *~ \#*\#
distclean:
	$(BASH) ./9realloc.sh distclean
uninstall:
	$(BASH) ./9realloc.sh uninstall

stage1:
	$(BASH) ./1check-archive.sh
stage2:
	$(BASH) ./2extract-src.sh
stage3:
	$(BASH) ./3make-install.sh
stage4:
	$(BASH) ./4extract-texmf.sh
stage5:
	$(BASH) ./5macro.sh clean default utf
stage5o:
	$(BASH) ./5macro.sh otf
stage6:
	@echo "Sorry, not implemented yet."
	@#$(BASH) ./6babel.sh
stage7:
	$(BASH) ./7font-search.sh
stage7y:
	$(BASH) ./7font-search.sh yes
stage8:
	$(BASH) ./8test.sh
stage9:
	$(BASH) ./9realloc.sh install refresh

checkfilelist:
	@perl -n -e 'print if m@  (archive|babel|macro|security)/@' \
	< 1check-archive.sh | awk '{print $$2}' | sort > tmp1
	@find archive/ babel/ macro/ security/ -type f | sort > tmp2
	diff tmp1 tmp2
	@rm -f tmp1 tmp2

tar: checkfilelist check clean
	@echo $(TARGET)-$(VER) > .package
	@$(RM) -r `cat .package`
	@mkdir `cat .package`
	@ln $(TARS) `cat .package`
	@mkdir `cat .package`/md5sum
	@ln md5sum/{texmf,texsrc} `cat .package`/md5sum
	#@ln package/*  `cat .package`/package
	tar cvf - `cat .package` | gzip -9 > `cat .package`-nosrc.tar.gz
	@mkdir `cat .package`/{archive,babel,macro,security}
	@ln archive/*  `cat .package`/archive
	@ln babel/*    `cat .package`/babel
	@ln macro/*    `cat .package`/macro
	@ln security/* `cat .package`/security
	@nkf -w --overwrite `cat .package`/{ChangeLog,README}
	tar cvf - `cat .package` | gzip -9 > `cat .package`.tar.gz
	@$(RM) -r `cat .package` .package
