## =================================================================
## File: Makefile --- makefile for rebatch/where.to
##
## Targets:
##	all     --- configures the scripts
##	install --- installs the scripts 
##	clean   --- cleans up backup files and the like
##      shar    --- creates a shar file of this package
##	tar	--- creates a compressed tar file of this package
##	docs	--- creates text files from html
##
## Part of the "rebatch" package
## By Russell Street <r.street@auckland.ac.nz>
##
## 04/02/94 RS Created
## =================================================================

## -----------------------------------------------------------------
## Make sure we are talking the same language
## -----------------------------------------------------------------
SHELL=/bin/sh

## -----------------------------------------------------------------
## If you want to use INN's subst/config.data for configuration
## set these variables to the right values.
## -----------------------------------------------------------------
INN_CONF_DIR=../INN/config			## directory in INN
INN_SUBST=$(INN_CONF_DIR)/subst
INN_CONFIG_DATA=$(INN_CONF_DIR)/config.data

##  If you use the script version of subst, and your version of sed chokes
##  then get FSF sed and edit the next line as appropriate.
#SED	= -e /usr/gnu/bin/sed

REBATCH_CONF_FILES=files.list
LIST=`grep -v '^;' <$(REBATCH_CONF_FILES)`


## -----------------------------------------------------------------
## To auto install you will need INN's installit.sh ...
## -----------------------------------------------------------------
INN_INSTALLIT=../INN/installit.sh

## =()<OWNER	= -O @<NEWSUSER>@ -G @<NEWSGROUP>@>()=
OWNER	= -O news -G news

##  Commands to make private or public, read or executable files.
COPY_RPRI	= $(SHELL) $(INN_INSTALLIT) $(OWNER) -m 0440 -b .OLD
COPY_RPUB	= $(SHELL) $(INN_INSTALLIT) $(OWNER) -m 0444 -b .OLD
COPY_XPRI	= $(SHELL) $(INN_INSTALLIT) $(OWNER) -m 0550 -b .OLD
COPY_XPUB	= $(SHELL) $(INN_INSTALLIT) $(OWNER) -m 0555 -b .OLD

##  =()<NEWSBIN	= @<_PATH_NEWSBIN>@>()=
NEWSBIN	= /usr/local/news/bin

##  =()<MAN8 = @<MAN8>@>()=
MAN8 = /usr/local/man/man8

## -----------------------------------------------------------------
## END OF CONFIGURATION SECTION
## -----------------------------------------------------------------


## -----------------------------------------------------------------
## The name of this directory 
## -----------------------------------------------------------------
THIS_DIR=rebatch
VERSION=1.0

## -----------------------------------------------------------------
## Files in this package
## -----------------------------------------------------------------
DOCS_HTML=INSTALLATION.html MISC.html README.html THEORY.html \
	OVERVIEW.html AUTHOR.html ANNOUNCE.html where.to.8 \
	rebatch.8
DOCS_TXT=INSTALLATION.txt MISC.txt README.txt THEORY.txt \
	OVERVIEW.txt AUTHOR.txt ANNOUNCE.txt where.to.cat \
	rebatch.cat
DOCS=INSTALLATION MISC README THEORY OVERVIEW AUTHOR ANNOUNCE \
	where.to.cat rebatch.cat

FILES=README Makefile MANIFEST rebatch where.to rebatch.conf \
	rebatch.common files.list $(DOCS_HTML) $(DOCS) \
	rebatch.8 where.to.8 clean.man

## -----------------------------------------------------------------
## The shar file to create, and  how to shar things up...
## -----------------------------------------------------------------
SHAR_OUT=rebatch-$(VERSION).shar
SHAR=shar -s 'r.street@auckland.ac.nz' -o $(THIS_DIR)/$(SHAR_OUT)

## -----------------------------------------------------------------
## The tar file to create and how to compress things
## -----------------------------------------------------------------
TAR_FILE=rebatch-$(VERSION).tar
##COMPRESS=compress -v
COMPRESS=gzip -v9

