#  Make WWW under unix for a.n.other unix system (bsd)
#   Use this as a template

# For W3 distribution, machine type for subdirectories
WWW_MACH = unix

# The ASIS repository's name for the machine we are on
ASIS_MACH = hardware/os


CFLAGS =  -DDEBUG -D__BSD__
LFLAGS =
CC = cc

# Directory for installed binary:
BINDIR = /usr/local/bin

# Where is the W3 object library to be installed (not normally done)?
LIBDIR = $(WWW)/Library/Implementation/$(WWW_MACH)

#_________________ OK if normal W3 distribution
# Where is the WWW source root?
WWW = ../..

#  Where should temporary (object) files go?
WTMP = ../..



#
#	WHEN COMPILING WITH DIRECT WAIS SUPPORT:
#
#	Uncomment these six lines (and edit them, if necessary).
#
# WAIS = ../../../freeWAIS
# WAISLIB =  $(WAIS)/bin/client.a $(WAIS)/bin/wais.a
# MATHLIB = -lm
# WAISINC = -I$(WAIS)/include
# WAISCFLAGS = -DHT_DIRECT_WAIS
# HTWAIS = $(WTMP)/Library/$(WWW_MACH)/HTWAIS.o

VL = 3.1
#	Makefile for WorldWideWeb    Line Mode browser (www)
#
#	(c) COPYRIGHT MIT 1995.
#	Please first read the full copyright statement in the file COPYRIGH.
#
# This file should be invariant between systems.
#	DEPENDENCIES NOT COMPLETE @@
#
#	make		Compile and link the software (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
#	
# Macros required to be defined already for make:
#
# CC		The C compiler
# CFLAGS	Flags for $(CC)
# LFLAGS	Flags for ld
# WWW		Root of WWW source tree
# USELIBDIR	Directory in which libwww.a should be found
#
# Macros needed for make install:
#
# BINDIR	Directory for installed binary
#______________________________________________________________________

#  If this env var is set to something else Some makes will use that instead
SHELL = /bin/sh

LM =  $(WWW)/LineMode/Implementation/
LMD = $(WWW)/LineMode/Defaults
CMN = $(WWW)/Library/Implementation/
DEFAULTS = $(WWW)/LineMode/Defaults
FTP = /afs/w3.org/member/Dist

# PURIFY_LOG = /home2/frystyk/purify-output
PURIFY_CACHE = /home2/frystyk/purify-cache

CFLAGS2 = $(CFLAGS) -I$(CMN) -I$(LM)

CERNLIBBIN = $(WWW)/bin

#	WTMP is either WWW or /tmp for example. It allows the 
# machine-dependent files to be put in a separate tree so that
#	- The source tree can be read-only
#	- The source tree can be shared across platforms
#
USELIBDIR = $(WTMP)/Library/$(WWW_MACH)
OBJ = $(WTMP)/LineMode/$(WWW_MACH)
BIN = $(WWW)/LineMode/$(WWW_MACH)

OE = $(OBJ)/.created

WWWLIB = -L$(USELIBDIR) -lwww

OBJS = $(OBJ)/HTBrowse.o $(OBJ)/GridText.o $(OBJ)/DefaultStyles.o

OBJS-CYR = $(OBJ)/HTBrowse-cyr.o $(OBJ)/GridText-cyr.o $(OBJ)/DefaultStyles-cyr.o $(OBJ)/a_stdio.o 

# Final main product
PROD = www

SOURCES = $(LM)HTBrowse.c	$(LM)HTBrowse.h \
	$(LM)GridText.c		$(LM)GridText.h \
	$(LM)GridStyle.c	$(LM)GridStyle.h \
	$(LM)HTFont.h		$(LM)DefaultStyles.c \
	$(LM)Version.make	$(LM)CommonMakefile \
	$(LM)README \
	$(WWW)/README		$(WWW)/COPYRIGH \
	$(WWW)/BUILD		$(WWW)/BUILD.SH \
	$(WWW)/PATCHES		$(WWW)/Makefile \
	$(WWW)/CERN \
 	$(LM)a_stdio.g		$(LM)a_stdio.h

DISTRIBUTION = \
	$(LM)DefaultStyles.c.classic \
	$(LM)DefaultStyles.c.modern

# $(LM)a_stdio.g $(LM)a_stdio.h were added to support -DCYRILLIC
HTMLFILES = \
	$(LM)HTBrowse.h \
	$(LM)GridStyle.h \
	$(LM)GridText.h \
	$(LM)HTFont.h \
	$(LM)a_stdio.h

.SUFFIXES: .h .html
.html.h:
	www -w90 -na -to text/x-c $*.html > $*.h

