#	Common Makefile for WWW Servers and some Gateways
#	-------------------------------------------------
#
# A Makefile in a subdirectory for the machine in question contains
# the necessary definitions of directories etc.
#
#	(c) CERN 1990, 1991 -- see Copyright.html for conditions
#
#	YOU NEED THE WWW LIBRARY TO USE THIS
#
# This file should be invariant between systems.
#	DEPENDENCIES NOT COMPLETE @@
#
#	make		Compile and link the daemon (private version)
#	make install	Copy it into the system (implies make)
#	make update	Copy installed version into installed version
#	make uninstall	Unlink installed version from the system
#	make clean	Remove intermediate files
#	make cleanall	Remove intremediate files and products
#
#	make httpd	as make
#	make tigate	Make Techinfo gateway
#
#	
# Macros required to be defined already for make:
#
# CC		The C compiler
# CFLAGS2	Flags for $(CC)
# LFLAGS	Flags for ld
# WWW		Root of WWW source tree
# WTMP		Root of tree in which to put objects e.g. $(WWW) or /tmp
#
# Only needed for use as WAIS gateway. Put into your Makefile.include
# Also have a WAIS-connected version of the libwww.
#
#	WAIS = ../../../freeWAIS
#	WAISLIB =  $(WAIS)/bin/client.a $(WAIS)/bin/wais.a
#
#______________________________________________________________________

#  If this env var is set to something else Some makes will use that instead
SHELL = /bin/sh
#  Rule file to be used by target daemon
RULE_FILE = "/etc/httpd.conf"

CMN = $(WWW)/Library/Implementation
INC = $(WWW)/Library/Implementation
SRC = $(WWW)/Daemon/Implementation
VMS = $(SRC)/vms

OBJ = .
OE = $(OBJ)/.created

DOC = \
    $(WWW)/Paper/www-server-guide.ps, $(WWW)/Paper/www-server-guide.txt

CFLAGS2 =  -I$(INC) -DDEBUG $(CFLAGS) -DACCESS_AUTH

PROD = httpd

USELIBDIR = $(WTMP)/Library/$(WWW_MACH)
OBJ = $(WTMP)/Daemon/$(WWW_MACH)
LIBWWW = $(WTMP)/Library/$(WWW_MACH)/libwww.a

OBJS = HTDaemonDIR.o HTRetrieve.o HTScript.o HTSInit.o $(LIBWWW) $(WAISLIB)
FOBJS = HTDaemonNR.o FINDGate.o  $(LIBWWW)
TIOBJS = HTDaemonNR.o TechInfoGate.o  $(LIBWWW)
WOBJS = HTDaemonNR.o WAISGate.o ParseWSRC.o $(LIBWWW)
TWOBJS = test.o WAISGate.o  $(LIBWWW)


SPECIFIC = $(SRC)/Makefile.decstation	\
	$(SRC)/Makefile.next

SOURCES = $(SRC)/HTDaemon.c	$(SRC)/HTDaemon.h \
	$(SRC)/HTRetrieve.c	\
	$(SRC)/HTScript.c	$(SRC)/HTScript.h \
	$(SRC)/HTImage.c	\
	$(SRC)/HTSInit.c	\
	$(SRC)/HTAdm.c		\
	$(SRC)/CommonMakefile	\
	$(SRC)/Version.make

#	$(SRC)/test.c		$(SRC)/Makefile		
#	$(SRC)/DCLServer.c	$(SRC)/VMServer.c
#	$(SRC)/VMSHelpGate.c	$(SRC)/TechInfoGate.c
#	$(SRC)/install.csh	


include $(ABS)$(SRC)/Version.make

everything : $(PROD) htadm htimage


#		Hypertext File server

$(PROD) : $(OBJS)
	$(CC) -o $(PROD)_$(VD)  $(OBJS) $(LFLAGS)
	-rm $(PROD)
	ln -s $(PROD)_$(VD) $(PROD)

HTRetrieve.o : $(SRC)/HTRetrieve.c $(INC)/HTUtils.h $(INC)/tcp.h \
	$(INC)/HTFile.h
	$(CC) -c $(CFLAGS2) -DRULES -DRULE_FILE=\"$(RULE_FILE)\" $(SRC)/HTRetrieve.c

