#!/bin/tcsh
#
# Name:
#	makeModule.
#
# Parameters:
#	#	Interpretation
#	------------------
#	1	Phase		1 | 2
#	2	Basename	Net-Telnet
#	3	Version		3_01
#	4	Dir name	3.01
#	5	Test		y or n. Phase 2 only. Default is y
#

setenv PHASE		$1
setenv BASE_NAME	$2
setenv VERSION		$3
setenv DIR_NAME		$4
setenv TEST			$5

if ($PHASE == "") then
	echo Error. Phase not specified
	exit -1
endif

if ($BASE_NAME == "") then
	echo Error. Base name not specified
	exit -1
endif

if ($VERSION == "") then
	echo Error. Version not specified
	exit -1
endif

if ($DIR_NAME == "") then
	echo Error. Dir name not specified
	exit -1
endif

if ( ($PHASE != "1") && ($PHASE != "2") ) then
	echo Error. Phase must be 1 or 2
	exit -1
endif

setenv TAR_NAME			${BASE_NAME}-$VERSION.tar.gz
setenv REAL_DIR_NAME	${BASE_NAME}-$DIR_NAME

if ($PHASE == "1") then

	echo Phase 1..........................................

	mkdir	~/Work
	pushd	~/Work

	# Clean up.
	rm -rf $TAR_NAME $REAL_DIR_NAME

	copy ~/ZipPerl/$TAR_NAME .

	tar xvzf $TAR_NAME

	# Rename dir so cases like File-NCopy0.32 become File-NCopy-0.32.

	if (-e ${BASE_NAME}$DIR_NAME) then
		move ${BASE_NAME}$DIR_NAME $REAL_DIR_NAME
	endif

	# Rename dir so cases like MIME-tools-4.121 become MIME-Tools-4.121.

	if (-e MIME-tools-4.121) then
		move MIME-tools-4.121 MIME-Tools-4.121
	endif

	cd $REAL_DIR_NAME

	perl Makefile.PL LIB=~/perlLib

	popd

else

	echo Phase 2..........................................

	pushd ~/Work/$REAL_DIR_NAME

	make
	make test
	make install

	popd

	rm -rf ~/Work

endif