# $(LM)a_stdio.h was added to support -DCYRILLIC
SPECIFIC =  \
	$(WWW)/All/*/Makefile.include \
	$(WWW)/All/Implementation/Makefile \
	$(LM)vms/descrip.mms \
	$(LM)vms/build_multinet.com \
	$(LM)vms/setup.com

# Bug: This path, if relative, is taken relative to the directory
# in which this makefile is, not the pwd.  This screws up the 
# recursive invocation

# This is now done by cat in WWW/All/Implementation/Makefile
# include $(ABS)$(LM)Version.make

$(BIN)/$(PROD) : $(OBJS) $(USELIBDIR)/libwww.a
	$(CC) -o $(BIN)/$(PROD)_$(VL)  $(OBJS) $(LFLAGS) $(WWWLIB) \
	$(WAISLIB) $(MATHLIB)
	-rm $(BIN)/$(PROD)
	ln -s $(PROD)_$(VL) $(BIN)/$(PROD)

purify : $(OBJS) $(USELIBDIR)/libwww.a
	purify -cache-dir=$(PURIFY_CACHE) \
	$(CC) -o $(PROD)_$(VL) $(OBJS) $(LFLAGS) $(WWWLIB) \
	$(WAISLIB) $(MATHLIB)
	-rm $(BIN)/$(PROD)
	ln -s $(PROD)_$(VL) $(BIN)/$(PROD)

PROOF = proof

proof : $(OBJS) $(USELIBDIR)/libwww.a
	$(PROOF) $(CC) -o $(PROD)_$(VL) $(OBJS) $(LFLAGS) $(WWWLIB) \
	$(WAISLIB) $(MATHLIB)
	-rm $(BIN)/$(PROD)
	ln -s $(PROD)_$(VL) $(BIN)/$(PROD)

cyrillic : $(OBJS-CYR) $(USELIBDIR)/libwww.a
	$(CC) -o $(PROD)_$(VL) $(OBJS) $(OBJ)/a_stdio.o $(LFLAGS) $(WWWLIB) \
	$(WAISLIB) $(MATHLIB)
	-rm $(BIN)/$(PROD)
	ln -s $(PROD)_$(VL) $(BIN)/$(PROD)
	
$(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)

inc :	$(HTMLFILES)
	@echo "Include files generated from member"

#	Make a copy of the binary and documentation on this machine
install :	$(PROD)
	cp $(PROD) $(BINDIR)/$(PROD)
	- mkdir /usr/local
	- mkdir /usr/local/lib
	- mkdir /usr/local/lib/WWW
	cp $(DEFAULTS)/*.html /usr/local/lib/WWW

#	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)_$(VL) so that trying
#  to make binay or asis on a weird machine doesn't try to build $(PROD)!

binary : $(PROD)_$(VL)
	-mkdir $(FTP)/bin/$(WWW_MACH)
	cp $(PROD)_$(VL) $(FTP)/bin/$(WWW_MACH)/$(PROD)_$(VL)

#	ASIS installation
#	-----------------
#	Can only happen on an allocated ASIS development machine and
#	with uid of the controlling user for the project.
#
asis : /asis/share/usr.local/lib/WWW/default.html \
	/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)_$(VL)
	cp $(PROD)_$(VL) /asis/specific/$(ASIS_MACH)/usr.local/bin/$(PROD)_$(VL)
	rm -f /asis/specific/$(ASIS_MACH)/usr.local/bin/$(PROD)
	ln -s $(PROD)_$(VL) \
		/asis/specific/$(ASIS_MACH)/usr.local/bin/$(PROD)

/asis/share/usr.local/lib/WWW/default.html : $(DEFAULTS)/cern.html
	- mkdir /asis/share/usr.local/lib/WWW
	cp $(DEFAULTS)/*.html /asis/share/usr.local/lib/WWW
	cp $(DEFAULTS)/cern.html /asis/share/usr.local/lib/WWW/default.html
	cp $(DEFAULTS)/default.html /asis/share/usr.local/lib/WWW/top.html

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


#_________________________________________________________________________	
# Compiling the Objects (Dependenies incomplete)

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

#
$(OBJ)/HTBrowse.o : $(OE) $(LM)HTBrowse.c $(LM)GridText.h $(LM)Version.make \
		$(CMN)HTUtils.h $(CMN)HTAccess.h
	$(CC) -c -o $@ $(CFLAGS2) -DVL=\"$(VL)\" $(LM)HTBrowse.c  

$(OBJ)/GridText.o : $(OE) $(LM)GridText.c $(LM)GridText.h $(LM)GridStyle.h\
	 $(CMN)HTAnchor.h $(CMN)HTStyle.h
	$(CC) -c -o $@ $(CFLAGS2) $(LM)GridText.c

$(OBJ)/DefaultStyles.o : $(OE) $(LM)DefaultStyles.c $(CMN)HTStyle.h
	$(CC) -c -o $@ $(CFLAGS2) $(LM)DefaultStyles.c  

# the cyrillic version 

$(OBJ)/HTBrowse-cyr.o : $(OE) $(LM)HTBrowse.c $(LM)GridText.h $(LM)Version.make \
		$(CMN)HTUtils.h $(CMN)HTAccess.h
	$(CC) -c -o $@ $(CFLAGS2) -DCYRILLIC -DVL=\"$(VL)\" $(LM)HTBrowse.c  

$(OBJ)/GridText-cyr.o : $(OE) $(LM)GridText.c $(LM)GridText.h $(LM)GridStyle.h\
	 $(CMN)HTAnchor.h $(CMN)HTStyle.h
	$(CC) -c -o $@ $(CFLAGS2) -DCYRILLIC $(LM)GridText.c

$(OBJ)/DefaultStyles-cyr.o : $(OE) $(LM)DefaultStyles.c $(CMN)HTStyle.h
	$(CC) -c -o $@ $(CFLAGS2) -DCYRILLIC $(LM)DefaultStyles.c  

$(OBJ)/a_stdio.o : $(OE) $(LM)a_stdio.g $(LM)a_stdio.h
	$(CC) -c -o $@ $(CFLAGS2) -xc $(LM)a_stdio.g

#_________________________________________________________________
# For W3 Administrative use only:

#	Source Destribution
distribute : $(WWW)/README $(WWW)/COPYRIGHT $(WWW)/PATCHES $(WWW)/CERN $(SOURCES)
	(cd $(WWW)/.. && WWW=WWW ABS=`pwd`/ make $(MFLAGS) \
	-f WWW/LineMode/Implementation/Version.make \
	-f WWW/LineMode/Implementation/CommonMakefile \
	$(FTP)/src/WWWLineMode_$(VL).tar.Z)
	(cd $(WWW); cvs tag \
	    `sed -e 's/V. = /v/' LineMode/Implementation/Version.make | sed -e 's?\.?/?'` \
	    LineMode)
	@echo Distribution of Line Mode version $(VC) up to date.

$(FTP)/src/WWWLineMode_$(VL).tar.Z : $(SOURCES)
	tar cvf $(FTP)/src/WWWLineMode_$(VL).tar \
	    $(SOURCES) \
	    $(DISTRIBUTION) \
	    $(SPECIFIC) \
	    $(LM)*.html
	cp $(FTP)/src/WWWLineMode_$(VL).tar $(FTP)/src/temp.tar
	compress -f $(FTP)/src/WWWLineMode_$(VL).tar
	mv $(FTP)/src/temp.tar $(FTP)/src/WWWLineMode_$(VL).tar
	gzip -f $(FTP)/src/WWWLineMode_$(VL).tar

zip : $(WWW)/README $(WWW)/COPYRIGHT $(WWW)/PATCHES $(WWW)/CERN $(SOURCES)
	(cd $(WWW)/..; WWW=WWW ABS=`pwd`/ make $(MFLAGS) \
	-f WWW/LineMode/Implementation/Version.make \
	-f WWW/LineMode/Implementation/CommonMakefile \
	$(FTP)/src/WWWLineMode_$(VL).zip)
	@echo Distribution of LineMode version $(VL) up to date.

$(FTP)/src/WWWLineMode_$(VL).zip : $(SOURCES)
	zip -v $(FTP)/src/WWWLineMode_$(VL).zip \
	    $(SOURCES) \
	    $(DISTRIBUTION) \
	    $(SPECIFIC) \
	    $(LM)*.html

#		Member supplied in text format
#		---------------------------------

$(WWW)/README : /afs/w3.org/member/WWW/README.html
	www -p -na http://www.w3.org/member/WWW/README.html -o $(WWW)/README

$(WWW)/COPYRIGHT : /afs/w3.org/member/WWW/COPYRIGHT.html
	www -p -na http://www.w3.org/member/WWW/COPYRIGHT.html -o $(WWW)/COPYRIGH

$(WWW)/PATCHES : /afs/w3.org/member/WWW/PATCHES.html
	www -p -na http://www.w3.org/member/WWW/PATCHES.html -o $(WWW)/PATCHES

$(WWW)/CERN : /afs/w3.org/member/WWW/CERN.html
	www -p -na http://www.w3.org/member/WWW/CERN.html -o $(WWW)/CERN

#	Line Mode Manual
#
QUICKGUIDE = \
	$(LMD)/QuickGuide.html \
	$(LMD)/Commands.html \
	    $(LMD)/SourceExamples.html \
	$(LMD)/CommandLine.html \
	$(LMD)/Shortcuts.html \
	    $(LMD)/VMS_Shortcuts.html \
	$(LMD)/Installation.html \
	    $(LMD)/Installation_VMS.html \
	    $(LMD)/Installation_VMS_NewTCP.html \
	    $(LMD)/Distribution.html \
	    $(LMD)/Porting.html \
	    $(LMD)/MachineTypes.html \
	    $(LMD)/InstallNotSU.html \
	    $(LMD)/Path.html \
	    $(LMD)/LoginScript.html \
	$(LMD)/Customisation.html \
	    $(LMD)/EnvVariables.html \
	    $(LMD)/GlobalV.html \
	    $(LMD)/NewsServer.html \
	$(LMD)/Bugs.html \
	$(LMD)/Features.html

doc : $(FTP)/doc/line-mode-guide.txt
	@echo line mode browser guide exists.

$(FTP)/doc/line-mode-guide.txt : $(LMD)/line-mode-guide.txt
	cp $? $@

$(LMD)/line-mode-guide.txt : $(QUICKGUIDE)
	-rm $@
	for i in $(QUICKGUIDE) ; do www -n -na -p66 $$i >> $@; done