HTScript.o : $(SRC)/HTScript.c $(INC)/HTUtils.h $(INC)/tcp.h \
	 $(INC)/HTFile.h
	$(CC) -c $(CFLAGS2) -DRULES -DRULE_FILE=\"$(RULE_FILE)\" $(SRC)/HTScript.c

#		Administration program

htadm : HTAdm.o $(LIBWWW)
	$(CC) -o htadm_$(VD) HTAdm.o $(LIBWWW)
	-rm htadm
	ln -s htadm_$(VD) htadm

HTAdm.o : $(SRC)/HTAdm.c $(INC)/HTUtils.h $(INC)/HTAlert.h \
	 $(INC)/HTAAUtil.h $(INC)/HTPasswd.h
	$(CC) -c $(CFLAGS2) $(SRC)/HTAdm.c


#		ISMAP image handling

htimage : HTImage.o $(LIBWWW)
	$(CC) -o htimage_$(VD) HTImage.o $(LIBWWW)
	-rm htimage
	ln -s htimage_$(VD) htimage

HTImage.o : $(SRC)/HTImage.c $(INC)/HTUtils.h
	$(CC) -c $(CFLAGS2) $(SRC)/HTImage.c


$(USELIBDIR)/libwww.a :
	@echo You must get and make the WWWLibrary product first!
	(cd $(WWW)/Library/$(WWW_MACH) && make)


lib :
	(cd $(WWW)/Library/$(WWW_MACH) && make)

# Things we check on all platforms and export binaries

all : httpd tigate
	echo "httpd and tigate daemons up to date"


# 		FIND gateway - test only (has to run on VM!)

FINDGate : $(FOBJS)
	$(CC) -o FINDGate $(FOBJS) $(LFLAGS)
FINDGate.o : $(SRC)/FINDGate.c $(INC)/HTUtils.h $(INC)/tcp.h
	$(CC) -c $(CFLAGS2) $(SRC)/FINDGate.c

#		Techinfo Gateway

tigate : $(TIOBJS)
	$(CC) $(LFLAGS) -o tigate $(TIOBJS)

TechInfoGate.o : $(SRC)/TechInfoGate.c
	$(CC) $(CFLAGS2) -c -o $@ $(SRC)/TechInfoGate.c

# 		WAIS Gateway is just httpd linked with freeWAIS
#	and a libwww copmpiled with the right flags.

# 		Common Code

test.o : $(SRC)/test.c $(INC)/HTUtils.h $(INC)/tcp.h $(INC)/HTTCP.h
	$(CC) -c $(CFLAGS2) -DRULES -DRULE_FILE=\"$(RULE_FILE)\" $(SRC)/test.c
HTDaemon.o : $(SRC)/HTDaemon.c $(INC)/HTUtils.h $(INC)/tcp.h $(INC)/HTTCP.h
	$(CC) -c $(CFLAGS2) -DRULES -DRULE_FILE=\"$(RULE_FILE)\" \
	 -DVD=\"$(VD)\" $(SRC)/HTDaemon.c
#
#  The following are version of the daemon code with different options.
#  They have to be made with a copy of the source because the -o
#  option does not work for object files for the AIX compiler! :-(
#
HTDaemonNR.o : $(SRC)/HTDaemon.c $(INC)/HTUtils.h $(INC)/tcp.h $(INC)/HTTCP.h
	cp $(SRC)/HTDaemon.c $(OBJ)/HTDaemonNR.c
	$(CC) -c $(CFLAGS2) -DNOCONVERT -DVD=\"$(VD)\"  $(OBJ)/HTDaemonNR.c
	rm $(OBJ)/HTDaemonNR.c
HTDaemonDIR.o : $(SRC)/HTDaemon.c $(INC)/HTUtils.h $(INC)/tcp.h \
	$(INC)/HTTCP.h
	cp $(SRC)/HTDaemon.c HTDaemonDIR.c
	$(CC) -c $(CFLAGS2)  -DRULES \
	-DRULE_FILE=\"$(RULE_FILE)\" -DDIR_OPTIONS  -DVD=\"$(VD)\" \
		HTDaemonDIR.c
	rm HTDaemonDIR.c

HTSInit.o : $(SRC)/HTSInit.c
	$(CC) -c $(CFLAGS) -I$(CMN) $(SRC)/HTSInit.c

#_________________________________________________________________________
#	Install the server

install :	$(PROD)
	csh $(SRC)/install.csh

