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

# for make ???
PREFIX	= /usr/local
# for make tmp???
PREFIX2	= /var/tmp

# next 3 variables are independent from each other
SRC_DIR	= $(PREFIX)/src
TEX_DIR	= $(PREFIX)/teTeX
DATA_DIR= $(PREFIX)/teTeX/share

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

all:  stage1 stage2 stage3 stage4 stage5
x:    stage1 stage2 stage3
c:    stage4
macro:stage5
otf:  stage5o
babel:stage6
font: stage7
fonty:stage7y
test: stage8

clean:
	rm -rf ptetex-test-* ptetex-tmp-* ptetex.tmp-* *~ \#*\#
uninstall:
	@echo -n 'Removing "$(TEX_DIR)" "$(SRC_DIR)/tetex-src-3.0" ok? (yes/no) '
	@read REPLY; \
	case $$REPLY in y*) rm -rf "$(TEX_DIR)" "$(SRC_DIR)/tetex-src-3.0";; esac
	@rmdir "$(SRC_DIR)" > /dev/null 2>&1 || true

stage1:
	./1check-archive.sh
stage2:
	./2extract-src.sh   $(SRC_DIR)
stage3:
	./3extract-texmf.sh $(DATA_DIR)
stage4:
	./4make-install.sh  $(TEX_DIR) $(DATA_DIR) $(SRC_DIR)
stage5:
	./5macro.sh         $(TEX_DIR) $(DATA_DIR) clean default utf
stage5o:
	./5macro.sh         $(TEX_DIR) $(DATA_DIR) otf
stage6:
	./6babel.sh         $(TEX_DIR) $(DATA_DIR)
stage7:
	./7font-search.sh   $(TEX_DIR) $(DATA_DIR)
stage7y:
	./7font-search.sh   $(TEX_DIR) $(DATA_DIR) yes
stage8:
	./8test.sh          $(TEX_DIR) $(DATA_DIR)

tmpall: tmp
tmp: tmpuninstall  # slightly differnt from 'make'
	DATE=`date +%m%d-%H%M`; \
	(make PREFIX=$(PREFIX2) all && echo "ptetex3 make succeeded" ) 2>&1 \
	| tee log-$$DATE; \
	grep "ptetex3 make succeeded" log-$$DATE > /dev/null
tmpx: tmpuninstall # slightly differnt from 'make x'
	make PREFIX=$(PREFIX2) stage2 stage3
tmpc:
	make PREFIX=$(PREFIX2) c
tmpmacro:
	make PREFIX=$(PREFIX2) macro
tmpotf:
	make PREFIX=$(PREFIX2) otf
tmpbabel:
	make PREFIX=$(PREFIX2) babel
tmpfont:
	make PREFIX=$(PREFIX2) font
tmpfonty:
	make PREFIX=$(PREFIX2) fonty
tmptest:
	make PREFIX=$(PREFIX2) test
tmpuninstall:
	make PREFIX=$(PREFIX2) uninstall

check:
	@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: check stage1 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
