# $Header: /home/amb/wwwoffle/RCS/Makefile 1.16 1997/03/24 17:36:50 amb Exp $
#
# WWWOFFLE - World Wide Web Offline Explorer - Version 1.1.
#
# 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=

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: if you used version 0.9 then read INSTALL. ; exit 1
	@[ ! -f $(INSTDIR)/sbin/wwwoffles ] || echo You must remove $(INSTDIR)/sbin/wwwoffles ; \
	 [ ! -f $(INSTDIR)/sbin/wwwoffles ] && exit 0 ; \
	 echo Important: if you used version 1.0 then read INSTALL. ; exit 1
	install -d $(INSTDIR)/bin
	install -m 755 wwwoffle  $(INSTDIR)/bin
	install -d $(INSTDIR)/sbin
	install -m 755 wwwoffled $(INSTDIR)/sbin
	install -d $(INSTDIR)/man
	install -d $(INSTDIR)/man/man1
	install -m 644 wwwoffle.man $(INSTDIR)/man/man1/wwwoffle.1
	install -d $(INSTDIR)/man/man5
	install -m 644 wwwoffle.conf.man $(INSTDIR)/man/man5/wwwoffle.conf.5
	install -d $(INSTDIR)/man/man8
	install -m 644 wwwoffled.man $(INSTDIR)/man/man8/wwwoffled.8
	install -d $(SPOOLDIR)
	-@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\
	html.o parse.o refresh.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
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

########