#	Link system to the binary and documentation in this tree

link : Works/$(PROD)
	ln -s `pwd`/$(PROD) $(BINDIR)/$(PROD)
	- mkdir /usr/local
	- mkdir /usr/local/lib
	ln -s $(DEFAULTS) /usr/local/lib/WWW

uninstall :
	rm $(BINDIR)/$(PROD)
	rm -r /usr/local/lib/WWW

#	Clean up everything generatable except final products
#	Including obj directory UNLESS there is anything else in it
clean :
	- rm $(OBJ)/.created $(OBJ)/*.o
	- rmdir $(OBJ)

#	Clean up everything generatable including final products

cleanall : clean
	- rm $(PROD)

#	Binary release
#
#	Must be done on anonymous FTP server!
#
#  This makefile does not knw how to make $(PROD)_$(VD) so that trying
#  to make binay or asis on a weird machine doesn't try to build $(PROD)!

binary : $(PROD)_$(VD)
	-mkdir /pub/www/bin/$(WWW_MACH)
	cp $(PROD)_$(VD) /pub/www/bin/$(WWW_MACH)/$(PROD)_$(VD)

#	ASIS installation
#	-----------------
#	Can only happen on an allocated ASIS development machine and
#	with uid of the controlling user for the project.
#
asis :  /asis/specific/$(ASIS_MACH)/usr.local/bin/$(PROD)
	touch asis
	echo ASIS distribution is now up-to-date.

/asis/specific/$(ASIS_MACH)/usr.local/bin/$(PROD) : $(PROD)_$(VD)
	cp $(PROD)_$(VD) /asis/specific/$(ASIS_MACH)/usr.local/bin/$(PROD)_$(VD)
	rm -f /asis/specific/$(ASIS_MACH)/usr.local/bin/$(PROD)
	ln -s $(PROD)_$(VD) \
		/asis/specific/$(ASIS_MACH)/usr.local/bin/$(PROD)

#	CERNLIB installation
#	--------------------
#	Assuming the cernlib-style directory structure
#	Warning: Not suitable for machine-shared file structure.
#
cernlib :	$(PROD)
	- mkdir $(CERNLIBBIN)
	cp $(PROD) $(CERNLIBBIN)


#_________________________________________________________________________	


#	Check directory exists
$(OE) :
	-mkdir $(WTMP)
	-mkdir $(WTMP)/Daemon
	-mkdir $(WTMP)/Daemon/$(WWW_MACH)
	touch $(OE)


#_________________________________________________________________
# For W3 Administrative use only:


#		W3 Source + documentation release
#		---------------------------------

distribute :  /pub/www/README.txt /pub/www/Copyright.txt $(SOURCES)
	(cd $(WWW)/.. && WWW=WWW ABS=`pwd`/ make $(MFLAGS) \
		-f WWW/Daemon/Implementation/CommonMakefile \
		/pub/www/src/WWWDaemon_$(VD).tar.Z)
	(cd ../Implementation; cvs tag \
	    `sed -e 's/VD = /v/' Version.make | sed -e 's?\.?/?'` )
	@ echo Distribution of Daemon version $(VD) up to date.

# THIS MUST BE BUILT FROM THE DIRECTORY ABOVE WWW ! USE distribute above!
/pub/www/src/WWWDaemon_$(VD).tar.Z : $(SOURCES)
	tar cvf /pub/www/src/WWWDaemon_$(VD).tar \
	    $(SOURCES) $(DOC) \
	    $(VMS)/descrip.mms $(VMS)/build_multinet.com \
	    $(VMS)/setup.com
	compress /pub/www/src/WWWDaemon_$(VD).tar

#________________________________________________________________________
#		Hypertext supplied in text format
#		---------------------------------

$(WWW)/README.txt : $(WWW)/../README.html
	www -n -p66 http://info.cern.ch/hypertext/README.html \
		> $(WWW)/README.txt
/pub/www/README.txt : $(WWW)/README.txt
	cp $(WWW)/README.txt /pub/www/README.txt

$(WWW)/Copyright.txt : $(WWW)/../Copyright.html
	www -n -p66 http://info.cern.ch/hypertext/Copyright.html \
		> $(WWW)/Copyright.txt
/pub/www/Copyright.txt : $(WWW)/Copyright.txt
	cp $? $@


