#
# ============================================================================
#
# This is the Makefile for the uudeview package, including the uudeview
# decoding, the uuenview encoding program, and a mini-inews that can be
# used by uuencode to post directly to the usenet. If you are a Unix
# hacker, you shouldn't have trouble with the comments given here; but
# if you are not, you should probably read the INSTALL file for a more
# complete description of the installation process.
#                                        fp@informatik.uni-frankfurt.de
#
# Usefull targets
#	all		Compile the package
#	install		Install the binaries to $(BINDIR)
#	install.man	Install the manual pages to $(MANDIR)
#	clean		Deletes the binaries and objects and all the
#			other dirty stuff.
#	tar		Packages everything neatly into a tar.gz file
#			for distribution.
#
# ============================================================================
#
# ---------------
# General Options
# ---------------
#
# Where you want the binaries and the manual pages installed
#
BINDIR	=	/usr/local/bin
MANDIR	=	/usr/local/man
#
# If you don't have the GNU C compiler installed, set CC=cc here
#
CC	=	gcc
#
# Configured for optimization.
# If you have a HP without gcc, add  -Aa -D_INCLUDE_POSIX_SOURCE
#
FLAGS	=	-O
#
# SunOS 4.x seems to need LIBS=-ldl here.
#
LIBS	=
#
# ----------------------
# uuenview configuration
# ----------------------
#
# The mail program. It must read the mail from standard input and should
# not output any messages (some elm implementation use to print out lots
# of terminal control characters). If it is not in your path, give the full
# pathname
#
MAIL	=	mail
#
# If the above mail program accepts the subject as a command line option
# as "mail -s 'The Subject'", set the following define to 1, else to 0.
#
MPSUBJECT =	0
#
# Your inews program. it must read the article from stdin. If it is not
# in your path, give the full pathname. Undefine if you do not want to
# post directly from uuenview
#
INEWS	=	$(BINDIR)/minews -S -h
#
# A mini inews, sufficient for uuenview use, is included in the minews
# subdirectory. If it fails to compile, comment out the following line
# and the INEWS definition above
#
MINEWS	=	minews
# 
# --------------------   No need to change this configuration if you
# minews configuration   don't need minewes and have commented out the
# --------------------   above definition.
#
# With minews, you can specify your news server if it doesn't run locally.
# Just don't define it if the news server is the local machine. Or you can
# also override the setting with the NNTPSERVER environment variable.
#
NNTPSERVER =	zeus
#
# Your domain.
#
DOMAIN	=	rbi.informatik.uni-frankfurt.de
#
# If you set the following to 1, your hostname will not appear in the 'from'
# address. This means the posting address will appear as user@DOMAIN instead
# of user@hostname.DOMAIN.
#
HIDDENNET =	1
#
###############################################################################
# You shouldn't have to change anything below.
###############################################################################
#
# Version number
#
VERSION	=	0.4
PATCH	=	13
#

BASE	=	.
C	=	$(BASE)
O	=	$(BASE)

all:			uudeview uuenview $(MINEWS)

clean:
	(cd inews ; make clobber)
	rm -f uudeview uuenview
	rm -f *.o core *~

install:
	if [ ! -d $(BINDIR) ] ; then \
		mkdir $(BINDIR) ; \
		chmod 755 $(BINDIR) ; \
	fi
	cp uuenview uudeview $(BINDIR)
	chmod 711 $(BINDIR)/uuenview $(BINDIR)/uudeview
	if [ -x inews/minews ] ; then \
		cp inews/minews $(BINDIR)/minews ; \
		chmod 711 $(BINDIR)/minews ; \
	fi

install.man:
	if [ ! -d $(MANDIR) ] ; then \
		mkdir $(MANDIR) ; \
		chmod 755 $(MANDIR) ; \
	fi
	if [ ! -d $(MANDIR)/man1 ] ; then \
		mkdir $(MANDIR)/man1 ; \
		chmod 755 $(MANDIR)/man1 ; \
	fi
	cp uudeview.1 uuenview.1 $(MANDIR)/man1
	chmod 644 $(MANDIR)/man1/uudeview.1 $(MANDIR)/man1/uuenview.1

new:		clean
	rm -f uudeview uuenview
	make all

dist:		tar
	mv uudeview-$(VERSION).$(PATCH).tar.gz ../dist/
	chmod 644 ../dist/uudeview-$(VERSION).$(PATCH).tar.gz