## -----------------------------------------------------------------
## Turn html to formatted text files
## 
## Plus a make rule to turn  x.html -> x
## And one to turn a man page into a text file
## -----------------------------------------------------------------
HTML2TXT=./lynx -dump
.SUFFIXES: .html .txt
.html.txt:
	$(HTML2TXT) $< > $@
	cp $@ $*
.SUFFIXES: .8 .cat
.8.cat:
	nroff -man $< | ./clean.man > $@

## -----------------------------------------------------------------
## Default target (all) --- produce a little helpful message
## -----------------------------------------------------------------

all:
	@echo "Try one of:"
	@echo "   make config        for automatic configuration based"
	@echo "                      on INN's configuration"
	@echo "   make install       to install"
	@echo "   make install-man   to install man pages"
	@echo "   make uninstall to  install man pages"
	@echo "   make uninstall-man to install man pages"
	@echo "   make tar           tar and feather"
	@echo "   make shar          shar archive"
	@echo "   make docs          build text files from the HTML"


## -----------------------------------------------------------------
## config --- configure based on INN's values
## 
## This section was stolen from INN's config/Makefile
## -----------------------------------------------------------------

config:
	-@rm -rf substtmp.new substtmp.old
	@$(SHELL) $(INN_CONF_DIR)/checkconf.sh $(INN_CONFIG_DATA)
	$(INN_SUBST) $(SED) -f $(INN_CONFIG_DATA) $(LIST)



## -----------------------------------------------------------------
## install --- put it all in place
## 
## This section was stolen from INN's site/Makefile
## -----------------------------------------------------------------

install:
	$(COPY_XPRI) rebatch $(NEWSBIN)/rebatch
	$(COPY_XPRI) where.to $(NEWSBIN)/where.to
	$(COPY_RPRI) rebatch.conf $(NEWSBIN)/rebatch.conf
	$(COPY_RPRI) rebatch.common $(NEWSBIN)/rebatch.common

install-man:
	$(COPY_RPUB) rebatch.8 $(MAN8)/rebatch.8
	$(COPY_RPUB) where.to.8 $(MAN8)/where.to.8


## -----------------------------------------------------------------
## uninstall --- remove it 
## -----------------------------------------------------------------

uninstall:
	-rm -f $(NEWSBIN)/rebatch
	-rm -f $(NEWSBIN)/where.to
	-rm -f $(NEWSBIN)/rebatch.conf
	-rm -f $(NEWSBIN)/rebatch.common

uninstall-man:
	-rm -f $(MAN8)/rebatch.8
	-rm -f $(MAN8)/where.to.8


## -----------------------------------------------------------------
## Produce a shar file for distribution
##
## The following mess prepends $(THIS_DIR)/ to the names in $(FILES)
## Then shars up the result
## -----------------------------------------------------------------

shar: docs
	cd .. ; \
	echo $(FILES) | tr ' ' '\012' | \
	sed -e 's-^-$(THIS_DIR)/-g'   | \
	$(SHAR) -S

## -----------------------------------------------------------------
## Produce a tar file for distribution
##
## The following mess prepends $(THIS_DIR)/ to the names in $(FILES)
## Then tars and feathers the result
## -----------------------------------------------------------------

tar: docs
	cd .. ; \
	tar -cvf $(THIS_DIR)/$(TAR_FILE) `echo $(FILES) | tr ' ' '\012' | \
	sed -e 's-^-$(THIS_DIR)/-g'`
	$(COMPRESS) $(TAR_FILE)

## -----------------------------------------------------------------
## docs turn the HTML documentation into plain text
## -----------------------------------------------------------------

docs: $(DOCS_TXT)


## -----------------------------------------------------------------
## clean
## -----------------------------------------------------------------

clean:
	-rm -f rebatch-$(VERSION).tar rebatch-$(VERSION).tar.Z rebatch-$(VERSION).tar.gz
	-rm -f rebatch-$(VERSION).shar.01 a.out *~ core
	-rm -f \#*\#

clobber: clean
	-rm -f $(DOCS) $(DOCS_TXT)

## End of file: Makefile
## =================================================================
