#---------------------------------------------------------------------
#     Copyright (C) GFD Dennou Club, 2005. All rights reserved.
#---------------------------------------------------------------------
#= Export source codes from cvsroot, and compress them.
#
# * Yasuhiro MORIKAWA, Masaki ISHIWATARI
#   * 2005/11/15 (Yasuhiro MORIKAWA) Target "makedoc" is modified.
#   * 2005/10/10 (Yasuhiro MORIKAWA) "CURTAG" is devided to "TAG" and "DIR".
#                                    "OVERWRITE", "CLEANARCH" are added.
#   * 2005/06/30 (Yasuhiro MORIKAWA) "Current_CVS_Tag.mk" is included
#   * 2005/06/23 (Yasuhiro MORIKAWA) Japanese commends are added
#   * 2005/06/12 (Yasuhiro MORIKAWA) Create
#
######################################################################
#
#== Settings
#
# [JAPANESE] 各種設定項目

INCLUDEFILE = Current_CVS_Tag.mk
include $(INCLUDEFILE)  # Include file              (optional)
                        # [JA] インクルードファイル (任意)

CVS_ROOT = /GFD_Dennou_Club/ftp/arch/dcmodel/cvsroot
                        # cvsroot                     (necessary)
                        # [JA] cvsroot のディレクトリ (必須)

MAKEDOC  = cd $(DIR) ; \
           RUBYLIB=/GFD_Dennou_Club/ftp/arch/dcmodel/lib/ruby/1.8 \
           PATH=/GFD_Dennou_Club/ftp/arch/dcmodel/bin:$$PATH  \
           make doc
                       # Commands excuted after exported      (optional)
                       # [JA] export 後, tar によるアーカイブ
                       #      前に実行するコマンド群          (任意)

PROJECT  = $(YOUR_PROJECT_NAME)
                       # Project name in cvs       (necessary)
                       # [JA] cvs のプロジェクト名 (必須)

TAG      = -r $(YOUR_CURRENT_TAG)
#TAG      = -D "2030-12-31"
                       # Tag (-r) or date (-D) in cvs  (necessary)
                       # [JA] タグ (-r) または日付 (-d)   (必須)

DIR      = $(TAG)
                       # Directory name for archive       (necessary)
                       # [JA] 展開するディレクトリ名      (必須)

CURNAME  = $(PROJECT)_current
                       # Latest symbolic link             (optional)
                       # [JA] 最新版につけるシンボリック
                       #      リンク名. 空の場合, シンボ
                       #      リックリンクは作成しない    (任意)

TGZ      = tgz
                       # Suffix of archive       (necessary)
                       # [JA] アーカイブの拡張子 (必須)

TGZLIST  = /GFD_Dennou_Club/ftp/arch/dcmodel/bin/tgzlist-html.rb
                       # "tgzlist-html.rb" command that create
                       # archive list HTML                      (optional)
                       # [JA] HTML のアーカイブリストを作成する
                       #      "tgzlist-html.rb" へのパス.
                       #      空の場合, リストは作成されない.   (任意)

OVERWRITE = 0
                       # Overwrite mode                (optional)
                       # [JA] 1 にすると, 既に DIR が
                       #      存在しても上書きする     (任意)

CLEANARCH = 0
                       # Clean directory and tar archive    (optional)
                       # [JA] 1 にすると, 展開したディレク
                       #      トリを削除し, tgz アーカイブ
                       #      を作成しない.                (任意)

RUBY     = ruby1.8     # Path to Ruby        (optional)
                       # [JA] Ruby へのパス  (任意)
CVS      = cvs         # cvs command         (necessary)
                       # [JA] cvs へのパス   (必須)
GATE     = /usr/local/bin/gate-user-show
                       # Path to "gate-user-show"       (optional)
                       # [JA] "gate-user-show" へのパス (任意)
                       #      空の場合, SIGEN ファイルを作成しない

# End Settings  [JA] 設定項目ここまで
######################################################################
#== SIGEN file
#
SIGENDIR = $(DIR).SIGEN
SIGENTGZ = $(DIR).$(TGZ).SIGEN

######################################################################
#== Get Japanese name from gate-toroku-system
#
GATEJPNAME=`$(GATE) $(USER) | grep kname | cut -d":" -f 2`

######################################################################
#== Generate archive list by "tgzlist-html.rb"
#
TGZLIST_CMD = $(RUBY) $(TGZLIST) \
		-o index --exclude $(CURNAME).$(TGZ),$(CURNAME)

######################################################################
#== Rules
#
all: export

help:
	@echo ""
	@echo "  make [export] :"
	@echo "             Export $(PROJECT) source from cvsroot. "
	@echo "             Expand source in" $(PROJECT) "."
	@echo "             Generate documentations from them."
	@if [ "$(CURNAME)" != "" ] && [ "$(CLEANARCH)" != "1" ]; then \
	 echo "             Compress them into" $(PROJECT)/$(CURNAME).$(TGZ) "." ;\
	fi
	@if [ "$(GATE)" != "" ] && [ "$(CLEANARCH)" != "1" ]; then \
	 echo "             Create SIGEN file" $(SIGENDIR) $(SIGENTGZ) ;\
	fi
	@if [ "$(TGZLIST)" != "" ] && [ "$(RUBY)" != "" ]; then \
	 echo "             Update Archive List. " ;\
	fi
	@echo ""
	@echo "  make tgzlist :"
	@echo "             Only Update Archive List. "
	@echo ""

