# $Header: /home/amb/wwwoffle/RCS/Makefile 1.22 1997/06/23 20:16:13 amb Exp $
#
# WWWOFFLE - World Wide Web Offline Explorer - Version 1.2b.
#
# Program Makefile.
#
# Written by Andrew M. Bishop
#
# This file Copyright 1995,96 Andrew M. Bishop
# It may be distributed under the GNU Public License, version 2, or
# any higher version.  See section COPYING of the GNU Public license
# for conditions under which this file may be redistributed.
#

########

INSTDIR=/usr/local
SPOOLDIR=/var/spool/wwwoffle

########

CC=gcc
CFLAGS=-O2 -Wall -g

LD=gcc
LDFLAGS=-g

LEX=flex -i -L

########

INCLUDE=
LIBRARY=
# For Solaris you need the following instead.
#LIBRARY=-lnsl -lsocket

COMPILE=$(CC) -c $(CFLAGS)

LINK=$(LD) $(LDFLAGS)

########

all : programs
	@

programs : wwwoffle wwwoffled
	@

########

install : programs
	@[ ! -f $(INSTDIR)/bin/wwwoffled ] || echo You must remove $(INSTDIR)/bin/wwwoffled ; \
	 [ ! -f $(INSTDIR)/bin/wwwoffles ] || echo You must remove $(INSTDIR)/bin/wwwoffles ; \
	 [ ! -f $(INSTDIR)/man/man1/wwwoffled.1 ] || echo You must remove $(INSTDIR)/man/man1/wwwoffled.1 ; \
	 [ ! -f $(INSTDIR)/bin/wwwoffled -a ! -f $(INSTDIR)/bin/wwwoffles -a ! -f $(INSTDIR)/man/man1/wwwoffled.1 ] && exit 0 ; \
	 echo Important: you must do this to allow this version to install. ; exit 1
	@[ ! -f $(INSTDIR)/sbin/wwwoffles ] || echo You must remove $(INSTDIR)/sbin/wwwoffles ; \
	 [ ! -f $(INSTDIR)/sbin/wwwoffles ] && exit 0 ; \
	 echo Important: if you have version 1.0 then read INSTALL. ; exit 1
	@[ ! -f $(SPOOLDIR)/wwwoffle.conf ] || echo You must edit $(SPOOLDIR)/wwwoffle.conf ; \
	 [ ! -f $(SPOOLDIR)/wwwoffle.conf ] && exit 0 ; \
	 echo Important: if you have version 1.1 then read INSTALL. ; exit 0
	[ -x $(INSTDIR)/bin ] || install -d $(INSTDIR)/bin
	install -m 755 wwwoffle  $(INSTDIR)/bin
	[ -x  $(INSTDIR)/sbin ] || install -d $(INSTDIR)/sbin
	install -m 755 wwwoffled $(INSTDIR)/sbin
	[ -x $(INSTDIR)/man ] || install -d $(INSTDIR)/man
	[ -x  $(INSTDIR)/man/man1 ] || install -d $(INSTDIR)/man/man1
	install -m 644 wwwoffle.man $(INSTDIR)/man/man1/wwwoffle.1
	[ -x  $(INSTDIR)/man/man5 ] || install -d $(INSTDIR)/man/man5
	install -m 644 wwwoffle.conf.man $(INSTDIR)/man/man5/wwwoffle.conf.5
	[ -x  $(INSTDIR)/man/man8 ] || install -d $(INSTDIR)/man/man8
	install -m 644 wwwoffled.man $(INSTDIR)/man/man8/wwwoffled.8
	[ -x  $(SPOOLDIR) ] || install -d $(SPOOLDIR)
	[ -x  $(SPOOLDIR)/outgoing ] || install -d $(SPOOLDIR)/outgoing
	@n=1; while [ -f $(SPOOLDIR)/outgoing/$$n ]; do n=`expr $$n + 1` ; done; \
	 echo 'GET http://www.gedanken.demon.co.uk/wwwoffle/version-1.2/user.html HTTP/1.0' > $(SPOOLDIR)/outgoing/$$n ; \
	 echo 'Accept: */*'                                                                >> $(SPOOLDIR)/outgoing/$$n ; \
	 echo 'Host: www.gedanken.demon.co.uk'                                             >> $(SPOOLDIR)/outgoing/$$n ; \
	 echo ''                                                                           >> $(SPOOLDIR)/outgoing/$$n
	-@rm -f $(SPOOLDIR)/wwwoffles
	sed -e 's%SPOOLDIR%$(SPOOLDIR)%' < wwwoffle.conf > wwwoffle.conf.install
	@[ ! -f $(SPOOLDIR)/wwwoffle.conf ] || echo There is already a configuration file $(SPOOLDIR)/wwwoffle.conf
	[  ! -f $(SPOOLDIR)/wwwoffle.conf ] || install -m 644 wwwoffle.conf.install $(SPOOLDIR)/wwwoffle.conf.install
	[    -f $(SPOOLDIR)/wwwoffle.conf ] || install -m 644 wwwoffle.conf.install $(SPOOLDIR)/wwwoffle.conf

########

clean :
	-rm -f wwwoffle wwwoffled wwwoffle.conf.install core *.o *~

########

WWWOFFLE_OBJ=wwwoffle.o\
	config.o errors.o io.o sockets.o

wwwoffle : $(WWWOFFLE_OBJ)
	$(LINK) $(WWWOFFLE_OBJ) -o $@ $(LIBRARY)

########

WWWOFFLED_OBJ=wwwoffled.o wwwoffles.o\
	connect.o control.o html.o index.o messages.o parse.o purge.o refresh.o spool.o\
	config.o errors.o io.o sockets.o

wwwoffled : $(WWWOFFLED_OBJ)
	$(LINK) $(WWWOFFLED_OBJ) -o $@ $(LIBRARY)

########

%.o:%.c
	$(COMPILE) $< -o $@ $(INCLUDE)

wwwoffle.o  : wwwoffle.c  wwwoffle.h config.h errors.h sockets.h
wwwoffled.o : wwwoffled.c wwwoffle.h config.h errors.h sockets.h
wwwoffles.o : wwwoffles.c wwwoffle.h config.h errors.h sockets.h

connect.o   : connect.c   wwwoffle.h config.h errors.h
control.o   : control.c   wwwoffle.h config.h errors.h sockets.h
html.o	    : html.c	  wwwoffle.h
index.o     : index.c     wwwoffle.h config.h errors.h
messages.o  : messages.c  wwwoffle.h config.h
parse.o     : parse.c     wwwoffle.h config.h errors.h
purge.o     : purge.c     wwwoffle.h config.h errors.h
refresh.o   : refresh.c   wwwoffle.h config.h errors.h sockets.h
spool.o     : spool.c     wwwoffle.h          errors.h

config.o    : config.c    wwwoffle.h config.h 
	$(COMPILE) $< -o $@ -DSPOOL_DIR=\"$(SPOOLDIR)\" $(INCLUDE)
errors.o    : errors.c               config.h errors.h
io.o        : io.c        wwwoffle.h          errors.h
sockets.o   : sockets.c                       errors.h sockets.h

########

html.c : html.l
	$(LEX) html.l
	@mv lex.yy.c html.c

########
