#-----------------------------------------------------------------------
#
#          Makefile for archive/unarchive system.
#
#-----------------------------------------------------------------------

ADM	=	/usr/adm
CATMAN	=	/usr/catman/u_man/man1
ETC	=	/etc
MAN	=	/usr/man/man1
TOOLS	=	/usr/tools
MAIT	=	../MAIT

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# define this if your system has the /usr/ucb bin directory:
#	DEFS	=	-DUCB
# define this if you have a BSD system with the /usr/ucb bin directory:
#	DEFS	=	-DUCB -DBSD4X
# define this if your system has the /usr/plx bin directory:
#	DEFS	=	-DPLX

CFLAGS	=	$(DEFS)

CC	=	cc
PRINT	=	pr

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

ADM_FILE=	unarch.msg  unarchive.note  archnote

ETC_CMD	=	mk.sysadm \
		arch.nite  unarch.ck  unarch.nite  unarch.tape \
		mv.files  table.edit  ck.disk

ETC_SH	=	mk.sysadm.sh \
		unarch.ck.sh  arch.nite.sh  unarch.tape.sh \
		unarch.nite.sh mv.files.sh  table.edit.sh  ck.disk.sh

ARCH_BSD=	arch.nite.b  unarch.tape.b  unarch.nite.b \
		mk.sysadm.b  unarch.ck.b \
		mv.files.b  table.edit.b  ck.disk.b \
		archive.b  archlist.b  unarchive.b \
		unarch.get.b  unarch.list.b  unarch.rqst.b \
		short.b  long.b

ARCH_SYSV=	arch.nite.v  unarch.tape.v  unarch.nite.v \
		mk.sysadm.v  unarch.ck.v \
		mv.files.v  table.edit.v  ck.disk.v \
		archive.v  archlist.v  unarchive.v \
		unarch.get.v  unarch.list.v  unarch.rqst.v \
		short.v  long.v

ARCH_XENIX=	arch.nite.x  unarch.tape.x  unarch.nite.x \
		mk.sysadm.x  unarch.ck.x \
		mv.files.x  table.edit.x  ck.disk.x \
		archive.x  archlist.x  unarchive.x \
		unarch.get.x  unarch.list.x  unarch.rqst.x \
		short.x  long.x

MAN_FILE=	archive.1  archlist.1  unarchive.1

NROFF_FILE=	archive.n  archlist.n  unarchive.n

PACK_FILE=	archive.1.z  archlist.1.z  unarchive.1.z

TOOL_CMD=	archive  archlist  unarchive \
		unarch.get  unarch.list  unarch.rqst \
		short  long

C_SRC	=	archexpire.c  unarch.log.c  cnvdate.c

TOOL_SH	=	archive.sh  archlist.sh  unarchive.sh \
		unarch.get.sh  unarch.list.sh  unarch.rqst.sh \
		short.sh  long.sh

TOOL_PRG=	archexpire  unarch.log	cnvdate  dmy  ymd  today

MISC	=	Makefile

ALL_SH	=	$(TOOL_SH)  $(ETC_SH)

ALLFILES=	$(MISC)  $(ADM_FILE)  $(MAN_FILE) \
		$(ALL_SH)  $(C_SRC)

#-----------------------------------------------------------------------


.c.o:       ;   $(CC) -c $(CFLAGS) $<


#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

.SUFFIXES:	.sh

#
#	Default rules for configuring commands and for RCS files
#

.SUFFIXES:	.b  .v  .x

.sh.b:	;	sed -e '1s:$$:--a commented version of this script is in '`pwd`':' -e '/%XENIX%/d' -e '/%SYSV%/d' -e '/%BSD4%/s/^#//' -e '/[\$$\\]#/s/#/++/' -e 's/[ 	]*#.*$$//' -e '/[\$$\\]++/s/++/#/' -e '/^[ 	]*$$/d' <$< >$@

.sh.v:	;	sed -e '1s:$$:--a commented version of this script is in '`pwd`':' -e '/%XENIX%/d' -e '/%BSD4%/d' -e '/%SYSV%/s/^#//' -e '/[\$$\\]#/s/#/++/' -e 's/[ 	]*#.*$$//' -e '/[\$$\\]++/s/++/#/' -e '/^[ 	]*$$/d' <$< >$@

.sh.x:	;	sed -e '1s:$$:--a commented version of this script is in '`pwd`':' -e '/%BSD4%/d' -e '/%SYSV%/d' -e '/%XENIX%/s/^#//' -e '/[\$$\\]#/s/#/++/' -e 's/[ 	]*#.*$$//' -e '/[\$$\\]++/s/++/#/' -e '/^[ 	]*$$/d' <$< >$@

#=======================================================================

#
# Install archive for specific systems
#

p60:		plexus
P60:		plexus
plexus:	;	make SYSTEM=SYSV DEFS=-DPLX all