tar:
	/bin/test -r ./Makefile
	/bin/test ! -r uudeview-$(VERSION).$(PATCH)
	/bin/test ! -r uudeview-$(VERSION).$(PATCH).tar.gz
	make clean
	rm -f uudeview-$(VERSION).*.tar.gz
	mkdir uudeview-$(VERSION).$(PATCH)
	mkdir uudeview-$(VERSION).$(PATCH)/inews
	cp [A-Z]* *.[1ch] *.lsm uudeview-$(VERSION).$(PATCH)
	cp inews/* uudeview-$(VERSION).$(PATCH)/inews
	find uudeview-$(VERSION).$(PATCH) -exec chmod a+r {} \;
	tar cf  uudeview-$(VERSION).$(PATCH).tar \
		uudeview-$(VERSION).$(PATCH)
	gzip -9 uudeview-$(VERSION).$(PATCH).tar
	rm -rf uudeview-$(VERSION).$(PATCH)
	chmod 644 uudeview-$(VERSION).$(PATCH).tar.gz

uudeview:		$(O)/uudeview.o $(O)/uuutil.o $(O)/uunconc.o \
			$(O)/uufree.o $(O)/uucheck.o $(O)/uudecomp.o \
			$(O)/uuerror.o $(O)/uuio.o $(O)/uutar.o \
			$(O)/toolbox.o
	$(CC) -o $@ $(FLAGS) $(O)/*.o $(LIBS)

uuenview:		$(C)/uuenview.c $(O)/toolbox.o
	$(CC) -o $@ $(FLAGS) -DSTANDALONE \
			-DMAIL='"$(MAIL)"' \
			-DMPSUBJECT=$(MPSUBJECT) \
			-DINEWS='"$(INEWS)"' \
			-DVERSION=\"$(VERSION)\" -DPATCH=\"$(PATCH)\" \
			$(C)/$(@F).c $(LIBS) toolbox.o

minews:
	(cd inews ; \
	 make CC='$(CC) $(FLAGS)' DOMAIN=\"$(DOMAIN)\" \
		NNTPSERVER=\"$(NNTPSERVER)\" \
		HIDDENNET=$(HIDDENNET) \
		LIBS='$(LIBS)' ) 

$(O)/uudeview.o:	$(C)/uudeview.c $(C)/uudeview.h $(C)/uuutil.h \
			$(C)/uufree.h $(C)/uucheck.h $(C)/uudecomp.h \
			$(C)/uuerror.h $(C)/uutar.h $(C)/uuio.h
	$(CC) -c $(FLAGS) \
			-DVERSION=\"$(VERSION)\" -DPATCH=\"$(PATCH)\" \
			-o $@ $(C)/$(@F:.o=.c)

$(O)/uuio.o:		$(C)/uuio.c $(C)/uuio.h $(C)/uudeview.h \
			$(C)/uutar.h
	$(CC) -c $(FLAGS) -o $@ $(C)/$(@F:.o=.c)

$(O)/uunconc.o:		$(C)/uunconc.c $(C)/uudeview.h
	$(CC) -c $(FLAGS) -o $@ $(C)/$(@F:.o=.c)

$(O)/uufree.o:		$(C)/uufree.c $(C)/uufree.h $(C)/uudeview.h
	$(CC) -c $(FLAGS) -o $@ $(C)/$(@F:.o=.c)

$(O)/uucheck.o:		$(C)/uucheck.c $(C)/uucheck.h $(C)/uudeview.h
	$(CC) -c $(FLAGS) -o $@ $(C)/$(@F:.o=.c)

$(O)/uudecomp.o:	$(C)/uudecomp.c $(C)/uudecomp.h $(C)/uudeview.h
	$(CC) -c $(FLAGS) -o $@ $(C)/$(@F:.o=.c)

$(O)/uuerror.o:		$(C)/uuerror.c $(C)/uuerror.h
	$(CC) -c $(FLAGS) -o $@ $(C)/$(@F:.o=.c)

$(O)/uuutil.o:		$(C)/uuutil.c $(C)/uuutil.h $(C)/uudeview.h
	$(CC) -c $(FLAGS) -o $@ $(C)/$(@F:.o=.c)

$(O)/uutar.o:		$(C)/uutar.c $(C)/uutar.h $(C)/uudeview.h
	$(CC) -c $(FLAGS) -o $@ $(C)/$(@F:.o=.c)

$(O)/toolbox.o:		$(C)/toolbox.c
	$(CC) -c $(FLAGS) -o $@ $(C)/$(@F:.o=.c)