clean:
	rm -f *~

clean.all: clean

export: varcheck tagcheck expand makedoc mktgz sigen tgzlist

varcheck:
	@if [ "$(PROJECT)" = "" ]; then \
	    echo -e "\n   Specify \"PROJECT\" in Makefile.export \n" ;\
	    exit 1 ;\
	fi
	@if [ "$(TAG)" = "" ]; then \
	    echo -e "\n   Specify \"TAG\" in Makefile.export \n" ;\
	    exit 1 ;\
	fi
	@if [ "$(DIR)" = "" ]; then \
	    echo -e "\n   Specify \"DIR\" in Makefile.export \n" ;\
	    exit 1 ;\
	fi
	@if [ "$(CVS)" = "" ]; then \
	    echo -e "\n   Specify \"CVS\" in Makefile.export \n" ;\
	    exit 1 ;\
	fi
	@if [ "$(TGZ)" = "" ]; then \
	    echo -e "\n   Specify \"TGZ\" in Makefile.export \n" ;\
	    exit 1 ;\
	fi
	@if [ "$(CVS_ROOT)" = "" ]; then \
	    echo -e "\n   Specify \"CVS_ROOT\" in Makefile.export \n" ;\
	    exit 1 ;\
	fi


tagcheck:
	@if [ -d "$(DIR)" ] && [ "$(OVERWRITE)" != "1" ]; then \
	    echo -e \
		"\n  " $(DIR) "is already exported .\n" \
		"  Please change \"DIR\" in \"Makefile.export\" to latest tag.\n" \
		"  or remove \"" $(DIR) "\".\n" \
		"  And do \"make export\" again.\n" ;\
	    exit 1 ;\
	fi
	@if [ -d "$(DIR)" ] && [ "$(OVERWRITE)" = "1" ]; then \
	    echo rm -rf $(DIR) ;\
	    rm -rf $(DIR) ;\
	fi

expand:
	$(CVS) -d $(CVS_ROOT) export $(TAG) \
	       -d $(DIR)   $(PROJECT) \
	|| \
	eval  " rm $(DIR)/CVS/*  ; \
		rmdir $(DIR)/CVS ; \
		rmdir $(DIR)     ; exit 1 "

makedoc:
	@if [ "$(MAKEDOC)" != "" ]; then \
	    echo "$(MAKEDOC)" ;\
	    eval "$(MAKEDOC)" ;\
	fi

mktgz:
	@if [ "$(CLEANARCH)" != "1" ] ; then \
	    echo tar cvfz $(DIR).$(TGZ) $(DIR) ;\
	    tar cvfz $(DIR).$(TGZ) $(DIR) ;\
	elif [ "$(CLEANARCH)" = "1" ] ; then \
	    echo rm -rf $(DIR) ;\
	    rm -rf $(DIR) ;\
	fi
	@if [ "$(CURNAME)" != "" ] && [ "$(CLEANARCH)" != "1" ]; then \
	    echo rm -f $(CURNAME) $(CURNAME).$(TGZ)        ;\
	    rm -f $(CURNAME) $(CURNAME).$(TGZ)        ;\
	    \
	    echo ln -s $(DIR)        $(CURNAME)         ;\
	    ln -s $(DIR)        $(CURNAME)         ;\
	    \
	    echo ln -s $(DIR).$(TGZ) $(CURNAME).$(TGZ)  ;\
	    ln -s $(DIR).$(TGZ) $(CURNAME).$(TGZ)  ;\
	fi

sigen: sigendir sigentgz

sigendir:
	@if [ "$(GATE)" != "" ] && [ "$(CLEANARCH)" != "1" ]; then \
	    echo -n "Generating $(SIGENDIR) ... " ;\
	    \
	    echo "Subject:	" $(DIR) "Source code directory" > $(SIGENDIR) ;\
	    echo "Maintainer:	" $(GATEJPNAME) >> $(SIGENDIR) ;\
	    echo "Description:	 This file is auto-generated form \"make export -f Makefile.export\"" >> $(SIGENDIR) ;\
	    echo "Note:		" >> $(SIGENDIR) ;\
	    echo "Update:		`date +%Y/%m/%d`" >> $(SIGENDIR) ;\
	    \
	    echo "done" ;\
	fi

sigentgz:
	@if [ "$(GATE)" != "" ] && [ "$(CLEANARCH)" != "1" ]; then \
	    echo -n "Generating $(SIGENTGZ) ... " ;\
	    \
	    echo "Subject:	" $(DIR) "tar.gz Package" > $(SIGENTGZ) ;\
	    echo "Maintainer:	" $(GATEJPNAME) >> $(SIGENTGZ) ;\
	    echo "Description:	 This file is auto-generated form \"make export -f Makefile.export\"" >> $(SIGENTGZ) ;\
	    echo "Note:		" >> $(SIGENTGZ) ;\
	    echo "Update:		`date +%Y/%m/%d`" >> $(SIGENTGZ) ;\
	    \
	    echo "done" ;\
	fi

tgzlist:
	@if [ "$(TGZLIST)" != "" ] && [ "$(RUBY)" != "" ]; then \
	    echo $(TGZLIST_CMD) ;\
	    $(TGZLIST_CMD) ;\
	fi

######################################################################
#== Mode setting for Emacs
#Local Variables:
#mode: makefile
#End:
#