5000:		sperry
arete:		sperry
sperry:	;	make SYSTEM=SYSV DEFS=-DUCB all

310:		intel
intel:		XENIX
xenix:		XENIX

vax:		bsd
bsd:	;	make SYSTEM=BSD DEFS="-DUCB -DBSD4X" all

sysv:		SYSV
sys5:		SYSV
SYS5:		SYSV

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#
# Install archive for proper configuration
#

all:		$(SYSTEM)

BSD:		bsd_arch man_inst install
		@echo BSD INSTALLATION COMPLETE!

SYSV:		sys5_arch sys5_man install
		@echo SYSV INSTALLATION COMPLETE!

XENIX:		xenix_arch man_inst install
		@echo XENIX INSTALLATION COMPLETE!

#
# Configure commands for archive shell scripts
#

bsd_arch:	$(ARCH_BSD)
		for i in $?; \
		do \
		    mv $$i `basename $$i .b`; \
		done
		-rm -f archexpire unarch.log cnvdate

sys5_arch:	$(ARCH_SYSV)
		for i in $?; \
		do \
		    mv $$i `basename $$i .v`; \
		done
		-rm -f archexpire unarch.log cnvdate

xenix_arch:	$(ARCH_XENIX)
		for i in $?; \
		do \
		    mv $$i `basename $$i .x`; \
		done
		-rm -f archexpire unarch.log cnvdate

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

install:	tools  tool_inst  etc_inst  adm_inst

#
# Install shell commands in TOOLS.
#

tool_inst:	$(TOOL_CMD)
		chmod 755 $(TOOL_CMD)
		cp $(TOOL_CMD) $(TOOLS)
		@echo ...$(TOOLS) installed.

#
# Compile commands in TOOLS.
#

tools:		$(TOOL_PRG)
		mv archexpire $(TOOLS)/archexpire
		mv unarch.log $(TOOLS)/unarch.log
		mv cnvdate $(TOOLS)/cnvdate
		rm -f $(TOOLS)/today
		rm -f $(TOOLS)/ymd
		rm -f $(TOOLS)/dmy
		ln $(TOOLS)/cnvdate $(TOOLS)/today
		ln $(TOOLS)/cnvdate $(TOOLS)/ymd
		ln $(TOOLS)/cnvdate $(TOOLS)/dmy
		chmod u+s $(TOOLS)/archexpire $(TOOLS)/unarch.log

archexpire:	archexpire.c
		cc $(CFLAGS) -o archexpire archexpire.c

unarch.log:	unarch.log.c
		cc $(CFLAGS) -o unarch.log unarch.log.c

cnvdate:	cnvdate.c
		cc $(CFLAGS) -o cnvdate cnvdate.c

today:		cnvdate.c

dmy:		cnvdate.c

ymd:		cnvdate.c

#
#	Install commands in ETC.
#

etc_inst:	$(ETC_CMD)
		chmod 744 $(ETC_CMD)
		cp $(ETC_CMD) $(ETC)
		@echo ...$(ETC) installed.

#
#	Install Files in ADM.
#

adm_inst:	$(ADM_FILE)
		chmod 644 $(ADM_FILE)
		cp $(ADM_FILE) $(ADM)
		@echo ... $(ADM) installed.

#
#	Install SystemV Man Pages:
#

sys5_man:	pack_step
		cp $(PACK_FILE) $(CATMAN)
		cd $(CATMAN); chmod 644 $(PACK_FILE)
		cd $(CATMAN); chown bin $(PACK_FILE)
		cd $(CATMAN); chgrp bin $(PACK_FILE)

pack_step:	nroff_step
		-pack $(MAN_FILE)
		touch $@

nroff_step: 	$(NROFF_FILE)
		nroff -man archive.n > archive.1
		nroff -man archlist.n > archlist.1
		nroff -man unarchive.n > unarchive.1
		touch $@

#
#	Install man pages for BSD and XENIX:
#

man_inst:	
		cp archive.n  archive.1
		cp archlist.n  archlist.1
		cp unarchive.n  unarchive.1
		chmod 644 $(MAN_FILE)
		cp $(MAN_FILE) $(MAN)
		@echo ...$(MAN) installed.

#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

#
# Clean up the makeable files (.o, programs)
#

clean:
		@echo;echo "	CLEANING ARCHIVE DIRECTORY:";echo 
		rm -f *.o
		rm -f $(ETC_CMD)  $(TOOL_CMD)
		@echo;echo "	ARCHIVE CLEANING DONE.";echo 

#
# Print listing of source and misc files:
#

print:		checkout
		@echo;echo "	PRINTING ARCHIVE DIRECTORY:";echo 
		 $(PRINT) $(ALLFILES)
		@echo;echo "	ARCHIVE PRINTING DONE.";echo 

