# $Header: /home/amb/wwwoffle/RCS/Makefile 1.26 1997/09/06 10:48:28 amb Exp $
#
# WWWOFFLE - World Wide Web Offline Explorer - Version 1.3.
#
# Program Makefile.
#
# Written by Andrew M. Bishop
#
# This file Copyright 1996,97 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
CONFDIR=/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
	[ -x $(INSTDIR)/bin ] || install -d $(INSTDIR)/bin
	install -c -m 755 wwwoffle  $(INSTDIR)/bin
	[ -x  $(INSTDIR)/sbin ] || install -d $(INSTDIR)/sbin
	install -c -m 755 wwwoffled $(INSTDIR)/sbin
	[ -x $(INSTDIR)/man ] || install -d $(INSTDIR)/man
	[ -x  $(INSTDIR)/man/man1 ] || install -d $(INSTDIR)/man/man1
	install -c -m 644 wwwoffle.man $(INSTDIR)/man/man1/wwwoffle.1
	[ -x  $(INSTDIR)/man/man5 ] || install -d $(INSTDIR)/man/man5
	sed -e 's%SPOOLDIR%$(SPOOLDIR)%' -e 's%CONFDIR%$(CONFDIR)%' < wwwoffle.conf.man > wwwoffle.conf.man.install
	install -c -m 644 wwwoffle.conf.man.install $(INSTDIR)/man/man5/wwwoffle.conf.5
	[ -x  $(INSTDIR)/man/man8 ] || install -d $(INSTDIR)/man/man8
	install -c -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.3/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
	sed -e 's%SPOOLDIR%$(SPOOLDIR)%' -e 's%CONFDIR%$(CONFDIR)%' < wwwoffle.conf > wwwoffle.conf.install
	@[ ! -f $(CONFDIR)/wwwoffle.conf ] || echo There is already a configuration file $(CONFDIR)/wwwoffle.conf
	[  ! -f $(CONFDIR)/wwwoffle.conf ] || install -c -m 644 wwwoffle.conf.install $(CONFDIR)/wwwoffle.conf.install
	[    -f $(CONFDIR)/wwwoffle.conf ] || install -c -m 644 wwwoffle.conf.install $(CONFDIR)/wwwoffle.conf

########

clean :
	-rm -f wwwoffle.conf.install wwwoffle.conf.man.install
	-rm -f wwwoffle wwwoffled
	-rm -f 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 configedit.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

configedit.o : configedit.c wwwoffle.h config.h errors.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 config.h errors.h

config.o     : config.c     wwwoffle.h config.h errors.h
	$(COMPILE) $< -o $@ -DSPOOL_DIR=\"$(SPOOLDIR)\" -DCONF_DIR=\"$(CONFDIR)\" $(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

########
