#
# ptetex -- Japanese patche collection for teTeX-3.0
#  Nobuyuki Tsuchimura
#

# 'bash' is better, but 'sh' is also OK.
BASH	= `which bash`
#BASH	= /bin/sh

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

all:
	@DATE=`date +%m%d-%H%M`; \
	$(MAKE) make 2>&1 | tee log-$$DATE; \
	echo; echo "Those messages are stored in 'log-$$DATE'."; echo; \
	grep "ptetex3 make succeeded." log-$$DATE > /dev/null
make: stage1 stage2 stage3 stage4 stage5
	@echo "ptetex3 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 stage3
c:    stage4
macro:stage5
otf:  stage5o
babel:stage6
font: stage7
fonty:stage7y
test: stage8
install: stage9

clean:
	rm -rf ptetex-test-* ptetex-tmp-* ptetex.tmp-* *~ \#*\#
distclean:
	@./9realloc.sh distclean
uninstall:
	@./9realloc.sh uninstall

stage1:
	$(BASH) ./1check-archive.sh
stage2:
	$(BASH) ./2extract-src.sh
stage3:
	$(BASH) ./3extract-texmf.sh
stage4:
	$(BASH) ./4make-install.sh
stage5:
	$(BASH) ./5macro.sh clean default utf
stage5o:
	$(BASH) ./5macro.sh otf
stage6:
	$(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|cmap|macro|security)/@' \
	< 1check-archive.sh | awk '{print $$2}' | sort > tmp1
	@find archive/ babel/ cmap/ 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,package}
	@ln md5sum/tex*{mf,al,out} `cat .package`/md5sum
	@ln package/*  `cat .package`/package
	tar cvf - `cat .package` | gzip -9 > `cat .package`-nosrc.tar.gz
	@mkdir `cat .package`/{archive,babel,cmap,macro,security}
	@ln archive/*  `cat .package`/archive
	@ln babel/*    `cat .package`/babel
	@ln cmap/*     `cat .package`/cmap
	@ln macro/*    `cat .package`/macro
	@ln security/* `cat .package`/security
	tar cvf - `cat .package` | gzip -9 > `cat .package`.tar.gz
	@$(RM) -r `cat .package` .package
